/* ============================================================
   m3-cargo — Chrome del sitio público (React, global)
   Exporta a window: SiteIcon, SiteNav, SiteFooter, SITE (datos)
   Requiere: React, shared/logic.js (M3)
   ============================================================ */
(function (g) {
  const { useState } = React;

  /* ---- Datos de la empresa (inventados / placeholder editables) ---- */
  const SITE = {
    email: "contacto@m3cargo.cl",
    ventas: "ventas@m3cargo.cl",
    soporte: "soporte@m3cargo.cl",
    waDisplay: "+56 9 7768 2189",
    waLink: "https://wa.me/56977682189",
    phone: "+56 2 2938 4180",
    address: "Av. Apoquindo 6410, Of. 212",
    comuna: "Las Condes, Santiago",
    hours: "Lun a Vie · 9:00–18:00 hrs",
    rut: "78.503.856-8",
    razon: "M3 CARGO & LOGÍSTICA SpA",
    founded: 2021,
    instagram: "https://instagram.com/m3cargo",
    linkedin: "https://linkedin.com/company/m3-cargo",
  };

  function SiteIcon({ d, s = 20, c = "currentColor", sw = 2, fill = "none" }) {
    return React.createElement("svg", { width: s, height: s, viewBox: "0 0 24 24", fill, stroke: c, strokeWidth: sw, strokeLinecap: "round", strokeLinejoin: "round" },
      Array.isArray(d) ? d.map((p, i) => React.createElement("path", { key: i, d: p })) : React.createElement("path", { d }));
  }

  function Brand({ onDark, size }) {
    return React.createElement("span", {
      dangerouslySetInnerHTML: { __html: M3.isotipo(size || 30) + M3.wordmark({ onDark, size: (size || 30) * 0.62 }) },
      style: { display: "inline-flex", alignItems: "center", gap: 10 }
    });
  }

  /* Links del sitio. `active` = clave de la página actual. `prefix` para subcarpetas. */
  const NAV_LINKS = [
    { key: "blog", label: "Blog", href: "blog.html" },
    { key: "nosotros", label: "Nosotros", href: "nosotros.html" },
    { key: "contacto", label: "Contacto", href: "contacto.html" },
    { key: "rastrear", label: "Rastrear envío", href: "tracker.html" },
  ];

  function SiteNav({ active, theme = "light", prefix = "" }) {
    const [open, setOpen] = useState(false);
    const onDark = theme === "dark";
    const q = (h) => prefix + h;
    const linkEls = NAV_LINKS.map(l =>
      React.createElement("a", { key: l.key, className: "link" + (active === l.key ? " active" : ""), href: q(l.href) }, l.label)
    );
    const ingresar = React.createElement("a", { key: "ingresar", href: q("portal.html"), className: "btn btn-sm" + (onDark ? " btn-ghost-dark" : " btn-ghost") }, "Ingresar");
    const cta = React.createElement("a", { href: q("web.html#cotizador"), className: "btn btn-accent btn-sm" }, "Cotizar ahora");
    return React.createElement("nav", { className: "snav " + (onDark ? "on-dark" : "on-light") + (open ? " open" : "") },
      React.createElement("div", { className: "snav-in" },
        React.createElement("a", { className: "snav-brand", href: q("web.html"), "aria-label": "m3-cargo · inicio" }, React.createElement(Brand, { onDark, size: 30 })),
        React.createElement("div", { className: "snav-links" }, ...linkEls, ingresar, cta),
        React.createElement("button", { className: "snav-burger", "aria-label": "Menú", onClick: () => setOpen(o => !o) },
          React.createElement(SiteIcon, { d: open ? "M18 6 6 18M6 6l12 12" : "M3 12h18M3 6h18M3 18h18", s: 24, c: onDark ? "#fff" : "var(--ink)" }))
      ),
      React.createElement("div", { className: "snav-mobile" }, ...linkEls, ingresar, cta)
    );
  }

  const FOOT_COLS = [
    { h: "Producto", items: [["Cotizador", "web.html#cotizador"], ["Cómo funciona", "web.html#como"], ["Rastrear envío", "tracker.html"], ["Portal cliente", "portal.html"]] },
    { h: "Recursos", items: [["Blog y guías", "blog.html"], ["Preguntas frecuentes", "web.html#faq"], ["Importar seguro", "article.html?slug=importar-seguro"], ["Buscar proveedores", "article.html?slug=buscar-proveedores"]] },
    { h: "Empresa", items: [["Nosotros", "nosotros.html"], ["Contacto", "contacto.html"], ["WhatsApp", SITE.waLink]] },
    { h: "Legal", items: [["Términos", "terminos.html"], ["Privacidad", "privacidad.html"], ["Aduana · SNA", "https://www.aduana.cl"]] },
  ];

  function SiteFooter({ prefix = "" }) {
    const q = (h) => (h.startsWith("http") ? h : prefix + h);
    return React.createElement("footer", { className: "sfoot" },
      React.createElement("div", { className: "wrap" },
        React.createElement("div", { className: "sfoot-top" },
          React.createElement("div", { style: { maxWidth: 300 } },
            React.createElement(Brand, { onDark: true, size: 30 }),
            React.createElement("p", { style: { marginTop: 14, fontSize: 13.5, lineHeight: 1.6 } },
              "Importa desde China con transparencia total: cotización instantánea, impuestos calculados y tu carga visible en cada paso. Con personas de verdad cuando las necesitas."),
            React.createElement("div", { style: { display: "flex", gap: 10, marginTop: 18 } },
              React.createElement("a", { href: SITE.instagram, "aria-label": "Instagram", target: "_blank", rel: "noopener", style: { color: "rgba(255,255,255,.6)" } }, React.createElement(SiteIcon, { d: ["M16 11.37A4 4 0 1 1 12.63 8 4 4 0 0 1 16 11.37z", "M17.5 6.5h.01M7 2h10a5 5 0 0 1 5 5v10a5 5 0 0 1-5 5H7a5 5 0 0 1-5-5V7a5 5 0 0 1 5-5z"], s: 19 })),
              React.createElement("a", { href: SITE.linkedin, "aria-label": "LinkedIn", target: "_blank", rel: "noopener", style: { color: "rgba(255,255,255,.6)" } }, React.createElement(SiteIcon, { d: ["M16 8a6 6 0 0 1 6 6v7h-4v-7a2 2 0 0 0-4 0v7h-4v-7a6 6 0 0 1 6-6z", "M2 9h4v12H2zM4 2a2 2 0 1 1 0 4 2 2 0 0 1 0-4z"], s: 19 }))
            )
          ),
          React.createElement("div", { className: "sfoot-cols" },
            FOOT_COLS.map(col => React.createElement("div", { key: col.h, className: "sfoot-col" },
              React.createElement("div", { className: "sfoot-col-h" }, col.h),
              col.items.map(([label, href]) => React.createElement("a", {
                key: label, href: q(href),
                target: href.startsWith("http") ? "_blank" : undefined,
                rel: href.startsWith("http") ? "noopener" : undefined
              }, label))
            ))
          )
        ),
        React.createElement("div", { className: "sfoot-bottom" },
          React.createElement("span", null, "© " + new Date().getFullYear() + " " + SITE.razon + " · RUT " + SITE.rut + " · Santiago, Chile"),
          React.createElement("span", { className: "mono" }, "Precios referenciales en USD · TC del día " + M3.USD_CLP + " CLP")
        )
      )
    );
  }

  Object.assign(g, { SITE, SiteIcon, SiteNav, SiteFooter, SiteBrand: Brand });
})(window);
