// Footer + Privacy modal

function SiteFooter({ openPrivacy }) {
  const year = new Date().getFullYear();
  return (
    <footer className="site-footer">
      <div className="site-wrap">
        <div className="footer-cols">
          <div className="footer-col">
            <div style={{ display: 'flex', alignItems: 'center', gap: 10, marginBottom: 8 }}>
              <span className="brand-mark">F</span>
              <span className="brand-name">fsacredit<span className="tld">.com</span></span>
            </div>
            <p className="footer-tag">
              The free Dependent Care FSA vs. Tax Credit calculator for working parents. Pick the optimal split, not the popular one.
            </p>
          </div>
          <div className="footer-col">
            <h4>The tool</h4>
            <ul>
              <li><a href="#calculator">Calculator</a></li>
              <li><a href="#result">Your results</a></li>
              <li><a href="#how-it-works">How it works</a></li>
              <li><a href="#faq">FAQ</a></li>
            </ul>
          </div>
          <div className="footer-col">
            <h4>Related</h4>
            <ul>
              <li><a href="https://www.irs.gov/forms-pubs/about-form-2441" rel="noopener" target="_blank">IRS Form 2441 (CDCC) ↗</a></li>
              <li><a href="https://www.irs.gov/publications/p503" rel="noopener" target="_blank">IRS Pub. 503 — Child &amp; Dependent Care ↗</a></li>
              <li><a href="https://www.irs.gov/credits-deductions/individuals/child-tax-credit" rel="noopener" target="_blank">IRS Child Tax Credit ↗</a></li>
              <li><a href="https://scorpbreakeven.com" rel="noopener" target="_blank">scorpbreakeven.com — S-corp breakeven for small-biz parents ↗</a></li>
              <li><a href="https://10yearrmd.com" rel="noopener" target="_blank">10yearrmd.com — Inherited IRA payouts ↗</a></li>
            </ul>
          </div>
        </div>

        <div className="footer-divider" />

        <p className="footer-legal">
          <strong>Not tax advice.</strong> This calculator uses 2025 IRS limits (DCFSA $5,000 / $2,500 MFS, CDCC expense base $3,000 / $6,000, CTC $2,000/qualifying child under 17). Sources: IRS Publication 503, Form 2441 instructions, and IRS inflation announcements. Limits are reviewed and updated each January when the IRS publishes the new year's figures. Your actual tax outcome depends on details this tool doesn't capture — state taxes, AMT, other credits, and your specific employer's plan terms. Consult a CPA or tax professional for advice on your situation.
        </p>

        <div className="footer-bottom">
          <span>© {year} fsacredit.com · An independent calculator, not affiliated with the IRS, the U.S. Treasury, or any tax preparation service.</span>
          <button type="button" onClick={openPrivacy}>Privacy</button>
        </div>
      </div>
    </footer>
  );
}

function PrivacyModal({ open, onClose }) {
  const modalRef = React.useRef(null);

  React.useEffect(() => {
    if (!open) return;
    const onKey = (e) => {
      if (e.key === 'Escape') onClose();
      // Focus trap
      if (e.key === 'Tab' && modalRef.current) {
        const focusables = modalRef.current.querySelectorAll(
          'a, button, input, select, textarea, [tabindex]:not([tabindex="-1"])'
        );
        if (!focusables.length) return;
        const first = focusables[0];
        const last = focusables[focusables.length - 1];
        if (e.shiftKey && document.activeElement === first) {
          e.preventDefault(); last.focus();
        } else if (!e.shiftKey && document.activeElement === last) {
          e.preventDefault(); first.focus();
        }
      }
    };
    document.addEventListener('keydown', onKey);
    document.body.style.overflow = 'hidden';
    // Initial focus
    setTimeout(() => {
      const closeBtn = modalRef.current?.querySelector('.modal-close');
      closeBtn?.focus();
    }, 30);
    return () => {
      document.removeEventListener('keydown', onKey);
      document.body.style.overflow = '';
    };
  }, [open, onClose]);

  if (!open) return null;
  return (
    <div className="modal-scrim" onClick={(e) => { if (e.target === e.currentTarget) onClose(); }}>
      <div
        className="modal"
        role="dialog"
        aria-modal="true"
        aria-labelledby="privacy-title"
        ref={modalRef}
      >
        <div className="modal-head">
          <h3 id="privacy-title">fsacredit.com · Privacy</h3>
          <button className="modal-close" onClick={onClose} aria-label="Close">×</button>
        </div>
        <div className="modal-body">
          <p className="lede-quote">
            <strong>The short version:</strong> we don't want your data, we don't ask for an account, and your filing status, household income, kids' ages, and childcare expenses never leave your browser. Use this page like you would a paper worksheet.
          </p>

          <h4>What we don't collect</h4>
          <ul>
            <li>No account, no email, no name, no phone number.</li>
            <li>Your filing status, AGI, kids' ages, and childcare expenses are <strong>processed entirely in your browser</strong>. They are never transmitted to our servers.</li>
            <li>We don't sell, share, or rent any user data — we don't have any to sell.</li>
          </ul>

          <h4>What we do collect</h4>
          <ul>
            <li><strong>Anonymous usage analytics</strong> — page views, browser type, country (from IP, not stored). Aggregated only; not tied to any individual.</li>
          </ul>

          <h4>Advertising</h4>
          <p>
            This site is free because it's supported by display advertising. Our advertising partners may set their own cookies on your device to serve relevant ads and measure performance. <strong>We do not share any of your household income, filing status, kids' ages, or childcare expenses with those partners.</strong> We explicitly do not share any household financial information you enter — including anything you log on this site — with any advertising or analytics partner.
          </p>
          <p>
            You can opt out of personalized advertising via aboutads.info or your browser's privacy controls. Visitors everywhere see a consent prompt on first visit; you can change your choice at any time:{' '}
            <button
              type="button"
              onClick={() => { try { window.CookieConsent && window.CookieConsent.showPreferences(); } catch (e) {} }}
              style={{ appearance: 'none', background: 'none', border: 0, padding: 0, color: 'var(--primary)', cursor: 'pointer', textDecoration: 'underline', textUnderlineOffset: '2px', font: 'inherit' }}
            >Manage cookie preferences</button>.
          </p>

          <h4>Deleting your data</h4>
          <p>Because we don't store anything server-side, the only place your data exists is on your device. To delete it, clear your browser's site data for fsacredit.com.</p>

          <h4>California residents</h4>
          <p>California residents have the right to opt out of the "sale" of personal information. Under CCPA's broad definition, our use of behavioral advertising cookies may qualify. To opt out, use the cookie consent controls or enable the Global Privacy Control signal in your browser — we honor GPC.</p>

          <h4>Children</h4>
          <p>This site is not directed to children under 13, and we do not knowingly collect any information from children. If you believe a child has provided us with information, contact us at the address below and we will delete it.</p>

          <h4>Third-party links</h4>
          <p>Links to the IRS, the U.S. Treasury, and sibling Red Goggles calculator sites lead to their own websites; we don't control or speak for their privacy practices.</p>

          <h4>Contact</h4>
          <p>For privacy questions, email <strong>privacy@fsacredit.com</strong>.</p>

          <p className="muted" style={{ fontSize: 12 }}>Last updated: May 24, 2026</p>
        </div>
        <div className="modal-foot">
          <button onClick={onClose}>Close</button>
        </div>
      </div>
    </div>
  );
}

window.SiteFooter = SiteFooter;
window.PrivacyModal = PrivacyModal;
