// ---------- LEGAL PAGES ----------
// Privacy y Terms describen lo que el sitio hace DE VERDAD, no una plantilla:
// los datos listados salen de api/contact.js (campos, IP, Resend, Blob) y de
// index.html (Google Fonts + unpkg). Si cambia cualquiera de esos dos, esta
// página miente — actualizarla en el mismo commit.
const LEGAL_UPDATED = "July 28, 2026";

const LegalSection = ({ n, h, children }) => (
  <section style={{ marginTop: 44 }}>
    <div style={{ display: "grid", gridTemplateColumns: "auto 1fr", gap: 16, alignItems: "baseline" }}>
      <div className="serif" style={{ fontStyle: "italic", fontSize: 22, color: hexA("#A86137", 0.75), lineHeight: 1, minWidth: 30 }}>
        {String(n).padStart(2, "0")}
      </div>
      <h2 className="serif" style={{
        fontSize: "clamp(21px, 2.1vw, 27px)", lineHeight: 1.2, margin: 0,
        color: "var(--ink)", fontWeight: 500, textWrap: "balance",
      }}>{h}</h2>
    </div>
    <div style={{ marginTop: 14, paddingLeft: 46 }} className="legal-body">
      {children}
    </div>
  </section>
);

const LegalList = ({ items }) => (
  <ul style={{ listStyle: "none", padding: 0, margin: "14px 0 0", display: "grid", gap: 11 }}>
    {items.map((it, i) => (
      <li key={i} style={{ display: "grid", gridTemplateColumns: "auto 1fr", gap: 12, alignItems: "start" }}>
        <span style={{ width: 5, height: 5, background: "var(--gold)", marginTop: 9, borderRadius: "50%" }} />
        <span>{it}</span>
      </li>
    ))}
  </ul>
);

const LegalShell = ({ onHome, onNav, eyebrow, title, lede, children, otherKey, otherLabel }) => {
  React.useEffect(() => { window.scrollTo(0, 0); }, []);
  return (
    <main>
      <style>{`
        .legal-body p { font-size: 15.5px; line-height: 1.75; color: var(--text); margin: 0 0 14px; text-wrap: pretty; }
        .legal-body p:last-child { margin-bottom: 0; }
        .legal-body li { font-size: 15.5px; line-height: 1.7; color: var(--text); }
        .legal-body strong { color: var(--ink); font-weight: 500; }
        .legal-body a { color: var(--green); border-bottom: 1px solid var(--gold); }
        @media (max-width: 620px) { .legal-body { padding-left: 0 !important; } }
      `}</style>

      {/* Hero */}
      <section style={{ position: "relative", overflow: "hidden", borderBottom: "1px solid var(--rule)" }}>
        <div style={{
          position: "absolute", inset: 0,
          background: `radial-gradient(900px 460px at 78% 15%, ${hexA("#212A3D", 0.07)} 0%, transparent 62%), linear-gradient(180deg, #F4F2EF 0%, #FFFFFF 72%)`,
        }} />
        <div style={{ position: "relative", maxWidth: 820, margin: "0 auto", padding: "clamp(44px, 5.5vw, 84px) clamp(18px, 4vw, 44px) clamp(34px, 4vw, 52px)" }}>
          <button onClick={onHome} style={{ fontSize: 12, color: "var(--muted)", letterSpacing: "0.14em", textTransform: "uppercase", marginBottom: 24 }}>
            ← Back to home
          </button>
          <div className="eyebrow" style={{ color: "var(--gold-deep)" }}>{eyebrow}</div>
          <span className="gold-rule" />
          <h1 className="serif" style={{
            fontSize: "clamp(34px, 4.4vw, 56px)", lineHeight: 1.06,
            margin: "8px 0 16px", color: "var(--ink)", fontWeight: 500,
            letterSpacing: "-0.01em", textWrap: "balance",
          }}>{title}</h1>
          <p style={{ fontSize: "clamp(15px, 1.3vw, 17px)", color: "var(--text)", lineHeight: 1.65, margin: 0, textWrap: "pretty" }}>
            {lede}
          </p>
          <div style={{
            marginTop: 22, fontFamily: "var(--mono)", fontSize: 10.5,
            letterSpacing: "0.16em", textTransform: "uppercase", color: "var(--muted)",
          }}>
            Last updated {LEGAL_UPDATED}
          </div>
        </div>
      </section>

      {/* Body */}
      <section style={{ padding: "clamp(20px, 3vw, 40px) clamp(18px, 4vw, 44px) clamp(56px, 7vw, 96px)" }}>
        <div style={{ maxWidth: 820, margin: "0 auto" }}>
          {children}

          {/* Contact + cross-link */}
          <div style={{
            marginTop: 56, padding: "clamp(22px, 3vw, 32px)",
            background: "var(--paper)", borderLeft: "2px solid var(--gold)",
          }}>
            <div className="eyebrow" style={{ color: "var(--gold-deep)" }}>Questions about this page</div>
            <p style={{ fontSize: 15, color: "var(--text)", lineHeight: 1.7, margin: "12px 0 0", textWrap: "pretty" }}>
              Write to <a href={mailLink("Privacy question")} style={{ color: "var(--green)", borderBottom: "1px solid var(--gold)" }}>{GMR.email}</a> or
              {GMR.whatsapp && <> message <a href={waLink()} target="_blank" rel="noopener noreferrer" style={{ color: "var(--green)", borderBottom: "1px solid var(--gold)" }}>{GMR.phone}</a> on</>}
              WhatsApp. The same person who answers watch questions answers these.
            </p>
            {onNav && otherKey && (
              <div style={{ marginTop: 20 }}>
                <button onClick={() => onNav(otherKey)} style={{
                  fontSize: 12, letterSpacing: "0.14em", textTransform: "uppercase",
                  color: "var(--ink)", borderBottom: "1px solid var(--gold)", paddingBottom: 2,
                }}>
                  {otherLabel} →
                </button>
              </div>
            )}
          </div>
        </div>
      </section>
    </main>
  );
};

// ---------- PRIVACY ----------
const PrivacyPage = ({ onHome, onNav }) => (
  <LegalShell
    onHome={onHome}
    onNav={onNav}
    eyebrow="Privacy"
    title="What we collect, and what we don't."
    lede="Brytez is a one-to-one dealer, not a data business. This page says exactly what this site collects, where it goes and how to have it deleted — in plain language, without the usual filler."
    otherKey="terms"
    otherLabel="Read the Terms of Use"
  >
    <LegalSection n={1} h="What we collect">
      <p>Only what you type into a form, plus one technical detail. Nothing is gathered in the background.</p>
      <LegalList items={[
        <span><strong>Inquiry form:</strong> your name, a phone number or email address, your message, and the watch you're asking about.</span>,
        <span><strong>Sell form:</strong> the same contact details, plus the brand, model, reference, year and condition of your watch, and whether you have the box and papers.</span>,
        <span><strong>Newsletter:</strong> the email address you enter, nothing else.</span>,
        <span><strong>Your IP address,</strong> recorded with each submission. We use it to stop spam — the form accepts a maximum of six messages per hour from the same connection — and it appears at the bottom of the email we receive.</span>,
      ]} />
      <p style={{ marginTop: 16 }}>
        We never ask for and never receive card or bank details: there is no online payment on this site.
      </p>
    </LegalSection>

    <LegalSection n={2} h="What we don't do">
      <LegalList items={[
        "No cookies of our own, and nothing stored in your browser.",
        "No Google Analytics, no Facebook pixel, no tracking or remarketing tools of any kind.",
        "No accounts, no passwords, no profiles.",
        "We don't sell, rent or share your details with anyone for marketing. Ever.",
      ]} />
      <p style={{ marginTop: 16 }}>
        That's also why you'll never see a cookie banner here — there's nothing to accept.
      </p>
    </LegalSection>

    <LegalSection n={3} h="Where your message goes">
      <LegalList items={[
        <span>Straight to <strong>{GMR.email}</strong> as an email. The sending is handled by Resend, our email provider.</span>,
        <span>A copy is kept in <strong>private storage on Vercel</strong>, so an email outage never quietly swallows someone's message.</span>,
        <span>This site is hosted by <strong>Vercel</strong>, which keeps standard server logs — IP address, time, page requested — the same as any web server.</span>,
        <span>If you tap the WhatsApp button, the conversation moves to <strong>WhatsApp</strong> and is governed by Meta's own policies, which we don't control.</span>,
      ]} />
      <p style={{ marginTop: 16 }}>Beyond those, nothing is shared with anyone.</p>
    </LegalSection>

    <LegalSection n={4} h="Third parties that see your IP address">
      <p>
        Being straight about this: the typefaces on this site load from <strong>Google Fonts</strong> and the
        underlying code libraries load from <strong>unpkg</strong>. When the page opens, your browser connects
        to those services and they can see your IP address, as they do on any site that uses them. We send them
        nothing about you, and they set no cookies here.
      </p>
    </LegalSection>

    <LegalSection n={5} h="How long we keep it">
      <p>
        Messages are kept for up to <strong>24 months</strong> and then deleted. If you'd rather we delete
        yours sooner, just ask — see below.
      </p>
    </LegalSection>

    <LegalSection n={6} h="Your choices">
      <p>Write to us and we will, at no cost:</p>
      <LegalList items={[
        "Tell you what we hold about you.",
        "Correct anything that's wrong.",
        "Delete it, unless we're legally required to keep a record of a completed sale.",
        "Stop contacting you altogether.",
      ]} />
      <p style={{ marginTop: 16 }}>
        No forms, no ticket numbers. We answer within 30 days and usually the same business day.
      </p>
    </LegalSection>

    <LegalSection n={7} h="Age">
      <p>
        This site isn't directed at anyone under 18, and we don't knowingly collect information from
        children. If you believe a minor has sent us their details, tell us and we'll delete them.
      </p>
    </LegalSection>

    <LegalSection n={8} h="Changes to this page">
      <p>
        If what we do changes, this page changes with it and the date at the top is updated. We don't make
        changes retroactively.
      </p>
    </LegalSection>
  </LegalShell>
);

// ---------- TERMS ----------
const TermsPage = ({ onHome, onNav }) => (
  <LegalShell
    onHome={onHome}
    onNav={onNav}
    eyebrow="Terms of Use"
    title="A catalogue and a conversation — not a checkout."
    lede="The short version: everything on this site is an invitation to talk, not a binding offer. Prices and availability come from our supplier network and are confirmed with you before anything is final. The rest is below."
    otherKey="privacy"
    otherLabel="Read the Privacy Policy"
  >
    <LegalSection n={1} h="What this site is">
      <p>
        Brytez is an independent dealer in Miami, Florida. This site is a catalogue of pieces available
        through our supplier network, plus editorial writing about the market. There is no cart and no online
        payment. Every sale is agreed in a conversation with a person, over WhatsApp, phone or email.
      </p>
    </LegalSection>

    <LegalSection n={2} h="Prices and availability">
      <p>
        Prices and availability come from our suppliers and move with the market. The catalogue refreshes
        daily, but a piece can sell or change price between refreshes, and some pieces are listed without a
        price at all.
      </p>
      <p>
        Nothing listed here is a binding offer. The price and availability of any watch are confirmed with
        you directly before you commit — what we quote is what you pay.
      </p>
    </LegalSection>

    <LegalSection n={3} h="We are not an authorized dealer">
      <p>
        Brytez is not an authorized dealer for Rolex, Patek Philippe, Audemars Piguet, or any other
        brand, and is not affiliated with, endorsed by or associated with any watch manufacturer. All brand
        names, model names and logos belong to their respective owners and are used here only to describe
        the pieces we offer.
      </p>
      <p>
        A manufacturer's warranty may not apply to a watch bought outside that brand's official network.
        Any assurance you receive comes from Brytez, not from the manufacturer.
      </p>
    </LegalSection>

    <LegalSection n={4} h="Verification, and what happens if something doesn't match">
      <p>
        Every piece is checked before a sale is confirmed: serial and reference numbers against the
        supplying dealer's records, and the documentation reviewed watch by watch. You can ask for extra
        photos or a live video call before committing, and nothing is final until you're satisfied with
        what you're looking at.
      </p>
      <p>
        If something doesn't match what was described, tell your specialist before the sale closes and we
        resolve it case by case. We don't offer a blanket refund policy, and we'd rather say so here than
        promise something we can't stand behind.
      </p>
    </LegalSection>

    <LegalSection n={5} h="The Journal is editorial, not advice">
      <p>
        Articles on this site are written to be useful, not to tell you what to buy. Nothing in them is
        investment advice, a professional valuation or a guarantee of what any watch will be worth. The
        market moves in both directions.
      </p>
    </LegalSection>

    <LegalSection n={6} h="Using this site">
      <p>Please don't:</p>
      <LegalList items={[
        "Scrape, copy or republish the catalogue, in whole or in part, by automated means.",
        "Use the contact or sell forms to send spam, or to impersonate someone else.",
        "Try to interfere with the site or gain access to parts of it that aren't public.",
      ]} />
      <p style={{ marginTop: 16 }}>
        The text, photography we produce, and the design of this site belong to Brytez.
      </p>
    </LegalSection>

    <LegalSection n={7} h="Accuracy and liability">
      <p>
        This site is provided as it is. We take real care with the catalogue and the writing, but listings
        are generated from supplier data and can contain errors or go out of date. Don't rely on the site
        alone for a purchase decision — that's precisely why we confirm everything in conversation first.
      </p>
      <p>
        To the extent the law allows, Brytez isn't liable for losses arising from use of this site or
        from reliance on information published on it.
      </p>
    </LegalSection>

    <LegalSection n={8} h="Age">
      <p>This site and our services are intended for people aged 18 or over.</p>
    </LegalSection>

    <LegalSection n={9} h="Governing law">
      <p>
        These terms are governed by the laws of the State of Florida, United States. Any dispute is subject
        to the courts of Miami-Dade County, Florida.
      </p>
    </LegalSection>
  </LegalShell>
);

Object.assign(window, { PrivacyPage, TermsPage });
