/* global React */
const { useEffect, useRef, useState } = React;

// ──────────────────────────────────────────────────────────
// Small shared UI bits
// ──────────────────────────────────────────────────────────

function Reveal({ children, delay = 0, as: Tag = "div", className = "", ...rest }) {
  const ref = useRef(null);
  const [shown, setShown] = useState(false);
  useEffect(() => {
    if (!ref.current) return;
    const obs = new IntersectionObserver(
      (entries) => {
        entries.forEach((e) => {
          if (e.isIntersecting) {
            setTimeout(() => setShown(true), delay);
            obs.disconnect();
          }
        });
      },
      { threshold: 0.12 }
    );
    obs.observe(ref.current);
    return () => obs.disconnect();
  }, [delay]);
  return (
    <Tag ref={ref} className={`reveal ${shown ? "in" : ""} ${className}`} {...rest}>
      {children}
    </Tag>);

}

function Star({ size = 14, color = "currentColor", style }) {
  return (
    <svg
      width={size}
      height={size}
      viewBox="0 0 24 24"
      style={style}
      aria-hidden="true">
      
      <path
        d="M12 1v22M1 12h22M4.2 4.2l15.6 15.6M19.8 4.2L4.2 19.8"
        stroke={color}
        strokeWidth="1.2" />
      
    </svg>);

}

function Asterisk({ size = 14, color = "currentColor", className = "", style }) {
  return (
    <svg
      width={size}
      height={size}
      viewBox="0 0 24 24"
      className={className}
      style={style}
      aria-hidden="true">
      
      <g stroke={color} strokeWidth="2" strokeLinecap="round">
        <line x1="12" y1="3" x2="12" y2="21" />
        <line x1="3" y1="12" x2="21" y2="12" />
        <line x1="5.6" y1="5.6" x2="18.4" y2="18.4" />
        <line x1="18.4" y1="5.6" x2="5.6" y2="18.4" />
      </g>
    </svg>);

}

function Wordmark({ size = 28, variant = "orange" }) {
  const src =
    variant === "white" ? "/assets/LogoWH.png" :
    variant === "black" ? "/assets/logo-black.png" :
    "/assets/logo-orange.png";
  return (
    <img
      src={src}
      alt="Tremendo Studio"
      style={{
        height: size,
        width: "auto",
        display: "block"
      }} />);

}

// Logotipo "Tremendo" que sustituye la palabra dentro de algunos titulares.
// color: "orange" (assets/tremendo-orange.svg) o "white" (assets/tremendo-white.svg)
function TremendoLogo({ color = "orange", className = "" }) {
  return (
    <img
      src={color === "white" ? "/assets/tremendo-white.svg" : "/assets/tremendo-orange.svg"}
      alt="Tremendo"
      className={"tremendo-logo " + className} />);

}

// Redes oficiales del estudio (footer, Nosotras y Hablemos)
const EMAIL = "somos.tremendo.st@gmail.com";
const SOCIALS = [
{ name: "Instagram", handle: "@somos.tremendo", url: "https://www.instagram.com/somos.tremendo/" },
{ name: "TikTok", handle: "@somos.tremendo", url: "https://www.tiktok.com/@somos.tremendo" }];


// Navbar with 4 tabs
function Navbar({ page, go }) {
  const tabs = [
  { id: "home", label: "Home" },
  { id: "servicios", label: "Servicios" },
  { id: "nosotras", label: "Nosotras" },
  { id: "hablemos", label: "Hablemos", cta: true }];

  return (
    <nav className="nav" style={{ backgroundColor: "rgb(33, 35, 34)" }}>
      <button className="nav-brand" onClick={() => go("home")} aria-label="Home">
        <Wordmark size={44} variant="white" />
      </button>

      <ul className="nav-tabs">
        {tabs.map((t) =>
        <li key={t.id}>
            <button
            onClick={() => go(t.id)}
            data-cursor={t.cta ? "hola" : "ir"}
            className={
            "nav-tab " + (
            t.cta ? "cta " : "") + (
            page === t.id ? "active" : "")
            }>
            
              <span className="nav-num">
                {String(tabs.indexOf(t) + 1).padStart(2, "0")}
              </span>
              <span>{t.label}</span>
            </button>
          </li>
        )}
      </ul>
    </nav>);

}

// Footer
function Footer({ go }) {
  return (
    <footer className="footer">
      <div className="footer-top">
        <div>
          <p className="eyebrow" style={{ color: "var(--orange)" }}>
            ¿Te quedaste con ganas?
          </p>
          <h3 className="display footer-big">
            HAGAMOS <br />
            ALGO <span className="display" style={{ color: "var(--orange)" }}>tremendo</span>.
          </h3>
          <button className="btn" onClick={() => go("hablemos")}>
            Escríbenos <Star size={12} />
          </button>
        </div>

        <div className="footer-cols">
          <div>
            <p className="eyebrow footer-head">Estudio</p>
            <ul>
              <li><button onClick={() => go("home")}>Home</button></li>
              <li><button onClick={() => go("servicios")}>Servicios</button></li>
              <li><button onClick={() => go("nosotras")}>Nosotras</button></li>
              <li><button onClick={() => go("hablemos")}>Hablemos</button></li>
            </ul>
          </div>
          <div>
            <p className="eyebrow footer-head">Redes</p>
            <ul>
              {SOCIALS.map((r) =>
              <li key={r.name}><a href={r.url} target="_blank" rel="noopener noreferrer">{r.name} ↗</a></li>
              )}
            </ul>
          </div>
          <div>
            <p className="eyebrow footer-head">Contacto</p>
            <ul>
              <li><a href={"mailto:" + EMAIL} className="footer-mail">{EMAIL}</a></li>
              <li><a href="https://wa.me/525548900185" target="_blank" rel="noopener noreferrer">WhatsApp ↗</a></li>
              <li>Sin Fronteras, MX</li>
            </ul>
          </div>
        </div>
      </div>

      <div className="footer-bottom">
        <span>© {new Date().getFullYear()} Tremendo Studio. Hecho con complicidad.</span>
        <span className="footer-astro">
          <Asterisk size={14} className="asterisk slow" />
          <span className="serif-ital">Menos ordinario, más tremendo.</span>
          <Asterisk size={14} className="asterisk slow" />
        </span>
      </div>
    </footer>);

}

Object.assign(window, { Reveal, Star, Asterisk, Wordmark, TremendoLogo, EMAIL, SOCIALS, Navbar, Footer });