/* global React, Icons */
// ============================================================
//  Legal — Privacy Policy + Refund & Cancellation Policy
//  Operated by Nestaa · get-resume.com
// ============================================================
const LEGAL_BRAND = "get-resume.com";
const LEGAL_ENTITY = "Nestaa";
const LEGAL_EMAIL = "care@get-resume.com";
const LEGAL_UPDATED = "7 June 2026";
const LEGAL_PRICE = (window.Pro && window.Pro.price) || "₹599";

function LegalShell({ title, intro, onHome, onBack, children }) {
  React.useEffect(() => { window.scrollTo(0, 0); }, []);
  return (
    <div className="legal wrap">
      <button className="legal-back" onClick={onBack}><Icons.arrowL size={15} /> Back</button>
      <div className="legal-head">
        <div className="eyebrow">Legal</div>
        <h1>{title}</h1>
        <p className="legal-updated">Last updated {LEGAL_UPDATED} · Operated by {LEGAL_ENTITY} ({LEGAL_BRAND})</p>
        {intro && <p className="legal-intro">{intro}</p>}
      </div>
      <div className="legal-body">{children}</div>
      <div className="legal-foot">
        <span>© 2026 {LEGAL_ENTITY}. All rights reserved.</span>
        <button onClick={onHome}>Back to home <Icons.arrow size={14} /></button>
      </div>
    </div>
  );
}

function LegalSection({ n, title, children }) {
  return (
    <section className="legal-sec">
      <h2>{n}. {title}</h2>
      {children}
    </section>
  );
}

function PrivacyPolicy(props) {
  return (
    <LegalShell title="Privacy Policy"
      intro={`This Privacy Policy explains how ${LEGAL_ENTITY} ("we", "us") collects, uses and protects your information when you use ${LEGAL_BRAND}.`}
      {...props}>
      <LegalSection n="1" title="Who we are">
        <p>{LEGAL_BRAND} is an online résumé and cover-letter builder operated by {LEGAL_ENTITY}. You can reach us any time at <a href={`mailto:${LEGAL_EMAIL}`}>{LEGAL_EMAIL}</a>.</p>
      </LegalSection>
      <LegalSection n="2" title="Information we collect">
        <ul>
          <li><b>Résumé &amp; cover-letter content</b> — the text, details and images you add. This is saved in your browser's local storage on your own device so your work persists between visits.</li>
          <li><b>Account &amp; billing details</b> — when you subscribe to Pro, your name, email and payment information are handled by our third-party payment processor. We do not store full card numbers.</li>
          <li><b>Usage data</b> — basic, aggregated information about how the product is used, to help us improve it.</li>
        </ul>
      </LegalSection>
      <LegalSection n="3" title="How we use your information">
        <ul>
          <li>To provide, maintain and improve the service.</li>
          <li>To process Pro subscriptions and respond to support requests.</li>
          <li>To keep the service secure and prevent abuse.</li>
        </ul>
      </LegalSection>
      <LegalSection n="4" title="AI writing features">
        <p>When you choose to improve a line with AI, only the relevant text is sent to our AI provider to generate a suggestion. We do not use your résumé content to train AI models, and the content is not shared for advertising.</p>
      </LegalSection>
      <LegalSection n="5" title="Storage, cookies &amp; security">
        <p>Your résumé data is stored locally in your browser, not on a central profile. We use local storage to remember your work and preferences. We apply reasonable technical and organisational measures to protect information we do process, though no method of transmission or storage is completely secure.</p>
      </LegalSection>
      <LegalSection n="6" title="Sharing your information">
        <p>We do not sell your personal information. We share it only with service providers who help us run {LEGAL_BRAND} — such as our payment processor and AI provider — and only to the extent needed to deliver the service, or where required by law.</p>
      </LegalSection>
      <LegalSection n="7" title="Your rights">
        <p>You can access, correct or delete your résumé content at any time by editing it or clearing your browser's local storage. For questions about data we hold, or to exercise your rights, email <a href={`mailto:${LEGAL_EMAIL}`}>{LEGAL_EMAIL}</a>.</p>
      </LegalSection>
      <LegalSection n="8" title="Children">
        <p>{LEGAL_BRAND} is not directed to children under 16, and we do not knowingly collect their information.</p>
      </LegalSection>
      <LegalSection n="9" title="Changes to this policy">
        <p>We may update this policy from time to time. Material changes will be reflected by the "last updated" date above.</p>
      </LegalSection>
      <LegalSection n="10" title="Contact">
        <p>{LEGAL_ENTITY} — <a href={`mailto:${LEGAL_EMAIL}`}>{LEGAL_EMAIL}</a></p>
      </LegalSection>
    </LegalShell>
  );
}

function RefundPolicy(props) {
  return (
    <LegalShell title="Refund &amp; Cancellation Policy"
      intro={`This policy explains how subscriptions to ${LEGAL_BRAND} Pro can be cancelled and when refunds apply.`}
      {...props}>
      <LegalSection n="1" title="Subscriptions">
        <p>{LEGAL_BRAND} is free to build, edit and copy as text. {LEGAL_BRAND} Pro is an optional subscription billed at <b>{LEGAL_PRICE}/month</b>, charged in advance each billing cycle, which unlocks PDF downloads, unlimited AI writing and all premium templates.</p>
      </LegalSection>
      <LegalSection n="2" title="Cancelling your subscription">
        <p>You can cancel any time from the <b>Manage your Pro plan</b> screen (the crown button in the top bar). When you cancel, you keep Pro access until the end of your current billing period, and you will not be charged again.</p>
      </LegalSection>
      <LegalSection n="3" title="Refunds">
        <ul>
          <li><b>7-day satisfaction window</b> — if you're not happy with Pro, email us within 7 days of your <i>first</i> payment and we'll issue a full refund.</li>
          <li><b>Renewals</b> — recurring renewal payments are generally non-refundable once the new period has begun, since access is granted immediately.</li>
          <li><b>Billing errors</b> — if you were charged in error or twice, contact us and we'll make it right.</li>
        </ul>
      </LegalSection>
      <LegalSection n="4" title="How to request a refund">
        <p>Email <a href={`mailto:${LEGAL_EMAIL}`}>{LEGAL_EMAIL}</a> from the address on your account, with the reason for your request. We aim to respond within 2 business days.</p>
      </LegalSection>
      <LegalSection n="5" title="How refunds are issued">
        <p>Approved refunds are returned to your original payment method, typically within 5–10 business days depending on your bank or card provider.</p>
      </LegalSection>
      <LegalSection n="6" title="Contact">
        <p>{LEGAL_ENTITY} — <a href={`mailto:${LEGAL_EMAIL}`}>{LEGAL_EMAIL}</a></p>
      </LegalSection>
    </LegalShell>
  );
}

function LegalPage({ kind, onHome, onBack }) {
  return kind === "refund"
    ? <RefundPolicy onHome={onHome} onBack={onBack} />
    : <PrivacyPolicy onHome={onHome} onBack={onBack} />;
}

window.LegalPage = LegalPage;
