import { AppShell } from "@/components/layout/app-shell";
import { getAdminDb } from "@/lib/firebase/admin";

async function getProjectName(projectId: string): Promise<string> {
  try {
    const adminDb = getAdminDb();
    const projectDoc = await adminDb.collection('projects').doc(projectId).get();
    if (projectDoc.exists) {
      const data = projectDoc.data();
      return data?.productName || data?.name || "Product";
    }
  } catch (error) {
    console.error("Error fetching project name:", error);
  }
  return "Product";
}

export default async function ProjectLayout({
  children,
  params,
}: {
  children: React.ReactNode;
  params: Promise<{ workspace: string; projectId: string }>;
}) {
  const { workspace, projectId } = await params;
  const projectName = await getProjectName(projectId);
  
  return (
    <AppShell workspace={workspace} projectId={projectId} projectName={projectName}>
      {children}
    </AppShell>
  );
}

