// Legal pages — Terms of Service, Privacy Policy, Return/Refund Policy,
// and Liability Disclaimer. One shared layout with a side index; routes
// are /legal/terms, /legal/privacy, /legal/refunds, /legal/liability.
//
// NOTE FOR JOY: this copy was drafted for Hazelbelle Embroidery & Print, LLC
// (Florida) from your stated policies. Have an attorney review it before
// relying on it — especially the refund and liability sections.

const HB_LEGAL_BUSINESS = "Hazelbelle Embroidery & Print, LLC";
const HB_LEGAL_STATE = "Florida";
const HB_LEGAL_EFFECTIVE = "June 11, 2026";

const HB_LEGAL_DOCS = [
  { slug: "terms",     title: "Terms of Service" },
  { slug: "privacy",   title: "Privacy Policy" },
  { slug: "refunds",   title: "Return & Refund Policy" },
  { slug: "liability", title: "Liability Disclaimer" },
];

function LegalSection({ n, title, children }) {
  return (
    <section className="legal-section">
      <h3><span className="legal-n mono">{n}</span> {title}</h3>
      {children}
    </section>
  );
}

function LegalShell({ slug, title, children }) {
  const app = useApp();
  return (
    <div className="page section">
      <div className="legal-grid">
        <aside className="legal-nav">
          <div className="smallcaps" style={{ color: "var(--ink-3)", marginBottom: 10 }}>Policies</div>
          {HB_LEGAL_DOCS.map(d => (
            <a key={d.slug}
               className={classNames("legal-nav-link", d.slug === slug && "active")}
               href={`#/legal/${d.slug}`}>{d.title}</a>
          ))}
        </aside>
        <article className="legal-doc">
          <h1 style={{ fontSize: "clamp(32px, 4vw, 48px)" }}>{title}</h1>
          <p className="mono legal-meta">
            {HB_LEGAL_BUSINESS} · Effective {HB_LEGAL_EFFECTIVE}
          </p>
          <ThreadDivider color="var(--line)" />
          {children}
          <ThreadDivider color="var(--line)" />
          <p style={{ color: "var(--ink-3)", fontSize: 15 }}>
            Questions about this policy? Reach us at{" "}
            <a href={`mailto:${app.tweaks.contactEmail}`}>{app.tweaks.contactEmail}</a> or
            through the <a href="#/contact">contact page</a>.
          </p>
        </article>
      </div>
    </div>
  );
}

// ---------------- Terms of Service ----------------
function LegalTermsPage() {
  return (
    <LegalShell slug="terms" title="Terms of Service">
      <LegalSection n="1" title="Who we are">
        <p>
          These Terms of Service ("Terms") govern your use of this website and your purchase of
          products and services from {HB_LEGAL_BUSINESS} ("Hazelbelle," "we," "us"), a limited
          liability company operating in {HB_LEGAL_STATE}. By placing an order or using this site,
          you agree to these Terms.
        </p>
      </LegalSection>

      <LegalSection n="2" title="Custom orders">
        <p>
          Most of our work is made to order. When you submit a custom order, you are engaging us to
          decorate goods to your specifications. Production timelines begin only after your artwork
          and any required mockup have been approved and any required deposit or setup fee has been
          paid. Standard custom orders typically ship within 5–10 business days after logo approval;
          rush service must be arranged with us before ordering.
        </p>
      </LegalSection>

      <LegalSection n="3" title="Artwork, digitizing, and setup fees">
        <p>
          Converting your artwork into a stitch file ("digitizing") requires a one-time setup fee.
          Once a design is digitized and saved, no further setup fee applies to future orders of
          that exact design. Artwork supplied in formats other than DST (such as PDF, PNG, SVG, or
          JPEG) is subject to a conversion fee. You represent that you own or are authorized to use
          any artwork, logo, or design you submit, and you grant us a limited license to reproduce
          it solely to fulfill your order.
        </p>
      </LegalSection>

      <LegalSection n="4" title="Digital design files">
        <p>
          Digital embroidery designs are delivered in DST format and are licensed for your own
          stitching use; they may not be resold or redistributed as files. We recommend stitching
          designs at their original size — significant resizing alters stitch density and can ruin
          embroidery quality, and we are not responsible for results produced from modified files.
        </p>
      </LegalSection>

      <LegalSection n="5" title="Deposits and payment">
        <p>
          Some orders require a deposit before production begins, with the balance due before
          shipment or pickup. Deposits cover work performed (such as digitizing and materials) and
          may be non-refundable once that work has begun, as described in our Return &amp; Refund
          Policy.
        </p>
      </LegalSection>

      <LegalSection n="6" title="Customer-supplied items">
        <p>
          You are welcome to supply your own garments or goods for decoration. As set out in our
          Liability Disclaimer, we are not responsible for replacing customer-supplied items in the
          rare event of a machine error or defect inherent in the item.
        </p>
      </LegalSection>

      <LegalSection n="7" title="Acceptable use">
        <p>
          You agree not to submit artwork that is unlawful, infringes another party's rights, or
          that we reasonably consider hateful or obscene. We may decline any order at our
          discretion; if we decline an order before work begins, any payment for that order will be
          refunded.
        </p>
      </LegalSection>

      <LegalSection n="8" title="Limitation of liability">
        <p>
          To the fullest extent permitted by {HB_LEGAL_STATE} law, our total liability arising from
          any order is limited to the amount you paid for that order. We are not liable for
          indirect, incidental, or consequential damages, including missed events or lost profits
          caused by shipping delays outside our control.
        </p>
      </LegalSection>

      <LegalSection n="9" title="Governing law and changes">
        <p>
          These Terms are governed by the laws of the State of {HB_LEGAL_STATE}. We may update
          these Terms from time to time; the version posted on this page at the time of your order
          applies to that order.
        </p>
      </LegalSection>
    </LegalShell>
  );
}

// ---------------- Privacy Policy ----------------
function LegalPrivacyPage() {
  return (
    <LegalShell slug="privacy" title="Privacy Policy">
      <LegalSection n="1" title="What we collect">
        <p>
          When you place an order, request a quote, or contact us, we collect the information you
          provide: your name, email address, phone number, order details, and any artwork or files
          you upload. Our server also keeps routine technical logs (such as IP address and pages
          visited) to keep the site running and secure.
        </p>
      </LegalSection>

      <LegalSection n="2" title="How we use it">
        <p>
          We use your information to prepare quotes, produce and deliver your orders, respond to
          your messages, and keep records of past designs so you aren't charged repeat setup fees.
          We do not sell your personal information, and we do not use it for third-party
          advertising.
        </p>
      </LegalSection>

      <LegalSection n="3" title="Cookies and sessions">
        <p>
          This site uses a small number of functional cookies — for example, a session cookie that
          keeps the studio owner signed in to the admin area. We do not use third-party tracking or
          advertising cookies.
        </p>
      </LegalSection>

      <LegalSection n="4" title="Who we share it with">
        <p>
          Your information is shared only with the service providers needed to run the business:
          our website hosting provider, payment processors when you pay for an order, and shipping
          carriers when we deliver to you. Each receives only what it needs to perform its role.
          We may also disclose information if required by law.
        </p>
      </LegalSection>

      <LegalSection n="5" title="Your artwork and files">
        <p>
          Uploaded artwork and digitized stitch files are stored so we can fulfill current and
          future orders. Your designs remain yours — we will not reuse, resell, or display your
          custom artwork without your permission, except in our portfolio or examples with your
          consent.
        </p>
      </LegalSection>

      <LegalSection n="6" title="Retention and your choices">
        <p>
          We keep order records and design files for as long as needed for business and tax
          purposes. You may ask us to correct your contact details or delete your uploaded files at
          any time by emailing us; we will honor the request except where we must retain records by
          law.
        </p>
      </LegalSection>

      <LegalSection n="7" title="Children">
        <p>
          This site is intended for adults. We do not knowingly collect personal information from
          children under 13; if you believe a child has provided us information, contact us and we
          will delete it.
        </p>
      </LegalSection>
    </LegalShell>
  );
}

// ---------------- Return & Refund Policy ----------------
function LegalRefundsPage() {
  return (
    <LegalShell slug="refunds" title="Return & Refund Policy">
      <LegalSection n="1" title="Custom decorated goods">
        <p>
          Because custom embroidered and printed items are made specifically for you, they cannot
          be restocked or resold. All sales of custom decorated goods are final once production has
          begun, except as described below. Please review your mockup, spelling, sizes, and colors
          carefully before approving — approval is your confirmation that everything is correct.
        </p>
      </LegalSection>

      <LegalSection n="2" title="Our mistake, our fix">
        <p>
          If your order arrives with a production error on our part — the decoration doesn't match
          the approved mockup, or there is a defect in our workmanship — contact us within 7 days
          of receiving the order with photos. We will remake the affected items or refund them,
          whichever is appropriate. This is our promise and your primary remedy.
        </p>
      </LegalSection>

      <LegalSection n="3" title="What isn't covered">
        <p>
          We can't offer refunds or remakes for errors approved in the mockup (including spelling
          and color choices), garment sizing you selected, normal variations in thread or fabric
          color, damage from improper laundering, or wear over time. Items decorated from files you
          resized or edited after purchase are likewise not covered.
        </p>
      </LegalSection>

      <LegalSection n="4" title="Deposits, setup fees, and cancellations">
        <p>
          Digitizing and setup fees pay for work that is performed up front, so they are
          non-refundable once that work has started. If you cancel an order before production
          begins, we will refund what you've paid minus any digitizing or setup work already
          completed. Once production has begun, orders cannot be cancelled.
        </p>
      </LegalSection>

      <LegalSection n="5" title="Digital design files">
        <p>
          Digital embroidery files (DST) are delivered electronically and cannot be returned. If a
          file we delivered is defective, contact us and we will correct and redeliver it.
        </p>
      </LegalSection>

      <LegalSection n="6" title="Blank, undecorated items">
        <p>
          Unworn, undecorated blank items purchased from us may be returned within 14 days in
          original condition for a refund of the item price; return shipping is the buyer's
          responsibility.
        </p>
      </LegalSection>
    </LegalShell>
  );
}

// ---------------- Liability Disclaimer ----------------
function LegalLiabilityPage() {
  return (
    <LegalShell slug="liability" title="Liability Disclaimer">
      <LegalSection n="1" title="Customer-supplied garments and goods">
        <p>
          You may supply your own garments or items for embroidery or printing by shipping them to
          us, dropping them off, or arranging pickup. Machine embroidery and decoration carry
          inherent risk, and in the rare event of a machine error, hooping mark, needle damage, or
          a defect in the supplied item itself, {HB_LEGAL_BUSINESS} is not responsible for
          replacing or reimbursing customer-supplied items. By providing your own goods, you accept
          this risk. We recommend supplying a spare when an order is critical.
        </p>
      </LegalSection>

      <LegalSection n="2" title="Customer-provided artwork">
        <p>
          You are solely responsible for the content and ownership of artwork you provide. By
          submitting a logo or design, you confirm you have the right to reproduce it, and you
          agree to hold {HB_LEGAL_BUSINESS} harmless from any claim that your artwork infringes a
          trademark, copyright, or other right of a third party. We reproduce artwork as supplied
          and approved; we are not responsible for errors contained in the artwork itself.
        </p>
      </LegalSection>

      <LegalSection n="3" title="Color and material variation">
        <p>
          Thread, vinyl, ink, and fabric colors can vary from how they appear on a screen, and
          slight variation between production runs is normal. Such variation is not a defect.
        </p>
      </LegalSection>

      <LegalSection n="4" title="Deadlines and shipping">
        <p>
          Quoted turnaround times are estimates measured in business days from artwork approval.
          Once an order ships, transit is in the carrier's hands; we are not liable for carrier
          delays, and missed-event damages are excluded as described in our Terms of Service.
        </p>
      </LegalSection>

      <LegalSection n="5" title="General">
        <p>
          Except as expressly stated in our Return &amp; Refund Policy, services and products are
          provided "as is" to the fullest extent permitted by {HB_LEGAL_STATE} law. Nothing in this
          disclaimer limits rights that cannot be limited under applicable law.
        </p>
      </LegalSection>
    </LegalShell>
  );
}

function LegalPage({ slug }) {
  switch (slug) {
    case "privacy":   return <LegalPrivacyPage />;
    case "refunds":   return <LegalRefundsPage />;
    case "liability": return <LegalLiabilityPage />;
    case "terms":
    default:          return <LegalTermsPage />;
  }
}

Object.assign(window, { LegalPage, HB_LEGAL_DOCS });
