// legal.jsx: Privacy Policy, Terms of Use, Cookies, Accessibility Statement
//
// These pages describe what the site ACTUALLY does today (no analytics, no ad
// trackers, contact form via Web3Forms, client portal on Supabase, maps from
// OpenStreetMap, weather from Open-Meteo). If any of that changes, update the
// matching page in the same commit. Business details come from SITE in
// shared.jsx.

// Internal link that navigates inside the app but still has a real href.
function LegalLink({ to, onNavigate, children }) {
  return (
    <a
      href={pathFor(to)}
      onClick={(e) => {
        e.preventDefault();
        if (onNavigate) onNavigate(to);
      }}
    >
      {children}
    </a>
  );
}

function LegalLayout({ title, subtitle, toc, children }) {
  return (
    <React.Fragment>
      <PageHero
        title={title}
        subtitle={subtitle}
        bg={'assets/about-hero.webp'}
        bgPosition="center center"
        hidePattern
        short
      />
      <section className="section section--paper">
        <div className="container">
          <article className="legal">
            <p className="legal__updated">Last updated: {SITE.legalUpdated}</p>
            {toc && (
              <nav className="legal__toc" aria-labelledby="legal-toc-title">
                <h2 id="legal-toc-title">On this page</h2>
                <ol>
                  {toc.map(([id, label]) => (
                    <li key={id}><a href={`#${id}`}>{label}</a></li>
                  ))}
                </ol>
              </nav>
            )}
            {children}
          </article>
        </div>
      </section>
    </React.Fragment>
  );
}

const ADDRESS_LINE = `${SITE.street}, ${SITE.city}, ${SITE.state} ${SITE.zip}`;

// ============================================
// PRIVACY POLICY
// ============================================
function PrivacyPage({ onNavigate }) {
  const toc = [
    ['who', 'Who we are'],
    ['collect', 'What we collect'],
    ['use', 'How we use it'],
    ['share', 'Who we share it with'],
    ['cookies', 'Cookies and tracking'],
    ['keep', 'How long we keep it'],
    ['security', 'How we protect it'],
    ['rights', 'Your choices and rights'],
    ['children', 'Children'],
    ['links', 'Links to other sites'],
    ['changes', 'Changes to this policy'],
    ['contact', 'Contact us'],
  ];
  return (
    <LegalLayout
      title="Privacy Policy"
      subtitle="What we collect, why, and the choices you have."
      toc={toc}
    >
      <p className="legal__lead">
        This policy explains what personal information {SITE.name} collects through
        {' '}{SITE.domain} and our client portal, why we collect it, who we share it with, and how
        you can control it. We have kept it plain on purpose.
      </p>

      <h2 id="who">Who we are</h2>
      <p>
        {SITE.name} (&ldquo;we&rdquo;, &ldquo;us&rdquo;) is a custom home builder at {ADDRESS_LINE}.
        We were formerly known as {SITE.formerName}. You can reach us at{' '}
        <a href={`mailto:${SITE.email}`}>{SITE.email}</a> or{' '}
        <a href={`tel:${SITE.phoneHref}`}>{SITE.phone}</a>.
      </p>

      <h2 id="collect">What we collect</h2>
      <h3>When you contact us</h3>
      <p>If you use the contact form on this site we collect:</p>
      <ul>
        <li>your first and last name, and email address (required so we can reply);</li>
        <li>your phone number (optional);</li>
        <li>the message you write about your project;</li>
        <li>a record that you agreed to be contacted and the time you agreed.</li>
      </ul>
      <p>
        If you email or call us instead, we keep whatever you choose to tell us.
      </p>

      <h3>If you have a client portal account</h3>
      <p>
        Portal accounts are created by invitation for clients and team members. Depending on your
        role we store:
      </p>
      <ul>
        <li>your name, email address and password (the password is stored in scrambled, hashed form, never in readable form);</li>
        <li>optional profile details such as phone number, mailing address, notes and a profile photo;</li>
        <li>an optional drawn signature, if you sign off on selections in the portal;</li>
        <li>the time you last signed in;</li>
        <li>
          project information: the project address and map location, schedules, selections,
          punch lists, photos, documents, files and financial summaries or invoices for your project.
        </li>
      </ul>

      <h3>Collected automatically</h3>
      <p>
        Like any website, our hosting providers receive your IP address, browser type and the pages
        or files requested so that the site can be delivered and kept secure. We do not run analytics
        or advertising tools and we do not build profiles of your browsing.
      </p>

      <h3>What we do not collect</h3>
      <p>
        This website does not take payments, so we do not collect payment card or bank account
        details here.
      </p>

      <h2 id="use">How we use it</h2>
      <ul>
        <li>to reply to your inquiry and discuss your project;</li>
        <li>to set up and run your project, and to operate the client portal;</li>
        <li>to send account emails such as invitations, sign-in links and password resets;</li>
        <li>to keep the website and portal secure and working;</li>
        <li>to keep business, accounting and warranty records, and to meet legal obligations.</li>
      </ul>
      <p>
        We do not use your information for advertising, and we do not make automated decisions
        about you.
      </p>

      <h2 id="share">Who we share it with</h2>
      <p>
        We use a small number of service providers to run the site. They handle your information
        only to provide their service to us.
      </p>
      <table>
        <thead>
          <tr><th>Provider</th><th>What it does</th><th>Information involved</th></tr>
        </thead>
        <tbody>
          <tr>
            <td data-label="Provider">Web3Forms</td>
            <td data-label="What it does">Delivers contact form messages to our email inbox.</td>
            <td data-label="Information involved">Name, email, phone, message, consent record.</td>
          </tr>
          <tr>
            <td data-label="Provider">Supabase</td>
            <td data-label="What it does">Hosts portal accounts, the project database and uploaded files, and sends sign-in and invitation emails.</td>
            <td data-label="Information involved">Portal account and project information listed above.</td>
          </tr>
          <tr>
            <td data-label="Provider">Vercel</td>
            <td data-label="What it does">Hosts and delivers this website.</td>
            <td data-label="Information involved">IP address and standard request details.</td>
          </tr>
          <tr>
            <td data-label="Provider">OpenStreetMap (Nominatim and map tiles)</td>
            <td data-label="What it does">Shows maps and looks up addresses in the portal.</td>
            <td data-label="Information involved">Addresses typed into a map search, the map area being viewed, and your IP address.</td>
          </tr>
          <tr>
            <td data-label="Provider">Open-Meteo</td>
            <td data-label="What it does">Provides weather forecasts for a project location in the portal.</td>
            <td data-label="Information involved">The project's approximate coordinates or town name, and your IP address.</td>
          </tr>
          <tr>
            <td data-label="Provider">unpkg and jsDelivr (code delivery networks)</td>
            <td data-label="What it does">Deliver open-source code libraries the site needs to run.</td>
            <td data-label="Information involved">Your IP address and browser details when the files load.</td>
          </tr>
        </tbody>
      </table>
      <p>
        Inside the portal, project information is visible to you, the Riggins team members assigned
        to your project, and anyone you or we add to the project as a member.
      </p>
      <p>
        We do not sell your personal information, and we do not share it with anyone for their own
        advertising. We may disclose information if the law requires it, to protect our rights or
        safety, or as part of a sale or transfer of our business.
      </p>

      <h2 id="cookies">Cookies and tracking</h2>
      <p>
        We do not use advertising, analytics or social media tracking cookies. The only browser
        storage we use is what is needed to keep you signed in to the portal and make the site load
        quickly. Details are on our{' '}
        <LegalLink to="cookies" onNavigate={onNavigate}>Cookies page</LegalLink>. Because we do not
        track you, there is nothing to opt out of, and browser settings such as Do Not Track or
        Global Privacy Control do not change how the site behaves.
      </p>

      <h2 id="keep">How long we keep it</h2>
      <p>
        We keep information for as long as we need it for the purposes above. Contact inquiries are
        kept while we are talking with you and afterward as a record of the conversation. Project and
        portal information is kept for the life of the project and after it as needed for warranty
        service, accounting, and legal and record-keeping requirements. You can ask us to delete
        information sooner (see below), and we will do so unless we are required or permitted by law
        to keep it.
      </p>

      <h2 id="security">How we protect it</h2>
      <p>
        The site is served over an encrypted connection (HTTPS). Portal data sits behind sign-in
        and access rules that limit each person to the projects they belong to. Portal administrator
        access is limited to our team. No system is perfectly secure, so we cannot guarantee absolute
        security. If a breach affects your information we will notify you and any authorities as
        required by law, including Florida's information protection statute.
      </p>

      <h2 id="rights">Your choices and rights</h2>
      <ul>
        <li>You can ask what personal information we hold about you, and ask us to correct or delete it.</li>
        <li>Portal users can update their own profile details when signed in.</li>
        <li>We do not send marketing emails. If you receive a call or message from us that you do not want, tell us and we will stop.</li>
      </ul>
      <p>
        Email <a href={`mailto:${SITE.email}`}>{SITE.email}</a> or call{' '}
        <a href={`tel:${SITE.phoneHref}`}>{SITE.phone}</a>. We may need to confirm who you are before
        acting on a request, and we respond within the time the law requires. We aim to honor these
        requests no matter where you live, including residents of states with their own privacy laws.
      </p>

      <h2 id="children">Children</h2>
      <p>
        This website is for adults planning a home. It is not directed to children under 13 and we do
        not knowingly collect their information. If you think a child has given us information, contact
        us and we will delete it.
      </p>

      <h2 id="links">Links to other sites</h2>
      <p>
        We link to our Instagram, Facebook and LinkedIn pages and to realtor and government websites.
        These links are plain links. We do not embed their buttons, feeds or tracking code on our
        pages. Once you click through, the other site's own privacy policy applies.
      </p>

      <h2 id="changes">Changes to this policy</h2>
      <p>
        If we change what we collect or how we use it, we will update this page and the date at the
        top. If we ever add analytics or advertising tools we will update this policy and our Cookies
        page first, and ask for your consent where the law requires it.
      </p>

      <h2 id="contact">Contact us</h2>
      <p>
        {SITE.name}<br />
        {ADDRESS_LINE}<br />
        <a href={`mailto:${SITE.email}`}>{SITE.email}</a><br />
        <a href={`tel:${SITE.phoneHref}`}>{SITE.phone}</a>
      </p>
    </LegalLayout>
  );
}

// ============================================
// TERMS OF USE (includes payments and refunds)
// ============================================
function TermsPage({ onNavigate }) {
  const toc = [
    ['scope', 'Scope of these terms'],
    ['info', 'Information on this site'],
    ['portal', 'The client portal'],
    ['payments', 'Payments, deposits and refunds'],
    ['ip', 'Copyright and ownership'],
    ['content', 'Content you upload'],
    ['links', 'Third-party links'],
    ['disclaimer', 'Disclaimers'],
    ['liability', 'Limits on liability'],
    ['law', 'Governing law'],
    ['changes', 'Changes'],
    ['contact', 'Contact us'],
  ];
  return (
    <LegalLayout
      title="Terms of Use"
      subtitle="The ground rules for using this website and the client portal."
      toc={toc}
    >
      <p className="legal__lead">
        By using {SITE.domain} or signing in to the {SITE.name} client portal you agree to these
        terms. If you do not agree, please do not use the site.
      </p>

      <h2 id="scope">Scope of these terms</h2>
      <p>
        These terms cover the website and the client portal only. They are not a construction
        contract. If you hire us to design or build a home, that work is governed by the written
        agreement you sign with us. If these terms and your signed agreement conflict, your signed
        agreement controls.
      </p>
      <p>
        Using this site or sending us a message does not create a client relationship or any
        obligation for either side. A relationship begins only when both parties sign an agreement.
      </p>

      <h2 id="info">Information on this site</h2>
      <p>
        Photographs, renderings, floor plans, descriptions, availability and timelines on this site
        are for general information and inspiration. They are not an offer. Homes shown may include
        upgrades, custom features, landscaping, furniture and finishes that are not part of every
        project. The scope, specifications, price and schedule of your own home are set only by your
        signed agreement and any written change orders.
      </p>

      <h2 id="portal">The client portal</h2>
      <ul>
        <li>Portal accounts are by invitation. Keep your sign-in details private and do not share your account.</li>
        <li>You are responsible for activity under your account. Tell us right away if you think someone else has used it.</li>
        <li>Do not try to access information that is not yours, probe or disrupt the system, scrape it, or upload anything unlawful, harmful or that you have no right to share.</li>
        <li>We may suspend or remove access to protect the system, other users or our business.</li>
        <li>
          Schedules, selections and financial summaries in the portal are provided for your
          convenience. Dates are estimates that can move because of weather, supply, inspections and
          other factors outside our control. Your signed agreement and written change orders control
          the actual scope, price and terms.
        </li>
      </ul>

      <h2 id="payments">Payments, deposits and refunds</h2>
      <p>
        This website does not accept payments and does not sell products. Amounts due, deposits,
        payment schedules, change orders, cancellation terms and any refunds for a project are set out
        only in your written agreement with us. Nothing on this website creates a right to a refund or
        changes that agreement. Any cancellation or refund rights that the law gives you are not
        limited by these terms.
      </p>
      <p>
        If you have a question about an invoice or payment, contact us at{' '}
        <a href={`mailto:${SITE.email}`}>{SITE.email}</a> or{' '}
        <a href={`tel:${SITE.phoneHref}`}>{SITE.phone}</a>.
      </p>

      <h2 id="ip">Copyright and ownership</h2>
      <p>
        The text, logos, names, photographs, videos, floor plans and designs on this site belong to
        {' '}{SITE.name} or are used with permission from their owners, including photographers. All
        rights are reserved.
      </p>
      <ul>
        <li>You may view the site, print pages for your own personal use, and share links to it.</li>
        <li>You may not copy, republish, scrape or use our content for commercial purposes without our written permission.</li>
        <li>Plans and designs we create are protected by copyright. Please do not use them, or have anyone else use them, to build a home without our written permission.</li>
      </ul>
      <p>
        If you believe something on this site infringes your copyright, email{' '}
        <a href={`mailto:${SITE.email}`}>{SITE.email}</a> with the page, what you believe is
        infringing, and how to reach you. We will review it promptly.
      </p>

      <h2 id="content">Content you upload</h2>
      <p>
        Photos and files you upload to the portal remain yours. You allow us to store and use them to
        deliver your project and as described in our{' '}
        <LegalLink to="privacy" onNavigate={onNavigate}>Privacy Policy</LegalLink>. You confirm you
        have the right to upload them.
      </p>

      <h2 id="links">Third-party links</h2>
      <p>
        Links to other websites are provided for convenience. We do not control those sites and are not
        responsible for their content or practices.
      </p>

      <h2 id="disclaimer">Disclaimers</h2>
      <p>
        We work to keep the site accurate and available, but it is provided &ldquo;as is&rdquo; and
        &ldquo;as available&rdquo; without promises that it will be error free or uninterrupted. This
        section does not reduce any warranty you receive under your signed construction agreement or
        under Florida law.
      </p>

      <h2 id="liability">Limits on liability</h2>
      <p>
        To the extent the law allows, we are not responsible for indirect, incidental or consequential
        losses that result from using the website or portal. This does not limit anything that cannot
        legally be limited, and it does not apply to your construction agreement, which has its own
        terms.
      </p>

      <h2 id="law">Governing law</h2>
      <p>
        These terms are governed by the laws of the State of Florida. Any dispute about the website or
        portal will be brought in the state or federal courts located in Alachua County, Florida.
      </p>

      <h2 id="changes">Changes</h2>
      <p>
        We may update these terms. The date at the top shows the latest version. Continuing to use the
        site after a change means you accept the updated terms. If any part of these terms is found
        unenforceable, the rest stays in effect.
      </p>

      <h2 id="contact">Contact us</h2>
      <p>
        {SITE.name}<br />
        {ADDRESS_LINE}<br />
        <a href={`mailto:${SITE.email}`}>{SITE.email}</a><br />
        <a href={`tel:${SITE.phoneHref}`}>{SITE.phone}</a>
      </p>
    </LegalLayout>
  );
}

// ============================================
// COOKIES AND LOCAL STORAGE
// ============================================
function CookiesPage({ onNavigate }) {
  return (
    <LegalLayout
      title="Cookies and Storage"
      subtitle="What this website stores in your browser, and why."
    >
      <p className="legal__lead">
        We do not use advertising, analytics or social media tracking cookies. That is why this site
        does not show a cookie banner: there is nothing optional to switch off.
      </p>

      <h2 id="stored">What is stored in your browser</h2>
      <table>
        <thead>
          <tr><th>Item</th><th>Where</th><th>Purpose</th><th>How long</th></tr>
        </thead>
        <tbody>
          <tr>
            <td data-label="Item">Sign-in session (browser local storage, name begins &ldquo;sb-&rdquo;)</td>
            <td data-label="Where">Client portal, only after you sign in</td>
            <td data-label="Purpose">Keeps you signed in. Strictly necessary.</td>
            <td data-label="How long">Until you sign out or it expires. It refreshes while you use the portal.</td>
          </tr>
          <tr>
            <td data-label="Item">rdb_install_dismissed (local storage)</td>
            <td data-label="Where">Client portal</td>
            <td data-label="Purpose">Remembers that you closed the &ldquo;add to home screen&rdquo; tip so it does not keep appearing.</td>
            <td data-label="How long">Until you clear site data.</td>
          </tr>
          <tr>
            <td data-label="Item">Site cache (service worker and cache storage)</td>
            <td data-label="Where">All pages</td>
            <td data-label="Purpose">Stores copies of the site's own files so pages load faster and the portal can be installed like an app. It holds no personal information.</td>
            <td data-label="How long">Until a newer version replaces it or you clear site data.</td>
          </tr>
        </tbody>
      </table>

      <h2 id="third">Requests to other servers</h2>
      <p>
        Our fonts are served from our own site, so loading text does not contact Google. A few other
        services receive your IP address and browser details when you load a page or use a feature,
        as any web request does: code libraries from unpkg and jsDelivr, maps from OpenStreetMap and
        weather from Open-Meteo in the portal, and Web3Forms when you send the contact form. We do
        not use any of them to track you. The{' '}
        <LegalLink to="privacy" onNavigate={onNavigate}>Privacy Policy</LegalLink> lists each one.
      </p>

      <h2 id="control">Controlling storage</h2>
      <p>
        You can clear or block site data in your browser settings. If you block storage for this site
        you will not be able to stay signed in to the client portal. The public pages will still work.
      </p>

      <h2 id="future">If this changes</h2>
      <p>
        If we ever add analytics, advertising or similar tools, we will update this page and the
        Privacy Policy first and ask for your consent before they run where the law requires it.
      </p>
    </LegalLayout>
  );
}

// ============================================
// ACCESSIBILITY STATEMENT
// ============================================
function AccessibilityPage({ onNavigate }) {
  return (
    <LegalLayout
      title="Accessibility"
      subtitle="Our commitment to a website everyone can use."
    >
      <p className="legal__lead">
        {SITE.name} wants everyone to be able to use this website, including people who use screen
        readers, keyboards, voice control, magnification or who prefer reduced motion. We are working
        toward meeting the Web Content Accessibility Guidelines (WCAG) 2.1 Level AA.
      </p>

      <h2 id="done">What we have done</h2>
      <ul>
        <li>A &ldquo;Skip to main content&rdquo; link and clear page landmarks.</li>
        <li>Menus, project galleries and forms that work with a keyboard, with a visible focus outline.</li>
        <li>Form fields with labels, autofill hints, and errors that are announced.</li>
        <li>Text alternatives for informative images, and decorative images hidden from screen readers.</li>
        <li>A pause button for the background video on the home page, and no motion effects for visitors whose device asks for reduced motion.</li>
        <li>Text and background colors chosen to meet WCAG contrast ratios.</li>
        <li>Fonts served from our own site, and no tracking or advertising scripts.</li>
      </ul>

      <h2 id="limits">Known limitations</h2>
      <ul>
        <li>Project photos are described by project name and photo number rather than in detail. If you would like a description of any photo, contact us and we will provide one.</li>
        <li>The signed-in client portal has more complex screens such as tables, schedules and document tools. We are still reviewing these and some parts may not yet meet every guideline.</li>
        <li>Maps in the portal come from OpenStreetMap and have their own accessibility limits.</li>
      </ul>

      <h2 id="how">How we check</h2>
      <p>
        We test with automated accessibility tools and by using the keyboard to move through the
        pages. This is a self-assessment and we have not claimed formal conformance. We last reviewed
        the public pages on {SITE.legalUpdated}.
      </p>

      <h2 id="feedback">Tell us about a barrier</h2>
      <p>
        If something on this site is hard to use, or you need information in another format, please
        tell us. Email <a href={`mailto:${SITE.email}`}>{SITE.email}</a> or call{' '}
        <a href={`tel:${SITE.phoneHref}`}>{SITE.phone}</a> ({SITE.hours}). Tell us the page, what you
        were trying to do, and how you access the web. We aim to reply within one business day and
        will help you by phone or email in the meantime. You can also use the{' '}
        <LegalLink to="contact" onNavigate={onNavigate}>contact page</LegalLink>.
      </p>
    </LegalLayout>
  );
}

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