// ---------- SELL PAGE ----------
const SellPage = ({ onHome, onInquire }) => {
  const [step, setStep] = React.useState(1);
  const [form, setForm] = React.useState({ brand: "", model: "", ref: "", year: "", condition: "", box: false, papers: false, name: "", contact: "" });

  React.useEffect(() => { window.scrollTo(0, 0); }, []);

  const set = (k, v) => setForm(f => ({ ...f, [k]: v }));

  return (
    <main>
      {/* Hero */}
      <section style={{ background: "#212A3D", color: "#F4F2EF", position: "relative", overflow: "hidden" }}>
        <svg viewBox="0 0 100 100" preserveAspectRatio="none" width="700" height="700" style={{
          position: "absolute", right: -240, top: -200, opacity: 0.06, pointerEvents: "none",
        }}>
          <circle cx="50" cy="50" r="48" fill="none" stroke="#A86137" strokeWidth="0.2" />
          <circle cx="50" cy="50" r="36" fill="none" stroke="#A86137" strokeWidth="0.2" />
          <circle cx="50" cy="50" r="24" fill="none" stroke="#A86137" strokeWidth="0.2" />
        </svg>
        <div style={{
          maxWidth: 1200, margin: "0 auto",
          padding: "clamp(60px, 8vw, 112px) clamp(18px, 4vw, 44px)",
          display: "grid", gridTemplateColumns: "minmax(0,1fr) minmax(0,1fr)",
          gap: "clamp(32px, 4vw, 72px)", alignItems: "center",
          position: "relative",
        }} className="sell-hero-grid">
          <div>
            <button onClick={onHome} style={{ fontSize: 12, color: "#9A948A", letterSpacing: "0.14em", textTransform: "uppercase", marginBottom: 24 }}>
              ← Back to home
            </button>
            <div className="eyebrow" style={{ color: "#A86137" }}>Sell to Brytez</div>
            <span className="gold-rule" />
            <h1 className="serif" style={{
              fontSize: "clamp(38px, 5vw, 68px)", lineHeight: 1.04,
              margin: "10px 0 18px", color: "#F4F2EF", fontWeight: 500, textWrap: "balance",
            }}>
              Sell your watch <em style={{ color: "#A86137", fontStyle: "italic" }}>face to face,</em><br/>
              here in Miami.
            </h1>
            <p style={{ color: "#B8B2A6", fontSize: 16, lineHeight: 1.65, maxWidth: 520, textWrap: "pretty" }}>
              Whether you've owned the piece for twelve months or twelve years, you deal with a specialist directly — no consignment, no auction fees, no waiting for a buyer to show up.
            </p>
          </div>

          {/* Wizard card */}
          <div style={{
            background: "#fff", color: "var(--ink)",
            padding: "clamp(26px, 3vw, 40px)",
            position: "relative",
          }}>
            <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 18 }}>
              <div className="eyebrow" style={{ color: "var(--gold-deep)" }}>Get a valuation</div>
              <div style={{ fontSize: 12, color: "var(--muted)" }}>Step {step} of 3</div>
            </div>
            {/* Progress */}
            <div style={{ display: "flex", gap: 6, marginBottom: 26 }}>
              {[1,2,3].map(i => (
                <div key={i} style={{
                  flex: 1, height: 2,
                  background: i <= step ? "var(--gold)" : "var(--rule)",
                  transition: "background .3s ease",
                }} />
              ))}
            </div>

            {step === 1 && (
              <div style={{ display: "grid", gap: 14 }}>
                <h3 className="serif" style={{ fontSize: 22, margin: "0 0 4px", color: "var(--ink)", fontWeight: 500 }}>Tell us about the watch</h3>
                <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 14 }}>
                  <Field label="Brand" value={form.brand} onChange={v => set("brand", v)} placeholder="e.g. Rolex" />
                  <Field label="Model" value={form.model} onChange={v => set("model", v)} placeholder="e.g. Submariner" />
                </div>
                <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 14 }}>
                  <Field label="Reference" value={form.ref} onChange={v => set("ref", v)} placeholder="e.g. 126610LN" />
                  <Field label="Year" value={form.year} onChange={v => set("year", v)} placeholder="2022" />
                </div>
                <PrimaryButton full onClick={() => setStep(2)}>Continue</PrimaryButton>
              </div>
            )}
            {step === 2 && (
              <div style={{ display: "grid", gap: 16 }}>
                <h3 className="serif" style={{ fontSize: 22, margin: "0 0 4px", color: "var(--ink)", fontWeight: 500 }}>Condition & accessories</h3>
                <div>
                  <div style={{ fontSize: 11, letterSpacing: "0.14em", textTransform: "uppercase", color: "var(--muted)", marginBottom: 8 }}>Condition</div>
                  <div style={{ display: "flex", gap: 8, flexWrap: "wrap" }}>
                    {["Unworn", "Mint", "Excellent", "Very Good", "Fair"].map(c => (
                      <button key={c} onClick={() => set("condition", c)} style={{
                        padding: "8px 14px",
                        border: `1px solid ${form.condition === c ? "var(--green)" : "var(--rule)"}`,
                        background: form.condition === c ? hexA("#212A3D", 0.06) : "#fff",
                        color: form.condition === c ? "var(--green)" : "var(--ink)",
                        fontSize: 12, letterSpacing: "0.08em",
                        transition: "all .15s ease",
                      }}>{c}</button>
                    ))}
                  </div>
                </div>
                <div style={{ display: "grid", gap: 10 }}>
                  <Check checked={form.box} onToggle={() => set("box", !form.box)} label="Original box included" />
                  <Check checked={form.papers} onToggle={() => set("papers", !form.papers)} label="Original papers / warranty card" />
                </div>
                <div style={{ display: "flex", gap: 10 }}>
                  <GhostButton onClick={() => setStep(1)}>Back</GhostButton>
                  <PrimaryButton full onClick={() => setStep(3)}>Continue</PrimaryButton>
                </div>
              </div>
            )}
            {step === 3 && (
              <div style={{ display: "grid", gap: 14 }}>
                <h3 className="serif" style={{ fontSize: 22, margin: "0 0 4px", color: "var(--ink)", fontWeight: 500 }}>How should we reach you?</h3>
                <Field label="Your name" value={form.name} onChange={v => set("name", v)} placeholder="Marcus Thompson" />
                <Field label="Phone or email" value={form.contact} onChange={v => set("contact", v)} placeholder="Best phone or email to reach you" />
                <div style={{
                  fontSize: 13, color: "var(--text)", background: "var(--paper)", padding: 14,
                  borderLeft: "2px solid var(--gold)",
                }}>
                  Your details go straight to a specialist on WhatsApp — you'll get an offer
                  based on the exact piece, not an automated estimate. We confirm it in person,
                  once we've seen the watch.
                </div>
                <PrimaryButton full icon={<IconWhatsApp size={18} color="#fff" />} onClick={() => onInquire({
                  kind: "sell",
                  watch: [form.brand, form.model, form.ref].filter(Boolean).join(" ").trim(),
                  prefill: { name: form.name, contact: form.contact },
                  message: "I'd like an offer for the watch described below.",
                  details: [
                    ["Brand", form.brand],
                    ["Model", form.model],
                    ["Reference", form.ref],
                    ["Year", form.year],
                    ["Condition", form.condition],
                    ["Box", form.box ? "Yes" : "No"],
                    ["Papers", form.papers ? "Yes" : "No"],
                  ],
                })}>
                  Submit for an offer
                </PrimaryButton>
                <button onClick={() => setStep(1)} style={{ fontSize: 12, color: "var(--muted)", textDecoration: "underline", marginTop: 4 }}>
                  Start over
                </button>
              </div>
            )}
          </div>
        </div>
        <style>{`@media (max-width: 900px) { .sell-hero-grid { grid-template-columns: 1fr !important; } }`}</style>
      </section>

      {/* Process — full */}
      <section style={{ padding: "clamp(60px, 8vw, 104px) clamp(18px, 4vw, 44px)" }}>
        <div style={{ maxWidth: 1200, margin: "0 auto" }}>
          <div style={{ textAlign: "center", marginBottom: 64 }}>
            <div className="eyebrow" style={{ color: "var(--gold-deep)" }}>Our Process</div>
            <span className="gold-rule" style={{ margin: "14px auto" }} />
            <h2 className="serif" style={{ fontSize: "clamp(30px, 3.4vw, 46px)", margin: "6px 0 0", color: "var(--ink)", lineHeight: 1.1 }}>
              Four steps, no surprises.
            </h2>
          </div>
          <div style={{
            display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(220px, 1fr))",
            gap: "clamp(20px, 2.2vw, 40px)",
          }}>
            {[
              { n: "01", t: "Submit details", b: "Photos, reference and condition — four minutes via our form or WhatsApp." },
              { n: "02", t: "Get an offer", b: "A specialist comes back on WhatsApp with an offer in writing for the exact piece." },
              { n: "03", t: "Meet in Miami", b: "If the number works for you, we agree a time and place and go over the watch together." },
              { n: "04", t: "Inspect and settle", b: "Once we've both looked it over and agreed, you're paid then and there, the way we arranged." },
            ].map(s => (
              <div key={s.n} style={{ borderTop: "1px solid var(--gold)", paddingTop: 20 }}>
                <div className="serif" style={{ fontSize: 42, fontStyle: "italic", color: hexA("#A86137", 0.6), lineHeight: 1 }}>
                  {s.n}
                </div>
                <div className="serif" style={{ fontSize: 22, color: "var(--ink)", fontWeight: 500, margin: "12px 0 8px" }}>{s.t}</div>
                <div style={{ fontSize: 14, color: "var(--text)", lineHeight: 1.6, textWrap: "pretty" }}>{s.b}</div>
              </div>
            ))}
          </div>
        </div>
      </section>

      {/* Brands accepted */}
      <section style={{ padding: "clamp(50px, 6vw, 84px) clamp(18px, 4vw, 44px)", background: "var(--paper)" }}>
        <div style={{ maxWidth: 1200, margin: "0 auto", textAlign: "center" }}>
          <div className="eyebrow" style={{ color: "var(--gold-deep)" }}>Brands we actively buy</div>
          <span className="gold-rule" style={{ margin: "14px auto" }} />
          <h3 className="serif" style={{ fontSize: "clamp(22px, 2.4vw, 32px)", margin: "6px 0 32px", color: "var(--ink)", fontWeight: 500 }}>
            From modern sport to grand complication.
          </h3>
          <div style={{ display: "flex", justifyContent: "center", gap: "clamp(24px, 4vw, 56px)", flexWrap: "wrap" }}>
            {["Rolex", "Audemars Piguet", "Patek Philippe", "Vacheron Constantin", "F.P. Journe", "Omega"].map(b => (
              <div key={b} className="serif" style={{
                fontSize: "clamp(18px, 2vw, 24px)", color: "var(--ink)",
                fontStyle: "italic", opacity: 0.8,
              }}>{b}</div>
            ))}
          </div>
        </div>
      </section>

    </main>
  );
};

const Check = ({ checked, onToggle, label }) => (
  <button onClick={onToggle} style={{
    display: "flex", alignItems: "center", gap: 12, padding: "10px 0",
    textAlign: "left",
  }}>
    <span style={{
      width: 18, height: 18, border: `1.5px solid ${checked ? "var(--green)" : "var(--rule)"}`,
      background: checked ? "var(--green)" : "#fff",
      display: "grid", placeItems: "center",
      transition: "all .15s ease",
    }}>
      {checked && <svg width="10" height="10" viewBox="0 0 10 10"><path d="M1 5l3 3 5-6" fill="none" stroke="#fff" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" /></svg>}
    </span>
    <span style={{ fontSize: 14, color: "var(--ink)" }}>{label}</span>
  </button>
);

Object.assign(window, { SellPage });
