// legal.jsx — Privacy Policy + Terms of Service

const COMPANY = "M&E Pearl LLC";
const BRAND   = "Healing Pearl Massage";
const EMAIL   = "info@healingpearlmassage.net";
const STATE   = "Texas";

const PRIVACY_SECTIONS = [
  {
    h: "Overview",
    p: [
      `${COMPANY} ("${BRAND}," "we," "our," "us") respects your privacy and is committed to protecting it through our compliance with this Privacy Policy (the "Policy"). This Policy describes the types of information we may collect from you or that you may provide when you visit our website (our "Site") and our practices for collecting, using, maintaining, protecting, and disclosing that information.`,
      `This Policy does not address the privacy practices of any third parties that we do not own, control, or are affiliated with. Capitalized terms not defined in this Policy will have the meaning set forth in our Terms of Service (the "Terms"). We encourage you to read this Policy and the Terms, and to use the information they contain to help you make informed decisions.`,
      `By visiting and/or using our Site or Services you are accepting the privacy and security practices described in this Policy. We reserve the right to change or update this Policy at any time. We will post any updated Policy to the Site. By accessing the Site after we make any such changes, you are deemed to have accepted them. We recommend that you review this Policy periodically.`,
      `This Policy is part of our Terms. By using the Site you agree to the terms and conditions of the Terms. If you choose to visit our Site or use our Services, our relationship and any dispute that should arise will be governed by our Terms and this Policy, including limitations on damages, dispute resolution provisions, and application of ${STATE} law.`,
      `We do not sell, trade, or rent your personal information to other companies or third parties, although our third-party technology and service providers may have access to your information as part of helping us provide Services or information to you and as set forth below. We, and such third-party providers, use the information we collect about you as stated in this Policy to process appointments, provide and improve Services, and send you information you may find of interest. Except for information collected as stated in this Policy, we will not collect any personal information about you except when you specifically and knowingly provide such information to us.`,
      `If you have a question or concern about any of the information in this Policy, please contact us at: ${COMPANY} — ${EMAIL}.`,
    ],
  },
  {
    h: "Information We Collect From You",
    p: [
      `When you book an appointment or contact us through the Site, we may ask you to provide information that allows us to personally identify you. This information includes your name, email address, physical address, phone number, and any health or preference information relevant to your massage services. If you choose to pay with a payment card, we collect payment information for processing by our third-party processor. All payment transactions are processed securely and we do not store full card details on our servers.`,
    ],
  },
  {
    h: "Use of Information We Collect From You",
    p: [
      `We electronically store all information that you provide us. We engage third-party companies and individuals to perform functions on our behalf and to help us provide the Services. We use information you provide us so that we, or such contractors, can be in contact with you to confirm appointments, send reminders, and provide our Services.`,
      `We may also use your information to send you updates about promotions, new services, or special offers. At any time, you may choose to stop receiving such communications by clicking the "opt-out" link in any marketing email. After you have opted-out, ${BRAND} will not send you unsolicited communications.`,
      `While using the Site, you can choose not to provide certain information or reject cookies (as explained below); however, your decision to do so may limit your ability to use some of the Site's features or book services online.`,
    ],
  },
  {
    h: "Use of Cookies and Web Beacons",
    p: [
      `A cookie is a small piece of data stored in a browser-related file on your computer's hard drive when you use the Services on the Site. Cookies are uniquely assigned to your computer and read by a web server in the domain that issued them. We use cookies to recognize your computer when you return to our Site, keep track of your preferences, and improve your online experience.`,
      `We may use an email delivery and marketing service to send emails you have agreed to receive. Pixel tags and cookies are used in those email messages to help us measure effectiveness. Third parties, including our booking platform (Skedron), may also set cookies. Such third parties are responsible for placing and using their cookies and may collect information about you through those cookies.`,
      `If you do not want cookies stored on your computer, you may reject them by modifying your browser settings. However, doing so may affect your ability to use certain features of our booking platform.`,
      `We also log standard information such as your IP address, referring URLs, and pages visited on our Site. This traffic data is used in aggregate form to improve the Site and is not used to personally identify you.`,
    ],
  },
  {
    h: "Protection of Collected Information",
    p: [
      `We take commercially reasonable steps to maintain security systems and secure servers to protect your information from loss, misuse, and unauthorized access, disclosure, alteration, or destruction. Please understand that no security system is impenetrable. You are also responsible for the security of any account credentials you hold. Our personnel will never ask you to divulge your password in written or electronic communications.`,
      `Please be aware that Internet security technology changes rapidly and data transmission is never 100% secure. We cannot guarantee that any safeguards we use will completely protect your information from security threats. Accordingly, you use the Site at your own risk.`,
    ],
  },
  {
    h: "Legal Matters; Protection of Rights, Property and Interests; Safety",
    p: [
      `We may, without your consent, access and disclose your personal information, any communications sent or received by you, and any other information that we have about you: as may be permitted or required by law, regulation, rule, or court order; pursuant to requests from governmental, regulatory, or law enforcement authorities; to establish or exercise our legal rights or defend against legal claims; or to prevent, investigate, or take action regarding suspected fraud, violations of our Terms, or activity that appears to be illegal or may expose us to legal liability.`,
    ],
  },
  {
    h: "Sharing of Information with Third Parties",
    p: [
      `Information about you is an important part of our business, and we are not in the business of selling it to others. We may, however, provide your personally identifiable information to third parties in the following instances:`,
    ],
    list: [
      "We need to share your information to provide the Service you have requested (e.g., confirming an appointment via our booking platform).",
      "We have your consent.",
      "We need to send the information to companies who work on our behalf to provide a Service to you.",
      "We are required by law or have a good-faith belief that disclosure of such information is reasonably necessary to protect our rights, property, or safety.",
      "Your actions on our Site violate the Terms.",
      "We provide such information to trusted businesses for the sole purpose of processing information on our behalf.",
    ],
    pAfter: [
      `In the event of a corporate sale, merger, reorganization, sale of assets, dissolution, or similar event, your information may be part of the transferred assets.`,
    ],
  },
  {
    h: "Children",
    p: [
      `The Site and our Services are not intended for children under 13 years of age. No one under age 13 may provide any information to or on the Site. We do not knowingly collect personal information from children under 13. If you are under 13, do not use the Site. If we learn we have collected or received personal information from a child under 13 without verification of parental consent, we will delete that information. If you believe we might have any information from or about a child under 13, please contact us at ${EMAIL}.`,
    ],
  },
  {
    h: "Links to Other Websites",
    p: [
      `This Site contains links to other websites and internet applications (including our booking platform). Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to read the privacy statements of each website that collects personally identifiable information. This privacy statement applies solely to information collected by this Site.`,
    ],
  },
  {
    h: "Important Notices to Non-U.S. Residents",
    p: [
      `The Site and its servers are operated in the United States. If you are located outside of the United States, please be aware that your personal information may be transferred to, processed, maintained, and used on computers, servers, and systems located in the United States, where privacy laws may not be as protective as those in your jurisdiction. By using the Site or Services, you consent to such transfer and use.`,
    ],
  },
  {
    h: "Integrations with Third Parties",
    p: [
      `We use third-party services, including our booking platform Skedron, to help operate and enhance our Services. Please refer to the privacy policies of those third-party services for information on how they handle your data.`,
    ],
  },
];

const TERMS_SECTIONS = [
  {
    h: "Overview",
    p: [
      `These Terms of Service (the "Agreement") govern your access to and use of the ${BRAND} website (the "Site") and the massage and wellness services offered through it (the "Services"). This Agreement is between you ("you" or "user") and ${COMPANY}, a ${STATE} Limited Liability Company doing business as ${BRAND}.`,
      `PLEASE READ THESE TERMS CAREFULLY BEFORE USING THE SITE OR BOOKING SERVICES. BY USING OUR SITE OR BOOKING A SERVICE, YOU ACKNOWLEDGE THAT YOU HAVE READ AND UNDERSTAND THESE TERMS AND AGREE TO BE BOUND BY THEM. IF YOU DO NOT AGREE, DO NOT USE THE SITE OR SERVICES.`,
      `We may revise this Agreement at any time by posting updates to the Site. All changes are effective immediately upon posting. Your continued use of the Site or Services after such posting constitutes your acceptance of the updated terms.`,
    ],
  },
  {
    h: "Eligibility",
    p: [
      `By using the Site, you represent and warrant that you are eighteen (18) years of age or older. Clients under 18 may receive services only with the written consent of a parent or legal guardian who accepts responsibility under this Agreement. If you accept this Agreement on behalf of another individual or entity, you represent that you have the legal authority to do so.`,
    ],
  },
  {
    h: "Privacy Policy",
    p: [
      `${BRAND} values your privacy. Please review our Privacy Policy, which describes in detail the kind of information we collect about you, how we use it, and how we protect your personal information.`,
    ],
  },
  {
    h: "Booking, Scheduling & Cancellations",
    p: [
      `Appointments may be booked online through our booking platform, by phone, or in person at either studio location. Booking an appointment constitutes acceptance of these Terms.`,
      `We ask that you arrive 5–10 minutes before your scheduled appointment. Late arrivals may result in a shortened session so that the next client is not delayed. The full session price applies regardless of a shortened session due to a late arrival.`,
      `To cancel or reschedule without charge, please notify us at least 24 hours before your appointment. Cancellations or rescheduling requests received less than 24 hours in advance may be subject to a cancellation fee equal to 50% of the scheduled service price. No-shows (failure to arrive without notice) may be charged the full service price.`,
      `${BRAND} reserves the right to cancel or reschedule appointments due to therapist illness, facility issues, or other circumstances beyond our control. In such cases, we will notify you as promptly as possible and offer a full rescheduling at no additional charge.`,
    ],
  },
  {
    h: "Health, Safety & Conduct",
    p: [
      `For the health and safety of our clients and staff, please inform us of any medical conditions, injuries, allergies, or contraindications before your session. Certain conditions may affect our ability to safely provide services.`,
      `Massage therapy is provided for professional therapeutic purposes only. Any request for or insinuation of sexual or inappropriate conduct will result in immediate termination of the session, and the full session price will be charged. The client may be banned from future services. We reserve the right to contact law enforcement if warranted.`,
      `${BRAND} reserves the right to refuse or terminate service to any client who is under the influence of alcohol or drugs, behaving inappropriately or aggressively, or presenting a health or safety risk to staff or other clients.`,
    ],
  },
  {
    h: "Fees and Payment",
    p: [
      `You agree to pay the fees in effect for each Service at the time of booking. All fees are due at the time of service unless otherwise agreed in writing. We accept major credit cards, debit cards, and cash. All applicable taxes are your responsibility.`,
      `Gift certificates and promotional offers are subject to the terms stated on the certificate or offer and may not be combined with other discounts unless expressly stated. Gift certificates are non-refundable and non-transferable for cash.`,
    ],
  },
  {
    h: "Website, Services & Your Consent",
    p: [
      `We reserve the right to withdraw or amend our Site, and any Services or material we provide, in our sole discretion without notice. ${BRAND} reserves the right to block users from certain IP addresses from accessing the Site.`,
      `By accessing the Site, booking through the Site, or using our Services, you consent to have this Agreement provided to you in electronic form and agree that ${BRAND} may communicate with you electronically. All electronic communications are equivalent to written communications. Notices to ${BRAND} must be sent to: ${EMAIL}.`,
    ],
  },
  {
    h: "Your Obligations",
    list: [
      "You are responsible for providing accurate and complete information when booking or registering.",
      "You agree to comply with this Agreement, our Privacy Policy, and all payment obligations.",
      "You agree to provide a safe and cooperative environment during your session.",
      "You agree to disclose relevant health information to your therapist prior to your session.",
      "You are responsible for ensuring that any person using Services through your account is aware of this Agreement and complies with it.",
    ],
  },
  {
    h: "Intellectual Property Rights",
    p: [
      `The Site and its entire contents — including text, images, logos, video, and design — are owned by ${COMPANY} and protected by United States and international copyright, trademark, and other intellectual property laws. You do not acquire any right, title, or interest in any ${BRAND} intellectual property by use of the Site or Services.`,
      `${BRAND}'s name, logo, and related marks are trademarks of ${COMPANY}. You must not use such marks without our prior written permission.`,
    ],
  },
  {
    h: "Prohibited Uses",
    p: [
      `You may use our Services and Site only for lawful purposes and in accordance with this Agreement. You agree not to:`,
    ],
    list: [
      "use the Site or Services in any way that violates any applicable federal, state, local, or international law or regulation;",
      "impersonate ${BRAND}, our staff, or any other person or entity;",
      "submit false, misleading, or fraudulent booking information;",
      "engage in any conduct that restricts or inhibits anyone's use or enjoyment of the Site, or which may harm ${BRAND} or expose ${BRAND} to liability;",
      "use any automated means to access the Site without our express written permission;",
      "introduce any viruses, malware, or other harmful code into the Site.",
    ],
  },
  {
    h: "Links",
    p: [
      `The Site may contain links to third-party websites and services (including our booking platform). These links are provided for your convenience only. We have no control over the contents of those sites and accept no responsibility for them or for any loss or damage that may arise from your use of them.`,
    ],
  },
  {
    h: "Modifications to Services and Website",
    p: [
      `${BRAND} may update the content on the Site from time to time. We reserve the right to modify or discontinue, temporarily or permanently, the Site or our Services with or without notice. ${BRAND} shall not be liable to you or any third party for any modification, suspension, or discontinuance of the Site or Services.`,
    ],
  },
  {
    h: "Limited Warranty; Disclaimers",
    p: [
      `${BRAND} warrants that we will provide our Services with a commercially reasonable level of professional care. Your sole remedy for our breach of this limited warranty is that ${BRAND} will, at its discretion, re-perform or refund the Service that does not conform to this warranty. You must notify us in writing within ten (10) days after you first become aware of the non-conforming Service.`,
      `${BRAND.toUpperCase()} MAKES NO WARRANTIES EXCEPT FOR THOSE PROVIDED ABOVE. ALL OTHER WARRANTIES, EXPRESS AND IMPLIED, ARE EXPRESSLY DISCLAIMED. ${BRAND.toUpperCase()} WILL NOT BE LIABLE FOR ANY LOSS OR DAMAGE CAUSED BY CIRCUMSTANCES BEYOND OUR REASONABLE CONTROL.`,
    ],
  },
  {
    h: "Limitation of Liability",
    p: [
      `IN NO EVENT WILL ${COMPANY.toUpperCase()} BE LIABLE TO YOU OR TO ANY THIRD PARTY FOR ANY LOSS OF USE, REVENUE, OR PROFIT, OR FOR ANY CONSEQUENTIAL, INCIDENTAL, INDIRECT, EXEMPLARY, SPECIAL, OR PUNITIVE DAMAGES WHETHER ARISING OUT OF BREACH OF CONTRACT, TORT (INCLUDING NEGLIGENCE), OR OTHERWISE, REGARDLESS OF WHETHER SUCH DAMAGE WAS FORESEEABLE.`,
      `IN NO EVENT WILL ${COMPANY.toUpperCase()}'S AGGREGATE LIABILITY ARISING OUT OF OR RELATED TO THIS AGREEMENT OR OUR SERVICES EXCEED THE AMOUNTS PAID BY YOU TO ${BRAND.toUpperCase()} IN THE TWELVE (12) MONTH PERIOD PRECEDING THE EVENT GIVING RISE TO SUCH CLAIM.`,
    ],
  },
  {
    h: "Dispute Resolution",
    p: [
      `If a dispute arises regarding the respective rights or obligations under this Agreement, the parties agree to first attempt to settle the dispute by direct discussion. If such dispute cannot be resolved by direct discussion, any unresolved dispute will be governed by the laws of the State of ${STATE}, without regard to its conflict-of-law provisions. You expressly agree and consent to the exclusive jurisdiction and venue of the state and federal courts located in the State of ${STATE} for the resolution of any such dispute.`,
      `ANY CAUSE OF ACTION OR CLAIM YOU MAY HAVE ARISING OUT OF OR RELATING TO THIS AGREEMENT OR THE SITE MUST BE COMMENCED WITHIN ONE (1) YEAR AFTER THE CAUSE OF ACTION ACCRUES, OTHERWISE, SUCH CAUSE OF ACTION OR CLAIM IS PERMANENTLY BARRED.`,
    ],
  },
  {
    h: "Indemnity",
    p: [
      `You agree to defend, indemnify, and hold ${COMPANY}, its affiliates, officers, agents, and employees harmless from any loss, liability, claim, damages, costs, or demands of any nature, including reasonable attorney's fees, made by any third party arising out of your use of the Services or the Site in violation of this Agreement, or arising from any breach of your obligations set forth herein.`,
    ],
  },
  {
    h: "General",
    p: [
      `${BRAND} will not be liable for any failure or delay in providing Services caused by circumstances beyond our reasonable control, including acts of God, pandemic, governmental actions, war, civil unrest, natural emergency, or utility or internet outage.`,
      `This Agreement contains the entire agreement between you and ${COMPANY} regarding the use of the Site and/or the Services. If any provision of this Agreement is held invalid, the remainder of this Agreement shall continue in full force and effect.`,
      `The Site is operated by ${COMPANY}. If you have questions regarding this Agreement, the Services, or the Site, please contact us at ${EMAIL}.`,
    ],
  },
];

function LegalPage({ kind }) {
  const { go } = useRoute();
  const isPrivacy = kind === "privacy";
  const sections  = isPrivacy ? PRIVACY_SECTIONS : TERMS_SECTIONS;
  const title     = isPrivacy ? "Privacy Policy" : "Terms of Service";
  const eyebrow   = isPrivacy ? "Privacy" : "Legal";
  const sub       = isPrivacy
    ? "How we collect, use, and protect your information."
    : "The agreement that governs your use of our website and services.";

  const slug = (s) => s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
  const jump = (id) => {
    const el = document.getElementById(id);
    if (el) el.scrollIntoView({ behavior: "smooth", block: "start" });
  };

  return (
    <main style={{ background: "var(--cream)", minHeight: "60vh" }}>
      {/* Header */}
      <section style={{ background: "var(--ivory)", borderBottom: "1px solid var(--line)", paddingTop: 56, paddingBottom: 48 }}>
        <div className="wrap">
          <div className="eyebrow"><span className="dot-mark" />{eyebrow} · {COMPANY}</div>
          <h1 className="t-h1" style={{ marginTop: 10 }}>{title}</h1>
          <p className="t-body" style={{ marginTop: 12, color: "var(--gray-600)", maxWidth: 480 }}>{sub}</p>
          <div className="t-small" style={{ marginTop: 16, color: "var(--gray-500)", display: "flex", gap: 16, flexWrap: "wrap" }}>
            <span><b>Effective</b> January 1, 2026</span>
            <span>·</span>
            <span><b>Governing law</b> State of {STATE}</span>
          </div>
          {/* Toggle */}
          <div style={{ marginTop: 28, display: "flex", gap: 8 }}>
            <button
              onClick={() => go("/terms")}
              className={!isPrivacy ? "btn btn-primary" : "btn btn-secondary"}
              style={{ padding: "10px 20px", fontSize: 14 }}
            >Terms of Service</button>
            <button
              onClick={() => go("/privacy")}
              className={isPrivacy ? "btn btn-primary" : "btn btn-secondary"}
              style={{ padding: "10px 20px", fontSize: 14 }}
            >Privacy Policy</button>
          </div>
        </div>
      </section>

      {/* Body — TOC sidebar + article */}
      <section style={{ paddingTop: 56, paddingBottom: 96 }}>
        <div className="wrap" style={{ display: "grid", gridTemplateColumns: "220px 1fr", gap: 64, alignItems: "start" }}>

          {/* Table of contents */}
          <aside style={{ position: "sticky", top: 24 }}>
            <div className="t-micro" style={{ color: "var(--gray-500)", marginBottom: 12 }}>CONTENTS</div>
            <ol style={{ listStyle: "none", padding: 0, margin: 0, display: "flex", flexDirection: "column", gap: 2 }}>
              {sections.map((s, i) => (
                <li key={i}>
                  <a
                    href={"#" + slug(s.h)}
                    onClick={(e) => { e.preventDefault(); jump(slug(s.h)); }}
                    style={{ display: "flex", gap: 10, alignItems: "baseline", color: "var(--gray-600)", fontSize: 13, textDecoration: "none", padding: "5px 0", lineHeight: 1.4 }}
                  >
                    <span style={{ fontVariantNumeric: "tabular-nums", color: "var(--gray-400)", minWidth: 20, fontSize: 11 }}>{String(i + 1).padStart(2, "0")}</span>
                    <span>{s.h}</span>
                  </a>
                </li>
              ))}
            </ol>
          </aside>

          {/* Article */}
          <article>
            {sections.map((s, i) => (
              <section
                key={i}
                id={slug(s.h)}
                style={{ paddingTop: 40, paddingBottom: 40, borderBottom: "1px solid var(--line)" }}
              >
                <div style={{ display: "flex", gap: 16, alignItems: "baseline", marginBottom: 16 }}>
                  <span className="t-micro" style={{ color: "var(--gray-400)", minWidth: 28, fontVariantNumeric: "tabular-nums" }}>{String(i + 1).padStart(2, "0")}</span>
                  <h2 className="t-h3" style={{ margin: 0 }}>{s.h}</h2>
                </div>
                <div style={{ paddingLeft: 44 }}>
                  {s.p && s.p.map((para, j) => (
                    <p key={"p" + j} className="t-body" style={{ marginBottom: 16, color: "var(--gray-700)", lineHeight: 1.75 }}>{para}</p>
                  ))}
                  {s.list && (
                    <ul style={{ paddingLeft: 20, margin: "0 0 16px", display: "flex", flexDirection: "column", gap: 8 }}>
                      {s.list.map((li, j) => (
                        <li key={"l" + j} className="t-body" style={{ color: "var(--gray-700)", lineHeight: 1.7 }}>{li}</li>
                      ))}
                    </ul>
                  )}
                  {s.pAfter && s.pAfter.map((para, j) => (
                    <p key={"a" + j} className="t-body" style={{ marginBottom: 16, color: "var(--gray-700)", lineHeight: 1.75 }}>{para}</p>
                  ))}
                </div>
              </section>
            ))}

            {/* Footer */}
            <div style={{ paddingTop: 48, display: "flex", justifyContent: "space-between", alignItems: "flex-start", flexWrap: "wrap", gap: 32 }}>
              <div>
                <div className="t-micro" style={{ color: "var(--gray-500)", marginBottom: 8 }}>Questions?</div>
                <h3 className="t-h3" style={{ marginBottom: 8 }}>Get in touch.</h3>
                <p className="t-body" style={{ color: "var(--gray-700)" }}>
                  {COMPANY}<br />
                  <a href={"mailto:" + EMAIL} style={{ color: "var(--warm)" }}>{EMAIL}</a>
                </p>
              </div>
              <div>
                {isPrivacy ? (
                  <button className="btn btn-primary" onClick={() => go("/terms")}>
                    Read Terms of Service →
                  </button>
                ) : (
                  <button className="btn btn-primary" onClick={() => go("/privacy")}>
                    Read Privacy Policy →
                  </button>
                )}
              </div>
            </div>
          </article>
        </div>
      </section>
    </main>
  );
}

Object.assign(window, { LegalPage });
