// Fictional but plausible Australian aged care data
const FACILITY = {
  name: "Wattlegrove Aged Care",
  suburb: "Parramatta, NSW",
  beds: 164,
  wards: ["Banksia", "Wattle", "Grevillea", "Bottlebrush"],
};

// Multi-site roll-up — the provider operates several facilities.
const FACILITIES = [
  { id: "F-WGV", name: "Wattlegrove Aged Care", suburb: "Parramatta, NSW", beds: 164, staff: 143, compliance: 0.976, agencyPct: 0.074, careMin: 215, risk: "warn",  riskReason: "1 AHPRA blocker · 14 expiring", cost: 249140, budget: 268000 },
  { id: "F-BKL", name: "Banksia Lodge",         suburb: "Newtown, NSW",    beds: 112, staff: 96,  compliance: 0.988, agencyPct: 0.052, careMin: 208, risk: "ok",    riskReason: "All clear",                 cost: 172300, budget: 182000 },
  { id: "F-KKP", name: "Kookaburra Place",      suburb: "Chatswood, NSW",  beds: 96,  staff: 81,  compliance: 0.962, agencyPct: 0.091, careMin: 198, risk: "warn",  riskReason: "Care minutes borderline",   cost: 151800, budget: 157000 },
  { id: "F-RVM", name: "Riverside Manor",       suburb: "Parramatta, NSW", beds: 78,  staff: 66,  compliance: 0.994, agencyPct: 0.041, careMin: 222, risk: "ok",    riskReason: "All clear",                 cost: 118900, budget: 128000 },
];

const STAFF = [
  { id: "E-1042", name: "Priya Sharma",       role: "RN",  grade: "RN L2", ward: "Banksia",     tone: "sage",  ahpra: "NMW0001429732", status: "ok",    hours: 38, agency: false },
  { id: "E-1088", name: "Marcus Tavita",      role: "EN",  grade: "EN L3", ward: "Wattle",      tone: "ink",   ahpra: "NMW0001882104", status: "warn",  hours: 36, agency: false, expiring: "Police check · 14 days" },
  { id: "E-1131", name: "Aisha Okonkwo",      role: "PCA", grade: "PCA",   ward: "Banksia",     tone: "sage",  ahpra: "—",             status: "ok",    hours: 32, agency: false },
  { id: "E-1205", name: "Lachlan Fitzgerald", role: "RN",  grade: "RN L3", ward: "Grevillea",   tone: "ink",   ahpra: "NMW0002001187", status: "block", hours: 0,  agency: false, expired: "AHPRA registration expired 12 Apr" },
  { id: "E-1310", name: "Hien Nguyen",        role: "RN",  grade: "RN L2", ward: "Bottlebrush", tone: "sage",  ahpra: "NMW0001553210", status: "ok",    hours: 40, agency: false },
  { id: "E-1402", name: "Olamide Adebayo",    role: "PCA", grade: "PCA",   ward: "Wattle",      tone: "amber", ahpra: "—",             status: "warn",  hours: 24, agency: false, expiring: "First Aid · 22 days" },
  { id: "E-1517", name: "Grace Whitford",     role: "EN",  grade: "EN L2", ward: "Grevillea",   tone: "sage",  ahpra: "NMW0001721498", status: "ok",    hours: 32, agency: false },
  { id: "E-1602", name: "Rahim Chaudhry",     role: "RN",  grade: "RN L1", ward: "Bottlebrush", tone: "ink",   ahpra: "NMW0002144519", status: "warn",  hours: 30, agency: false, expiring: "Visa 482 · 31 days" },
  { id: "A-2017", name: "Siobhán Kelly",      role: "RN",  grade: "RN L2", ward: "Banksia",     tone: "amber", ahpra: "NMW0001009872", status: "ok",    hours: 24, agency: true  },
  { id: "A-2042", name: "Dominic Rossi",      role: "PCA", grade: "PCA",   ward: "Wattle",      tone: "amber", ahpra: "—",             status: "ok",    hours: 16, agency: true  },
];

// Exceptions, ranked by severity
const EXCEPTIONS = [
  {
    id: "X-001",
    tone: "block",
    kind: "Compliance",
    title: "AHPRA registration expired — Lachlan Fitzgerald",
    body: "Registration lapsed 5 days ago. 3 upcoming shifts now blocked.",
    meta: "E-1205 · Grevillea · RN L3",
    chain: ["Credential", "Roster × 3", "Payroll hold"],
    action: "Remove from roster",
  },
  {
    id: "X-002",
    tone: "warn",
    kind: "Roster",
    title: "Night shift short 1 RN — Banksia, Fri 24 Apr",
    body: "Care minutes will fall below target (182 → 173). Agency fill available: Siobhán K.",
    meta: "21:00 – 07:00 · ratio 1:12",
    chain: ["Ratio breach", "Care minutes", "SIRS risk"],
    action: "Review AI fill",
    ai: true,
  },
  {
    id: "X-003",
    tone: "warn",
    kind: "Payroll",
    title: "7 timesheets missing approval — pay period closes in 18h",
    body: "Holding $11,420 in payable wages. All within Wattle.",
    meta: "Period 2026-04-04 to 2026-04-17",
    chain: ["Timesheets", "Payroll run", "ATO STP"],
    action: "Bulk review",
  },
  {
    id: "X-004",
    tone: "warn",
    kind: "HR",
    title: "6 credentials expiring within 30 days",
    body: "4 First Aid, 1 Police check, 1 Visa 482. NuCo has drafted renewal emails.",
    meta: "Banksia (2) · Wattle (3) · Grevillea (1)",
    chain: ["Credentials", "Roster eligibility"],
    action: "Approve outreach",
    ai: true,
  },
  {
    id: "X-005",
    tone: "ok",
    kind: "Resolved",
    title: "Replaced sick call-out with internal — Hien N. → Grace W.",
    body: "NuCo auto-filled from eligible RN pool. Saved est. $412 vs agency.",
    meta: "Shift 07:00–15:00 · Grevillea · 04:12 AM",
    chain: ["Call-out", "Eligibility check", "Auto-fill"],
    action: "View",
    ai: true,
  },
];

// Agent activity (right-rail "things the system did")
const AGENT_ACTIVITY = [
  { tone: "sage", time: "04:12", title: "Filled sick call-out",          body: "Grace Whitford offered shift 07:00–15:00 Grevillea. Replaced Hien Nguyen. Avoided $412 agency cost." },
  { tone: "ink",  time: "02:48", title: "Drafted 4 credential renewals", body: "First Aid renewals drafted for Olamide A., Terence P., Mei L., Chloé D. Awaiting your approval." },
  { tone: "amber",time: "01:30", title: "Flagged ratio risk",            body: "Banksia night shift Fri 24 Apr will fall below care-minute target. 1 internal option, 1 agency option." },
  { tone: "sage", time: "Yesterday", title: "Reconciled 142 timesheets", body: "Auto-matched roster, clock events and award rules. 7 held for manual approval." },
  { tone: "terra",time: "Yesterday", title: "Blocked shift assignment",  body: "Lachlan F. assigned to Sat 20 Apr RN shift — AHPRA lapsed. Held and notified manager." },
  { tone: "ink",  time: "Mon",   title: "Generated SIRS readiness report", body: "Q2 incident reporting bundle prepared. 0 notifiable incidents. Ready to review." },
];

// KPIs
const KPIS = [
  { label: "On roster now",       value: "142",  unit: "/ 148", delta: "+4 vs yest.", tone: "up",  bar: 0.96, note: "96% staffed" },
  { label: "Compliance rate",     value: "97.6", unit: "%",     delta: "−0.4 pts",    tone: "down",bar: 0.976, note: "2 blockers · 6 expiring" },
  { label: "Agency spend (WTD)",  value: "$18.4",unit: "k",     delta: "−24% vs plan",tone: "up",  bar: 0.42, note: "Below target $24k" },
  { label: "Care minutes",        value: "215",  unit: "min/res", delta: "Target 200", tone: "up", bar: 1.075, note: "7.5% above target" },
];

const MODULES = [
  { key: "dashboard",  label: "Dashboard",   count: null, tone: null },
  { key: "roster",     label: "Roster",      count: 3,    tone: "warn" },
  { key: "people",     label: "People",      count: null, tone: null },
  { key: "payroll",    label: "Payroll",     count: 7,    tone: "warn" },
  { key: "compliance", label: "Compliance",  count: 2,    tone: "block" },
];

// Roster data — 24h grid for one ward
// Times from 00 to 23
const ROSTER_ROWS = [
  { staff: STAFF[0], shifts: [{ start: 7,  end: 15, kind: "day",     label: "Day · RN" }] },
  { staff: STAFF[1], shifts: [{ start: 15, end: 23, kind: "evening", label: "PM · EN" }] },
  { staff: STAFF[2], shifts: [{ start: 7,  end: 15, kind: "day",     label: "Day · PCA" }] },
  { staff: STAFF[4], shifts: [{ start: 23, end: 24, kind: "night",   label: "Night · RN", wrap: true }] },
  { staff: STAFF[3], shifts: [{ start: 7,  end: 15, kind: "day",     label: "Day · RN", blocked: true }] },
  { staff: STAFF[6], shifts: [{ start: 15, end: 23, kind: "evening", label: "PM · EN" }] },
  { staff: STAFF[5], shifts: [{ start: 7,  end: 13, kind: "day",     label: "Day · PCA" }] },
  { staff: STAFF[8], shifts: [{ start: 15, end: 23, kind: "agency",  label: "PM · Agency RN" }] },
  { staff: { name: "Open — RN required",  role: "", ward: "Banksia", tone: "amber", open: true }, shifts: [{ start: 23, end: 24, kind: "open", label: "Night · Open", wrap: true }] },
  { staff: { name: "AI suggested — Siobhán K.", role: "", ward: "Banksia", tone: "sage", ai: true }, shifts: [{ start: 23, end: 24, kind: "ai", label: "Night · Accept?", wrap: true }] },
];

// Compliance categories
const COMPLIANCE = [
  { label: "AHPRA registrations",  ok: 38, warn: 2, block: 1, total: 41 },
  { label: "First Aid / CPR",      ok: 92, warn: 4, block: 0, total: 96 },
  { label: "Police check",         ok: 94, warn: 1, block: 0, total: 95 },
  { label: "NDIS worker screen",   ok: 61, warn: 0, block: 0, total: 61 },
  { label: "Working rights / visa",ok: 23, warn: 1, block: 0, total: 24 },
  { label: "Mandatory training",   ok: 88, warn: 6, block: 2, total: 96 },
];

// Payroll — seed of open exceptions used by state and the payroll page.
const PAYROLL_OPEN = [
  { id: "P-101", type: "Missing approval",   personId: "E-1402", detail: "8 shifts pending manager sign-off (Wattle)",                       impact: "+$2,180", impactCents: 218000, tone: "warn",  chain: ["Timesheets","Mgr approval","Payroll"],          aiFix: "Apply delegated manager sign-off (Lee W.) to all 8 shifts per Wattle delegation policy." },
  { id: "P-102", type: "Penalty mismatch",   personId: "E-1088", detail: "Sat PM shift coded at base rate, award requires 1.5×",             impact: "+$284",   impactCents:  28400, tone: "warn",  chain: ["Award rule","Penalty","Payroll"],               aiFix: "Apply SCHADS Schedule B penalty 1.5× to Sat 15:00–23:00 shift." },
  { id: "P-103", type: "Timesheet gap",      personId: "E-1131", detail: "Clock-out missing for Wed shift. NuCo inferred 15:02.",            impact: "±$12",    impactCents:   1200, tone: "warn",  ai: true, chain: ["Clock event","Inference","Payroll"], aiFix: "Accept inferred clock-out 15:02 (based on next verified event + 2 min)." },
  { id: "P-104", type: "Compliance hold",    personId: "E-1205", detail: "AHPRA expired · pay release blocked until valid reg on file",      impact: "$0",      impactCents:      0, tone: "block", chain: ["Credential","Eligibility","Payroll gate"],      aiFix: "Cannot auto-resolve — requires valid AHPRA registration upload. Clears automatically once renewed." },
  { id: "P-105", type: "Overtime threshold", personId: "E-1310", detail: "44.2h this week — award threshold 40h",                            impact: "+$168",   impactCents:  16800, tone: "warn",  chain: ["Threshold","OT","Payroll"],                     aiFix: "Pay 4.2h at 1.5× overtime per SCHADS clause 28.2." },
  { id: "P-106", type: "Leave without pay",  personId: "E-1602", detail: "LWOP not set — Thu absence currently paid at base",                impact: "−$198",   impactCents: -19800, tone: "warn",  chain: ["Leave","Pay","Payroll"],                        aiFix: "Flag Thu absence as LWOP per leave register entry L-2041." },
  { id: "P-107", type: "Allowance missing",  personId: "E-1042", detail: "Infection control allowance flagged by award Schedule F",          impact: "+$42",    impactCents:   4200, tone: "warn",  ai: true, chain: ["Allowance","Award","Payroll"],       aiFix: "Apply Infection Control Allowance (Schedule F) — $10.20 × 4 qualifying shifts." },
];

const PAYROLL_AUTO_INITIAL = [
  { id: "A-001", text: "Matched 142 timesheets to roster events", note: "0 disputes" },
  { id: "A-002", text: "Applied night penalty to 14 shifts",      note: "+$1,840" },
  { id: "A-003", text: "Recalculated super on back-pay",          note: "+$312" },
  { id: "A-004", text: "Corrected duplicate clock events (×3)",   note: "−$186" },
  { id: "A-005", text: "Routed LWOP for pre-approved leave",      note: "−$420" },
];

// Payroll preview
const PAYROLL = {
  period: "2026-04-04 to 2026-04-17",
  closes: "Today, 17:00",
  gross: 421850,
  net: 298410,
  super: 48512,
  paye: 78928,
  staffOK: 135,
  staffException: 7,
  staffHold: 1,
  deltaWeek: +2.4,
  autoResolved: 18,
};

// Sparkline generator
function spark(points, {color="var(--ink)", fill=null, width=200, height=44}={}) {
  const min = Math.min(...points), max = Math.max(...points);
  const r = max - min || 1;
  const step = width / (points.length - 1);
  const path = points.map((p,i) => `${i===0?'M':'L'}${(i*step).toFixed(1)},${(height - ((p-min)/r)*height*0.85 - 2).toFixed(1)}`).join(" ");
  return { path, width, height };
}

// Expiry timeline — compliance page.
const EXPIRIES = [
  { id: "EXP-01", name: "Lachlan Fitzgerald", cred: "AHPRA registration", category: "clinical",     day: -5, tone: "block", tone2: "terra", impact: "3 shifts held, pay gate" },
  { id: "EXP-02", name: "Marcus Tavita",      cred: "Police check",       category: "non-clinical", day: 14, tone: "warn",  tone2: "ink",   impact: "Eligibility at 14d" },
  { id: "EXP-03", name: "Olamide Adebayo",    cred: "First Aid / CPR",    category: "clinical",     day: 22, tone: "warn",  tone2: "amber", impact: "Reminder sent" },
  { id: "EXP-04", name: "Rahim Chaudhry",     cred: "Visa 482",           category: "non-clinical", day: 31, tone: "warn",  tone2: "ink",   impact: "Working rights review" },
  { id: "EXP-05", name: "Mei Lin",            cred: "First Aid / CPR",    category: "clinical",     day: 38, tone: "ok",    tone2: "sage",  impact: "NuCo drafted renewal" },
  { id: "EXP-06", name: "Chloé Dubois",       cred: "Mandatory training", category: "clinical",     day: 44, tone: "ok",    tone2: "sage",  impact: "Auto-enrolled" },
  { id: "EXP-07", name: "Terence Park",       cred: "First Aid / CPR",    category: "clinical",     day: 52, tone: "ok",    tone2: "ink",   impact: "On track" },
];

// AI plans — copilot plans tab and roster "Review & apply".
const AI_PLANS = [
  {
    id: "PL-001",
    title: "Apply NuCo's roster proposal for Banksia (Fri 24 Apr)",
    summary: "3 changes · maintain 1:7 ratio · reduce agency from 2→1 · save $1,240",
    risk: "low",
    steps: [
      { before: "Open · RN · Banksia · 23:00–07:00", after: "Siobhán K. · agency RN · $412 lower than Medacs" },
      { before: "Agency PM · Dominic R. · Wattle",    after: "Grace W. · internal EN · no OT breach" },
      { before: "Day · PCA · Aisha (6h)",              after: "Day · PCA · Aisha (8h, rostered lunch cover)" },
    ],
    activity: { tone: "sage", title: "Applied AI roster plan", body: "3 shifts re-assigned · agency reduced to 1 · est. saving $1,240." },
  },
  {
    id: "PL-002",
    title: "Close 6 credential expiries proactively",
    summary: "6 renewal drafts · 0 blockers forecast for next 60d",
    risk: "low",
    steps: [
      { before: "First Aid expiring (×4)", after: "Renewal email sent · slot booked 23 Apr" },
      { before: "Police check 14d",        after: "AusCheck e-form pushed to Marcus T." },
      { before: "Visa 482 31d",            after: "Working-rights reviewer assigned · Fran K." },
    ],
    activity: { tone: "ink", title: "Approved credential renewal plan", body: "6 drafts sent. Tracking on Compliance page." },
  },
];

// Leave requests — awaiting approval / upcoming.
const LEAVE_REQUESTS = [
  { id: "L-201", personId: "E-1088", type: "Annual",    start: "2026-04-22", end: "2026-04-28", days: 5, status: "pending", reason: "Family holiday · booked 6 weeks ago", rosterImpact: "1 PM shift affected" },
  { id: "L-202", personId: "E-1402", type: "Sick",      start: "2026-04-17", end: "2026-04-17", days: 1, status: "pending", reason: "Medical certificate uploaded",        rosterImpact: "Day shift · NuCo filled from internal pool" },
  { id: "L-203", personId: "E-1310", type: "Personal",  start: "2026-04-19", end: "2026-04-19", days: 1, status: "pending", reason: "Carer's leave — parent",               rosterImpact: "Night shift needs cover" },
  { id: "L-204", personId: "E-1042", type: "Annual",    start: "2026-05-12", end: "2026-05-19", days: 6, status: "approved",reason: "Pre-approved · booked Feb",            rosterImpact: "Roster locked ±2w ahead" },
  { id: "L-205", personId: "E-1517", type: "Long service", start: "2026-06-01", end: "2026-06-28", days: 20, status: "approved", reason: "20yr LSL entitlement",            rosterImpact: "Successor rostered" },
  { id: "L-206", personId: "E-1131", type: "Unpaid",    start: "2026-04-24", end: "2026-04-24", days: 1, status: "pending", reason: "Personal · no certificate",            rosterImpact: "Covered by agency swap" },
];

const LEAVE_BALANCES = [
  { personId: "E-1042", annual: 18.4, sick: 7.0, personal: 3.0, lsl: 4.2 },
  { personId: "E-1088", annual: 12.1, sick: 5.5, personal: 2.0, lsl: 0.9 },
  { personId: "E-1131", annual: 9.6,  sick: 6.2, personal: 3.0, lsl: 0.2 },
  { personId: "E-1205", annual: 22.8, sick: 8.0, personal: 3.0, lsl: 6.1 },
  { personId: "E-1310", annual: 14.2, sick: 4.0, personal: 2.5, lsl: 1.4 },
  { personId: "E-1402", annual: 6.8,  sick: 3.1, personal: 1.0, lsl: 0.0 },
  { personId: "E-1517", annual: 28.0, sick: 10.0,personal: 3.0, lsl: 12.5 },
  { personId: "E-1602", annual: 4.2,  sick: 2.5, personal: 1.0, lsl: 0.0 },
];

// Agencies — for the direct-engage-agency flow on open shifts.
const AGENCIES = [
  { id: "AG-MED", name: "Medacs Healthcare",  tone: "amber", rate: 78.5, fill: "2h avg", rating: 4.6, note: "Existing preferred supplier" },
  { id: "AG-HEX", name: "HealthX Nursing",    tone: "ink",   rate: 71.0, fill: "3h avg", rating: 4.3, note: "Competitive rate · new supplier" },
  { id: "AG-NCO", name: "Nursing Co",         tone: "sage",  rate: 74.2, fill: "90 min avg", rating: 4.8, note: "Highest local reliability" },
];

// Regulatory bundles for the Submit-now flow on Compliance → Regulatory.
const REGULATORY_BUNDLES = [
  {
    id: "RB-SIRS-Q2",
    title: "SIRS Q2 2026 · Priority 1/2 report",
    body: "Zero notifiable incidents this quarter. Bundle includes incident register, investigation notes, and attestation.",
    due: "30 Jun 2026",
    readiness: 1.0,
    items: [
      { name: "Incident register",            state: "ok" },
      { name: "Investigation notes",          state: "ok" },
      { name: "Attestation signed (Facility Manager)", state: "ok" },
      { name: "ATO / portal endpoint verified", state: "ok" },
    ],
  },
  {
    id: "RB-ACQS",
    title: "Aged Care Quality Standards · evidence bundle",
    body: "Evidence required for upcoming QSC audit. 4 documents outstanding — NuCo has drafted replacements awaiting approval.",
    due: "12 Jun 2026",
    readiness: 0.91,
    items: [
      { name: "Resident feedback summary",    state: "ok" },
      { name: "Clinical governance minutes",  state: "ok" },
      { name: "Restrictive practice register",state: "warn" },
      { name: "Consumer experience report",   state: "warn" },
      { name: "Workforce planning evidence",  state: "warn" },
      { name: "Continuous improvement log",   state: "warn" },
    ],
  },
  {
    id: "RB-AHPRA",
    title: "AHPRA registry sync attestation",
    body: "Monthly sync attestation. All 41 registrations verified hourly against the public register.",
    due: "28 Apr 2026",
    readiness: 1.0,
    items: [
      { name: "Hourly sync uptime log",       state: "ok" },
      { name: "Registration discrepancy log", state: "ok" },
      { name: "Attestation signed (DoN)",     state: "ok" },
    ],
  },
];

// Seed audit events — the human record of actions across the system.
// New entries are prepended via reducer logging whenever the user performs an action.
const AUDIT_EVENTS = [
  { id: "EV-9001", ts: "2026-04-17 04:12", actor: "NuCo",         module: "Roster",     action: "Filled sick call-out",          detail: "Grace Whitford · 07:00–15:00 Grevillea · avoided $412 agency cost", tone: "ok" },
  { id: "EV-9000", ts: "2026-04-17 03:28", actor: "NuCo",         module: "Compliance", action: "Held 3 shifts",                 detail: "Lachlan F. · AHPRA expired 12 Apr",                                   tone: "block" },
  { id: "EV-8999", ts: "2026-04-17 02:48", actor: "NuCo",         module: "HR",         action: "Drafted 4 credential renewals", detail: "First Aid renewals · Olamide A., Terence P., Mei L., Chloé D.",        tone: "ok" },
  { id: "EV-8998", ts: "2026-04-17 01:30", actor: "NuCo",         module: "Roster",     action: "Flagged ratio risk",            detail: "Banksia night shift Fri 24 Apr · 1 internal + 1 agency option",       tone: "warn" },
  { id: "EV-8997", ts: "2026-04-16 22:02", actor: "jess.palmer",  module: "Payroll",    action: "Approved 18 timesheets",        detail: "Wattle · period 2026-04-04 to 2026-04-17",                             tone: "ok" },
  { id: "EV-8996", ts: "2026-04-16 16:41", actor: "NuCo",         module: "Payroll",    action: "Reconciled 142 timesheets",     detail: "0 disputes · 7 held for manual approval",                              tone: "ok" },
  { id: "EV-8995", ts: "2026-04-15 09:00", actor: "ops.lead",     module: "HR",         action: "Onboarded new EN",              detail: "Grace Whitford · Grevillea",                                           tone: "ok" },
  { id: "EV-8994", ts: "2026-04-14 11:24", actor: "NuCo",         module: "Compliance", action: "Synced AHPRA registry",         detail: "41 of 41 verified · 1 discrepancy flagged",                            tone: "ok" },
];

// Reports — scheduled, recent, categories, featured metrics.
const REPORT_CATEGORIES = [
  { key: "workforce",   label: "Workforce",     icon: "users",    count: 9,  desc: "Headcount, turnover, agency vs internal mix, FTE"           },
  { key: "labour",      label: "Labour cost",   icon: "coin",     count: 7,  desc: "Cost per bed, overtime, agency spend, award leakage"         },
  { key: "compliance",  label: "Compliance",    icon: "shield",   count: 11, desc: "AHPRA currency, credential expiries, audit evidence bundles" },
  { key: "payroll",     label: "Payroll",       icon: "trend",    count: 6,  desc: "Earnings, super, PAYG, deductions, YTD reconciliations"      },
  { key: "regulatory",  label: "Regulatory",    icon: "eye",      count: 8,  desc: "AN-ACC, 24/7 RN, care minutes, SIRS, quality indicators"     },
  { key: "ops",         label: "Operational",   icon: "calendar", count: 5,  desc: "Ratio adherence, roster efficiency, open-shift fill rate"     },
];

const SCHEDULED_REPORTS = [
  { id: "R-S01", name: "Weekly workforce roll-up",           cadence: "Every Monday 07:00",   audience: "Exec team (4)",        owner: "NuCo", next: "Mon 20 Apr", lastRun: "Mon 13 Apr",  status: "ok"   },
  { id: "R-S02", name: "Payroll reconciliation · period",    cadence: "End of pay period",    audience: "Finance, HR (6)",      owner: "NuCo", next: "Fri 17 Apr 17:00", lastRun: "Fri 03 Apr",  status: "ok"   },
  { id: "R-S03", name: "Compliance posture · daily",         cadence: "Daily 06:00",          audience: "Facility managers (8)", owner: "NuCo", next: "Tomorrow 06:00",   lastRun: "Today 06:00",  status: "ok"   },
  { id: "R-S04", name: "AN-ACC care minutes attestation",    cadence: "Monthly",              audience: "DoN + Board",          owner: "NuCo", next: "01 May",          lastRun: "01 Apr",       status: "warn" },
  { id: "R-S05", name: "SIRS quarterly readiness",           cadence: "Quarterly",            audience: "Compliance mgr",       owner: "NuCo", next: "30 Jun",          lastRun: "30 Mar",       status: "ok"   },
  { id: "R-S06", name: "Board pack · labour & risk",         cadence: "Monthly 5th",          audience: "Board (6)",            owner: "jess.palmer", next: "05 May",  lastRun: "05 Apr",       status: "ok"   },
];

const RECENT_REPORTS = [
  { id: "R-2041", name: "Agency spend · Wattlegrove Q1 2026",       generated: "17 Apr 06:14", by: "NuCo",        format: "PDF · 14 pages", downloads: 12, category: "labour"     },
  { id: "R-2040", name: "Credential expiries · next 90d",           generated: "17 Apr 06:00", by: "NuCo",        format: "XLSX",          downloads: 3,  category: "compliance" },
  { id: "R-2039", name: "Pay run preview · 2026-04-04 → 17",         generated: "16 Apr 22:11", by: "jess.palmer", format: "PDF",           downloads: 8,  category: "payroll"    },
  { id: "R-2038", name: "24/7 RN compliance · Banksia last 30d",    generated: "16 Apr 18:02", by: "NuCo",        format: "PDF",           downloads: 4,  category: "regulatory" },
  { id: "R-2037", name: "Open-shift fill-rate · all facilities",    generated: "16 Apr 12:40", by: "NuCo",        format: "XLSX",          downloads: 7,  category: "ops"        },
  { id: "R-2036", name: "Workforce headcount · March movements",    generated: "15 Apr 09:22", by: "ops.lead",    format: "PDF · 22 pages", downloads: 11, category: "workforce"  },
  { id: "R-2035", name: "Allowance leakage · SCHADS audit",         generated: "14 Apr 11:00", by: "NuCo",        format: "XLSX",          downloads: 2,  category: "payroll"    },
  { id: "R-2034", name: "Care minutes vs target · Kookaburra",      generated: "14 Apr 08:15", by: "NuCo",        format: "PDF",           downloads: 6,  category: "regulatory" },
];

const REPORT_METRICS = [
  { label: "Reports auto-generated / month",  value: "184",   delta: "+12 vs last mo",    tone: "up"   },
  { label: "Board-ready evidence bundles",    value: "28",    delta: "3 lodged this wk",  tone: "up"   },
  { label: "Avg time-to-audit",               value: "6 min", delta: "−42% vs last yr",   tone: "up"   },
  { label: "Data sources in live sync",       value: "17",    delta: "All green",         tone: "up"   },
];

// Agents — each module has a named agent with a Gartner-style tier + guardrails.
// Tiers: L1 Shadow (observe only), L2 Suggest (drafts), L3 Act w/ approval, L4 Autonomous-with-limits.
const AGENTS = [
  {
    id: "AG-ROSTER",
    name: "Roster Agent",
    icon: "calendar",
    tier: "L3",
    scope: ["Roster", "Shifts", "Agency requests"],
    approver: "Jess Palmer · Roster Coordinator",
    confidence: 0.94,
    confidenceTrend: [0.86, 0.88, 0.90, 0.91, 0.93, 0.94, 0.94],
    actions24h: 6,
    pending: 2,
    lastAction: "Proposed Banksia night fill · awaiting your approval",
    guardrails: [
      { rule: "Cannot assign a shift if credential check fails", tone: "block" },
      { rule: "Must request approval for agency fills > $500",   tone: "warn" },
      { rule: "Max 3 changes per roster per run",                 tone: "warn" },
      { rule: "No consecutive double-shifts without consent",     tone: "ok" },
      { rule: "Ratio adherence: block any below SCHADS minimum",  tone: "block" },
    ],
  },
  {
    id: "AG-PAYROLL",
    name: "Payroll Agent",
    icon: "coin",
    tier: "L4",
    scope: ["Timesheets", "Award interp", "Reconciliation"],
    approver: "Finance (delegated) · Kevin Brooks",
    confidence: 0.97,
    confidenceTrend: [0.95, 0.96, 0.96, 0.96, 0.97, 0.97, 0.97],
    actions24h: 142,
    pending: 0,
    lastAction: "Auto-resolved 18 timesheet exceptions · $1,840 penalty correctly applied",
    guardrails: [
      { rule: "Blocks release for any employee failing compliance gate", tone: "block" },
      { rule: "Autonomous within SCHADS 2010 interpretation only",        tone: "ok" },
      { rule: "Escalates any single impact > $500",                        tone: "warn" },
      { rule: "Cannot release pay without STP lodgement readiness",        tone: "block" },
    ],
  },
  {
    id: "AG-COMPLIANCE",
    name: "Compliance Agent",
    icon: "shield",
    tier: "L3",
    scope: ["AHPRA sync", "Credential monitoring", "Regulatory bundles"],
    approver: "Andrew Cox · DoN",
    confidence: 0.98,
    confidenceTrend: [0.95, 0.96, 0.97, 0.97, 0.98, 0.98, 0.98],
    actions24h: 41,
    pending: 1,
    lastAction: "Lodgement bundle drafted for SIRS Q2 · 100% ready",
    guardrails: [
      { rule: "Cannot auto-lodge regulatory submissions — always requires human sign-off", tone: "block" },
      { rule: "Syncs hourly against public registers only",                                  tone: "ok" },
      { rule: "Flag-only for Visa 482 holders — never block unilaterally",                   tone: "warn" },
    ],
  },
  {
    id: "AG-LEAVE",
    name: "Leave Agent",
    icon: "clock",
    tier: "L3",
    scope: ["Parse requests", "Apply award rules", "Draft approval or escalate"],
    approver: "Jess Palmer · Roster Coordinator",
    confidence: 0.91,
    confidenceTrend: [0.85, 0.86, 0.87, 0.88, 0.90, 0.91, 0.91],
    actions24h: 8,
    pending: 2,
    lastAction: "Parsed 'I need Thursday off' → Personal leave · 1d · auto-covered",
    guardrails: [
      { rule: "Single-day personal leave: auto-approve if balance > 0 and notice > 2h",      tone: "ok" },
      { rule: "Multi-day: always escalate to roster coordinator",                              tone: "warn" },
      { rule: "Sick leave > 2 consecutive days: require medical certificate",                  tone: "warn" },
      { rule: "Never override legislative minimums (NES)",                                     tone: "block" },
    ],
  },
  {
    id: "AG-COPILOT",
    name: "Copilot",
    icon: "sparkle",
    tier: "L2",
    scope: ["Conversation", "Insights", "Drafts"],
    approver: "n/a — advisory only",
    confidence: 0.88,
    confidenceTrend: [0.80, 0.82, 0.84, 0.85, 0.86, 0.88, 0.88],
    actions24h: 27,
    pending: 0,
    lastAction: "Drafted board pack talking points for Wattlegrove",
    guardrails: [
      { rule: "Never takes action on user's behalf without explicit confirmation", tone: "block" },
      { rule: "Always cites the live state it reasoned over",                        tone: "ok" },
      { rule: "Falls back to human if confidence < 70%",                               tone: "warn" },
    ],
  },
];

// Data sources — the Datalake surface. Each is a live integration NuCo reasons over.
const DATA_SOURCES = [
  { id: "DS-AHPRA",  name: "AHPRA public register",     type: "Regulatory", mode: "Hourly pull",  records: "41",      freshness: "4 min ago", health: "ok",    direction: "in",  note: "Credential currency + AHPRA number match" },
  { id: "DS-VEVO",   name: "Home Affairs VEVO",         type: "Regulatory", mode: "Hourly pull",  records: "24",      freshness: "11 min ago", health: "ok",    direction: "in",  note: "Visa conditions + working rights" },
  { id: "DS-ATO",    name: "ATO · STP lodgement",       type: "Finance",    mode: "Event push",   records: "14 lodgements", freshness: "Last period",  health: "ok",    direction: "out", note: "Single Touch Payroll submissions" },
  { id: "DS-HESTA",  name: "HESTA · super fund",        type: "Finance",    mode: "Daily reconcile", records: "122",     freshness: "Today 06:00", health: "ok",    direction: "out", note: "Employee super contributions" },
  { id: "DS-SCHADS", name: "Fair Work · SCHADS 2010",   type: "Regulatory", mode: "Published rule-set", records: "1 rule-set", freshness: "v2026.3",  health: "ok",    direction: "in",  note: "Award interpretation source of truth" },
  { id: "DS-XERO",   name: "Xero · GL mapping",         type: "Finance",    mode: "Daily reconcile", records: "5 cost centres", freshness: "Today 06:00", health: "ok",    direction: "both", note: "Cost centre + GL posting" },
  { id: "DS-M365",   name: "Microsoft 365 · identity",  type: "HR",         mode: "Real-time SCIM", records: "143",     freshness: "Live",         health: "ok",    direction: "in",  note: "Joiners / movers / leavers" },
  { id: "DS-ROST",   name: "Rostering event bus",       type: "HR",         mode: "Real-time",    records: "1,912 events", freshness: "Live",          health: "ok",    direction: "both", note: "Clock events · shift mutations" },
  { id: "DS-CARE",   name: "CarePro · resident mgmt",   type: "Clinical",   mode: "Hourly pull",  records: "156 residents", freshness: "22 min ago",   health: "warn",  direction: "in",  note: "Resident demographics + acuity · sync delayed" },
  { id: "DS-AUSCK",  name: "AusCheck · police check",   type: "Regulatory", mode: "Weekly pull",  records: "95",      freshness: "Mon 13 Apr",  health: "ok",    direction: "in",  note: "NPC expiry + renewal flagging" },
  { id: "DS-NDIS",   name: "NDIS worker screening",     type: "Regulatory", mode: "Weekly pull",  records: "61",      freshness: "Tue 14 Apr",  health: "ok",    direction: "in",  note: "Worker screening currency" },
  { id: "DS-MYOB",   name: "MYOB · legacy payroll",     type: "Finance",    mode: "Migration",    records: "Archive",  freshness: "Frozen 31 Mar", health: "ok",    direction: "in",  note: "Historical pay data · read-only" },
];

Object.assign(window, {
  FACILITY, FACILITIES, STAFF, EXCEPTIONS, AGENT_ACTIVITY, KPIS, MODULES, ROSTER_ROWS, COMPLIANCE, PAYROLL, spark,
  PAYROLL_OPEN, PAYROLL_AUTO_INITIAL, EXPIRIES, AI_PLANS,
  LEAVE_REQUESTS, LEAVE_BALANCES, AGENCIES, REGULATORY_BUNDLES, AUDIT_EVENTS,
  REPORT_CATEGORIES, SCHEDULED_REPORTS, RECENT_REPORTS, REPORT_METRICS,
  AGENTS, DATA_SOURCES,
});
