// Shared components: Nav, Icon glyphs, IconTile, ChatBubble, AvatarTile, etc.

// Logo: green rounded square icon + chat bubble glyph + "Allora Agent" wordmark
const Logo = ({ size = 22, hideText = false }) => (
  <span className="brand" style={{ gap: 8 }}>
    <span style={{
      width: size, height: size,
      borderRadius: Math.round(size * 0.25),
      background: "var(--brand-green, #2F6E54)",
      display: "inline-grid", placeItems: "center",
      boxShadow: "0 1px 0 rgba(255,255,255,.18) inset, 0 2px 6px rgba(47,110,84,.25)",
    }}>
      <svg width={Math.round(size * 0.62)} height={Math.round(size * 0.62)} viewBox="0 0 20 20" fill="white" aria-hidden="true">
        <path d="M3.5 2.5h13a1.5 1.5 0 0 1 1.5 1.5v9.5a1.5 1.5 0 0 1-1.5 1.5h-4l-3.2 2.6a.5.5 0 0 1-.8-.4V15H3.5A1.5 1.5 0 0 1 2 13.5V4a1.5 1.5 0 0 1 1.5-1.5Z"/>
      </svg>
    </span>
    {!hideText && (
      <span style={{ display: "inline-flex", gap: "0.25ch", letterSpacing: "-0.015em" }}>
        <span style={{ color: "var(--ink)" }}>Allora</span>
        <span style={{ color: "var(--brand-green, #2F6E54)" }}>Agent</span>
      </span>
    )}
  </span>
);

const Nav = ({ onCta }) => {
  return (
    <div className="nav-shell">
      <nav className="nav-pill" role="navigation" aria-label="Principal">
        <Logo size={22} />
        <span style={{ width: 8 }} />
        <a className="nav-link hide-sm" href="#como-funciona">Como funciona</a>
        <a className="nav-link hide-sm" href="#beneficios">Benefícios</a>
        <a className="nav-link hide-sm" href="#planos">Planos</a>
        <a className="nav-link hide-sm" href="nosso-time.html">Nosso time</a>
        <a className="nav-link hide-sm" href="#faq">FAQ</a>
        <a className="btn btn-ghost btn-sm" href="#login" style={{ marginLeft: 8 }}>Entrar</a>
        <a className="btn btn-dark btn-sm" href="#cta" onClick={onCta}>Assine agora</a>
      </nav>
    </div>
  );
};

// ─── glyph icons (simple, brand-consistent) ───
const G = {
  Bolt: (p) => (<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M13 2 4 14h7l-1 8 9-12h-7l1-8Z"/></svg>),
  Chat: (p) => (<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M21 11.5a8.4 8.4 0 0 1-9 8.4c-1.4 0-2.8-.3-4-.9L3 21l1.9-4.5A8.4 8.4 0 1 1 21 11.5Z"/></svg>),
  Calendar: (p) => (<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><rect x="3" y="5" width="18" height="16" rx="3"/><path d="M3 10h18M8 3v4M16 3v4"/></svg>),
  Check: (p) => (<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="m4 12 5 5L20 6"/></svg>),
  Heart: (p) => (<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M12 21s-7-4.5-9.5-9A5.5 5.5 0 0 1 12 6.5 5.5 5.5 0 0 1 21.5 12C19 16.5 12 21 12 21Z"/></svg>),
  Shield: (p) => (<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M12 3 4 6v6c0 5 3.5 8.5 8 9 4.5-.5 8-4 8-9V6l-8-3Z"/></svg>),
  Spark: (p) => (<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M12 3v4M12 17v4M3 12h4M17 12h4M5.6 5.6l2.8 2.8M15.6 15.6l2.8 2.8M5.6 18.4l2.8-2.8M15.6 8.4l2.8-2.8"/></svg>),
  Clock: (p) => (<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/></svg>),
  Phone: (p) => (<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M5 4h4l2 5-3 2a12 12 0 0 0 5 5l2-3 5 2v4a2 2 0 0 1-2 2A16 16 0 0 1 3 6a2 2 0 0 1 2-2Z"/></svg>),
  Moon: (p) => (<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M21 13A9 9 0 1 1 11 3a7 7 0 0 0 10 10Z"/></svg>),
  Repeat: (p) => (<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M17 1l4 4-4 4M3 11V9a4 4 0 0 1 4-4h14M7 23l-4-4 4-4M21 13v2a4 4 0 0 1-4 4H3"/></svg>),
  User: (p) => (<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><circle cx="12" cy="8" r="4"/><path d="M3 21a9 9 0 0 1 18 0"/></svg>),
  WhatsApp: (p) => (<svg viewBox="0 0 24 24" width="22" height="22" fill="currentColor" {...p}><path d="M12 2a10 10 0 0 0-8.5 15.2L2 22l4.9-1.4A10 10 0 1 0 12 2Zm5.6 14c-.2.6-1.4 1.2-1.9 1.2-.5 0-1.1.1-3.4-.9-2.8-1.2-4.6-4-4.7-4.2-.1-.2-1-1.4-1-2.6 0-1.3.6-1.9.9-2.2.2-.2.6-.3.8-.3h.6c.2 0 .5 0 .7.5l1 2.3c.1.2.1.4 0 .6l-.4.5-.4.4c-.1.1-.3.3-.1.6.2.4.9 1.5 2 2.4 1.4 1.2 2.5 1.6 2.9 1.7.3.1.6.1.8-.1.2-.2.9-1 1.1-1.4.2-.4.4-.3.7-.2.3.1 1.9.9 2.2 1 .3.2.5.2.6.4.1.2.1.9-.2 1.6Z"/></svg>),
};

// Icon tile with colored bg (decorative)
const IconTile = ({ glyph, bg = "#FFFFFF", color = "#111", size = "md", style }) => {
  const sizeClass = size === "lg" ? "icon lg" : size === "xl" ? "icon xl" : "icon";
  const Glyph = G[glyph] || G.Bolt;
  return (
    <div className={`float-tile ${sizeClass}`} style={{ background: bg, color, ...style }}>
      <Glyph width={size === "xl" ? 44 : size === "lg" ? 36 : 28} height={size === "xl" ? 44 : size === "lg" ? 36 : 28} strokeWidth={2.2}/>
    </div>
  );
};

// Avatar placeholder tile (initials + tint)
const AvatarTile = ({ initials = "AB", tint = "#E9D8FF", style, w = 96, h = 96, label }) => (
  <div className="float-tile avatar" style={{ width: w, height: h, position: "relative", ...style }}>
    <div style={{
      position: "absolute", inset: 0,
      background: `radial-gradient(120% 80% at 50% 30%, ${tint}, color-mix(in srgb, ${tint} 55%, white))`,
    }} />
    <div style={{
      position: "relative",
      fontFamily: "Bricolage Grotesque, sans-serif",
      fontSize: Math.round(Math.min(w,h) * 0.36),
      fontWeight: 700, letterSpacing: "-0.02em",
      color: "#1d1224",
      mixBlendMode: "multiply",
      opacity: 0.85,
    }}>{initials}</div>
    {label && (
      <div style={{ position: "absolute", left: 8, bottom: 6, fontSize: 10, color: "#1d1224", opacity: 0.6, fontFamily: "JetBrains Mono, monospace" }}>{label}</div>
    )}
  </div>
);

// chat bubble float-tile
const ChatBubble = ({ children, them = false, style, time }) => (
  <div className={`float-tile bubble ${them ? "them" : ""}`} style={style}>
    {children}
    {time && (
      <div style={{ fontSize: 10, opacity: 0.55, marginTop: 6, fontFamily: "JetBrains Mono, monospace" }}>{time}</div>
    )}
  </div>
);

// reusable section header
const SectionHead = ({ eyebrow, title, lede, align = "left", maxWidth = 760 }) => (
  <div className="section-head" style={{ textAlign: align, marginInline: align === "center" ? "auto" : 0, alignItems: align === "center" ? "center" : "flex-start", maxWidth }}>
    {eyebrow && <div className="eyebrow">{eyebrow}</div>}
    {title && <h2 className="display display-md" style={{ margin: 0 }}>{title}</h2>}
    {lede && <p className="lede" style={{ margin: 0 }}>{lede}</p>}
  </div>
);

Object.assign(window, {
  Logo, Nav, G, IconTile, AvatarTile, ChatBubble, SectionHead,
});
