// data.jsx — mock data for Haven (self-managed NDIS planner)
const HAVEN_VERSION = 'v1.7 (10 Jun 2026)';
// "today" is 9 June 2026. Plan period 15 Aug 2025 – 14 Aug 2026.

const TODAY = new Date();   // live — Haven runs on the real today
const PLAN_START = new Date('2025-08-15');
const PLAN_END = new Date('2026-08-14');

const DAY = 86400000;
const daysBetween = (a, b) => Math.round((b - a) / DAY);
const PLAN_TOTAL_DAYS = daysBetween(PLAN_START, PLAN_END);
const PLAN_DAYS_ELAPSED = daysBetween(PLAN_START, TODAY);
const PLAN_DAYS_LEFT = daysBetween(TODAY, PLAN_END);
const PLAN_TIME_PCT = PLAN_DAYS_ELAPSED / PLAN_TOTAL_DAYS;

const fmtMoney = (n, dp = 0) =>
  '$' + Number(n).toLocaleString('en-AU', { minimumFractionDigits: dp, maximumFractionDigits: dp });

const fmtDate = (d) => {
  const dt = typeof d === 'string' ? new Date(d) : d;
  return dt.toLocaleDateString('en-AU', { day: 'numeric', month: 'short', year: 'numeric' });
};
const fmtDateShort = (d) => {
  const dt = typeof d === 'string' ? new Date(d) : d;
  return dt.toLocaleDateString('en-AU', { day: 'numeric', month: 'short' });
};

const CHILD = { name: 'Sarah', age: 9, ndis: '430 982 671', parent: 'Mum' };

// ── Budget categories ───────────────────────────────────────────────
// Three NDIS budget types, each with sub-categories.
const BUDGET = [
  {
    key: 'core', name: 'Core supports', color: 'var(--core)', soft: 'var(--core-soft)',
    plain: "Your everyday, flexible funding — day-to-day help, getting out and about, consumables and transport. You can usually move money between most Core supports as you need.",
    subs: [
      { name: 'Assistance with Daily Life', budget: 9000, spent: 7800 },
      { name: 'Social & Community Participation', budget: 14000, spent: 12600 },
      { name: 'Consumables', budget: 3400, spent: 2900 },
      { name: 'Transport', budget: 10000, spent: 7900 },
    ],
  },
  {
    key: 'capacity', name: 'Capacity Building', color: 'var(--capacity)', soft: 'var(--capacity-soft)',
    plain: "Funding to build your child's skills and independence — therapies, support coordination and the like. This money is locked to each sub-category, so it can't be moved between them.",
    subs: [
      { name: 'Improved Daily Living (therapies)', budget: 32000, spent: 24500 },
      { name: 'Support Coordination', budget: 9800, spent: 6200 },
      { name: 'Improved Relationships', budget: 4500, spent: 2400 },
      { name: 'Improved Health & Wellbeing', budget: 3500, spent: 800 },
    ],
  },
  {
    key: 'capital', name: 'Capital', color: 'var(--capital)', soft: 'var(--capital-soft)',
    plain: "One-off, higher-cost items like assistive technology or equipment. These are usually quoted and approved for a specific purpose.",
    subs: [
      { name: 'Assistive Technology', budget: 5800, spent: 2150 },
    ],
  },
];

// derived totals
BUDGET.forEach((cat) => {
  cat.budget = cat.subs.reduce((s, x) => s + x.budget, 0);
  cat.spent = cat.subs.reduce((s, x) => s + x.spent, 0);
  cat.remaining = cat.budget - cat.spent;
  cat.pct = cat.spent / cat.budget;
  cat.subs.forEach((s) => { s.remaining = s.budget - s.spent; s.pct = s.spent / s.budget; });
});

const PLAN = {
  total: BUDGET.reduce((s, c) => s + c.budget, 0),
  spent: BUDGET.reduce((s, c) => s + c.spent, 0),
};
PLAN.remaining = PLAN.total - PLAN.spent;
PLAN.pct = PLAN.spent / PLAN.total;

// ── Providers & supports ────────────────────────────────────────────
const PROVIDERS = [
  { id: 'p1', name: 'Bright Steps Occupational Therapy', short: 'Bright Steps OT', cat: 'capacity', sub: 'Improved Daily Living (therapies)', rate: '$193.99 / hr', agreementEnds: '2026-06-27' },
  { id: 'p2', name: 'Sunshine Speech Pathology', short: 'Sunshine Speech', cat: 'capacity', sub: 'Improved Daily Living (therapies)', rate: '$193.99 / hr', agreementEnds: '2026-09-30' },
  { id: 'p3', name: 'Active Kids Physiotherapy', short: 'Active Kids Physio', cat: 'capacity', sub: 'Improved Daily Living (therapies)', rate: '$193.99 / hr', agreementEnds: '2026-10-12' },
  { id: 'p4', name: 'Coastal Support Coordination', short: 'Coastal Coordination', cat: 'capacity', sub: 'Support Coordination', rate: '$100.14 / hr', agreementEnds: '2026-08-01' },
  { id: 'p5', name: 'Riverside Riding for the Disabled', short: 'Riverside Riding', cat: 'core', sub: 'Social & Community Participation', rate: '$64.00 / session', agreementEnds: '2026-12-01' },
  { id: 'p6', name: 'Sensory World Supplies', short: 'Sensory World', cat: 'core', sub: 'Consumables', rate: 'per item', agreementEnds: null },
];

// directly-employed support workers
const WORKERS = [
  { id: 'w1', name: 'Maria Lawson', role: 'Support Worker', rate: 38.5, initials: 'ML', cat: 'core' },
  { id: 'w2', name: 'Jacob Tran', role: 'Support Worker', rate: 36.0, initials: 'JT', cat: 'core' },
];

const TIMESHEETS = [
  { id: 't1', worker: 'w1', date: '2026-06-06', hours: 5, note: 'Saturday community access — swimming & park', status: 'pending' },
  { id: 't2', worker: 'w2', date: '2026-06-05', hours: 3, note: 'After-school routine support', status: 'pending' },
  { id: 't3', worker: 'w1', date: '2026-05-31', hours: 6, note: 'Community access — library program', status: 'paid' },
  { id: 't4', worker: 'w2', date: '2026-05-29', hours: 3, note: 'After-school routine support', status: 'paid' },
];

// ── Claims ──────────────────────────────────────────────────────────
// status: draft | submitted | paid | rejected
const CLAIMS = [
  { id: 'c108', provider: 'Bright Steps OT', cat: 'capacity', sub: 'Improved Daily Living (therapies)', date: '2026-06-02', amount: 387.98, status: 'submitted', submitted: '2026-06-03', invoice: 'INV-2291' },
  { id: 'c107', provider: 'Sunshine Speech', cat: 'capacity', sub: 'Improved Daily Living (therapies)', date: '2026-05-28', amount: 193.99, status: 'paid', submitted: '2026-05-29', paid: '2026-06-01', invoice: 'SSP-0884' },
  { id: 'c106', provider: 'Riverside Riding', cat: 'core', sub: 'Social & Community Participation', date: '2026-05-24', amount: 128.0, status: 'paid', submitted: '2026-05-25', paid: '2026-05-27', invoice: 'RR-1187' },
  { id: 'c105', provider: 'Active Kids Physio', cat: 'capacity', sub: 'Improved Daily Living (therapies)', date: '2026-05-20', amount: 387.98, status: 'paid', submitted: '2026-05-21', paid: '2026-05-23', invoice: 'AKP-552' },
  { id: 'c104', provider: 'Coastal Coordination', cat: 'capacity', sub: 'Support Coordination', date: '2026-05-15', amount: 300.42, status: 'rejected', submitted: '2026-05-16', invoice: 'CC-310', reason: 'Support category had no remaining funds at claim date. Check the category and resubmit.' },
  { id: 'c103', provider: 'Sensory World', cat: 'core', sub: 'Consumables', date: '2026-05-12', amount: 84.5, status: 'paid', submitted: '2026-05-12', paid: '2026-05-14', invoice: 'SW-7741' },
];

// ── Invoices & receipts (the vault) ─────────────────────────────────
// claimed links to a claim id, or null when waiting to be claimed.
const INVOICES = [
  { id: 'INV-2291', provider: 'Bright Steps OT', cat: 'capacity', date: '2026-06-02', amount: 387.98, claimed: 'c108', kind: 'invoice' },
  { id: 'BS-2310', provider: 'Bright Steps OT', cat: 'capacity', date: '2026-06-07', amount: 387.98, claimed: null, kind: 'invoice' },
  { id: 'RR-1209', provider: 'Riverside Riding', cat: 'core', date: '2026-06-07', amount: 64.0, claimed: null, kind: 'invoice' },
  { id: 'SW-7902', provider: 'Sensory World', cat: 'core', date: '2026-06-05', amount: 112.4, claimed: null, kind: 'receipt' },
  { id: 'SSP-0884', provider: 'Sunshine Speech', cat: 'capacity', date: '2026-05-28', amount: 193.99, claimed: 'c107', kind: 'invoice' },
  { id: 'RR-1187', provider: 'Riverside Riding', cat: 'core', date: '2026-05-24', amount: 128.0, claimed: 'c106', kind: 'invoice' },
  { id: 'AKP-552', provider: 'Active Kids Physio', cat: 'capacity', date: '2026-05-20', amount: 387.98, claimed: 'c105', kind: 'invoice' },
  { id: 'SW-7741', provider: 'Sensory World', cat: 'core', date: '2026-05-12', amount: 84.5, claimed: 'c103', kind: 'receipt' },
];

// ── Goals (for plan review) ─────────────────────────────────────────
const GOALS = [
  { id: 'g1', text: 'Communicate needs and feelings more independently', supports: 'Speech pathology, AAC device', progress: 0.7, note: 'Now using 2–3 word phrases consistently at home and school.' },
  { id: 'g2', text: 'Take part in a weekly community activity', supports: 'Riding program, support workers', progress: 0.9, note: 'Attends Riverside Riding every Saturday — loves it.' },
  { id: 'g3', text: 'Build daily-living and self-care skills', supports: 'Occupational therapy', progress: 0.55, note: 'Independent with morning routine 4 of 7 days.' },
  { id: 'g4', text: 'Improve gross-motor strength and balance', supports: 'Physiotherapy, swimming', progress: 0.4, note: 'Building up — physio happy with progress.' },
];

// ── Gentle reminders ("Needs you") ──────────────────────────────────
const REMINDERS = [
  { id: 'r1', kind: 'claim', tone: 'amber', icon: 'receipt', title: '3 invoices ready to claim', body: "$564.38 waiting to go to the NDIS. They'll usually land in your account within 2–3 days.", cta: 'Review & claim', to: 'invoices' },
  { id: 'r2', kind: 'pay', tone: 'amber', icon: 'people', title: "Maria & Jacob's timesheets need approving", body: '2 timesheets · 8 hours · about $311 before pay run.', cta: 'Open pay run', to: 'workers' },
  { id: 'r3', kind: 'agreement', tone: 'alert', icon: 'doc', title: 'Bright Steps OT agreement ends in 18 days', body: 'Renew it before 27 Jun so therapy claims keep flowing.', cta: 'View agreement', to: 'providers' },
  { id: 'r4', kind: 'review', tone: 'primary', icon: 'spark', title: 'Plan review in 66 days', body: "Your review summary is 40% ready. A little now saves a scramble later.", cta: 'Open review prep', to: 'review' },
];

// ── Activity feed ───────────────────────────────────────────────────
const ACTIVITY = [
  { id: 'a1', date: '2026-06-07', text: 'Added invoice BS-2310 from Bright Steps OT', amount: 387.98, type: 'invoice' },
  { id: 'a2', date: '2026-06-03', text: 'Claimed Bright Steps OT — session 2 Jun', amount: 387.98, type: 'claim' },
  { id: 'a3', date: '2026-06-01', text: 'NDIS paid your Sunshine Speech claim', amount: 193.99, type: 'paid' },
  { id: 'a4', date: '2026-05-31', text: 'Paid Maria Lawson — 6 hrs community access', amount: 231.0, type: 'pay' },
  { id: 'a5', date: '2026-05-27', text: 'NDIS paid your Riverside Riding claim', amount: 128.0, type: 'paid' },
];

// jargon glossary for plain-English helper
const GLOSSARY = {
  'Core supports': "Your everyday, flexible funding for daily help, getting out, consumables and transport.",
  'Capacity Building': "Funding to build skills and independence — like therapies and support coordination. Locked to each sub-category.",
  'Capital': "One-off, higher-cost items like assistive technology or equipment.",
  'Self-managed': "You pay providers yourself and claim the money back from the NDIS. Most freedom, a bit more admin — which is what Haven is here for.",
  'Plan review': "A meeting (now called a reassessment) where the NDIS looks at how things went and decides your next plan. Good records make it much easier.",
  'Claim': "A request to the NDIS to be paid back for a support you've bought. You enter the support, date and amount and attach the invoice.",
  'Service agreement': "A simple written agreement between you and a provider about what they'll do, the cost, and cancellation terms.",
};

Object.assign(window, {
  HAVEN_VERSION,
  TODAY, PLAN_START, PLAN_END, PLAN_TOTAL_DAYS, PLAN_DAYS_ELAPSED, PLAN_DAYS_LEFT, PLAN_TIME_PCT,
  fmtMoney, fmtDate, fmtDateShort, daysBetween,
  CHILD, BUDGET, PLAN, PROVIDERS, WORKERS, TIMESHEETS, CLAIMS, INVOICES, GOALS, REMINDERS, ACTIVITY, GLOSSARY,
});
