import type { Metadata } from "next";
import { headers } from "next/headers";
import "./globals.css";
import { Header } from "@/components/Header";
import { Footer } from "@/components/Footer";
import { JsonLd } from "@/components/JsonLd";
import { siteConfig } from "@/data/site";
import { createPageMetadata, tourismOrganizationSchema, websiteSchema } from "@/lib/seo";
import { AdTracking } from "@/components/AdTracking";
import { BUILD_VERSION, IS_STAGING } from "@/lib/environment";
import { MpcAnalyticsTracker } from "@/components/MpcAnalyticsTracker";

export const dynamic = "force-dynamic";


const criticalLaunchCss = `
:root{--mpc-ink:#21160f;--mpc-forest:#111b11;--mpc-cream:#fbf4e8;--mpc-soft:#f4e4c6;--mpc-gold:#f2c661;--mpc-muted:#6c5c49}
*{box-sizing:border-box}.mpc-staging-indicator{position:fixed;right:12px;bottom:12px;z-index:2147483647;padding:8px 12px;border-radius:999px;background:#b42318;color:#fff;font:900 12px/1.2 Inter,system-ui,sans-serif;letter-spacing:.04em;box-shadow:0 8px 24px rgba(0,0,0,.28)}html{scroll-behavior:smooth}body{margin:0;background:var(--mpc-cream);color:var(--mpc-ink);font-family:Inter,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;line-height:1.5}img{max-width:100%;height:auto;display:block}a{color:inherit}.container{width:min(1160px,calc(100% - 32px));margin-inline:auto}.site-header{position:sticky;top:0;z-index:50;background:#17100b;color:#fff;border-bottom:1px solid rgba(255,255,255,.08)}.nav-wrap{min-height:72px;display:flex;align-items:center;gap:18px;justify-content:space-between}.brand{display:inline-flex;align-items:center;text-decoration:none}.brand-logo,.header-emblem-logo{width:56px;height:56px;border-radius:999px;object-fit:contain}.nav-links{display:flex;gap:16px;align-items:center;flex-wrap:wrap}.nav-links a{text-decoration:none;font-weight:800;font-size:.94rem;color:#fff8e8}.visitor-menu-shell{position:relative}.visitor-menu-toggle{cursor:pointer;list-style:none;display:inline-flex;align-items:center;gap:8px;border:1px solid rgba(255,255,255,.18);border-radius:999px;padding:10px 14px;font-weight:900;background:rgba(255,255,255,.07)}.visitor-main-menu{position:absolute;right:0;top:calc(100% + 10px);width:min(420px,calc(100vw - 32px));background:#fffaf2;color:#21160f;border-radius:24px;padding:18px;box-shadow:0 22px 80px rgba(0,0,0,.22);border:1px solid rgba(55,38,20,.14)}.visitor-menu-grid,.premium-menu-actions{display:grid;gap:8px}.visitor-menu-grid{grid-template-columns:repeat(2,minmax(0,1fr))}.visitor-menu-grid a{text-decoration:none;border-radius:14px;background:#f3eadb;padding:10px;font-weight:800}.mpc-page-hero,.ui48-page-hero{background:linear-gradient(135deg,#121d12 0%,#25391e 55%,#60421d 100%);color:#fff;padding:clamp(36px,6vw,76px) 0}.ui48-page-hero-layout{display:grid;grid-template-columns:minmax(0,1.02fr) minmax(300px,.98fr);gap:clamp(24px,4vw,48px);align-items:center}.mpc-page-hero-content{max-width:720px}.eyebrow{margin:0 0 12px;text-transform:uppercase;letter-spacing:.16em;font-size:.78rem;font-weight:950;color:var(--mpc-gold)}.mpc-page-hero h1{margin:0;font-family:Georgia,"Times New Roman",serif;font-size:clamp(2.45rem,5.4vw,5.8rem);line-height:.96;letter-spacing:-.045em}.mpc-page-hero-content>p:not(.eyebrow){max-width:620px;margin:18px 0 0;color:#f4e9d4;font-size:clamp(1.05rem,2vw,1.22rem);font-weight:700}.hero-actions{display:flex;gap:12px;flex-wrap:wrap;align-items:center;margin-top:22px}.btn{display:inline-flex;align-items:center;justify-content:center;min-height:48px;border-radius:999px;padding:12px 22px;text-decoration:none;font-weight:950;border:1px solid transparent;line-height:1.1}.btn-gold{background:var(--mpc-gold);color:#181107}.btn-dark{background:#172014;color:#fff}.btn-outline{background:rgba(255,255,255,.1);color:#fff;border-color:rgba(255,255,255,.2)}.dark-text{color:#21160f;border-color:rgba(33,22,15,.18);background:#fff8eb}.ui52-hero-quick-links{display:flex;gap:8px;flex-wrap:wrap;margin-top:18px}.ui52-hero-quick-links a{text-decoration:none;border-radius:999px;padding:9px 12px;background:rgba(255,255,255,.11);border:1px solid rgba(255,255,255,.16);font-weight:850;font-size:.9rem;color:#fff}.ui48-page-hero-media{overflow:hidden;border-radius:28px;box-shadow:0 24px 80px rgba(0,0,0,.28);max-height:420px}.ui48-page-hero-img,.mpc-page-hero-img{width:100%;height:100%;min-height:280px;max-height:420px;object-fit:contain}.section{padding:clamp(42px,6vw,72px) 0}.alt-soft{background:#f4e5ca}.mpc-section-header{max-width:760px;margin:0 auto 24px;text-align:center}.mpc-section-header h2{margin:0;font-family:Georgia,"Times New Roman",serif;font-size:clamp(2rem,4vw,4rem);line-height:1}.mpc-section-header p:last-child{margin:12px auto 0;color:var(--mpc-muted);font-weight:750}.homepage-visual-action-grid,.listing-category-grid,.homepage-premium-home-grid,.homepage-department-grid{display:grid;gap:16px}.homepage-visual-action-grid{grid-template-columns:repeat(3,minmax(0,1fr))}.listing-category-grid{grid-template-columns:repeat(4,minmax(0,1fr))}.homepage-premium-home-grid{grid-template-columns:repeat(2,minmax(0,1fr))}.homepage-department-grid{grid-template-columns:repeat(3,minmax(0,1fr))}.homepage-visual-action-card,.listing-category-card,.homepage-premium-home-card,.homepage-department-card,.mpc-planning-card{display:block;text-decoration:none;border:1px solid rgba(42,29,16,.13);border-radius:26px;background:#fffaf1;color:var(--mpc-ink);overflow:hidden;box-shadow:0 14px 40px rgba(55,38,20,.08)}.homepage-visual-action-card,.listing-category-card,.mpc-planning-card{padding:18px}.homepage-visual-action-card h3,.listing-category-card h3,.homepage-department-card h3,.homepage-premium-home-card h3{margin:0 0 8px;font-family:Georgia,"Times New Roman",serif;font-size:clamp(1.35rem,2vw,2rem);line-height:1}.homepage-visual-action-card p,.homepage-department-card p,.homepage-premium-home-card p{color:var(--mpc-muted);font-weight:700}.homepage-department-image,.homepage-premium-home-image{position:relative;display:block;aspect-ratio:4/3;overflow:hidden}.homepage-department-image img,.homepage-premium-home-image img{width:100%;height:100%;object-fit:contain}.homepage-department-image span,.homepage-premium-home-image span{position:absolute;left:12px;top:12px;border-radius:999px;background:#f8e6bd;padding:6px 10px;font-weight:950;font-size:.78rem}.homepage-department-body,.homepage-premium-home-body{padding:18px}.ui48-section-image-frame{margin-top:24px;border-radius:28px;overflow:hidden;max-height:300px}.ui48-section-image-frame img{width:100%;height:100%;object-fit:contain}.site-footer{background:#120c08;color:#fff;padding:44px 0 90px}.site-footer a{color:#fff7df}@media(max-width:860px){.nav-links{display:none}.nav-wrap{min-height:64px}.ui48-page-hero-layout{grid-template-columns:1fr}.mpc-page-hero{padding:28px 0 34px}.mpc-page-hero h1{font-size:clamp(2.3rem,11vw,3.6rem)}.ui48-page-hero-media{max-height:260px}.ui48-page-hero-img,.mpc-page-hero-img{min-height:210px;max-height:260px}.hero-actions,.premium-menu-actions{display:grid;grid-template-columns:1fr}.btn{width:100%}.ui52-hero-quick-links{display:grid;grid-template-columns:repeat(2,minmax(0,1fr))}.homepage-visual-action-grid,.listing-category-grid,.homepage-premium-home-grid,.homepage-department-grid{grid-template-columns:1fr}.mpc-section-header{text-align:left;margin-left:0}.section{padding:36px 0}body{padding-bottom:0}}
`;

export const metadata: Metadata = {
  ...createPageMetadata({
    title: "Marloth Park Central | Stays, Safari Drives, Restaurants & Services Near Kruger",
    description:
      "Find Marloth Park accommodation, safari drives, restaurants, activities, local businesses and services near Kruger National Park.",
    path: "/",
  }),
  title: {
    default: "Marloth Park Central | Stays, Safari Drives, Restaurants & Services Near Kruger",
    template: "%s | Marloth Park Central",
  },
  applicationName: siteConfig.name,
  authors: [{ name: siteConfig.name }],
  creator: siteConfig.name,
  publisher: siteConfig.name,
  manifest: "/manifest.json",
  icons: {
    icon: [
      { url: "/favicon.ico" },
      { url: "/favicon-16x16.png", sizes: "16x16", type: "image/png" },
      { url: "/favicon-32x32.png", sizes: "32x32", type: "image/png" },
    ],
    apple: [{ url: "/apple-touch-icon.png", sizes: "180x180", type: "image/png" }],
    shortcut: "/favicon.ico",
  },
  formatDetection: { telephone: true, address: true, email: true },
};

export default async function RootLayout({ children }: { children: React.ReactNode }) {
  const nonce = (await headers()).get("x-nonce") || undefined;
  return (
    <html lang="en-ZA">
      <body data-mpc-analytics="next">
        <style nonce={nonce} dangerouslySetInnerHTML={{ __html: criticalLaunchCss }} />
        {IS_STAGING ? (
          <div className="mpc-staging-indicator" role="status">STAGING — NOT PRODUCTION · {BUILD_VERSION}</div>
        ) : null}
        <MpcAnalyticsTracker />
        <AdTracking nonce={nonce} />
        <JsonLd data={[websiteSchema(), tourismOrganizationSchema()]} />
        <Header />
        {children}
        <Footer />
      </body>
    </html>
  );
}
