/* global React */
/* Comparison, How-it-works, Final CTA, Footer */

function Comparison() {
  const cols = ["Adam Checks", "Googling it", "Checking manually"];
  const rows = [
    ["Speed", ["Instant", "ok"], ["Minutes", "no"], ["Minutes", "no"]],
    ["Accuracy", ["Verified", "ok"], ["Unreliable", "no"], ["Accurate", "ok"]],
    ["Finds restaurants", ["✓", "yes"], ["✕", "x"], ["✕", "x"]],
    ["Compares prices", ["✓", "yes"], ["✕", "x"], ["✕", "x"]],
    ["Works on WhatsApp", ["✓", "yes"], ["✕", "x"], ["✕", "x"]],
    ["Free", ["✓", "yes"], ["✓", "yes"], ["✓", "yes"]],
  ];
  function Cell({ val, kind, hero }) {
    let color = "var(--ink)", weight = 700;
    if (kind === "no") color = "var(--ink-faint)";
    if (kind === "x") return <span style={{ color: "var(--haram)", fontWeight: 900, fontSize: 18 }}>✕</span>;
    if (kind === "yes") return <span style={{ color: hero ? "var(--halal)" : "var(--ink)", fontWeight: 900, fontSize: 18 }}>✓</span>;
    if (kind === "ok") color = hero ? "var(--halal)" : "var(--ink)";
    return <span style={{ color, fontWeight: weight, fontSize: 15 }}>{val}</span>;
  }
  return (
    <section className="section reveal" id="compare">
      <div className="wrap" style={{ maxWidth: 980 }}>
        <div style={{ textAlign: "center", marginBottom: 40 }}>
          <span className="eyebrow" style={{ justifyContent: "center" }}>Why it’s different</span>
          <h2 className="h-section" style={{ marginTop: 16 }}>Nothing else does all of this.</h2>
        </div>
        <div className="cmp">
          <div className="cmp-head">
            <div></div>
            {cols.map((c, i) => (
              <div key={c} className={`cmp-col ${i === 0 ? "cmp-hero" : ""}`}>{i === 0 && <span className="cmp-crown">★</span>}{c}</div>
            ))}
          </div>
          {rows.map((r, ri) => (
            <div className="cmp-row" key={ri}>
              <div className="cmp-label">{r[0]}</div>
              {[1, 2, 3].map((ci) => (
                <div key={ci} className={`cmp-cell ${ci === 1 ? "cmp-hero" : ""}`}>
                  <Cell val={r[ci][0]} kind={r[ci][1]} hero={ci === 1} />
                </div>
              ))}
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

function HowItWorks() {
  const steps = [
    { n: "1", t: "Save the number", d: "Add 213-259-2977 to your contacts as “Adam Checks”.", icon: "📇" },
    { n: "2", t: "Text Adam", d: "Send a product name, a photo of the label, or a voice note.", icon: "💬" },
    { n: "3", t: "Get your answer", d: "A clear halal / haram verdict in seconds — with the proof.", icon: "✅" },
  ];
  return (
    <section className="section reveal" id="how" style={{ background: "var(--paper-2)", borderTop: "1px solid var(--line)", borderBottom: "1px solid var(--line)" }}>
      <div className="wrap">
        <div style={{ textAlign: "center", marginBottom: 46 }}>
          <span className="eyebrow" style={{ justifyContent: "center" }}>How it works</span>
          <h2 className="h-section" style={{ marginTop: 16 }}>Up and running in 30 seconds.</h2>
        </div>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(3,1fr)", gap: 22 }}>
          {steps.map((s, i) => (
            <div key={s.n} style={{ position: "relative", background: "#fff", border: "1px solid var(--line)", borderRadius: "var(--r-lg)", padding: "30px 26px", boxShadow: "var(--shadow-sm)" }}>
              <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between" }}>
                <span style={{ width: 44, height: 44, borderRadius: 12, background: "var(--wa-green)", color: "#04130C", display: "grid", placeItems: "center", fontWeight: 900, fontSize: 20, fontFamily: "var(--font-display)" }}>{s.n}</span>
                <span style={{ fontSize: 28 }}>{s.icon}</span>
              </div>
              <h3 style={{ fontSize: 23, marginTop: 20 }}>{s.t}</h3>
              <p style={{ marginTop: 8, color: "var(--ink-soft)", fontSize: 16, lineHeight: 1.5 }}>{s.d}</p>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

/* QR placeholder (simple deterministic blocks — not a scannable code) */
function QRPlaceholder({ size = 150 }) {
  const cells = 11;
  const seed = [0,1,1,0,1,0,1,1,0,1,0, 1,0,0,1,0,1,0,0,1,0,1, 1,1,0,1,1,0,1,0,1,1,0];
  const grid = [];
  for (let i = 0; i < cells * cells; i++) grid.push((seed[(i * 7 + (i % 5)) % seed.length] + (i % 3 === 0 ? 1 : 0)) % 2);
  return (
    <div style={{ width: size, height: size, background: "#fff", borderRadius: 14, padding: 12, display: "grid", gridTemplateColumns: `repeat(${cells},1fr)`, gap: 2, boxShadow: "var(--shadow-md)" }}>
      {grid.map((v, i) => <div key={i} style={{ background: v ? "var(--ink)" : "transparent", borderRadius: 1 }}></div>)}
    </div>
  );
}

function FinalCTA() {
  return (
    <section className="section" id="get" style={{ background: "var(--ink)", color: "#fff" }}>
      <div className="wrap" style={{ display: "grid", gridTemplateColumns: "1.15fr .85fr", gap: 50, alignItems: "center" }}>
        <div>
          <span className="eyebrow" style={{ color: "#7CF0B6" }}>Try it right now</span>
          <h2 style={{ fontSize: "clamp(38px,5.2vw,68px)", marginTop: 18, color: "#fff", lineHeight: .98 }}>
            Ask Adam if your<br />favourite snack<br />is halal.
          </h2>
          <p style={{ fontSize: 19, color: "rgba(255,255,255,.72)", marginTop: 20, maxWidth: 460 }}>
            It’s free, it’s instant, it’s halal. Save the number and use it next time you’re at the store.
          </p>
          <div style={{ display: "flex", gap: 14, marginTop: 30, flexWrap: "wrap" }}>
            <a className="btn btn-primary" href={window.WA_LINK} target="_blank" rel="noopener"><window.WAIcon /> Text Adam on WhatsApp</a>
            <a className="btn btn-ghost" href={window.WA_LINK} target="_blank" rel="noopener" style={{ color: "#fff", borderColor: "rgba(255,255,255,.3)" }}>{window.PHONE}</a>
          </div>
        </div>
        <div style={{ display: "grid", placeItems: "center" }}>
          <div style={{ background: "rgba(255,255,255,.06)", border: "1px solid rgba(255,255,255,.14)", borderRadius: "var(--r-xl)", padding: 30, textAlign: "center" }}>
            <QRPlaceholder size={168} />
            <div style={{ marginTop: 16, fontWeight: 800, fontSize: 16, whiteSpace: "nowrap" }}>Scan to start chatting</div>
            <div style={{ marginTop: 5, fontSize: 14, color: "#7CF0B6", fontWeight: 700, fontFamily: "ui-monospace,monospace", whiteSpace: "nowrap" }}>+1 213-259-2977</div>
          </div>
        </div>
      </div>
    </section>
  );
}

function Footer() {
  return (
    <footer style={{ background: "var(--ink)", color: "rgba(255,255,255,.6)", borderTop: "1px solid rgba(255,255,255,.1)", padding: "40px 0" }}>
      <div className="wrap" style={{ display: "flex", flexWrap: "wrap", justifyContent: "space-between", gap: 18, alignItems: "center" }}>
        <div style={{ display: "flex", alignItems: "center", gap: 11 }}>
          <span style={{ width: 32, height: 32, borderRadius: 9, background: "var(--wa-green)", display: "grid", placeItems: "center" }}><Tick size={16} color="#04130C" /></span>
          <span style={{ fontFamily: "var(--font-display)", fontWeight: 800, fontSize: 18, color: "#fff", whiteSpace: "nowrap" }}>Adam Checks</span>
        </div>
        <p style={{ fontSize: 14, maxWidth: 440 }}>
          Free WhatsApp halal assistant for Canadian Muslims. Adam provides guidance based on certification data; always verify for dietary-critical needs.
        </p>
        <div style={{ fontSize: 13 }}>© 2026 Adam Checks</div>
      </div>
    </footer>
  );
}

window.Comparison = Comparison;
window.HowItWorks = HowItWorks;
window.FinalCTA = FinalCTA;
window.Footer = Footer;
window.QRPlaceholder = QRPlaceholder;
