@burdenoff/microfe-movethewheels 2026.1107.2 → 2026.1107.4

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,374 @@
1
+ import { LoaderCircle as e } from "../node_modules/lucide-react/dist/esm/icons/loader-circle.js";
2
+ import { Navigation as t } from "../node_modules/lucide-react/dist/esm/icons/navigation.js";
3
+ import { Plus as n } from "../node_modules/lucide-react/dist/esm/icons/plus.js";
4
+ import { RefreshCw as r } from "../node_modules/lucide-react/dist/esm/icons/refresh-cw.js";
5
+ import { Sparkles as i } from "../node_modules/lucide-react/dist/esm/icons/sparkles.js";
6
+ import { WandSparkles as a } from "../node_modules/lucide-react/dist/esm/icons/wand-sparkles.js";
7
+ import { joinPath as o } from "../utils/navigation.js";
8
+ import { useMoveTheWheels as s } from "../providers/MoveTheWheelsProvider.js";
9
+ import { formatDateTime as c } from "../utils/formatters.js";
10
+ import { Badge as l, Button as u, Card as d, CardContent as f, CardHeader as p, CardTitle as m, Select as h, SelectContent as g, SelectItem as _, SelectTrigger as v, SelectValue as y, Skeleton as b } from "../components/ui.js";
11
+ import { PageLayout as ee } from "../components/PageLayout.js";
12
+ import { FormError as te } from "../components/FormError.js";
13
+ import { Notice as x, useNotice as S } from "../components/Notice.js";
14
+ import { DispatchDecisionCard as C } from "../components/DispatchDecisionCard.js";
15
+ import { useDispatchPlan as ne } from "../hooks/useDispatchPlan.js";
16
+ import { useEffect as re, useMemo as w, useState as T } from "react";
17
+ import { Fragment as E, jsx as D, jsxs as O } from "react/jsx-runtime";
18
+ import { useI18n as ie } from "@burdenoff/fe-libs/shared/providers/shell/I18nProvider";
19
+ import { CTAOverflowMenu as ae, EmphasisPanel as k, PagePurpose as A } from "@burdenoff/fe-libs/ui";
20
+ //#region src/movethewheels/pages/DispatchPlanPage.tsx
21
+ var j = {
22
+ "24h": 24,
23
+ "72h": 72,
24
+ "7d": 168
25
+ }, M = {
26
+ PROPOSED: ["movethewheels.dispatch.status.proposed", "Waiting for your decision"],
27
+ APPLYING: ["movethewheels.dispatch.status.applying", "Applying decisions"],
28
+ APPLIED: ["movethewheels.dispatch.status.applied", "All accepted"],
29
+ PARTIALLY_APPLIED: ["movethewheels.dispatch.status.partiallyApplied", "Partly accepted"],
30
+ REJECTED: ["movethewheels.dispatch.status.rejected", "Rejected — nothing written"],
31
+ EXPIRED: ["movethewheels.dispatch.status.expired", "Expired"]
32
+ }, N = {
33
+ NOT_NEEDED: ["movethewheels.dispatch.ai.notNeeded", "Nothing could be assigned, so there was nothing for AI to explain."],
34
+ AI_DISABLED: ["movethewheels.dispatch.ai.disabled", "AI explanations are switched off. The rule-based rationale below is complete."],
35
+ CREDITS_EXHAUSTED: ["movethewheels.dispatch.ai.creditsExhausted", "This workspace has used its MoveTheWheels AI credits, so no AI explanation was written. The proposal and its rule-based rationale are unaffected."],
36
+ DAILY_CAP_REACHED: ["movethewheels.dispatch.ai.dailyCap", "Today's AI explanation limit is reached. The proposal and its rule-based rationale are unaffected."],
37
+ UNAVAILABLE: ["movethewheels.dispatch.ai.unavailable", "The AI explanation could not be produced this time. The proposal and its rule-based rationale are unaffected."]
38
+ }, P = {
39
+ NO_ELIGIBLE_PAIR: ["movethewheels.dispatch.unassigned.noPair", "No linked vehicle and driver are free (vehicle active and not on a live route, driver with a valid licence)."],
40
+ FLEET_FULLY_ASSIGNED: ["movethewheels.dispatch.unassigned.fleetFull", "Every free vehicle and driver pair is already used in this plan."],
41
+ OVER_CAPACITY: ["movethewheels.dispatch.unassigned.overCapacity", "The load is heavier than every free vehicle’s recorded capacity."],
42
+ PLAN_LIMIT_REACHED: ["movethewheels.dispatch.unassigned.limit", "The plan reached its assignment limit."],
43
+ NOT_PLANNABLE: ["movethewheels.dispatch.unassigned.notPlannable", "Not a planned shipment without a route."]
44
+ };
45
+ function F(e) {
46
+ return e === "all" ? {} : { to: new Date(Date.now() + j[e] * 36e5).toISOString() };
47
+ }
48
+ function I({ plan: e, t }) {
49
+ let [n, r] = M[e.status];
50
+ return /* @__PURE__ */ O(k, { children: [/* @__PURE__ */ O("div", {
51
+ className: "flex flex-wrap items-center justify-between gap-3",
52
+ children: [/* @__PURE__ */ O("div", {
53
+ className: "space-y-1",
54
+ children: [/* @__PURE__ */ O("p", {
55
+ className: "text-sm font-medium text-text-secondary",
56
+ children: [
57
+ t("movethewheels.dispatch.planLabel", "Latest proposal"),
58
+ " ·",
59
+ " ",
60
+ c(e.createdAt)
61
+ ]
62
+ }), /* @__PURE__ */ O("div", {
63
+ className: "flex flex-wrap items-center gap-2",
64
+ children: [/* @__PURE__ */ D(l, {
65
+ variant: e.status === "PROPOSED" ? "default" : "secondary",
66
+ children: t(n, r)
67
+ }), /* @__PURE__ */ O("span", {
68
+ className: "text-xs text-text-secondary",
69
+ children: [
70
+ t("movethewheels.dispatch.method", "Rule-based planner"),
71
+ " (",
72
+ e.method,
73
+ ")"
74
+ ]
75
+ })]
76
+ })]
77
+ }), /* @__PURE__ */ O("div", {
78
+ className: "grid grid-cols-3 gap-4 text-center",
79
+ children: [
80
+ /* @__PURE__ */ O("div", { children: [/* @__PURE__ */ D("p", {
81
+ className: "text-2xl font-bold tabular-nums text-text-primary",
82
+ children: e.assignments.length
83
+ }), /* @__PURE__ */ D("p", {
84
+ className: "text-xs text-text-secondary",
85
+ children: t("movethewheels.dispatch.proposed", "Proposed")
86
+ })] }),
87
+ /* @__PURE__ */ O("div", { children: [/* @__PURE__ */ D("p", {
88
+ className: "text-2xl font-bold tabular-nums text-text-primary",
89
+ children: e.acceptedCount
90
+ }), /* @__PURE__ */ D("p", {
91
+ className: "text-xs text-text-secondary",
92
+ children: t("movethewheels.dispatch.acceptedCount", "Accepted")
93
+ })] }),
94
+ /* @__PURE__ */ O("div", { children: [/* @__PURE__ */ D("p", {
95
+ className: "text-2xl font-bold tabular-nums text-text-primary",
96
+ children: e.unassigned.length
97
+ }), /* @__PURE__ */ D("p", {
98
+ className: "text-xs text-text-secondary",
99
+ children: t("movethewheels.dispatch.unassignedCount", "Unassigned")
100
+ })] })
101
+ ]
102
+ })]
103
+ }), e.status === "PROPOSED" && /* @__PURE__ */ O("p", {
104
+ className: "mt-3 text-xs text-text-secondary",
105
+ children: [
106
+ t("movethewheels.dispatch.expires", "Valid until"),
107
+ " ",
108
+ c(e.expiresAt)
109
+ ]
110
+ })] });
111
+ }
112
+ function L({ plan: e, t }) {
113
+ if (e.aiStatus === "AVAILABLE" && e.aiSummary) return /* @__PURE__ */ O(d, { children: [/* @__PURE__ */ D(p, { children: /* @__PURE__ */ O(m, {
114
+ className: "flex items-center gap-2 text-base",
115
+ children: [/* @__PURE__ */ D(i, {
116
+ size: 16,
117
+ "aria-hidden": "true"
118
+ }), t("movethewheels.dispatch.ai.title", "AI summary")]
119
+ }) }), /* @__PURE__ */ O(f, {
120
+ className: "space-y-2",
121
+ children: [/* @__PURE__ */ D("p", {
122
+ className: "text-sm text-text-primary",
123
+ children: e.aiSummary
124
+ }), /* @__PURE__ */ O("p", {
125
+ className: "text-xs text-text-secondary",
126
+ children: [t("movethewheels.dispatch.ai.disclaimer", "Written by AI from the planner’s facts. It never changes an assignment; check before accepting."), e.aiModel ? ` (${e.aiModel})` : ""]
127
+ })]
128
+ })] });
129
+ let [n, r] = N[e.aiStatus === "AVAILABLE" ? "UNAVAILABLE" : e.aiStatus];
130
+ return /* @__PURE__ */ D("div", {
131
+ role: "status",
132
+ className: "rounded-lg border border-status-info-border bg-status-info-bg-subtle px-4 py-3 text-sm text-status-info-text",
133
+ children: t(n, r)
134
+ });
135
+ }
136
+ function R() {
137
+ let { t: i } = ie(), c = (e, t) => {
138
+ let n = i(e);
139
+ return n === e ? t : n;
140
+ }, { basePath: l, navigate: k } = s(), j = (e) => k?.(o(l, e)), { plan: M, isLoading: N, error: R, pendingAction: z, refetch: B, propose: V, apply: H, reject: U } = ne(), [W, G] = T("72h"), [K, q] = T({}), [oe, J] = T(null), { message: se, notify: ce } = S(6e3);
141
+ re(() => {
142
+ q({});
143
+ }, [M?.id, M?.status]);
144
+ let Y = M?.status === "PROPOSED", X = z !== null, Z = w(() => M ? M.assignments.filter((e) => K[e.id] === "accept").map((e) => e.id) : [], [M, K]), le = M ? M.assignments.filter((e) => e.decision === "PENDING" && !K[e.id]).length : 0, Q = async (e, t) => {
145
+ J(null);
146
+ try {
147
+ ce(t(await e()));
148
+ } catch (e) {
149
+ J(e instanceof Error ? e.message : "The request failed.");
150
+ }
151
+ }, ue = () => Q(() => V(F(W)), (e) => e.assignments.length > 0 ? c("movethewheels.dispatch.notice.proposed", "New proposal ready. Nothing is written until you accept.") : c("movethewheels.dispatch.notice.proposedEmpty", "No shipment could be assigned right now.")), de = () => M && Q(() => H(M.id, Z), (e) => `${c("movethewheels.dispatch.notice.applied", "Decisions applied. Routes created")}: ${e.acceptedCount}`), fe = () => M && Q(() => U(M.id), () => c("movethewheels.dispatch.notice.rejected", "Proposal rejected. Nothing was written.")), $ = (e) => M && q(Object.fromEntries(M.assignments.map((t) => [t.id, e])));
152
+ return /* @__PURE__ */ O(ee, {
153
+ title: c("movethewheels.dispatch.title", "Dispatch planner"),
154
+ subtitle: c("movethewheels.dispatch.subtitle", "Proposed vehicle and driver assignments for planned shipments — you decide what becomes a route."),
155
+ icon: /* @__PURE__ */ D(a, {
156
+ size: 24,
157
+ "aria-hidden": "true"
158
+ }),
159
+ headerActions: /* @__PURE__ */ D(ae, {
160
+ primary: {
161
+ label: c("movethewheels.dispatch.manual", "Create route manually"),
162
+ icon: /* @__PURE__ */ D(n, { size: 16 }),
163
+ onSelect: () => j("routes/new")
164
+ },
165
+ actions: [{
166
+ label: c("movethewheels.dispatch.allRoutes", "All routes"),
167
+ icon: /* @__PURE__ */ D(t, { size: 16 }),
168
+ onSelect: () => j("routes")
169
+ }, {
170
+ label: c("movethewheels.dispatch.refresh", "Refresh"),
171
+ icon: /* @__PURE__ */ D(r, { size: 16 }),
172
+ onSelect: () => B()
173
+ }]
174
+ }),
175
+ children: [
176
+ /* @__PURE__ */ D(A, {
177
+ icon: /* @__PURE__ */ D(a, { size: 18 }),
178
+ children: c("movethewheels.dispatch.purpose", "The planner pairs each planned shipment that has no route with a free, linked vehicle and driver, earliest due first, and explains why. Proposing writes nothing. Accept the cards you agree with and apply: each accepted card becomes a planned route, checked again at that moment; everything else is rejected.")
179
+ }),
180
+ /* @__PURE__ */ D(d, { children: /* @__PURE__ */ O(f, {
181
+ className: "flex flex-wrap items-center gap-3 p-4",
182
+ children: [
183
+ /* @__PURE__ */ D("span", {
184
+ className: "text-sm font-medium",
185
+ children: c("movethewheels.dispatch.horizon", "Shipments due within")
186
+ }),
187
+ /* @__PURE__ */ O(h, {
188
+ value: W,
189
+ onValueChange: (e) => G(e),
190
+ children: [/* @__PURE__ */ D(v, {
191
+ className: "w-[180px]",
192
+ "aria-label": c("movethewheels.dispatch.horizon", "Shipments due within"),
193
+ children: /* @__PURE__ */ D(y, {})
194
+ }), /* @__PURE__ */ O(g, { children: [
195
+ /* @__PURE__ */ D(_, {
196
+ value: "24h",
197
+ children: c("movethewheels.dispatch.horizon.24h", "Next 24 hours")
198
+ }),
199
+ /* @__PURE__ */ D(_, {
200
+ value: "72h",
201
+ children: c("movethewheels.dispatch.horizon.72h", "Next 3 days")
202
+ }),
203
+ /* @__PURE__ */ D(_, {
204
+ value: "7d",
205
+ children: c("movethewheels.dispatch.horizon.7d", "Next 7 days")
206
+ }),
207
+ /* @__PURE__ */ D(_, {
208
+ value: "all",
209
+ children: c("movethewheels.dispatch.horizon.all", "Any due date")
210
+ })
211
+ ] })]
212
+ }),
213
+ /* @__PURE__ */ O(u, {
214
+ onClick: ue,
215
+ disabled: X,
216
+ children: [z === "propose" ? /* @__PURE__ */ D(e, {
217
+ size: 16,
218
+ className: "animate-spin",
219
+ "aria-hidden": "true"
220
+ }) : /* @__PURE__ */ D(a, {
221
+ size: 16,
222
+ "aria-hidden": "true"
223
+ }), z === "propose" ? c("movethewheels.dispatch.proposing", "Proposing…") : c("movethewheels.dispatch.propose", "Propose assignments")]
224
+ }),
225
+ /* @__PURE__ */ D("span", {
226
+ className: "text-xs text-text-secondary",
227
+ children: c("movethewheels.dispatch.noUndatedNote", "Shipments without a due date are always included.")
228
+ })
229
+ ]
230
+ }) }),
231
+ /* @__PURE__ */ D(x, { message: se }),
232
+ /* @__PURE__ */ D(te, { message: oe }),
233
+ N && !M ? /* @__PURE__ */ O("div", {
234
+ className: "space-y-3",
235
+ children: [/* @__PURE__ */ D(b, { className: "h-24 w-full" }), /* @__PURE__ */ D(b, { className: "h-40 w-full" })]
236
+ }) : R ? /* @__PURE__ */ D(d, {
237
+ className: "border-status-error-border",
238
+ children: /* @__PURE__ */ O(f, {
239
+ className: "space-y-3 p-6 text-center",
240
+ children: [
241
+ /* @__PURE__ */ D("p", {
242
+ className: "font-medium text-status-error-text",
243
+ children: c("movethewheels.dispatch.loadError", "Couldn't load the dispatch plan")
244
+ }),
245
+ /* @__PURE__ */ D("p", {
246
+ className: "text-sm text-text-secondary",
247
+ children: R.message
248
+ }),
249
+ /* @__PURE__ */ D(u, {
250
+ variant: "outline",
251
+ onClick: B,
252
+ children: c("movethewheels.fleet.error.retry", "Retry")
253
+ })
254
+ ]
255
+ })
256
+ }) : M ? /* @__PURE__ */ O(E, { children: [
257
+ /* @__PURE__ */ D(I, {
258
+ plan: M,
259
+ t: c
260
+ }),
261
+ /* @__PURE__ */ D(L, {
262
+ plan: M,
263
+ t: c
264
+ }),
265
+ Y && M.assignments.length > 0 && /* @__PURE__ */ D(d, { children: /* @__PURE__ */ O(f, {
266
+ className: "flex flex-wrap items-center justify-between gap-3 p-4",
267
+ children: [/* @__PURE__ */ O("div", {
268
+ className: "space-y-1",
269
+ children: [/* @__PURE__ */ O("p", {
270
+ className: "text-sm font-medium text-text-primary",
271
+ "aria-live": "polite",
272
+ children: [
273
+ Z.length,
274
+ " ",
275
+ c("movethewheels.dispatch.toAccept", "to accept"),
276
+ " ·",
277
+ " ",
278
+ M.assignments.length - Z.length,
279
+ " ",
280
+ c("movethewheels.dispatch.toReject", "to reject")
281
+ ]
282
+ }), le > 0 && /* @__PURE__ */ D("p", {
283
+ className: "text-xs text-text-secondary",
284
+ children: c("movethewheels.dispatch.undecidedNote", "Cards you have not accepted are rejected when you apply.")
285
+ })]
286
+ }), /* @__PURE__ */ O("div", {
287
+ className: "flex flex-wrap gap-2",
288
+ children: [
289
+ /* @__PURE__ */ D(u, {
290
+ variant: "ghost",
291
+ size: "sm",
292
+ disabled: X,
293
+ onClick: () => $("accept"),
294
+ children: c("movethewheels.dispatch.acceptAll", "Accept all")
295
+ }),
296
+ /* @__PURE__ */ D(u, {
297
+ variant: "ghost",
298
+ size: "sm",
299
+ disabled: X,
300
+ onClick: () => $(null),
301
+ children: c("movethewheels.dispatch.clear", "Clear")
302
+ }),
303
+ /* @__PURE__ */ O(u, {
304
+ variant: "outline",
305
+ disabled: X,
306
+ onClick: fe,
307
+ children: [z === "reject" && /* @__PURE__ */ D(e, {
308
+ size: 16,
309
+ className: "animate-spin",
310
+ "aria-hidden": "true"
311
+ }), c("movethewheels.dispatch.rejectPlan", "Reject proposal")]
312
+ }),
313
+ /* @__PURE__ */ O(u, {
314
+ disabled: X || Z.length === 0,
315
+ onClick: de,
316
+ children: [z === "apply" && /* @__PURE__ */ D(e, {
317
+ size: 16,
318
+ className: "animate-spin",
319
+ "aria-hidden": "true"
320
+ }), z === "apply" ? c("movethewheels.dispatch.applying", "Creating routes…") : c("movethewheels.dispatch.apply", "Apply decisions")]
321
+ })
322
+ ]
323
+ })]
324
+ }) }),
325
+ M.assignments.length > 0 && /* @__PURE__ */ D("section", {
326
+ "aria-label": c("movethewheels.dispatch.cards", "Decision cards"),
327
+ className: "grid gap-4 lg:grid-cols-2",
328
+ children: M.assignments.map((e) => /* @__PURE__ */ D(C, {
329
+ assignment: e,
330
+ open: Y,
331
+ choice: K[e.id] ?? null,
332
+ disabled: X,
333
+ onChoose: (t) => q((n) => ({
334
+ ...n,
335
+ [e.id]: t
336
+ })),
337
+ onOpenRoute: (e) => j(`routes/${e}`),
338
+ t: c
339
+ }, e.id))
340
+ }),
341
+ M.unassigned.length > 0 && /* @__PURE__ */ O(d, { children: [/* @__PURE__ */ D(p, { children: /* @__PURE__ */ D(m, {
342
+ className: "text-base",
343
+ children: c("movethewheels.dispatch.unassignedTitle", "Not assigned")
344
+ }) }), /* @__PURE__ */ D(f, { children: /* @__PURE__ */ D("ul", {
345
+ className: "divide-y",
346
+ children: M.unassigned.map((e) => {
347
+ let t = P[e.reason];
348
+ return /* @__PURE__ */ O("li", {
349
+ className: "flex flex-wrap justify-between gap-2 py-2 text-sm",
350
+ children: [/* @__PURE__ */ D("span", {
351
+ className: "font-medium break-words",
352
+ children: e.shipmentNumber ?? e.shipmentId
353
+ }), /* @__PURE__ */ D("span", {
354
+ className: "text-text-secondary",
355
+ children: t ? c(t[0], t[1]) : e.reason
356
+ })]
357
+ }, e.shipmentId);
358
+ })
359
+ }) })] })
360
+ ] }) : /* @__PURE__ */ D(d, { children: /* @__PURE__ */ O(f, {
361
+ className: "space-y-2 p-6 text-center",
362
+ children: [/* @__PURE__ */ D("p", {
363
+ className: "font-medium text-text-primary",
364
+ children: c("movethewheels.dispatch.empty", "No proposal yet")
365
+ }), /* @__PURE__ */ D("p", {
366
+ className: "text-sm text-text-secondary",
367
+ children: c("movethewheels.dispatch.emptyHint", "Propose assignments to see decision cards for your planned shipments.")
368
+ })]
369
+ }) })
370
+ ]
371
+ });
372
+ }
373
+ //#endregion
374
+ export { R as default };