@burdenoff/microfe-movethewheels 2026.1102.2 → 2026.1107.2

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,721 @@
1
+ import { CalendarClock as e } from "../node_modules/lucide-react/dist/esm/icons/calendar-clock.js";
2
+ import { Download as t } from "../node_modules/lucide-react/dist/esm/icons/download.js";
3
+ import { FileChartColumnIncreasing as n } from "../node_modules/lucide-react/dist/esm/icons/file-chart-column-increasing.js";
4
+ import { LoaderCircle as r } from "../node_modules/lucide-react/dist/esm/icons/loader-circle.js";
5
+ import { Pencil as i } from "../node_modules/lucide-react/dist/esm/icons/pencil.js";
6
+ import { Play as a } from "../node_modules/lucide-react/dist/esm/icons/play.js";
7
+ import { Plus as o } from "../node_modules/lucide-react/dist/esm/icons/plus.js";
8
+ import { RefreshCw as ee } from "../node_modules/lucide-react/dist/esm/icons/refresh-cw.js";
9
+ import { Trash2 as te } from "../node_modules/lucide-react/dist/esm/icons/trash-2.js";
10
+ import { useMoveTheWheels as s } from "../providers/MoveTheWheelsProvider.js";
11
+ import { executeGraphQL as c } from "../utils/graphqlClient.js";
12
+ import { formatCurrency as l, formatDate as u, formatDateTime as d, formatDistance as f, formatWeight as p } from "../utils/formatters.js";
13
+ import { useModuleSettings as ne } from "../providers/ModuleSettingsProvider.js";
14
+ import { Badge as re, Button as m, Card as h, CardContent as g, CardDescription as ie, CardHeader as ae, CardTitle as _, Dialog as oe, DialogContent as se, DialogDescription as ce, DialogFooter as le, DialogHeader as ue, DialogTitle as de, Input as v, Label as y, Select as b, SelectContent as x, SelectItem as S, SelectTrigger as C, SelectValue as w, Skeleton as T, Switch as fe, Table as pe, TableBody as me, TableCell as E, TableHead as D, TableHeader as he, TableRow as O, Textarea as k } from "../components/ui.js";
15
+ import { PageLayout as ge } from "../components/PageLayout.js";
16
+ import { FormError as A } from "../components/FormError.js";
17
+ import { Notice as _e, useNotice as ve } from "../components/Notice.js";
18
+ import { CREATE_MTW_REPORT_MUTATION as ye, DELETE_MTW_REPORT_MUTATION as be, FREQUENCY_OPTIONS as j, GENERATE_MTW_REPORT_MUTATION as xe, MTW_REPORTS_QUERY as Se, MTW_REPORT_RUNS_QUERY as Ce, MTW_REPORT_RUN_EXPORT_QUERY as we, MTW_REPORT_RUN_QUERY as Te, REPORT_TYPE_OPTIONS as M, UPDATE_MTW_REPORT_MUTATION as Ee, WEEKDAY_LABELS as N, formatCell as P, formatMetric as F, metricLabel as I, newReportInput as L, reportInputError as R, reportToInput as De, reportTypeLabel as Oe, scheduleSummary as ke, suggestedPeriodDays as z, toServiceInput as Ae } from "../utils/reports.js";
19
+ import { useCallback as je, useEffect as Me, useMemo as Ne, useState as B } from "react";
20
+ import { Fragment as Pe, jsx as V, jsxs as H } from "react/jsx-runtime";
21
+ import { clearGraphqlFetchResponseCache as Fe } from "@burdenoff/fe-libs/shared/graphql";
22
+ import { EmphasisPanel as Ie, PagePurpose as Le } from "@burdenoff/fe-libs/ui";
23
+ import { PermissionProvider as U, usePermissions as Re } from "@burdenoff/fe-libs/shared/providers/shell";
24
+ //#region src/movethewheels/pages/ReportsPage.tsx
25
+ var W = {
26
+ currency: l,
27
+ distance: f,
28
+ weight: p
29
+ };
30
+ function ze(e, t, n) {
31
+ let r = URL.createObjectURL(new Blob([t], { type: n })), i = document.createElement("a");
32
+ i.href = r, i.download = e, document.body.appendChild(i), i.click(), i.remove(), URL.revokeObjectURL(r);
33
+ }
34
+ function G(e, t) {
35
+ return e instanceof Error && e.message ? e.message : t;
36
+ }
37
+ function Be(e) {
38
+ return e === "COMPLETED" ? "default" : e === "FAILED" ? "destructive" : e === "RUNNING" ? "secondary" : "outline";
39
+ }
40
+ function Ve(e) {
41
+ return `${d(e.periodStart)} – ${d(e.periodEnd)}`;
42
+ }
43
+ function He() {
44
+ let { workspaceId: e } = s();
45
+ return /* @__PURE__ */ V(U, {
46
+ scopeId: e ?? null,
47
+ gateway: "workspace",
48
+ children: /* @__PURE__ */ V(K, {})
49
+ });
50
+ }
51
+ function K() {
52
+ let { apiGatewayUrl: t, authToken: l, workspaceToken: u, workspaceId: f, tenantId: p, currentUser: v } = s(), { settings: y } = ne(), b = Re(), x = Ne(() => ({
53
+ apiGatewayUrl: t,
54
+ authToken: l,
55
+ workspaceToken: u,
56
+ workspaceId: f,
57
+ tenantId: p,
58
+ actorId: v?.id
59
+ }), [
60
+ t,
61
+ l,
62
+ u,
63
+ f,
64
+ p,
65
+ v?.id
66
+ ]), [S, C] = B([]), [w, fe] = B(!0), [k, j] = B(null), [N, P] = B(null), [F, I] = B([]), [L, R] = B(null), [De, z] = B(!1), [U, W] = B(null), [He, K] = B(null), [Ge, q] = B(null), [J, Y] = B(null), [Ke, qe] = B(0), X = je(() => {
67
+ Fe(), qe((e) => e + 1);
68
+ }, []), { message: Je, notify: Ye } = ve(), Xe = !!(f && v?.id && b.scopeId === f && !b.isLoading && !b.error), Z = je((e) => !Xe || b.isSuperAdmin || b.hasPermission(`mtw-report:${e}`), [Xe, b]), Q = S.find((e) => e.id === N) ?? null;
69
+ Me(() => {
70
+ if (!x.workspaceId) return;
71
+ let e = !1;
72
+ return fe(!0), c(x, Se, { pagination: { limit: 100 } }).then((t) => {
73
+ e || (C(t.mtwReports), j(null), P((e) => e && t.mtwReports.some((t) => t.id === e) ? e : t.mtwReports[0]?.id ?? null));
74
+ }).catch((t) => {
75
+ e || j(G(t, "Could not load the reports"));
76
+ }).finally(() => {
77
+ e || fe(!1);
78
+ }), () => {
79
+ e = !0;
80
+ };
81
+ }, [x, Ke]);
82
+ let Ze = je(async (e) => {
83
+ z(!0);
84
+ try {
85
+ R((await c(x, Te, {
86
+ id: e,
87
+ rows: { limit: 50 }
88
+ })).mtwReportRun);
89
+ } catch (e) {
90
+ K(G(e, "Could not load the report run"));
91
+ } finally {
92
+ z(!1);
93
+ }
94
+ }, [x]), $ = Q?.latestRun?.id ?? null;
95
+ Me(() => {
96
+ if (I([]), R(null), !N) return;
97
+ let e = !1;
98
+ return c(x, Ce, {
99
+ reportId: N,
100
+ pagination: { limit: 30 }
101
+ }).then((t) => {
102
+ e || I(t.mtwReportRuns);
103
+ }).catch((t) => {
104
+ e || K(G(t, "Could not load the run history"));
105
+ }), $ && Ze($), () => {
106
+ e = !0;
107
+ };
108
+ }, [
109
+ x,
110
+ N,
111
+ $,
112
+ Ze
113
+ ]);
114
+ let Qe = async (e) => {
115
+ W(`generate:${e.id}`), K(null);
116
+ try {
117
+ let t = (await c(x, xe, { id: e.id }, "SINGLE_ATTEMPT")).generateMtwReport;
118
+ t.status === "COMPLETED" ? Ye(`"${e.name}" generated.`) : K(t.error ?? "The report could not be generated."), P(e.id), X();
119
+ } catch (e) {
120
+ K(G(e, "Could not generate the report"));
121
+ } finally {
122
+ W(null);
123
+ }
124
+ }, $e = async (e, t) => {
125
+ W(`download:${e}:${t}`), K(null);
126
+ try {
127
+ let n = (await c(x, we, {
128
+ runId: e,
129
+ format: t
130
+ })).mtwReportRunExport;
131
+ ze(n.filename, n.content, n.contentType);
132
+ } catch (e) {
133
+ K(G(e, "Could not download the report"));
134
+ } finally {
135
+ W(null);
136
+ }
137
+ }, et = async (e) => {
138
+ W(`delete:${e.id}`), K(null);
139
+ try {
140
+ await c(x, be, { id: e.id }, "SINGLE_ATTEMPT"), Ye(`"${e.name}" deleted.`), Y(null), N === e.id && P(null), X();
141
+ } catch (e) {
142
+ K(G(e, "Could not delete the report"));
143
+ } finally {
144
+ W(null);
145
+ }
146
+ };
147
+ return /* @__PURE__ */ H(ge, {
148
+ title: "Reports",
149
+ subtitle: "Scheduled and on-demand reports over your logistics data",
150
+ icon: /* @__PURE__ */ V(n, { size: 24 }),
151
+ maxWidth: "full",
152
+ headerActions: /* @__PURE__ */ H("div", {
153
+ className: "flex flex-wrap gap-2",
154
+ children: [/* @__PURE__ */ H(m, {
155
+ variant: "outline",
156
+ onClick: X,
157
+ children: [/* @__PURE__ */ V(ee, {
158
+ size: 16,
159
+ className: "mr-2"
160
+ }), " Refresh"]
161
+ }), Z("create") && /* @__PURE__ */ H(m, {
162
+ onClick: () => q("new"),
163
+ children: [/* @__PURE__ */ V(o, {
164
+ size: 16,
165
+ className: "mr-2"
166
+ }), " New report"]
167
+ })]
168
+ }),
169
+ children: [
170
+ /* @__PURE__ */ V(Le, {
171
+ icon: /* @__PURE__ */ V(n, { size: 18 }),
172
+ children: "Save the reports you need and generate them whenever you like, or have them generated every day, week or month. Each generation keeps its figures and rows so you can compare periods and download them as CSV or JSON."
173
+ }),
174
+ k && /* @__PURE__ */ V(A, { message: k }),
175
+ /* @__PURE__ */ V(A, { message: He }),
176
+ /* @__PURE__ */ V(_e, { message: Je }),
177
+ /* @__PURE__ */ H("div", {
178
+ className: "grid grid-cols-1 gap-6 xl:grid-cols-3",
179
+ children: [/* @__PURE__ */ H(Ie, {
180
+ className: "space-y-3 xl:col-span-1",
181
+ children: [/* @__PURE__ */ V("h2", {
182
+ className: "text-base font-semibold text-text-primary",
183
+ children: "Saved reports"
184
+ }), w && S.length === 0 ? /* @__PURE__ */ H("div", {
185
+ className: "space-y-3",
186
+ "aria-busy": "true",
187
+ children: [/* @__PURE__ */ V(T, { className: "h-16 w-full" }), /* @__PURE__ */ V(T, { className: "h-16 w-full" })]
188
+ }) : S.length === 0 ? /* @__PURE__ */ H("div", {
189
+ className: "rounded-lg border border-dashed border-border-default p-6 text-center text-sm text-text-secondary",
190
+ children: [/* @__PURE__ */ V("p", { children: "No reports yet." }), Z("create") && /* @__PURE__ */ H(m, {
191
+ className: "mt-4",
192
+ onClick: () => q("new"),
193
+ children: [/* @__PURE__ */ V(o, {
194
+ size: 16,
195
+ className: "mr-2"
196
+ }), " Create your first report"]
197
+ })]
198
+ }) : /* @__PURE__ */ V("ul", {
199
+ className: "space-y-2",
200
+ "aria-label": "Saved reports",
201
+ children: S.map((e) => /* @__PURE__ */ V("li", { children: /* @__PURE__ */ H("button", {
202
+ type: "button",
203
+ onClick: () => P(e.id),
204
+ "aria-current": e.id === N ? "true" : void 0,
205
+ className: `w-full rounded-lg border px-3 py-2 text-left transition-colors ${e.id === N ? "border-border-primary bg-surface-secondary" : "border-border-default hover:bg-surface-secondary"}`,
206
+ children: [
207
+ /* @__PURE__ */ H("span", {
208
+ className: "flex items-center justify-between gap-2",
209
+ children: [/* @__PURE__ */ V("span", {
210
+ className: "truncate text-sm font-medium text-text-primary",
211
+ children: e.name
212
+ }), /* @__PURE__ */ V(re, {
213
+ variant: "outline",
214
+ children: Oe(e.type)
215
+ })]
216
+ }),
217
+ /* @__PURE__ */ V("span", {
218
+ className: "mt-1 block text-xs text-text-secondary",
219
+ children: ke(e)
220
+ }),
221
+ /* @__PURE__ */ V("span", {
222
+ className: "mt-1 block text-xs text-text-tertiary",
223
+ children: e.lastGeneratedAt ? `Last generated ${d(e.lastGeneratedAt)}` : "Never generated"
224
+ })
225
+ ]
226
+ }) }, e.id))
227
+ })]
228
+ }), /* @__PURE__ */ V("div", {
229
+ className: "space-y-6 xl:col-span-2",
230
+ children: Q ? /* @__PURE__ */ H(Pe, { children: [
231
+ /* @__PURE__ */ V(h, { children: /* @__PURE__ */ H(ae, {
232
+ className: "flex flex-row flex-wrap items-start justify-between gap-3",
233
+ children: [/* @__PURE__ */ H("div", {
234
+ className: "min-w-0 space-y-1",
235
+ children: [
236
+ /* @__PURE__ */ V(_, {
237
+ className: "text-lg",
238
+ children: Q.name
239
+ }),
240
+ /* @__PURE__ */ V(ie, { children: Q.description || M.find((e) => e.value === Q.type)?.description }),
241
+ /* @__PURE__ */ H("p", {
242
+ className: "flex flex-wrap items-center gap-2 text-xs text-text-secondary",
243
+ children: [
244
+ /* @__PURE__ */ V(e, { size: 14 }),
245
+ /* @__PURE__ */ V("span", { children: ke(Q) }),
246
+ /* @__PURE__ */ H("span", { children: [
247
+ "· Covers the last ",
248
+ Q.periodDays,
249
+ " day(s)"
250
+ ] }),
251
+ Q.nextRunAt && /* @__PURE__ */ H("span", { children: ["· Next run ", d(Q.nextRunAt)] })
252
+ ]
253
+ })
254
+ ]
255
+ }), /* @__PURE__ */ H("div", {
256
+ className: "flex flex-wrap gap-2",
257
+ children: [
258
+ Z("generate") && /* @__PURE__ */ H(m, {
259
+ onClick: () => void Qe(Q),
260
+ disabled: U !== null,
261
+ "aria-label": `Generate ${Q.name} now`,
262
+ children: [U === `generate:${Q.id}` ? /* @__PURE__ */ V(r, {
263
+ size: 16,
264
+ className: "mr-2 animate-spin"
265
+ }) : /* @__PURE__ */ V(a, {
266
+ size: 16,
267
+ className: "mr-2"
268
+ }), "Generate now"]
269
+ }),
270
+ Z("update") && /* @__PURE__ */ H(m, {
271
+ variant: "outline",
272
+ onClick: () => q(Q),
273
+ disabled: U !== null,
274
+ children: [/* @__PURE__ */ V(i, {
275
+ size: 16,
276
+ className: "mr-2"
277
+ }), " Edit"]
278
+ }),
279
+ Z("delete") && /* @__PURE__ */ V(m, {
280
+ variant: "outline",
281
+ onClick: () => Y(Q),
282
+ disabled: U !== null,
283
+ "aria-label": `Delete ${Q.name}`,
284
+ children: /* @__PURE__ */ V(te, { size: 16 })
285
+ })
286
+ ]
287
+ })]
288
+ }) }),
289
+ /* @__PURE__ */ V(Ue, {
290
+ run: L,
291
+ isLoading: De,
292
+ hasRuns: !!Q.latestRun,
293
+ busy: U,
294
+ onDownload: (e, t) => void $e(e, t)
295
+ }),
296
+ /* @__PURE__ */ H(h, { children: [/* @__PURE__ */ H(ae, { children: [/* @__PURE__ */ V(_, {
297
+ className: "text-base",
298
+ children: "Run history"
299
+ }), /* @__PURE__ */ V(ie, { children: "The latest 30 generations are kept. Select one to preview it." })] }), /* @__PURE__ */ V(g, { children: F.length === 0 ? /* @__PURE__ */ V("p", {
300
+ className: "text-sm text-text-secondary",
301
+ children: "No runs yet."
302
+ }) : /* @__PURE__ */ V("div", {
303
+ className: "overflow-x-auto",
304
+ children: /* @__PURE__ */ H(pe, { children: [/* @__PURE__ */ V(he, { children: /* @__PURE__ */ H(O, { children: [
305
+ /* @__PURE__ */ V(D, { children: "Generated" }),
306
+ /* @__PURE__ */ V(D, { children: "Period" }),
307
+ /* @__PURE__ */ V(D, { children: "Trigger" }),
308
+ /* @__PURE__ */ V(D, { children: "Status" }),
309
+ /* @__PURE__ */ V(D, {
310
+ className: "text-right",
311
+ children: "Rows"
312
+ }),
313
+ /* @__PURE__ */ V(D, {
314
+ className: "text-right",
315
+ children: "Download"
316
+ })
317
+ ] }) }), /* @__PURE__ */ V(me, { children: F.map((e) => /* @__PURE__ */ H(O, {
318
+ className: e.id === L?.id ? "bg-surface-secondary" : void 0,
319
+ children: [
320
+ /* @__PURE__ */ V(E, { children: /* @__PURE__ */ V("button", {
321
+ type: "button",
322
+ className: "text-left font-medium text-text-primary underline-offset-2 hover:underline",
323
+ onClick: () => void Ze(e.id),
324
+ children: d(e.startedAt)
325
+ }) }),
326
+ /* @__PURE__ */ V(E, {
327
+ className: "whitespace-nowrap text-xs",
328
+ children: Ve(e)
329
+ }),
330
+ /* @__PURE__ */ V(E, { children: e.trigger === "SCHEDULED" ? "Scheduled" : "Manual" }),
331
+ /* @__PURE__ */ V(E, { children: /* @__PURE__ */ V(re, {
332
+ variant: Be(e.status),
333
+ children: e.status
334
+ }) }),
335
+ /* @__PURE__ */ V(E, {
336
+ className: "text-right",
337
+ children: e.rowCount.toLocaleString()
338
+ }),
339
+ /* @__PURE__ */ V(E, {
340
+ className: "text-right",
341
+ children: e.status === "COMPLETED" ? /* @__PURE__ */ V("span", {
342
+ className: "inline-flex gap-1",
343
+ children: ["CSV", "JSON"].map((t) => /* @__PURE__ */ V(m, {
344
+ variant: "ghost",
345
+ size: "sm",
346
+ disabled: U !== null,
347
+ onClick: () => void $e(e.id, t),
348
+ children: t
349
+ }, t))
350
+ }) : "—"
351
+ })
352
+ ]
353
+ }, e.id)) })] })
354
+ }) })] })
355
+ ] }) : !w && /* @__PURE__ */ V(h, { children: /* @__PURE__ */ V(g, {
356
+ className: "p-6 text-sm text-text-secondary",
357
+ children: "Select a report to see its latest figures and run history."
358
+ }) })
359
+ })]
360
+ }),
361
+ Ge && /* @__PURE__ */ V(We, {
362
+ report: Ge === "new" ? null : Ge,
363
+ defaultTimezone: y.timezone ?? "UTC",
364
+ onClose: () => q(null),
365
+ onSave: async (e, t) => {
366
+ let n = t ? await c(x, Ee, {
367
+ id: t.id,
368
+ input: Ae(e)
369
+ }, "SINGLE_ATTEMPT").then((e) => e.updateMtwReport) : await c(x, ye, { input: Ae(e) }, "SINGLE_ATTEMPT").then((e) => e.createMtwReport);
370
+ Ye(t ? `"${n.name}" saved.` : `"${n.name}" created.`), q(null), P(n.id), X();
371
+ }
372
+ }),
373
+ /* @__PURE__ */ V(oe, {
374
+ open: J !== null,
375
+ onOpenChange: (e) => !e && Y(null),
376
+ children: /* @__PURE__ */ H(se, { children: [/* @__PURE__ */ H(ue, { children: [/* @__PURE__ */ V(de, { children: "Delete this report?" }), /* @__PURE__ */ V(ce, { children: J ? `"${J.name}" stops being generated and leaves the list. This cannot be undone.` : "" })] }), /* @__PURE__ */ H(le, { children: [/* @__PURE__ */ V(m, {
377
+ variant: "outline",
378
+ onClick: () => Y(null),
379
+ children: "Cancel"
380
+ }), /* @__PURE__ */ H(m, {
381
+ variant: "destructive",
382
+ disabled: U !== null,
383
+ onClick: () => J && void et(J),
384
+ children: [U?.startsWith("delete:") && /* @__PURE__ */ V(r, {
385
+ size: 16,
386
+ className: "mr-2 animate-spin"
387
+ }), "Delete report"]
388
+ })] })] })
389
+ })
390
+ ]
391
+ });
392
+ }
393
+ function Ue({ run: e, isLoading: n, hasRuns: i, busy: a, onDownload: o }) {
394
+ return n && !e ? /* @__PURE__ */ V(h, { children: /* @__PURE__ */ H(g, {
395
+ className: "space-y-3 p-6",
396
+ "aria-busy": "true",
397
+ children: [/* @__PURE__ */ V(T, { className: "h-20 w-full" }), /* @__PURE__ */ V(T, { className: "h-40 w-full" })]
398
+ }) }) : e ? /* @__PURE__ */ H(h, {
399
+ "data-testid": "mtw-report-run",
400
+ children: [/* @__PURE__ */ H(ae, {
401
+ className: "flex flex-row flex-wrap items-start justify-between gap-3",
402
+ children: [/* @__PURE__ */ H("div", {
403
+ className: "space-y-1",
404
+ children: [/* @__PURE__ */ H(_, {
405
+ className: "text-base",
406
+ children: [
407
+ e.trigger === "SCHEDULED" ? "Scheduled run" : "Run",
408
+ " of",
409
+ " ",
410
+ d(e.startedAt)
411
+ ]
412
+ }), /* @__PURE__ */ H(ie, { children: ["Covers ", Ve(e)] })]
413
+ }), /* @__PURE__ */ H("div", {
414
+ className: "flex items-center gap-2",
415
+ children: [/* @__PURE__ */ V(re, {
416
+ variant: Be(e.status),
417
+ children: e.status
418
+ }), e.status === "COMPLETED" && ["CSV", "JSON"].map((n) => /* @__PURE__ */ H(m, {
419
+ variant: "outline",
420
+ size: "sm",
421
+ disabled: a !== null,
422
+ onClick: () => o(e.id, n),
423
+ children: [a === `download:${e.id}:${n}` ? /* @__PURE__ */ V(r, {
424
+ size: 14,
425
+ className: "mr-2 animate-spin"
426
+ }) : /* @__PURE__ */ V(t, {
427
+ size: 14,
428
+ className: "mr-2"
429
+ }), n]
430
+ }, n))]
431
+ })]
432
+ }), /* @__PURE__ */ H(g, {
433
+ className: "space-y-6",
434
+ children: [
435
+ e.status === "FAILED" && /* @__PURE__ */ V(A, { message: e.error ?? "This run failed." }),
436
+ e.metrics.length > 0 && /* @__PURE__ */ V("dl", {
437
+ className: "grid grid-cols-2 gap-3 md:grid-cols-3 lg:grid-cols-4",
438
+ children: e.metrics.map((e) => /* @__PURE__ */ H("div", {
439
+ className: "rounded-lg border border-border-default px-3 py-2",
440
+ children: [/* @__PURE__ */ V("dt", {
441
+ className: "text-xs text-text-secondary",
442
+ children: I(e)
443
+ }), /* @__PURE__ */ V("dd", {
444
+ className: "text-lg font-semibold text-text-primary",
445
+ children: F(e, W)
446
+ })]
447
+ }, e.key))
448
+ }),
449
+ e.status === "COMPLETED" && (e.rowCount === 0 ? /* @__PURE__ */ V("p", {
450
+ className: "text-sm text-text-secondary",
451
+ children: "The period had no rows for this report."
452
+ }) : /* @__PURE__ */ H("div", {
453
+ className: "space-y-2",
454
+ children: [/* @__PURE__ */ H("p", {
455
+ className: "text-xs text-text-secondary",
456
+ children: [
457
+ "Showing ",
458
+ Math.min(e.rows.length, e.rowCount).toLocaleString(),
459
+ " of",
460
+ " ",
461
+ e.rowCount.toLocaleString(),
462
+ " rows. Download the run for all of them.",
463
+ e.truncated && " The period had more rows than a run keeps (5,000); the figures above still cover all of them."
464
+ ]
465
+ }), /* @__PURE__ */ V("div", {
466
+ className: "max-h-[28rem] overflow-auto rounded-lg border border-border-default",
467
+ children: /* @__PURE__ */ H(pe, { children: [/* @__PURE__ */ V(he, { children: /* @__PURE__ */ V(O, { children: e.columns.map((e) => /* @__PURE__ */ V(D, {
468
+ className: "whitespace-nowrap",
469
+ children: e.label
470
+ }, e.key)) }) }), /* @__PURE__ */ V(me, { children: e.rows.map((t, n) => /* @__PURE__ */ V(O, { children: e.columns.map((e) => /* @__PURE__ */ V(E, {
471
+ className: "whitespace-nowrap text-xs",
472
+ children: e.kind === "CURRENCY" && typeof t[e.key] == "number" ? l(t[e.key], typeof t.currency == "string" ? t.currency : void 0) : P(t[e.key], e, (e) => u(e))
473
+ }, e.key)) }, n)) })] })
474
+ })]
475
+ }))
476
+ ]
477
+ })]
478
+ }) : /* @__PURE__ */ V(h, { children: /* @__PURE__ */ V(g, {
479
+ className: "p-6 text-sm text-text-secondary",
480
+ children: i ? "Select a run to preview it." : "This report has not been generated yet. Use \"Generate now\" to produce the first run."
481
+ }) });
482
+ }
483
+ function We({ report: e, defaultTimezone: t, onClose: n, onSave: i }) {
484
+ let [a, o] = B(() => e ? De(e) : L(t)), [ee, te] = B(String(a.periodDays)), [s, c] = B(!1), [l, u] = B(null), d = {
485
+ ...a,
486
+ periodDays: Number(ee)
487
+ }, f = R(d), p = (e, t) => {
488
+ u(null), o((n) => ({
489
+ ...n,
490
+ [e]: t
491
+ }));
492
+ }, ne = async (t) => {
493
+ if (t.preventDefault(), f) {
494
+ u(f);
495
+ return;
496
+ }
497
+ c(!0), u(null);
498
+ try {
499
+ await i(d, e);
500
+ } catch (e) {
501
+ u(G(e, "Could not save the report"));
502
+ } finally {
503
+ c(!1);
504
+ }
505
+ };
506
+ return /* @__PURE__ */ V(oe, {
507
+ open: !0,
508
+ onOpenChange: (e) => !e && !s && n(),
509
+ children: /* @__PURE__ */ H(se, {
510
+ className: "max-h-[90vh] overflow-y-auto sm:max-w-xl",
511
+ children: [/* @__PURE__ */ H(ue, { children: [/* @__PURE__ */ V(de, { children: e ? "Edit report" : "New report" }), /* @__PURE__ */ V(ce, { children: "Choose what the report covers and, if you like, when it is generated automatically." })] }), /* @__PURE__ */ H("form", {
512
+ className: "space-y-4",
513
+ onSubmit: (e) => void ne(e),
514
+ "aria-label": "Report",
515
+ children: [
516
+ /* @__PURE__ */ H("div", {
517
+ className: "space-y-2",
518
+ children: [/* @__PURE__ */ V(y, {
519
+ htmlFor: "mtw-report-name",
520
+ children: "Name"
521
+ }), /* @__PURE__ */ V(v, {
522
+ id: "mtw-report-name",
523
+ value: a.name,
524
+ maxLength: 120,
525
+ onChange: (e) => p("name", e.target.value),
526
+ placeholder: "Weekly operations review"
527
+ })]
528
+ }),
529
+ /* @__PURE__ */ H("div", {
530
+ className: "space-y-2",
531
+ children: [
532
+ /* @__PURE__ */ V(y, {
533
+ htmlFor: "mtw-report-type",
534
+ children: "Report type"
535
+ }),
536
+ /* @__PURE__ */ H(b, {
537
+ value: a.type,
538
+ onValueChange: (e) => {
539
+ let t = M.find((t) => t.value === e);
540
+ t && p("type", t.value);
541
+ },
542
+ children: [/* @__PURE__ */ V(C, {
543
+ id: "mtw-report-type",
544
+ "aria-label": "Report type",
545
+ children: /* @__PURE__ */ V(w, {})
546
+ }), /* @__PURE__ */ V(x, { children: M.map((e) => /* @__PURE__ */ V(S, {
547
+ value: e.value,
548
+ children: e.label
549
+ }, e.value)) })]
550
+ }),
551
+ /* @__PURE__ */ V("p", {
552
+ className: "text-xs text-text-secondary",
553
+ children: M.find((e) => e.value === a.type)?.description
554
+ })
555
+ ]
556
+ }),
557
+ /* @__PURE__ */ H("div", {
558
+ className: "space-y-2",
559
+ children: [/* @__PURE__ */ V(y, {
560
+ htmlFor: "mtw-report-description",
561
+ children: "Description (optional)"
562
+ }), /* @__PURE__ */ V(k, {
563
+ id: "mtw-report-description",
564
+ value: a.description,
565
+ maxLength: 1e3,
566
+ rows: 2,
567
+ onChange: (e) => p("description", e.target.value)
568
+ })]
569
+ }),
570
+ /* @__PURE__ */ H("div", {
571
+ className: "grid grid-cols-1 gap-4 md:grid-cols-2",
572
+ children: [/* @__PURE__ */ H("div", {
573
+ className: "space-y-2",
574
+ children: [/* @__PURE__ */ V(y, {
575
+ htmlFor: "mtw-report-frequency",
576
+ children: "Generate"
577
+ }), /* @__PURE__ */ H(b, {
578
+ value: a.frequency,
579
+ onValueChange: (t) => {
580
+ let n = j.find((e) => e.value === t);
581
+ n && (p("frequency", n.value), e || te(String(z(n.value))));
582
+ },
583
+ children: [/* @__PURE__ */ V(C, {
584
+ id: "mtw-report-frequency",
585
+ "aria-label": "Generate",
586
+ children: /* @__PURE__ */ V(w, {})
587
+ }), /* @__PURE__ */ V(x, { children: j.map((e) => /* @__PURE__ */ V(S, {
588
+ value: e.value,
589
+ children: e.label
590
+ }, e.value)) })]
591
+ })]
592
+ }), /* @__PURE__ */ H("div", {
593
+ className: "space-y-2",
594
+ children: [/* @__PURE__ */ V(y, {
595
+ htmlFor: "mtw-report-period",
596
+ children: "Covers the last (days)"
597
+ }), /* @__PURE__ */ V(v, {
598
+ id: "mtw-report-period",
599
+ type: "number",
600
+ inputMode: "numeric",
601
+ min: 1,
602
+ max: 366,
603
+ step: 1,
604
+ value: ee,
605
+ onChange: (e) => {
606
+ u(null), te(e.target.value);
607
+ }
608
+ })]
609
+ })]
610
+ }),
611
+ a.frequency !== "NONE" && /* @__PURE__ */ H("div", {
612
+ className: "grid grid-cols-1 gap-4 md:grid-cols-3",
613
+ children: [
614
+ a.frequency === "WEEKLY" && /* @__PURE__ */ H("div", {
615
+ className: "space-y-2",
616
+ children: [/* @__PURE__ */ V(y, {
617
+ htmlFor: "mtw-report-weekday",
618
+ children: "Day"
619
+ }), /* @__PURE__ */ H(b, {
620
+ value: String(a.runWeekday),
621
+ onValueChange: (e) => p("runWeekday", Number(e)),
622
+ children: [/* @__PURE__ */ V(C, {
623
+ id: "mtw-report-weekday",
624
+ "aria-label": "Day",
625
+ children: /* @__PURE__ */ V(w, {})
626
+ }), /* @__PURE__ */ V(x, { children: N.map((e, t) => /* @__PURE__ */ V(S, {
627
+ value: String(t + 1),
628
+ children: e
629
+ }, e)) })]
630
+ })]
631
+ }),
632
+ a.frequency === "MONTHLY" && /* @__PURE__ */ H("div", {
633
+ className: "space-y-2",
634
+ children: [/* @__PURE__ */ V(y, {
635
+ htmlFor: "mtw-report-monthday",
636
+ children: "Day of month"
637
+ }), /* @__PURE__ */ H(b, {
638
+ value: String(a.runMonthDay),
639
+ onValueChange: (e) => p("runMonthDay", Number(e)),
640
+ children: [/* @__PURE__ */ V(C, {
641
+ id: "mtw-report-monthday",
642
+ "aria-label": "Day of month",
643
+ children: /* @__PURE__ */ V(w, {})
644
+ }), /* @__PURE__ */ V(x, {
645
+ className: "max-h-72",
646
+ children: Array.from({ length: 28 }, (e, t) => /* @__PURE__ */ V(S, {
647
+ value: String(t + 1),
648
+ children: t + 1
649
+ }, t + 1))
650
+ })]
651
+ })]
652
+ }),
653
+ /* @__PURE__ */ H("div", {
654
+ className: "space-y-2",
655
+ children: [/* @__PURE__ */ V(y, {
656
+ htmlFor: "mtw-report-hour",
657
+ children: "Time"
658
+ }), /* @__PURE__ */ H(b, {
659
+ value: String(a.runHour),
660
+ onValueChange: (e) => p("runHour", Number(e)),
661
+ children: [/* @__PURE__ */ V(C, {
662
+ id: "mtw-report-hour",
663
+ "aria-label": "Time",
664
+ children: /* @__PURE__ */ V(w, {})
665
+ }), /* @__PURE__ */ V(x, {
666
+ className: "max-h-72",
667
+ children: Array.from({ length: 24 }, (e, t) => /* @__PURE__ */ V(S, {
668
+ value: String(t),
669
+ children: `${String(t).padStart(2, "0")}:00`
670
+ }, t))
671
+ })]
672
+ })]
673
+ }),
674
+ /* @__PURE__ */ H("div", {
675
+ className: "space-y-2",
676
+ children: [/* @__PURE__ */ V(y, {
677
+ htmlFor: "mtw-report-timezone",
678
+ children: "Time zone"
679
+ }), /* @__PURE__ */ V(v, {
680
+ id: "mtw-report-timezone",
681
+ value: a.timezone,
682
+ onChange: (e) => p("timezone", e.target.value),
683
+ placeholder: "Asia/Kolkata"
684
+ })]
685
+ })
686
+ ]
687
+ }),
688
+ a.frequency !== "NONE" && /* @__PURE__ */ H("div", {
689
+ className: "flex items-center justify-between gap-3 rounded-lg border border-border-default px-3 py-2",
690
+ children: [/* @__PURE__ */ V(y, {
691
+ htmlFor: "mtw-report-active",
692
+ className: "text-sm",
693
+ children: "Generate automatically"
694
+ }), /* @__PURE__ */ V(fe, {
695
+ id: "mtw-report-active",
696
+ checked: a.isActive,
697
+ onCheckedChange: (e) => p("isActive", e)
698
+ })]
699
+ }),
700
+ /* @__PURE__ */ V(A, { message: l }),
701
+ /* @__PURE__ */ H(le, { children: [/* @__PURE__ */ V(m, {
702
+ type: "button",
703
+ variant: "outline",
704
+ onClick: n,
705
+ disabled: s,
706
+ children: "Cancel"
707
+ }), /* @__PURE__ */ H(m, {
708
+ type: "submit",
709
+ disabled: s,
710
+ children: [s && /* @__PURE__ */ V(r, {
711
+ size: 16,
712
+ className: "mr-2 animate-spin"
713
+ }), e ? "Save report" : "Create report"]
714
+ })] })
715
+ ]
716
+ })]
717
+ })
718
+ });
719
+ }
720
+ //#endregion
721
+ export { He as default };