/* ============================================
   Yurt on Wheels — Shared components, icons, router
   ============================================ */

const { useState, useEffect, useMemo, useRef, useCallback } = React;

// ---------- Icons (small SVG sprites) ----------
const Icon = {
  Globe: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <circle cx="12" cy="12" r="9"/>
      <path d="M3 12h18M12 3c2.5 3 2.5 15 0 18M12 3c-2.5 3-2.5 15 0 18"/>
    </svg>
  ),
  Menu: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" {...p}>
      <path d="M4 7h16M4 12h16M4 17h16"/>
    </svg>
  ),
  Close: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" {...p}>
      <path d="M6 6l12 12M18 6L6 18"/>
    </svg>
  ),
  Chevron: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M6 9l6 6 6-6"/>
    </svg>
  ),
  ArrowRight: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M5 12h14M13 6l6 6-6 6"/>
    </svg>
  ),
  ArrowLeft: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M19 12H5M11 6l-6 6 6 6"/>
    </svg>
  ),
  Heart: (p) => (
    <svg viewBox="0 0 24 24" fill="currentColor" {...p}>
      <path d="M12 21s-7-4.35-9.33-8.74A5.5 5.5 0 0 1 12 6a5.5 5.5 0 0 1 9.33 6.26C19 16.65 12 21 12 21z" opacity=".15" stroke="white" strokeWidth="0" />
      <path d="M12 21s-7-4.35-9.33-8.74A5.5 5.5 0 0 1 12 6a5.5 5.5 0 0 1 9.33 6.26C19 16.65 12 21 12 21z" fill="none" stroke="currentColor" strokeWidth="1.8" />
    </svg>
  ),
  HeartFill: (p) => (
    <svg viewBox="0 0 24 24" fill="currentColor" {...p}>
      <path d="M12 21s-7-4.35-9.33-8.74A5.5 5.5 0 0 1 12 6a5.5 5.5 0 0 1 9.33 6.26C19 16.65 12 21 12 21z" />
    </svg>
  ),
  Mountain: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinejoin="round" strokeLinecap="round" {...p}>
      <path d="M3 19l5-9 4 6 3-4 6 7H3z"/>
      <circle cx="17" cy="6" r="1.5"/>
    </svg>
  ),
  Clock: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" {...p}>
      <circle cx="12" cy="12" r="9"/>
      <path d="M12 7v5l3 2"/>
    </svg>
  ),
  Calendar: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" {...p}>
      <rect x="3" y="5" width="18" height="16" rx="2"/>
      <path d="M3 9h18M8 3v4M16 3v4"/>
    </svg>
  ),
  Users: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <circle cx="9" cy="8" r="3.5"/>
      <path d="M2 20c.7-3.5 3.7-5 7-5s6.3 1.5 7 5"/>
      <circle cx="17" cy="7" r="2.5"/>
      <path d="M16 14c2.5 0 5 1 5.5 4"/>
    </svg>
  ),
  Truck: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M3 15V6h10v9M13 9h5l3 4v2h-3"/>
      <circle cx="7" cy="17" r="2"/><circle cx="17" cy="17" r="2"/>
    </svg>
  ),
  Plate: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" {...p}>
      <circle cx="12" cy="12" r="9"/><circle cx="12" cy="12" r="4"/>
    </svg>
  ),
  Shield: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinejoin="round" strokeLinecap="round" {...p}>
      <path d="M12 3l8 3v6c0 5-3.5 8-8 9-4.5-1-8-4-8-9V6l8-3z"/>
      <path d="M9 12l2 2 4-4"/>
    </svg>
  ),
  Yurt: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinejoin="round" strokeLinecap="round" {...p}>
      <path d="M3 19h18M5 19V11l7-5 7 5v8"/>
      <path d="M10 19v-5h4v5"/>
      <path d="M12 6L8 11h8L12 6z"/>
    </svg>
  ),
  Compass: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinejoin="round" strokeLinecap="round" {...p}>
      <circle cx="12" cy="12" r="9"/>
      <path d="M15 9l-2 5-4 1 2-5 4-1z"/>
    </svg>
  ),
  Camera: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <rect x="3" y="6" width="18" height="14" rx="2"/>
      <circle cx="12" cy="13" r="4"/>
      <path d="M8 6l1.5-2h5L16 6"/>
    </svg>
  ),
  Check: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M5 12l4 4 10-10"/>
    </svg>
  ),
  X: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" {...p}>
      <path d="M6 6l12 12M18 6L6 18"/>
    </svg>
  ),
  WhatsApp: (p) => (
    <svg viewBox="0 0 24 24" fill="currentColor" {...p}>
      <path d="M17.5 14.4c-.3-.1-1.7-.8-1.9-.9-.3-.1-.5-.1-.7.1-.2.3-.8.9-1 1.1-.2.2-.4.2-.7.1-.3-.1-1.2-.4-2.3-1.4-.9-.8-1.4-1.7-1.6-2-.2-.3 0-.5.1-.6.1-.1.3-.3.4-.5.1-.2.2-.3.3-.5.1-.2 0-.4 0-.5 0-.1-.7-1.7-1-2.3-.3-.7-.5-.6-.7-.6h-.6c-.2 0-.5.1-.8.4s-1 1-1 2.4 1.1 2.8 1.2 3c.1.2 2.1 3.2 5.1 4.5.7.3 1.3.5 1.7.6.7.2 1.3.2 1.8.1.5-.1 1.7-.7 1.9-1.4.2-.7.2-1.3.2-1.4-.1-.1-.3-.2-.6-.3zM12 2C6.5 2 2 6.5 2 12c0 1.7.4 3.3 1.2 4.7L2 22l5.4-1.2c1.4.7 2.9 1.2 4.6 1.2 5.5 0 10-4.5 10-10S17.5 2 12 2z"/>
    </svg>
  ),
  Mail: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <rect x="3" y="5" width="18" height="14" rx="2"/>
      <path d="M3 7l9 6 9-6"/>
    </svg>
  ),
  Phone: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M5 4h3l2 5-2 1c1 2.5 2.5 4 5 5l1-2 5 2v3a2 2 0 01-2 2A14 14 0 015 6a2 2 0 012-2z"/>
    </svg>
  ),
  Instagram: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" {...p}>
      <rect x="3" y="3" width="18" height="18" rx="5"/>
      <circle cx="12" cy="12" r="4"/>
      <circle cx="17.5" cy="6.5" r="1" fill="currentColor"/>
    </svg>
  ),
  MapPin: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M12 22s7-6 7-12a7 7 0 10-14 0c0 6 7 12 7 12z"/>
      <circle cx="12" cy="10" r="2.5"/>
    </svg>
  ),
  Search: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" {...p}>
      <circle cx="11" cy="11" r="6"/>
      <path d="M16 16l5 5"/>
    </svg>
  ),
  Sparkle: (p) => (
    <svg viewBox="0 0 24 24" fill="currentColor" {...p}>
      <path d="M12 2l1.6 6.4L20 10l-6.4 1.6L12 18l-1.6-6.4L4 10l6.4-1.6L12 2z"/>
    </svg>
  ),
  Star: (p) => (
    <svg viewBox="0 0 24 24" fill="currentColor" {...p}>
      <path d="M12 3l2.7 5.7 6.3.6-4.7 4.3 1.4 6.2L12 16.9 6.3 19.8l1.4-6.2L3 9.3l6.3-.6L12 3z"/>
    </svg>
  ),
  Leaf: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M5 19c0-7 5-12 14-13-.5 8-5 14-13 14l-1-1z"/>
      <path d="M5 19l9-9"/>
    </svg>
  ),
};

// ---------- Hash router ----------
// Routes look like: #/<lang>/<page>/[slug]
function parseHash() {
  const raw = (window.location.hash || "#/en").replace(/^#\/?/, "");
  const parts = raw.split("?")[0].split("/").filter(Boolean);
  const lang = (window.YOW_LANGS || ["en"]).includes(parts[0]) ? parts[0] : (window.YOW_DEFAULT_LANG || "en");
  const page = parts[1] || "home";
  const slug = parts[2] || null;
  return { lang, page, slug, raw };
}

function navigate(lang, page, slug) {
  let p = `#/${lang}`;
  if (page && page !== "home") p += `/${page}`;
  if (slug) p += `/${slug}`;
  if (window.location.hash !== p) {
    window.location.hash = p;
  }
}

function useRouter() {
  const [route, setRoute] = useState(parseHash());
  useEffect(() => {
    const onHash = () => {
      setRoute(parseHash());
      // smooth scroll-to-top on route change
      window.scrollTo({ top: 0, behavior: "auto" });
    };
    window.addEventListener("hashchange", onHash);
    return () => window.removeEventListener("hashchange", onHash);
  }, []);
  return route;
}

// ---------- i18n hook ----------
function useT(lang) {
  return useMemo(() => window.YOW_I18N[lang] || window.YOW_I18N.en, [lang]);
}

// ---------- Tour helpers ----------
function buildTimelineLabel(t, step) {
  const L = window.YOW_LOCATIONS;
  const loc = step.loc ? L[step.loc] : null;
  const locName = loc?.name || "";
  switch (step.action) {
    case "depart":      return loc ? `${t.tl.depart}: ${locName}` : t.tl.depart;
    case "departCity":  return t.tl.departCity;
    case "arrive":      return loc ? `${t.tl.arrive} ${locName}` : t.tl.arrive;
    case "lunch":
    case "lunchAt":     return loc ? `${t.tl.lunchAt} ${locName}` : t.tl.lunch;
    case "dinner":
    case "dinnerAt":    return loc ? `${t.tl.dinnerAt} ${locName}` : t.tl.dinner;
    case "breakfast":   return t.tl.breakfast;
    case "overnight":   return loc ? `${t.tl.overnight}: ${locName}` : t.tl.overnight;
    case "returnCity":  return t.tl.returnCity;
    case "arriveCity":  return t.tl.arriveCity;
    case "visit":       return loc ? `${t.tl.visit}: ${locName}` : t.tl.visit;
    case "tea":         return t.tl.tea;
    default:            return locName || "";
  }
}
function isStopStep(step) {
  return ["arrive", "visit", "lunch", "lunchAt", "dinner", "dinnerAt", "overnight"].includes(step.action);
}

function formatPriceKZT(n, locale) {
  if (locale === "ru" || locale === "kz") {
    return n.toLocaleString("ru-RU").replace(/,/g, " ") + " ₸";
  }
  return n.toLocaleString("en-US") + " ₸";
}

// ---------- Generic primitives ----------
function PhotoPlaceholder({ locId, label, sub, aspect, tone, icon, className = "" }) {
  const L = window.YOW_LOCATIONS;
  const loc = locId ? L[locId] : null;
  const lbl = label || loc?.name || "Photo";
  const subLine = sub || loc?.blurb || "Mangystau · Photo placeholder";
  const _tone = tone || loc?.tone || "warm";
  const IconC = icon || Icon.Camera;
  return (
    <div className={`photo-ph ${className}`} data-aspect={aspect || "3-2"} data-tone={_tone}>
      <div className="ph-grid"></div>
      <div className="ph-content">
        <IconC className="ph-icon"/>
        <div className="ph-loc">{lbl}</div>
        <div className="ph-sub">{subLine}</div>
      </div>
    </div>
  );
}

// ---------- Hero "yurt-light" illustration ----------
function YurtLightHero({ caption }) {
  return (
    <div className="hero-illus">
      <svg viewBox="0 0 600 750" preserveAspectRatio="xMidYMid slice" xmlns="http://www.w3.org/2000/svg">
        <defs>
          <linearGradient id="sky" x1="0" y1="0" x2="0" y2="1">
            <stop offset="0%"  stopColor="#0c0a0e"/>
            <stop offset="55%" stopColor="#1a1410"/>
            <stop offset="100%" stopColor="#2a1f15"/>
          </linearGradient>
          <radialGradient id="glow" cx="50%" cy="50%" r="50%">
            <stop offset="0%"  stopColor="#FFE9C7" stopOpacity="0.95"/>
            <stop offset="30%" stopColor="#E5B473" stopOpacity="0.55"/>
            <stop offset="70%" stopColor="#9B6E3E" stopOpacity="0.15"/>
            <stop offset="100%" stopColor="#E5B473" stopOpacity="0"/>
          </radialGradient>
          <radialGradient id="windowGlow" cx="50%" cy="50%" r="50%">
            <stop offset="0%" stopColor="#FFE2B4" stopOpacity="1"/>
            <stop offset="100%" stopColor="#FFE2B4" stopOpacity="0"/>
          </radialGradient>
          <linearGradient id="cliff" x1="0" y1="0" x2="0" y2="1">
            <stop offset="0%" stopColor="#3a2a1c"/>
            <stop offset="100%" stopColor="#1a120a"/>
          </linearGradient>
        </defs>

        {/* sky */}
        <rect x="0" y="0" width="600" height="750" fill="url(#sky)"/>

        {/* stars */}
        {[
          [40, 80], [110, 50], [180, 120], [250, 70], [320, 140], [400, 60], [480, 110], [560, 80],
          [70, 200], [150, 230], [300, 210], [430, 250], [540, 220],
          [30, 320], [220, 300], [380, 330], [510, 360],
        ].map(([x, y], i) => (
          <circle key={i} cx={x} cy={y} r={i % 4 === 0 ? 1.6 : 1} fill="#f6e9d2" opacity={0.5 + (i % 5) * 0.08}/>
        ))}

        {/* far cliffs */}
        <path d="M0,560 L80,500 L140,520 L200,475 L260,505 L330,470 L400,495 L470,465 L540,480 L600,455 L600,620 L0,620 Z"
              fill="#2a1f15" opacity="0.95"/>

        {/* mid cliffs */}
        <path d="M0,610 L70,575 L150,590 L210,560 L280,580 L360,555 L440,575 L520,560 L600,585 L600,720 L0,720 Z"
              fill="url(#cliff)"/>

        {/* warm glow around yurt */}
        <ellipse cx="300" cy="608" rx="220" ry="120" fill="url(#glow)"/>

        {/* yurt silhouette */}
        <g transform="translate(260,565)">
          {/* base ring */}
          <rect x="0" y="22" width="80" height="38" rx="3" fill="#1a120a"/>
          {/* roof */}
          <path d="M0,22 L40,-6 L80,22 Z" fill="#0e0a06"/>
          {/* tent ribs */}
          <path d="M0,22 L40,-6 M20,22 L40,-6 M60,22 L40,-6 M80,22 L40,-6" stroke="#2a1f15" strokeWidth="1"/>
          {/* tunduk */}
          <circle cx="40" cy="-6" r="3" fill="#E5B473"/>
          {/* glowing door window */}
          <ellipse cx="40" cy="42" rx="28" ry="18" fill="url(#windowGlow)"/>
          <rect x="32" y="32" width="16" height="22" rx="2" fill="#E5B473"/>
          <rect x="34.5" y="34" width="11" height="18" rx="1.5" fill="#FFE2B4"/>
        </g>

        {/* tiny tea steam */}
        <g opacity="0.5" stroke="#f6e9d2" strokeWidth="1" fill="none" strokeLinecap="round">
          <path d="M355,585 q3,-8 0,-16 q-3,-8 0,-16"/>
          <path d="M362,592 q3,-6 0,-12 q-3,-6 0,-12"/>
        </g>

        {/* foreground horizon dust line */}
        <rect x="0" y="715" width="600" height="35" fill="#1a120a"/>
      </svg>
      <div className="caption"><span className="dot"></span>{caption}</div>
    </div>
  );
}

// ---------- Header ----------
function Header({ route, t, openMenu, openLang, langMenuOpen }) {
  const isActive = (page) => route.page === page;
  return (
    <header className="topnav">
      <div className="container topnav-inner">
        <a href={`#/${route.lang}`} className="topnav-logo" aria-label="Yurt on Wheels">
          <Logo/>
        </a>
        <nav className="topnav-links">
          <a href={`#/${route.lang}`} className={`topnav-link ${isActive("home") ? "is-active" : ""}`}>{t.nav.home}</a>
          <a href={`#/${route.lang}/tours`} className={`topnav-link ${isActive("tours") ? "is-active" : ""}`}>{t.nav.tours}</a>
          <a href={`#/${route.lang}/private-custom-tours`} className={`topnav-link ${isActive("private-custom-tours") ? "is-active" : ""}`}>{t.nav.private}</a>
          <a href={`#/${route.lang}/nature`} className={`topnav-link ${isActive("nature") ? "is-active" : ""}`}>{t.nav.nature}</a>
          <a href={`#/${route.lang}/safety-insurance`} className={`topnav-link ${isActive("safety-insurance") ? "is-active" : ""}`}>{t.nav.safety}</a>
          <a href={`#/${route.lang}/contact`} className={`topnav-link ${isActive("contact") ? "is-active" : ""}`}>{t.nav.contact}</a>
        </nav>
        <div className="topnav-right">
          <LanguageSwitcher route={route} t={t} open={langMenuOpen} onOpen={openLang}/>
          <button className="icon-btn menu-btn" aria-label="Menu" onClick={openMenu}>
            <Icon.Menu width="18" height="18"/>
          </button>
        </div>
      </div>
    </header>
  );
}

function Logo({ height = 28 }) {
  // Real brand logo (wordmark + yurt mark). Native gold #E6B574 on transparent.
  return (
    <img
      src="assets/logo-wordmark.svg"
      alt="Yurt on Wheels"
      style={{
        height,
        width: "auto",
        display: "block",
      }}
    />
  );
}

// ---------- Language switcher ----------
function LanguageSwitcher({ route, t, open, onOpen }) {
  const wrapRef = useRef(null);
  useEffect(() => {
    if (!open) return;
    function onClickOutside(e) {
      if (wrapRef.current && !wrapRef.current.contains(e.target)) onOpen(false);
    }
    document.addEventListener("mousedown", onClickOutside);
    return () => document.removeEventListener("mousedown", onClickOutside);
  }, [open, onOpen]);

  const langs = window.YOW_LANGS;
  return (
    <div className="lang-wrap" ref={wrapRef}>
      <button className="lang-pill" onClick={() => onOpen(!open)} aria-label="Language">
        <Icon.Globe/>
        <span>{(window.YOW_I18N[route.lang] || {}).nameLocal}</span>
      </button>
      {open && (
        <div className="lang-menu" role="menu">
          {langs.map(lc => {
            const info = window.YOW_I18N[lc];
            return (
              <button
                key={lc}
                className={`lang-menu-item ${route.lang === lc ? "is-active" : ""}`}
                role="menuitem"
                onClick={() => {
                  navigate(lc, route.page, route.slug);
                  onOpen(false);
                }}
              >
                <span>{info.nameLocal}</span>
                <span className="meta">{info.name}</span>
              </button>
            );
          })}
        </div>
      )}
    </div>
  );
}

// ---------- Mobile drawer menu ----------
function MobileDrawer({ open, onClose, t, route }) {
  return (
    <React.Fragment>
      <div className={`drawer-scrim ${open ? "is-open" : ""}`} onClick={onClose}/>
      <aside className={`drawer ${open ? "is-open" : ""}`} aria-hidden={!open}>
        <div className="drawer-head">
          <Logo/>
          <button className="icon-btn" onClick={onClose} aria-label="Close">
            <Icon.Close width="16" height="16"/>
          </button>
        </div>
        <div className="drawer-body">
          <a href={`#/${route.lang}`} onClick={onClose} className={`drawer-link ${route.page === "home" ? "is-active" : ""}`}>{t.nav.home}</a>
          <a href={`#/${route.lang}/tours`} onClick={onClose} className={`drawer-link ${route.page === "tours" ? "is-active" : ""}`}>{t.nav.tours}</a>
          <a href={`#/${route.lang}/private-custom-tours`} onClick={onClose} className={`drawer-link ${route.page === "private-custom-tours" ? "is-active" : ""}`}>{t.nav.private}</a>
          <a href={`#/${route.lang}/nature`} onClick={onClose} className={`drawer-link ${route.page === "nature" ? "is-active" : ""}`}>{t.nav.nature}</a>
          <a href={`#/${route.lang}/safety-insurance`} onClick={onClose} className={`drawer-link ${route.page === "safety-insurance" ? "is-active" : ""}`}>{t.nav.safety}</a>
          <a href={`#/${route.lang}/contact`} onClick={onClose} className={`drawer-link ${route.page === "contact" ? "is-active" : ""}`}>{t.nav.contact}</a>

          <div className="drawer-section-label">{t.footer.lang_h}</div>
          <div style={{ display: "flex", gap: 8, flexWrap: "wrap" }}>
            {window.YOW_LANGS.map(lc => (
              <button
                key={lc}
                className={`chip ${route.lang === lc ? "is-active" : ""}`}
                onClick={() => { navigate(lc, route.page, route.slug); onClose(); }}
              >
                {window.YOW_I18N[lc].nameLocal}
              </button>
            ))}
          </div>

          <div className="drawer-section-label">{t.cta.contactUs}</div>
          <a className="btn btn-primary" href="https://wa.me/77775102211" target="_blank" rel="noreferrer" style={{ width: "100%" }}>
            <Icon.WhatsApp width="18" height="18"/> {t.cta.bookWhatsApp}
          </a>
        </div>
      </aside>
    </React.Fragment>
  );
}

// ---------- Footer ----------
function Footer({ t, route }) {
  return (
    <footer className="site-footer">
      <div className="container">
        <div className="footer-grid">
          <div>
            <Logo/>
            <p className="t-body-sm t-muted" style={{ marginTop: 12, maxWidth: 280 }}>
              {t.footer.tagline}
            </p>
            <div className="yurt-strip">
              <span className="yurt-ico"><Icon.Yurt width="18" height="18" color="#3a2a14"/></span>
              <span>{t.footer.yurt_strip}</span>
            </div>
          </div>
          <div>
            <h4>{t.footer.explore_h}</h4>
            <ul>
              <li><a href={`#/${route.lang}/tours`}>{t.nav.tours}</a></li>
              <li><a href={`#/${route.lang}/tours/2-location-tour`}>{t.tours["2-location-tour"].title}</a></li>
              <li><a href={`#/${route.lang}/tours/combo-tour`}>{t.tours["combo-tour"].title}</a></li>
              <li><a href={`#/${route.lang}/tours/1-day-jeep-tour`}>{t.tours["1-day-jeep-tour"].title}</a></li>
              <li><a href={`#/${route.lang}/private-custom-tours`}>{t.nav.private}</a></li>
            </ul>
          </div>
          <div>
            <h4>{t.footer.support_h}</h4>
            <ul>
              <li><a href={`#/${route.lang}/safety-insurance`}>{t.nav.safety}</a></li>
              <li><a href={`#/${route.lang}/nature`}>{t.nav.nature}</a></li>
              <li><a href={`#/${route.lang}/contact`}>{t.nav.contact}</a></li>
            </ul>
          </div>
          <div>
            <h4>{t.footer.contact_h}</h4>
            <ul>
              <li><a href="https://wa.me/77775102211" target="_blank" rel="noreferrer">WhatsApp · +7 777 510 22 11</a></li>
              <li><a href="mailto:yurtonwheels.kz@gmail.com">yurtonwheels.kz@gmail.com</a></li>
              <li><a href="tel:+77775102211">+7 777 510 22 11</a></li>
              <li><a href="https://instagram.com/yurtonwheels.kz" target="_blank" rel="noreferrer">Instagram · @yurtonwheels.kz</a></li>
            </ul>
          </div>
        </div>
        <div className="legal-band">
          <div>{t.footer.legal}</div>
          <div className="socials">
            <a href="https://wa.me/77775102211" aria-label="WhatsApp"><Icon.WhatsApp width="16" height="16"/></a>
            <a href="https://instagram.com/yurtonwheels.kz" aria-label="Instagram"><Icon.Instagram width="16" height="16"/></a>
            <a href="mailto:yurtonwheels.kz@gmail.com" aria-label="Email"><Icon.Mail width="16" height="16"/></a>
          </div>
        </div>
      </div>
    </footer>
  );
}

// ---------- Photo carousel ----------
function PhotoCarousel({ locIds }) {
  const [idx, setIdx] = useState(0);
  const n = locIds.length;
  const prev = () => setIdx((i) => (i - 1 + n) % n);
  const next = () => setIdx((i) => (i + 1) % n);
  return (
    <div className="carousel">
      <div className="carousel-mask">
        <div className="carousel-track" style={{ "--n": n, "--idx": idx }}>
          {locIds.map((id, i) => (
            <PhotoPlaceholder key={i} locId={id} aspect="3-2"/>
          ))}
        </div>
      </div>
      {n > 1 && (
        <React.Fragment>
          <button className="carousel-arrow prev" onClick={prev} aria-label="Previous">
            <Icon.ArrowLeft width="16" height="16"/>
          </button>
          <button className="carousel-arrow next" onClick={next} aria-label="Next">
            <Icon.ArrowRight width="16" height="16"/>
          </button>
          <div className="carousel-dots">
            {locIds.map((_, i) => (
              <button
                key={i}
                className={`dot ${i === idx ? "is-active" : ""}`}
                onClick={() => setIdx(i)}
                aria-label={`Slide ${i + 1}`}
              />
            ))}
          </div>
        </React.Fragment>
      )}
    </div>
  );
}

// Expose
Object.assign(window, {
  Icon, useT, useRouter, navigate, parseHash,
  PhotoPlaceholder, YurtLightHero, Header, Footer, MobileDrawer, LanguageSwitcher, Logo, PhotoCarousel,
  buildTimelineLabel, isStopStep, formatPriceKZT,
});
