@burdenoff/microfe-movethewheels 2026.1107.5 → 2026.1107.7

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,362 @@
1
+ import { Building2 as e } from "../node_modules/lucide-react/dist/esm/icons/building-2.js";
2
+ import { Check as t } from "../node_modules/lucide-react/dist/esm/icons/check.js";
3
+ import { LoaderCircle as n } from "../node_modules/lucide-react/dist/esm/icons/loader-circle.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 { X as o } from "../node_modules/lucide-react/dist/esm/icons/x.js";
8
+ import { formatCurrency as s, formatDateTime as c } from "../utils/formatters.js";
9
+ import { Badge as l, Button as u, Card as d, CardContent as f, Skeleton as p } from "./ui.js";
10
+ import { FormError as m } from "./FormError.js";
11
+ import { confidenceTone as h } from "./DispatchDecisionCard.js";
12
+ import { useShipmentDecision as g } from "../hooks/useShipmentDecision.js";
13
+ import { useState as _ } from "react";
14
+ import { Fragment as v, jsx as y, jsxs as b } from "react/jsx-runtime";
15
+ //#region src/movethewheels/components/ShipmentDecisionPanel.tsx
16
+ var x = {
17
+ USE_CARRIER: ["movethewheels.decision.action.useCarrier", "Use carrier"],
18
+ REASSIGN_VEHICLE: ["movethewheels.decision.action.reassignVehicle", "Reassign the vehicle"],
19
+ REPROMISE_DELIVERY: ["movethewheels.decision.action.repromise", "Re-promise the delivery"],
20
+ REQUEST_TRACKING_UPDATE: ["movethewheels.decision.action.trackingUpdate", "Get a tracking update"],
21
+ SWITCH_CARRIER: ["movethewheels.decision.action.switchCarrier", "Switch carrier"],
22
+ ACCEPT_SLIP: ["movethewheels.decision.action.acceptSlip", "Accept the delay"]
23
+ }, S = {
24
+ LANE_HISTORY: ["movethewheels.decision.reason.laneHistory", "Lane history"],
25
+ LANE_HISTORY_THIN: ["movethewheels.decision.reason.laneThin", "Little lane history"],
26
+ NO_LANE_HISTORY: ["movethewheels.decision.reason.noLane", "No lane history"],
27
+ ON_TIME_STRONG: ["movethewheels.decision.reason.onTimeStrong", "Strong on-time record"],
28
+ LATE_HISTORY: ["movethewheels.decision.reason.lateHistory", "Often late"],
29
+ LOWEST_LANE_COST: ["movethewheels.decision.reason.lowestCost", "Lowest lane cost"],
30
+ CURRENT_CARRIER: ["movethewheels.decision.reason.current", "Current carrier"],
31
+ PREDICTED_SLIP: ["movethewheels.decision.reason.predictedSlip", "Predicted late"],
32
+ PROMISE_MISSED: ["movethewheels.decision.reason.promiseMissed", "Promise missed"],
33
+ VEHICLE_UNAVAILABLE: ["movethewheels.decision.reason.vehicleUnavailable", "Vehicle unavailable"],
34
+ TRACKING_STALE: ["movethewheels.decision.reason.trackingStale", "Tracking stale"],
35
+ BETTER_LANE_RECORD: ["movethewheels.decision.reason.betterRecord", "Better lane record"],
36
+ CURRENT_CARRIER_LATE: ["movethewheels.decision.reason.currentLate", "Current carrier often late"]
37
+ }, C = new Set([
38
+ "LANE_HISTORY_THIN",
39
+ "NO_LANE_HISTORY",
40
+ "LATE_HISTORY",
41
+ "PROMISE_MISSED",
42
+ "CURRENT_CARRIER_LATE"
43
+ ]), w = {
44
+ APPLY: ["movethewheels.decision.execution.apply", "Accepting changes the shipment."],
45
+ FOLLOW_UP: ["movethewheels.decision.execution.followUp", "Accepting records the decision; you then carry out the step."],
46
+ RECORD: ["movethewheels.decision.execution.record", "Accepting only records the decision; nothing on the shipment changes."]
47
+ }, T = {
48
+ PROPOSED: ["movethewheels.decision.status.proposed", "Waiting for your decision"],
49
+ ACCEPTED: ["movethewheels.decision.status.accepted", "Accepted"],
50
+ REJECTED: ["movethewheels.decision.status.rejected", "Rejected — nothing changed"],
51
+ STALE: ["movethewheels.decision.status.stale", "Not applied — the shipment changed"],
52
+ EXPIRED: ["movethewheels.decision.status.expired", "Expired"]
53
+ }, E = {
54
+ APPLIED: ["movethewheels.decision.outcome.applied", "Applied to the shipment"],
55
+ RECORDED: ["movethewheels.decision.outcome.recorded", "Recorded"],
56
+ FOLLOW_UP: ["movethewheels.decision.outcome.followUp", "Recorded — follow-up to do"]
57
+ }, D = {
58
+ NOT_NEEDED: ["movethewheels.decision.ai.notNeeded", "There was nothing to rank, so there was nothing for AI to explain."],
59
+ AI_DISABLED: ["movethewheels.decision.ai.disabled", "AI explanations are switched off. The rule-based rationale below is complete."],
60
+ CREDITS_EXHAUSTED: ["movethewheels.decision.ai.creditsExhausted", "This workspace has used its MoveTheWheels AI credits, so no AI explanation was written. The options are unaffected."],
61
+ DAILY_CAP_REACHED: ["movethewheels.decision.ai.dailyCap", "Today's AI explanation limit is reached. The options are unaffected."],
62
+ UNAVAILABLE: ["movethewheels.decision.ai.unavailable", "The AI explanation could not be produced this time. The options are unaffected."]
63
+ }, O = {
64
+ CARRIER_RECOMMENDATION: {
65
+ propose: ["movethewheels.carrierDecision.propose", "Recommend a carrier"],
66
+ again: ["movethewheels.carrierDecision.again", "Recommend again"],
67
+ empty: ["movethewheels.carrierDecision.empty", "No carrier has delivered for this workspace in the last 180 days, so there is nothing to rank yet. Set the carrier on the shipment by hand."]
68
+ },
69
+ EXCEPTION_REMEDIATION: {
70
+ propose: ["movethewheels.exceptionDecision.propose", "Propose remediations"],
71
+ again: ["movethewheels.exceptionDecision.again", "Propose again"],
72
+ empty: ["movethewheels.exceptionDecision.empty", "No remediation could be proposed."]
73
+ }
74
+ };
75
+ function k(e, t) {
76
+ let n = S[e];
77
+ return n ? t(n[0], n[1]) : e;
78
+ }
79
+ function A(e, t) {
80
+ let [n, r] = x[e.action], i = t(n, r);
81
+ return e.carrierId ? `${i} · ${e.carrierId}` : e.newEstimatedDelivery ? `${i} · ${c(e.newEstimatedDelivery)}` : i;
82
+ }
83
+ function j({ option: e, t }) {
84
+ return e.deliveredCount === null ? null : /* @__PURE__ */ b("dl", {
85
+ className: "grid grid-cols-2 gap-2 text-xs sm:grid-cols-3",
86
+ children: [
87
+ /* @__PURE__ */ b("div", { children: [/* @__PURE__ */ y("dt", {
88
+ className: "text-text-secondary",
89
+ children: t("movethewheels.carrierDecision.lane", "On this lane")
90
+ }), /* @__PURE__ */ b("dd", {
91
+ className: "font-medium tabular-nums",
92
+ children: [
93
+ e.laneOnTimeCount ?? 0,
94
+ "/",
95
+ e.laneDeliveredCount ?? 0,
96
+ " ",
97
+ t("movethewheels.carrierDecision.onTime", "on time")
98
+ ]
99
+ })] }),
100
+ /* @__PURE__ */ b("div", { children: [/* @__PURE__ */ y("dt", {
101
+ className: "text-text-secondary",
102
+ children: t("movethewheels.carrierDecision.overall", "All lanes")
103
+ }), /* @__PURE__ */ b("dd", {
104
+ className: "font-medium tabular-nums",
105
+ children: [
106
+ e.onTimeCount ?? 0,
107
+ "/",
108
+ e.deliveredCount,
109
+ " ",
110
+ t("movethewheels.carrierDecision.onTime", "on time")
111
+ ]
112
+ })] }),
113
+ e.medianLaneCost !== null && /* @__PURE__ */ b("div", { children: [/* @__PURE__ */ y("dt", {
114
+ className: "text-text-secondary",
115
+ children: t("movethewheels.carrierDecision.cost", "Median lane cost")
116
+ }), /* @__PURE__ */ y("dd", {
117
+ className: "font-medium tabular-nums",
118
+ children: e.currency ? s(e.medianLaneCost, e.currency) : e.medianLaneCost
119
+ })] })
120
+ ]
121
+ });
122
+ }
123
+ function M({ option: r, decision: a, disabled: o, accepting: s, onAccept: c, followUp: p, t: m }) {
124
+ let g = a.status === "PROPOSED", _ = a.chosenOptionId === r.id, v = Math.round(r.confidence * 100), [x, S] = w[r.execution];
125
+ return /* @__PURE__ */ y(d, {
126
+ className: _ ? "border-status-success-border" : "border-border-default",
127
+ "data-option-id": r.id,
128
+ "data-testid": "shipment-decision-card",
129
+ children: /* @__PURE__ */ b(f, {
130
+ className: "space-y-3 p-4",
131
+ children: [
132
+ /* @__PURE__ */ b("div", {
133
+ className: "flex flex-wrap items-start justify-between gap-3",
134
+ children: [/* @__PURE__ */ b("div", {
135
+ className: "min-w-0 space-y-1",
136
+ children: [/* @__PURE__ */ b("p", {
137
+ className: "text-xs text-text-secondary",
138
+ children: [
139
+ m("movethewheels.decision.rank", "Option"),
140
+ " ",
141
+ r.rank
142
+ ]
143
+ }), /* @__PURE__ */ b("p", {
144
+ className: "flex items-center gap-2 text-sm font-semibold break-words text-text-primary",
145
+ children: [r.carrierId && /* @__PURE__ */ y(e, {
146
+ size: 14,
147
+ className: "shrink-0 text-text-secondary",
148
+ "aria-hidden": "true"
149
+ }), A(r, m)]
150
+ })]
151
+ }), /* @__PURE__ */ b("div", {
152
+ className: "text-right",
153
+ children: [/* @__PURE__ */ b("p", {
154
+ className: `text-lg font-bold tabular-nums ${h(r.confidence)}`,
155
+ children: [v, "%"]
156
+ }), /* @__PURE__ */ y("p", {
157
+ className: "text-xs text-text-secondary",
158
+ children: m("movethewheels.decision.confidence", "Confidence")
159
+ })]
160
+ })]
161
+ }),
162
+ /* @__PURE__ */ y("ul", {
163
+ className: "flex flex-wrap gap-1.5",
164
+ "aria-label": m("movethewheels.dispatch.reasons", "Reasons"),
165
+ children: r.reasons.map((e) => /* @__PURE__ */ y("li", { children: /* @__PURE__ */ y(l, {
166
+ variant: C.has(e) ? "outline" : "secondary",
167
+ children: k(e, m)
168
+ }) }, e))
169
+ }),
170
+ /* @__PURE__ */ y(j, {
171
+ option: r,
172
+ t: m
173
+ }),
174
+ /* @__PURE__ */ y("p", {
175
+ className: "text-sm text-text-secondary",
176
+ children: r.rationale
177
+ }),
178
+ r.aiRationale && /* @__PURE__ */ b("p", {
179
+ className: "flex items-start gap-2 rounded-md bg-surface-secondary p-2 text-sm text-text-primary",
180
+ children: [/* @__PURE__ */ y(i, {
181
+ size: 14,
182
+ className: "mt-0.5 shrink-0",
183
+ "aria-hidden": "true"
184
+ }), /* @__PURE__ */ b("span", { children: [/* @__PURE__ */ b("span", {
185
+ className: "sr-only",
186
+ children: [
187
+ m("movethewheels.dispatch.aiWritten", "AI-written"),
188
+ ":",
189
+ " "
190
+ ]
191
+ }), r.aiRationale] })]
192
+ }),
193
+ /* @__PURE__ */ y("p", {
194
+ className: "text-xs text-text-secondary",
195
+ children: m(x, S)
196
+ }),
197
+ g ? /* @__PURE__ */ b(u, {
198
+ size: "sm",
199
+ disabled: o,
200
+ onClick: c,
201
+ children: [s ? /* @__PURE__ */ y(n, {
202
+ size: 14,
203
+ className: "animate-spin",
204
+ "aria-hidden": "true"
205
+ }) : /* @__PURE__ */ y(t, {
206
+ size: 14,
207
+ "aria-hidden": "true"
208
+ }), m("movethewheels.dispatch.accept", "Accept")]
209
+ }) : _ && /* @__PURE__ */ b("div", {
210
+ className: "space-y-2",
211
+ children: [
212
+ a.status === "ACCEPTED" && a.outcome ? /* @__PURE__ */ y(l, {
213
+ variant: "default",
214
+ children: m(E[a.outcome][0], E[a.outcome][1])
215
+ }) : /* @__PURE__ */ y(l, {
216
+ variant: "outline",
217
+ children: m(T[a.status][0], T[a.status][1])
218
+ }),
219
+ a.status === "STALE" && a.decisionReason && /* @__PURE__ */ y("p", {
220
+ className: "text-xs text-status-warning-text",
221
+ children: a.decisionReason
222
+ }),
223
+ a.outcome === "FOLLOW_UP" && p
224
+ ]
225
+ })
226
+ ]
227
+ })
228
+ });
229
+ }
230
+ function N({ shipmentId: e, kind: t, t: s, onApplied: d, renderFollowUp: f }) {
231
+ let { decision: h, isLoading: x, error: S, pendingAction: C, refetch: w, propose: E, accept: k, reject: A } = g(e, t), [j, N] = _(null), [P, F] = _(null), I = C !== null, L = O[t], R = async (e) => {
232
+ N(null);
233
+ try {
234
+ let t = await e();
235
+ t.status === "ACCEPTED" && t.outcome === "APPLIED" && d?.(t);
236
+ } catch (e) {
237
+ N(e instanceof Error ? e.message : "The request failed.");
238
+ } finally {
239
+ F(null);
240
+ }
241
+ }, z = h?.status === "PROPOSED", B = D[!h || h.aiStatus === "AVAILABLE" ? "UNAVAILABLE" : h.aiStatus];
242
+ return /* @__PURE__ */ b("section", {
243
+ className: "space-y-3",
244
+ "data-testid": `shipment-decision-${t}`,
245
+ children: [
246
+ /* @__PURE__ */ b("div", {
247
+ className: "flex flex-wrap items-center gap-2",
248
+ children: [
249
+ !z && /* @__PURE__ */ b(u, {
250
+ size: "sm",
251
+ disabled: I || !e,
252
+ onClick: () => R(E),
253
+ children: [C === "propose" ? /* @__PURE__ */ y(n, {
254
+ size: 14,
255
+ className: "animate-spin",
256
+ "aria-hidden": "true"
257
+ }) : /* @__PURE__ */ y(a, {
258
+ size: 14,
259
+ "aria-hidden": "true"
260
+ }), h ? s(L.again[0], L.again[1]) : s(L.propose[0], L.propose[1])]
261
+ }),
262
+ h && /* @__PURE__ */ y(l, {
263
+ variant: z ? "default" : "secondary",
264
+ children: s(T[h.status][0], T[h.status][1])
265
+ }),
266
+ h && /* @__PURE__ */ b("span", {
267
+ className: "text-xs text-text-secondary",
268
+ children: [
269
+ s("movethewheels.decision.method", "Rule-based ranking"),
270
+ " (",
271
+ h.method,
272
+ ") ·",
273
+ " ",
274
+ c(h.createdAt)
275
+ ]
276
+ })
277
+ ]
278
+ }),
279
+ /* @__PURE__ */ y(m, { message: j }),
280
+ x && !h && /* @__PURE__ */ y(p, { className: "h-24 w-full" }),
281
+ S && !x && /* @__PURE__ */ b("div", {
282
+ role: "alert",
283
+ className: "space-y-2 text-sm",
284
+ children: [/* @__PURE__ */ y("p", {
285
+ className: "text-status-error-text",
286
+ children: S.message
287
+ }), /* @__PURE__ */ b(u, {
288
+ size: "sm",
289
+ variant: "outline",
290
+ onClick: w,
291
+ children: [/* @__PURE__ */ y(r, {
292
+ size: 14,
293
+ "aria-hidden": "true"
294
+ }), s("movethewheels.risk.retry", "Retry")]
295
+ })]
296
+ }),
297
+ h && /* @__PURE__ */ b(v, { children: [
298
+ h.aiStatus === "AVAILABLE" && h.aiSummary ? /* @__PURE__ */ b("div", {
299
+ className: "space-y-1 rounded-md bg-surface-secondary p-3 text-sm",
300
+ children: [/* @__PURE__ */ b("p", {
301
+ className: "flex items-start gap-2 text-text-primary",
302
+ children: [/* @__PURE__ */ y(i, {
303
+ size: 14,
304
+ className: "mt-0.5 shrink-0",
305
+ "aria-hidden": "true"
306
+ }), /* @__PURE__ */ y("span", { children: h.aiSummary })]
307
+ }), /* @__PURE__ */ b("p", {
308
+ className: "text-xs text-text-secondary",
309
+ children: [s("movethewheels.decision.ai.disclaimer", "Written by AI from the ranker’s facts. It never changes the ranking; check before accepting."), h.aiModel ? ` (${h.aiModel})` : ""]
310
+ })]
311
+ }) : /* @__PURE__ */ y("p", {
312
+ role: "status",
313
+ className: "rounded-md border border-status-info-border bg-status-info-bg-subtle px-3 py-2 text-xs text-status-info-text",
314
+ children: s(B[0], B[1])
315
+ }),
316
+ h.options.length === 0 ? /* @__PURE__ */ y("p", {
317
+ className: "text-sm text-text-secondary",
318
+ children: s(L.empty[0], L.empty[1])
319
+ }) : /* @__PURE__ */ y("div", {
320
+ className: "space-y-3",
321
+ children: h.options.map((e) => /* @__PURE__ */ y(M, {
322
+ option: e,
323
+ decision: h,
324
+ disabled: I,
325
+ accepting: C === "accept" && P === e.id,
326
+ onAccept: () => {
327
+ F(e.id), R(() => k(h.id, e.id));
328
+ },
329
+ followUp: f?.(e),
330
+ t: s
331
+ }, e.id))
332
+ }),
333
+ z && /* @__PURE__ */ b("div", {
334
+ className: "flex flex-wrap items-center justify-between gap-2",
335
+ children: [/* @__PURE__ */ b("span", {
336
+ className: "text-xs text-text-secondary",
337
+ children: [
338
+ s("movethewheels.dispatch.expires", "Valid until"),
339
+ " ",
340
+ c(h.expiresAt)
341
+ ]
342
+ }), /* @__PURE__ */ b(u, {
343
+ size: "sm",
344
+ variant: "outline",
345
+ disabled: I,
346
+ onClick: () => R(() => A(h.id)),
347
+ children: [C === "reject" ? /* @__PURE__ */ y(n, {
348
+ size: 14,
349
+ className: "animate-spin",
350
+ "aria-hidden": "true"
351
+ }) : /* @__PURE__ */ y(o, {
352
+ size: 14,
353
+ "aria-hidden": "true"
354
+ }), s("movethewheels.decision.rejectAll", "Reject all")]
355
+ })]
356
+ })
357
+ ] })
358
+ ]
359
+ });
360
+ }
361
+ //#endregion
362
+ export { N as ShipmentDecisionPanel };