import type { Metadata, Viewport } from "next";
import { Nunito, Shrikhand } from "next/font/google";
import "./globals.css";

const body = Nunito({ variable: "--font-body", subsets: ["latin"] });
const heading = Shrikhand({ variable: "--font-heading", subsets: ["latin"], weight: "400" });

// Schermate di avvio iPhone generate da scripts/build-icons.sh: larghezza, altezza (punti), densità
const SPLASH = [
  [430, 932, 3], [393, 852, 3], [402, 874, 3], [440, 956, 3], [390, 844, 3],
  [428, 926, 3], [375, 812, 3], [414, 896, 2], [375, 667, 2],
] as const;

const SITE = process.env.VERCEL_PROJECT_PRODUCTION_URL ? `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}` : "http://localhost:3210";

export const metadata: Metadata = {
  metadataBase: new URL(SITE),
  title: "AmiCibi",
  description: "Cosa mangiano, e cosa no, i nostri amici",
  openGraph: { siteName: "AmiCibi", title: "AmiCibi", description: "Cosa mangiano, e cosa no, i nostri amici", locale: "it_IT", type: "website" },
  robots: { index: false, follow: false, nocache: true, googleBot: { index: false, follow: false } },
  appleWebApp: {
    capable: true,
    title: "AmiCibi",
    // Barra opaca: con black-translucent iOS 26+ sfuma la cima (vedi .scudo-barra-ios).
    // Con "default" resta bianca fissa; con "black" iOS prende il colore dalla barra sticky in cima (vedi .gingham.sticky)
    statusBarStyle: "black",
    startupImage: SPLASH.map(([w, h, d]) => ({
      url: `/splash/splash-${w}x${h}@${d}x.png`,
      media: `(device-width: ${w}px) and (device-height: ${h}px) and (-webkit-device-pixel-ratio: ${d}) and (orientation: portrait)`,
    })),
  },
  formatDetection: { telephone: false },
};

export const viewport: Viewport = {
  width: "device-width",
  initialScale: 1,
  viewportFit: "cover",
  themeColor: [
    { media: "(prefers-color-scheme: light)", color: "#2f55c9" },
    { media: "(prefers-color-scheme: dark)", color: "#2a4ab0" },
  ],
};

export default function RootLayout({ children }: LayoutProps<"/">) {
  return (
    <html lang="it" className={`${body.variable} ${heading.variable} h-full antialiased`}>
      <body className="min-h-full">
        <div className="scudo-barra-ios" aria-hidden="true">
          <div />
        </div>
        {children}
      </body>
    </html>
  );
}
