"use client";

import type { ReactNode } from "react";
import { usePathname } from "next/navigation";
import type { Session } from "next-auth";
import { AdminHeader } from "@/components/admin/AdminHeader";
import { AdminSidebar } from "@/components/admin/AdminSidebar";

type AdminShellProps = { children: ReactNode; session: Session | null };

export function AdminShell({ children, session }: AdminShellProps) {
  const pathname = usePathname();

  if (pathname === "/admin/login") {
    return <>{children}</>;
  }

  const sectionTitle =
    pathname === "/admin"
      ? "Admin Dashboard"
      : pathname
          .replace("/admin/", "")
          .split("/")
          .filter(Boolean)
          .map((item) => item.replace(/-/g, " "))
          .join(" / ");

  return (
    <div className="min-h-screen bg-[#f5f7fb] lg:flex">
      <AdminSidebar />
      <div className="min-w-0 flex-1 lg:px-4 lg:py-3">
        <div className="overflow-hidden rounded-2xl border border-border bg-white shadow-sm">
          <AdminHeader session={session} title={sectionTitle || "Admin"} />
          <main className="p-4 md:p-6">{children}</main>
        </div>
      </div>
    </div>
  );
}
