// jsx/LegalPage.jsx — one document layout, four datasets (privacy / cookies /
// terms / accessibility). Alpine Premium: warm paper, Clash Display title,
// readable single column. Renders its own TopNav + Footer.
//
// ⚠️ Company facts live in ONE place (ORG). Fill `number` + `office` with the
// real Companies House details before this is relied upon. Drafts are a
// starting template, not legal advice — have them reviewed.

const ORG = {
  name: "Zarco Systems Ltd",
  number: "",                                  // TODO: real Companies House number (renders only when set)
  office: "",                                  // TODO: registered office to display (renders only when set)
  email: "luke@zarco.uk",
};

// Registration detail renders only once the real values are filled in, so the
// live page never shows placeholder text. Fill ORG.number / ORG.office above.
const REG = (() => {
  const bits = [];
  if (ORG.number) bits.push("company number " + ORG.number);
  if (ORG.office) bits.push("registered office " + ORG.office);
  return bits.length ? " (" + bits.join(", ") + ")" : "";
})();

const UPDATED = "16 June 2026";

const LEGAL = {
  privacy: {
    title: "Privacy Policy",
    updated: UPDATED,
    intro:
      `${ORG.name} respects your privacy. This notice explains what personal data we collect through this website, why we use it, and the rights you have under UK GDPR and the Data Protection Act 2018.`,
    sections: [
      { h: "Who we are", body: [
        `${ORG.name} is registered in England and Wales${REG}. We are the data controller for personal data collected through this site. You can reach us at ${ORG.email}.`,
      ]},
      { h: "What we collect", body: [
        "We only collect personal data you choose to give us. When you submit the contact form, that is:",
        { list: [
          "Your name",
          "Your work email address",
          "Your company name (optional)",
          "The message you write to us",
        ]},
        "We do not collect special category data, and we ask that you do not send sensitive personal information through the form.",
      ]},
      { h: "Why we use it", body: [
        "We use this information to reply to your enquiry and to discuss working together. Our lawful bases are our legitimate interest in responding to people who contact us, and taking steps at your request before entering into a contract.",
        "We do not sell your data, and we do not use it for advertising or profiling.",
      ]},
      { h: "Who processes it", body: [
        "Our contact form is delivered using Web3Forms, which relays your message to our Microsoft 365 inbox. The website is hosted by Vercel. These providers act as processors on our behalf and only handle your data to provide their service.",
        "Where a provider processes data outside the UK, we rely on appropriate safeguards such as the UK International Data Transfer Agreement or equivalent contractual protections.",
      ]},
      { h: "How long we keep it", body: [
        "We keep enquiry correspondence only as long as needed to deal with your enquiry and any relationship that follows from it, then delete it.",
      ]},
      { h: "Your rights", body: [
        "Under UK data protection law you have the right to access, correct, delete, restrict or object to our use of your personal data, and to data portability. To exercise any of these, email us at " + ORG.email + ".",
        "If you are unhappy with how we have handled your data, you can complain to the Information Commissioner's Office at ico.org.uk.",
      ]},
      { h: "Changes to this notice", body: [
        "We may update this notice from time to time. The date at the top shows when it was last changed.",
      ]},
    ],
  },

  cookies: {
    title: "Cookie Policy",
    updated: UPDATED,
    intro:
      "The short version: this website does not use tracking or analytics cookies. We do not profile you, and we do not share your data with advertising networks.",
    sections: [
      { h: "What we use", body: [
        "Zarco's website runs no analytics, advertising or tracking cookies. There is no Google Analytics, no advertising pixels, and no cross-site tracking.",
      ]},
      { h: "Strictly necessary cookies", body: [
        "Our hosting provider may set a small number of strictly necessary cookies that are needed to serve and secure the site. These do not track you across other websites.",
      ]},
      { h: "When you contact us", body: [
        "When you submit the contact form, your message is handled by Web3Forms. How we use the information you send is described in our Privacy Policy.",
      ]},
      { h: "Managing cookies", body: [
        "You can block or delete cookies in your browser settings at any time. This site is built to work without them.",
      ]},
      { h: "Changes", body: [
        "If we ever introduce analytics or other non-essential cookies, we will update this page and ask for your consent where the law requires it.",
      ]},
    ],
  },

  terms: {
    title: "Terms of Use",
    updated: UPDATED,
    intro:
      "These terms govern your use of zarco.uk. By using this website you agree to them. If you do not agree, please do not use the site.",
    sections: [
      { h: "Who we are", body: [
        `This website is operated by ${ORG.name}, registered in England and Wales${REG}. You can contact us at ${ORG.email}.`,
      ]},
      { h: "Using this site", body: [
        "You may use this site for lawful purposes only. You agree not to misuse it, attempt to disrupt or gain unauthorised access to it, or scrape it in ways that harm the service or other users.",
      ]},
      { h: "Intellectual property", body: [
        "The content, design and branding on this site are owned by Zarco unless stated otherwise, and may not be copied or reused without our permission. Third-party names and logos shown on the site remain the property of their respective owners.",
      ]},
      { h: "Information, not advice", body: [
        "The content on this site is general information about Zarco and our services. We work to keep it accurate and current but make no guarantees, and nothing on the site is a binding offer or professional advice.",
      ]},
      { h: "Links to other sites", body: [
        "We may link to third-party websites we do not control. We are not responsible for their content or their handling of your data.",
      ]},
      { h: "Liability", body: [
        "To the fullest extent permitted by law, we exclude liability for any loss arising from your use of, or inability to use, this site. Nothing in these terms limits liability that cannot be limited under applicable law.",
      ]},
      { h: "Governing law", body: [
        "These terms are governed by the laws of England and Wales, and the courts of England and Wales have exclusive jurisdiction.",
      ]},
      { h: "Changes", body: [
        "We may update these terms from time to time. Continued use of the site means you accept the current version.",
      ]},
    ],
  },

  accessibility: {
    title: "Accessibility",
    updated: UPDATED,
    intro:
      "We want zarco.uk to be usable by as many people as possible, and we aim to meet the WCAG 2.2 AA standard.",
    sections: [
      { h: "What we have done", body: [
        "We have built the site with accessibility in mind:",
        { list: [
          "Semantic structure and clear headings",
          "Keyboard navigation throughout",
          "Colour contrast that meets AA on body text",
          "Motion that respects your “reduce motion” setting",
          "Text that scales when you zoom",
          "Descriptive alternative text on meaningful images",
        ]},
      ]},
      { h: "Known limitations", body: [
        "Some of the site's motion is decorative and is switched off automatically when you have asked your device to reduce motion. If you come across anything that does not work for you, please tell us.",
      ]},
      { h: "Tell us", body: [
        "If you have trouble using any part of this site, email " + ORG.email + ". We aim to respond within a few working days and will fix issues wherever we can.",
      ]},
    ],
  },
};

function LegalBlocks({ blocks }) {
  return blocks.map((b, i) => {
    if (typeof b === "string") return <p key={i}>{b}</p>;
    if (b && b.list) {
      return (
        <ul key={i} className="legal-list">
          {b.list.map((li, j) => <li key={j}>{li}</li>)}
        </ul>
      );
    }
    return null;
  });
}

function LegalPage({ page }) {
  const d = LEGAL[page] || LEGAL.privacy;
  return (
    <React.Fragment>
      <TopNav />
      <main className="legal shell">
        <header className="legal-head">
          <p className="legal-kicker">Legal</p>
          <h1 className="legal-title">{d.title}</h1>
          <p className="legal-updated">Last updated {d.updated}</p>
        </header>
        <p className="legal-intro">{d.intro}</p>
        <div className="legal-doc">
          {d.sections.map((s, i) => (
            <section key={i} className="legal-section">
              <h2>{s.h}</h2>
              <LegalBlocks blocks={s.body} />
            </section>
          ))}
        </div>
        <p className="legal-foot">
          Questions about this page? Email <a href={"mailto:" + ORG.email}>{ORG.email}</a>.
        </p>
      </main>
      <Footer />
    </React.Fragment>
  );
}

const legalCss = `
.legal{ padding: clamp(120px,18vh,184px) 0 clamp(72px,11vh,128px); }
.legal-head{ margin-bottom: clamp(36px,5.5vh,56px); }
.legal-kicker{ font-family:var(--font-sans); font-size:13px; color:var(--magenta); font-weight:500; margin:0 0 14px; }
.legal-title{ font-family:var(--font-display); font-weight:300; font-size:clamp(40px,6.2vw,76px); letter-spacing:-.03em; line-height:1; margin:0 0 16px; }
.legal-updated{ font-size:14px; color:var(--ink-40); margin:0; }
.legal-intro{ font-size:19px; line-height:1.6; color:var(--ink); max-width:64ch; margin:0 0 clamp(36px,5.5vh,52px); }
.legal-doc{ max-width:68ch; }
.legal-section{ margin-bottom:clamp(30px,4.5vh,42px); }
.legal-section h2{ font-family:var(--font-display); font-weight:400; font-size:clamp(21px,2.5vw,27px); letter-spacing:-.02em; line-height:1.15; margin:0 0 14px; color:var(--ink); }
.legal-section p{ font-size:16.5px; line-height:1.65; color:var(--ink-60); margin:0 0 14px; }
.legal-section p:last-child{ margin-bottom:0; }
.legal-list{ margin:0 0 14px; padding-left:20px; color:var(--ink-60); font-size:16.5px; line-height:1.65; }
.legal-list li{ margin-bottom:8px; }
.legal a{ color:var(--magenta); text-decoration:none; border-bottom:1px solid var(--ink-10); padding-bottom:1px; }
.legal a:hover{ border-color:var(--magenta); }
.legal-foot{ margin-top:clamp(44px,6.5vh,68px); padding-top:24px; border-top:1px solid var(--ink-10); font-size:15px; color:var(--ink-60); max-width:68ch; }
`;

window.LegalPage = LegalPage;
window.legalCss = legalCss;
