// Shared vertical landing page component.
// Each HTML file sets window.VERTICAL_CONFIG before this loads.
const { useState, useEffect, useRef } = React;
const { Icon, Tick, TextBubble, PhotoCardBubble, Phone } = window.WA;

const cfg = window.VERTICAL_CONFIG;

// -- SVG Logo (shared) --------------------------------------------------------
const LOGO_PATH = "M234.59,503.35C236.96,499.36 243.72,488.22 249.62,478.60C266.87,450.43 299.88,395.81 305.16,386.72L310.02,378.35L307.46,376.22C302.26,371.91 266.05,341.25 264.69,340.00C263.50,338.91 264.97,335.76 274.35,319.40C325.65,229.89 338.52,207.34 338.90,206.30C339.47,204.69 339.46,204.67 345.81,216.10C348.86,221.60 361.69,244.33 374.31,266.60C386.93,288.87 402.35,316.10 408.58,327.10C441.99,386.12 483.51,459.34 488.54,468.10C491.70,473.60 495.74,480.69 497.51,483.85L500.75,489.60L476.42,489.55L452.10,489.51L434.15,457.83C424.28,440.41 403.61,404.32 388.21,377.63C372.82,350.94 357.94,325.10 355.16,320.21C352.38,315.31 349.65,311.43 349.10,311.57C347.37,312.03 338.71,333.94 339.60,335.60C340.05,336.42 347.03,348.58 355.11,362.60C379.26,404.48 415.48,467.69 428.03,489.85L439.78,510.60L487.69,510.60C515.01,510.60 535.60,510.22 535.60,509.71C535.60,508.10 523.32,486.25 418.61,301.60C391.38,253.57 353.60,186.85 345.08,171.74L339.81,162.39L337.31,166.74C335.93,169.14 330.77,178.30 325.83,187.10C320.90,195.90 308.18,218.17 297.58,236.60C286.98,255.03 271.36,282.25 262.87,297.10C254.38,311.95 247.26,324.27 247.05,324.48C246.72,324.81 237.44,317.15 191.67,278.71C184.20,272.44 178.18,267.04 178.28,266.71C178.38,266.37 188.22,248.33 200.15,226.60C232.31,168.03 264.69,107.63 284.84,68.60C289.53,59.52 297.02,45.01 301.50,36.35C305.97,27.69 309.38,20.60 309.08,20.60C304.86,20.60 226.07,66.34 120.10,130.30C93.70,146.24 64.45,163.90 55.10,169.54C45.75,175.18 37.54,180.26 36.85,180.82C35.89,181.61 35.60,191.18 35.60,222.47L35.60,263.10L76.76,296.60C99.40,315.03 118.34,330.78 118.86,331.61C119.54,332.73 116.03,339.75 105.35,358.61C61.89,435.36 20.60,509.14 20.60,510.04C20.60,510.35 67.78,510.60 125.44,510.60L230.29,510.60L234.59,503.35ZM56.60,488.82C56.60,488.40 64.97,473.21 75.20,455.07C85.44,436.94 97.72,415.12 102.50,406.60C107.27,398.08 116.79,381.10 123.64,368.87C130.49,356.64 136.33,346.63 136.61,346.62C136.89,346.61 140.50,349.41 144.63,352.85C148.77,356.29 162.49,367.69 175.12,378.19C187.76,388.68 198.71,398.01 199.45,398.91C200.62,400.33 200.12,401.83 195.72,410.07L190.64,419.58L193.02,429.66C194.33,435.20 195.60,439.93 195.85,440.18C196.50,440.83 224.60,395.06 224.60,393.35C224.60,392.56 222.15,389.93 219.16,387.50C216.17,385.08 188.14,361.72 156.87,335.60C125.60,309.48 90.49,280.45 78.85,271.10L57.68,254.10L57.64,223.46L57.60,192.81L88.85,173.86C176.25,120.87 257.71,72.38 258.31,72.98C258.98,73.65 224.54,138.07 177.65,223.84L161.40,253.57L154.75,247.77C151.09,244.58 144.53,238.96 140.18,235.28L132.25,228.60L123.68,228.61C118.96,228.61 112.00,228.91 108.21,229.27L101.31,229.92L104.34,232.51C126.39,251.39 170.08,288.30 217.11,327.75C249.00,354.51 276.84,377.93 278.98,379.78L282.85,383.16L276.64,393.63C273.22,399.39 258.71,423.34 244.39,446.85L218.35,489.60L137.48,489.60C92.99,489.60 56.60,489.25 56.60,488.82Z";

function Logo({ size = 36 }) {
  return <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 556 531" fill="var(--emerald)" fillRule="evenodd" style={{ height: size, width: "auto", display: "block" }}><path d={LOGO_PATH}/></svg>;
}

// -- Pain point icons ---------------------------------------------------------
const PainIcons = {
  clock: () => <svg className="pain-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>,
  repeat: () => <svg className="pain-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><polyline points="17 1 21 5 17 9"/><path d="M3 11V9a4 4 0 0 1 4-4h14"/><polyline points="7 23 3 19 7 15"/><path d="M21 13v2a4 4 0 0 1-4 4H3"/></svg>,
  calendar: () => <svg className="pain-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><rect x="3" y="5" width="18" height="16" rx="2"/><line x1="3" y1="10" x2="21" y2="10"/><line x1="8" y1="2" x2="8" y2="6"/><line x1="16" y1="2" x2="16" y2="6"/></svg>,
  phone: () => <svg className="pain-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><path d="M22 16.92v3a2 2 0 0 1-2.18 2A19.79 19.79 0 0 1 2.08 4.18 2 2 0 0 1 4.07 2h3a2 2 0 0 1 2 1.72c.13.96.37 1.9.72 2.81a2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45c.91.35 1.85.59 2.81.72A2 2 0 0 1 22 16.92z"/></svg>,
  users: () => <svg className="pain-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></svg>,
  alertCircle: () => <svg className="pain-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>,
  package: () => <svg className="pain-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><path d="M16.5 9.4l-9-5.19M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"/><polyline points="3.27 6.96 12 12.01 20.73 6.96"/><line x1="12" y1="22.08" x2="12" y2="12"/></svg>,
  messageCircle: () => <svg className="pain-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8A8.5 8.5 0 0 1 12.5 20a8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6A8.38 8.38 0 0 1 12.5 3h.5A8.48 8.48 0 0 1 21 11.5z"/></svg>,
  scissors: () => <svg className="pain-icon" 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>,
  utensils: () => <svg className="pain-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><path d="M3 2v7c0 1.1.9 2 2 2h4a2 2 0 0 0 2-2V2"/><line x1="7" y1="2" x2="7" y2="22"/><path d="M21 15V2v0a5 5 0 0 0-5 5v6c0 1.1.9 2 2 2h3"/><line x1="18" y1="22" x2="18" y2="15"/></svg>,
  shoppingBag: () => <svg className="pain-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><path d="M6 2L3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4z"/><line x1="3" y1="6" x2="21" y2="6"/><path d="M16 10a4 4 0 0 1-8 0"/></svg>,
  ruler: () => <svg className="pain-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"><path d="M21.73 18l-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>,
};

// -- Chat renderer ------------------------------------------------------------
function renderChat(msg, i) {
  if (msg.card) {
    return <PhotoCardBubble key={i} dir={msg.dir} src={cfg.photo.url} alt={cfg.photo.alt} title={cfg.card.title} sub={cfg.card.sub} time={msg.time} read delay={i * 0.15} />;
  }
  return <TextBubble key={i} dir={msg.dir} time={msg.time} read={msg.dir === "out"} delay={i * 0.15}>{msg.text}</TextBubble>;
}

// -- FAQ Item -----------------------------------------------------------------
function FAQItem({ q, a, open, onClick }) {
  return (
    <div className={`faq-item ${open ? "open" : ""}`}>
      <button className="faq-q" onClick={onClick}>
        <span>{q}</span>
        <span className="faq-icon" aria-hidden="true"/>
      </button>
      <div className="faq-a"><div className="faq-a-inner">{a}</div></div>
    </div>
  );
}

// -- Main page component ------------------------------------------------------
function VerticalPage() {
  const [faqOpen, setFaqOpen] = useState(0);
  const [scrolled, setScrolled] = useState(false);
  const progressRef = useRef(null);

  useEffect(() => {
    document.documentElement.setAttribute("data-theme", "dark");
    try { localStorage.removeItem("wa-theme"); } catch (e) {}
  }, []);

  useEffect(() => {
    const onScroll = () => {
      setScrolled(window.scrollY > 20);
      const h = document.documentElement.scrollHeight - window.innerHeight;
      const r = h > 0 ? window.scrollY / h : 0;
      if (progressRef.current) progressRef.current.style.transform = `scaleX(${r})`;
    };
    window.addEventListener("scroll", onScroll);
    onScroll();
    return () => window.removeEventListener("scroll", onScroll);
  }, []);

  useEffect(() => {
    const io = new IntersectionObserver((entries) => {
      entries.forEach((e) => { if (e.isIntersecting) e.target.classList.add("in"); });
    }, { threshold: 0.12, rootMargin: "-40px" });
    document.querySelectorAll(".reveal, .reveal-stagger").forEach((el) => io.observe(el));
    return () => io.disconnect();
  }, []);

  return (
    <>
      {/* Scroll progress */}
      <div ref={progressRef} className="scroll-progress" style={{ transform: "scaleX(0)" }}/>

      {/* Nav */}
      <nav className={`nav ${scrolled ? "scrolled" : ""}`}>
        <a href="/" className="nav-logo" aria-label="SamaLabs home">
          <Logo size={36}/>
          <span style={{ fontSize: 17, letterSpacing: "-0.01em", color: "var(--ink)", fontFamily: "Inter, sans-serif" }}>
            <span style={{ fontWeight: 500 }}>Sama</span><span style={{ fontWeight: 700 }}>Labs</span>
          </span>
        </a>
        <div className="nav-links">
          <a href="/#industries">Industries</a>
          <a href="/#how">How it works</a>
          <a href="/#tryit">Try it</a>
          <a href="/FAQ">FAQ</a>
          <a href="#pricing">Pricing</a>
          <a className="btn btn-primary" href="#cta">Book a demo</a>
        </div>
      </nav>

      {/* 1 — HERO */}
      <section className="hero vertical-hero">
        <div className="hero-mesh" aria-hidden="true"/>
        <div className="hero-inner wrap">
          <div className="breadcrumb">
            <a href="/">Home</a><span className="sep">/</span>
            <a href="/#industries">Industries</a><span className="sep">/</span>
            <span>{cfg.hero.eyebrow}</span>
          </div>
          <span className="eyebrow hero-eyebrow" style={{ justifyContent: "center" }}>{cfg.hero.eyebrow}</span>
          <h1 className="display">
            {cfg.hero.headline}{" "}<em className="italic-serif" style={{ color: "var(--emerald-2)" }}>{cfg.hero.headlineAccent}</em>
          </h1>
          <p className="hero-sub">{cfg.hero.sub}</p>
          <div className="hero-ctas">
            <a className="btn btn-primary btn-lg" href={cfg.demoUrl} target="_blank" rel="noopener">Try the live demo</a>
            <a className="btn btn-ghost btn-lg" href="#pricing">See pricing</a>
          </div>
        </div>
      </section>

      {/* 2 — PAIN POINTS */}
      <section className="pain-section">
        <div className="wrap">
          <div className="section-header reveal">
            <span className="eyebrow" style={{ justifyContent: "center" }}>The problem</span>
            <h2 className="display" style={{ textAlign: "center" }}>Without AI, you're leaving <em className="italic-serif">money on the table.</em></h2>
          </div>
          <div className="pain-grid reveal-stagger">
            {cfg.painPoints.map((p, i) => {
              const PainIcon = PainIcons[p.icon] || PainIcons.alertCircle;
              return (
                <div key={i} className="pain-card">
                  <PainIcon />
                  <h3>{p.title}</h3>
                  <p>{p.body}</p>
                </div>
              );
            })}
          </div>
        </div>
      </section>

      {/* 3 — FEATURES + PHONE DEMO */}
      <section className="vertical-features" id="features">
        <div className="wrap">
          <div className="section-header reveal" style={{ textAlign: "center", maxWidth: 680, margin: "0 auto clamp(40px, 5vw, 64px)" }}>
            <span className="eyebrow" style={{ justifyContent: "center" }}>{cfg.hero.eyebrow}</span>
            <h2 className="display">See how it <em className="italic-serif">works.</em></h2>
          </div>
          <div className="industry-panel reveal">
            <div className="industry-phone-wrap">
              <Phone {...cfg.phone}>{cfg.chat.map(renderChat)}</Phone>
            </div>
            <div className="industry-copy">
              <span className="kicker">{cfg.hero.kicker}</span>
              <h3>{cfg.hero.featureHeadline}</h3>
              <p>{cfg.hero.featureBody}</p>
              <ul className="industry-bullets">
                {cfg.features.map((f, i) => (
                  <li key={i}><Icon.Check /><span><strong>{f.title}</strong> — {f.body}</span></li>
                ))}
              </ul>
              <a className="btn btn-primary" href={cfg.demoUrl} target="_blank" rel="noopener">Try the live demo</a>
            </div>
          </div>
        </div>
      </section>

      {/* 4 — PRICING */}
      <section id="pricing">
        <div className="wrap">
          <div className="section-header reveal">
            <span className="eyebrow">Pricing</span>
            <h2 className="display">Pay for the conversations<br/>you <em className="italic-serif">actually use.</em></h2>
          </div>
          <div className="pricing-grid reveal-stagger">
            <div className="price-card">
              <div className="price-name">Starter</div>
              <div className="price-amt"><span className="num">AED 499</span><span className="per">/mo</span></div>
              <div className="price-setup">+ AED 1,800 setup (one-time)</div>
              <p className="price-desc">For solo operators getting replies off their plate.</p>
              <ul className="price-features">
                <li><Icon.Check /><span>200 conversations/mo · text replies + qualification</span></li>
                <li><Icon.Check /><span>Calendar integration (Cal.com, Google, Outlook)</span></li>
                <li><Icon.Check /><span>Email support</span></li>
                <li><Icon.Check /><span>AED 1.50/conv beyond included</span></li>
              </ul>
              <div className="price-cta"><a className="btn btn-ghost" href="#cta">Start</a></div>
            </div>
            <div className="price-card pro">
              <span className="tag-popular">Most popular</span>
              <div className="price-name">Pro</div>
              <div className="price-amt"><span className="num">AED 999</span><span className="per">/mo</span></div>
              <div className="price-setup">+ AED 3,000 setup (one-time)</div>
              <p className="price-desc">For businesses where every message is revenue.</p>
              <ul className="price-features">
                <li><Icon.Check /><span>1,000 conversations/mo · everything in Starter</span></li>
                <li><Icon.Check /><span>Booking integrations (Fresha, OpenTable)<span className="coming-pill">Coming Q2</span></span></li>
                <li><Icon.Check /><span>Hot-lead detection + escalation</span></li>
                <li><Icon.Check /><span>Priority support</span></li>
                <li><Icon.Check /><span>AED 1.25/conv beyond included</span></li>
              </ul>
              <div className="price-cta"><a className="btn btn-primary" href="#cta">Book a demo</a></div>
            </div>
            <div className="price-card elite">
              <div className="price-name">Custom</div>
              <div className="price-amt"><span className="num">Talk to us</span></div>
              <div className="price-setup">Built for your scale</div>
              <p className="price-desc">For brokerages with 100+ agents, multi-location chains, white-label needs, or high-volume verticals.</p>
              <ul className="price-features">
                <li><Icon.Check /><span>Unlimited conversations · everything in Pro</span></li>
                <li><Icon.Check /><span>Multi-tenant + multi-location config</span></li>
                <li><Icon.Check /><span>Custom knowledge base + integrations</span></li>
                <li><Icon.Check /><span>White-label options</span></li>
                <li><Icon.Check /><span>Dedicated success manager + SLA</span></li>
                <li><Icon.Check /><span>Volume pricing on conversations</span></li>
              </ul>
              <div className="price-cta"><a className="btn btn-ghost" href="#cta">Book a strategy call</a></div>
            </div>
          </div>
          <p className="pricing-fineprint">Month-to-month. 14-day money-back on month 1. Annual prepay: 15% off.</p>
        </div>
      </section>

      {/* 5 — VERTICAL FAQ */}
      <section className="vertical-faq">
        <div className="wrap-narrow">
          <div className="section-header reveal" style={{ textAlign: "center" }}>
            <span className="eyebrow" style={{ justifyContent: "center" }}>FAQ</span>
            <h2 className="display">Common <em className="italic-serif">questions.</em></h2>
          </div>
          <div className="faq-list">
            {cfg.verticalFaqs.map((f, i) => (
              <FAQItem key={i} q={f.q} a={f.a} open={faqOpen === i} onClick={() => setFaqOpen(faqOpen === i ? -1 : i)}/>
            ))}
          </div>
          <p style={{ textAlign: "center", marginTop: 32 }}>
            <a href="/FAQ" style={{ color: "var(--emerald-2)", fontFamily: "var(--mono)", fontSize: 13, letterSpacing: "0.04em" }}>See all FAQs →</a>
          </p>
        </div>
      </section>

      {/* 6 — FINAL CTA */}
      <section id="cta" className="final">
        <div className="wrap-narrow">
          <h2 className="display">{cfg.cta.headline}{" "}<em className="italic-serif">{cfg.cta.headlineAccent}</em></h2>
          <p>{cfg.cta.sub}</p>
          <a className="btn btn-primary btn-xl" href="https://cal.com/samalabs-rbrmuq/samalabs-demo">Book a 15-min demo</a>
        </div>
      </section>

      {/* FOOTER */}
      <footer className="footer">
        <div className="wrap">
          <div className="footer-inner">
            <div style={{ display: "flex", gap: 12, alignItems: "center" }}>
              <Logo size={24}/>
              <span style={{ fontSize: 14, letterSpacing: "-0.01em", color: "var(--ink)", fontFamily: "Inter, sans-serif" }}>
                <span style={{ fontWeight: 500 }}>Sama</span><span style={{ fontWeight: 700 }}>Labs</span>
              </span>
              <span className="tagline" style={{ marginLeft: 6 }}>· AI for WhatsApp Business</span>
            </div>
            <div style={{ display: "flex", gap: 24, alignItems: "center", flexWrap: "wrap" }}>
              <a href="mailto:hello@samalabs.ai">hello@samalabs.ai</a>
              <a href="/">Home</a>
              <span className="copy">© 2026</span>
            </div>
          </div>
        </div>
      </footer>
    </>
  );
}

const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(<VerticalPage />);
