/* global React, SiteIcon, Reveal */

const LEGAL_DOCS = {
  privacy: {
    eyebrow: "Legal",
    title: "Privacy Policy",
    updated: "May 12, 2026",
    effective: "May 12, 2026",
    intro: "DealAgent AI, Inc. (\u201cDealAgent,\u201d \u201cwe,\u201d \u201cus\u201d) builds an AI deal desk for ecommerce merchants. This policy explains what data we collect, how we use it, and the choices you have. It applies to our marketing site, the merchant dashboard, and the Agentic Offer API.",
    sections: [
      { id: "data-we-collect", h: "Information we collect", body: [
        { p: "We collect three categories of information:" },
        { list: [
          "Account data you provide — name, work email, company, and billing details.",
          "Merchant store data synced from your commerce platform — products, costs, inventory, orders, and customer segments — used solely to calculate margin and generate offers.",
          "Usage data — log events, device and browser metadata, and how you interact with the dashboard.",
        ] },
        { p: "We do not collect or store payment card numbers; billing is processed through your commerce platform or a PCI-compliant processor." },
      ] },
      { id: "how-we-use", h: "How we use information", body: [
        { p: "We use your information to provide and improve DealAgent: to compute contribution margin, evaluate offers against your policies, surface analytics, and support your account. We never sell your data, and we never use one merchant's store data to benefit another." },
      ] },
      { id: "ai-processing", h: "AI processing", body: [
        { p: "DealAgent uses automated models to recommend and evaluate offers. These decisions are bounded by the guardrails you set. We do not use your private store data to train shared or third-party foundation models." },
      ] },
      { id: "sharing", h: "How we share information", body: [
        { p: "We share data only with subprocessors that help us run the service (hosting, analytics, error monitoring), under contract and confidentiality. We may disclose information if required by law, or as part of a merger or acquisition, with notice to you." },
      ] },
      { id: "retention", h: "Data retention", body: [
        { p: "We retain store data for as long as your account is active. On cancellation, we delete or anonymize merchant store data within 90 days, except where retention is required for legal or accounting reasons." },
      ] },
      { id: "your-rights", h: "Your rights", body: [
        { p: "Depending on your jurisdiction, you may have the right to access, correct, export, or delete your personal data. Submit requests to privacy@dealagent.ai and we will respond within 30 days." },
      ] },
      { id: "security", h: "Security", body: [
        { p: "We protect your data with encryption in transit and at rest, least-privilege access controls, and continuous monitoring. See our Security page for details." },
      ] },
      { id: "contact", h: "Contact", body: [
        { p: "Questions about this policy? Email privacy@dealagent.ai or write to DealAgent AI, Inc., 2261 Market Street, San Francisco, CA." },
      ] },
    ],
  },

  terms: {
    eyebrow: "Legal",
    title: "Terms of Service",
    updated: "May 12, 2026",
    effective: "May 12, 2026",
    intro: "These Terms govern your access to and use of DealAgent\u2019s software, dashboard, and APIs. By installing the app or creating an account, you agree to these Terms on behalf of your business.",
    sections: [
      { id: "accounts", h: "Accounts & eligibility", body: [
        { p: "You must be authorized to bind your business and to connect your commerce store to DealAgent. You are responsible for activity under your account and for keeping credentials secure." },
      ] },
      { id: "the-service", h: "The service", body: [
        { p: "DealAgent evaluates carts and generates private, margin-safe offers based on policies you configure. You remain responsible for the policies you set and for compliance with applicable pricing, tax, and consumer-protection laws." },
      ] },
      { id: "offers", h: "Offers & merchant control", body: [
        { p: "DealAgent will not approve an offer that violates the guardrails you define. You can pause, edit, or revoke any policy at any time. Offers generated by DealAgent are extended on your behalf and at your discretion." },
      ] },
      { id: "billing", h: "Fees & billing", body: [
        { p: "Plan fees and any performance-based fees are described on our Pricing page and billed through your commerce platform. Fees are non-refundable except where required by law. We may change pricing with 30 days\u2019 notice." },
      ] },
      { id: "acceptable-use", h: "Acceptable use", body: [
        { p: "You agree not to misuse the service, reverse-engineer it, or use it to set deceptive or unlawful prices. We may suspend accounts that violate these Terms or put the platform at risk." },
      ] },
      { id: "ip", h: "Intellectual property", body: [
        { p: "DealAgent and its software remain our property. Your store data remains yours; you grant us a limited license to process it solely to provide the service." },
      ] },
      { id: "warranty", h: "Disclaimers & liability", body: [
        { p: "The service is provided \u201cas is.\u201d To the maximum extent permitted by law, DealAgent is not liable for indirect or consequential damages, and our aggregate liability is limited to the fees you paid in the prior 12 months." },
      ] },
      { id: "termination", h: "Termination", body: [
        { p: "You may cancel at any time. We may terminate for breach or non-payment. On termination, your right to use the service ends and we handle your data as described in the Privacy Policy." },
      ] },
    ],
  },

  security: {
    eyebrow: "Legal",
    title: "Security",
    updated: "May 12, 2026",
    effective: "May 12, 2026",
    intro: "Merchants trust DealAgent with margin-sensitive commerce data. We treat that as a responsibility, not a checkbox. Here is how we protect it.",
    sections: [
      { id: "infrastructure", h: "Infrastructure", body: [
        { p: "DealAgent runs on SOC 2-compliant cloud infrastructure with isolated environments, automated patching, and continuous monitoring. Production access is restricted and logged." },
      ] },
      { id: "encryption", h: "Encryption", body: [
        { p: "All data is encrypted in transit with TLS 1.2+ and at rest with AES-256. Secrets and API keys are stored in a managed secrets vault, never in source code." },
      ] },
      { id: "access", h: "Access control", body: [
        { list: [
          "Least-privilege, role-based access for all internal systems.",
          "Mandatory SSO and multi-factor authentication for employees.",
          "Read-only by default for store data; writes require an approved policy.",
        ] },
      ] },
      { id: "data-handling", h: "Data handling", body: [
        { p: "Merchant store data is logically isolated per account. We never use one merchant's data to benefit another, and we do not train shared models on your private data." },
      ] },
      { id: "compliance", h: "Compliance & audits", body: [
        { p: "We maintain SOC 2 Type II, undergo regular third-party penetration testing, and support GDPR and CCPA data-subject requests. Enterprise customers can request our compliance package and sign a DPA." },
      ] },
      { id: "disclosure", h: "Responsible disclosure", body: [
        { p: "Found a vulnerability? Email security@dealagent.ai. We investigate every report, and we will not pursue legal action against good-faith research." },
      ] },
    ],
  },
};

function LegalPage({ doc }) {
  const d = LEGAL_DOCS[doc] || LEGAL_DOCS.privacy;
  const [active, setActive] = React.useState(d.sections[0].id);

  React.useEffect(() => {
    const obs = new IntersectionObserver(
      (entries) => {
        entries.forEach((e) => { if (e.isIntersecting) setActive(e.target.id); });
      },
      { rootMargin: "-96px 0px -65% 0px", threshold: 0 }
    );
    d.sections.forEach((s) => { const el = document.getElementById(s.id); if (el) obs.observe(el); });
    return () => obs.disconnect();
  }, [doc]);

  const Dot = () => <SiteIcon name="check" size={14} stroke={2.5}/>;

  return (
    <>
      <header className="doc-hero">
        <div className="container">
          <Reveal><div className="eyebrow">{d.eyebrow}</div></Reveal>
          <Reveal delay={60}><h1>{d.title}</h1></Reveal>
          <Reveal delay={120}>
            <div className="meta">
              <span>Last updated <b>{d.updated}</b></span>
              <span>Effective <b>{d.effective}</b></span>
            </div>
          </Reveal>
        </div>
      </header>

      <section className="doc-wrap">
        <div className="container">
          <div className="doc-grid">
            <nav className="doc-toc">
              <div className="toc-label">On this page</div>
              <ul>
                {d.sections.map((s) => (
                  <li key={s.id}>
                    <a href={`#${s.id}`} className={active === s.id ? "active" : ""}>{s.h}</a>
                  </li>
                ))}
              </ul>
            </nav>

            <div className="doc-body">
              <p className="doc-intro">{d.intro}</p>
              {d.sections.map((s, i) => (
                <div className="doc-section" id={s.id} key={s.id}>
                  <h2><span className="num">{String(i + 1).padStart(2, "0")}</span>{s.h}</h2>
                  {s.body.map((blk, j) => (
                    blk.list
                      ? <ul className="doc-list" key={j}>{blk.list.map((li, k) => <li key={k}><Dot/>{li}</li>)}</ul>
                      : <p key={j}>{blk.p}</p>
                  ))}
                </div>
              ))}
            </div>
          </div>
        </div>
      </section>

      {window.Footer ? <window.Footer/> : null}
    </>
  );
}

window.LegalPage = LegalPage;
