/* CrickAI marketing — shared primitives: Icon, Button, Chip, Eyebrow, EmailCapture, Logo */

const ICON_PATHS = {
  video: <><path d="m22 8-6 4 6 4V8Z"/><rect width="14" height="12" x="2" y="6" rx="2"/></>,
  zap: <path d="M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z"/>,
  sync: <><path d="M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8"/><path d="M21 3v5h-5"/><path d="M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16"/><path d="M8 16H3v5"/></>,
  trend: <><path d="M16 7h6v6"/><path d="m22 7-8.5 8.5-5-5L2 17"/></>,
  tablet: <><rect width="16" height="20" x="4" y="2" rx="2"/><path d="M12 18h.01"/></>,
  archive: <><rect width="20" height="5" x="2" y="3" rx="1"/><path d="M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8"/><path d="M10 12h4"/></>,
  clapper: <><path d="M20.2 6 3 11l-.9-2.4c-.3-1.1.3-2.2 1.3-2.5l13.5-4c1.1-.3 2.2.3 2.5 1.3Z"/><path d="m6.2 5.3 3.1 3.9"/><path d="m12.4 3.4 3.1 4"/><path d="M3 11h18v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z"/></>,
  scissors: <><circle cx="6" cy="6" r="3"/><path d="M8.12 8.12 12 12"/><path d="M20 4 8.12 15.88"/><circle cx="6" cy="18" r="3"/><path d="M14.8 14.8 20 20"/></>,
  trophy: <><path d="M6 9H4.5a2.5 2.5 0 0 1 0-5H6"/><path d="M18 9h1.5a2.5 2.5 0 0 0 0-5H18"/><path d="M4 22h16"/><path d="M10 14.66V17c0 .55-.47.98-.97 1.21C7.85 18.75 7 20.24 7 22"/><path d="M14 14.66V17c0 .55.47.98.97 1.21C16.15 18.75 17 20.24 17 22"/><path d="M18 2H6v7a6 6 0 0 0 12 0V2Z"/></>,
  check: <path d="M20 6 9 17l-5-5"/>,
  users: <><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M22 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></>,
  flag: <><path d="M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z"/><line x1="4" x2="4" y1="22" y2="15"/></>,
  handshake: <><path d="m11 17 2 2a1 1 0 1 0 3-3"/><path d="m14 14 2.5 2.5a1 1 0 1 0 3-3l-3.88-3.88a3 3 0 0 0-4.24 0l-.88.88a1 1 0 1 1-3-3l2.81-2.81a5.79 5.79 0 0 1 7.06-.87l.47.28a2 2 0 0 0 1.42.25L21 4"/><path d="m21 3 1 11h-2"/><path d="M3 3 2 14l6.5 6.5a1 1 0 1 0 3-3"/><path d="M3 4h8"/></>,
  mail: <><rect width="20" height="16" x="2" y="4" rx="2"/><path d="m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"/></>,
  arrow: <><path d="M7 7h10v10"/><path d="M7 17 17 7"/></>,
  play: <polygon points="6 3 20 12 6 21 6 3"/>,
  clock: <><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></>,
  cloud: <><path d="M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z"/><path d="m2 2 20 20"/></>,
};

function Icon({ name, size = 22, stroke = 2, className = "", style }) {
  return (
    <svg className={className} style={style} width={size} height={size} viewBox="0 0 24 24"
      fill="none" stroke="currentColor" strokeWidth={stroke} strokeLinecap="round" strokeLinejoin="round">
      {ICON_PATHS[name] || null}
    </svg>
  );
}

function Button({ variant = "primary", size = "", children, icon, onClick, type = "button" }) {
  const cls = ["btn", `btn--${variant}`, size ? `btn--${size}` : ""].join(" ").trim();
  return (
    <button type={type} className={cls} onClick={onClick}>
      {children}{icon ? <Icon name={icon} size={17} /> : null}
    </button>
  );
}

function Chip({ variant = "", children, dot = false }) {
  return (
    <span className={`chip ${variant ? "chip--" + variant : ""}`}>
      {dot ? <span className="dot"></span> : null}{children}
    </span>
  );
}

function Eyebrow({ gold = false, children }) {
  return <p className={`eyebrow ${gold ? "eyebrow--gold" : ""}`}>{children}</p>;
}

function Logo({ className = "nav__logo" }) {
  return <img className={className} src={(window.CRICK_ASSETS && window.CRICK_ASSETS.logo) || "../assets/crickai-logo.svg"} alt="crickai" />;
}

window.CRICKAI_EMAIL = window.CRICKAI_EMAIL || "info@crickai.com";

/* High-intent CTA: opens the visitor's mail client to compose a real email.
   Asking them to actually write in is a deliberate qualifier — only motivated
   leads follow through. No backend needed; works on any static / Git host. */
function EmailCTA({ label = "Get Early Access", subject = "Early access — CrickAI beta", body, fine, variant = "primary" }) {
  const href = "mailto:" + window.CRICKAI_EMAIL
    + "?subject=" + encodeURIComponent(subject)
    + (body ? "&body=" + encodeURIComponent(body) : "");
  return (
    <div className="capture">
      <div className="cta-row">
        <a className={"btn btn--" + variant + " btn--lg"} href={href}>
          <Icon name="mail" size={18} />{label}
        </a>
        <a className="cta-addr" href={href}>{window.CRICKAI_EMAIL}</a>
      </div>
      {fine ? <p className="capture__fine">{fine}</p> : null}
    </div>
  );
}

function EmailCapture(props) { return <EmailCTA {...props} cta={undefined} label={props.cta || "Get Early Access"} />; }

Object.assign(window, { Icon, Button, Chip, Eyebrow, Logo, EmailCapture, EmailCTA });
