import type { Metadata } from "next";
import localFont from "next/font/local";
import { defaultSEOConfig } from "@/config/seoConfig";

import "./globals.css";
import Layout from "@/components/Layout";
import RegisterSW from "@/components/RegisterSW";

const iranSansFont = localFont({
  src: "./../../public/fonts/IRANSansX-Regular.woff",
});

export const metadata: Metadata = {
  title: defaultSEOConfig.title,
  description: defaultSEOConfig.description,
  metadataBase: new URL("https://modstagram.com"),
  keywords: [
    "مادستاگرام",
    "مدلینگ",
    "بیلبورد تبلیغاتی",
    "پست مدل",
    "آموزشگاه مدلینگ",
  ],
  authors: [{ name: "Modstagram", url: "https://modstagram.com" }],
  creator: "Modstagram",
  alternates: {
    canonical: "/",
  },
  openGraph: {
    title: defaultSEOConfig.openGraph?.title || "",
    description: defaultSEOConfig.openGraph?.description || "",
    url: defaultSEOConfig.openGraph?.url || "",
    siteName: defaultSEOConfig.openGraph?.site_name || "",
    locale: "fa_IR",
    type: "website",
  },
  robots: "index, follow",
  twitter: {
    card: "summary_large_image",
    title: defaultSEOConfig.title || "",
    description: defaultSEOConfig.description || "",
    creator: "@modstagram",
    images: defaultSEOConfig.openGraph?.images?.map((img) => img.url) || [],
  },
  verification: {
    google: "yVjB5yKPchPUtxl33GWVyMvjH6wCEInqEvaH7ZsXXMo",
  },
};

const getInitialTheme = (): string => {
  if (typeof window !== "undefined") {
    return localStorage.getItem("theme") || "light";
  }
  return "light";
};

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  const initialTheme = getInitialTheme();

  return (
    <html lang="fa" dir="rtl" className={initialTheme}>
      <link rel="manifest" href="/manifest.json" />
      <meta name="theme-color" content="#ffffff" />
      <link rel="apple-touch-icon" href="/images/icons/192x192.png" />

      <head>
        <link rel="icon" href="/favicon.ico" type="image/x-icon" />
        <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
        <meta name="apple-mobile-web-app-capable" content="yes" />
        <meta name="apple-mobile-web-app-status-bar-style" content="black" />
        <link
          rel="apple-touch-icon"
          href="/images/icons/apple-touch-icon.png"
        />
        <meta name="msapplication-TileColor" content="#0072BC" />
        <meta name="msapplication-TileImage" content="/path/to/tileImage.png" />
        <meta name="samandehi" content="522190795" />
      </head>
      <body
        className={`${iranSansFont.className} antialiased bg-white dark:bg-neutral-950 text-text-primary-light dark:text-primary-light`}
      >
        <RegisterSW />
        <Layout>{children}</Layout>
      </body>
    </html>
  );
}
