/* 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)
   - patel   (Tier 1 NY parity · NYC small-claims · NY Lab. Law § 198 + FLSA § 207 wage theft)
              [Sarah Chen v. Brooklyn Bites. Persona migrated 2026-05-13 from
              auto-repair (sarah-ny / GBL §396-p) to wage theft per James's
              SEO/launch-priority decision. See memory:
              scope_sarah_persona_wage_theft.md]
*/

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 Hello Court' },
    ],
    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.',
  },
  patel: {
    id: 'patel',
    title: 'Chen v. Brooklyn Bites',
    short: 'Chen v. Brooklyn Bites',
    client: { name: 'Sarah Chen', role: 'plaintiff (pro se)', initials: 'SC', city: 'Brooklyn, NY', occupation: 'Restaurant server', age: 24 },
    opposing: { name: 'Brooklyn Bites', counsel: 'No counsel of record', initials: 'BB' },
    type: 'Unpaid overtime + recordkeeping violation',
    typeShort: 'Wage theft',
    jurisdiction: 'ny',
    court: 'NYC Civil Court · Small Claims Part · Kings County',
    courtShort: 'NYC Civil Ct.',
    courtAddress: '141 Livingston Street, Brooklyn, NY 11201',
    courtForm: 'Statement of Claim',
    cause: 'unpaid-overtime',
    causeLabel: 'Unpaid overtime · 50-hour weeks paid straight time',
    statute: 'NY Lab. Law § 198 · § 195(4) · FLSA § 207',
    statuteShort: '§ 198 · FLSA § 207',
    altCauses: ['recordkeeping-violation', 'retaliation'],
    stage: 'Filing prep',
    pct: 76,
    amount: 2100,
    amountLabel: '$2,100',
    courtCosts: 20,
    filedDate: null,
    filedLabel: 'Drafting · not yet filed',
    daysToHearing: 42,
    hearingLabel: '~6 weeks out',
    elementsTotal: 4,
    elementsCovered: 4,
    evidenceCount: 4,
    readinessPct: 76,
    readinessDone: 16,
    readinessTotal: 21,
    readinessLabel: 'File-ready · 1 procedural gap (service method)',
    urgent: false,
    flag: null,
    sandbox: false,
    tier: 1,
    decisionsLogged: 12,
    summary: '8-week tenure as server at Brooklyn Bites. Scheduled 50 hours/week, paid straight time only. Required 30 minutes of off-the-clock prep before every shift, never recorded. NY Lab. Law § 198 and FLSA § 207 require time-and-a-half over 40 hours; NY § 198 adds 100% liquidated damages on top.',
    keyDates: [
      { date: 'Jan 6, 2026', event: 'Hired · $20/hr straight time · 50-hr weeks scheduled' },
      { date: 'Jan 13, 2026', event: 'Manager text: 30-min off-the-clock prep required every shift' },
      { date: 'Mar 2, 2026', event: 'Last shift worked · 8 weeks tenure total' },
      { date: 'Mar 5, 2026', event: 'Final paycheck · still straight-time only · no overtime premium' },
      { date: 'Mar 12, 2026', event: 'Written request to Brooklyn Bites for complete time records' },
      { date: 'Mar 26, 2026', event: 'No response · § 195(4) recordkeeping violation perfects' },
      { date: 'May 13, 2026', event: 'Filing prep with Hello Court' },
    ],
    evidence: [
      { name: 'Brooklyn Bites timecards.pdf', kind: 'PDF', size: '8 weeks · employer-produced', element: 1 },
      { name: 'Paystubs (8 weeks).pdf', kind: 'PDF', size: '$20/hr straight time confirmed', element: 3 },
      { name: 'Manager prep-time text.png', kind: 'PNG', size: 'Jan 13 SMS screenshot', element: 2 },
      { name: 'Contemporaneous prep log.pdf', kind: 'PDF', size: 'Sarah\'s own daily log', element: 2 },
    ],
    damagesBreakdown: [
      { line: 'Off-the-clock wages', math: '12 hrs × $20/hr', amount: 240 },
      { line: 'Overtime premium', math: '80 hrs × $10/hr half-time bump', amount: 800 },
      { line: 'NY liquidated damages', math: '100% of unpaid wages (NY Lab. § 198)', amount: 1040 },
      { line: 'Filing fee', math: 'NYC small-claims', amount: 20 },
    ],
  },
};

const ACTIVE_MATTER_ID = 'maria';
const PRIMARY_MATTERS = ['maria', 'daniel', 'patel'];

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;
