import type { Metadata } from "next";
import { Manrope, Host_Grotesk, Barlow_Condensed, Instrument_Serif, Funnel_Sans } from "next/font/google";
import ScrollToTop from "@/components/ScrollToTop";
import ScrollToTopButton from "@/components/ScrollToTopButton";
import Header from "@/components/Header";
import Footer from "@/components/Footer";
import GlobalImageFallback from "@/components/GlobalImageFallback";
import { getHeaderData } from "@/lib/api/header";
import { getFooterData } from "@/lib/api/footer";
import { resolveAssetUrls } from "@/lib/asset-url";
import "./global.css";

const manrope = Manrope({
  variable: "--font-manrope",
  subsets: ["latin"],
  weight: ["400", "500", "600", "700", "800"],
});

const hostGrotesk = Host_Grotesk({
  variable: "--font-host-grotesk",
  subsets: ["latin"],
  weight: ["400", "500", "700", "800"],
});

const barlowCondensed = Barlow_Condensed({
  variable: "--font-barlow-condensed",
  subsets: ["latin"],
  weight: ["400", "500", "600", "700", "800"],
});

const instrumentSerif = Instrument_Serif({
  variable: "--font-instrument-serif",
  subsets: ["latin"],
  weight: "400",
});

const funnelSans = Funnel_Sans({
  variable: "--font-funnel-sans",
  subsets: ["latin"],
  weight: ["400", "500", "700"],
});

export const metadata: Metadata = {
  title: "MGM Group | Diversified Conglomerate Since 1963",
  description: "MGM Group - A diversified conglomerate established in 1963, excelling in entertainment, hospitality, manufacturing, renewable energy, and logistics across India.",
  keywords: "MGM Group, M.G. Muthu Group, business conglomerate, hospitality, entertainment, renewable energy, logistics, manufacturing, India",
  authors: [{ name: "MGM Group" }],
  metadataBase: new URL("https://www.mgm-india.com"),
  manifest: "/site.webmanifest",
  openGraph: {
    title: "MGM Group | Diversified Conglomerate Since 1963",
    description: "A diversified conglomerate established in 1963, excelling in entertainment, hospitality, manufacturing, renewable energy, and logistics.",
    type: "website",
    url: "https://www.mgm-india.com",
    images: [
      {
        url: "/opengraph-image",
        width: 1200,
        height: 630,
        alt: "MGM Group",
      },
    ],
    siteName: "MGM Group",
    locale: "en_IN",
  },
  twitter: {
    card: "summary_large_image",
    title: "MGM Group | Diversified Conglomerate Since 1963",
    description: "A diversified conglomerate established in 1963, excelling across industries.",
    images: ["/opengraph-image"],
  },
  icons: {
    icon: [
      { url: "/favicon.ico", sizes: "any" },
      { url: "/favicon-48x48.png", sizes: "48x48", type: "image/png" },
      { url: "/favicon-96x96.png", sizes: "96x96", type: "image/png" },
      { url: "/android-chrome-192x192.png", sizes: "192x192", type: "image/png" },
      { url: "/android-chrome-512x512.png", sizes: "512x512", type: "image/png" },
    ],
    shortcut: "/favicon.ico",
    apple: [
      { url: "/apple-touch-icon.png", sizes: "180x180", type: "image/png" },
    ],
  },
  other: {
    "theme-color": "#102443",
    "mobile-web-app-capable": "yes",
    "msapplication-TileColor": "#ffffff",
    "msapplication-TileImage": "/mstile-150x150.png",
  },
};

export default async function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  const [headerData, footerData] = await Promise.all([
    getHeaderData(),
    getFooterData(),
  ]);
  const header = resolveAssetUrls(headerData);
  const footer = resolveAssetUrls(footerData);

  return (
    <html
      lang="en"
      className={`${manrope.variable} ${hostGrotesk.variable} ${barlowCondensed.variable} ${instrumentSerif.variable} ${funnelSans.variable} antialiased`}
    >
      <head>
        <script
          type="application/ld+json"
          dangerouslySetInnerHTML={{
            __html: JSON.stringify({
              "@context": "https://schema.org",
              "@type": "Organization",
              name: "MGM Group",
              alternateName: "M.G. Muthu Group",
              url: "https://www.mgm-india.com",
              logo: "https://www.mgm-india.com/favicon-512x512.png",
              description: "A diversified Indian conglomerate established in 1963, excelling in entertainment, hospitality, manufacturing, renewable energy, and logistics.",
              foundingDate: "1963",
              address: {
                "@type": "PostalAddress",
                addressLocality: "Chennai",
                addressRegion: "Tamil Nadu",
                addressCountry: "IN",
              },
              contactPoint: {
                "@type": "ContactPoint",
                telephone: "+91-898-989-8989",
                contactType: "customer service",
                email: "info@mgm-india.com",
              },
            }),
          }}
        />
      </head>
      <body suppressHydrationWarning className="min-h-screen flex flex-col bg-[#f4f7fb]">
        <GlobalImageFallback />
        <ScrollToTop />
        <Header data={header} />
        <div className="flex-1">{children}</div>
        <Footer data={footer} />
        <ScrollToTopButton />
      </body>
    </html>
  );
}
