/* ─── Legal Pages — Privacy Policy & Terms of Service ─── */

const LegalPage = ({ page, onNavigate }) => {
  const isMobile = useMediaQuery(680);

  const s = {
    wrapper: {
      paddingTop: isMobile ? 'var(--space-8)' : 'var(--space-10)',
      paddingBottom: isMobile ? 'var(--space-8)' : 'var(--space-10)',
      paddingLeft: isMobile ? 'calc(var(--space-5) + var(--safe-left, 0px))' : 'calc(var(--space-6) + var(--safe-left, 0px))',
      paddingRight: isMobile ? 'calc(var(--space-5) + var(--safe-right, 0px))' : 'calc(var(--space-6) + var(--safe-right, 0px))',
    },
    inner: {
      maxWidth: '680px',
      margin: '0 auto',
    },
    h1: {
      fontFamily: 'var(--font-serif-display)',
      fontSize: isMobile ? '1.75rem' : 'clamp(1.75rem, 3.5vw, 2.25rem)',
      fontWeight: 500,
      lineHeight: 1.2,
      letterSpacing: 'var(--tracking-tight)',
      color: 'var(--fg-primary)',
      margin: '0 0 var(--space-3) 0',
    },
    updated: {
      fontFamily: 'var(--font-sans)',
      fontSize: '13px',
      color: 'var(--fg-tertiary)',
      margin: '0 0 var(--space-7) 0',
    },
    h2: {
      fontFamily: 'var(--font-serif)',
      fontSize: '1.25rem',
      fontWeight: 500,
      lineHeight: 1.3,
      color: 'var(--fg-primary)',
      margin: 'var(--space-7) 0 var(--space-3) 0',
    },
    p: {
      fontFamily: 'var(--font-serif)',
      fontSize: 'var(--text-base)',
      lineHeight: 'var(--leading-relaxed)',
      color: 'var(--fg-secondary)',
      margin: '0 0 var(--space-4) 0',
      maxWidth: 'var(--measure)',
      textWrap: 'pretty',
    },
    ul: {
      fontFamily: 'var(--font-serif)',
      fontSize: 'var(--text-base)',
      lineHeight: 'var(--leading-relaxed)',
      color: 'var(--fg-secondary)',
      margin: '0 0 var(--space-4) 0',
      paddingLeft: 'var(--space-5)',
    },
    li: {
      marginBottom: 'var(--space-2)',
    },
    link: {
      color: 'var(--accent)',
      textDecoration: 'none',
      cursor: 'pointer',
    },
  };

  const e = React.createElement;
  const effective = '26 May 2026';

  if (page === 'privacy') {
    return e('div', { style: s.wrapper },
      e('div', { style: s.inner },
        e('h1', { style: s.h1 }, 'Privacy Policy'),
        e('p', { style: s.updated }, 'Effective ', effective),

        e('h2', { style: s.h2 }, 'Who we are'),
        e('p', { style: s.p }, 'Sufficient Certainty Pty Ltd ("we", "us") operates sufficientcertainty.com and the Walk decision-coaching service.'),

        e('h2', { style: s.h2 }, 'What we collect'),
        e('ul', { style: s.ul },
          e('li', { style: s.li }, 'Email address — when you start a Walk or subscribe to updates.'),
          e('li', { style: s.li }, 'Walk conversation data — the decisions, options, assumptions, and other inputs you provide during a Walk session.'),
          e('li', { style: s.li }, 'Payment information — processed by Stripe. We do not store card numbers.'),
          e('li', { style: s.li }, 'Analytics — anonymous page-view and event data collected by Umami (no cookies, no personal data, self-hosted).'),
        ),

        e('h2', { style: s.h2 }, 'How we use it'),
        e('ul', { style: s.ul },
          e('li', { style: s.li }, 'To deliver your Walk session and generate your Decision Record.'),
          e('li', { style: s.li }, 'To send your 30-day check-in email (one follow-up, then we stop).'),
          e('li', { style: s.li }, 'To process payments securely through Stripe.'),
          e('li', { style: s.li }, 'To improve the service based on aggregate, anonymised usage patterns.'),
        ),

        e('h2', { style: s.h2 }, 'What we do not do'),
        e('ul', { style: s.ul },
          e('li', { style: s.li }, 'We do not sell, rent, or share your personal data with third parties for marketing.'),
          e('li', { style: s.li }, 'We do not use tracking cookies or fingerprinting.'),
          e('li', { style: s.li }, 'We do not train AI models on your Walk conversations.'),
        ),

        e('h2', { style: s.h2 }, 'Data storage and retention'),
        e('p', { style: s.p }, 'Walk data is stored in a Supabase-hosted PostgreSQL database. We retain your Walk data for as long as you need access to your Decision Record. You may request deletion at any time.'),

        e('h2', { style: s.h2 }, 'Your rights'),
        e('p', { style: s.p }, 'You can request a copy of your data, ask us to correct it, or ask us to delete it. Contact us and we will respond within 30 days.'),

        e('h2', { style: s.h2 }, 'Third-party services'),
        e('ul', { style: s.ul },
          e('li', { style: s.li }, 'Stripe — payment processing (', e('a', { href: 'https://stripe.com/privacy', target: '_blank', rel: 'noopener noreferrer', style: s.link }, 'their privacy policy'), ').'),
          e('li', { style: s.li }, 'Umami — privacy-friendly, cookieless, self-hosted analytics (', e('a', { href: 'https://umami.is/docs/about', target: '_blank', rel: 'noopener noreferrer', style: s.link }, 'about Umami'), ').'),
          e('li', { style: s.li }, 'PostHog — product analytics, session recordings, and heatmaps. Uses cookies to link sessions across subdomains (', e('a', { href: 'https://posthog.com/privacy', target: '_blank', rel: 'noopener noreferrer', style: s.link }, 'their privacy policy'), ').'),
          e('li', { style: s.li }, 'Resend — transactional email delivery.'),
          e('li', { style: s.li }, 'Vercel — website hosting.'),
        ),

        e('h2', { style: s.h2 }, 'Contact'),
        e('p', { style: s.p }, 'For privacy-related questions, reach us through our ',
          e('a', { href: 'https://www.linkedin.com/company/sufficient-certainty', target: '_blank', rel: 'noopener noreferrer', style: s.link }, 'LinkedIn page'), '.'),

        e('h2', { style: s.h2 }, 'Changes'),
        e('p', { style: s.p }, 'We may update this policy. Material changes will be noted on this page with a revised effective date.'),
      ),
    );
  }

  // Terms of Service
  return e('div', { style: s.wrapper },
    e('div', { style: s.inner },
      e('h1', { style: s.h1 }, 'Terms of Service'),
      e('p', { style: s.updated }, 'Effective ', effective),

      e('h2', { style: s.h2 }, 'The service'),
      e('p', { style: s.p }, 'Sufficient Certainty provides a structured decision-coaching experience called "the Walk." Each Walk guides you through five steps derived from the Universal Decision-Making Method described in the book Deciding (2020). At the end, you receive a Decision Record summarising your thinking.'),

      e('h2', { style: s.h2 }, 'What the Walk is not'),
      e('p', { style: s.p }, 'The Walk is an educational and reflective tool. It is not professional advice — legal, financial, medical, or otherwise. The Decision Record captures your reasoning; it does not recommend a course of action. You remain responsible for the decisions you make.'),

      e('h2', { style: s.h2 }, 'Payment'),
      e('ul', { style: s.ul },
        e('li', { style: s.li }, 'A single Walk costs US$29 (or US$19 during the launch promotion).'),
        e('li', { style: s.li }, 'An annual pass costs US$99 and provides unlimited Walks for 12 months from purchase.'),
        e('li', { style: s.li }, 'Payments are processed by Stripe. All prices are in US dollars.'),
      ),

      e('h2', { style: s.h2 }, 'Your content'),
      e('p', { style: s.p }, 'The inputs you provide during a Walk are yours. We store them to generate and deliver your Decision Record and to send your 30-day check-in. We do not claim ownership of your content, and we do not use individual Walk data to train AI models.'),

      e('h2', { style: s.h2 }, 'Intellectual property'),
      e('p', { style: s.p }, 'The Walk interface, the five-step structure, and all site content are the intellectual property of Sufficient Certainty Pty Ltd. The underlying methodology is described in Deciding (2020). You may not reproduce or redistribute the Walk experience or its outputs commercially without written permission.'),

      e('h2', { style: s.h2 }, 'AI-generated content'),
      e('p', { style: s.p }, 'The Walk uses a large language model to facilitate conversation and generate your Decision Record. AI outputs are shaped by the methodology but may occasionally contain errors. Review your Decision Record before acting on it.'),

      e('h2', { style: s.h2 }, 'Availability'),
      e('p', { style: s.p }, 'We aim to keep the service available but do not guarantee uninterrupted access. We may take the service offline for maintenance or updates.'),

      e('h2', { style: s.h2 }, 'Limitation of liability'),
      e('p', { style: s.p }, 'To the maximum extent permitted by law, Sufficient Certainty Pty Ltd is not liable for any indirect, incidental, or consequential damages arising from your use of the service. Our total liability is limited to the amount you paid for the Walk in question.'),

      e('h2', { style: s.h2 }, 'Governing law'),
      e('p', { style: s.p }, 'These terms are governed by the laws of Victoria, Australia.'),

      e('h2', { style: s.h2 }, 'Contact'),
      e('p', { style: s.p }, 'Questions about these terms? Reach us through our ',
        e('a', { href: 'https://www.linkedin.com/company/sufficient-certainty', target: '_blank', rel: 'noopener noreferrer', style: s.link }, 'LinkedIn page'), '.'),

      e('h2', { style: s.h2 }, 'Changes'),
      e('p', { style: s.p }, 'We may update these terms. Continued use of the service after changes constitutes acceptance. Material changes will be noted on this page with a revised effective date.'),
    ),
  );
};

window.LegalPage = LegalPage;
