// EzClaim — informational pages: Help/FAQ, Privacy, Terms, Refund.

function PageShell({ title, subtitle, updated, children }) {
  return (
    <div className="fade-in" style={{ display: "flex", flexDirection: "column", gap: 18 }}>
      <div>
        <div className="eyebrow">EzClaim</div>
        <h2 className="h-page" style={{ marginTop: 6 }}>{title}</h2>
        {subtitle ? <p className="subtle" style={{ marginTop: 6, fontSize: 15 }}>{subtitle}</p> : null}
        {updated ? <p className="muted" style={{ fontSize: 12, marginTop: 8 }}>Last updated {updated}</p> : null}
      </div>
      {children}
    </div>
  );
}

function Section({ title, children }) {
  return (
    <div className="card lg">
      <h3 className="h-section" style={{ fontSize: 18, marginBottom: 10 }}>{title}</h3>
      <div style={{ display: "flex", flexDirection: "column", gap: 10, color: "var(--ink-700)", lineHeight: 1.6, fontSize: 14.5 }}>
        {children}
      </div>
    </div>
  );
}

function TOC({ items }) {
  return (
    <nav className="card" style={{ padding: 14 }}>
      <div className="eyebrow" style={{ marginBottom: 8 }}>On this page</div>
      <ol style={{ margin: 0, padding: "0 0 0 18px", display: "flex", flexDirection: "column", gap: 4, fontSize: 14 }}>
        {items.map((it) => (
          <li key={it.id}><a href={"#" + it.id} onClick={(e) => { e.preventDefault(); document.getElementById(it.id)?.scrollIntoView({ block: "start", behavior: "smooth" }); }}>{it.t}</a></li>
        ))}
      </ol>
    </nav>
  );
}

// ─────────────────────────────────────────────────────────────────────────────
// FAQ / Help
// ─────────────────────────────────────────────────────────────────────────────
const FAQ = [
  {
    q: "What is the Homestead Tax Credit?",
    a: "Maryland's Homestead Tax Credit caps how much your taxable property assessment can rise each year for your primary residence. The cap is 10% statewide; individual counties and Baltimore City set lower caps. Without the credit on file, your assessed value can rise without that protection — and your bill rises with it.",
  },
  {
    q: "Why do I have to file at all? Isn't it automatic?",
    a: "It isn't. Maryland requires a one-time application for each primary residence. Even if you owned a home with the credit on file, moving to a new home means re-applying. New owners and recent re-assessments are the most common reasons people miss the cap.",
  },
  {
    q: "What does the $19.99 actually buy me?",
    a: <>It pays for preparation, submission, and tracking — we collect your information in plain English, generate the SDAT Homestead application packet, fax it to SDAT from a secure fax service, confirm delivery, and email you a magic link to track status. <strong>The form itself is free.</strong> You can file directly with SDAT at sdathtc.dat.maryland.gov; we don't charge for access to anything you couldn't reach yourself.</>,
  },
  {
    q: "Why fax instead of online submission?",
    a: "SDAT accepts Homestead applications by mail, fax, and through their online portal. The online portal requires a one-time access number that SDAT mails to property owners — many people don't have it. Fax is the most reliable channel for assisted filings because we can confirm delivery in seconds.",
  },
  {
    q: "How long does SDAT take to approve?",
    a: "Typically 4–8 weeks for the public record to update after delivery. SDAT's public-facing status can lag the actual processing by several weeks; we re-check daily and update your status page automatically.",
  },
  {
    q: "Can you guarantee approval?",
    a: "No. Approval is determined by SDAT based on whether you meet Maryland's residency and eligibility rules. We will prepare and submit a complete, accurate application — but the determination is theirs, not ours.",
  },
  {
    q: "What if SDAT denies the application?",
    a: "We'll prepare and re-file a corrected application at no additional charge, provided the denial is correctable (typo, missing detail, mismatched deed). If the denial is because you don't meet residency or ownership rules, we'll refund the $19.99 in full.",
  },
  {
    q: "What happens to my SSN?",
    a: "We collect SSNs only after payment, only on a secure form, and only long enough to render the SDAT packet, fax it, and confirm delivery. Your SSN is stored encrypted in volatile memory — it is never written to our database, never appears in our logs, and is purged from servers within minutes of fax delivery. The magic-link status page contains only non-sensitive metadata.",
  },
  {
    q: "Do I need to create an account?",
    a: "No. We use magic-link URLs instead of passwords. After you submit, we email you a unique status URL — opening that URL is how you check progress. There's nothing to remember, nothing to lose.",
  },
  {
    q: "What if I file with EzClaim and then realize I already had the credit?",
    a: "We check your status against SDAT's public record before charging. If you're already approved, we'll show that and won't proceed to payment. If a duplicate filing slips through anyway, SDAT will simply ignore it and we'll refund the $19.99.",
  },
  {
    q: "I lost my status link. How do I get it back?",
    a: <>Email us at <a href="mailto:help@ezclaim.app">help@ezclaim.app</a> from the address you used to file and we'll re-send. The link is tied to your email, your filing ID, and the original property — we don't use it as a credential by itself.</>,
  },
  {
    q: "Is EzClaim affiliated with the State of Maryland?",
    a: "No. EzClaim is a private service. The Homestead Tax Credit is a Maryland program administered by the State Department of Assessments & Taxation. You can always file free directly with SDAT.",
  },
];

function FaqScreen({ nav }) {
  const [open, setOpen] = useState(0);
  return (
    <PageShell
      title="Help & frequently asked questions"
      subtitle="Plain answers to the things people actually ask before paying $19.99."
    >
      <div className="card" style={{ padding: 0, overflow: "hidden" }}>
        {FAQ.map((item, i) => (
          <div key={i} style={{ borderBottom: i === FAQ.length - 1 ? "0" : "1px solid var(--line)" }}>
            <button
              onClick={() => setOpen(open === i ? -1 : i)}
              aria-expanded={open === i}
              style={{
                width: "100%", textAlign: "left", padding: "16px 18px",
                background: "transparent", border: "0", cursor: "pointer",
                display: "flex", gap: 14, alignItems: "center",
                font: "inherit", color: "var(--ink-900)",
              }}>
              <span style={{ flex: 1, fontWeight: 600, fontSize: 15, lineHeight: 1.35 }}>{item.q}</span>
              <span style={{
                color: "var(--ink-500)",
                transition: "transform .15s",
                transform: open === i ? "rotate(180deg)" : "none",
                display: "inline-flex",
              }}><I.ChevronDown size={18}/></span>
            </button>
            {open === i ? (
              <div style={{ padding: "0 18px 18px", color: "var(--ink-700)", lineHeight: 1.6, fontSize: 14.5 }}>
                {item.a}
              </div>
            ) : null}
          </div>
        ))}
      </div>

      <Callout kind="info" icon={<I.Mail size={18}/>}>
        Didn't find what you needed? Email <a href="mailto:help@ezclaim.app">help@ezclaim.app</a>. We aim to respond within one business day.
      </Callout>

      <div className="card">
        <h3 className="h-section">Maryland resources</h3>
        <ul style={{ margin: "4px 0 0", paddingLeft: 18, color: "var(--ink-700)", lineHeight: 1.7, fontSize: 14 }}>
          <li><a href="https://sdat.dat.maryland.gov" target="_blank" rel="noreferrer">SDAT — State Department of Assessments & Taxation</a></li>
          <li><a href="https://sdathtc.dat.maryland.gov" target="_blank" rel="noreferrer">SDAT Homestead online application portal</a></li>
          <li><a href="https://dat.maryland.gov/realproperty" target="_blank" rel="noreferrer">Real Property search — find your parcel and assessment</a></li>
        </ul>
      </div>
    </PageShell>
  );
}

// ─────────────────────────────────────────────────────────────────────────────
// Privacy
// ─────────────────────────────────────────────────────────────────────────────
function PrivacyScreen() {
  const toc = [
    { id: "what-we-collect", t: "What we collect" },
    { id: "what-we-dont",    t: "What we don't collect" },
    { id: "sensitive",       t: "How we handle SSNs, signatures, and the filing PDF" },
    { id: "retention",       t: "Retention" },
    { id: "third-parties",   t: "Third-party services" },
    { id: "your-rights",     t: "Your rights" },
    { id: "contact",         t: "Contact" },
  ];
  return (
    <PageShell title="Privacy & data handling" subtitle="A short, plain-English description of what we collect, what we don't, and what happens to the sensitive parts." updated="May 13, 2026">
      <TOC items={toc}/>

      <div id="what-we-collect">
        <Section title="What we collect">
          <p>To prepare a Homestead Tax Credit application on your behalf, we collect:</p>
          <ul style={{ margin: "0 0 0 18px", padding: 0, display: "flex", flexDirection: "column", gap: 6 }}>
            <li>The property address you look up, and the matching parcel record from SDAT's public index.</li>
            <li>Your name, email, and (optionally) phone number.</li>
            <li>Move-in date, primary-residence answers, and information about any co-owners on the deed.</li>
            <li>Payment metadata from Stripe (receipt ID, last 4, ZIP). We never see your full card number.</li>
            <li><strong>After payment only:</strong> the Social Security Numbers required by the SDAT form, and a digital signature.</li>
          </ul>
        </Section>
      </div>

      <div id="what-we-dont">
        <Section title="What we don't collect">
          <ul style={{ margin: "0 0 0 18px", padding: 0, display: "flex", flexDirection: "column", gap: 6 }}>
            <li>We don't collect your credit card number — Stripe Checkout handles it.</li>
            <li>We don't ask for income, employment, bank statements, or tax returns.</li>
            <li>We don't track you with third-party advertising cookies.</li>
            <li>We don't sell, rent, or share your information for marketing.</li>
          </ul>
        </Section>
      </div>

      <div id="sensitive">
        <Section title="How we handle SSNs, signatures, and the filing PDF">
          <p>The SDAT form requires SSNs for each owner. We collect them as the very last step, only after payment, and the data path looks like this:</p>
          <ol style={{ margin: "0 0 0 18px", padding: 0, display: "flex", flexDirection: "column", gap: 6 }}>
            <li>You enter your SSN on a TLS-encrypted form. The value posts directly to a memory-only worker.</li>
            <li>The worker renders the SDAT PDF in volatile memory and faxes it via a HIPAA-grade fax provider.</li>
            <li>On successful delivery, the worker zeroes the SSN, signature, and PDF from memory and writes only a non-sensitive event record ("fax delivered, 6 pages, session 88a3").</li>
            <li>No SSN, signature, or completed PDF is ever written to our database, our logs, or any backup.</li>
          </ol>
          <p><strong>The magic-link status page</strong> contains only the filing ID, the timeline, and the receipt. It is safe to share with anyone who already knows you're filing.</p>
        </Section>
      </div>

      <div id="retention">
        <Section title="Retention">
          <ul style={{ margin: "0 0 0 18px", padding: 0, display: "flex", flexDirection: "column", gap: 6 }}>
            <li><strong>Sensitive data</strong> (SSN, signature, completed PDF) — purged within minutes of fax delivery, never persisted.</li>
            <li><strong>Filing record</strong> (parcel, name, email, status timeline) — retained 24 months, then deleted. You can request deletion at any time.</li>
            <li><strong>Payment records</strong> — retained 7 years to comply with U.S. tax/accounting rules.</li>
            <li><strong>Server logs</strong> — retained 30 days, contain IP and request path only.</li>
          </ul>
        </Section>
      </div>

      <div id="third-parties">
        <Section title="Third-party services">
          <ul style={{ margin: "0 0 0 18px", padding: 0, display: "flex", flexDirection: "column", gap: 6 }}>
            <li><strong>Stripe</strong> — payment processing. Stripe's privacy policy applies to card data.</li>
            <li><strong>Phaxio</strong> (or equivalent HIPAA-grade fax provider) — fax delivery to SDAT. Sees the PDF in transit; deletes within 7 days per their retention policy.</li>
            <li><strong>Cloudflare</strong> — hosting and DDoS protection.</li>
            <li><strong>SDAT</strong> — the State Department of Assessments & Taxation, the actual government recipient. Their handling is governed by Maryland public-records law.</li>
          </ul>
        </Section>
      </div>

      <div id="your-rights">
        <Section title="Your rights">
          <p>You can request a copy of, or deletion of, any data we hold about you by emailing <a href="mailto:privacy@ezclaim.app">privacy@ezclaim.app</a>. We'll respond within 30 days. Maryland residents have additional rights under the Maryland Online Consumer Protection Act.</p>
        </Section>
      </div>

      <div id="contact">
        <Section title="Contact">
          <p>EzClaim, Inc. · privacy@ezclaim.app · 1000 Lancaster St, Suite 201, Baltimore, MD 21202.</p>
        </Section>
      </div>
    </PageShell>
  );
}

// ─────────────────────────────────────────────────────────────────────────────
// Terms
// ─────────────────────────────────────────────────────────────────────────────
function TermsScreen() {
  const toc = [
    { id: "service",     t: "What EzClaim is" },
    { id: "not-gov",     t: "Not a government agency" },
    { id: "your-info",   t: "Information you provide" },
    { id: "fee",         t: "The $19.99 fee" },
    { id: "no-guarantee",t: "No guarantee of approval" },
    { id: "permitted",   t: "Permitted use" },
    { id: "liability",   t: "Limitation of liability" },
    { id: "law",         t: "Governing law" },
  ];
  return (
    <PageShell title="Terms of service" subtitle="The plain-English version. The full legal text mirrors what's here." updated="May 13, 2026">
      <TOC items={toc}/>

      <div id="service">
        <Section title="What EzClaim is">
          <p>EzClaim is a private service that helps Maryland homeowners prepare and submit the Maryland Homestead Tax Credit application to the State Department of Assessments &amp; Taxation (SDAT). We collect your information through a guided form, render the official SDAT application as a PDF, fax it to SDAT, and provide you a magic-link status page that tracks delivery and SDAT acknowledgement.</p>
        </Section>
      </div>

      <div id="not-gov">
        <Section title="Not a government agency">
          <p>EzClaim is not affiliated with SDAT, the State of Maryland, or any other government entity. The Homestead Tax Credit application is free, and you can file it directly with SDAT at <a href="https://sdathtc.dat.maryland.gov" target="_blank" rel="noreferrer">sdathtc.dat.maryland.gov</a> at no cost. Our $19.99 fee is for preparation, submission, and tracking — not for access to the application itself.</p>
        </Section>
      </div>

      <div id="your-info">
        <Section title="Information you provide">
          <p>You agree that the information you provide is accurate to the best of your knowledge. SDAT may reject or revoke a Homestead Credit based on incorrect information. EzClaim has no obligation or ability to verify the truthfulness of statements you make to us.</p>
        </Section>
      </div>

      <div id="fee">
        <Section title="The $19.99 fee">
          <p>The fee is charged at the time of submission via Stripe Checkout. It is a one-time fee per filing — there is no subscription. If you start a filing and don't complete it, you are not charged.</p>
          <p>See our <a href="#/refund">Refund policy</a> for refund conditions.</p>
        </Section>
      </div>

      <div id="no-guarantee">
        <Section title="No guarantee of approval">
          <p>Estimates of "avoidable annual property-tax increases" are computed from public assessment data and your county's most recent rate. They are estimates, not guarantees. SDAT determines eligibility based on Maryland law and the facts you certify on the application. EzClaim makes no representation or warranty that your application will be approved or that any specific savings will result.</p>
        </Section>
      </div>

      <div id="permitted">
        <Section title="Permitted use">
          <p>You may use EzClaim only to file your own application or one for which you have legal authority to act (e.g., as a joint owner). You may not submit information about a person without their knowledge, file an application as a non-owner, or use the service to harass, defraud, or impersonate.</p>
        </Section>
      </div>

      <div id="liability">
        <Section title="Limitation of liability">
          <p>To the maximum extent permitted by Maryland law, EzClaim's total liability for any claim arising from your use of the service is limited to the $19.99 fee actually paid. EzClaim is not liable for SDAT processing times, lost mail/fax on SDAT's end, or county-level tax rate changes that affect your actual savings.</p>
        </Section>
      </div>

      <div id="law">
        <Section title="Governing law">
          <p>These terms are governed by the laws of the State of Maryland. Any dispute is venue in the state or federal courts located in Baltimore City, Maryland.</p>
          <p style={{ color: "var(--ink-500)", fontSize: 13, marginTop: 6 }}>EzClaim, Inc. · 1000 Lancaster St, Suite 201, Baltimore, MD 21202 · legal@ezclaim.app</p>
        </Section>
      </div>
    </PageShell>
  );
}

// ─────────────────────────────────────────────────────────────────────────────
// Refund
// ─────────────────────────────────────────────────────────────────────────────
function RefundScreen() {
  return (
    <PageShell title="Refund policy" subtitle="When we refund, when we don't, and how to ask." updated="May 13, 2026">
      <div className="card lg">
        <h3 className="h-section" style={{ fontSize: 18 }}>We refund the full $19.99 if:</h3>
        <ul style={{ margin: "8px 0 0 18px", padding: 0, display: "flex", flexDirection: "column", gap: 8, color: "var(--ink-700)", fontSize: 14.5, lineHeight: 1.6 }}>
          <li><strong>Our fax to SDAT fails permanently.</strong> We retry every 30 minutes for 24 hours. If we still can't get through, we refund and notify you so you can file by mail or via SDAT's portal.</li>
          <li><strong>SDAT rejects your application for a reason we can't correct.</strong> If the rejection is because you don't qualify (e.g., not a primary residence), we refund. If it's a correctable issue (typo, missing detail), we re-file at no additional charge first, then refund only if that re-filing also fails.</li>
          <li><strong>You discover you already had the Homestead Credit on file.</strong> If our pre-submission check missed it and the duplicate filing has no effect, we refund.</li>
          <li><strong>You change your mind before we fax.</strong> If you reach us within 1 hour of payment and we haven't yet submitted, we refund. After fax submission we can't recall the application from SDAT.</li>
        </ul>
      </div>

      <div className="card">
        <h3 className="h-section">We don't refund for:</h3>
        <ul style={{ margin: "8px 0 0 18px", padding: 0, display: "flex", flexDirection: "column", gap: 6, color: "var(--ink-700)", fontSize: 14, lineHeight: 1.6 }}>
          <li>SDAT processing time. Reviews typically take 4–8 weeks; this is normal and not a service failure.</li>
          <li>Smaller-than-estimated savings. Estimates are based on public data and county rates and can shift between bills.</li>
          <li>Decisions you make on your application that prove incorrect after the fact.</li>
        </ul>
      </div>

      <Callout kind="info" icon={<I.Mail size={18}/>}>
        To request a refund, email <a href="mailto:help@ezclaim.app">help@ezclaim.app</a> with your filing ID. Refunds post to the original card within 5–10 business days.
      </Callout>
    </PageShell>
  );
}

Object.assign(window, { FaqScreen, PrivacyScreen, TermsScreen, RefundScreen });
