import type { Metadata, Viewport } from "next";
import { DM_Sans, Fraunces } from "next/font/google";
import { BRAND_DOMAIN, BRAND_NAME, BRAND_TAGLINE } from "@/lib/brand";
import { ToastRegion } from "@/components/ui/toast";
import "./globals.css";

// DM Sans : geometrique distinctement reconnaissable (a/e/o ronds), utilisee
// par Stripe / Notion / Replit. Manrope etait trop subtil vs Cabinet Grotesk
// pour qu'on percoive le changement. DM Sans est nettement plus tranche.
const dmSans = DM_Sans({
  subsets: ["latin"],
  weight: ["400", "500", "600", "700"],
  variable: "--font-sans-base",
  display: "swap",
});

const fraunces = Fraunces({
  subsets: ["latin"],
  variable: "--font-fraunces",
  display: "swap",
  axes: ["SOFT", "opsz"],
});

const SITE_URL = `https://${BRAND_DOMAIN}`;

export const metadata: Metadata = {
  metadataBase: new URL(SITE_URL),
  title: { default: BRAND_NAME, template: `%s · ${BRAND_NAME}` },
  description: BRAND_TAGLINE,
  applicationName: BRAND_NAME,
  authors: [{ name: BRAND_NAME }],
  creator: BRAND_NAME,
  publisher: BRAND_NAME,
  formatDetection: { email: false, address: false, telephone: false },
  openGraph: {
    type: "website",
    locale: "fr_FR",
    url: SITE_URL,
    siteName: BRAND_NAME,
    title: BRAND_NAME,
    description: BRAND_TAGLINE,
  },
  twitter: {
    card: "summary_large_image",
    title: BRAND_NAME,
    description: BRAND_TAGLINE,
  },
  robots: {
    index: true,
    follow: true,
    googleBot: { index: true, follow: true, "max-image-preview": "large", "max-snippet": -1 },
  },
};

export const viewport: Viewport = {
  themeColor: "#faf7f2",
  colorScheme: "light",
};

// LocalBusiness + Organization combines : Novelia est une agence (Organization)
// mais avec une cible commerciale locale TPE/artisans (LocalBusiness =
// eligibilite pack local Google). On utilise ProfessionalService (sous-type
// LocalBusiness) qui colle mieux a "agence de services".
const organizationJsonLd = {
  "@context": "https://schema.org",
  "@type": ["Organization", "ProfessionalService"],
  "@id": `${SITE_URL}#organization`,
  name: BRAND_NAME,
  url: SITE_URL,
  description: BRAND_TAGLINE,
  areaServed: { "@type": "Country", name: "France" },
  foundingDate: "2025",
  logo: `${SITE_URL}/logo.png`,
  image: `${SITE_URL}/opengraph-image`,
  priceRange: "EUR",
  contactPoint: {
    "@type": "ContactPoint",
    contactType: "customer service",
    email: `contact@${BRAND_DOMAIN}`,
    availableLanguage: ["French"],
    areaServed: "FR",
  },
  // sameAs : profils sociaux + repos publics. Vide pour l'instant, a remplir
  // quand les comptes LinkedIn/X/GitHub seront crees. Aide signal d'autorite.
  sameAs: [] as string[],
};

// WebSite + SearchAction : eligible "Sitelinks searchbox" Google sur la SERP
// pour la marque (recherche directe depuis Google sans cliquer sur le site).
const websiteJsonLd = {
  "@context": "https://schema.org",
  "@type": "WebSite",
  "@id": `${SITE_URL}#website`,
  url: SITE_URL,
  name: BRAND_NAME,
  description: BRAND_TAGLINE,
  publisher: { "@id": `${SITE_URL}#organization` },
  inLanguage: "fr-FR",
};

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="fr" className={`${dmSans.variable} ${fraunces.variable}`}>
      <body>
        <a href="#main-content" className="skip-link">
          Aller au contenu principal
        </a>
        {children}
        <ToastRegion />
        <script
          type="application/ld+json"
          dangerouslySetInnerHTML={{ __html: JSON.stringify(organizationJsonLd) }}
        />
        <script
          type="application/ld+json"
          dangerouslySetInnerHTML={{ __html: JSON.stringify(websiteJsonLd) }}
        />
      </body>
    </html>
  );
}
