// Legal modal — Privacy / Disclaimer / Terms / Imprint / Contact
// Required for Meta ads in the EU (GDPR + DSA + Spanish/German imprint laws).
// Replace [PLACEHOLDER] tokens before launch.

function LegalModal({ open, kind, onClose }) {
  React.useEffect(() => {
    if (!open) return;
    const onKey = (e) => { if (e.key === "Escape") onClose(); };
    window.addEventListener("keydown", onKey);
    document.body.style.overflow = "hidden";
    return () => {
      window.removeEventListener("keydown", onKey);
      document.body.style.overflow = "";
    };
  }, [open, onClose]);

  if (!open) return null;

  const content = LEGAL_CONTENT[kind] || LEGAL_CONTENT.privacy;

  return (
    <div className="legal-overlay" onClick={onClose} role="dialog" aria-modal="true">
      <div className="legal-modal" onClick={(e) => e.stopPropagation()}>
        <button className="legal-close" onClick={onClose} aria-label="Close">
          <svg viewBox="0 0 24 24" width="20" height="20"><path d="M6 6l12 12M6 18L18 6" stroke="currentColor" strokeWidth="2" fill="none"/></svg>
        </button>
        <div className="legal-eyebrow">{content.eyebrow}</div>
        <h2 className="legal-title">{content.title}</h2>
        <div className="legal-body">
          {content.body.map((block, i) => {
            if (block.h) return <h3 key={i}>{block.h}</h3>;
            if (block.p) return <p key={i}>{block.p}</p>;
            if (block.ul) return <ul key={i}>{block.ul.map((li, j) => <li key={j}>{li}</li>)}</ul>;
            return null;
          })}
        </div>
        <div className="legal-footer">
          <span>Last updated: May 2026</span>
          <button className="legal-close-btn" onClick={onClose}>Close</button>
        </div>
      </div>
    </div>
  );
}

const LEGAL_CONTENT = {
  privacy: {
    eyebrow: "GDPR · ePrivacy",
    title: "Privacy Policy",
    body: [
      { p: "Cashy respects your privacy. This page explains what we collect, why, and your rights under the EU General Data Protection Regulation (GDPR)." },
      { h: "1. Data controller" },
      { p: "Upscale, Poortland 66, 1046 BD Amsterdam, Netherlands. KVK 74008587. VAT NL002379319B19. Contact: Info@cashy.one." },
      { h: "2. What we collect" },
      { ul: [
        "Name and email — when you opt in to watch the breakdown video.",
        "Phone number — only when you complete the founding-cohort application, used solely to call you at the scheduled time.",
        "Application answers — revenue tier, niche, DM volume, current setup, timeline, optional outcome description.",
        "Technical data — IP address, browser, device, referrer, UTM parameters (for ad attribution).",
        "Cookies and pixels — Meta Pixel, Google Analytics 4 (only after consent)."
      ]},
      { h: "3. Why we collect it (legal basis)" },
      { ul: [
        "Consent (Art. 6(1)(a) GDPR) — for marketing emails and advertising cookies.",
        "Contract (Art. 6(1)(b) GDPR) — to deliver the strategy call you applied for.",
        "Legitimate interest (Art. 6(1)(f) GDPR) — to measure ad performance and prevent fraud."
      ]},
      { h: "4. Who sees your data" },
      { ul: [
        "Meta Platforms Ireland Ltd. — for ad measurement (Conversions API).",
        "Google Ireland Ltd. — for analytics.",
        "Our CRM provider — for storing your application securely.",
        "Calendly LLC — when you book a call.",
        "We do not sell, rent, or share your data with anyone else."
      ]},
      { h: "5. International transfers" },
      { p: "Some processors (Meta, Google, Calendly) are based in the United States. Transfers are protected by the EU–US Data Privacy Framework and Standard Contractual Clauses." },
      { h: "6. How long we keep it" },
      { p: "Application data: 24 months from submission. Ad-attribution data: 13 months. Email list: until you unsubscribe." },
      { h: "7. Your rights" },
      { p: "You can access, correct, delete, or export your data, restrict processing, or withdraw consent at any time. Email Info@cashy.one. You can also lodge a complaint with your local data protection authority — in the Netherlands this is the Autoriteit Persoonsgegevens (autoriteitpersoonsgegevens.nl)." },
      { h: "8. Cookies" },
      { p: "Non-essential cookies (Meta Pixel, Google Analytics) only fire after you accept the cookie banner. You can change your choice anytime via the cookie-settings link in the footer." }
    ]
  },
  disclaimer: {
    eyebrow: "EARNINGS · RESULTS",
    title: "Disclaimer",
    body: [
      { p: "Cashy is a software tool that automates Instagram DM replies for coaches. The information on this page describes our service and the typical results we aim for." },
      { h: "Results not guaranteed" },
      { p: "Any revenue figures, call-booking numbers, or case studies referenced reflect specific accounts and time periods. Your results will depend on your offer, audience, traffic volume, sales skill, and market conditions. We make no guarantee of any specific income, lead volume, or business outcome." },
      { h: "Founding-cohort offer" },
      { p: "The \"work free until results\" arrangement is contractual: if Cashy does not book 10 qualified calls in your first 30 days, we work for an additional 30 days at no cost. The exact qualification criteria are agreed with each founding-cohort member during onboarding and recorded in writing." },
      { h: "Not affiliated with Meta" },
      { p: "Cashy is an independent product. We are not affiliated with, endorsed by, or sponsored by Meta Platforms, Inc., Instagram, or Facebook. \"Instagram\" is a trademark of Meta Platforms, Inc." },
      { h: "No financial, legal, or medical advice" },
      { p: "Nothing on this site is financial, legal, tax, or medical advice. Consult a qualified professional before making business or financial decisions." }
    ]
  },
  terms: {
    eyebrow: "TERMS OF USE",
    title: "Terms of Service",
    body: [
      { p: "By using cashy.one and the Cashy service you agree to these terms." },
      { h: "1. Service description" },
      { p: "Cashy provides automated Instagram DM handling for coaches: replies, qualification, and Calendly booking. The service is delivered via the Cashy software platform under the supervision of Upscale (Amsterdam, Netherlands)." },
      { h: "2. Founding-cohort terms" },
      { p: "Founding-cohort members pay $0 setup. If Cashy does not book 10 qualified calls in 30 days, the service continues at no cost for an additional 30 days. If the threshold is still not met, no fees are owed. After the cohort closes, standard pricing applies and is communicated in writing." },
      { h: "3. Acceptable use" },
      { p: "You agree not to use Cashy to send spam, harass users, violate Instagram's Terms of Service, or break any applicable law. We reserve the right to terminate accounts that do." },
      { h: "4. Limitation of liability" },
      { p: "To the extent permitted by law, our total liability is limited to the fees you paid us in the 12 months prior to the claim. We are not liable for indirect, consequential, or lost-profit damages." },
      { h: "5. Governing law" },
      { p: "These terms are governed by the laws of the Netherlands. Disputes are subject to the exclusive jurisdiction of the courts of Amsterdam, Netherlands." }
    ]
  },
  imprint: {
    eyebrow: "LEGAL · IMPRESSUM",
    title: "Imprint",
    body: [
      { p: "Information required by Dutch and EU law (incl. §5 TMG for Germany, Art. 10 LSSI for Spain)." },
      { h: "Operator" },
      { p: "Upscale" },
      { p: "Poortland 66" },
      { p: "1046 BD Amsterdam, Netherlands" },
      { h: "Contact" },
      { p: "Email: Info@cashy.one" },
      { p: "Phone: +31 6 54 67 74 74" },
      { h: "Registration" },
      { p: "Chamber of Commerce (KVK): 74008587" },
      { p: "VAT ID: NL002379319B19" },
      { h: "Responsible for content" },
      { p: "Daniel, Founder. Address as above." }
    ]
  },
  contact: {
    eyebrow: "GET IN TOUCH",
    title: "Contact",
    body: [
      { p: "For partnership, press, or support questions:" },
      { p: "Email: Info@cashy.one" },
      { p: "Phone: +31 6 54 67 74 74" },
      { p: "For privacy / GDPR requests: Info@cashy.one" },
      { p: "Address: Upscale, Poortland 66, 1046 BD Amsterdam, Netherlands" },
      { p: "We reply within 2 business days." }
    ]
  }
};

window.LegalModal = LegalModal;
