import type { Metadata } from "next"; import { GeistSans } from "geist/font"; import { cookies } from "next/headers"; import "./globals.css"; import type { SpaceConfig } from "@/lib/spaces"; import { themeToCSS } from "@/lib/spaces"; import { HeaderBar } from "@/components/HeaderBar"; import { EcosystemFooter } from "@/components/EcosystemFooter"; const API_URL = process.env.NEXT_PUBLIC_API_URL || "http://localhost:8000/api"; async function getSpaceConfig(spaceId: string): Promise { try { const res = await fetch(`${API_URL}/spaces/${spaceId}`, { next: { revalidate: 300 }, }); if (res.ok) return res.json(); } catch {} return null; } export async function generateMetadata(): Promise { const cookieStore = await cookies(); const spaceId = cookieStore.get("space_id")?.value || "default"; const space = await getSpaceConfig(spaceId); const name = space?.name || "rSwag"; const tagline = space?.tagline || "Merch for the rSpace Ecosystem"; return { title: `${name} — ${tagline}`, description: space?.description || "Design and order custom merchandise.", }; } export default async function RootLayout({ children, }: { children: React.ReactNode; }) { const cookieStore = await cookies(); const spaceId = cookieStore.get("space_id")?.value || "default"; const space = await getSpaceConfig(spaceId); const name = space?.name || "rSwag"; const logoUrl = space?.logo_url; const themeCSS = space?.theme ? themeToCSS(space.theme) : ""; return ( {themeCSS && (