/* policies.jsx — Policy modals, cookie consent bar, footer policy links */

/* ── Policy content ─────────────────────────────────── */
const POLICIES = {
  privacy: {
    title: "Privacy Policy",
    updated: "31 May 2026",
    sections: [
      { heading: null, body: `This Privacy Policy explains how Born to Know ("we," "us," or "our") handles personal data in connection with the website theborntoknow.com and the sale of the digital product The Baby Blueprint. Born to Know is a sole proprietorship established in the Netherlands. We can be reached at support@theborntoknow.com.\n\nWe respect your privacy and aim to collect as little personal data as possible.` },
      { heading: "Who is responsible for your data", body: `Born to Know is the data controller for the limited personal data described below. Our checkout and payment process is operated by Lemon Squeezy, which acts as our Merchant of Record. Lemon Squeezy is an independent data controller for the payment and order data it processes, and its own privacy policy applies to that processing. We encourage you to review Lemon Squeezy's privacy policy at lemonsqueezy.com.` },
      { heading: "What data we collect", body: `We collect only what is necessary to deliver the product and provide support:\n\n• Your email address, which you provide at checkout (collected through Lemon Squeezy) and which we use to deliver your purchase and respond to support requests.\n• Any information you choose to include when you contact us by email, such as your name, your message, and the details of your question.\n\nWe do not use analytics, advertising, tracking, or marketing tools on our website. We do not run a newsletter or email marketing list. We do not build profiles of visitors.` },
      { heading: "Payment information", body: `We do not collect, see, or store your payment card details. All payment information is processed directly by Lemon Squeezy and its payment processors. Lemon Squeezy, as Merchant of Record, also handles billing and applicable taxes.` },
      { heading: "Why we process your data and our legal basis", body: `Under the General Data Protection Regulation (GDPR), we process your data on the following legal bases:\n\n• To perform our contract with you, namely to deliver The Baby Blueprint and provide access to your purchase.\n• To respond to your questions and provide customer support, based on our legitimate interest in helping our customers.\n• To comply with legal obligations where applicable.` },
      { heading: "Who we share data with", body: `We share limited data only with service providers that make our business possible:\n\n• Lemon Squeezy, our Merchant of Record and checkout provider, which processes orders, payments, delivery, and applicable taxes.\n• Hostinger, our website hosting and domain provider, which hosts theborntoknow.com.\n\nWe do not sell your personal data, and we do not share it with advertisers.` },
      { heading: "How long we keep your data", body: `We keep order-related data, including your email address, for as long as necessary to provide access to your purchase, handle support requests, and meet any applicable legal or accounting obligations. Email correspondence is kept only as long as needed to resolve your request and for reasonable record-keeping.` },
      { heading: "International transfers", body: `Some of our service providers, such as Lemon Squeezy, may process data outside the European Economic Area. Where this occurs, we rely on appropriate safeguards such as Standard Contractual Clauses.` },
      { heading: "Your rights", body: `Under the GDPR, you have the right to access, correct, or delete the personal data we hold about you, to object to or restrict processing, and to lodge a complaint with the Dutch Data Protection Authority (Autoriteit Persoonsgegevens) at autoriteitpersoonsgegevens.nl. To exercise your rights, email us at support@theborntoknow.com.` },
      { heading: "Changes to this policy", body: `We may update this Privacy Policy from time to time. The 'Last updated' date reflects the most recent version.` },
      { heading: "Contact", body: `For any privacy question, email support@theborntoknow.com.` },
    ]
  },
  terms: {
    title: "Terms of Service",
    updated: "31 May 2026",
    sections: [
      { heading: null, body: `These Terms of Service ("Terms") govern your use of the website theborntoknow.com and your purchase and use of the digital product The Baby Blueprint (the "Product"). By using our website or purchasing the Product, you agree to these Terms. Born to Know is a sole proprietorship established in the Netherlands and can be reached at support@theborntoknow.com.` },
      { heading: "About the Product and the seller of record", body: `The Baby Blueprint is a digital ebook created and provided by Born to Know. Purchases are processed by Lemon Squeezy, which acts as the Merchant of Record. This means Lemon Squeezy is the seller of record for the transaction, handles payment and applicable taxes, and its own terms also apply to the checkout. Born to Know remains the creator and provider of the Product content.` },
      { heading: "License to use the Product", body: `When you purchase The Baby Blueprint, you receive a personal, non-exclusive, non-transferable license to download and read the ebook for your own personal, non-commercial use.\n\nYou may not copy, reproduce, redistribute, resell, sublicense, share, publicly post, or otherwise make the Product available to others, in whole or in part, without our prior written permission. The only exception is brief quotation for the purpose of review or commentary.` },
      { heading: "Intellectual property", body: `All content in The Baby Blueprint and on theborntoknow.com, including text, design, illustrations, and branding, is owned by Born to Know and is protected by copyright and other intellectual property laws. All rights not expressly granted to you are reserved.` },
      { heading: "Digital delivery", body: `The Product is delivered digitally. After a successful purchase, you receive access to download the Product through Lemon Squeezy. It is your responsibility to provide a correct email address and to download and store your copy. See our Digital Product and Delivery Disclaimer for details.` },
      { heading: "Refunds", body: `Because the Product is a digital item delivered immediately, all sales are final and no refunds are provided, except where required by applicable law. By purchasing and accessing the Product, you acknowledge our Refund Policy and the EU Right of Withdrawal Waiver, both of which form part of these Terms.` },
      { heading: "Educational purpose and no professional advice", body: `The Baby Blueprint is provided for educational and informational purposes only. It is not medical, psychological, or professional advice and is not a substitute for guidance from a licensed pediatrician or qualified healthcare professional. You remain responsible for decisions about your child's health, development, and care. Born to Know is not liable for any decisions or outcomes based on the Product.` },
      { heading: "Limitation of liability", body: `To the fullest extent permitted by law, Born to Know shall not be liable for any indirect, incidental, or consequential damages arising from your use of the website or the Product. Nothing in these Terms limits liability that cannot be limited under applicable Dutch law.` },
      { heading: "Governing law", body: `These Terms are governed by Dutch law. Any disputes shall be subject to the jurisdiction of the courts of the Netherlands, without prejudice to your rights as a consumer under applicable EU law.` },
      { heading: "Changes to these Terms", body: `We may update these Terms from time to time. The 'Last updated' date reflects the most recent version. Continued use of the website after changes constitutes acceptance of the updated Terms.` },
      { heading: "Contact", body: `For any question about these Terms, email support@theborntoknow.com.` },
    ]
  },
  refund: {
    title: "Refund Policy",
    updated: "31 May 2026",
    sections: [
      { heading: "All sales are final", body: `The Baby Blueprint is a digital product that is delivered immediately after purchase. Because you receive instant access to the full content, all sales are final and we do not offer refunds, returns, or exchanges, except where required by applicable law.` },
      { heading: "Why we have this policy", body: `Once a digital product has been delivered and can be downloaded, it cannot be 'returned' in any meaningful way. For this reason, and in line with standard practice for digital goods, purchases of The Baby Blueprint are non-refundable.` },
      { heading: "Your acknowledgment at purchase", body: `By completing your purchase and accessing the download, you expressly agree to immediate delivery of the digital content and acknowledge that you lose your right of withdrawal, as explained in our EU Right of Withdrawal Waiver. This means you understand that no refund will be available once you have accessed the Product.` },
      { heading: "Payment provider", body: `Purchases are processed by Lemon Squeezy, our Merchant of Record. In limited cases, refund handling may also be subject to Lemon Squeezy's own policies as the seller of record.` },
      { heading: "If you have a problem with your file", body: `While we do not offer refunds, we do want you to be able to access what you paid for. If your download does not work, the file appears corrupted, or you did not receive your access, please contact us at support@theborntoknow.com and we will help you access your copy.` },
      { heading: "Contact", body: `For any question about this policy, email support@theborntoknow.com.` },
    ]
  },
  cookies: {
    title: "Cookie Policy",
    updated: "31 May 2026",
    sections: [
      { heading: null, body: `This Cookie Policy explains how cookies are used in connection with the website theborntoknow.com.` },
      { heading: "What cookies are", body: `Cookies are small text files placed on your device when you visit a website. They can be used to make a website function, to remember preferences, or to analyze traffic.` },
      { heading: "Our approach to cookies", body: `We keep cookie use to a minimum. Born to Know does not use analytics, advertising, tracking, or marketing cookies on theborntoknow.com. We do not track your behavior across websites and we do not build visitor profiles.\n\nOur website may rely on essential cookies or similar technical files that are necessary for the website to load and function correctly through our hosting provider, Hostinger.` },
      { heading: "Cookies during checkout", body: `When you proceed to purchase, the checkout is operated by Lemon Squeezy, our Merchant of Record, on its own checkout environment. Lemon Squeezy may set its own cookies that are necessary to process your order and payment securely. The use of those cookies is governed by Lemon Squeezy's own cookie and privacy policies, which we encourage you to review at lemonsqueezy.com.` },
      { heading: "How to manage cookies", body: `You can control or delete cookies through your browser settings at any time. Because we do not use non-essential cookies, disabling cookies should not significantly affect your experience on theborntoknow.com, although the checkout provider may require certain essential cookies to complete a purchase.` },
      { heading: "Changes to this policy", body: `We may update this Cookie Policy from time to time. The 'Last updated' date reflects the most recent version.` },
      { heading: "Contact", body: `For any question about cookies, email support@theborntoknow.com.` },
    ]
  },
  legal: {
    title: "Legal Notice",
    updated: "31 May 2026",
    sections: [
      { heading: "Business information", body: `This website, theborntoknow.com, is operated by Born to Know, a sole proprietorship established in the Netherlands.\n\nContact email: support@theborntoknow.com\n\nBorn to Know operates as a digital business and does not maintain a public physical or postal address for visitors. The fastest and preferred way to reach us is by email.` },
      { heading: "Seller of record", body: `Sales of The Baby Blueprint are processed by Lemon Squeezy, which acts as the Merchant of Record and seller of record for transactions. Lemon Squeezy handles payment processing and applicable taxes. Born to Know is the creator and provider of the product content.` },
      { heading: "Hosting", body: `This website is hosted by Hostinger, which also provides our domain services.` },
      { heading: "Responsibility for content", body: `Born to Know is responsible for the content published on theborntoknow.com. We aim to keep all information accurate and up to date. The content of The Baby Blueprint and this website is provided for educational and informational purposes and does not constitute medical or professional advice.` },
      { heading: "Contact", body: `For any inquiry, email support@theborntoknow.com.` },
    ]
  },
  digital: {
    title: "Digital Product & Delivery Disclaimer",
    updated: "31 May 2026",
    sections: [
      { heading: "A digital product", body: `The Baby Blueprint is a digital ebook delivered as a downloadable PDF. It is not a physical book and nothing is shipped or mailed to you. No physical item will be sent.` },
      { heading: "How delivery works", body: `After you complete your purchase through our checkout, operated by Lemon Squeezy, you receive access to download The Baby Blueprint. Access is provided digitally, typically immediately, and a confirmation email is sent to the email address you provided at checkout.\n\nTo receive your Product successfully, please make sure you enter a correct and active email address at checkout. If you do not see your confirmation, please check your spam or promotions folder.` },
      { heading: "Device compatibility", body: `The Baby Blueprint is delivered as a PDF, which can be opened on most modern devices, including phones, tablets, computers, and e-readers that support PDF files. You are responsible for ensuring you have a compatible device and PDF reader.` },
      { heading: "If you do not receive your download", body: `If your download link does not work, your file appears corrupted, or you did not receive access to your purchase, please contact us at support@theborntoknow.com. We will help you access the copy you paid for.` },
      { heading: "Educational purpose", body: `The Baby Blueprint is provided for educational and informational purposes only. It is not medical, psychological, or professional advice and does not replace guidance from a licensed pediatrician or qualified healthcare professional. Always consult a qualified professional for concerns about your child's health, development, or care.` },
      { heading: "Contact", body: `For any delivery question, email support@theborntoknow.com.` },
    ]
  },
  withdrawal: {
    title: "EU Right of Withdrawal Waiver",
    updated: "31 May 2026",
    sections: [
      { heading: "Your standard right of withdrawal", body: `Under European Union and Dutch consumer law, consumers normally have a 14-day right of withdrawal ("cooling-off period") when buying online, during which they can cancel a purchase and receive a refund.` },
      { heading: "The exception for digital content", body: `The law provides an exception for digital content that is delivered immediately. When you buy digital content that is supplied without a physical medium, such as The Baby Blueprint, you can lose your right of withdrawal if you give your prior express consent to immediate delivery and acknowledge that you lose your right of withdrawal once delivery begins.` },
      { heading: "Your consent and acknowledgment", body: `By completing your purchase of The Baby Blueprint and accessing or downloading the Product, you expressly request and consent to immediate delivery of the digital content, and you acknowledge and agree that you thereby lose your 14-day right of withdrawal.` },
      { heading: "What this means", body: `Because you receive immediate access to the full digital Product, once delivery has begun you no longer have a right to withdraw from the purchase. This is the legal basis for our Refund Policy, under which all sales are final and no refunds are provided, except where required by applicable law.` },
      { heading: "Before you buy", body: `If you are unsure whether The Baby Blueprint is right for you, we encourage you to review the product description and the preview available on theborntoknow.com before purchasing, or to email us with any questions at support@theborntoknow.com before you complete your purchase.` },
      { heading: "Contact", body: `For any question about this waiver, email support@theborntoknow.com.` },
    ]
  },
};

/* ── Policy Modal ───────────────────────────────────── */
function PolicyModal({ policyKey, onClose }) {
  const policy = POLICIES[policyKey];
  React.useEffect(() => {
    const onKey = (e) => { if (e.key === "Escape") onClose(); };
    document.addEventListener("keydown", onKey);
    document.body.style.overflow = "hidden";
    return () => {
      document.removeEventListener("keydown", onKey);
      document.body.style.overflow = "";
    };
  }, [onClose]);

  if (!policy) return null;
  return (
    <div
      onClick={(e) => { if (e.target === e.currentTarget) onClose(); }}
      style={{
        position: "fixed", inset: 0, zIndex: 9999,
        background: "rgba(15,15,15,0.65)", backdropFilter: "blur(4px)",
        display: "flex", alignItems: "center", justifyContent: "center",
        padding: "16px"
      }}>
      <div style={{
        background: "#FAF6EE", borderRadius: 16, width: "100%", maxWidth: 680,
        maxHeight: "88vh", display: "flex", flexDirection: "column",
        boxShadow: "0 32px 80px rgba(0,0,0,0.35)",
        border: "1px solid rgba(200,162,74,0.20)"
      }}>
        {/* Header */}
        <div style={{
          display: "flex", alignItems: "center", justifyContent: "space-between",
          padding: "22px 28px 18px", borderBottom: "1px solid #E8DFCC", flexShrink: 0
        }}>
          <div>
            <h2 style={{
              fontFamily: "'Playfair Display', Georgia, serif",
              fontSize: 22, fontWeight: 800, color: "#0F0F0F",
              letterSpacing: "-0.01em", lineHeight: 1.1
            }}>{policy.title}</h2>
            <p style={{ fontFamily: "Inter,sans-serif", fontSize: 11, color: "#6B655B",
                         marginTop: 3, letterSpacing: "0.06em" }}>
              Last updated: {policy.updated}
            </p>
          </div>
          <button
            onClick={onClose}
            aria-label="Close"
            style={{
              width: 36, height: 36, borderRadius: "50%", border: "1px solid #E8DFCC",
              background: "#FFFCF5", cursor: "pointer", flexShrink: 0,
              display: "flex", alignItems: "center", justifyContent: "center",
              transition: "background 180ms ease"
            }}
            onMouseEnter={e => e.currentTarget.style.background = "#F4EDD8"}
            onMouseLeave={e => e.currentTarget.style.background = "#FFFCF5"}>
            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#3D3A33" strokeWidth="2.2" strokeLinecap="round">
              <path d="M18 6L6 18M6 6l12 12"/>
            </svg>
          </button>
        </div>

        {/* Scrollable body */}
        <div style={{ overflowY: "auto", padding: "24px 28px 32px", flex: 1 }}>
          {policy.sections.map((sec, i) => (
            <div key={i} style={{ marginBottom: 22 }}>
              {sec.heading && (
                <h3 style={{
                  fontFamily: "'Playfair Display', Georgia, serif",
                  fontSize: 15, fontWeight: 700, color: "#0F0F0F",
                  marginBottom: 6, letterSpacing: "-0.005em"
                }}>{sec.heading}</h3>
              )}
              {sec.body.split("\n\n").map((para, j) => (
                <p key={j} style={{
                  fontFamily: "Lora, Georgia, serif", fontSize: 14,
                  color: "#3D3A33", lineHeight: 1.72, marginBottom: 10
                }}>{para}</p>
              ))}
            </div>
          ))}
        </div>

        {/* Footer */}
        <div style={{
          padding: "14px 28px", borderTop: "1px solid #E8DFCC",
          display: "flex", justifyContent: "flex-end", flexShrink: 0
        }}>
          <button
            onClick={onClose}
            style={{
              fontFamily: "Inter,sans-serif", fontSize: 13, fontWeight: 600,
              color: "#FAF6EE", background: "#2C3A24", border: "none",
              borderRadius: 8, padding: "9px 22px", cursor: "pointer"
            }}>
            Close
          </button>
        </div>
      </div>
    </div>
  );
}

/* ── Cookie Consent Bar ─────────────────────────────── */
function CookieConsentBar({ onOpenPolicy }) {
  const [visible, setVisible] = React.useState(false);

  React.useEffect(() => {
    const accepted = localStorage.getItem("btk_cookies_accepted");
    if (!accepted) {
      const t = setTimeout(() => setVisible(true), 1200);
      return () => clearTimeout(t);
    }
  }, []);

  const accept = () => {
    localStorage.setItem("btk_cookies_accepted", "1");
    setVisible(false);
  };

  if (!visible) return null;

  return (
    <div style={{
      position: "fixed", bottom: 0, left: 0, right: 0, zIndex: 8888,
      background: "rgba(15,15,15,0.94)", backdropFilter: "blur(10px)",
      borderTop: "1px solid rgba(200,162,74,0.20)",
      padding: "14px 24px",
      display: "flex", alignItems: "center", justifyContent: "center",
      flexWrap: "wrap", gap: "10px 24px",
      animation: "slideUpCookie 320ms cubic-bezier(0.22,0.61,0.36,1)"
    }}>
      <p style={{
        fontFamily: "Lora, Georgia, serif", fontSize: 13,
        color: "rgba(250,246,238,0.85)", lineHeight: 1.5,
        maxWidth: 560, flex: "1 1 260px"
      }}>
        We only use essential cookies needed for the site to function.{" "}
        <button
          onClick={() => onOpenPolicy("cookies")}
          style={{
            background: "none", border: "none", padding: 0, cursor: "pointer",
            fontFamily: "inherit", fontSize: "inherit", color: "#C8A24A",
            textDecoration: "underline", textUnderlineOffset: 3
          }}>
          Learn more
        </button>
      </p>
      <div style={{ display: "flex", gap: 10, flexShrink: 0 }}>
        <button
          onClick={accept}
          style={{
            fontFamily: "Inter,sans-serif", fontSize: 13, fontWeight: 600,
            background: "#2C3A24", color: "#FAF6EE", border: "1px solid rgba(200,162,74,0.35)",
            borderRadius: 8, padding: "9px 22px", cursor: "pointer", whiteSpace: "nowrap"
          }}>
          Accept
        </button>
      </div>
    </div>
  );
}

function PolicyFooterLinks({ onOpen }) {
  const links = [
    ["privacy",    "Privacy Policy"],
    ["terms",      "Terms of Service"],
    ["refund",     "Refund Policy"],
    ["cookies",    "Cookie Policy"],
    ["legal",      "Legal Notice"],
    ["digital",    "Delivery Disclaimer"],
    ["withdrawal", "EU Withdrawal Waiver"],
  ];
  return (
    <div style={{ display: "flex", flexWrap: "wrap", alignItems: "center", gap: "4px 0" }}>
      {links.map(([key, label], i) => (
        <React.Fragment key={key}>
          <button
            onClick={() => onOpen(key)}
            style={{
              background: "none", border: "none", padding: "0 2px", cursor: "pointer",
              fontFamily: "Inter, sans-serif", fontSize: 11.5, color: "#6B655B",
              transition: "color 180ms ease", letterSpacing: "0.02em", whiteSpace: "nowrap"
            }}
            onMouseEnter={e => e.currentTarget.style.color = "#A8851F"}
            onMouseLeave={e => e.currentTarget.style.color = "#6B655B"}>
            {label}
          </button>
          {i < links.length - 1 && (
            <span style={{ color: "#C8A24A", padding: "0 8px", fontSize: 10, userSelect: "none" }}>·</span>
          )}
        </React.Fragment>
      ))}
    </div>
  );
}

/* ── PoliciesSystem — mounts modals + cookie bar ────── */
function PoliciesSystem() {
  const [openPolicy, setOpenPolicy] = React.useState(null);

  // Expose openPolicy globally so footer links can trigger it
  React.useEffect(() => {
    window.__openPolicy = setOpenPolicy;
    return () => { delete window.__openPolicy; };
  }, []);

  return (
    <>
      <CookieConsentBar onOpenPolicy={setOpenPolicy} />
      {openPolicy && (
        <PolicyModal policyKey={openPolicy} onClose={() => setOpenPolicy(null)} />
      )}
      <style>{`
        @keyframes slideUpCookie {
          from { transform: translateY(100%); opacity: 0; }
          to   { transform: translateY(0);    opacity: 1; }
        }
      `}</style>
    </>
  );
}

Object.assign(window, { PoliciesSystem, PolicyFooterLinks });
