import { redirect } from "next/navigation";

import { getActiveContext } from "@/lib/appwrite/active-context";
import { DashboardShell } from "./dashboard-shell";

export default async function DashboardLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  const ctx = await getActiveContext();
  if (!ctx) redirect("/onboarding");

  const company = {
    id: ctx.tenantId,
    name: ctx.settings?.companyName ?? "Çalışma alanı",
  };
  const user = {
    id: ctx.user.id,
    name: ctx.user.name || ctx.user.email,
    email: ctx.user.email,
  };

  return (
    <DashboardShell user={user} company={company}>
      {children}
    </DashboardShell>
  );
}
