/* Shared Matters Dataset. REVISED per 00-brief-REVISED.md
   Three personas thread through the entire prototype:
   - maria   (Tier 1 · the demo arc · Utah · §57-17-3 security deposit)
   - daniel  (Tier 2 · lawyer-handoff · Utah · $24K contract + counterclaim)
   - sarah-ny (Tier 1 NY parity · NYC small-claims · GBL §396-p auto repair)
*/

const TIERS = {
  1: {
    id: 1,
    label: 'Tier 1',
    full: 'Tier 1 · Full pro-se support',
    short: 'Full pro-se',
    tone: () => THEME.success,
    desc: 'End-to-end pro-se support: theory selection, evidence mapping, packet generation, courtroom prep.',
  },
  2: {
    id: 2,
    label: 'Tier 2',
    full: 'Tier 2 · Lawyer handoff',
    short: 'Lawyer handoff',
    tone: () => THEME.warn,
    desc: 'Triage + organize + handoff. We prepare a watermarked pitch packet you send to attorneys.',
  },
  3: {
    id: 3,
    label: 'Tier 3',
    full: 'Tier 3 · Orientation + lawyer match',
    short: 'Orientation + match',
    tone: () => THEME.blue,
    desc: 'Universal welcome and lawyer-scan for situations outside Tier 1/2 scope.',
  },
};

const MATTERS = {
  maria: {
    id: 'maria',
    title: 'Vargas v. Westhaven Properties',
    short: 'Vargas v. Westhaven',
    client: { name: 'Maria Vargas', role: 'plaintiff (pro se)', initials: 'MV', city: 'Salt Lake City, UT', occupation: 'Restaurant server', age: 28 },
    opposing: { name: 'Westhaven Properties', counsel: 'No counsel of record', initials: 'WP' },
    type: 'Wrongful retention of security deposit',
    typeShort: 'Security deposit',
    jurisdiction: 'utah',
    court: 'Salt Lake County Justice Court',
    courtShort: 'Salt Lake Justice Ct.',
    courtAddress: '450 South State Street, Salt Lake City, UT 84111',
    courtForm: 'Small Claims Affidavit',
    cause: 'wrongful-retention',
    causeLabel: 'Wrongful retention of security deposit',
    statute: 'Utah Code § 57-17-3',
    statuteShort: '§ 57-17-3',
    altCauses: ['breach-lease'],
    stage: 'Filing prep',
    pct: 87,
    amount: 3690,
    amountLabel: '$3,690',
    deposit: 1800,
    depositLabel: '$1,800',
    statutoryMultiplier: 2,
    courtCosts: 90,
    filedDate: null,
    filedLabel: 'Drafting · not yet filed',
    daysToHearing: 42,
    hearingLabel: '~6 weeks out',
    elementsTotal: 4,
    elementsCovered: 4,
    evidenceCount: 8,
    readinessPct: 87,
    readinessDone: 19,
    readinessTotal: 22,
    readinessLabel: 'File-ready · No critical gaps',
    urgent: false,
    flag: null,
    sandbox: true,
    tier: 1,
    decisionsLogged: 17,
    summary: 'Lease ended 3/15/26. Maria gave 30-day notice + forwarding address. April 14 statutory deadline passed with no deposit return and no written itemized statement. § 57-17-3(c) authorizes 2× recovery.',
    keyDates: [
      { date: 'Jul 1, 2025', event: 'Lease begins · $1,800 deposit paid' },
      { date: 'Mar 14, 2026', event: '30-day notice + forwarding address (email + cert. mail)' },
      { date: 'Mar 15, 2026', event: 'Move-out · 12 walkthrough photos' },
      { date: 'Apr 14, 2026', event: 'Statutory 30-day deadline · no response' },
      { date: 'Apr 16, 2026', event: 'Follow-up email · no response' },
      { date: 'Apr 22, 2026', event: 'Second follow-up · no response' },
      { date: 'Apr 30, 2026', event: 'Filing prep with AllLaw Guide' },
    ],
    evidence: [
      { name: 'Lease agreement.pdf', kind: 'PDF', size: '11 pages', element: 1 },
      { name: 'Move-in checklist.pdf', kind: 'PDF', size: '1 page', element: 1 },
      { name: 'Move-out photos (12).zip', kind: 'JPG', size: '12 photos · EXIF stripped', element: 4 },
      { name: 'Forwarding address email.eml', kind: 'EML', size: 'Mar 14, 2026', element: 2 },
      { name: 'Certified mail receipt.pdf', kind: 'PDF', size: 'USPS green card', element: 2 },
      { name: 'Follow-up email Apr 16.eml', kind: 'EML', size: 'No response', element: 4 },
      { name: 'Follow-up email Apr 22.eml', kind: 'EML', size: 'No response', element: 4 },
      { name: 'Bank statement Jul 2025.pdf', kind: 'PDF', size: 'Deposit ACH', element: 1 },
    ],
  },
  daniel: {
    id: 'daniel',
    title: 'Romero v. Mountain View Homeowners',
    short: 'Romero v. Mountain View',
    client: { name: 'Daniel Romero', role: 'plaintiff/counter-defendant', initials: 'DR', city: 'Provo, UT', occupation: 'Small contractor (2-person crew)' },
    opposing: { name: 'Mountain View Homeowners', counsel: 'TBD', initials: 'MV' },
    type: 'Breach of contract + counterclaim risk',
    typeShort: 'Contract dispute',
    jurisdiction: 'utah',
    court: 'Utah District Court (above small-claims cap)',
    courtShort: 'UT District Ct.',
    courtForm: 'Civil Complaint',
    cause: 'breach-contract',
    causeLabel: 'Breach of contract',
    statute: 'Utah common law',
    statuteShort: 'Common law',
    stage: 'Tier 2 handoff',
    pct: 65,
    amount: 24000,
    amountLabel: '$24,000',
    filedDate: null,
    filedLabel: 'Pitch packet drafted · 3 attorneys contacted',
    daysToHearing: null,
    hearingLabel: 'Pending engagement',
    elementsTotal: 5,
    elementsCovered: 4,
    evidenceCount: 11,
    readinessPct: 65,
    readinessDone: 11,
    readinessTotal: 17,
    urgent: false,
    flag: 'Above small-claims cap · counterclaim threat',
    sandbox: true,
    tier: 2,
    decisionsLogged: 9,
    packetViews: 5,
    packetSent: 3,
    lastOpened: '2 days ago',
    summary: 'Finished a $24,000 kitchen remodel. Homeowner refusing to pay, threatening fraud counterclaim alleging substandard materials. Above $15K small-claims cap; counterclaim exceeds solo pro-se capacity.',
  },
  'sarah-ny': {
    id: 'sarah-ny',
    title: 'Patel v. East Side Auto Repair',
    short: 'Patel v. East Side',
    client: { name: 'Sarah Patel', role: 'plaintiff (pro se)', initials: 'SP', city: 'Brooklyn, NY' },
    opposing: { name: 'East Side Auto Repair', counsel: 'TBD', initials: 'EA' },
    type: 'Auto repair · Deceptive practices',
    typeShort: 'Consumer',
    jurisdiction: 'ny',
    court: 'NYC Civil Court · Small Claims',
    courtShort: 'NYC Small Claims',
    courtForm: 'Statement of Claim',
    cause: 'deceptive-practices',
    causeLabel: 'Motor vehicle repair shops · GBL § 396-p + § 349',
    statute: 'NY GBL § 396-p · § 349',
    statuteShort: 'GBL §396-p · §349',
    stage: 'Theory selection',
    pct: 24,
    amount: 4180,
    amountLabel: '$4,180',
    filedDate: null,
    filedLabel: 'Early intake · choosing theory',
    daysToHearing: null,
    hearingLabel: 'Not yet scheduled',
    elementsTotal: 4,
    elementsCovered: 1,
    evidenceCount: 5,
    readinessPct: 24,
    readinessDone: 5,
    readinessTotal: 21,
    urgent: false,
    flag: null,
    sandbox: false,
    tier: 1,
    decisionsLogged: 3,
    summary: 'Took car for $400 brake job. Shop charged $4,180 for "necessary additional work" never authorized. NY GBL §396-p requires written authorization for repairs over $100.',
  },
};

const ACTIVE_MATTER_ID = 'maria';
const PRIMARY_MATTERS = ['maria', 'daniel', 'sarah-ny'];

const STAGE_TONE = {
  'Filing prep': () => THEME.warn,
  'Tier 2 handoff': () => THEME.warn,
  'Theory selection': () => THEME.blue,
  'Hearing prep': () => THEME.danger,
  'Discovery': () => THEME.blue,
  'Resolved': () => THEME.success,
};

/* Tier badge. Used on every case card, page header, filter chip */
const TierBadge = ({ tier, dense, full }) => {
  const t = TIERS[tier];
  if (!t) return null;
  const tone = t.tone();
  return (
    <span style={{
      display: 'inline-flex', alignItems: 'center', gap: 5,
      fontSize: dense ? 9.5 : 10.5, fontWeight: 700, padding: dense ? '2px 6px' : '3px 8px',
      borderRadius: 5, letterSpacing: 0.5, textTransform: 'uppercase',
      background: tone + '1f', color: tone, border: `1px solid ${tone}55`,
    }}>
      <span style={{ width: 5, height: 5, borderRadius: 3, background: tone }}/>
      {full ? t.full : t.label}
    </span>
  );
};

window.MATTERS = MATTERS;
window.TIERS = TIERS;
window.TierBadge = TierBadge;
window.ACTIVE_MATTER_ID = ACTIVE_MATTER_ID;
window.PRIMARY_MATTERS = PRIMARY_MATTERS;
window.STAGE_TONE = STAGE_TONE;
