// Legal.jsx — shared prose layout for Privacy / Terms / Cookies pages.
// Renders a clean, readable legal document body that matches the design tokens.
//
// Usage:
//   <LDLegalBody updated="24 June 2026" sections={[...]} />
//
// A section is: { id, h, body: [ ...nodes ] }
// A node is one of:
//   "plain paragraph string"
//   { h4: "Sub-heading" }
//   { ul: ["item", "item", ...] }       // bulleted list
//   { note: "callout / disclaimer text" }

function LDLegalNode({ node }) {
  if (typeof node === "string") {
    return <p className="ld-body" style={{ marginBottom: 16, color: "var(--ld-ink-2)" }}>{node}</p>;
  }
  if (node.h4) {
    return <h3 className="ld-h4" style={{ marginTop: 28, marginBottom: 12 }}>{node.h4}</h3>;
  }
  if (node.ul) {
    return (
      <ul style={{ margin: "0 0 16px", paddingLeft: 22, display: "flex", flexDirection: "column", gap: 8 }}>
        {node.ul.map((li, i) => (
          <li key={i} className="ld-body" style={{ color: "var(--ld-ink-2)", lineHeight: 1.6 }}>{li}</li>
        ))}
      </ul>
    );
  }
  if (node.table) {
    const { head, rows } = node.table;
    return (
      <div style={{ overflowX: "auto", margin: "8px 0 24px" }}>
        <table style={{ width: "100%", borderCollapse: "collapse", fontSize: 14, minWidth: 420 }}>
          <thead>
            <tr>
              {head.map((h, i) => (
                <th key={i} className="ld-mono" style={{
                  textAlign: "left", padding: "10px 14px",
                  background: "var(--ld-cream-2)", color: "var(--ld-ink-2)",
                  borderBottom: "1px solid var(--ld-line)",
                  textTransform: "uppercase", letterSpacing: "0.6px", fontWeight: 600,
                  whiteSpace: "nowrap",
                }}>{h}</th>
              ))}
            </tr>
          </thead>
          <tbody>
            {rows.map((r, ri) => (
              <tr key={ri}>
                {r.map((cell, ci) => (
                  <td key={ci} style={{
                    padding: "11px 14px", color: "var(--ld-ink-2)", lineHeight: 1.5,
                    borderBottom: "1px solid var(--ld-line-soft)",
                    fontFamily: ci === 0 ? "var(--ld-font-mono)" : "inherit",
                    verticalAlign: "top",
                  }}>{cell}</td>
                ))}
              </tr>
            ))}
          </tbody>
        </table>
      </div>
    );
  }
  if (node.note) {
    return (
      <div style={{
        margin: "8px 0 20px",
        background: "var(--ld-yellow-tint)",
        border: "1px solid var(--ld-yellow-deep)",
        borderRadius: "var(--ld-r-md)",
        padding: "14px 18px",
      }}>
        <p className="ld-small" style={{ color: "var(--ld-ink-2)", margin: 0, lineHeight: 1.55 }}>{node.note}</p>
      </div>
    );
  }
  return null;
}

function LDLegalBody({ updated, sections }) {
  return (
    <section style={{ background: "var(--ld-paper)", padding: "64px 0 88px" }}>
      <div className="ld-container" style={{ maxWidth: 1080 }}>
        <div className="ld-legal-grid" style={{ display: "grid", gridTemplateColumns: "232px minmax(0,1fr)", gap: 56, alignItems: "start" }}>

          {/* sticky table of contents */}
          <nav className="ld-legal-toc" style={{ position: "sticky", top: 92 }}>
            <div className="ld-mono" style={{ color: "var(--ld-ink-soft)", textTransform: "uppercase", letterSpacing: "1.4px", fontWeight: 600, marginBottom: 14 }}>
              On this page
            </div>
            <ul style={{ listStyle: "none", margin: 0, padding: 0, display: "flex", flexDirection: "column", gap: 10 }}>
              {sections.map((s) => (
                <li key={s.id}>
                  <a href={"#" + s.id} className="ld-small" style={{ color: "var(--ld-ink-mute)", lineHeight: 1.4 }}>{s.h}</a>
                </li>
              ))}
            </ul>
          </nav>

          {/* document body */}
          <div>
            {updated && (
              <p className="ld-mono" style={{ color: "var(--ld-ink-soft)", marginBottom: 36 }}>
                Last updated: {updated}
              </p>
            )}
            {sections.map((s) => (
              <div key={s.id} id={s.id} style={{ scrollMarginTop: 92, marginBottom: 44 }}>
                <h2 className="ld-h3" style={{ marginBottom: 16 }}>{s.h}</h2>
                {s.body.map((node, i) => <LDLegalNode key={i} node={node} />)}
              </div>
            ))}
          </div>
        </div>
      </div>
    </section>
  );
}

window.LDLegalBody = LDLegalBody;

// ---- legal document content (single source for the .html pages + the artifact router) ----
window.LD_LEGAL = {
  privacy: {
    title: "Privacy Policy",
    sub: "How Local Delivery Premium, by Locate2u, collects, uses, and protects personal information.",
    updated: "January 2026",
    sections: [
      { id: "about", h: "About this policy", body: [
        "Local Delivery Premium is a Shopify app published by Locate Technologies Limited (“Locate2u”, “we”, “us”). It lets Shopify merchants offer local delivery and pickup scheduling at checkout. This Privacy Policy applies to the Local Delivery Premium app and website and follows the same data practices as the Locate2u Privacy Policy.",
        { note: "Local Delivery Premium is part of the Locate2u family. Where this policy and the master Locate2u Privacy Policy at locate2u.com/legal/privacy differ, the Locate2u Privacy Policy prevails." },
      ] },
      { id: "information-we-collect", h: "Information We Collect", body: [
        "When you install and use Local Delivery Premium, we collect information that you provide directly to us. This includes personal details such as your name, email address, phone number, company name, and billing information when you create an account or subscribe to our services.",
        "We also collect information automatically when you interact with our platform. This includes device information, IP addresses, browser type, operating system, pages visited, and usage patterns within the application.",
        "If you integrate Locate2u with third-party services such as Shopify, Zapier, or Xero, we may receive additional data from those platforms as necessary to provide the integrated functionality you have requested.",
        "Because Local Delivery Premium operates inside your Shopify store, we also process limited order and customer information needed to schedule deliveries and pickups. This includes the store details Shopify provides when you install the app, the delivery or pickup location, date, and time slot a customer selects at checkout, delivery address details such as postcode or suburb, an optional delivery note, and the associated Shopify order reference.",
      ] },
      { id: "how-we-use", h: "How We Use Your Information", body: [
        "We use the information we collect to provide, maintain, and improve our local delivery and pickup scheduling services. This includes presenting delivery and pickup options at checkout, calculating delivery fees, recording the date and time a customer chooses, and — when you enable it — syncing delivery and pickup stops to your Locate2u account.",
        "Your information also helps us communicate with you about your account, respond to support requests, send service updates, and provide technical notices. We may use aggregated and anonymized data to analyze trends, monitor platform performance, and develop new features.",
        "We do not sell your personal information to third parties. We do not use your delivery data for advertising purposes. Your operational data belongs to you and is used solely to power the services you have subscribed to.",
      ] },
      { id: "information-sharing", h: "Information Sharing", body: [
        "We share your information only in limited circumstances. We may share data with trusted service providers who help us operate the platform, such as cloud hosting providers, payment processors, and email delivery services. These providers are contractually obligated to protect your data and may only use it to perform services on our behalf.",
        "For Local Delivery Premium specifically, these providers include Shopify (the platform the app runs on and the source of order data), Cloudflare (hosting and compute for the app's backend), and Supabase (the database where app settings and delivery selections are stored). When you enable the Locate2u integration, the delivery and pickup details needed to create a stop are shared with your Locate2u account.",
        "We may also disclose your information if required by law, in response to a valid legal request, or to protect the rights, safety, or property of Locate2u, our users, or the public.",
      ] },
      { id: "data-security", h: "Data Security", body: [
        "We take the security of your data seriously. Locate2u employs industry-standard security measures including encryption in transit (TLS/SSL) and at rest (AES-256), regular security audits, access controls, and monitoring systems to protect against unauthorized access, alteration, or destruction of your information.",
        "Our infrastructure is hosted on enterprise-grade cloud platforms with SOC 2 compliance, and we maintain regular backups to ensure data availability. While no method of transmission or storage is completely secure, we continuously review and update our security practices to align with current best practices.",
      ] },
      { id: "your-rights", h: "Your Rights", body: [
        "You have the right to access, correct, or delete your personal information at any time. You can update most of your account information directly through your Locate2u dashboard. For requests that cannot be handled through the dashboard, please contact our support team.",
        "If you are a customer of a store that uses Local Delivery Premium, we process your information on that merchant's behalf. We may therefore direct your request to the merchant who collected it.",
        "If you are located in the European Economic Area, the United Kingdom, or other jurisdictions with applicable data protection laws, you may also have the right to restrict processing, object to processing, and request data portability. We will respond to valid requests within the timeframes required by applicable law.",
        "You may opt out of non-essential communications at any time by using the unsubscribe link in our emails or by updating your notification preferences in your account settings.",
      ] },
      { id: "cookies", h: "Cookies", body: [
        "Locate2u uses cookies and similar tracking technologies to provide and improve our services. Essential cookies are required for the platform to function properly, including maintaining your session and remembering your preferences. We also use analytics cookies to understand how users interact with our platform so we can make improvements.",
        "You can manage your cookie preferences through your browser settings. For more detailed information about the cookies we use, please refer to our Cookie Policy.",
      ] },
      { id: "contact", h: "Contact Us", body: [
        "If you have any questions about this Privacy Policy or our data practices, please contact us at:",
        { ul: ["Email: privacy@locate2u.com", "Mail: Locate Technologies Limited, Level 5, 20 Customhouse Quay, Wellington 6011, New Zealand"] },
        "We will make every effort to respond to your inquiry within 30 days. If you are not satisfied with our response, you may have the right to lodge a complaint with your local data protection authority.",
      ] },
    ],
  },
  terms: {
    title: "Terms & Conditions",
    sub: "The terms that apply when you use the Local Delivery Premium app and website.",
    updated: "January 2026",
    sections: [
      { id: "acceptance", h: "Acceptance of Terms", body: [
        "By accessing or using Local Delivery Premium, the Locate2u platform, website, mobile applications, or any associated services (collectively, the “Service”), you agree to be bound by these Terms and Conditions. If you are using the Service on behalf of an organization, you represent and warrant that you have the authority to bind that organization to these terms.",
        "If you do not agree to these terms, you must not access or use the Service. We reserve the right to update or modify these terms at any time, and your continued use of the Service after any changes constitutes acceptance of the revised terms.",
        { note: "Local Delivery Premium is a Shopify app published by Locate Technologies Limited (“Locate2u”). Your use of the Shopify platform also remains subject to Shopify's own terms." },
      ] },
      { id: "use-of-service", h: "Use of Service", body: [
        "Locate2u grants you a limited, non-exclusive, non-transferable, revocable license to access and use the Service in accordance with your subscription plan and these terms. You may use the Service solely for your lawful business operations, including local delivery and pickup scheduling, route optimization, fleet tracking, delivery management, and related logistics activities.",
        "You agree not to use the Service to:",
        { ul: [
          "Violate any applicable local, national, or international law or regulation",
          "Transmit any material that is unlawful, harmful, threatening, abusive, or otherwise objectionable",
          "Attempt to gain unauthorized access to the Service, other user accounts, or connected systems",
          "Reverse engineer, decompile, or disassemble any part of the Service",
          "Use automated scripts, bots, or other tools to access the Service beyond what is permitted by your subscription and the API documentation",
          "Resell, sublicense, or redistribute the Service without prior written consent from Locate2u",
        ] },
        "We reserve the right to suspend or terminate your access if we reasonably believe you are in violation of these terms or are engaging in activities that could harm the Service or other users.",
        "Any delivery or pickup fees you configure in Local Delivery Premium are set and collected by you from your own customers through Shopify. We calculate and present those fees based on the settings you provide.",
      ] },
      { id: "user-accounts", h: "User Accounts", body: [
        "To use the Service, you must create an account and provide accurate, complete, and current information. You are responsible for maintaining the confidentiality of your account credentials and for all activities that occur under your account. You must notify us immediately if you become aware of any unauthorized use of your account.",
        "Account administrators have the ability to add, remove, and manage team members within their organization's account. The account owner is responsible for the actions of all users added to their account and for ensuring that team members comply with these terms.",
        "You may not share your login credentials with unauthorized individuals, create multiple accounts to circumvent plan limitations, or transfer your account to another party without our prior written consent.",
      ] },
      { id: "intellectual-property", h: "Intellectual Property", body: [
        "The Service, including all software, algorithms, user interfaces, designs, documentation, trademarks, and content created by Locate2u, is the exclusive property of Locate Technologies Limited and is protected by intellectual property laws. Nothing in these terms grants you ownership of any intellectual property belonging to Locate2u.",
        "You retain all ownership rights to the data you upload, create, or generate through the Service, including delivery addresses, route data, proof of delivery records, and customer information. By using the Service, you grant Locate2u a limited license to process and store your data as necessary to provide the Service.",
        "We may use aggregated, anonymized data derived from your use of the Service to improve our algorithms, analyze platform performance, and develop new features. This data will not identify you or your customers.",
      ] },
      { id: "liability", h: "Limitation of Liability", body: [
        "To the fullest extent permitted by law, Locate2u and its officers, directors, employees, and agents shall not be liable for any indirect, incidental, special, consequential, or punitive damages, including but not limited to loss of profits, data, business opportunities, or goodwill, arising out of or related to your use of the Service.",
        "Our total liability for any claims arising from or related to the Service shall not exceed the total amount you paid to Locate2u during the twelve (12) months immediately preceding the event giving rise to the claim. This limitation applies regardless of the legal theory on which the claim is based.",
        "The Service relies on third-party mapping data, GPS signals, traffic information, and network connectivity. While we strive for accuracy, we do not guarantee that route calculations, ETAs, or tracking data will be error-free at all times. You acknowledge that real-world conditions may differ from the information provided by the Service.",
      ] },
      { id: "termination", h: "Termination", body: [
        "You may cancel your subscription and terminate your account at any time through your account settings, by uninstalling the app from your Shopify store, or by contacting our support team. Upon cancellation, your access to the Service will continue until the end of your current billing period, after which your account will be deactivated.",
        "We may terminate or suspend your access to the Service immediately, without prior notice, if you breach these terms, fail to pay subscription fees, or if we are required to do so by law. In the event of termination for cause, you will not be entitled to a refund of any prepaid fees.",
        "Upon termination, you may request an export of your data for a period of 30 days. After this period, we reserve the right to delete your data from our systems, except as required to comply with legal obligations or resolve disputes.",
      ] },
      { id: "governing-law", h: "Governing Law", body: [
        "These terms shall be governed by and construed in accordance with the laws of New Zealand, without regard to its conflict of law principles. Any disputes arising from or related to these terms or the Service shall be subject to the exclusive jurisdiction of the courts of New Zealand.",
        "If any provision of these terms is found to be unenforceable or invalid, that provision shall be limited or eliminated to the minimum extent necessary, and the remaining provisions shall continue in full force and effect.",
        "These terms, together with our Privacy Policy and Cookie Policy, constitute the entire agreement between you and Locate2u with respect to the Service and supersede all prior agreements, understandings, and representations.",
      ] },
      { id: "contact", h: "Contact", body: [
        "If you have any questions about these Terms and Conditions, please contact us at:",
        { ul: ["Email: legal@locate2u.com", "Mail: Locate Technologies Limited, Level 5, 20 Customhouse Quay, Wellington 6011, New Zealand"] },
      ] },
    ],
  },
  cookies: {
    title: "Cookie Policy",
    sub: "What cookies the Local Delivery Premium website and Locate2u platform use, and how to control them.",
    updated: "January 2026",
    sections: [
      { id: "what-are-cookies", h: "What Are Cookies", body: [
        "Cookies are small text files that are stored on your device (computer, tablet, or mobile phone) when you visit a website. They are widely used to make websites work more efficiently, provide a better user experience, and give website operators information about how the site is being used.",
        "Cookies can be “session” cookies, which are temporary and deleted when you close your browser, or “persistent” cookies, which remain on your device for a set period of time or until you manually delete them. Cookies can be set by the website you are visiting (“first-party cookies”) or by third-party services that the website uses (“third-party cookies”).",
        "This Cookie Policy explains what cookies and similar technologies the Local Delivery Premium website and the Locate2u platform use, why we use them, and your choices regarding their use. Local Delivery Premium is a Shopify app published by Locate Technologies Limited (“Locate2u”).",
      ] },
      { id: "cookies-we-use", h: "Cookies We Use", body: [
        { h4: "Essential Cookies" },
        "These cookies are strictly necessary for the Locate2u platform to function. They enable core features such as user authentication, session management, and security protections. Without these cookies, the services you have requested cannot be provided. Essential cookies cannot be disabled.",
        { table: { head: ["Cookie", "Purpose", "Duration"], rows: [
          ["session_id", "Maintains your authenticated session while using the platform", "Session"],
          ["csrf_token", "Protects against cross-site request forgery attacks", "Session"],
          ["cookie_consent", "Stores your cookie preference selections", "12 months"],
        ] } },
        { h4: "Analytics Cookies" },
        "Analytics cookies help us understand how visitors interact with the Locate2u website and platform. They collect information about which pages are visited, how long users spend on each page, and any errors encountered. This data is aggregated and anonymized, meaning it cannot be used to identify you personally. We use this information to improve our website and the user experience.",
        { table: { head: ["Cookie", "Purpose", "Duration"], rows: [
          ["_ga", "Distinguishes unique visitors for site analytics", "24 months"],
          ["_ga_*", "Maintains session state for analytics tracking", "24 months"],
        ] } },
        { h4: "Functionality Cookies" },
        "Functionality cookies allow the Locate2u platform to remember choices you have made and provide enhanced, personalized features. For example, these cookies may remember your preferred language, region, dashboard layout, or map view settings. If you disable these cookies, some features may not function as intended.",
        { table: { head: ["Cookie", "Purpose", "Duration"], rows: [
          ["user_prefs", "Stores your dashboard and display preferences", "12 months"],
          ["map_settings", "Remembers your preferred map view and zoom level", "6 months"],
          ["locale", "Stores your preferred language and region settings", "12 months"],
        ] } },
      ] },
      { id: "managing-cookies", h: "Managing Cookies", body: [
        "You have the right to decide whether to accept or reject cookies. When you first visit the Locate2u website, you will be presented with a cookie consent banner that allows you to accept or customize your cookie preferences. You can change your preferences at any time through the cookie settings link in the footer of our website.",
        "You can also manage cookies through your web browser settings. Most browsers allow you to view, delete, and block cookies from websites. Please note that if you choose to block or delete cookies, some features of the Locate2u platform may not work as intended. Here are links to cookie management instructions for common browsers:",
        { ul: [
          "Google Chrome: Settings → Privacy and Security → Cookies and other site data",
          "Mozilla Firefox: Settings → Privacy & Security → Cookies and Site Data",
          "Safari: Preferences → Privacy → Manage Website Data",
          "Microsoft Edge: Settings → Cookies and site permissions → Cookies and site data",
        ] },
      ] },
      { id: "third-party-cookies", h: "Third-Party Cookies", body: [
        "Some cookies on the Locate2u website are set by third-party services that appear on our pages. We use third-party services for analytics (such as Google Analytics), mapping (such as Google Maps and Mapbox), and customer support. These third parties may set their own cookies to provide their services and may collect information about your online activities across different websites.",
        "We do not control the cookies set by third parties. We encourage you to review the privacy and cookie policies of these third-party services for more information about their data practices. We select our third-party partners carefully and only work with providers who meet our standards for data protection and privacy.",
        "We do not use cookies for targeted advertising purposes. No advertising cookies or tracking pixels are used on the Locate2u platform.",
      ] },
      { id: "contact", h: "Contact", body: [
        "If you have any questions about our use of cookies or this Cookie Policy, please contact us at:",
        { ul: ["Email: privacy@locate2u.com", "Mail: Locate Technologies Limited, Level 5, 20 Customhouse Quay, Wellington 6011, New Zealand"] },
        "For more information about how we handle your personal data, please see our Privacy Policy.",
      ] },
    ],
  },
};

// full legal page (nav + hero + body + footer), used by the .html pages and the artifact router
function LDLegalPage({ doc }) {
  const d = window.LD_LEGAL[doc];
  if (!d) return null;
  return (
    <React.Fragment>
      <window.LDNav active="" />
      <window.LDSubpageHero eyebrow="Legal" title={d.title} sub={d.sub} />
      <LDLegalBody updated={d.updated} sections={d.sections} />
      <window.LDFooter />
    </React.Fragment>
  );
}
window.LDLegalPage = LDLegalPage;