/* Hero. 2-col layout: copy left, product demo right
   Per blueprint: Eyebrow → Headline → Sub → CTA → trust signals → product mock */

const Sparkle = () => (
  <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor">
    <path d="M12 2l2.4 6.6L21 11l-6.6 2.4L12 20l-2.4-6.6L3 11l6.6-2.4z"/>
  </svg>
);

const ArrowRight = ({ s = 16 }) => (
  <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round">
    <path d="M5 12h14M13 5l7 7-7 7"/>
  </svg>
);

const PlayIcon = ({ s = 18 }) => (
  <svg width={s} height={s} viewBox="0 0 24 24" fill="currentColor">
    <path d="M8 5v14l11-7z"/>
  </svg>
);

const CloseIcon = ({ s = 22 }) => (
  <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round">
    <path d="M6 6l12 12"/><path d="M18 6L6 18"/>
  </svg>
);

const WPP_LINK = "https://wa.me/5512992126931?text=Ol%C3%A1%2C%20quero%20conhecer%20a%20TechFala%20IA!";
const LOGIN_URL = "https://app.techfala.com.br";
const REGISTER_URL = "https://www.techfala.com/login/register/863/MONTHLY";

/* ═════════ LIGHTBOX ═════════ */
const VideoLightbox = ({ open, onClose, src }) => {
  React.useEffect(() => {
    if (!open) return;
    const onKey = (e) => { if (e.key === 'Escape') onClose(); };
    document.body.style.overflow = 'hidden';
    window.addEventListener('keydown', onKey);
    return () => {
      document.body.style.overflow = '';
      window.removeEventListener('keydown', onKey);
    };
  }, [open, onClose]);

  if (!open) return null;
  return (
    <div className="tf-lightbox" onClick={onClose} role="dialog" aria-modal="true" aria-label="Vídeo de demonstração">
      <button className="tf-lightbox-close" onClick={onClose} aria-label="Fechar vídeo">
        <CloseIcon />
      </button>
      <div className="tf-lightbox-inner" onClick={(e) => e.stopPropagation()}>
        <video src={src} controls autoPlay playsInline preload="auto">
          Seu navegador não suporta vídeo HTML5.
        </video>
      </div>
    </div>
  );
};

/* ═════════ JARVIS HERO ═════════ */
const JarvisOrbit = ({ onPlay }) => (
  <div className="jx-stage">
    <div className="jx-glow" aria-hidden="true" />
    <button
      className="jx-photo-wrap"
      onClick={onPlay}
      aria-label="Reproduzir vídeo de demonstração da TechFala"
    >
      <img
        className="jx-photo"
        src="../../assets/jarvis-dash.png"
        alt="Jarvis. IA da TechFala integrada ao seu negócio"
      />
      <span className="jx-play" aria-hidden="true">
        <PlayIcon s={28} />
      </span>
    </button>
  </div>
);

const Hero = () => {
  const [videoOpen, setVideoOpen] = React.useState(false);
  return (
    <section className="hero">
      <div className="grid-pattern" />

      <div className="container hero-inner2">
        <div className="hero-copy">
          <span className="pill"><span className="dot" /> Inteligência Artificial que Executa</span>
          <h1>
            <span className="hero-h1-row">Não é chatbot.</span>
            <span className="hero-h1-row">É <em>IA que vende.</em></span>
          </h1>
          <p className="sub">
            A TechFala cria IAs treinadas no seu negócio que atendem, qualificam, agendam e automatizam de verdade. Integração real a CRMs, ERPs e fluxos personalizados. Atuação nacional com centenas de implementações ativas.
          </p>
          <div className="hero-ctas">
            <a href={WPP_LINK} target="_blank" rel="noopener" className="btn-primary">Fale com o Jarvis <ArrowRight /></a>
            <button className="btn-ghost" onClick={() => setVideoOpen(true)}>
              <PlayIcon /> Ver demonstração
            </button>
          </div>
          <p className="hero-micro" style={{marginTop: 18, opacity: 0.7, fontSize: 13}}>Tecnologia proprietária. Integrações nativas. Implementação guiada.</p>
        </div>

        <div className="hero-right">
          <JarvisOrbit onPlay={() => setVideoOpen(true)} />
        </div>
      </div>

      <VideoLightbox
        open={videoOpen}
        onClose={() => setVideoOpen(false)}
        src="../../assets/hero-showcase.mp4"
      />
    </section>
  );
};

/* ═════════ FLOATING WHATSAPP BUTTON ═════════ */
const FloatingWpp = () => (
  <a
    href={WPP_LINK}
    target="_blank"
    rel="noopener"
    className="tf-fab-wpp"
    aria-label="Falar no WhatsApp"
    title="Falar no WhatsApp"
  >
    <svg width="30" height="30" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
      <path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 0 1-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 0 1-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 0 1 2.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0 0 12.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 0 0 5.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 0 0-3.48-8.413Z"/>
    </svg>
  </a>
);

window.Hero = Hero;
window.FloatingWpp = FloatingWpp;
window.Sparkle = Sparkle;
window.ArrowRight = ArrowRight;
window.PlayIcon = PlayIcon;
window.WPP_LINK = WPP_LINK;
window.LOGIN_URL = LOGIN_URL;
window.REGISTER_URL = REGISTER_URL;
