import type { Metadata } from "next";
import localFont from "next/font/local";
import "@/styles/globals.css";
import { ModelInitializer } from "@/components/ModelInitializer";
import QueryProvider from "@/components/providers/QueryProvider";
import { ThemeProvider } from "@/components/providers/ThemeProvider";
import { OfflineSyncProvider } from "@/components/providers/OfflineSyncProvider";
import { OfflineBanner } from "@/components/common/OfflineIndicator";
import { Toaster } from "@/components/ui/toaster";
import { ErrorBoundary } from "@/components/providers/ErrorBoundary";
import { TaskPollingProvider } from "@/components/providers/TaskPollingProvider";
import { GlobalSettings } from "@/components/GlobalSettings";

const geistSans = localFont({
  src: "../styles/fonts/GeistVF.woff",
  variable: "--font-geist-sans",
  weight: "100 900",
});
const geistMono = localFont({
  src: "../styles/fonts/GeistMonoVF.woff",
  variable: "--font-geist-mono",
  weight: "100 900",
});

export const metadata: Metadata = {
  title: "Pixel Studio",
  description: "AI Comic and Video Creation Platform",
};

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html lang="zh" suppressHydrationWarning>
      <body
        className={`${geistSans.variable} ${geistMono.variable} antialiased`}
      >
        <ThemeProvider
            attribute="class"
            forcedTheme="dark"
            disableTransitionOnChange
          >
          <QueryProvider>
            <TaskPollingProvider>
              <OfflineSyncProvider>
                <ErrorBoundary>
                  <ModelInitializer />
                  <OfflineBanner />
                  {children}
                  <GlobalSettings />
                  <Toaster />
                </ErrorBoundary>
              </OfflineSyncProvider>
            </TaskPollingProvider>
          </QueryProvider>
        </ThemeProvider>
      </body>
    </html>
  );
}
