// Legal pages — Ciao Bella
// Privacy, Terms, Refunds — DRAFT copy. Recommend lawyer review before launch.

// ── Shared legal page chrome ──
function LegalPage({ title, eyebrow, lastUpdated, intro, sections, navigate, currentRoute }) {
  return (
    <main className="legal-page" style={{ position: 'relative' }}>
      <section className="legal-hero">
        <div className="container">
          <div className="legal-hero-inner">
            <Pill>{eyebrow}</Pill>
            <h1 className="legal-title">{title}</h1>
            <p className="legal-updated">Last updated: {lastUpdated}</p>
            {intro && <p className="legal-intro">{intro}</p>}
          </div>
        </div>
      </section>

      <SectionDivider color="blue" />

      <section className="section legal-body-section">
        <div className="container">
          <div className="legal-layout">
            {/* TOC */}
            <aside className="legal-toc" aria-label="Sections">
              <h4>On this page</h4>
              <ol>
                {sections.map((s, i) => (
                  <li key={i}>
                    <a
                      href={`#${s.id}`}
                      onClick={(e) => {
                        e.preventDefault();
                        document.getElementById(s.id)?.scrollIntoView({ behavior: 'smooth', block: 'start' });
                      }}
                    >{s.heading}</a>
                  </li>
                ))}
              </ol>

              <div className="legal-toc-foot">
                <h4>Other legal</h4>
                <ul>
                  {currentRoute !== '/privacy' && <li><a href="#" onClick={(e) => { e.preventDefault(); navigate('/privacy'); }}>Privacy</a></li>}
                  {currentRoute !== '/terms' && <li><a href="#" onClick={(e) => { e.preventDefault(); navigate('/terms'); }}>Terms of service</a></li>}
                  {currentRoute !== '/refunds' && <li><a href="#" onClick={(e) => { e.preventDefault(); navigate('/refunds'); }}>Returns &amp; refunds</a></li>}
                </ul>
              </div>
            </aside>

            <article className="legal-body">
              {sections.map((s, i) => (
                <section key={i} id={s.id} className="legal-section">
                  <h2>{s.heading}</h2>
                  {s.body}
                </section>
              ))}

              <p className="legal-contact-line">
                Questions about this policy? Email
                {' '}<a href="mailto:info@ciaobellaphone.com.au">info@ciaobellaphone.com.au</a>
                {' '}or use our{' '}
                <a href="#" onClick={(e) => { e.preventDefault(); navigate('/contact'); }}>contact form</a>.
              </p>
            </article>
          </div>
        </div>
      </section>
    </main>
  );
}

// ── PRIVACY ─────────────────────────────────────────────
function PrivacyPage({ navigate }) {
  const sections = [
    {
      id: 'overview',
      heading: 'Overview',
      body: <>
        <p><strong>Ciao Bella</strong> is a brand of Vincent Rose Pty Ltd (ABN 39 677 320 348), a small Australian-owned business based in Australia. We (&ldquo;Ciao Bella&rdquo;, &ldquo;we&rdquo;, &ldquo;us&rdquo;) take your family&apos;s privacy seriously and we keep what we collect to the absolute minimum needed to ship you a phone, connect your calls, and answer your emails.</p>
        <p>This policy explains, in plain language, what we collect, why, how long we keep it, and what choices you have. It is written to comply with the Australian Privacy Principles under the <em>Privacy Act 1988</em> (Cth).</p>
      </>,
    },
    {
      id: 'what-we-collect',
      heading: 'What we collect',
      body: <>
        <p>We collect only what we need to do our job:</p>
        <ul>
          <li><strong>Order &amp; delivery details</strong> &mdash; your full name, shipping address (street, suburb, state, postcode), email, and phone number. Collected when you reserve or buy a Ciao Bella, used to ship the product and stay in touch about your order.</li>
          <li>
            <strong>Payment details</strong> &mdash; payments are processed by <strong>Stripe</strong>, our payment provider. We <em>never see and never store</em> your card number, expiry, or CVC. Stripe handles card data directly, in accordance with PCI-DSS standards. See{' '}
            <a href="https://stripe.com/au/privacy" target="_blank" rel="noopener noreferrer">Stripe&apos;s privacy policy</a>{' '}
            for how they handle it.
          </li>
          <li>
            <strong>Saved card for the balance charge</strong> &mdash; because Ciao Bella uses a $25 deposit model with the balance charged when your phone ships, <strong>Stripe stores your payment method on our behalf</strong> so we can charge the remaining balance at dispatch. The card data still sits with Stripe, not us. You can request removal at any time by emailing us, and your card is removed automatically once your final balance has been settled.
          </li>
          <li><strong>Order metadata we keep</strong> &mdash; the colour combination you chose, the quantity, the balance owed, the order status, and a Stripe payment-intent ID linking back to the transaction. No card data is ever stored in our metadata.</li>
          <li><strong>Account &amp; parent app data</strong> &mdash; your email, the contacts you add to your child&apos;s whitelist, your child&apos;s nickname, and call metadata (who called whom, when, for how long). We do not record or listen to call audio.</li>
          <li><strong>Customer support</strong> &mdash; emails, messages, and replies you send us, kept so we can help you and learn from common questions.</li>
        </ul>
      </>,
    },
    {
      id: 'children',
      heading: "Children's information",
      body: <>
        <p>Ciao Bella is bought by parents, for children. We do not knowingly collect personal information directly from a child. The parent who sets up the device is the account holder, and your child&apos;s nickname and contact list sit inside that account.</p>
        <p>You can request to delete your child&apos;s profile at any time by emailing us at <a href="mailto:info@ciaobellaphone.com.au">info@ciaobellaphone.com.au</a>. Within 30 days of your request, we&apos;ll remove their nickname, whitelist, voicemail messages, and call history from our servers.</p>
      </>,
    },
    {
      id: 'how-we-use',
      heading: 'How we use information',
      body: <>
        <ul>
          <li>Fulfilling your order &mdash; address, name, email.</li>
          <li>Connecting calls &mdash; whitelist contacts, your child&apos;s nickname, call metadata.</li>
          <li>Answering support emails &mdash; whatever you tell us.</li>
          <li>Improving the product &mdash; aggregated, anonymised metrics only.</li>
          <li>Sending occasional updates &mdash; only if you opted in. One-click unsubscribe in every email.</li>
        </ul>
        <p>We do not sell your personal information to third parties for their marketing purposes. Ever.</p>
      </>,
    },
    {
      id: 'sharing',
      heading: 'Who we share with',
      body: <>
        <p>The short list:</p>
        <ul>
          <li>
            <strong>Stripe</strong> &mdash; processes your payment and stores your card on our behalf for the balance charge. Stripe is PCI-DSS compliant.{' '}
            <a href="https://stripe.com/au/privacy" target="_blank" rel="noopener noreferrer">Read Stripe&apos;s privacy policy</a>.
          </li>
          <li><strong>Our shipping partner</strong> &mdash; to deliver your phone.</li>
          <li><strong>Our call carrier</strong> &mdash; to actually connect calls in and out of Ciao Bella phones.</li>
          <li><strong>Our hosting provider</strong> &mdash; to run the parent app and website.</li>
          <li><strong>Government agencies</strong> &mdash; only if compelled by Australian law.</li>
        </ul>
        <p>All of these providers handle data on our behalf and are contractually required to keep it secure and private. <strong>We never sell your personal information to third parties for their marketing.</strong></p>
      </>,
    },
    {
      id: 'storage',
      heading: 'How long we keep things',
      body: <>
        <ul>
          <li><strong>Active accounts</strong> &mdash; for as long as you have a Ciao Bella with us.</li>
          <li><strong>Saved payment method (Stripe)</strong> &mdash; held by Stripe until your final balance has been charged at dispatch, then removed automatically. You can request earlier removal at any time.</li>
          <li><strong>Call metadata</strong> &mdash; visible to you for 90 days in the parent app, then deleted from our servers.</li>
          <li><strong>Voicemail messages</strong> &mdash; 30 days, unless you delete sooner.</li>
          <li><strong>Order records</strong> &mdash; kept 7 years, as required by Australian tax law.</li>
          <li><strong>Closed accounts</strong> &mdash; personal data deleted within 30 days of closure.</li>
        </ul>
      </>,
    },
    {
      id: 'your-rights',
      heading: 'Your rights',
      body: <>
        <p>Under Australian privacy law, you have the right to:</p>
        <ul>
          <li>See what we hold about you.</li>
          <li>Correct anything that&apos;s wrong.</li>
          <li>Ask us to delete your data (subject to legal retention requirements).</li>
          <li>Lodge a complaint with the Office of the Australian Information Commissioner (OAIC) if you&apos;re unhappy with how we&apos;ve handled it.</li>
        </ul>
        <p>To exercise any of these, email <a href="mailto:info@ciaobellaphone.com.au">info@ciaobellaphone.com.au</a>.</p>
      </>,
    },
    {
      id: 'security',
      heading: 'Security',
      body: <>
        <p>We protect your information with industry-standard measures &mdash; TLS encryption in transit, encryption at rest for sensitive fields, access logging, and least-privilege internal access. If a data breach affecting you ever occurred, we&apos;d notify you and the OAIC as required by the Notifiable Data Breaches scheme.</p>
      </>,
    },
    {
      id: 'changes',
      heading: 'Changes to this policy',
      body: <>
        <p>If we make material changes to this policy, we&apos;ll email account holders and post a notice on this page at least 14 days before the change takes effect.</p>
      </>,
    },
  ];

  return (
    <LegalPage
      title="Privacy Policy"
      eyebrow="Privacy"
      lastUpdated="May 24, 2026"
      intro="A small Australian team. A short list of data. Everything we collect, why, and how to ask us to delete it."
      sections={sections}
      navigate={navigate}
      currentRoute="/privacy"
    />
  );
}

// ── TERMS ───────────────────────────────────────────────
function TermsPage({ navigate }) {
  const sections = [
    {
      id: 'who-we-are',
      heading: 'Who we are',
      body: <>
        <p>These terms are an agreement between you and <strong>Vincent Rose Pty Ltd (ABN 39 677 320 348)</strong>, the Australian company that operates the Ciao Bella brand from Australia. By placing an order, creating a parent account, or using a Ciao Bella phone or its accompanying app, you agree to these terms.</p>
        <p>If you don&apos;t agree with any part of these terms, please don&apos;t use our products. If you change your mind before your phone ships, contact us and we&apos;ll process a full refund of your deposit. After delivery, our standard returns policy applies — see the <a href="#" onClick={(e) => { e.preventDefault(); navigate('/refunds'); }}>Returns &amp; Refunds</a> page for the details.</p>
      </>,
    },
    {
      id: 'orders',
      heading: 'Orders, pre-orders & pricing',
      body: <>
        <p>All prices are in Australian dollars (AUD) and include GST. A $25 deposit reserves your Ciao Bella; the balance is charged once your phone is ready to ship. If your chosen colour or bundle is unavailable, we&apos;ll contact you before charging the balance.</p>
        <p>We aim to ship pre-orders in the order they were placed. Estimated dispatch dates are indicative only and we cannot guarantee specific delivery dates. We&apos;ll keep you posted by email if anything changes.</p>
      </>,
    },
    {
      id: 'subscriptions',
      heading: 'Subscriptions',
      body: <>
        <p>Every Ciao Bella ships with our <strong>Free</strong> plan switched on &mdash; unlimited Ciao-to-Ciao calls and one approved parent line, included forever. <strong>Ciao Plus</strong> ($14.99 / month) unlocks unlimited calls to Australian landlines and mobiles, and lets the whole whitelist call your child&apos;s Ciao Bella.</p>
        <p>Plus is billed monthly. You can cancel any time from the parent app; on cancellation, you drop back to the Free plan instantly &mdash; no contracts, no exit fees.</p>
      </>,
    },
    {
      id: 'acceptable-use',
      heading: 'Acceptable use',
      body: <>
        <p>Ciao Bella phones, our parent app, and our calling network are intended for personal, household use by Australian families. You agree not to:</p>
        <ul>
          <li>Use the service for commercial telemarketing, bulk calling, or autodialling.</li>
          <li>Attempt to access our systems without authorisation.</li>
          <li>Use the service to harass, threaten, or break Australian law.</li>
          <li>Resell, sublet, or relicense the parent app.</li>
        </ul>
        <p>We can suspend or close any account that breaches these rules.</p>
      </>,
    },
    {
      id: 'warranty',
      heading: 'Warranty & consumer rights',
      body: <>
        <p>Every Ciao Bella comes with a <strong>12-month manufacturer warranty</strong> covering defects in materials and workmanship under normal household use. This is on top of, and does not replace, the consumer guarantees you have under the Australian Consumer Law.</p>
        <p>If your phone has a problem, email us. We&apos;ll work with you to repair, replace, or refund &mdash; in line with your rights under the Australian Consumer Law.</p>
      </>,
    },
    {
      id: 'liability',
      heading: 'Limits on liability',
      body: <>
        <p>To the maximum extent permitted by law, and without limiting any non-excludable rights you have under the Australian Consumer Law, our aggregate liability for any claim relating to a Ciao Bella phone, the parent app, or our calling service is capped at the amount you paid us for the affected product or service.</p>
        <p>Ciao Bella relies on your home internet and our calling network and may not work during internet, power, or carrier outages. <strong>Do not rely on Ciao Bella as your only means of contacting emergency services.</strong> In an emergency, use a mobile or another working phone to call 000.</p>
      </>,
    },
    {
      id: 'changes',
      heading: 'Changes to these terms',
      body: <>
        <p>We may update these terms occasionally. If we change anything material, we&apos;ll email account holders and post a notice on this page at least 14 days before the change takes effect. Your continued use after that date means you accept the updated terms.</p>
      </>,
    },
    {
      id: 'governing-law',
      heading: 'Governing law',
      body: <>
        <p>These terms are governed by the laws of New South Wales, Australia. Any disputes that can&apos;t be sorted by talking go to the courts of New South Wales.</p>
      </>,
    },
  ];

  return (
    <LegalPage
      title="Terms of Service"
      eyebrow="Terms"
      lastUpdated="May 24, 2026"
      intro="The agreement between Ciao Bella and you, in human language. Read it once, then get back to being a parent."
      sections={sections}
      navigate={navigate}
      currentRoute="/terms"
    />
  );
}

// ── REFUNDS ─────────────────────────────────────────────
function RefundsPage({ navigate }) {
  const sections = [
    {
      id: 'pre-order',
      heading: 'Pre-order deposits',
      body: <>
        <p>Your $25 deposit is <strong>fully refundable</strong> at any time until your phone ships. Email us and we&apos;ll process it within two business days, back to your original payment method.</p>
        <p>If you cancel <em>after</em> we&apos;ve charged your balance but <em>before</em> we&apos;ve dispatched the phone, we&apos;ll refund both the deposit and the balance, in full.</p>
      </>,
    },
    {
      id: 'change-of-mind',
      heading: '30-day change-of-mind',
      body: <>
        <p>Once your Ciao Bella has arrived, you have <strong>30 days from the delivery date</strong> to change your mind for any reason.</p>
        <ul>
          <li>The phone should be in re-saleable condition &mdash; we don&apos;t need original packaging, but normal handling is expected.</li>
          <li>Email us to start the return; we&apos;ll send you a pre-paid return label.</li>
          <li>Once your phone arrives back with us, we refund within 5 business days to your original payment method.</li>
        </ul>
      </>,
    },
    {
      id: 'faulty',
      heading: 'Faulty phones & warranty claims',
      body: <>
        <p>Your phone is covered by a <strong>12-month manufacturer warranty</strong> in addition to the consumer guarantees under the Australian Consumer Law. If your Ciao Bella stops working through no fault of your own:</p>
        <ol>
          <li>Email <a href="mailto:info@ciaobellaphone.com.au">info@ciaobellaphone.com.au</a> describing the issue.</li>
          <li>We&apos;ll try to fix it remotely first (most things turn out to be a router restart away).</li>
          <li>If it&apos;s genuinely faulty, we&apos;ll repair, replace, or refund the phone &mdash; the remedy depends on the nature of the failure and your rights under the ACL (major failures: your choice; minor failures: our choice in the first instance).</li>
        </ol>
        <p>Return shipping for warranty claims is on us.</p>
      </>,
    },
    {
      id: 'damaged',
      heading: 'Damaged in transit',
      body: <>
        <p>If your phone arrives damaged, take a photo before you do anything else and email us within 7 days of delivery. We&apos;ll send a replacement immediately and collect the damaged unit at no cost to you.</p>
      </>,
    },
    {
      id: 'subscriptions',
      heading: 'Subscriptions & service fees',
      body: <>
        <p>Ciao Plus ($14.99 / month) is billed in advance. If you cancel mid-month, your Plus access continues until the end of that billing period &mdash; we don&apos;t pro-rate refunds for the unused days, but you can keep enjoying the benefits until the period closes.</p>
        <p>The Free plan has nothing to refund &mdash; it&apos;s always free.</p>
      </>,
    },
    {
      id: 'how-to-claim',
      heading: 'How to start a return or claim',
      body: <>
        <p>One step:</p>
        <ol>
          <li>Email <a href="mailto:info@ciaobellaphone.com.au">info@ciaobellaphone.com.au</a> with your order number and a one-line description.</li>
        </ol>
        <p>That&apos;s it. A real Australian human will reply, usually the same day.</p>
      </>,
    },
  ];

  return (
    <LegalPage
      title="Returns &amp; Refunds"
      eyebrow="Returns"
      lastUpdated="May 24, 2026"
      intro="30 days to change your mind. 12 months of warranty. One email to make it happen."
      sections={sections}
      navigate={navigate}
      currentRoute="/refunds"
    />
  );
}

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