import { isLocale, type Locale } from "@/i18n/routes";
import { SiteHeader } from "@/components/site-header";
import { SiteFooter } from "@/components/site-footer";
import { getDb } from "@/lib/db";
import { seedIfEmpty } from "@/lib/seed";
import { listProjects } from "@/lib/models";

export default async function LangLayout({
  children,
  params,
}: {
  children: React.ReactNode;
  params: Promise<{ lang: string }>;
}) {
  const { lang } = await params;
  const locale: Locale = isLocale(lang) ? lang : "de";
  const db = getDb();
  seedIfEmpty(db);
  // Schlanke Projektliste für die Command-Palette.
  const projects = listProjects(db, locale).map((p) => ({
    slug: p.slug,
    summary: p.summary,
    category: p.category,
    status: p.status,
  }));
  return (
    <div className="flex min-h-screen flex-col">
      <SiteHeader locale={locale} projects={projects} />
      <main className="flex-1">{children}</main>
      <SiteFooter locale={locale} />
    </div>
  );
}
