import { redirect } from "next/navigation";
import PanelShell from "@/components/panel/PanelShell";
import { getSession } from "@/lib/session";
import { getDb } from "@/lib/db";

export const metadata = { title: "Client Portal", robots: { index: false } };

const NAV = [
  { href: "/client", label: "Overview", icon: "grid" },
  { href: "/client/services", label: "My services", icon: "server" },
  { href: "/client/tickets", label: "Support tickets", icon: "ticket" },
  { href: "/client/invoices", label: "Invoices", icon: "invoice" },
];

export default async function ClientLayout({ children }: { children: React.ReactNode }) {
  const session = await getSession();
  if (!session) redirect("/login");
  const db = await getDb();
  const user = db.users.find((u) => u.id === session.uid);
  if (!user) redirect("/login");

  return (
    <PanelShell items={NAV} title="Client portal" userName={user.name} userMeta={user.company}>
      {children}
    </PanelShell>
  );
}
