// app-data.jsx — shared state, mock data, helpers

const fmt = (n) => {
  const sign = n < 0 ? '-' : '';
  const abs = Math.abs(n);
  return sign + '$' + abs.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
};
const fmtShort = (n) => {
  const sign = n < 0 ? '-' : '';
  const abs = Math.abs(n);
  if (abs >= 1000) return sign + '$' + (abs / 1000).toFixed(abs >= 10000 ? 0 : 1) + 'k';
  return sign + '$' + Math.round(abs).toLocaleString();
};
const fmtMoney = (n, decimals=0) => '$' + Number(n).toLocaleString('en-US', { minimumFractionDigits: decimals, maximumFractionDigits: decimals });

const PEOPLE = {
  B: { id: 'B', name: 'Branden', initial: 'B', color: '#2b3a55', soft: '#dde3ee' },
  C: { id: 'C', name: 'Cindy',   initial: 'C', color: '#c97a4a', soft: '#f3dccb' },
  J: { id: 'J', name: 'Joint',   initial: 'BC', color: '#5a6b4f', soft: '#dde3d3' },
};

// 14 days of transactions, mixed across accounts & people
const TRANSACTIONS = [
  { id: 't01', date: '2026-05-06', who: 'C', acct: 'Joint Checking',  merchant: 'Trader Joe\'s',           cat: 'Groceries',     amt: -78.42,  approved: true,  bank: 'Chase' },
  { id: 't02', date: '2026-05-06', who: 'B', acct: 'Joint Checking',  merchant: 'Shell',                   cat: 'Gas',           amt: -52.10,  approved: true,  bank: 'Chase' },
  { id: 't03', date: '2026-05-05', who: 'B', acct: 'Branden Checking',merchant: 'Direct Deposit — Acme',   cat: 'Income',        amt: 2840.00, approved: true,  bank: 'Chase' },
  { id: 't04', date: '2026-05-05', who: 'C', acct: 'Cindy Checking',  merchant: 'Lulu\'s Cleaning',        cat: 'Income',        amt: 350.00,  approved: true,  bank: 'Ally' },
  { id: 't05', date: '2026-05-05', who: 'C', acct: 'Joint Checking',  merchant: 'Spotify',                 cat: 'Subscriptions', amt: -16.99,  approved: true,  bank: 'Chase' },
  { id: 't06', date: '2026-05-04', who: 'B', acct: 'Joint Credit',    merchant: 'The Home Depot',          cat: 'Home',          amt: -126.84, approved: false, bank: 'Chase', flag: 'needs-split' },
  { id: 't07', date: '2026-05-04', who: 'C', acct: 'Cindy Credit',    merchant: 'Anthropologie',           cat: 'Personal',      amt: -88.50,  approved: true,  bank: 'Ally', private: true },
  { id: 't08', date: '2026-05-03', who: 'B', acct: 'Joint Checking',  merchant: 'PG&E',                    cat: 'Utilities',     amt: -184.22, approved: true,  bank: 'Chase' },
  { id: 't09', date: '2026-05-03', who: 'C', acct: 'Joint Checking',  merchant: 'Whole Foods',             cat: 'Groceries',     amt: -112.04, approved: true,  bank: 'Chase' },
  { id: 't10', date: '2026-05-02', who: 'B', acct: 'Joint Credit',    merchant: 'Chevron',                 cat: 'Gas',           amt: -48.91,  approved: true,  bank: 'Chase' },
  { id: 't11', date: '2026-05-02', who: 'C', acct: 'Joint Credit',    merchant: 'Sprout Wellness Studio',  cat: 'Wellness',      amt: -45.00,  approved: false, bank: 'Chase', flag: 'review' },
  { id: 't12', date: '2026-05-01', who: 'B', acct: 'Joint Checking',  merchant: 'Rent — Lakeshore Apts',   cat: 'Rent',          amt: -1850.00,approved: true,  bank: 'Chase' },
  { id: 't13', date: '2026-05-01', who: 'B', acct: 'Joint Checking',  merchant: 'AT&T',                    cat: 'Utilities',     amt: -94.00,  approved: true,  bank: 'Chase' },
  { id: 't14', date: '2026-04-30', who: 'C', acct: 'Joint Checking',  merchant: 'Target',                  cat: 'Household',     amt: -64.18,  approved: true,  bank: 'Chase' },
  { id: 't15', date: '2026-04-30', who: 'B', acct: 'Branden Checking',merchant: 'Coffee Roastery',         cat: 'Coffee',        amt: -6.50,   approved: true,  bank: 'Chase', private: true },
  { id: 't16', date: '2026-04-29', who: 'C', acct: 'Cindy Checking',  merchant: 'Cindy\'s Etsy Shop',      cat: 'Income',        amt: 142.00,  approved: true,  bank: 'Ally' },
  { id: 't17', date: '2026-04-29', who: 'B', acct: 'Joint Checking',  merchant: 'Geico Auto',              cat: 'Insurance',     amt: -148.00, approved: true,  bank: 'Chase' },
  { id: 't18', date: '2026-04-28', who: 'C', acct: 'Joint Checking',  merchant: 'Trader Joe\'s',           cat: 'Groceries',     amt: -94.10,  approved: true,  bank: 'Chase' },
];

const ACCOUNTS = [
  { id: 'jc',  bank: 'Chase', name: 'Joint Checking',   owner: 'J', balance: 4218.74, type: 'checking', last4: '1209' },
  { id: 'jcc', bank: 'Chase', name: 'Joint Credit',     owner: 'J', balance: -842.31, type: 'credit',   last4: '7740', limit: 8000 },
  { id: 'js',  bank: 'Chase', name: 'Joint Savings',    owner: 'J', balance: 7942.10, type: 'savings',  last4: '0044' },
  { id: 'bc',  bank: 'Chase', name: 'Branden Checking', owner: 'B', balance: 1284.52, type: 'checking', last4: '8821', private: true },
  { id: 'cc',  bank: 'Ally',  name: 'Cindy Checking',   owner: 'C', balance: 612.08,  type: 'checking', last4: '3380', private: true },
  { id: 'ccc', bank: 'Ally',  name: 'Cindy Credit',     owner: 'C', balance: -218.50, type: 'credit',   last4: '5519', limit: 3500, private: true },
];

const BUDGET = [
  { cat: 'Rent',          planned: 1850, spent: 1850, kind: 'fixed' },
  { cat: 'Utilities',     planned: 320,  spent: 278,  kind: 'fixed' },
  { cat: 'Groceries',     planned: 700,  spent: 284,  kind: 'flex' },
  { cat: 'Gas',           planned: 220,  spent: 101,  kind: 'flex' },
  { cat: 'Insurance',     planned: 148,  spent: 148,  kind: 'fixed' },
  { cat: 'Subscriptions', planned: 65,   spent: 17,   kind: 'flex' },
  { cat: 'Home',          planned: 200,  spent: 127,  kind: 'flex' },
  { cat: 'Household',     planned: 150,  spent: 64,   kind: 'flex' },
  { cat: 'Wellness',      planned: 120,  spent: 45,   kind: 'flex' },
  { cat: 'Personal',      planned: 200,  spent: 89,   kind: 'flex' },
  { cat: 'Coffee',        planned: 60,   spent: 7,    kind: 'flex' },
  { cat: 'Class (Cindy)', planned: 0,    spent: 0,    kind: 'goal', proposed: 275 },
];

// Income sources, for scenario engine
const INCOME = [
  { id: 'i1', who: 'B', source: 'Acme — Salary',    monthly: 5680, certain: true },
  { id: 'i2', who: 'C', source: 'Lulu\'s Cleaning', monthly: 700,  certain: true,  flagForRemoval: true },
  { id: 'i3', who: 'C', source: 'Etsy shop',        monthly: 220,  certain: false },
];

// Habits (life tracker)
const HABITS = [
  { id: 'h1', who: 'B', name: 'Walk 30 min',     streak: 12, today: true,  weekly: [1,1,0,1,1,1,1] },
  { id: 'h2', who: 'B', name: 'No takeout',      streak: 4,  today: true,  weekly: [0,1,1,1,1,1,0] },
  { id: 'h3', who: 'C', name: 'Class practice',  streak: 8,  today: false, weekly: [1,1,1,0,1,1,0] },
  { id: 'h4', who: 'C', name: 'Read 20 min',     streak: 21, today: true,  weekly: [1,1,1,1,1,1,1] },
  { id: 'h5', who: 'J', name: 'Money check-in',  streak: 3,  today: false, weekly: [0,1,0,1,0,1,0], shared: true },
];

// Mood log: last 14 days, 1-5 scale
const MOOD = {
  B: [3,4,3,4,5,4,3,3,4,5,4,4,3,4],
  C: [3,2,2,3,3,2,3,4,4,3,4,4,5,4], // trends up after class is mentioned
};

const GOAL = {
  title: 'Cindy quits cleaning + starts pottery class',
  stated: 'Cindy wants to leave her cleaning job ($700/mo) and enroll in a ceramics class ($275/mo). Find a way to make this work without dipping into savings.',
  startBy: '2026-06-01',
  netImpact: -975, // -700 lost + -275 new expense
  status: 'planning',
};

// expose
Object.assign(window, {
  fmt, fmtShort, fmtMoney,
  PEOPLE, TRANSACTIONS, ACCOUNTS, BUDGET, INCOME, HABITS, MOOD, GOAL,
});
