@burdenoff/microfe-movethewheels 2026.1107.4 → 2026.1107.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,411 @@
1
+ import { GitCompare as e } from "../node_modules/lucide-react/dist/esm/icons/git-compare.js";
2
+ import { Plus as t } from "../node_modules/lucide-react/dist/esm/icons/plus.js";
3
+ import { Trash2 as n } from "../node_modules/lucide-react/dist/esm/icons/trash-2.js";
4
+ import { TriangleAlert as r } from "../node_modules/lucide-react/dist/esm/icons/triangle-alert.js";
5
+ import { Truck as i } from "../node_modules/lucide-react/dist/esm/icons/truck.js";
6
+ import { formatCurrency as a } from "../utils/formatters.js";
7
+ import { Badge as o, Button as s, Card as c, CardContent as l, CardDescription as u, CardHeader as d, CardTitle as f, Checkbox as p, Input as m, Label as h, Skeleton as g, Table as _, TableBody as v, TableCell as y, TableHead as b, TableHeader as x, TableRow as S, Tabs as C, TabsContent as w, TabsList as T, TabsTrigger as E } from "./ui.js";
8
+ import { FormError as D } from "./FormError.js";
9
+ import { DEFAULT_REQUEST as O, useScenarioPlanning as k } from "../hooks/useScenarioPlanning.js";
10
+ import { useMemo as A, useState as j } from "react";
11
+ import { Fragment as M, jsx as N, jsxs as P } from "react/jsx-runtime";
12
+ //#region src/movethewheels/components/ScenarioPlanningPanel.tsx
13
+ var F = 4, I = -100, L = 500, R = 80, z = 4, B = (e, t = 1) => Number.isInteger(e) ? String(e) : e.toFixed(t), V = (e) => e > 0 ? `+${e}` : String(e), H = (e) => e === null ? "—" : `${Math.round(e * 100)}%`, U = (e) => e.trim() === "" ? 0 : Number(e), W = 0, G = ({ demandChangePct: e, capacityChangePct: t, ...n }) => (W += 1, {
14
+ ...n,
15
+ uid: W,
16
+ demandText: String(e),
17
+ capacityText: String(t)
18
+ }), K = ({ uid: e, demandText: t, capacityText: n, ...r }) => ({
19
+ ...r,
20
+ demandChangePct: U(t),
21
+ capacityChangePct: U(n)
22
+ });
23
+ function q(e) {
24
+ if (e.jobsPerVehiclePerWeek !== null && (!Number.isFinite(e.jobsPerVehiclePerWeek) || e.jobsPerVehiclePerWeek <= 0 || e.jobsPerVehiclePerWeek > 1e3)) return "Jobs per vehicle per week must be greater than 0 and at most 1000.";
25
+ let t = /* @__PURE__ */ new Set();
26
+ for (let [n, r] of e.scenarios.entries()) {
27
+ let e = r.name.trim();
28
+ if (e.length === 0 || e.length > R) return `Scenario ${n + 1} needs a name of 1 to ${R} characters.`;
29
+ if (t.has(e.toLowerCase())) return `Scenario names must be unique; "${e}" is used twice.`;
30
+ if (e.toLowerCase() === "baseline") return "\"Baseline\" is the unchanged forecast; give the scenario another name.";
31
+ t.add(e.toLowerCase());
32
+ for (let t of [r.demandChangePct, r.capacityChangePct]) if (!Number.isFinite(t) || t < I || t > L) return `Changes in "${e}" must be percentages between ${I} and ${L}.`;
33
+ }
34
+ return null;
35
+ }
36
+ function J(e) {
37
+ if (e.weeklyFleetCapacity === null || e.jobsPerVehiclePerWeek === null) return `${e.activeVehicles} available vehicles. No vehicle-assigned jobs in the last 12 weeks, so capacity is unknown: enter jobs per vehicle per week to compare against it.`;
38
+ let t = e.source === "OVERRIDE" ? "as entered" : `observed on ${e.observedVehicles} vehicle${e.observedVehicles === 1 ? "" : "s"} (busiest week, median)`, n = e.laneShareBasis === "DEMAND_SHARE" ? " Lane capacity follows each lane’s share of forecast demand." : e.laneShareBasis === "VEHICLE_HISTORY" ? " Lane capacity follows where vehicles ran in the last 12 weeks." : "";
39
+ return `${e.activeVehicles} available vehicles × ${B(e.jobsPerVehiclePerWeek)} jobs/vehicle/week (${t}) = ${B(e.weeklyFleetCapacity)} jobs/week.${n}`;
40
+ }
41
+ function Y() {
42
+ let { comparison: n, isLoading: r, error: a, run: o } = k(O), [p, _] = j(String(O.weeks)), [v, y] = j(""), [b, x] = j(() => O.scenarios.map(G)), [S, C] = j(null), w = A(() => (n?.baseline.lanes ?? []).map((e) => ({
43
+ key: e.laneKey,
44
+ label: e.laneLabel
45
+ })).sort((e, t) => e.label.localeCompare(t.label)), [n]), T = (e, t) => {
46
+ x((n) => n.map((n, r) => r === e ? {
47
+ ...n,
48
+ ...t
49
+ } : n));
50
+ }, E = (e, t, n) => {
51
+ x((r) => r.map((r, i) => {
52
+ if (i !== e) return r;
53
+ let a = r.closedLanes.filter((e) => e !== t);
54
+ return {
55
+ ...r,
56
+ closedLanes: n ? [...a, t] : a
57
+ };
58
+ }));
59
+ };
60
+ return /* @__PURE__ */ P(c, {
61
+ "data-testid": "scenario-planning-panel",
62
+ children: [/* @__PURE__ */ P(d, { children: [/* @__PURE__ */ P(f, {
63
+ className: "flex items-center gap-2",
64
+ children: [/* @__PURE__ */ N(e, {
65
+ size: 18,
66
+ "aria-hidden": "true"
67
+ }), "Scenario planning (S&OP)"]
68
+ }), /* @__PURE__ */ N(u, { children: "Try what-if changes on the lane forecast — demand up or down, lanes closed, fleet added or removed — and compare them side by side against your fleet capacity." })] }), /* @__PURE__ */ P(l, {
69
+ className: "space-y-6",
70
+ children: [
71
+ n && /* @__PURE__ */ P("div", {
72
+ className: "flex items-start gap-2 rounded-lg border border-border/60 bg-muted/40 p-4 text-sm text-text-secondary",
73
+ children: [/* @__PURE__ */ N(i, {
74
+ size: 16,
75
+ "aria-hidden": "true",
76
+ className: "mt-0.5 shrink-0"
77
+ }), /* @__PURE__ */ N("p", {
78
+ "data-testid": "scenario-capacity-basis",
79
+ children: J(n.capacity)
80
+ })]
81
+ }),
82
+ /* @__PURE__ */ P("div", {
83
+ className: "grid grid-cols-1 sm:grid-cols-2 gap-4",
84
+ children: [/* @__PURE__ */ P("div", {
85
+ className: "space-y-1.5",
86
+ children: [/* @__PURE__ */ N(h, {
87
+ htmlFor: "scenario-weeks",
88
+ children: "Weeks to compare"
89
+ }), /* @__PURE__ */ N(m, {
90
+ id: "scenario-weeks",
91
+ type: "number",
92
+ min: 1,
93
+ max: z,
94
+ value: p,
95
+ onChange: (e) => _(e.target.value)
96
+ })]
97
+ }), /* @__PURE__ */ P("div", {
98
+ className: "space-y-1.5",
99
+ children: [/* @__PURE__ */ N(h, {
100
+ htmlFor: "scenario-throughput",
101
+ children: "Jobs per vehicle per week"
102
+ }), /* @__PURE__ */ N(m, {
103
+ id: "scenario-throughput",
104
+ type: "number",
105
+ min: 0,
106
+ step: "0.5",
107
+ placeholder: "Observed from history",
108
+ value: v,
109
+ onChange: (e) => y(e.target.value)
110
+ })]
111
+ })]
112
+ }),
113
+ /* @__PURE__ */ N("div", {
114
+ className: "grid grid-cols-1 md:grid-cols-2 gap-4",
115
+ children: b.map((e, t) => /* @__PURE__ */ N(X, {
116
+ index: t,
117
+ draft: e,
118
+ lanes: w,
119
+ onChange: (e) => T(t, e),
120
+ onToggleLane: (e, n) => E(t, e, n),
121
+ onRemove: () => x((e) => e.filter((e, n) => n !== t))
122
+ }, e.uid))
123
+ }),
124
+ /* @__PURE__ */ N(D, { message: S }),
125
+ /* @__PURE__ */ P("div", {
126
+ className: "flex flex-wrap gap-2",
127
+ children: [/* @__PURE__ */ P(s, {
128
+ type: "button",
129
+ variant: "outline",
130
+ onClick: () => {
131
+ x((e) => {
132
+ let t = new Set(e.map((e) => e.name.trim().toLowerCase())), n = e.length + 1;
133
+ for (; t.has(`scenario ${n}`);) n += 1;
134
+ return [...e, G({
135
+ name: `Scenario ${n}`,
136
+ demandChangePct: 0,
137
+ capacityChangePct: 0,
138
+ closedLanes: [],
139
+ laneAdjustments: []
140
+ })];
141
+ });
142
+ },
143
+ disabled: b.length >= F,
144
+ children: [/* @__PURE__ */ N(t, {
145
+ size: 16,
146
+ "aria-hidden": "true",
147
+ className: "mr-1"
148
+ }), "Add scenario"]
149
+ }), /* @__PURE__ */ P(s, {
150
+ type: "button",
151
+ onClick: () => {
152
+ let e = Math.min(z, Math.max(1, Math.round(U(p) || z))), t = {
153
+ weeks: e,
154
+ jobsPerVehiclePerWeek: v.trim() === "" ? null : Number(v),
155
+ scenarios: b.map(K)
156
+ }, n = q(t);
157
+ C(n), !n && (_(String(e)), o(t));
158
+ },
159
+ disabled: r,
160
+ children: [/* @__PURE__ */ N(e, {
161
+ size: 16,
162
+ "aria-hidden": "true",
163
+ className: "mr-1"
164
+ }), r ? "Comparing…" : "Compare scenarios"]
165
+ })]
166
+ }),
167
+ a && !r && /* @__PURE__ */ N(D, { message: `Couldn't compare scenarios: ${a.message}` }),
168
+ r && !n && /* @__PURE__ */ P("div", {
169
+ className: "space-y-3",
170
+ children: [/* @__PURE__ */ N(g, { className: "h-10 w-full" }), /* @__PURE__ */ N(g, { className: "h-40 w-full" })]
171
+ }),
172
+ n && n.baseline.lanes.length === 0 && /* @__PURE__ */ N("p", {
173
+ className: "rounded-lg border border-border/60 p-4 text-sm text-text-secondary",
174
+ children: "No lane forecast yet. Scenarios apply to the lanes your delivery jobs ran on in the last 12 weeks."
175
+ }),
176
+ n && n.baseline.lanes.length > 0 && /* @__PURE__ */ P(M, { children: [/* @__PURE__ */ N(Z, { results: [n.baseline, ...n.scenarios] }), /* @__PURE__ */ N($, { results: [n.baseline, ...n.scenarios] })] })
177
+ ]
178
+ })]
179
+ });
180
+ }
181
+ function X({ index: e, draft: t, lanes: r, onChange: i, onToggleLane: a, onRemove: o }) {
182
+ let c = `scenario-${e}`;
183
+ return /* @__PURE__ */ P("fieldset", {
184
+ className: "space-y-3 rounded-lg border border-border/60 p-4",
185
+ "aria-label": `Scenario ${e + 1}`,
186
+ children: [
187
+ /* @__PURE__ */ P("div", {
188
+ className: "flex items-end gap-2",
189
+ children: [/* @__PURE__ */ P("div", {
190
+ className: "flex-1 space-y-1.5",
191
+ children: [/* @__PURE__ */ N(h, {
192
+ htmlFor: `${c}-name`,
193
+ children: "Scenario name"
194
+ }), /* @__PURE__ */ N(m, {
195
+ id: `${c}-name`,
196
+ value: t.name,
197
+ maxLength: R,
198
+ onChange: (e) => i({ name: e.target.value })
199
+ })]
200
+ }), /* @__PURE__ */ N(s, {
201
+ type: "button",
202
+ variant: "ghost",
203
+ size: "icon",
204
+ "aria-label": `Remove ${t.name || `scenario ${e + 1}`}`,
205
+ onClick: o,
206
+ children: /* @__PURE__ */ N(n, {
207
+ size: 16,
208
+ "aria-hidden": "true"
209
+ })
210
+ })]
211
+ }),
212
+ /* @__PURE__ */ P("div", {
213
+ className: "grid grid-cols-2 gap-3",
214
+ children: [/* @__PURE__ */ P("div", {
215
+ className: "space-y-1.5",
216
+ children: [/* @__PURE__ */ N(h, {
217
+ htmlFor: `${c}-demand`,
218
+ children: "Demand change %"
219
+ }), /* @__PURE__ */ N(m, {
220
+ id: `${c}-demand`,
221
+ type: "number",
222
+ min: I,
223
+ max: L,
224
+ value: t.demandText,
225
+ onChange: (e) => i({ demandText: e.target.value })
226
+ })]
227
+ }), /* @__PURE__ */ P("div", {
228
+ className: "space-y-1.5",
229
+ children: [/* @__PURE__ */ N(h, {
230
+ htmlFor: `${c}-capacity`,
231
+ children: "Capacity change %"
232
+ }), /* @__PURE__ */ N(m, {
233
+ id: `${c}-capacity`,
234
+ type: "number",
235
+ min: I,
236
+ max: L,
237
+ value: t.capacityText,
238
+ onChange: (e) => i({ capacityText: e.target.value })
239
+ })]
240
+ })]
241
+ }),
242
+ r.length > 0 && /* @__PURE__ */ P("div", {
243
+ className: "space-y-2",
244
+ children: [/* @__PURE__ */ N("p", {
245
+ className: "text-sm font-medium",
246
+ children: "Close lanes"
247
+ }), /* @__PURE__ */ N("div", {
248
+ className: "max-h-36 space-y-2 overflow-y-auto pr-1",
249
+ children: r.map((e) => {
250
+ let n = `${c}-close-${e.key}`;
251
+ return /* @__PURE__ */ P("div", {
252
+ className: "flex items-center gap-2",
253
+ children: [/* @__PURE__ */ N(p, {
254
+ id: n,
255
+ checked: t.closedLanes.includes(e.key),
256
+ onCheckedChange: (t) => a(e.key, t === !0)
257
+ }), /* @__PURE__ */ N(h, {
258
+ htmlFor: n,
259
+ className: "truncate text-sm font-normal",
260
+ title: e.label,
261
+ children: e.label
262
+ })]
263
+ }, e.key);
264
+ })
265
+ })]
266
+ })
267
+ ]
268
+ });
269
+ }
270
+ function Z({ results: e }) {
271
+ return /* @__PURE__ */ P("div", {
272
+ className: "overflow-x-auto",
273
+ "data-testid": "scenario-comparison-table",
274
+ children: [/* @__PURE__ */ P(_, { children: [/* @__PURE__ */ N(x, { children: /* @__PURE__ */ P(S, { children: [/* @__PURE__ */ N(b, { children: "Metric" }), e.map((e) => /* @__PURE__ */ N(b, {
275
+ className: "text-right",
276
+ children: e.name
277
+ }, e.name))] }) }), /* @__PURE__ */ N(v, { children: [
278
+ {
279
+ label: "Forecast jobs",
280
+ value: (e) => String(e.totalVolume)
281
+ },
282
+ {
283
+ label: "vs baseline",
284
+ value: (e) => V(e.volumeDelta)
285
+ },
286
+ {
287
+ label: "Revenue",
288
+ value: (e) => a(e.totalRevenue)
289
+ },
290
+ {
291
+ label: "Jobs lost to closed lanes",
292
+ value: (e) => String(e.lostVolume)
293
+ },
294
+ {
295
+ label: "Fleet capacity (jobs)",
296
+ value: (e) => e.totalCapacity === null ? "Unknown" : B(e.totalCapacity)
297
+ },
298
+ {
299
+ label: "Utilisation",
300
+ value: (e) => H(e.utilization)
301
+ },
302
+ {
303
+ label: "Shortfall (jobs)",
304
+ value: (e) => B(e.totalShortfall)
305
+ },
306
+ {
307
+ label: "Lanes short of capacity",
308
+ value: (e) => String(e.shortfallLanes)
309
+ }
310
+ ].map((t) => /* @__PURE__ */ P(S, { children: [/* @__PURE__ */ N(y, {
311
+ className: "font-medium",
312
+ children: t.label
313
+ }), e.map((e) => /* @__PURE__ */ N(y, {
314
+ className: "text-right tabular-nums",
315
+ children: t.value(e)
316
+ }, e.name))] }, t.label)) })] }), e.some((e) => e.unknownLanes.length > 0) && /* @__PURE__ */ N("p", {
317
+ className: "mt-2 text-xs text-text-secondary",
318
+ children: "Some lanes in a scenario have no forecast and were ignored."
319
+ })]
320
+ });
321
+ }
322
+ function Q(e) {
323
+ return e.closed ? /* @__PURE__ */ N(o, {
324
+ variant: "secondary",
325
+ children: "Closed"
326
+ }) : e.flagged ? /* @__PURE__ */ P(o, {
327
+ variant: "destructive",
328
+ className: "inline-flex items-center gap-1",
329
+ children: [/* @__PURE__ */ N(r, {
330
+ size: 12,
331
+ "aria-hidden": "true"
332
+ }), "Short"]
333
+ }) : e.capacity === null ? /* @__PURE__ */ N(o, {
334
+ variant: "outline",
335
+ children: "No fleet share"
336
+ }) : /* @__PURE__ */ N(o, {
337
+ variant: "outline",
338
+ children: "OK"
339
+ });
340
+ }
341
+ function $({ results: e }) {
342
+ let [t, n] = j(e[0]?.name ?? ""), r = e.some((e) => e.name === t) ? t : e[0]?.name ?? "";
343
+ return /* @__PURE__ */ P("div", {
344
+ className: "space-y-3",
345
+ "data-testid": "scenario-lane-breakdown",
346
+ children: [/* @__PURE__ */ N("p", {
347
+ className: "text-sm font-medium",
348
+ children: "Capacity vs demand by lane"
349
+ }), /* @__PURE__ */ P(C, {
350
+ value: r,
351
+ onValueChange: n,
352
+ children: [/* @__PURE__ */ N(T, {
353
+ className: "flex-wrap h-auto",
354
+ children: e.map((e) => /* @__PURE__ */ P(E, {
355
+ value: e.name,
356
+ children: [e.name, e.shortfallLanes > 0 ? ` (${e.shortfallLanes} short)` : ""]
357
+ }, e.name))
358
+ }), e.map((e) => /* @__PURE__ */ N(w, {
359
+ value: e.name,
360
+ children: /* @__PURE__ */ N("div", {
361
+ className: "overflow-x-auto",
362
+ children: /* @__PURE__ */ P(_, { children: [/* @__PURE__ */ N(x, { children: /* @__PURE__ */ P(S, { children: [
363
+ /* @__PURE__ */ N(b, { children: "Lane" }),
364
+ /* @__PURE__ */ N(b, {
365
+ className: "text-right",
366
+ children: "Baseline jobs"
367
+ }),
368
+ /* @__PURE__ */ N(b, {
369
+ className: "text-right",
370
+ children: "Scenario jobs"
371
+ }),
372
+ /* @__PURE__ */ N(b, {
373
+ className: "text-right",
374
+ children: "Capacity"
375
+ }),
376
+ /* @__PURE__ */ N(b, {
377
+ className: "text-right",
378
+ children: "Shortfall"
379
+ }),
380
+ /* @__PURE__ */ N(b, { children: "Status" })
381
+ ] }) }), /* @__PURE__ */ N(v, { children: e.lanes.map((e) => /* @__PURE__ */ P(S, { children: [
382
+ /* @__PURE__ */ N(y, {
383
+ className: "max-w-56 truncate font-medium",
384
+ title: e.laneLabel,
385
+ children: e.laneLabel
386
+ }),
387
+ /* @__PURE__ */ N(y, {
388
+ className: "text-right tabular-nums",
389
+ children: e.baselineVolume
390
+ }),
391
+ /* @__PURE__ */ N(y, {
392
+ className: "text-right tabular-nums",
393
+ children: e.scenarioVolume
394
+ }),
395
+ /* @__PURE__ */ N(y, {
396
+ className: "text-right tabular-nums",
397
+ children: e.capacity === null ? "—" : B(e.capacity)
398
+ }),
399
+ /* @__PURE__ */ N(y, {
400
+ className: "text-right tabular-nums",
401
+ children: B(e.shortfall)
402
+ }),
403
+ /* @__PURE__ */ N(y, { children: Q(e) })
404
+ ] }, e.laneKey)) })] })
405
+ })
406
+ }, e.name))]
407
+ })]
408
+ });
409
+ }
410
+ //#endregion
411
+ export { Y as ScenarioPlanningPanel };