import type { Metadata, Viewport } from "next";
import { UIProvider } from "@/components/ui";
import "./globals.css";

const NAME = process.env.NEXT_PUBLIC_PRODUCT_NAME ?? "Tempest Pulse";

export const metadata: Metadata = {
  title: { default: `${NAME} · Brand Tempest`, template: `%s · ${NAME}` },
  description: "Unified marketing automation: leads, CRM, messaging, ads, content, analytics and AI on one customer record.",
  icons: { icon: "/icon.svg" },
};
export const viewport: Viewport = { width: "device-width", initialScale: 1, themeColor: "#2563EB" };

const themeScript = `try{var t=localStorage.getItem('tp-theme');if(t==='dark'||t==='light')document.documentElement.dataset.theme=t}catch(e){}`;
// Brand Tempest typefaces: Syne (display), Inter Tight (UI), Hind Siliguri (Bangla)
const FONTS = "https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@500;600;700;800&family=Inter:wght@400;500;600;700&family=Hind+Siliguri:wght@400;500;600&display=swap";

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en" suppressHydrationWarning>
      <head>
        <link rel="preconnect" href="https://fonts.googleapis.com" />
        <link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="" />
        <link rel="stylesheet" href={FONTS} />
        <script dangerouslySetInnerHTML={{ __html: themeScript }} />
      </head>
      <body><UIProvider>{children}</UIProvider></body>
    </html>
  );
}
