// admin-state-2.jsx — Part 2 of the back-office mock data: jobs, timecards,
// exceptions, payroll runs, integrations + the AdminProvider context.

// ── Active jobs / projects ───────────────────────────────────
const JOBS = [
  { id: 'JOB-24179', clientId: 'cli-bnsf', projectNumber: 'N-0224.3.014.02', name: 'Mainline Tie Renewal — Cascade Sub', railroad: 'BNSF', subdivision: 'Cascade Sub', mp: '142.3 – 143.1', state: 'WA', start: '2026-05-04', end: '2026-06-12', status: 'active',   billRate: 92.50, foreman: 'D. Reyes',  contractor: 'Northwest Track Construction', rwicIds: ['e-2241', 'e-1907'] },
  { id: 'JOB-24166', clientId: 'cli-bnsf', projectNumber: 'N-0224.3.001.07', name: 'Stampede Sub Welding',                railroad: 'BNSF', subdivision: 'Stampede',    mp: '67.4 – 69.0',   state: 'WA', start: '2026-05-08', end: '2026-06-30', status: 'active',   billRate: 92.50, foreman: 'M. Trujillo', contractor: 'Pacific Rail Welding',           rwicIds: ['e-3025'] },
  { id: 'JOB-24201', clientId: 'cli-uprr', projectNumber: 'U-1188.4.022.03', name: 'Feather River Bridge Repair',         railroad: 'UPRR', subdivision: 'Feather River', mp: '198.0 – 198.3', state: 'CA', start: '2026-05-15', end: '2026-07-30', status: 'active',   billRate: 89.00, foreman: 'A. Vargas', contractor: 'BridgePro West',                 rwicIds: ['e-5512'] },
  { id: 'JOB-24210', clientId: 'cli-uprr', projectNumber: 'U-2030.1.005.11', name: 'Salt Lake Tie Replacement',           railroad: 'UPRR', subdivision: 'Lynndyl',     mp: '744.1 – 745.2', state: 'UT', start: '2026-05-18', end: '2026-06-22', status: 'active',   billRate: 89.00, foreman: 'L. Park',   contractor: 'Lynndyl Track Services',         rwicIds: ['e-7733'] },
  { id: 'JOB-24208', clientId: 'cli-uprr', projectNumber: 'U-3304.2.014.09', name: 'Sierra Sub Switch Repair',            railroad: 'UPRR', subdivision: 'Sierra',      mp: '202.6 – 203.1', state: 'NV', start: '2026-05-12', end: '2026-06-10', status: 'active',   billRate: 89.00, foreman: 'D. Carmona', contractor: 'High Desert Rail',              rwicIds: ['e-8814'] },
  { id: 'JOB-24155', clientId: 'cli-bnsf', projectNumber: 'N-0411.6.008.01', name: 'Hi-Line Curve Resurfacing',           railroad: 'BNSF', subdivision: 'Hi-Line',     mp: '1110.4 – 1112.0', state: 'MT', start: '2026-04-29', end: '2026-05-30', status: 'wrapping', billRate: 92.50, foreman: 'B. Olson', contractor: 'Big Sky Track Co',                rwicIds: ['e-4488'] },
  { id: 'JOB-24225', clientId: 'cli-csx', projectNumber: 'C-1502.1.030.02', name: 'Cumberland Sub Crossing Replace',     railroad: 'CSX',  subdivision: 'Cumberland',  mp: '142.0 – 142.4', state: 'MD', start: '2026-05-20', end: '2026-07-04', status: 'starting', billRate: 94.00, foreman: 'F. Diaz',   contractor: 'Mid-Atlantic Rail',              rwicIds: [] },
];

// ── Timecards (current pay period — week of May 18-22, 2026) ──
// Each record represents an employee's day with multi-state allocation
// where appropriate. Approval state: draft → pending-ops → pending-acct → approved
function genTimecards() {
  const days = ['2026-05-18','2026-05-19','2026-05-20','2026-05-21','2026-05-22'];
  const seed = [
    // Marcus — WA work
    ['e-2241','JOB-24179', [['F10',10.5,'WA']]],
    ['e-2241','JOB-24179', [['F10',11.0,'WA']]],
    ['e-2241','JOB-24179', [['F10', 9.2,'WA']]],
    ['e-2241','JOB-24179', [['F10',10.8,'WA']]],
    ['e-2241','JOB-24179', [['F10', 8.0,'WA'],['V10',0.75,'WA']]],
    // Diana — WA work
    ['e-1907','JOB-24179', [['F10',10.0,'WA']]],
    ['e-1907','JOB-24179', [['F10',10.5,'WA']]],
    ['e-1907','JOB-24179', [['F10',12.2,'WA'],['V10',1.5,'WA']]],
    ['e-1907','JOB-24179', [['F10', 9.0,'WA']]],
    ['e-1907','JOB-24179', [['F10', 9.5,'WA']]],
    // Tomás — multi-state (OR → WA travel)
    ['e-3025','JOB-24166', [['V10',1.2,'OR'],['F10', 9.5,'WA']]],
    ['e-3025','JOB-24166', [['F10',10.0,'WA']]],
    ['e-3025','JOB-24166', [['F10', 8.5,'WA']]],
    ['e-3025','JOB-24166', [['F10', 7.0,'WA'],['V10',2.0,'OR']]],
    ['e-3025','JOB-24166', [['F10', 9.0,'WA']]],
    // Jaylen — MT (wrapping)
    ['e-4488','JOB-24155', [['F30',10.5,'MT']]],
    ['e-4488','JOB-24155', [['F30',12.0,'MT'],['V10',1.0,'MT']]],
    ['e-4488','JOB-24155', [['L30', 8.0,'MT']]],   // sick
    ['e-4488','JOB-24155', [['F30',10.0,'MT']]],
    ['e-4488','JOB-24155', [['F30', 9.5,'MT']]],
    // Priya — CA
    ['e-5512','JOB-24201', [['F10', 9.0,'CA']]],
    ['e-5512','JOB-24201', [['F10',10.5,'CA']]],
    ['e-5512','JOB-24201', [['F10',11.0,'CA']]],
    ['e-5512','JOB-24201', [['F10', 9.5,'CA']]],
    ['e-5512','JOB-24201', [['F10', 8.0,'CA']]],
    // Anita — UT
    ['e-7733','JOB-24210', [['F10', 8.5,'UT']]],
    ['e-7733','JOB-24210', [['F10', 9.0,'UT']]],
    ['e-7733','JOB-24210', [['F10',10.2,'UT']]],
    ['e-7733','JOB-24210', [['F10', 8.0,'UT']]],
    ['e-7733','JOB-24210', [['F10', 9.5,'UT']]],
    // Reuben — NV
    ['e-8814','JOB-24208', [['F10', 9.0,'NV']]],
    ['e-8814','JOB-24208', [['F10', 8.0,'NV']]],
    ['e-8814','JOB-24208', [['F10',10.5,'NV']]],
    ['e-8814','JOB-24208', [['F10', 9.5,'NV']]],
    ['e-8814','JOB-24208', [['F10', 8.5,'NV']]],
  ];
  let i = 0;
  return seed.map((row, idx) => {
    const [empId, jobId, segs] = row;
    const day = days[idx % 5];
    const blocks = segs.map(([code, hrs, state]) => ({ code, hrs, state }));
    const total = blocks.reduce((s, b) => s + b.hrs, 0);
    const reg = Math.min(8, total);
    const ot = Math.max(0, total - 8);
    // Random approval state — most pending, a few approved/rejected
    const statusRoll = (idx * 13 + 7) % 10;
    let status = 'pending-ops';
    if (statusRoll < 1) status = 'rejected';
    else if (statusRoll < 4) status = 'pending-acct';
    else if (statusRoll < 7) status = 'approved';
    return {
      id: `tc-${empId}-${day}`,
      employeeId: empId,
      jobId,
      date: day,
      blocks,
      total,
      regular: reg,
      overtime: ot,
      status,
      submitted: true,
      gpsVerified: true,
      flags: ot > 4 ? ['extreme-ot'] : (idx % 11 === 0 ? ['missing-photo'] : []),
    };
  });
}
const TIMECARDS = genTimecards();

Object.assign(window, { JOBS, TIMECARDS });
