/* ============================================================
   PWC LEGAL — Privacy / Terms / Accessibility.
   Starter content carrying the kit's required disclaimers
   (911-first, no-warranty content, response-time estimates,
   form consent). PENDING TEXAS-ATTORNEY REVIEW before launch.
   ============================================================ */
const LG = window.PWC.INV;

function LegalStyles() {
  return <style dangerouslySetInnerHTML={{ __html: `
.legal-wrap{ max-width:780px; margin:0 auto; }
.legal-updated{ color:var(--text-3); font-size:.86rem; font-weight:600; letter-spacing:.02em; }
.legal-note{ background:var(--bg-2); border:1px solid var(--line); border-left:3px solid var(--ember); border-radius:var(--r);
  padding:14px 18px; color:var(--text-2); font-size:.92rem; line-height:1.55; margin:18px 0 44px; }
.legal-note strong{ color:var(--text); }
.legal-h{ font-family:var(--font-display); font-weight:800; font-size:1.34rem; line-height:1.2; margin:42px 0 14px; letter-spacing:-.01em; }
.legal-h:first-of-type{ margin-top:0; }
.legal-p{ color:var(--text-2); font-size:1.06rem; line-height:1.7; margin-bottom:14px; }
.legal-p a{ color:var(--ember); }
.legal-p strong{ color:var(--text); }
.legal-list{ color:var(--text-2); font-size:1.05rem; line-height:1.65; padding-left:22px; margin:0 0 14px; }
.legal-list li{ margin-bottom:9px; }
.legal-contact{ margin-top:44px; padding-top:24px; border-top:1px solid var(--line); color:var(--text-2); font-size:1rem; line-height:1.7; }
.legal-contact a{ color:var(--text); font-weight:600; }
` }} />;
}

function LegalBody({ blocks }) {
  return blocks.map((b, i) => {
    if (b.h) return <h2 key={i} className="legal-h">{b.h}</h2>;
    if (b.list) return <ul key={i} className="legal-list">{b.list.map((li, j) => <li key={j} dangerouslySetInnerHTML={{ __html: li }} />)}</ul>;
    return <p key={i} className="legal-p" dangerouslySetInnerHTML={{ __html: b.p }} />;
  });
}

function LegalPage({ doc }) {
  return (
    <React.Fragment>
      <LegalStyles />
      <PageHero eyebrow="Legal & compliance" h1={doc.title} sub={doc.sub} />
      <section className="section">
        <div className="wrap">
          <div className="legal-wrap">
            <p className="legal-updated">{doc.updated}</p>
            <p className="legal-note"><strong>Draft — pending review.</strong> This is starter wording for an emergency-services-adjacent business and has not yet been reviewed by a Texas attorney. It is not legal advice and is not final.</p>
            <LegalBody blocks={doc.blocks} />
            <div className="legal-contact">
              <strong>Questions?</strong> Contact {LG.principal}, {LG.role}.<br />
              Call <a href={`tel:${LG.tel}`}>{LG.phone}</a> · <a href={`mailto:${LG.email}`}>{LG.email}</a>
            </div>
          </div>
        </div>
      </section>
    </React.Fragment>
  );
}

const LEGAL_DOCS = {
  privacy: {
    title: "Privacy Policy",
    sub: "What we collect, why, and the short answer: as little as possible, used only to respond to you.",
    updated: "Draft — June 2026",
    blocks: [
      { h: "The short version" },
      { p: "We collect as little as we can to respond to you and run a simple, fast website. We don't sell, rent, or share your information. If a well is getting away from you, the fastest thing you can do is <strong>call 432-349-4892</strong> — and for a life-threatening emergency (fire, injury, H2S), call 911 first." },
      { h: "What we collect" },
      { list: [
        "<strong>What you give us.</strong> When you call, text, or email — or send details about a well — we keep what you tell us (your name, number, location, and the situation) so we can respond and follow up.",
        "<strong>Basic site analytics.</strong> Standard, privacy-respecting information like pages viewed and device type, to keep the site fast and useful. No advertising profiles are built from it.",
      ] },
      { h: "Saving our number" },
      { p: "“Save Our Number” downloads a contact card to your device. That happens entirely on your phone — <strong>nothing is sent to us when you save the number.</strong>" },
      { h: "How we use it" },
      { p: "Only to respond to you, provide the service, and follow up about your well control needs. We do not sell, rent, or trade your information, and we don't share it except as needed to respond (or as required by law)." },
      { h: "Cookies & analytics" },
      { p: "We use minimal cookies/local storage for site function and basic analytics. You can block or clear cookies in your browser; the call and save actions still work without them." },
      { h: "Retention & security" },
      { p: "We keep your details only as long as needed to respond and meet our records obligations, and we use reasonable safeguards to protect them." },
      { h: "Your choices" },
      { p: "Call or email us to ask what we have, to correct it, or to have it deleted." },
      { h: "Changes" },
      { p: "If this policy changes, we'll post the update here and change the date above." },
    ],
  },

  terms: {
    title: "Terms of Use",
    sub: "Using this site means you agree to these terms. The most important one: the content here is general information, not well-control advice.",
    updated: "Draft — June 2026",
    blocks: [
      { h: "Not advice — and no warranty" },
      { p: "Everything on this site — the glossary, the events and lessons-learned library, first-steps content, and the coverage map — is <strong>general information, not engineering or well-control advice</strong>, and is provided “as is” without warranty of any kind. In an event, follow your training and your company's well control policy. <strong>Life-threatening emergency (fire, injury, H2S)? Call 911 first</strong>, then call us at 432-349-4892." },
      { h: "Using the site doesn't create a relationship" },
      { p: "Reading this site, saving our number, or sending us a message does not create a service, consulting, or professional relationship. That begins only under a separate, agreed engagement." },
      { h: "Response-time estimates" },
      { p: "Coverage and response-time bands are <strong>planning estimates</strong> (approximate mobilization plus drive time from Midland) — not a guarantee. Call for a straight estimate for your exact location." },
      { h: "Events & lessons-learned content" },
      { p: "Event entries are curated from public records and reporting, summarized in our own words, and credited with a link to the source. We verify details against primary records before publishing and flag what's incomplete, but we don't warrant completeness or accuracy. Coordinates shown are approximate county/place centroids, not survey locations." },
      { h: "Limitation of liability" },
      { p: "To the fullest extent permitted by law, Permian Well Control is not liable for any damages arising from your use of this site or reliance on its content." },
      { h: "External links & intellectual property" },
      { p: "We link to third-party sources we don't control and aren't responsible for. The site's content and brand are ours; please don't republish them wholesale." },
      { h: "Governing law" },
      { p: "These terms are governed by the laws of the State of Texas." },
      { h: "Changes" },
      { p: "We may update these terms; the current version always lives on this page." },
    ],
  },

  accessibility: {
    title: "Accessibility Statement",
    sub: "We build this site to be usable on a phone, in the field, in the sun — for everyone. We target WCAG 2.1 AA.",
    updated: "Draft — June 2026",
    blocks: [
      { h: "Our commitment" },
      { p: "When a well is getting away from you, the site has to work — fast, on a phone, in bright sun, for every user. We design and build to meet <strong>WCAG 2.1 Level AA</strong> and treat accessibility as part of the job, not an add-on." },
      { h: "What we've done" },
      { list: [
        "Semantic HTML with a clear heading order and a skip-to-content link.",
        "Full keyboard operation with a visible focus outline on every interactive element.",
        "High-contrast, sunlight-legible color, with the <strong>Call action as the most prominent element on every screen</strong> and a real tap-to-call link.",
        "A complete <strong>text fallback for the coverage map</strong> — counties, response bands, and the documented events — so you never need the map to get the information.",
        "Reduced-motion support: animation is minimal and is disabled when your device asks for it.",
        "Descriptive text for meaningful images and resizable text that reflows on small screens.",
      ] },
      { h: "Known limitations" },
      { p: "The interactive map is an enhancement, not the only path — the text fallback carries the same information. The map uses third-party tiles we don't fully control. We're improving continuously." },
      { h: "Tell us if something's hard to use" },
      { p: "If any part of this site is hard to use, or you need information in another format, <strong>call or email and we'll help you directly and fix it.</strong>" },
    ],
  },
};

Object.assign(window, { LegalStyles, LegalPage, LEGAL_DOCS });
