import type { Metadata } from "next";
import { ThemeInit } from "@/components/theme-init";
import "./globals.css";

export const metadata: Metadata = {
  title: "Mindavio",
  description: "Your all-in-one productivity system",
};

const themeScript = `(function(){try{var t=localStorage.getItem("mindavio-theme")||"system";var d=t==="system"?window.matchMedia("(prefers-color-scheme:dark)").matches?"dark":"light":t;document.documentElement.classList.add(d)}catch(e){}})()`;

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html
      lang="en"
      suppressHydrationWarning
      className="h-full antialiased"
    >
      <head>
        {/* Raw <script> is hoisted correctly by React 19 in <head> — avoids the
            "script tag in React component" warning that <Script beforeInteractive> triggers */}
        <script
          id="mindavio-theme-init"
          // eslint-disable-next-line react/no-danger
          dangerouslySetInnerHTML={{ __html: themeScript }}
        />
      </head>
      <body className="min-h-screen bg-background text-foreground">
        <ThemeInit />
        {children}
      </body>
    </html>
  );
}
