import type { Metadata, Viewport } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import { headers } from "next/headers";
import { ThemeProvider } from "@/components/providers/ThemeProvider";
import { UserProvider } from "@/components/providers/UserProvider";
import { CalendarProvider } from "@/components/providers/CalendarProvider";
import "./globals.css";

const geistSans = Geist({
  variable: "--font-geist-sans",
  subsets: ["latin"],
});

const geistMono = Geist_Mono({
  variable: "--font-geist-mono",
  subsets: ["latin"],
});

export const metadata: Metadata = {
  title: process.env.NEXT_PUBLIC_SYSTEM_NAME || "Teletraan",
  description: "Claude Code Web Interface",
};

export const viewport: Viewport = {
  width: "device-width",
  initialScale: 1,
  viewportFit: "cover",
};

export default async function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  const headersList = await headers();
  const userEmail =
    headersList.get("x-forwarded-email") ||
    process.env.DEV_USER_EMAIL ||
    "developer@localhost";
  const userName =
    headersList.get("x-forwarded-user") ||
    process.env.DEV_USER_NAME ||
    "Developer";

  return (
    <html
      lang="en"
      suppressHydrationWarning
      className={`${geistSans.variable} ${geistMono.variable} h-full antialiased`}
    >
      <body className="h-full">
        <ThemeProvider>
          <UserProvider email={userEmail} name={userName}>
            <CalendarProvider>
                {children}
            </CalendarProvider>
          </UserProvider>
        </ThemeProvider>
      </body>
    </html>
  );
}
