/* Stanley Bankruptcy Law — Chapter 7 and Chapter 13 practice pages */

const CH = window.StanleyBankruptcyLawDesignSystem_1e6713;

function ChapterHero({ eyebrow, title, gold, standfirst, badges, navigate, otherKey, otherLabel }) {
  const { Button, Badge } = CH;
  return (
    <div style={{ background:'var(--brand)', position:'relative', overflow:'hidden' }}>
      <div style={{ position:'absolute', inset:0, background:'radial-gradient(110% 100% at 88% 0%, rgba(200,151,47,0.14) 0%, transparent 55%)' }}></div>
      <div style={{ position:'relative', maxWidth:'var(--container-narrow)', margin:'0 auto', padding:'70px 24px 64px' }} className="page-head-inner">
        <Eyebrow onBrand>{eyebrow}</Eyebrow>
        <h1 className="page-head-h1" style={{ color:'#F7F5EE', fontSize:'44px', lineHeight:1.08, margin:'0 0 16px', letterSpacing:'-0.022em' }}>{title} <span style={{ color:'var(--gold-300)' }}>{gold}</span></h1>
        <p style={{ color:'#D7E3DA', fontSize:'18px', lineHeight:1.62, maxWidth:'58ch', margin:'0 0 22px' }}>{standfirst}</p>
        <div style={{ display:'flex', gap:'8px', marginBottom:'26px', flexWrap:'wrap' }}>
          {badges.map((b)=> <Badge key={b} variant="accent">{b}</Badge>)}
        </div>
        <div style={{ display:'flex', gap:'14px', flexWrap:'wrap' }}>
          <Button variant="accent" size="lg" onClick={()=>navigate('contact')} iconLeft={<Icon name="calendar-check" size={18} />}>Schedule a free consult</Button>
          <Button variant="outline" size="lg" onClick={()=>navigate(otherKey)} style={{ color:'#F4F2EA', borderColor:'rgba(244,242,234,0.4)' }} iconRight={<Icon name="arrow-right" size={17} />}>{otherLabel}</Button>
        </div>
      </div>
    </div>);
}

function CheckList({ items }) {
  return (
    <ul style={{ listStyle:'none', padding:0, margin:0, display:'flex', flexDirection:'column', gap:'11px' }}>
      {items.map((pt)=>(
        <li key={pt} style={{ display:'flex', alignItems:'flex-start', gap:'10px', fontSize:'16px', color:'var(--ink-700)', lineHeight:1.55 }}>
          <span style={{ color:'var(--success)', flexShrink:0, marginTop:'2px' }}><Icon name="check" size={18} strokeWidth={2.4} /></span>{pt}
        </li>
      ))}
    </ul>);
}

function XList({ items }) {
  return (
    <ul style={{ listStyle:'none', padding:0, margin:0, display:'flex', flexDirection:'column', gap:'11px' }}>
      {items.map((pt)=>(
        <li key={pt} style={{ display:'flex', alignItems:'flex-start', gap:'10px', fontSize:'16px', color:'var(--ink-700)', lineHeight:1.55 }}>
          <span style={{ color:'var(--danger)', flexShrink:0, marginTop:'2px' }}><Icon name="x" size={18} strokeWidth={2.4} /></span>{pt}
        </li>
      ))}
    </ul>);
}

function ChapterFaq({ faqs, city }) {
  const [open, setOpen] = React.useState(null);
  return (
    <div style={{ display:'flex', flexDirection:'column', gap:'12px' }}>
      {faqs.map((f,i)=>(
        <div key={i} style={{ background:'var(--paper)', border:'1px solid var(--border)', borderRadius:'var(--radius-md)', boxShadow: open===i?'var(--shadow-md)':'var(--shadow-sm)', overflow:'hidden', transition:'box-shadow var(--dur) var(--ease-out)' }}>
          <button onClick={()=>setOpen(open===i?null:i)} style={{ width:'100%', display:'flex', alignItems:'center', justifyContent:'space-between', gap:'16px', padding:'18px 22px', background:'transparent', border:'none', cursor:'pointer', textAlign:'left', fontFamily:'var(--font-display)', fontSize:'17.5px', fontWeight:600, color:'var(--text-strong)' }}>
            {f.q}
            <span style={{ flexShrink:0, color:'var(--accent-strong)', transform: open===i?'rotate(180deg)':'none', transition:'transform var(--dur) var(--ease-out)' }}><Icon name="chevron-down" size={21} /></span>
          </button>
          <div style={{ maxHeight: open===i?'340px':'0', transition:'max-height var(--dur-slow) var(--ease-out)', overflow:'hidden' }}>
            <p style={{ padding:'0 22px 20px', margin:0, fontSize:'15.5px', lineHeight:1.65, color:'var(--ink-700)' }}>{f.a}</p>
          </div>
        </div>
      ))}
    </div>);
}

function ChapterSteps({ steps }) {
  const { Card } = CH;
  return (
    <div className="resp-grid-2col" style={{ gridTemplateColumns:'repeat(4,1fr)' }}>
      {steps.map((s,i)=>(
        <Card key={s.t} padding="md">
          <div style={{ width:'38px', height:'38px', borderRadius:'999px', background:'var(--brand)', color:'var(--gold-300)', display:'flex', alignItems:'center', justifyContent:'center', fontFamily:'var(--font-display)', fontWeight:700, fontSize:'16px', marginBottom:'14px' }}>{i+1}</div>
          <Icon name={s.icon} size={22} color="var(--accent-strong)" />
          <div style={{ fontFamily:'var(--font-display)', fontWeight:600, fontSize:'17px', margin:'10px 0 7px', color:'var(--text-strong)', lineHeight:1.2 }}>{s.t}</div>
          <p style={{ fontSize:'14px', lineHeight:1.58, color:'var(--ink-700)', margin:0 }}>{s.body}</p>
        </Card>
      ))}
    </div>);
}

function ChapterCrossLinks({ navigate, links }) {
  return (
    <div style={{ display:'flex', flexWrap:'wrap', gap:'10px', alignItems:'center', justifyContent:'center', fontFamily:'var(--font-sans)', fontSize:'14.5px', marginTop:'8px' }}>
      <span style={{ color:'var(--text-muted)' }}>Keep reading:</span>
      {links.map((l,i)=>(
        <React.Fragment key={l.key}>
          {i>0 && <span style={{ color:'var(--border-strong)' }}>·</span>}
          <a href={window.hrefFor ? window.hrefFor(l.key) : '#'} onClick={(e)=>{e.preventDefault();navigate(l.key);}} style={{ color:'var(--brand)', fontWeight:600, textDecoration:'none' }}>{l.label}</a>
        </React.Fragment>
      ))}
    </div>);
}

/* ===================== CHAPTER 7 ===================== */
function ChapterSevenPage({ navigate }) {
  const { Button, Card, Callout, Stat } = CH;
  const steps = [
    { icon:'calendar-check', t:'Free consultation', body:'A no-obligation call to look at your income, debts, and goals, and confirm Chapter 7 is the right fit.' },
    { icon:'file-text', t:'We prepare and file', body:'We handle the petition, schedules, and means test paperwork. You can begin with $0 down.' },
    { icon:'shield-check', t:'The stay protects you', body:'The moment we file, the automatic stay stops collection calls, garnishments, and repossessions.' },
    { icon:'sunrise', t:'Discharge in months', body:'Most Chapter 7 cases end in a discharge a few months after filing. Your fresh start begins.' },
  ];
  const faqs = [
    { q:'How much does it cost to file Chapter 7?', a:'You can begin your Chapter 7 with $0 down. We walk you through the court filing fee and our straightforward fee structure during your free consultation, so there are no surprises.' },
    { q:'Will I lose my house or my car?', a:'In most cases, no. Exemptions are designed to let people keep essential property, and most Chapter 7 filers keep their home, vehicle, and personal belongings. If you are behind on a mortgage or car loan you want to keep, Chapter 13 may be the better fit.' },
    { q:'Do I qualify for Chapter 7?', a:'Qualification turns on the means test, which compares your household income to the Kentucky median for your family size. A recent drop in income, a layoff, or reduced hours can make Chapter 7 more accessible than you expect. We run the numbers together, free.' },
    { q:'How long does Chapter 7 take?', a:'Most cases move from filing to discharge in about three to five months. The required meeting of creditors is commonly held by video, so most clients never set foot in a courtroom.' },
    { q:'Will Chapter 7 ruin my credit forever?', a:'No. For many people already behind on payments, credit is already suffering. A discharge stops the damage and gives you a clean slate. Many clients begin re-establishing healthy credit within a year.' },
  ];
  return (
    <main>
      <ChapterHero eyebrow="Chapter 7 Bankruptcy" title="A fresh start, often in a matter of" gold="months"
        standfirst="Chapter 7 wipes out most unsecured debt, credit cards, medical bills, personal loans, and stops collection calls, garnishments, and repossessions the day you file. It is the fastest path the law offers to a clean slate, and you can begin for $0 down."
        badges={['$0 down to file', 'Free consultation', 'Most cases done in months']}
        navigate={navigate} otherKey="chapter-13" otherLabel="Compare with Chapter 13" />

      <Section bg="paper" pad="md">
        <div className="resp-grid-2col" style={{ gap:'40px', alignItems:'start' }}>
          <div>
            <Eyebrow>What it erases</Eyebrow>
            <h2 style={{ fontSize:'30px', margin:'0 0 14px' }}>Debts a Chapter 7 discharge wipes out</h2>
            <p style={{ fontSize:'16.5px', lineHeight:1.66, color:'var(--ink-700)', margin:'0 0 18px' }}>A discharge under 11 U.S.C. § 727 erases the great majority of ordinary consumer debt, permanently. Creditors can never lawfully collect a discharged debt again.</p>
            <CheckList items={['Credit card balances', 'Medical bills and hospital debt', 'Personal loans and payday loans', 'Old utility, phone, and rent balances', 'Repossession deficiencies and most judgments']} />
          </div>
          <div>
            <Eyebrow>What survives</Eyebrow>
            <h2 style={{ fontSize:'30px', margin:'0 0 14px' }}>Debts the law does not discharge</h2>
            <p style={{ fontSize:'16.5px', lineHeight:1.66, color:'var(--ink-700)', margin:'0 0 18px' }}>The Bankruptcy Code draws careful lines in 11 U.S.C. § 523. Being honest about them is part of giving you real counsel.</p>
            <XList items={['Child support and alimony', 'Most student loans', 'Recent income taxes', 'Court fines and criminal restitution', 'Debts from fraud, if a court finds it']} />
            <div style={{ marginTop:'18px' }}>
              <Button variant="outline" onClick={()=>navigate('article-discharge')} iconRight={<Icon name="arrow-right" size={15} />}>Read the full statute-by-statute guide</Button>
            </div>
          </div>
        </div>
      </Section>

      <Section bg="surface" pad="md">
        <div className="resp-grid-2col" style={{ gap:'40px', alignItems:'center' }}>
          <div>
            <Eyebrow>Who it fits</Eyebrow>
            <h2 style={{ fontSize:'30px', margin:'0 0 14px' }}>Chapter 7 is typically best for people who…</h2>
            <CheckList items={['Carry mostly unsecured debt, credit cards, medical bills, personal loans', 'Have household income at or below the Kentucky median for their family size, or income that has recently dropped', 'Are current on any home or car they want to keep, or do not need time to catch up', 'Want the fastest, cleanest fresh start the law offers']} />
            <p style={{ fontSize:'16px', lineHeight:1.65, color:'var(--ink-700)', margin:'18px 0 0' }}>Behind on a mortgage or car loan you want to keep? That is exactly what <a href={window.hrefFor?window.hrefFor('chapter-13'):'#'} onClick={(e)=>{e.preventDefault();navigate('chapter-13');}} style={{ color:'var(--brand)', fontWeight:600 }}>Chapter 13</a> is built for.</p>
          </div>
          <Card padding="lg" accentTop>
            <div style={{ fontFamily:'var(--font-sans)', fontWeight:700, fontSize:'14px', letterSpacing:'0.06em', textTransform:'uppercase', color:'var(--accent-strong)', marginBottom:'14px' }}>The means test, plainly</div>
            <p style={{ fontSize:'15.5px', lineHeight:1.65, color:'var(--ink-700)', margin:'0 0 14px' }}>The means test compares your household income over the last six months to Kentucky's median income for your family size. Below the median, you generally qualify. Above it, deductions for real expenses often still get you there, or Chapter 13 steps in.</p>
            <p style={{ fontSize:'15.5px', lineHeight:1.65, color:'var(--ink-700)', margin:'0 0 18px' }}>Seasonal work, self-employment, or income that varies month to month? We take the time to calculate it correctly rather than relying on a single pay stub.</p>
            <div style={{ display:'flex', gap:'28px' }}>
              <Stat value="$0" label="Down to file" sublabel="Chapter 7 bankruptcy" />
              <Stat value="3–5" label="Months" sublabel="Typical filing to discharge" />
            </div>
          </Card>
        </div>
      </Section>

      <Section bg="paper" pad="md">
        <div style={{ textAlign:'center', marginBottom:'32px' }}>
          <Eyebrow>Simple process</Eyebrow>
          <h2 style={{ fontSize:'30px', margin:'0 0 10px' }}>How your Chapter 7 case moves</h2>
          <p style={{ fontSize:'16.5px', color:'var(--ink-700)', maxWidth:'54ch', margin:'0 auto' }}>Four steps, most of them handled by our office. The meeting of creditors is commonly held by video, so most clients never leave home.</p>
        </div>
        <ChapterSteps steps={steps} />
        <div style={{ maxWidth:'var(--container-narrow)', margin:'28px auto 0' }}>
          <Callout variant="accent" title="Your property is protected by exemptions" icon={<Icon name="shield-check" size={18} />}>
            Federal exemptions protect your home equity, vehicle, household goods, and retirement accounts in the overwhelming majority of cases. <a href={window.hrefFor?window.hrefFor('article-exemptions'):'#'} onClick={(e)=>{e.preventDefault();navigate('article-exemptions');}} style={{ color:'var(--brand)', fontWeight:600 }}>How exemptions work →</a>
          </Callout>
        </div>
      </Section>

      <Section bg="surface" narrow pad="md">
        <div style={{ textAlign:'center', marginBottom:'28px' }}>
          <Eyebrow>Common questions</Eyebrow>
          <h2 style={{ fontSize:'30px', margin:0 }}>Chapter 7 questions, answered honestly</h2>
        </div>
        <ChapterFaq faqs={faqs} />
        <ChapterCrossLinks navigate={navigate} links={[
          { key:'chapter-13', label:'Chapter 13 bankruptcy' },
          { key:'types', label:'Chapter 7 vs Chapter 13' },
          { key:'article-garnishment', label:'Stopping a wage garnishment' },
          { key:'faq', label:'Debts FAQ' },
        ]} />
      </Section>

      <CtaBand navigate={navigate} />
    </main>);
}

/* ===================== CHAPTER 13 ===================== */
function ChapterThirteenPage({ navigate }) {
  const { Button, Card, Callout, Stat } = CH;
  const steps = [
    { icon:'calendar-check', t:'Free consultation', body:'We look at your income, your arrears, and what you want to protect, then size a plan that actually fits your budget.' },
    { icon:'file-text', t:'We file your plan', body:'Your petition and repayment plan go to the court. The automatic stay stops foreclosure and repossession immediately.' },
    { icon:'hand-coins', t:'One monthly payment', body:'For three to five years you make a single payment to the trustee, sized to your real income, not your creditors\u2019 demands.' },
    { icon:'sunrise', t:'Discharge at the end', body:'Complete the plan and remaining unsecured balances are discharged. Your home and car are yours, caught up.' },
  ];
  const faqs = [
    { q:'Can Chapter 13 really stop a foreclosure?', a:'Yes. The automatic stay halts a foreclosure sale the moment your case is filed, and the plan lets you cure the missed payments over three to five years while you stay in the home and keep making the regular mortgage payment.' },
    { q:'How is my monthly payment calculated?', a:'The plan payment is built from your actual budget: what is left after reasonable living expenses. It covers your arrears, certain priority debts, and a portion of unsecured debt, which is often pennies on the dollar.' },
    { q:'What if my car was already repossessed?', a:'Move quickly. If the vehicle has not yet been sold, filing Chapter 13 can often get it back, and the loan is then caught up through the plan.' },
    { q:'Do I qualify for Chapter 13?', a:'You need regular income, from a job, self-employment, benefits, or a combination, and your debts must fall under the statutory limits, which they do for nearly all consumer cases. Steady income that the means test puts above the Chapter 7 line is a classic Chapter 13 fit.' },
    { q:'What happens if my income changes during the plan?', a:'Plans can be modified. If you lose hours or hit a hardship mid-plan, we go back to the court and adjust. You are not locked into a payment that no longer fits reality.' },
  ];
  return (
    <main>
      <ChapterHero eyebrow="Chapter 13 Bankruptcy" title="Keep your home. Keep your car. Catch up on" gold="your terms"
        standfirst="Chapter 13 reorganizes what you owe into one affordable monthly payment over three to five years. It stops foreclosure and repossession the day you file, and it is specifically built to let you cure missed mortgage and car payments instead of losing what you have worked for."
        badges={['Stops foreclosure', 'One monthly payment', 'Free consultation']}
        navigate={navigate} otherKey="chapter-7" otherLabel="Compare with Chapter 7" />

      <Section bg="paper" pad="md">
        <div className="resp-grid-2col" style={{ gap:'40px', alignItems:'start' }}>
          <div>
            <Eyebrow>What it does</Eyebrow>
            <h2 style={{ fontSize:'30px', margin:'0 0 14px' }}>What a Chapter 13 plan can do</h2>
            <CheckList items={['Stop a foreclosure sale and cure missed mortgage payments over time', 'Stop repossession, and often recover a recently repossessed vehicle', 'Combine arrears, taxes, and other debts into one payment sized to your income', 'Protect co-signers on consumer debts while the plan runs', 'Discharge remaining unsecured balances when the plan completes']} />
          </div>
          <div>
            <Eyebrow>Who it fits</Eyebrow>
            <h2 style={{ fontSize:'30px', margin:'0 0 14px' }}>Chapter 13 is typically best for people who…</h2>
            <CheckList items={['Are behind on a mortgage or car loan they want to keep', 'Have steady income, from work, self-employment, or benefits', 'Earn above the Chapter 7 means-test line but still cannot keep up', 'Have property they want to protect beyond what exemptions cover']} />
            <p style={{ fontSize:'16px', lineHeight:1.65, color:'var(--ink-700)', margin:'18px 0 0' }}>Mostly unsecured debt and no arrears to cure? <a href={window.hrefFor?window.hrefFor('chapter-7'):'#'} onClick={(e)=>{e.preventDefault();navigate('chapter-7');}} style={{ color:'var(--brand)', fontWeight:600 }}>Chapter 7</a> may get you there faster.</p>
          </div>
        </div>
      </Section>

      <Section bg="surface" pad="md">
        <div className="resp-grid-2col" style={{ gap:'40px', alignItems:'center' }}>
          <Card padding="lg" accentTop>
            <div style={{ fontFamily:'var(--font-sans)', fontWeight:700, fontSize:'14px', letterSpacing:'0.06em', textTransform:'uppercase', color:'var(--accent-strong)', marginBottom:'14px' }}>The automatic stay</div>
            <p style={{ fontSize:'15.5px', lineHeight:1.65, color:'var(--ink-700)', margin:'0 0 14px' }}>The moment your case is filed, a federal law, 11 U.S.C. § 362, freezes most collection activity: the foreclosure sale, the repossession, the garnishment, the calls. It is not a request. Willful violations carry damages.</p>
            <p style={{ fontSize:'15.5px', lineHeight:1.65, color:'var(--ink-700)', margin:'0 0 18px' }}>If you have a sale date on the calendar, treat it as a countdown, the earlier you call, the more options stay on the table.</p>
            <div style={{ display:'flex', gap:'28px' }}>
              <Stat value="3–5" label="Years" sublabel="One plan, one payment" />
              <Stat value="Day 1" label="Protection" sublabel="Stay takes effect at filing" />
            </div>
          </Card>
          <div>
            <Eyebrow>How the plan works</Eyebrow>
            <h2 style={{ fontSize:'30px', margin:'0 0 14px' }}>One payment, sized to your real budget</h2>
            <p style={{ fontSize:'16.5px', lineHeight:1.66, color:'var(--ink-700)', margin:'0 0 14px' }}>Your plan payment is built from what your household actually earns and actually needs to live on. It goes to the Chapter 13 trustee, who distributes it: mortgage or car arrears first-class, certain taxes and priority debts, then unsecured creditors receive what the budget allows, often a small fraction.</p>
            <p style={{ fontSize:'16.5px', lineHeight:1.66, color:'var(--ink-700)', margin:0 }}>Dalton's years clerking at the U.S. Bankruptcy Court for the Eastern District of Kentucky mean your plan is drafted the way judges and trustees expect to see it, which is what gets plans confirmed.</p>
          </div>
        </div>
      </Section>

      <Section bg="paper" pad="md">
        <div style={{ textAlign:'center', marginBottom:'32px' }}>
          <Eyebrow>Simple process</Eyebrow>
          <h2 style={{ fontSize:'30px', margin:'0 0 10px' }}>How your Chapter 13 case moves</h2>
          <p style={{ fontSize:'16.5px', color:'var(--ink-700)', maxWidth:'54ch', margin:'0 auto' }}>Most of the process is handled electronically, and the meeting of creditors is commonly held by video.</p>
        </div>
        <ChapterSteps steps={steps} />
        <div style={{ maxWidth:'var(--container-narrow)', margin:'28px auto 0' }}>
          <Callout variant="accent" title="Facing a foreclosure sale date?" icon={<Icon name="home" size={18} />}>
            Filing before the sale is what stops it. <a href={window.hrefFor?window.hrefFor('article-foreclosure'):'#'} onClick={(e)=>{e.preventDefault();navigate('article-foreclosure');}} style={{ color:'var(--brand)', fontWeight:600 }}>How the stay halts a Kentucky foreclosure →</a>
          </Callout>
        </div>
      </Section>

      <Section bg="surface" narrow pad="md">
        <div style={{ textAlign:'center', marginBottom:'28px' }}>
          <Eyebrow>Common questions</Eyebrow>
          <h2 style={{ fontSize:'30px', margin:0 }}>Chapter 13 questions, answered honestly</h2>
        </div>
        <ChapterFaq faqs={faqs} />
        <ChapterCrossLinks navigate={navigate} links={[
          { key:'chapter-7', label:'Chapter 7 bankruptcy' },
          { key:'types', label:'Chapter 7 vs Chapter 13' },
          { key:'article-foreclosure', label:'Stopping a foreclosure' },
          { key:'article-stay', label:'The automatic stay' },
        ]} />
      </Section>

      <CtaBand navigate={navigate} />
    </main>);
}

Object.assign(window, { ChapterSevenPage, ChapterThirteenPage });
