/* legal.jsx — shared renderer for Gigi Money's legal documents.
   Each HTML shell sets window.GIGI_LEGAL_DOC ('privacy' | 'terms' | 'disclosures')
   before this script mounts, and this file renders the matching document inside
   the standard site chrome (GNav + GFooter).

   NOTE FOR REVIEW: this copy is a structured first draft written to be accurate
   to Gigi's model (rent-receivables purchase + DCP-regulated credit). It still
   needs sign-off by Kenyan counsel before publishing. Every company-specific
   fact that we don't yet have in code is rendered as a visible <Todo> marker so
   it can't be shipped by accident — search the rendered page (or this file) for
   "TODO:" to find them all. */
const { Icon } = window.GigiMoneyDesignSystem_b54949;

/* Visible, impossible-to-miss placeholder for facts pending confirmation. */
function Todo({ children }) {
  return <mark className="legal-todo" title="Confirm before publishing">TODO: {children}</mark>;
}

/* The registered entity. Suffix is the standard Kenyan form; confirm the exact
   registered name and number before publishing. */
const ENTITY = 'Gigi Money Limited';

/* ── Document content ──
   Each doc: { title, updated, intro, sections: [{ id, h, blocks }] }.
   A block is a string (paragraph), { h: '…' } (sub-heading), or { ul: […] }
   (bullet list). List items and paragraphs may contain JSX. */
const DOCS = {
  privacy: {
    eyebrow: 'Privacy',
    title: 'Privacy Policy',
    updated: 'June 2026',
    intro: <>This policy explains what personal data {ENTITY} (&ldquo;Gigi Money&rdquo;, &ldquo;we&rdquo;, &ldquo;us&rdquo;) collects from property owners, tenants and partners, why we collect it, and the rights you have under the Kenya Data Protection Act, 2019. We are registered with the Office of the Data Protection Commissioner (ODPC), registration number <Todo>ODPC registration no.</Todo>.</>,
    sections: [
      {
        id: 'who', h: '1. Who we are',
        blocks: [
          <>{ENTITY} is a financial-technology company based in Nairobi, Kenya, licensed and regulated. We are the data controller for the personal data described in this policy.</>,
          <>You can reach our Data Protection Officer at <a href="mailto:privacy@gigi.money">privacy@gigi.money</a>, or by post at <Todo>registered physical address</Todo>.</>,
        ],
      },
      {
        id: 'collect', h: '2. The data we collect',
        blocks: [
          'We collect only what we need to assess eligibility, fund and service our products, and meet our legal obligations:',
          { ul: [
            <><b>Identity &amp; contact</b> — name, national ID or passport number, KRA PIN, phone number, email and postal address.</>,
            <><b>Property &amp; ownership</b> — title details and ownership confirmation obtained via the national land registry (Ardhi&nbsp;Sasa), property address and valuation inputs.</>,
            <><b>Tenancy &amp; rent</b> — lease terms, rent amounts and your verified rent roll, including tenant payment history.</>,
            <><b>Financial &amp; payment</b> — M-Pesa or bank details for disbursement and collection, and transaction records.</>,
            <><b>Usage &amp; device</b> — pages visited, form submissions, and device/security signals (including App Check attestations used to prevent fraud and abuse).</>,
          ] },
        ],
      },
      {
        id: 'use', h: '3. How and why we use it',
        blocks: [
          { ul: [
            'To verify your identity and confirm property ownership via Ardhi Sasa.',
            'To assess eligibility, price an offer, and underwrite a rent advance, guarantee, HELOC or credit card.',
            'To disburse funds and to collect repayment from rent as agreed.',
            'To prevent fraud, money laundering and abuse, and to keep your account secure.',
            'To meet our legal, regulatory and reporting obligations as a licensed and regulated business.',
            'To contact you about your application or account, and — only where you have agreed — about other Gigi products.',
          ] },
          <><b>Legal basis.</b> We process your data to perform our contract with you, to comply with our legal obligations, for our legitimate interest in operating and securing the service, and — for optional marketing — on the basis of your consent, which you can withdraw at any time.</>,
        ],
      },
      {
        id: 'share', h: '4. When we share data',
        blocks: [
          'We do not sell your personal data. We share it only with:',
          { ul: [
            <><b>Verification and registry services</b>, including Ardhi&nbsp;Sasa, to confirm ownership.</>,
            <><b>Payment providers</b> (such as M-Pesa and banks) to disburse and collect funds.</>,
            <><b>Funding and lending partners</b> who finance the advances, under strict confidentiality.</>,
            <><b>Service providers</b> (hosting, analytics, customer support) acting on our instructions.</>,
            <><b>Regulators, courts and authorities</b> where we are required by law to disclose.</>,
          ] },
          'Where a property is managed by a partner agency you have authorised, we share only what is needed to service your facility.',
        ],
      },
      {
        id: 'retain', h: '5. How long we keep it',
        blocks: [
          'We keep your data only as long as needed for the purposes above and to meet legal and regulatory retention requirements (for financial records, generally up to seven years after your relationship with us ends). After that, we securely delete or anonymise it.',
        ],
      },
      {
        id: 'security', h: '6. How we protect it',
        blocks: [
          'We protect your data with encryption in transit and at rest, access controls, and continuous monitoring. Form submissions are protected by anti-fraud attestation, and access to your records is limited to staff who need it to serve you.',
        ],
      },
      {
        id: 'rights', h: '7. Your rights',
        blocks: [
          'Under the Data Protection Act, 2019, you have the right to:',
          { ul: [
            'be informed of how your data is used;',
            'access the personal data we hold about you;',
            'ask us to correct inaccurate or incomplete data;',
            'ask us to delete data where there is no lawful reason to keep it;',
            'object to or restrict certain processing, and withdraw consent for marketing.',
          ] },
          <>To exercise any of these, email <a href="mailto:privacy@gigi.money">privacy@gigi.money</a>. If you are not satisfied with our response, you may lodge a complaint with the Office of the Data Protection Commissioner at <a href="https://www.odpc.go.ke" target="_blank" rel="noopener">odpc.go.ke</a>.</>,
        ],
      },
      {
        id: 'cookies', h: '8. Cookies & analytics',
        blocks: [
          'We use a small number of cookies and similar technologies to keep the site secure and to understand how it is used so we can improve it. You can control cookies through your browser settings.',
        ],
      },
      {
        id: 'changes', h: '9. Changes to this policy',
        blocks: [
          'We may update this policy from time to time. We will post the updated version here and change the date above. Significant changes will be communicated to you directly where appropriate.',
        ],
      },
    ],
  },

  terms: {
    eyebrow: 'Terms',
    title: 'Eligibility & Service Terms',
    updated: 'June 2026',
    intro: <>These terms govern your use of the products offered by {ENTITY} (&ldquo;Gigi Money&rdquo;). Please read them alongside our <a href="disclosures.html">Lending Disclosures</a> and <a href="privacy.html">Privacy Policy</a>. By applying for or using a Gigi product, you agree to these terms.</>,
    sections: [
      {
        id: 'eligibility', h: '1. Who can apply',
        blocks: [
          'To use a Gigi product you must:',
          { ul: [
            'be at least 18 years old and legally able to enter a contract;',
            'be the verified owner of the property (or duly authorised to act for the owner), confirmed via Ardhi Sasa;',
            'hold a genuine tenancy with verifiable rent; and',
            'pass our identity, eligibility and underwriting checks.',
          ] },
          'Approval, amounts and pricing are always subject to verification and underwriting, and we may decline an application at our discretion.',
        ],
      },
      {
        id: 'products', h: '2. What our products are',
        blocks: [
          { h: 'Rent advance — a purchase of future rent, not a loan' },
          'A rent advance is an assignment and purchase of your future rent receivables at a discount. You receive a lump sum today and assign up to 24 months of agreed future rent to us. It does not create a mortgage or charge over your property, and ownership of the title stays with you.',
          { h: 'HELOC and credit card — regulated credit' },
          'Our property HELOC and home-equity credit card are regulated credit facilities. They are secured against your property equity and serviced by your verified rent roll. The applicable interest, fees and the total cost of credit are disclosed to you before you accept.',
          { h: 'Rent guarantee — a service' },
          'Under rent guarantee, your tenant pays a recurring fee instead of a deposit, your rent is paid to you on schedule, and we manage recovery if a tenant falls behind, on the terms of your agreement.',
        ],
      },
      {
        id: 'process', h: '3. Application & verification',
        blocks: [
          'When you apply we verify your identity, confirm ownership through Ardhi Sasa, and review your rent roll. You agree that the information you provide is true and complete, and that we may rely on it and on third-party verification in making our decision.',
        ],
      },
      {
        id: 'pricing', h: '4. Pricing & fees',
        blocks: [
          'The cost of a rent advance is the discount applied to your future rent. For credit products, the cost is the interest and any fees disclosed to you. We show every charge in full before you agree. We do not charge monthly account fees. Estimates and representative examples shown on this site are illustrative and are not an offer.',
        ],
      },
      {
        id: 'repayment', h: '5. Repayment & collection',
        blocks: [
          'A rent advance is repaid from the rent you have assigned, as it is collected. Credit facilities are repaid on the schedule in your agreement, serviced from collected rent. You authorise the agreed collection arrangements for the rent covered by your facility.',
        ],
      },
      {
        id: 'obligations', h: '6. Your responsibilities',
        blocks: [
          { ul: [
            'keep your tenancy and rent roll accurate, and tell us promptly of material changes (for example, a tenant leaving or the property being sold);',
            'not assign the same rent to anyone else for the period covered by your facility;',
            'maintain the property and any insurance required by your agreement; and',
            'use the facility lawfully and not for any prohibited purpose.',
          ] },
        ],
      },
      {
        id: 'default', h: '7. If something goes wrong',
        blocks: [
          <>If assigned rent is not collected — for example because a tenant defaults — we follow the recovery process set out in your agreement and in our Lending Disclosures. Your obligations, and any recourse we have to you, are limited to what that agreement states. We explain this in plain language in our <a href="risk.html">owner risk &amp; recourse guide</a>.</>,
        ],
      },
      {
        id: 'cancellation', h: '8. Cancellation',
        blocks: [
          'You may decline an offer at any time before you accept it, at no cost. Once a facility is funded, the terms of your agreement, including any cooling-off rights, apply.',
        ],
      },
      {
        id: 'liability', h: '9. Liability',
        blocks: [
          'We provide our services with reasonable skill and care. To the extent permitted by law, we are not liable for losses that were not reasonably foreseeable or that arise from circumstances outside our control. Nothing in these terms excludes liability that cannot be excluded under Kenyan law.',
        ],
      },
      {
        id: 'law', h: '10. Governing law & disputes',
        blocks: [
          'These terms are governed by the laws of Kenya. We aim to resolve any concern quickly and fairly — please contact us first (see Complaints in our Lending Disclosures). Disputes that cannot be resolved are subject to the jurisdiction of the courts of Kenya.',
        ],
      },
      {
        id: 'changes', h: '11. Changes',
        blocks: [
          'We may update these terms from time to time. The current version is always published here with the date it took effect. Material changes affecting an active facility will be communicated to you directly.',
        ],
      },
    ],
  },

  disclosures: {
    eyebrow: 'Lending disclosures',
    title: 'Lending Disclosures',
    updated: 'June 2026',
    intro: <>{ENTITY} is licensed and regulated. These disclosures summarise the cost, terms, risks and your recourse for our products.</>,
    sections: [
      {
        id: 'regulation', h: '1. Licensing & regulation',
        blocks: [
          <>We are a licensed and regulated business, and we are registered with the Office of the Data Protection Commissioner (registration no. <Todo>ODPC registration no.</Todo>). We lend responsibly and price every facility on its merits.</>,
        ],
      },
      {
        id: 'cost', h: '2. The total cost — a representative example',
        blocks: [
          'For a rent advance, the only cost is the discount on your future rent. There are no monthly account fees and no hidden charges.',
          { ul: [
            <>You assign <b>6 months</b> of rent at <b>KES 250,000/month</b> (gross future rent <b>KES 1,500,000</b>).</>,
            <>We apply a discount of <b>KES 135,000</b>.</>,
            <>You receive <b>KES 1,365,000</b> today — a <b>total cost of 9.0% over 6 months</b>.</>,
          ] },
          'This example is illustrative. Your actual rate depends on the verified rent and the assessed risk of the tenancy. For credit facilities (HELOC and credit card), the interest rate, fees and total cost of credit are disclosed to you in full before you accept.',
        ],
      },
      {
        id: 'pricing', h: '3. How pricing is set',
        blocks: [
          'Pricing reflects our cost of funding and the assessed default risk of each tenancy. We disclose every charge before you agree, and the figure you accept is the figure you pay — we do not add fees afterwards.',
        ],
      },
      {
        id: 'security', h: '4. What you assign or secure',
        blocks: [
          'A rent advance assigns your future rent receivables for the agreed period; it does not place a mortgage or charge on your title, and ownership stays with you. A HELOC or credit card is secured against your property equity as described in your agreement. We confirm ownership via Ardhi Sasa before funding.',
        ],
      },
      {
        id: 'risks', h: '5. Key risks to understand',
        blocks: [
          'Before you take a facility, make sure you understand that:',
          { ul: [
            'bringing future rent forward means that rent is committed — you will not receive it again during the assigned period;',
            'if a tenant defaults, the recovery process in your agreement applies, and depending on the product you may have obligations to us;',
            'for secured credit, missing repayments can affect your equity and may be reported to credit reference bureaus;',
            'amounts and rates shown on this site are estimates, not offers.',
          ] },
          <>We explain what each of these means for you, in plain language, in our <a href="risk.html">owner risk &amp; recourse guide</a>.</>,
        ],
      },
      {
        id: 'recovery', h: '6. Default & recovery',
        blocks: [
          'If a tenant falls behind, we follow a fair, lawful recovery process and keep you informed. We do not use harassment, threats, or unlawful collection practices. Any recourse we have to you is limited to what your agreement sets out.',
        ],
      },
      {
        id: 'complaints', h: '7. Complaints & recourse',
        blocks: [
          'If something is wrong, we want to fix it:',
          { ul: [
            <><b>Talk to us first</b> — email <a href="mailto:complaints@gigi.money">complaints@gigi.money</a> or call <Todo>support phone no.</Todo>. We aim to acknowledge within 2 business days and resolve promptly.</>,
            <><b>Central Bank of Kenya</b> — if your complaint relates to a credit facility and remains unresolved, you may escalate to the CBK at <a href="https://www.centralbank.go.ke" target="_blank" rel="noopener">centralbank.go.ke</a>.</>,
            <><b>Data Protection Commissioner</b> — for concerns about your personal data, contact the ODPC at <a href="https://www.odpc.go.ke" target="_blank" rel="noopener">odpc.go.ke</a>.</>,
          ] },
        ],
      },
      {
        id: 'responsible', h: '8. Responsible lending',
        blocks: [
          'We only fund what the verified rent can support, and we will not knowingly put you into a facility that is not suitable for you. If your circumstances change, contact us early — we would rather work something out than see you struggle.',
        ],
      },
    ],
  },
};

function Block(b, i) {
  if (typeof b === 'string' || React.isValidElement(b)) return <p key={i} className="legal-p">{b}</p>;
  if (b.h) return <h3 key={i} className="legal-h3">{b.h}</h3>;
  if (b.ul) return <ul key={i} className="legal-ul">{b.ul.map((li, j) => <li key={j}>{li}</li>)}</ul>;
  return null;
}

function LegalPage() {
  const doc = DOCS[window.GIGI_LEGAL_DOC] || DOCS.privacy;
  return (
    <div className="g-root">
      <window.GNav active={null} />
      <main className="legal-wrap">
        <div className="wrap legal-inner">
          <aside className="legal-side">
            <span className="eyebrow"><span className="dot" /> {doc.eyebrow}</span>
            <h1 className="legal-title">{doc.title}</h1>
            <p className="legal-updated">Last updated {doc.updated} · {ENTITY}</p>
            <nav className="legal-toc" aria-label="On this page">
              {doc.sections.map(s => <a key={s.id} href={`#${s.id}`}>{s.h}</a>)}
            </nav>
            <div className="legal-docs">
              <a href="privacy.html" className={window.GIGI_LEGAL_DOC === 'privacy' ? 'cur' : ''}>Privacy Policy</a>
              <a href="terms.html" className={window.GIGI_LEGAL_DOC === 'terms' ? 'cur' : ''}>Eligibility &amp; Service Terms</a>
              <a href="disclosures.html" className={window.GIGI_LEGAL_DOC === 'disclosures' ? 'cur' : ''}>Lending Disclosures</a>
            </div>
          </aside>

          <article className="legal-body">
            <p className="legal-intro">{doc.intro}</p>
            {doc.sections.map(s => (
              <section className="legal-sec" id={s.id} key={s.id}>
                <h2 className="legal-h2">{s.h}</h2>
                {s.blocks.map(Block)}
              </section>
            ))}
            <div className="legal-foot">
              <span className="li"><Icon name="shield" size={16} /></span>
              <p>This page is for information and does not replace the specific terms of your agreement. For anything you&rsquo;re unsure about, email <a href="mailto:hello@gigi.money">hello@gigi.money</a>.</p>
            </div>
          </article>
        </div>
      </main>
      <window.GFooter />
    </div>
  );
}

ReactDOM.createRoot(document.getElementById('root')).render(<LegalPage />);
