// Icons + Nav + Hero
const { useEffect: useEffectNH, useRef: useRefNH, useState: useStateNH } = React;

/* ─────────────────────────────────────────────────────────────
   Inline SVG icons (lucide-style, stroke only)
   ───────────────────────────────────────────────────────────── */

const Icon = ({ d, size = 22, sw = 1.6 }) => (
  <svg width={size} height={size} viewBox="0 0 24 24" fill="none"
       stroke="currentColor" strokeWidth={sw} strokeLinecap="round" strokeLinejoin="round">
    {Array.isArray(d) ? d.map((p, i) => <path key={i} d={p} />) : <path d={d} />}
  </svg>
);

const Icons = {
  ArrowUpRight: () => <Icon d="M7 17 17 7 M8 7h9v9" />,
  ArrowRight:   () => <Icon d="M5 12h14 M13 6l6 6-6 6" />,
  Smile: () => (
    <svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round">
      <circle cx="12" cy="12" r="9" /><path d="M8 14s1.5 2 4 2 4-2 4-2" /><line x1="9" y1="9" x2="9.01" y2="9" /><line x1="15" y1="9" x2="15.01" y2="9" />
    </svg>
  ),
  Sparkles: () => (
    <svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round">
      <path d="M12 3v4 M12 17v4 M3 12h4 M17 12h4 M5.6 5.6l2.8 2.8 M15.6 15.6l2.8 2.8 M18.4 5.6l-2.8 2.8 M8.4 15.6l-2.8 2.8" />
    </svg>
  ),
  Scissors: () => (
    <svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round">
      <circle cx="6" cy="6" r="3" /><circle cx="6" cy="18" r="3" /><line x1="20" y1="4" x2="8.12" y2="15.88" /><line x1="14.47" y1="14.48" x2="20" y2="20" /><line x1="8.12" y1="8.12" x2="12" y2="12" />
    </svg>
  ),
  Footprints: () => (
    <svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round">
      <path d="M4 16v-2.38c0-2.7 .68-3.62 2-4.62v0c1.32-1 2-1.92 2-4.62V3 M4 16a2 2 0 1 0 4 0 v-2 M20 20v-2.38c0-2.7-.68-3.62-2-4.62 v0c-1.32-1-2-1.92-2-4.62V7 M20 20a2 2 0 1 1-4 0v-2" />
    </svg>
  ),
  Activity: () => (
    <svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round">
      <polyline points="22 12 18 12 15 21 9 3 6 12 2 12" />
    </svg>
  ),
  LinkedIn: () => (
    <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <path 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" />
      <rect x="2" y="9" width="4" height="12" /><circle cx="4" cy="4" r="2" />
    </svg>
  ),
  WhatsApp: () => (
    <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <path d="M3 21l1.65-3.8a9 9 0 1 1 3.4 3.5z" />
      <path d="M9 10c.5 1 1.5 2 3 3s2.5 1.5 3.5 1c.5 -.25 1 -.75 1 -1.5 -2-1-2-1-3-2 -.75 0 -1.25 .5-1.5 1" />
    </svg>
  ),
  Mail: () => (
    <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <rect x="2" y="4" width="20" height="16" rx="3" /><polyline points="2,7 12,13 22,7" />
    </svg>
  ),
  Clock: () => (
    <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <circle cx="12" cy="12" r="9" /><polyline points="12,7 12,12 15,14" />
    </svg>
  ),
  Calendar: () => (
    <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <rect x="3" y="5" width="18" height="16" rx="3" /><line x1="3" y1="10" x2="21" y2="10" /><line x1="8" y1="3" x2="8" y2="7" /><line x1="16" y1="3" x2="16" y2="7" />
    </svg>
  ),
  Video: () => (
    <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <polygon points="22 8 16 12 22 16" /><rect x="2" y="6" width="14" height="12" rx="2" />
    </svg>
  ),
};

/* ─────────────────────────────────────────────────────────────
   JuicyButton
   ───────────────────────────────────────────────────────────── */

function JuicyButton({ children, variant = "primary", wide, href, onClick, type }) {
  const cls = "juicy" + (variant === "ghost" ? " ghost" : "") + (wide ? " wide" : "");
  const inner = (
    <React.Fragment>
      <span>{children}</span>
      <span className="arrow"><Icons.ArrowUpRight /></span>
    </React.Fragment>
  );
  if (href) {
    return <a className={cls} href={href} data-magnetic onClick={onClick}>{inner}</a>;
  }
  return <button className={cls} type={type || "button"} onClick={onClick} data-magnetic>{inner}</button>;
}

/* ─────────────────────────────────────────────────────────────
   Nav
   ───────────────────────────────────────────────────────────── */

function Nav() {
  const [scrolled, setScrolled] = useStateNH(false);
  useEffectNH(() => {
    const onScroll = () => setScrolled(window.scrollY > 80);
    window.addEventListener("scroll", onScroll, { passive: true });
    onScroll();
    return () => window.removeEventListener("scroll", onScroll);
  }, []);

  return (
    <nav className={"nav" + (scrolled ? " scrolled" : "")}>
      <a className="nav-logo" href="#top" data-magnetic>
        <img src="images/logo-mark.png" alt="" className="nav-mark" />
        Kinetix
      </a>
      <ul className="nav-links">
        <li><a href="#servicios" data-magnetic>Servicios</a></li>
        <li><a href="#sectores" data-magnetic>Sectores</a></li>
        <li><a href="#proceso"  data-magnetic>Proceso</a></li>
        <li><a href="#fundador" data-magnetic>Fundador</a></li>
        <li><a href="#contacto" data-magnetic>Contacto</a></li>
      </ul>
      <JuicyButton href="#contacto">Reservar auditoría</JuicyButton>
    </nav>
  );
}

/* ─────────────────────────────────────────────────────────────
   Hero
   ───────────────────────────────────────────────────────────── */

function HeroDiamond() {
  // Replaced CSS blob with the real chrome reference render.
  return (
    <div className="hero-visual" aria-hidden="true">
      <div className="chrome-piece chrome-piece--hero">
        <img src="images/chrome-bubble.png" alt="" />
        <div className="chrome-piece__glow" />
      </div>
    </div>
  );
}

function Hero() {
  return (
    <header className="hero" id="top">
      <div className="shell hero-shell">
        <div className="hero-text reveal">
          <span className="eyebrow">IA · CLÍNICAS PRIVADAS · ESPAÑA</span>
          <h1>
            La IA ya está atendiendo a los pacientes de{" "}
            <span className="metal">tu competencia.</span>{" "}
            <span className="serif soft">¿Y los tuyos?</span>
          </h1>
          <p className="sub">
            En 4 semanas tu clínica está cogiendo cada llamada, recuperando
            no-shows y reservando tratamientos a las 23:00.{" "}
            <strong>Sin que tu equipo toque nada técnico.</strong>
          </p>
          <div className="hero-ctas">
            <JuicyButton href="#contacto">Solicitar auditoría</JuicyButton>
            <JuicyButton href="#proceso" variant="ghost">Ver cómo trabajamos</JuicyButton>
          </div>
          <div className="hero-micro">
            <span>Auditoría a medida</span>
            <span>Se descuenta si contratas</span>
            <span>Datos 100% RGPD/LOPDGDD</span>
          </div>
        </div>
      </div>
    </header>
  );
}

Object.assign(window, { Icons, JuicyButton, Nav, Hero });
