/* global React, LegalPage, EM_GA_ID */

// DUMMY CONTENT: sample policy for layout only. Replace with a reviewed policy before launch.
// Covers the website and the app. Facts used (trial, plans, Guardians, Stripe, Cloudflare,
// self-hosted fonts and scripts, consent-only analytics) match the rest of the site.
const PRIVACY_UPDATED = '30 October 2026';

// The cookies section describes what the site really does, so it follows the analytics switch.
function privacyCookies() {
  if (!EM_GA_ID) {
    return [
      "This website doesn't set any cookies. We don't use analytics, advertising or tracking cookies, and everything the site needs, from fonts to code, is served from our own domain.",
      "If we ever add analytics, we'll ask for your permission first, with Accept and Decline given equal weight, and we'll update this policy.",
      'The app uses cookies that are strictly necessary to keep you signed in. These do not need your consent.',
    ];
  }
  return [
    'We use analytics cookies only if you agree. Until you choose, and if you decline, none are set. Your choice covers this website and the app (my.everlasting-memory.com), so you only need to make it once; the app’s cookie policy is at my.everlasting-memory.com/cookies.',
    { table: {
      label: 'Cookies and storage we use',
      head: ['Name', 'Purpose', 'How long'],
      rows: [
        ['_ga', 'Google Analytics: tells visits apart, so we can count them', '2 years'],
        ['_ga_' + EM_GA_ID.replace(/^G-/, ''), 'Google Analytics: remembers the current visit', '2 years'],
        ['em_consent', 'Remembers whether you accepted or declined, on this website and the app', '12 months'],
        ['em_cookie_consent', 'The same choice, kept in your browser (not a cookie)', 'Until you clear it'],
      ],
    } },
    'You can change your mind at any time. Declining removes the analytics cookies from this site.',
    { cookieSettings: true },
    'The app uses cookies that are strictly necessary to keep you signed in. These do not need your consent.',
  ];
}

function PrivacyPage() {
  const sections = [
    { id: 'about', title: 'About this policy', body: [
      'This policy explains what personal information Everlasting Memory collects, why, and what we do with it. It covers this website and the Everlasting Memory app.',
      "Some of what you trust us with is deeply personal: your voice, your face, your family's story. We collect only what we need to keep it and deliver it as you ask.",
    ] },
    { id: 'who-we-are', title: 'Who we are', body: [
      'Everlasting Memory is run by [PLACEHOLDER: company name], registered in England and Wales under company number [PLACEHOLDER: number], at [PLACEHOLDER: address]. We are the controller of your personal information.',
      'We are registered with the Information Commissioner’s Office under number [PLACEHOLDER: ICO registration number].',
    ] },
    { id: 'what-we-collect', title: 'What we collect', body: [
      'Your account: your name, email address and password, and your plan.',
      'What you create: video and voice recordings, letters, photos, stories, your family tree, and the dates you choose for each message.',
      'The people in your messages: the names and contact details of the people you send messages to, and of your two Guardians if you add Legacy.',
      "Payments: Stripe handles your card details. We receive a record of what you paid and when, but we never see or store your card number.",
      'Support: anything you tell us when you write to hello@everlasting-memory.com.',
      'Website visits: our hosting provider keeps short-lived server logs, including IP addresses, to run and protect the site. We only use analytics if you agree (see Cookies).',
    ] },
    { id: 'how-we-use', title: 'How we use it, and why', body: [
      'UK data protection law requires a lawful basis for each use of your information. These are ours.',
      { table: {
        label: 'How we use your information and our lawful basis',
        head: ['What we do', 'Lawful basis'],
        rows: [
          ['Run your account, store your messages and deliver them on the dates you choose', 'Contract: it is the service you signed up for'],
          ['Release Legacy messages once both your Guardians confirm', 'Contract'],
          ['Take payments and keep financial records', 'Contract, and legal obligation'],
          ['Answer your emails and support requests', 'Legitimate interests: helping you'],
          ['Keep the website and app secure', 'Legitimate interests: protecting you and us'],
          ['Measure website visits with analytics', 'Consent: only if you accept'],
        ],
      } },
      'We never sell your information, use it for advertising, or use your recordings to train AI.',
    ] },
    { id: 'sharing', title: 'Who we share it with', body: [
      'We use a small number of trusted providers to run the service. Each one may only use your information to do that job for us.',
      { table: {
        label: 'Providers we share information with',
        head: ['Provider', 'What for'],
        rows: [
          ['Cloudflare', 'Hosting the website and app, and protecting them from attacks'],
          ['Stripe', 'Taking payments'],
          ['[PLACEHOLDER: email provider]', 'Sending account emails and delivering messages'],
          ['[PLACEHOLDER: storage provider]', 'Storing your recordings and photos'],
        ],
      } },
      'We will also share information if the law requires it, for example in response to a court order.',
    ] },
    { id: 'where', title: 'Where your information is stored', body: [
      'Your recordings and account information are stored in [PLACEHOLDER: UK / EU region]. Where a provider handles information outside the UK, we make sure it is protected by approved safeguards, such as the UK International Data Transfer Agreement.',
    ] },
    { id: 'how-long', title: 'How long we keep it', body: [
      "During your free trial, no messages are saved. If you don't subscribe, your trial account is deleted when the 7 days are up.",
      'While you have an account, we keep your messages, photos and family tree. Messages you have scheduled are kept until they are delivered, including after your subscription ends.',
      'With Legacy, your legacy video stays on your family tree for as long as the service exists.',
      'We keep payment records for 6 years, as UK tax law requires. Support emails are kept for [PLACEHOLDER: period].',
    ] },
    { id: 'security', title: 'Keeping it safe', body: [
      'We protect your information with [PLACEHOLDER: encryption and security measures to be confirmed]. Access is limited to the people who need it to run the service.',
      'If something ever goes wrong with your information, we will tell you and the Information Commissioner’s Office where the law requires.',
    ] },
    { id: 'people-in-messages', title: 'The people in your messages', body: [
      'When you add someone as a recipient or Guardian, we use their details only to deliver your messages or to ask them to confirm. We do not market to them.',
      'Please let them know you have added them. They can contact us at any time to ask what we hold about them.',
    ] },
    { id: 'children', title: 'Children', body: [
      'You must be 18 or over to have an account. Messages can be addressed to children; we deliver them to the contact details you give us, such as a parent’s email address.',
    ] },
    { id: 'rights', title: 'Your rights', body: [
      'You have the right to ask for a copy of your information, to have it corrected or deleted, to restrict or object to how we use it, and to take it with you to another service. Where we rely on consent, you can withdraw it at any time.',
      'To use any of these rights, write to hello@everlasting-memory.com. We will reply within one month.',
      "If you're unhappy with how we've handled your information, please tell us first. You can also complain to the Information Commissioner’s Office at ico.org.uk or on 0303 123 1113.",
    ] },
    { id: 'cookies', title: 'Cookies', body: privacyCookies() },
    { id: 'changes', title: 'Changes to this policy', body: [
      'If we change this policy in a way that affects you, we will email you before the change takes effect and update the date at the top.',
    ] },
    { id: 'contact', title: 'Contact us', body: [
      'Questions about your privacy? Write to us at hello@everlasting-memory.com.',
    ] },
  ];

  return (
    <LegalPage
      title="Privacy policy"
      lede="What we collect, why we need it, and the choices you have."
      path="/privacy/"
      updated={PRIVACY_UPDATED}
      notice={<><strong>Placeholder text.</strong> This policy is sample content for layout only and is not legally binding. It will be replaced with a reviewed policy before launch.</>}
      sections={sections}
    />
  );
}

window.PrivacyPage = PrivacyPage;
