@nivaro/react 0.3.45 → 0.3.47

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.
Files changed (90) hide show
  1. package/dist/full.css +1 -1
  2. package/dist/hooks/useSessionRecorder.js +1 -1
  3. package/dist/index.d.ts +290 -23
  4. package/dist/index.js +679 -659
  5. package/dist/shared/components/BaseMap.js +149 -103
  6. package/dist/shared/components/CollectionBrowserView.js +813 -826
  7. package/dist/shared/components/ErrorNotice.js +169 -0
  8. package/dist/shared/components/ErrorSurface.js +23 -17
  9. package/dist/shared/components/ListLoadError.js +8 -29
  10. package/dist/shared/components/LoadErrorNote.js +38 -21
  11. package/dist/shared/components/QueryErrorState.js +8 -11
  12. package/dist/shared/components/ReportView.js +1320 -1291
  13. package/dist/shared/components/chat/ChannelArchive.js +60 -60
  14. package/dist/shared/components/chat/ChannelExtras.js +74 -74
  15. package/dist/shared/components/chat/ChatPanel.js +368 -367
  16. package/dist/shared/components/command-center/CommandCenterView.js +313 -69
  17. package/dist/shared/components/command-center/Customize.js +353 -0
  18. package/dist/shared/components/command-center/Header.js +279 -53
  19. package/dist/shared/components/command-center/KioskLinks.js +198 -0
  20. package/dist/shared/components/command-center/PeekPanel.js +144 -3
  21. package/dist/shared/components/command-center/announce.js +13 -0
  22. package/dist/shared/components/command-center/board-prefs.js +99 -0
  23. package/dist/shared/components/command-center/freshness.js +29 -0
  24. package/dist/shared/components/command-center/layout.js +56 -0
  25. package/dist/shared/components/command-center/panels/AttentionPanel.js +132 -3
  26. package/dist/shared/components/command-center/panels/Banner.js +75 -0
  27. package/dist/shared/components/command-center/panels/BoardSettings.js +224 -0
  28. package/dist/shared/components/command-center/panels/FeedPanel.js +145 -29
  29. package/dist/shared/components/command-center/panels/FlowPanel.js +154 -56
  30. package/dist/shared/components/command-center/panels/ForecastPanel.js +244 -3
  31. package/dist/shared/components/command-center/panels/MapLegend.js +266 -0
  32. package/dist/shared/components/command-center/panels/MapPanel.js +216 -66
  33. package/dist/shared/components/command-center/panels/PartnersPanel.js +49 -3
  34. package/dist/shared/components/command-center/panels/PeoplePanel.js +258 -40
  35. package/dist/shared/components/command-center/panels/RegionPicker.js +88 -3
  36. package/dist/shared/components/command-center/panels/SystemPanel.js +158 -38
  37. package/dist/shared/components/command-center/panels/ThroughputPanel.js +307 -3
  38. package/dist/shared/components/command-center/panels/TimeBar.js +227 -6
  39. package/dist/shared/components/command-center/panels/TrafficPanel.js +12 -8
  40. package/dist/shared/components/command-center/panels/WorkloadPanel.js +82 -3
  41. package/dist/shared/components/command-center/panels/attention-actions.js +267 -0
  42. package/dist/shared/components/command-center/panels/map-shared.js +95 -0
  43. package/dist/shared/components/command-center/panels/registry.js +87 -19
  44. package/dist/shared/components/command-center/shell-hooks.js +118 -0
  45. package/dist/shared/components/command-center/shortcuts.js +37 -0
  46. package/dist/shared/components/command-center/theme.js +39 -21
  47. package/dist/shared/components/command-center/time.js +52 -0
  48. package/dist/shared/components/command-center/url-state.js +54 -0
  49. package/dist/shared/components/command-center/work-links.js +32 -0
  50. package/dist/shared/components/help-videos/editor/ClipsPanel.js +49 -48
  51. package/dist/shared/components/help-videos/editor/PublishButton.js +37 -36
  52. package/dist/shared/components/help-videos/editor/StatsTab.js +45 -44
  53. package/dist/shared/components/help-videos/editor/VersionsTab.js +29 -28
  54. package/dist/shared/components/help-videos/library/AuthorRolesButton.js +19 -18
  55. package/dist/shared/components/help-videos/library/HelpVideoLibrary.js +132 -129
  56. package/dist/shared/components/help-videos/library/LearningPathsPanel.js +42 -41
  57. package/dist/shared/components/help-videos/settings/HouseStyleButton.js +21 -20
  58. package/dist/shared/components/help-videos/settings/RenderSettingsButton.js +22 -21
  59. package/dist/shared/components/import/DocumentAutofillButton.js +24 -20
  60. package/dist/shared/components/import/ImportFromFileButton.js +61 -60
  61. package/dist/shared/components/imports/ImportStalenessControl.js +20 -21
  62. package/dist/shared/components/imports/NewImportDialog.js +29 -28
  63. package/dist/shared/components/imports/RunDetailSheet.js +63 -63
  64. package/dist/shared/components/item-edit/FieldRow.js +329 -329
  65. package/dist/shared/components/item-edit/InlineTableField.js +898 -898
  66. package/dist/shared/components/item-edit/PersonalDefaultControl.js +57 -56
  67. package/dist/shared/components/item-edit/PlanGrid.js +220 -221
  68. package/dist/shared/components/item-edit/RecordGrantTools.js +49 -48
  69. package/dist/shared/components/item-edit/placement-behaviour.js +68 -67
  70. package/dist/shared/components/layout-editor/inspector/ColumnFit.js +24 -23
  71. package/dist/shared/components/layout-editor/inspector/PickerPreview.js +17 -16
  72. package/dist/shared/components/layout-editor/matrix/FieldStateMatrix.js +41 -41
  73. package/dist/shared/components/layout-editor/outputs/output-api.js +33 -31
  74. package/dist/shared/components/layout-editor/overview/overview-api.js +84 -83
  75. package/dist/shared/components/layout-editor/useLayoutDraft.js +47 -42
  76. package/dist/shared/components/monitoring/InactiveUserLinksView.js +10 -9
  77. package/dist/shared/components/monitoring/TrafficMiniMap.js +111 -70
  78. package/dist/shared/components/panels/SlaClock.js +35 -36
  79. package/dist/shared/components/pipeline/PipelineEditorView.js +311 -312
  80. package/dist/shared/components/pipeline/TeamSuggestions.js +31 -30
  81. package/dist/shared/components/profile/AgentsPanel.js +73 -72
  82. package/dist/shared/components/profile/MailSuppressedPill.js +22 -21
  83. package/dist/shared/components/support/SupportRequestDialog.js +85 -81
  84. package/dist/shared/components/support/SupportView.js +94 -87
  85. package/dist/shared/lib/autofill-poll.js +21 -18
  86. package/dist/shared/lib/error-actions.js +85 -0
  87. package/dist/shared/lib/error-message.js +223 -82
  88. package/dist/shared/lib/error-toast.js +71 -13
  89. package/dist/shared/lib/safe-error.js +136 -38
  90. package/package.json +1 -1
@@ -1,47 +1,47 @@
1
- import { jsxs as i, jsx as e, Fragment as Ge } from "react/jsx-runtime";
2
- import { saveReportFilterPreset as Ot, listReportFilterPresets as ma, deleteReportFilterPreset as ua, readReport as pa, executeCustomQuery as ha, readItems as fa, readReportFilterOptions as xa, aiReportFilters as ba, readReportWidgetData as yt, listReportAlerts as ga, createReportAlert as va, toggleReportAlert as ya, deleteReportAlert as ka, readReportAlertLog as Na, resolveReportAlert as wa } from "@nivaro/sdk";
3
- import { useQuery as ke, useQueryClient as Ct, useMutation as Me, isCancelledError as Sa } from "@tanstack/react-query";
4
- import { X as Ae, Check as Qt, Plus as Ut, Camera as Nt, Bell as Yt, RefreshCw as Mt, ChevronsUpDown as Jt, Sparkles as Kt, Info as _a, Table as Ca, Sigma as $a, StickyNote as qa, Download as Ma, TrendingUp as Vt, TrendingDown as Gt, Trash2 as Fa } from "lucide-react";
5
- import { useState as C, useEffect as wt, useCallback as Ft, useRef as St, useMemo as dt, Suspense as $t, lazy as Rt, memo as Aa } from "react";
6
- import { toast as Ht } from "sonner";
7
- import { useNivaroClient as Ke, useDrilldown as Xt, useOverlayState as Ta } from "../context.js";
8
- import { get as ot, post as ct, del as Ra, put as La } from "../lib/commands.js";
9
- import { useLiveWidget as Oa, liveWidgetInterval as Ka } from "../lib/live-widgets.js";
10
- import { serverErrorText as Zt, loadErrorText as At } from "../lib/load-error.js";
11
- import { buildReportTree as Da } from "../lib/report-tree.js";
12
- import { uniqueByValue as Pa } from "../lib/unique-options.js";
13
- import { useMyScopes as za, matchScopeDimension as ja, translateScopeValues as Dt, effectiveScopeSeedIds as Ea } from "../lib/use-my-scopes.js";
14
- import { cn as Q } from "../lib/utils.js";
15
- import { BackgroundRunOffer as It } from "./BackgroundRunOffer.js";
16
- import { RechartsGate as Le } from "./charts/RechartsGate.js";
17
- import { LoadErrorNote as ea } from "./LoadErrorNote.js";
18
- import { RecordDrilldownSheet as Wa } from "./RecordDrilldownSheet.js";
19
- import { TipLayer as Ba } from "./TipLayer.js";
20
- import { Command as Qa, CommandInput as Ua, CommandList as Ya, CommandEmpty as Ja, CommandItem as Va } from "./ui/command.js";
21
- import { Popover as ta, PopoverTrigger as aa, PopoverContent as la } from "./ui/popover.js";
22
- import { SimpleSelect as kt } from "./ui/SimpleSelect.js";
1
+ import { jsx as e, jsxs as i, Fragment as He } from "react/jsx-runtime";
2
+ import { saveReportFilterPreset as Kt, listReportFilterPresets as ua, deleteReportFilterPreset as pa, readReport as ha, executeCustomQuery as fa, readItems as xa, readReportFilterOptions as ba, aiReportFilters as ga, readReportWidgetData as kt, listReportAlerts as va, createReportAlert as ya, toggleReportAlert as ka, deleteReportAlert as Na, readReportAlertLog as wa, resolveReportAlert as Sa } from "@nivaro/sdk";
3
+ import { useQuery as Ne, useQueryClient as Ct, useMutation as Me, isCancelledError as _a } from "@tanstack/react-query";
4
+ import { X as Ae, Check as Ut, Plus as Vt, Camera as wt, Bell as Yt, RefreshCw as Ft, ChevronsUpDown as Jt, Sparkles as Dt, Info as Ca, Table as $a, Sigma as qa, StickyNote as Ma, Download as Fa, TrendingUp as Gt, TrendingDown as Ht, Trash2 as Aa } from "lucide-react";
5
+ import { useState as C, useEffect as mt, useCallback as At, useRef as St, useMemo as ut, Suspense as qt, lazy as Rt, memo as Ta } from "react";
6
+ import { toast as Xt } from "sonner";
7
+ import { useNivaroClient as Ke, useDrilldown as Zt, useOverlayState as La } from "../context.js";
8
+ import { get as ct, post as pt, del as Ra, put as Oa } from "../lib/commands.js";
9
+ import { useLiveWidget as Ka, liveWidgetInterval as Da } from "../lib/live-widgets.js";
10
+ import { serverErrorText as It, loadErrorText as Tt } from "../lib/load-error.js";
11
+ import { buildReportTree as Pa } from "../lib/report-tree.js";
12
+ import { uniqueByValue as za } from "../lib/unique-options.js";
13
+ import { useMyScopes as ja, matchScopeDimension as Ea, translateScopeValues as Pt, effectiveScopeSeedIds as Wa } from "../lib/use-my-scopes.js";
14
+ import { cn as j } from "../lib/utils.js";
15
+ import { BackgroundRunOffer as ea } from "./BackgroundRunOffer.js";
16
+ import { RechartsGate as Re } from "./charts/RechartsGate.js";
17
+ import { LoadErrorNote as ta } from "./LoadErrorNote.js";
18
+ import { RecordDrilldownSheet as Ba } from "./RecordDrilldownSheet.js";
19
+ import { TipLayer as Qa } from "./TipLayer.js";
20
+ import { Command as Ua, CommandInput as Va, CommandList as Ya, CommandEmpty as Ja, CommandItem as Ga } from "./ui/command.js";
21
+ import { Popover as aa, PopoverTrigger as la, PopoverContent as ra } from "./ui/popover.js";
22
+ import { SimpleSelect as Nt } from "./ui/SimpleSelect.js";
23
23
  import { Skeleton as Oe } from "./ui/skeleton.js";
24
- async function Ga(t, s) {
24
+ async function Ha(t, n) {
25
25
  const a = t == null ? void 0 : t.querySelector("svg");
26
26
  if (!(!a || typeof ClipboardItem > "u"))
27
27
  try {
28
- const o = a.getBoundingClientRect(), m = a.cloneNode(!0);
29
- m.setAttribute("width", String(o.width)), m.setAttribute("height", String(o.height));
30
- const u = new XMLSerializer().serializeToString(m), h = URL.createObjectURL(new Blob([u], { type: "image/svg+xml;charset=utf-8" })), f = new Image();
31
- await new Promise((P, c) => {
32
- f.onload = () => P(), f.onerror = () => c(new Error("svg load failed")), f.src = h;
28
+ const o = a.getBoundingClientRect(), c = a.cloneNode(!0);
29
+ c.setAttribute("width", String(o.width)), c.setAttribute("height", String(o.height));
30
+ const m = new XMLSerializer().serializeToString(c), h = URL.createObjectURL(new Blob([m], { type: "image/svg+xml;charset=utf-8" })), f = new Image();
31
+ await new Promise((E, u) => {
32
+ f.onload = () => E(), f.onerror = () => u(new Error("svg load failed")), f.src = h;
33
33
  });
34
34
  const p = 2, L = document.createElement("canvas");
35
35
  L.width = Math.max(1, Math.round(o.width * p)), L.height = Math.max(1, Math.round(o.height * p) + 28 * p);
36
- const $ = L.getContext("2d");
37
- if (!$) return;
38
- $.fillStyle = "#ffffff", $.fillRect(0, 0, L.width, L.height), $.fillStyle = "#172940", $.font = `${12 * p}px system-ui, sans-serif`, $.fillText(s || "Chart", 8 * p, 18 * p), $.drawImage(f, 0, 28 * p, o.width * p, o.height * p), URL.revokeObjectURL(h);
39
- const w = await new Promise((P) => L.toBlob(P, "image/png"));
36
+ const q = L.getContext("2d");
37
+ if (!q) return;
38
+ q.fillStyle = "#ffffff", q.fillRect(0, 0, L.width, L.height), q.fillStyle = "#172940", q.font = `${12 * p}px system-ui, sans-serif`, q.fillText(n || "Chart", 8 * p, 18 * p), q.drawImage(f, 0, 28 * p, o.width * p, o.height * p), URL.revokeObjectURL(h);
39
+ const w = await new Promise((E) => L.toBlob(E, "image/png"));
40
40
  w && await navigator.clipboard.write([new ClipboardItem({ "image/png": w })]);
41
41
  } catch {
42
42
  }
43
43
  }
44
- const Ce = (t) => Math.abs(t) >= 1e9 ? `${(t / 1e9).toFixed(1).replace(/\.0$/, "")}B` : Math.abs(t) >= 1e6 ? `${(t / 1e6).toFixed(1).replace(/\.0$/, "")}M` : Math.abs(t) >= 1e3 ? `${(t / 1e3).toFixed(1).replace(/\.0$/, "")}k` : String(t), Ha = [
44
+ const Ce = (t) => Math.abs(t) >= 1e9 ? `${(t / 1e9).toFixed(1).replace(/\.0$/, "")}B` : Math.abs(t) >= 1e6 ? `${(t / 1e6).toFixed(1).replace(/\.0$/, "")}M` : Math.abs(t) >= 1e3 ? `${(t / 1e3).toFixed(1).replace(/\.0$/, "")}k` : String(t), Xa = [
45
45
  "Jan",
46
46
  "Feb",
47
47
  "Mar",
@@ -54,18 +54,18 @@ const Ce = (t) => Math.abs(t) >= 1e9 ? `${(t / 1e9).toFixed(1).replace(/\.0$/, "
54
54
  "Oct",
55
55
  "Nov",
56
56
  "Dec"
57
- ], Xa = (t) => {
58
- const s = String(t ?? ""), a = /^(\d{4})-(\d{2})(?:-(\d{2}))?/.exec(s);
57
+ ], Za = (t) => {
58
+ const n = String(t ?? ""), a = /^(\d{4})-(\d{2})(?:-(\d{2}))?/.exec(n);
59
59
  if (a) {
60
- const o = Ha[Number(a[2]) - 1] ?? a[2];
60
+ const o = Xa[Number(a[2]) - 1] ?? a[2];
61
61
  return a[3] ? `${o} ${Number(a[3])}` : `${o} '${a[1].slice(2)}`;
62
62
  }
63
- return s.length > 16 ? `${s.slice(0, 15)}…` : s;
63
+ return n.length > 16 ? `${n.slice(0, 15)}…` : n;
64
64
  }, _t = (t) => ({
65
65
  interval: t > 12 ? Math.ceil(t / 12) - 1 : 0,
66
- tickFormatter: Xa,
66
+ tickFormatter: Za,
67
67
  minTickGap: 4
68
- }), Lt = () => import("./ReportEditMode.js"), Za = Rt(() => Lt().then((t) => ({ default: t.AddWidgetBar }))), Ia = Rt(() => Lt().then((t) => ({ default: t.WidgetConfigSheet }))), el = Rt(() => Lt().then((t) => ({ default: t.WidgetEditBar }))), Ve = "rgb(var(--nvr-cyan-rgb, 0 206 255))", ce = [Ve, "#172940", "#10b981", "#f59e0b", "#8b5cf6", "#ef4444", "#64748b"], tl = [
68
+ }), Ot = () => import("./ReportEditMode.js"), Ia = Rt(() => Ot().then((t) => ({ default: t.AddWidgetBar }))), el = Rt(() => Ot().then((t) => ({ default: t.WidgetConfigSheet }))), tl = Rt(() => Ot().then((t) => ({ default: t.WidgetEditBar }))), Ge = "rgb(var(--nvr-cyan-rgb, 0 206 255))", oe = [Ge, "#172940", "#10b981", "#f59e0b", "#8b5cf6", "#ef4444", "#64748b"], al = [
69
69
  { id: "", label: "All time" },
70
70
  { id: "this_month", label: "This month" },
71
71
  { id: "last_30_days", label: "Last 30 days" },
@@ -74,233 +74,233 @@ const Ce = (t) => Math.abs(t) >= 1e9 ? `${(t / 1e9).toFixed(1).replace(/\.0$/, "
74
74
  { id: "last_12_months", label: "Last 12 months" },
75
75
  { id: "ytd", label: "Year to date" }
76
76
  ];
77
- function qe(t, s) {
77
+ function qe(t, n) {
78
78
  if (t == null) return "—";
79
- const a = (s == null ? void 0 : s.decimals) != null ? t.toLocaleString(void 0, {
80
- minimumFractionDigits: s.decimals,
81
- maximumFractionDigits: s.decimals
79
+ const a = (n == null ? void 0 : n.decimals) != null ? t.toLocaleString(void 0, {
80
+ minimumFractionDigits: n.decimals,
81
+ maximumFractionDigits: n.decimals
82
82
  }) : t.toLocaleString();
83
- return `${(s == null ? void 0 : s.prefix) ?? ""}${a}${(s == null ? void 0 : s.suffix) ?? ""}`;
83
+ return `${(n == null ? void 0 : n.prefix) ?? ""}${a}${(n == null ? void 0 : n.suffix) ?? ""}`;
84
84
  }
85
- function Pt({ pct: t }) {
85
+ function zt({ pct: t }) {
86
86
  if (t == null) return null;
87
- const s = t >= 0;
87
+ const n = t >= 0;
88
88
  return /* @__PURE__ */ i(
89
89
  "span",
90
90
  {
91
- className: Q(
91
+ className: j(
92
92
  "inline-flex items-center gap-0.5 rounded px-1 py-px text-[10.5px] font-medium",
93
- s ? "bg-emerald-50 text-emerald-600 dark:bg-emerald-500/10 dark:text-emerald-400" : "bg-red-50 text-red-600 dark:bg-red-500/10 dark:text-red-400"
93
+ n ? "bg-emerald-50 text-emerald-600 dark:bg-emerald-500/10 dark:text-emerald-400" : "bg-red-50 text-red-600 dark:bg-red-500/10 dark:text-red-400"
94
94
  ),
95
95
  children: [
96
- s ? /* @__PURE__ */ e(Vt, { className: "h-2.5 w-2.5" }) : /* @__PURE__ */ e(Gt, { className: "h-2.5 w-2.5" }),
96
+ n ? /* @__PURE__ */ e(Gt, { className: "h-2.5 w-2.5" }) : /* @__PURE__ */ e(Ht, { className: "h-2.5 w-2.5" }),
97
97
  Math.abs(t),
98
98
  "%"
99
99
  ]
100
100
  }
101
101
  );
102
102
  }
103
- function ra({
103
+ function na({
104
104
  reportId: t,
105
- field: s,
105
+ field: n,
106
106
  label: a,
107
107
  optionSource: o,
108
- selected: m,
109
- onChange: u,
108
+ selected: c,
109
+ onChange: m,
110
110
  allowedValues: h
111
111
  }) {
112
- const f = Ke(), [p, L] = C(!1), { data: $ = [] } = ke({
113
- queryKey: ["nivaro-report-filter-opts", t, s, o ?? null],
112
+ const f = Ke(), [p, L] = C(!1), { data: q = [] } = Ne({
113
+ queryKey: ["nivaro-report-filter-opts", t, n, o ?? null],
114
114
  queryFn: async () => {
115
115
  if (o) {
116
- const c = o.value_field ?? "id", S = o.label_field ?? c, J = await f.request(
117
- fa(o.collection, {
118
- fields: [.../* @__PURE__ */ new Set(["id", c, S])],
116
+ const u = o.value_field ?? "id", N = o.label_field ?? u, U = await f.request(
117
+ xa(o.collection, {
118
+ fields: [.../* @__PURE__ */ new Set(["id", u, N])],
119
119
  sort: o.sort ? [o.sort] : void 0,
120
120
  limit: 200
121
121
  })
122
122
  );
123
- return Pa(
124
- (J.data ?? []).map((O) => ({
125
- value: String(O[c] ?? O.id),
126
- label: String(O[S] ?? O[c] ?? O.id)
123
+ return za(
124
+ (U.data ?? []).map((O) => ({
125
+ value: String(O[u] ?? O.id),
126
+ label: String(O[N] ?? O[u] ?? O.id)
127
127
  })),
128
128
  (O) => O.value
129
129
  );
130
130
  }
131
- return f.request(xa(t, s)).then((c) => c.data);
131
+ return f.request(ba(t, n)).then((u) => u.data);
132
132
  },
133
133
  enabled: p,
134
134
  staleTime: 12e4
135
- }), w = h != null && h.length ? $.filter((c) => h.some((S) => String(S) === c.value)) : $, P = m.length > 0;
136
- return /* @__PURE__ */ i(ta, { open: p, onOpenChange: L, children: [
137
- /* @__PURE__ */ e(aa, { asChild: !0, children: /* @__PURE__ */ i(
135
+ }), w = h != null && h.length ? q.filter((u) => h.some((N) => String(N) === u.value)) : q, E = c.length > 0;
136
+ return /* @__PURE__ */ i(aa, { open: p, onOpenChange: L, children: [
137
+ /* @__PURE__ */ e(la, { asChild: !0, children: /* @__PURE__ */ i(
138
138
  "button",
139
139
  {
140
140
  type: "button",
141
- className: Q(
141
+ className: j(
142
142
  "flex h-7 items-center gap-1.5 rounded-md border px-2 text-[12px]",
143
- P ? "border-nvr-cyan bg-accent font-medium text-nvr-navy dark:text-nvr-cyan" : "border-slate-200 text-slate-500 hover:border-slate-300 dark:border-border"
143
+ E ? "border-nvr-cyan bg-accent font-medium text-nvr-navy dark:text-nvr-cyan" : "border-slate-200 text-slate-500 hover:border-slate-300 dark:border-border"
144
144
  ),
145
145
  children: [
146
146
  a,
147
- P && /* @__PURE__ */ e("span", { className: "rounded-full bg-white/60 px-1 text-[10px] dark:bg-black/20", children: m.length }),
147
+ E && /* @__PURE__ */ e("span", { className: "rounded-full bg-white/60 px-1 text-[10px] dark:bg-black/20", children: c.length }),
148
148
  /* @__PURE__ */ e(Jt, { className: "h-3 w-3 opacity-50" })
149
149
  ]
150
150
  }
151
151
  ) }),
152
- /* @__PURE__ */ e(la, { className: "w-[240px] p-0", align: "start", children: /* @__PURE__ */ i(Qa, { children: [
153
- /* @__PURE__ */ e(Ua, { placeholder: `Filter ${a}…`, className: "h-8 text-[12.5px]" }),
152
+ /* @__PURE__ */ e(ra, { className: "w-[240px] p-0", align: "start", children: /* @__PURE__ */ i(Ua, { children: [
153
+ /* @__PURE__ */ e(Va, { placeholder: `Filter ${a}…`, className: "h-8 text-[12.5px]" }),
154
154
  /* @__PURE__ */ i(Ya, { className: "max-h-52", children: [
155
155
  /* @__PURE__ */ e(Ja, { children: "No values." }),
156
- w.map((c) => {
157
- const S = m.some((J) => String(J) === c.value);
156
+ w.map((u) => {
157
+ const N = c.some((U) => String(U) === u.value);
158
158
  return /* @__PURE__ */ i(
159
- Va,
159
+ Ga,
160
160
  {
161
- value: c.label,
161
+ value: u.label,
162
162
  onSelect: () => {
163
- const J = S ? m.filter((G) => String(G) !== c.value) : [...m, c.value], O = (G) => {
163
+ const U = N ? c.filter((ee) => String(ee) !== u.value) : [...c, u.value], O = (ee) => {
164
164
  var H;
165
- return ((H = $.find((me) => me.value === String(G))) == null ? void 0 : H.label) ?? String(G);
165
+ return ((H = q.find((ue) => ue.value === String(ee))) == null ? void 0 : H.label) ?? String(ee);
166
166
  };
167
- u(J, J.map(O));
167
+ m(U, U.map(O));
168
168
  },
169
169
  className: "text-[12.5px]",
170
170
  children: [
171
- /* @__PURE__ */ e(Qt, { className: Q("mr-1.5 h-3 w-3", S ? "opacity-100" : "opacity-0") }),
172
- c.label
171
+ /* @__PURE__ */ e(Ut, { className: j("mr-1.5 h-3 w-3", N ? "opacity-100" : "opacity-0") }),
172
+ u.label
173
173
  ]
174
174
  },
175
- c.value
175
+ u.value
176
176
  );
177
177
  })
178
178
  ] })
179
179
  ] }) })
180
180
  ] });
181
181
  }
182
- function na(t) {
182
+ function sa(t) {
183
183
  if (!t) return null;
184
- const s = /* @__PURE__ */ new Date(), a = (u) => {
184
+ const n = /* @__PURE__ */ new Date(), a = (m) => {
185
185
  const h = (f) => String(f).padStart(2, "0");
186
- return `${u.getFullYear()}-${h(u.getMonth() + 1)}-${h(u.getDate())}`;
187
- }, o = (u, h) => new Date(u, h, 1), m = (u) => new Date(u.getFullYear(), u.getMonth() + 1, 0);
186
+ return `${m.getFullYear()}-${h(m.getMonth() + 1)}-${h(m.getDate())}`;
187
+ }, o = (m, h) => new Date(m, h, 1), c = (m) => new Date(m.getFullYear(), m.getMonth() + 1, 0);
188
188
  switch (t.preset) {
189
189
  case "this_month":
190
- return { start: a(o(s.getFullYear(), s.getMonth())), end: a(m(s)) };
190
+ return { start: a(o(n.getFullYear(), n.getMonth())), end: a(c(n)) };
191
191
  case "last_30_days":
192
- return { start: a(new Date(s.getTime() - 30 * 864e5)), end: a(s) };
192
+ return { start: a(new Date(n.getTime() - 30 * 864e5)), end: a(n) };
193
193
  case "last_3_months":
194
- return { start: a(o(s.getFullYear(), s.getMonth() - 3)), end: a(m(s)) };
194
+ return { start: a(o(n.getFullYear(), n.getMonth() - 3)), end: a(c(n)) };
195
195
  case "last_6_months":
196
- return { start: a(o(s.getFullYear(), s.getMonth() - 6)), end: a(m(s)) };
196
+ return { start: a(o(n.getFullYear(), n.getMonth() - 6)), end: a(c(n)) };
197
197
  case "last_12_months":
198
- return { start: a(o(s.getFullYear(), s.getMonth() - 12)), end: a(m(s)) };
198
+ return { start: a(o(n.getFullYear(), n.getMonth() - 12)), end: a(c(n)) };
199
199
  case "ytd":
200
- return { start: `${s.getFullYear()}-01-01`, end: a(s) };
200
+ return { start: `${n.getFullYear()}-01-01`, end: a(n) };
201
201
  case "custom":
202
202
  return t.start && t.end ? { start: t.start, end: t.end } : null;
203
203
  default:
204
204
  return null;
205
205
  }
206
206
  }
207
- function Ee(t, s, a) {
207
+ function je(t, n, a) {
208
208
  if (t == null || t === "") return "—";
209
- if (s === "date" || s === "datetime") {
210
- const u = new Date(String(t));
211
- if (Number.isNaN(u.getTime())) return String(t);
212
- const h = u.toLocaleDateString();
213
- return s === "date" ? h : `${h} ${u.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" })}`;
209
+ if (n === "date" || n === "datetime") {
210
+ const m = new Date(String(t));
211
+ if (Number.isNaN(m.getTime())) return String(t);
212
+ const h = m.toLocaleDateString();
213
+ return n === "date" ? h : `${h} ${m.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" })}`;
214
214
  }
215
215
  const o = Number(t);
216
216
  if (Number.isNaN(o)) return String(t);
217
- const m = (u, h) => o.toLocaleString(void 0, {
218
- minimumFractionDigits: a ?? u,
217
+ const c = (m, h) => o.toLocaleString(void 0, {
218
+ minimumFractionDigits: a ?? m,
219
219
  maximumFractionDigits: a ?? h
220
220
  });
221
- return s === "currency" ? `$${m(0, 0)}` : s === "percent" ? `${m(0, 1)}%` : s === "days" ? `${m(0, 1)}d` : s === "integer" ? Math.round(o).toLocaleString() : s === "number" ? m(0, 2) : String(t);
221
+ return n === "currency" ? `$${c(0, 0)}` : n === "percent" ? `${c(0, 1)}%` : n === "days" ? `${c(0, 1)}d` : n === "integer" ? Math.round(o).toLocaleString() : n === "number" ? c(0, 2) : String(t);
222
222
  }
223
- const je = /* @__PURE__ */ new Set([
223
+ const ze = /* @__PURE__ */ new Set([
224
224
  "currency",
225
225
  "number",
226
226
  "integer",
227
227
  "percent",
228
228
  "days"
229
229
  ]);
230
- function sa(t, s, a) {
231
- const o = {}, m = na(s);
232
- for (const [u, h] of Object.entries(t.params ?? {})) {
230
+ function ia(t, n, a) {
231
+ const o = {}, c = sa(n);
232
+ for (const [m, h] of Object.entries(t.params ?? {})) {
233
233
  if (h === "$date.start") {
234
- m && (o[u] = m.start);
234
+ c && (o[m] = c.start);
235
235
  continue;
236
236
  }
237
237
  if (h === "$date.end") {
238
- m && (o[u] = m.end);
238
+ c && (o[m] = c.end);
239
239
  continue;
240
240
  }
241
241
  const f = /^\$filters\.([\w.]+?)(:values)?$/.exec(h);
242
242
  if (f) {
243
- const p = a.find(($) => $.field === f[1]), L = f[2] ? p == null ? void 0 : p.values : p != null && p.labels && p.labels.length > 0 ? p.labels : p == null ? void 0 : p.values;
244
- L && L.length > 0 && (o[u] = L.join(","));
243
+ const p = a.find((q) => q.field === f[1]), L = f[2] ? p == null ? void 0 : p.values : p != null && p.labels && p.labels.length > 0 ? p.labels : p == null ? void 0 : p.values;
244
+ L && L.length > 0 && (o[m] = L.join(","));
245
245
  continue;
246
246
  }
247
- o[u] = h;
247
+ o[m] = h;
248
248
  }
249
249
  return o;
250
250
  }
251
- const al = (t) => `$${Ce(Math.round(t))}`, ll = [
251
+ const ll = (t) => `$${Ce(Math.round(t))}`, rl = [
252
252
  { gte: 90, color: "#ef4444" },
253
253
  { gte: 70, color: "#f59e0b" },
254
254
  { gte: -1 / 0, color: "#10b981" }
255
255
  ];
256
- function rl({
256
+ function nl({
257
257
  rows: t,
258
- cfg: s,
258
+ cfg: n,
259
259
  onDrill: a
260
260
  }) {
261
- const o = s.tree, m = s.series && s.series.length > 0 ? s.series : Object.keys(t[0] ?? {}).filter((c) => {
262
- var S;
263
- return typeof ((S = t[0]) == null ? void 0 : S[c]) == "number";
264
- }).slice(0, 3).map((c) => ({ field: c, label: c })), u = dt(
265
- () => o ? Da(
261
+ const o = n.tree, c = n.series && n.series.length > 0 ? n.series : Object.keys(t[0] ?? {}).filter((u) => {
262
+ var N;
263
+ return typeof ((N = t[0]) == null ? void 0 : N[u]) == "number";
264
+ }).slice(0, 3).map((u) => ({ field: u, label: u })), m = ut(
265
+ () => o ? Pa(
266
266
  t,
267
267
  o,
268
- m.map((c) => c.field)
268
+ c.map((u) => u.field)
269
269
  ) : [],
270
270
  // eslint-disable-next-line react-hooks/exhaustive-deps
271
271
  [t, o]
272
272
  ), [h, f] = C(() => /* @__PURE__ */ new Set()), [p, L] = C(!1);
273
- wt(() => {
274
- if (p || u.length === 0) return;
275
- const c = /* @__PURE__ */ new Set(), S = (J) => {
276
- for (const O of J)
277
- (O.depth > 0 || u.length === 1) && c.add(O.key), S(O.children);
273
+ mt(() => {
274
+ if (p || m.length === 0) return;
275
+ const u = /* @__PURE__ */ new Set(), N = (U) => {
276
+ for (const O of U)
277
+ (O.depth > 0 || m.length === 1) && u.add(O.key), N(O.children);
278
278
  };
279
- S(u), f(c), L(!0);
280
- }, [u, p]);
281
- const $ = (o == null ? void 0 : o.thresholds) ?? ll, w = (c) => {
282
- var S;
283
- return c == null ? void 0 : ((S = $.find((J) => c >= J.gte)) == null ? void 0 : S.color) ?? "#10b981";
284
- }, P = (c) => {
285
- const S = c.children.length === 0, J = h.has(c.key), O = w(c.pct), G = S && (o == null ? void 0 : o.drill) && c.drillId != null;
286
- return /* @__PURE__ */ i("div", { style: { paddingLeft: c.depth === 0 ? 0 : 14 }, children: [
279
+ N(m), f(u), L(!0);
280
+ }, [m, p]);
281
+ const q = (o == null ? void 0 : o.thresholds) ?? rl, w = (u) => {
282
+ var N;
283
+ return u == null ? void 0 : ((N = q.find((U) => u >= U.gte)) == null ? void 0 : N.color) ?? "#10b981";
284
+ }, E = (u) => {
285
+ const N = u.children.length === 0, U = h.has(u.key), O = w(u.pct), ee = N && (o == null ? void 0 : o.drill) && u.drillId != null;
286
+ return /* @__PURE__ */ i("div", { style: { paddingLeft: u.depth === 0 ? 0 : 14 }, children: [
287
287
  /* @__PURE__ */ i(
288
288
  "div",
289
289
  {
290
- role: G || !S ? "button" : void 0,
291
- tabIndex: G || !S ? 0 : void 0,
292
- className: Q(
290
+ role: ee || !N ? "button" : void 0,
291
+ tabIndex: ee || !N ? 0 : void 0,
292
+ className: j(
293
293
  "group/tn rounded-md px-1.5 py-1",
294
- (G || !S) && "cursor-pointer hover:bg-slate-50 dark:hover:bg-muted/40"
294
+ (ee || !N) && "cursor-pointer hover:bg-slate-50 dark:hover:bg-muted/40"
295
295
  ),
296
296
  onClick: () => {
297
- S ? G && (o != null && o.drill) && a({
297
+ N ? ee && (o != null && o.drill) && a({
298
298
  collection: o.drill.collection,
299
- itemId: String(c.drillId),
300
- title: c.label
299
+ itemId: String(u.drillId),
300
+ title: u.label
301
301
  }) : f((H) => {
302
- const me = new Set(H);
303
- return me.has(c.key) ? me.delete(c.key) : me.add(c.key), me;
302
+ const ue = new Set(H);
303
+ return ue.has(u.key) ? ue.delete(u.key) : ue.add(u.key), ue;
304
304
  });
305
305
  },
306
306
  onKeyDown: (H) => {
@@ -308,78 +308,100 @@ function rl({
308
308
  },
309
309
  children: [
310
310
  /* @__PURE__ */ i("div", { className: "flex items-center gap-1.5", children: [
311
- S ? /* @__PURE__ */ e("span", { className: "w-3 shrink-0" }) : /* @__PURE__ */ e(
311
+ N ? /* @__PURE__ */ e("span", { className: "w-3 shrink-0" }) : /* @__PURE__ */ e(
312
312
  Jt,
313
313
  {
314
- className: Q(
314
+ className: j(
315
315
  "h-3 w-3 shrink-0 text-slate-400 transition-transform",
316
- J && "rotate-180"
316
+ U && "rotate-180"
317
317
  )
318
318
  }
319
319
  ),
320
- S && c.badge && /* @__PURE__ */ e("span", { className: "shrink-0 rounded bg-slate-100 px-1 py-px text-[9.5px] tabular-nums text-slate-500 dark:bg-muted dark:text-slate-400", children: c.badge }),
320
+ N && u.badge && /* @__PURE__ */ e("span", { className: "shrink-0 rounded bg-slate-100 px-1 py-px text-[9.5px] tabular-nums text-slate-500 dark:bg-muted dark:text-slate-400", children: u.badge }),
321
321
  /* @__PURE__ */ e(
322
322
  "span",
323
323
  {
324
- className: Q(
324
+ className: j(
325
325
  "min-w-0 flex-1 truncate",
326
- c.depth === 0 ? "text-[12px] font-semibold text-slate-800 dark:text-slate-100" : c.depth === 1 ? "text-[11.5px] font-medium text-slate-700 dark:text-slate-200" : Q(
326
+ u.depth === 0 ? "text-[12px] font-semibold text-slate-800 dark:text-slate-100" : u.depth === 1 ? "text-[11.5px] font-medium text-slate-700 dark:text-slate-200" : j(
327
327
  "text-[11px] text-slate-600 dark:text-slate-300",
328
- G && "group-hover/tn:underline"
328
+ ee && "group-hover/tn:underline"
329
329
  )
330
330
  ),
331
- children: c.label
331
+ children: u.label
332
332
  }
333
333
  ),
334
- (o == null ? void 0 : o.pct) && (c.pct == null ? /* @__PURE__ */ e("span", { className: "shrink-0 text-[10.5px] font-semibold tabular-nums text-slate-400", children: "—" }) : /* @__PURE__ */ i(
334
+ (o == null ? void 0 : o.pct) && (u.pct == null ? /* @__PURE__ */ e("span", { className: "shrink-0 text-[10.5px] font-semibold tabular-nums text-slate-400", children: "—" }) : /* @__PURE__ */ i(
335
335
  "span",
336
336
  {
337
337
  className: "shrink-0 text-[10.5px] font-semibold tabular-nums",
338
338
  style: { color: O },
339
339
  children: [
340
- c.pct.toFixed(1),
340
+ u.pct.toFixed(1),
341
341
  "%"
342
342
  ]
343
343
  }
344
344
  ))
345
345
  ] }),
346
- (o == null ? void 0 : o.pct) && c.pct != null && /* @__PURE__ */ e(
346
+ (o == null ? void 0 : o.pct) && u.pct != null && /* @__PURE__ */ e(
347
347
  "div",
348
348
  {
349
- className: Q(
349
+ className: j(
350
350
  "ml-[18px] mt-0.5 overflow-hidden rounded-full bg-slate-100 dark:bg-muted",
351
- c.depth === 0 ? "h-[5px]" : c.depth === 1 ? "h-[3px]" : "h-[2px]"
351
+ u.depth === 0 ? "h-[5px]" : u.depth === 1 ? "h-[3px]" : "h-[2px]"
352
352
  ),
353
353
  children: /* @__PURE__ */ e(
354
354
  "div",
355
355
  {
356
356
  className: "h-full rounded-full transition-[width] duration-300",
357
- style: { width: `${Math.min(Math.max(c.pct, 0), 100)}%`, background: O }
357
+ style: { width: `${Math.min(Math.max(u.pct, 0), 100)}%`, background: O }
358
358
  }
359
359
  )
360
360
  }
361
361
  ),
362
- /* @__PURE__ */ e("div", { className: "ml-[18px] mt-0.5 flex flex-wrap gap-x-3 text-[10px] tabular-nums text-slate-400", children: m.map((H) => /* @__PURE__ */ i("span", { children: [
362
+ /* @__PURE__ */ e("div", { className: "ml-[18px] mt-0.5 flex flex-wrap gap-x-3 text-[10px] tabular-nums text-slate-400", children: c.map((H) => /* @__PURE__ */ i("span", { children: [
363
363
  H.label ?? H.field,
364
364
  " ",
365
- /* @__PURE__ */ e("span", { className: "font-medium text-slate-500 dark:text-slate-300", children: c.sums[H.field] == null ? H.empty_label ?? "—" : s.value_format === "currency" ? al(c.sums[H.field]) : c.sums[H.field].toLocaleString() })
365
+ /* @__PURE__ */ e("span", { className: "font-medium text-slate-500 dark:text-slate-300", children: u.sums[H.field] == null ? H.empty_label ?? "—" : n.value_format === "currency" ? ll(u.sums[H.field]) : u.sums[H.field].toLocaleString() })
366
366
  ] }, H.field)) })
367
367
  ]
368
368
  }
369
369
  ),
370
- J && c.children.map(P)
371
- ] }, c.key);
370
+ U && u.children.map(E)
371
+ ] }, u.key);
372
372
  };
373
- return !o || u.length === 0 ? /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-400", children: "No data." }) : /* @__PURE__ */ e("div", { className: "min-h-0 flex-1 space-y-0.5 overflow-y-auto pr-1", children: u.map(P) });
373
+ return !o || m.length === 0 ? /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-400", children: "No data." }) : /* @__PURE__ */ e("div", { className: "min-h-0 flex-1 space-y-0.5 overflow-y-auto pr-1", children: m.map(E) });
374
374
  }
375
- function nl(t) {
376
- const s = Ke(), a = St(!1);
375
+ function sl(t) {
376
+ const [n, a] = C(() => typeof IntersectionObserver > "u");
377
+ return mt(() => {
378
+ if (n) return;
379
+ const o = t.current;
380
+ if (!o) {
381
+ a(!0);
382
+ return;
383
+ }
384
+ const c = new IntersectionObserver(
385
+ (h) => {
386
+ h.some((f) => f.isIntersecting) && a(!0);
387
+ },
388
+ { rootMargin: "600px 0px" }
389
+ );
390
+ c.observe(o);
391
+ const m = () => a(!0);
392
+ return window.addEventListener("beforeprint", m), () => {
393
+ c.disconnect(), window.removeEventListener("beforeprint", m);
394
+ };
395
+ }, [n, t]), n;
396
+ }
397
+ function il(t) {
398
+ const n = Ke(), a = St(!1);
377
399
  return async (o) => {
378
400
  if (!(!t || a.current)) {
379
401
  a.current = !0;
380
402
  try {
381
- const u = (await s.request(ct("/report-studio/drill-row", { values: o }))).data;
382
- u != null && u.collection && u.item_id && t({ collection: u.collection, itemId: u.item_id });
403
+ const m = (await n.request(pt("/report-studio/drill-row", { values: o }))).data;
404
+ m != null && m.collection && m.item_id && t({ collection: m.collection, itemId: m.item_id });
383
405
  } catch {
384
406
  } finally {
385
407
  a.current = !1;
@@ -387,162 +409,166 @@ function nl(t) {
387
409
  }
388
410
  };
389
411
  }
390
- function ia(t, s) {
391
- let a = s;
412
+ function oa(t, n) {
413
+ let a = n;
392
414
  if (t.group_rows && t.x_field) {
393
- const o = /* @__PURE__ */ new Map(), m = new Set(
394
- (t.series ?? []).map((u) => u.field).length > 0 ? (t.series ?? []).map((u) => u.field) : Object.keys(a[0] ?? {}).filter((u) => {
415
+ const o = /* @__PURE__ */ new Map(), c = new Set(
416
+ (t.series ?? []).map((m) => m.field).length > 0 ? (t.series ?? []).map((m) => m.field) : Object.keys(a[0] ?? {}).filter((m) => {
395
417
  var h;
396
- return typeof ((h = a[0]) == null ? void 0 : h[u]) == "number";
418
+ return typeof ((h = a[0]) == null ? void 0 : h[m]) == "number";
397
419
  })
398
420
  );
399
- for (const u of a) {
400
- const h = String(u[t.x_field] ?? "Unknown"), f = o.get(h) ?? { [t.x_field]: h };
401
- for (const p of m) f[p] = (Number(f[p]) || 0) + (Number(u[p]) || 0);
421
+ for (const m of a) {
422
+ const h = String(m[t.x_field] ?? "Unknown"), f = o.get(h) ?? { [t.x_field]: h };
423
+ for (const p of c) f[p] = (Number(f[p]) || 0) + (Number(m[p]) || 0);
402
424
  o.set(h, f);
403
425
  }
404
426
  a = [...o.values()];
405
427
  }
406
428
  if (t.sort) {
407
- const o = t.sort.startsWith("-"), m = o ? t.sort.slice(1) : t.sort;
408
- a = [...a].sort((u, h) => {
409
- const f = u[m], p = h[m], L = typeof f == "number" && typeof p == "number" ? f - p : String(f ?? "").localeCompare(String(p ?? ""));
429
+ const o = t.sort.startsWith("-"), c = o ? t.sort.slice(1) : t.sort;
430
+ a = [...a].sort((m, h) => {
431
+ const f = m[c], p = h[c], L = typeof f == "number" && typeof p == "number" ? f - p : String(f ?? "").localeCompare(String(p ?? ""));
410
432
  return o ? -L : L;
411
433
  });
412
434
  }
413
435
  return t.limit && t.limit > 0 && (a = a.slice(0, t.limit)), a;
414
436
  }
415
- function oa(t, s, a, o) {
416
- const m = ha(s, a);
417
- return t.request(o ? { ...m, _signal: o } : m).then((u) => u.data ?? []);
437
+ function da(t, n, a, o) {
438
+ const c = fa(n, a);
439
+ return t.request(o ? { ...c, _signal: o } : c).then((m) => m.data ?? []);
418
440
  }
419
- function sl({
441
+ function ol({
420
442
  cfg: t,
421
- dateRange: s,
443
+ dateRange: n,
422
444
  entityFilters: a,
423
445
  refetchInterval: o,
424
- onStatus: m,
425
- onDrill: u
446
+ onStatus: c,
447
+ onDrill: m,
448
+ deferred: h = !1
426
449
  }) {
427
- var ue, le;
428
- const h = Ke(), f = nl(u), [p, L] = C(""), [$, w] = C(0), [P, c] = C(null), S = sa(t, s, a), { data: J, isLoading: O, error: G, isFetching: H, refetch: me } = ke({
429
- queryKey: ["nivaro-report-query", t.slug, S],
430
- queryFn: ({ signal: v }) => oa(h, t.slug, S, v),
450
+ var le, ae;
451
+ const f = Ke(), p = il(m), [L, q] = C(""), [w, E] = C(0), [u, N] = C(null), U = ia(t, n, a), { data: O, isLoading: ee, error: H, isFetching: ue, refetch: pe } = Ne({
452
+ queryKey: ["nivaro-report-query", t.slug, U],
453
+ queryFn: ({ signal: S }) => da(f, t.slug, U, S),
454
+ enabled: !h,
431
455
  staleTime: 6e4,
432
456
  refetchInterval: o,
433
457
  retry: !1
434
458
  });
435
- if (wt(() => {
436
- m == null || m({ isFetching: H, refetch: () => void me() });
437
- }, [H]), O)
459
+ if (mt(() => {
460
+ c == null || c({ isFetching: ue, refetch: () => void pe() });
461
+ }, [ue]), h && O === void 0)
462
+ return /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-300", children: "Loading…" });
463
+ if (ee)
438
464
  return /* @__PURE__ */ i("div", { className: "flex flex-col gap-2 px-1", children: [
439
465
  /* @__PURE__ */ e("p", { className: "text-[12px] text-slate-300", children: "Loading…" }),
440
466
  /* @__PURE__ */ e(
441
- It,
467
+ ea,
442
468
  {
443
469
  pending: !0,
444
470
  request: {
445
471
  method: "POST",
446
472
  url: `/custom-queries/${t.slug}/execute`,
447
- body: { params: S }
473
+ body: { params: U }
448
474
  },
449
475
  label: `Query ${t.slug}`,
450
- queryKey: ["nivaro-report-query", t.slug, S],
451
- select: (v) => (v == null ? void 0 : v.data) ?? []
476
+ queryKey: ["nivaro-report-query", t.slug, U],
477
+ select: (S) => (S == null ? void 0 : S.data) ?? []
452
478
  }
453
479
  )
454
480
  ] });
455
- if (G)
481
+ if (H)
456
482
  return /* @__PURE__ */ e(
457
- ea,
483
+ ta,
458
484
  {
459
485
  className: "px-1",
460
- message: Zt(G) ?? At(G, "this query"),
461
- onRetry: () => void me()
486
+ message: It(H) ?? Tt(H, "this query"),
487
+ onRetry: () => void pe()
462
488
  }
463
489
  );
464
- const Z = ia(t, J ?? []);
465
- if (Z.length === 0) return /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-400", children: "No data." });
466
- const te = t.columns && t.columns.length > 0 ? t.columns : Object.keys(Z[0] ?? {}).map((v) => ({ field: v }));
490
+ const X = oa(t, O ?? []);
491
+ if (X.length === 0) return /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-400", children: "No data." });
492
+ const de = t.columns && t.columns.length > 0 ? t.columns : Object.keys(X[0] ?? {}).map((S) => ({ field: S }));
467
493
  if (t.display === "kpis") {
468
- const v = t.x_field ? Z.map((A, X) => {
469
- var K, ie, oe, pe, M;
494
+ const S = t.x_field ? X.map((T, P) => {
495
+ var Y, ne, ce, fe, _;
470
496
  return {
471
- label: String(A[t.x_field] ?? ""),
472
- value: A[((ie = (K = t.series) == null ? void 0 : K[0]) == null ? void 0 : ie.field) ?? ((oe = te.find((z) => z.field !== t.x_field)) == null ? void 0 : oe.field) ?? ""],
473
- color: ((M = (pe = t.series) == null ? void 0 : pe[0]) == null ? void 0 : M.color) ?? ce[X % ce.length],
497
+ label: String(T[t.x_field] ?? ""),
498
+ value: T[((ne = (Y = t.series) == null ? void 0 : Y[0]) == null ? void 0 : ne.field) ?? ((ce = de.find((D) => D.field !== t.x_field)) == null ? void 0 : ce.field) ?? ""],
499
+ color: ((_ = (fe = t.series) == null ? void 0 : fe[0]) == null ? void 0 : _.color) ?? oe[P % oe.length],
474
500
  format: t.value_format
475
501
  };
476
- }) : te.map((A, X) => {
477
- var K;
502
+ }) : de.map((T, P) => {
503
+ var Y;
478
504
  return {
479
- label: A.label ?? A.field,
480
- value: (K = Z[0]) == null ? void 0 : K[A.field],
481
- color: ce[X % ce.length],
482
- format: A.format ?? t.value_format
505
+ label: T.label ?? T.field,
506
+ value: (Y = X[0]) == null ? void 0 : Y[T.field],
507
+ color: oe[P % oe.length],
508
+ format: T.format ?? t.value_format
483
509
  };
484
510
  });
485
511
  return /* @__PURE__ */ e(
486
512
  "div",
487
513
  {
488
514
  className: "grid gap-2",
489
- style: { gridTemplateColumns: `repeat(${Math.min(6, Math.max(1, v.length))}, 1fr)` },
490
- children: v.map((A) => /* @__PURE__ */ i(
515
+ style: { gridTemplateColumns: `repeat(${Math.min(6, Math.max(1, S.length))}, 1fr)` },
516
+ children: S.map((T) => /* @__PURE__ */ i(
491
517
  "div",
492
518
  {
493
519
  className: "flex flex-col justify-center rounded-md border border-slate-100 px-3 py-2 dark:border-border/60",
494
- style: { borderTopColor: A.color, borderTopWidth: 2 },
520
+ style: { borderTopColor: T.color, borderTopWidth: 2 },
495
521
  children: [
496
- /* @__PURE__ */ e("p", { className: "truncate text-[10.5px] uppercase tracking-wide text-slate-400", children: A.label }),
497
- /* @__PURE__ */ e("p", { className: "text-[19px] font-semibold leading-tight text-slate-900 dark:text-foreground", children: Ee(A.value, A.format ?? "integer") })
522
+ /* @__PURE__ */ e("p", { className: "truncate text-[10.5px] uppercase tracking-wide text-slate-400", children: T.label }),
523
+ /* @__PURE__ */ e("p", { className: "text-[19px] font-semibold leading-tight text-slate-900 dark:text-foreground", children: je(T.value, T.format ?? "integer") })
498
524
  ]
499
525
  },
500
- A.label
526
+ T.label
501
527
  ))
502
528
  }
503
529
  );
504
530
  }
505
531
  if (t.display === "tree")
506
- return /* @__PURE__ */ e(rl, { rows: Z, cfg: t, onDrill: (v) => u == null ? void 0 : u(v) });
532
+ return /* @__PURE__ */ e(nl, { rows: X, cfg: t, onDrill: (S) => m == null ? void 0 : m(S) });
507
533
  if (t.display === "table") {
508
- const v = te.filter((M) => je.has(M.format ?? "")), A = p.trim().toLowerCase(), X = A ? Z.filter(
509
- (M) => Object.values(M).some(
510
- (z) => String(z ?? "").toLowerCase().includes(A)
534
+ const S = de.filter((_) => ze.has(_.format ?? "")), T = L.trim().toLowerCase(), P = T ? X.filter(
535
+ (_) => Object.values(_).some(
536
+ (D) => String(D ?? "").toLowerCase().includes(T)
511
537
  )
512
- ) : Z, K = 12, ie = Math.max(1, Math.ceil(X.length / K)), oe = Math.min($, ie - 1), pe = X.length > K ? X.slice(oe * K, oe * K + K) : X;
538
+ ) : X, Y = 12, ne = Math.max(1, Math.ceil(P.length / Y)), ce = Math.min(w, ne - 1), fe = P.length > Y ? P.slice(ce * Y, ce * Y + Y) : P;
513
539
  return /* @__PURE__ */ i("div", { className: "flex min-h-0 flex-1 flex-col", children: [
514
- Z.length > K && /* @__PURE__ */ i("div", { className: "mb-1 flex items-center gap-2", children: [
540
+ X.length > Y && /* @__PURE__ */ i("div", { className: "mb-1 flex items-center gap-2", children: [
515
541
  /* @__PURE__ */ e(
516
542
  "input",
517
543
  {
518
- value: p,
519
- onChange: (M) => {
520
- L(M.target.value), w(0);
544
+ value: L,
545
+ onChange: (_) => {
546
+ q(_.target.value), E(0);
521
547
  },
522
548
  placeholder: "Search rows…",
523
549
  className: "h-6 w-40 rounded border border-slate-200 bg-white px-1.5 text-[11px] dark:border-border dark:bg-card dark:text-slate-200"
524
550
  }
525
551
  ),
526
- ie > 1 && /* @__PURE__ */ i("span", { className: "ml-auto flex items-center gap-1 text-[10.5px] text-slate-400", children: [
552
+ ne > 1 && /* @__PURE__ */ i("span", { className: "ml-auto flex items-center gap-1 text-[10.5px] text-slate-400", children: [
527
553
  /* @__PURE__ */ e(
528
554
  "button",
529
555
  {
530
556
  type: "button",
531
- disabled: oe <= 0,
532
- onClick: () => w(oe - 1),
557
+ disabled: ce <= 0,
558
+ onClick: () => E(ce - 1),
533
559
  className: "rounded px-1 disabled:opacity-30",
534
560
  children: "←"
535
561
  }
536
562
  ),
537
- oe + 1,
563
+ ce + 1,
538
564
  "/",
539
- ie,
565
+ ne,
540
566
  /* @__PURE__ */ e(
541
567
  "button",
542
568
  {
543
569
  type: "button",
544
- disabled: oe >= ie - 1,
545
- onClick: () => w(oe + 1),
570
+ disabled: ce >= ne - 1,
571
+ onClick: () => E(ce + 1),
546
572
  className: "rounded px-1 disabled:opacity-30",
547
573
  children: "→"
548
574
  }
@@ -550,119 +576,119 @@ function sl({
550
576
  ] })
551
577
  ] }),
552
578
  /* @__PURE__ */ e("div", { className: "min-h-0 flex-1 overflow-auto", children: /* @__PURE__ */ i("table", { className: "w-full text-[11.5px]", children: [
553
- /* @__PURE__ */ e("thead", { className: "sticky top-0 z-[1] bg-white dark:bg-card", children: /* @__PURE__ */ e("tr", { children: te.map((M) => /* @__PURE__ */ e(
579
+ /* @__PURE__ */ e("thead", { className: "sticky top-0 z-[1] bg-white dark:bg-card", children: /* @__PURE__ */ e("tr", { children: de.map((_) => /* @__PURE__ */ e(
554
580
  "th",
555
581
  {
556
- className: Q(
582
+ className: j(
557
583
  "whitespace-nowrap border-b border-slate-100 px-1.5 py-1 text-left font-medium text-slate-400 dark:border-border",
558
- je.has(M.format ?? "") && "text-right"
584
+ ze.has(_.format ?? "") && "text-right"
559
585
  ),
560
- children: M.label ?? M.field
586
+ children: _.label ?? _.field
561
587
  },
562
- M.field
588
+ _.field
563
589
  )) }) }),
564
- /* @__PURE__ */ e("tbody", { children: pe.map((M, z) => /* @__PURE__ */ e(
590
+ /* @__PURE__ */ e("tbody", { children: fe.map((_, D) => /* @__PURE__ */ e(
565
591
  "tr",
566
592
  {
567
- className: u ? "cursor-pointer hover:bg-slate-50 dark:hover:bg-muted/60" : void 0,
568
- onClick: () => void f(M),
569
- title: u ? "Open the record behind this row" : void 0,
570
- children: te.map((de) => /* @__PURE__ */ e(
593
+ className: m ? "cursor-pointer hover:bg-slate-50 dark:hover:bg-muted/60" : void 0,
594
+ onClick: () => void p(_),
595
+ title: m ? "Open the record behind this row" : void 0,
596
+ children: de.map((me) => /* @__PURE__ */ e(
571
597
  "td",
572
598
  {
573
- className: Q(
599
+ className: j(
574
600
  "max-w-[220px] truncate border-b border-slate-50 px-1.5 py-1 text-slate-700 dark:border-border/40 dark:text-slate-300",
575
- je.has(de.format ?? "") && "text-right tabular-nums"
601
+ ze.has(me.format ?? "") && "text-right tabular-nums"
576
602
  ),
577
- children: Ee(M[de.field], de.format, de.decimals)
603
+ children: je(_[me.field], me.format, me.decimals)
578
604
  },
579
- de.field
605
+ me.field
580
606
  ))
581
607
  },
582
- z
608
+ D
583
609
  )) }),
584
- t.totals && v.length > 0 && /* @__PURE__ */ e("tfoot", { className: "sticky bottom-0 bg-white dark:bg-card", children: /* @__PURE__ */ e("tr", { children: te.map((M, z) => /* @__PURE__ */ e(
610
+ t.totals && S.length > 0 && /* @__PURE__ */ e("tfoot", { className: "sticky bottom-0 bg-white dark:bg-card", children: /* @__PURE__ */ e("tr", { children: de.map((_, D) => /* @__PURE__ */ e(
585
611
  "td",
586
612
  {
587
- className: Q(
613
+ className: j(
588
614
  "border-t border-slate-200 px-1.5 py-1 font-semibold text-slate-800 dark:border-border dark:text-slate-200",
589
- je.has(M.format ?? "") && "text-right tabular-nums"
615
+ ze.has(_.format ?? "") && "text-right tabular-nums"
590
616
  ),
591
- children: z === 0 && !je.has(M.format ?? "") ? "Total" : je.has(M.format ?? "") ? Ee(
592
- Z.reduce((de, ge) => de + (Number(ge[M.field]) || 0), 0),
593
- M.format,
594
- M.decimals
617
+ children: D === 0 && !ze.has(_.format ?? "") ? "Total" : ze.has(_.format ?? "") ? je(
618
+ X.reduce((me, ve) => me + (Number(ve[_.field]) || 0), 0),
619
+ _.format,
620
+ _.decimals
595
621
  ) : ""
596
622
  },
597
- M.field
623
+ _.field
598
624
  )) }) })
599
625
  ] }) })
600
626
  ] });
601
627
  }
602
- const se = t.x_field ?? ((ue = te[0]) == null ? void 0 : ue.field) ?? "", fe = t.series && t.series.length > 0 ? t.series : te.filter((v) => {
603
- var A;
604
- return v.field !== se && typeof ((A = Z[0]) == null ? void 0 : A[v.field]) == "number";
605
- }).slice(0, 3).map((v) => ({ field: v.field, label: v.label ?? v.field })), be = Z.map((v) => {
606
- const A = { [se]: v[se] };
607
- for (const X of fe) A[X.field] = Number(v[X.field]) || 0;
608
- return A;
609
- }), Se = (v) => t.value_format === "currency" ? `$${Ce(v)}` : Ce(v), _e = (v) => Ee(v, t.value_format ?? "number"), x = t.display === "hbar" || t.display === "stacked_bar" && t.horizontal, I = (v) => {
610
- if (!u) return;
611
- const A = (J ?? []).filter((X) => String(X[se] ?? "") === v);
612
- A.length > 0 && c({ label: v, rows: A });
613
- }, ae = P ? /* @__PURE__ */ e(
628
+ const xe = t.x_field ?? ((le = de[0]) == null ? void 0 : le.field) ?? "", be = t.series && t.series.length > 0 ? t.series : de.filter((S) => {
629
+ var T;
630
+ return S.field !== xe && typeof ((T = X[0]) == null ? void 0 : T[S.field]) == "number";
631
+ }).slice(0, 3).map((S) => ({ field: S.field, label: S.label ?? S.field })), ge = X.map((S) => {
632
+ const T = { [xe]: S[xe] };
633
+ for (const P of be) T[P.field] = Number(S[P.field]) || 0;
634
+ return T;
635
+ }), $e = (S) => t.value_format === "currency" ? `$${Ce(S)}` : Ce(S), x = (S) => je(S, t.value_format ?? "number"), Z = t.display === "hbar" || t.display === "stacked_bar" && t.horizontal, te = (S) => {
636
+ if (!m) return;
637
+ const T = (O ?? []).filter((P) => String(P[xe] ?? "") === S);
638
+ T.length > 0 && N({ label: S, rows: T });
639
+ }, V = u ? /* @__PURE__ */ e(
614
640
  "div",
615
641
  {
616
642
  className: "fixed inset-0 z-[126] flex items-center justify-center bg-black/30 p-6",
617
- onClick: () => c(null),
643
+ onClick: () => N(null),
618
644
  children: /* @__PURE__ */ i(
619
645
  "div",
620
646
  {
621
647
  className: "flex max-h-[70vh] w-full max-w-2xl flex-col overflow-hidden rounded-xl border border-slate-200 bg-white shadow-2xl dark:border-border dark:bg-card",
622
- onClick: (v) => v.stopPropagation(),
648
+ onClick: (S) => S.stopPropagation(),
623
649
  children: [
624
650
  /* @__PURE__ */ i("div", { className: "flex items-center gap-2 border-b border-slate-100 px-4 py-2.5 dark:border-border", children: [
625
- /* @__PURE__ */ e("p", { className: "min-w-0 flex-1 truncate text-[13px] font-semibold text-slate-800 dark:text-slate-100", children: P.label }),
651
+ /* @__PURE__ */ e("p", { className: "min-w-0 flex-1 truncate text-[13px] font-semibold text-slate-800 dark:text-slate-100", children: u.label }),
626
652
  /* @__PURE__ */ i("span", { className: "text-[11.5px] text-slate-400", children: [
627
- P.rows.length,
653
+ u.rows.length,
628
654
  " rows — click one to open its record"
629
655
  ] }),
630
656
  /* @__PURE__ */ e(
631
657
  "button",
632
658
  {
633
659
  type: "button",
634
- onClick: () => c(null),
660
+ onClick: () => N(null),
635
661
  className: "rounded p-1 text-slate-400 hover:text-slate-600",
636
662
  children: /* @__PURE__ */ e(Ae, { className: "h-4 w-4" })
637
663
  }
638
664
  )
639
665
  ] }),
640
666
  /* @__PURE__ */ e("div", { className: "min-h-0 flex-1 overflow-auto p-2", children: /* @__PURE__ */ i("table", { className: "w-full text-[11px]", children: [
641
- /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ e("tr", { children: Object.keys(P.rows[0] ?? {}).slice(0, 7).map((v) => /* @__PURE__ */ e(
667
+ /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ e("tr", { children: Object.keys(u.rows[0] ?? {}).slice(0, 7).map((S) => /* @__PURE__ */ e(
642
668
  "th",
643
669
  {
644
670
  className: "border-b border-slate-100 px-1.5 py-1 text-left font-medium text-slate-400 dark:border-border",
645
- children: v
671
+ children: S
646
672
  },
647
- v
673
+ S
648
674
  )) }) }),
649
- /* @__PURE__ */ e("tbody", { children: P.rows.slice(0, 100).map((v, A) => /* @__PURE__ */ e(
675
+ /* @__PURE__ */ e("tbody", { children: u.rows.slice(0, 100).map((S, T) => /* @__PURE__ */ e(
650
676
  "tr",
651
677
  {
652
678
  className: "cursor-pointer hover:bg-slate-50 dark:hover:bg-muted/60",
653
679
  onClick: () => {
654
- c(null), f(v);
680
+ N(null), p(S);
655
681
  },
656
- children: Object.keys(P.rows[0] ?? {}).slice(0, 7).map((X) => /* @__PURE__ */ e(
682
+ children: Object.keys(u.rows[0] ?? {}).slice(0, 7).map((P) => /* @__PURE__ */ e(
657
683
  "td",
658
684
  {
659
685
  className: "max-w-[160px] truncate border-b border-slate-50 px-1.5 py-1 text-slate-600 dark:border-border/40 dark:text-slate-300",
660
- children: String(v[X] ?? "")
686
+ children: String(S[P] ?? "")
661
687
  },
662
- X
688
+ P
663
689
  ))
664
690
  },
665
- A
691
+ T
666
692
  )) })
667
693
  ] }) })
668
694
  ]
@@ -671,31 +697,31 @@ function sl({
671
697
  }
672
698
  ) : null;
673
699
  if (t.display === "donut") {
674
- const v = ((le = fe[0]) == null ? void 0 : le.field) ?? "", A = be.map((K) => ({ dim: String(K[se]), value: Number(K[v]) || 0 })), X = A.reduce((K, ie) => K + ie.value, 0);
700
+ const S = ((ae = be[0]) == null ? void 0 : ae.field) ?? "", T = ge.map((Y) => ({ dim: String(Y[xe]), value: Number(Y[S]) || 0 })), P = T.reduce((Y, ne) => Y + ne.value, 0);
675
701
  return /* @__PURE__ */ i("div", { className: "flex min-h-0 flex-1 items-stretch gap-3", children: [
676
702
  /* @__PURE__ */ i("div", { className: "relative min-h-[110px] min-w-0 flex-1", children: [
677
- /* @__PURE__ */ e(Le, { fallback: /* @__PURE__ */ e(Oe, { className: "h-full w-full", "aria-busy": "true" }), children: ({ Cell: K, Pie: ie, PieChart: oe, ResponsiveContainer: pe, Tooltip: M }) => /* @__PURE__ */ e(pe, { width: "100%", height: "100%", children: /* @__PURE__ */ i(oe, { children: [
703
+ /* @__PURE__ */ e(Re, { fallback: /* @__PURE__ */ e(Oe, { className: "h-full w-full", "aria-busy": "true" }), children: ({ Cell: Y, Pie: ne, PieChart: ce, ResponsiveContainer: fe, Tooltip: _ }) => /* @__PURE__ */ e(fe, { width: "100%", height: "100%", children: /* @__PURE__ */ i(ce, { children: [
678
704
  /* @__PURE__ */ e(
679
- ie,
705
+ ne,
680
706
  {
681
- data: A,
707
+ data: T,
682
708
  dataKey: "value",
683
709
  nameKey: "dim",
684
710
  innerRadius: "58%",
685
711
  outerRadius: "88%",
686
712
  paddingAngle: 2,
687
713
  strokeWidth: 0,
688
- className: u ? "cursor-pointer" : void 0,
689
- onClick: (z) => {
690
- var ge;
691
- const de = (ge = z == null ? void 0 : z.payload) == null ? void 0 : ge.dim;
692
- de && I(String(de));
714
+ className: m ? "cursor-pointer" : void 0,
715
+ onClick: (D) => {
716
+ var ve;
717
+ const me = (ve = D == null ? void 0 : D.payload) == null ? void 0 : ve.dim;
718
+ me && te(String(me));
693
719
  },
694
- children: A.map((z, de) => /* @__PURE__ */ e(K, { fill: ce[de % ce.length] }, z.dim))
720
+ children: T.map((D, me) => /* @__PURE__ */ e(Y, { fill: oe[me % oe.length] }, D.dim))
695
721
  }
696
722
  ),
697
723
  /* @__PURE__ */ e(
698
- M,
724
+ _,
699
725
  {
700
726
  contentStyle: {
701
727
  fontSize: 12,
@@ -706,44 +732,44 @@ function sl({
706
732
  },
707
733
  labelStyle: { color: "#f1f5f9" },
708
734
  itemStyle: { color: "#e2e8f0" },
709
- formatter: (z) => _e(z)
735
+ formatter: (D) => x(D)
710
736
  }
711
737
  )
712
738
  ] }) }) }),
713
739
  /* @__PURE__ */ i("div", { className: "pointer-events-none absolute inset-0 flex flex-col items-center justify-center", children: [
714
- /* @__PURE__ */ e("span", { className: "text-[17px] font-semibold leading-none text-slate-900 dark:text-foreground", children: Ee(X, t.value_format ?? "integer") }),
740
+ /* @__PURE__ */ e("span", { className: "text-[17px] font-semibold leading-none text-slate-900 dark:text-foreground", children: je(P, t.value_format ?? "integer") }),
715
741
  /* @__PURE__ */ e("span", { className: "text-[9.5px] text-slate-400", children: "total" })
716
742
  ] })
717
743
  ] }),
718
- /* @__PURE__ */ e("div", { className: "max-h-full w-[40%] shrink-0 space-y-0.5 self-center overflow-y-auto pr-1", children: A.slice(0, 12).map((K, ie) => /* @__PURE__ */ i("div", { className: "flex items-center gap-1.5 text-[10.5px]", children: [
744
+ /* @__PURE__ */ e("div", { className: "max-h-full w-[40%] shrink-0 space-y-0.5 self-center overflow-y-auto pr-1", children: T.slice(0, 12).map((Y, ne) => /* @__PURE__ */ i("div", { className: "flex items-center gap-1.5 text-[10.5px]", children: [
719
745
  /* @__PURE__ */ e(
720
746
  "span",
721
747
  {
722
748
  className: "h-2 w-2 shrink-0 rounded-sm",
723
- style: { background: ce[ie % ce.length] }
749
+ style: { background: oe[ne % oe.length] }
724
750
  }
725
751
  ),
726
- /* @__PURE__ */ e("span", { className: "truncate text-slate-600 dark:text-slate-300", children: K.dim }),
727
- /* @__PURE__ */ e("span", { className: "ml-auto tabular-nums text-slate-400", children: _e(K.value) })
728
- ] }, K.dim)) }),
729
- ae
752
+ /* @__PURE__ */ e("span", { className: "truncate text-slate-600 dark:text-slate-300", children: Y.dim }),
753
+ /* @__PURE__ */ e("span", { className: "ml-auto tabular-nums text-slate-400", children: x(Y.value) })
754
+ ] }, Y.dim)) }),
755
+ V
730
756
  ] });
731
757
  }
732
758
  if (t.display === "line" || t.display === "area")
733
759
  return /* @__PURE__ */ i("div", { className: "min-h-[110px] min-w-0 flex-1", children: [
734
- /* @__PURE__ */ e(Le, { fallback: /* @__PURE__ */ e(Oe, { className: "h-full w-full", "aria-busy": "true" }), children: ({ Area: v, AreaChart: A, Legend: X, ResponsiveContainer: K, Tooltip: ie, XAxis: oe, YAxis: pe }) => /* @__PURE__ */ e(K, { width: "100%", height: "100%", children: /* @__PURE__ */ i(A, { data: be, margin: { top: 6, right: 8, left: -6, bottom: 0 }, children: [
760
+ /* @__PURE__ */ e(Re, { fallback: /* @__PURE__ */ e(Oe, { className: "h-full w-full", "aria-busy": "true" }), children: ({ Area: S, AreaChart: T, Legend: P, ResponsiveContainer: Y, Tooltip: ne, XAxis: ce, YAxis: fe }) => /* @__PURE__ */ e(Y, { width: "100%", height: "100%", children: /* @__PURE__ */ i(T, { data: ge, margin: { top: 6, right: 8, left: -6, bottom: 0 }, children: [
735
761
  /* @__PURE__ */ e(
736
- oe,
762
+ ce,
737
763
  {
738
- dataKey: se,
764
+ dataKey: xe,
739
765
  tick: { fontSize: 10 },
740
766
  stroke: "#94a3b8",
741
- ..._t(be.length)
767
+ ..._t(ge.length)
742
768
  }
743
769
  ),
744
- /* @__PURE__ */ e(pe, { tick: { fontSize: 10 }, stroke: "#94a3b8", tickFormatter: Se, width: 48 }),
770
+ /* @__PURE__ */ e(fe, { tick: { fontSize: 10 }, stroke: "#94a3b8", tickFormatter: $e, width: 48 }),
745
771
  /* @__PURE__ */ e(
746
- ie,
772
+ ne,
747
773
  {
748
774
  contentStyle: {
749
775
  fontSize: 12,
@@ -754,70 +780,70 @@ function sl({
754
780
  },
755
781
  labelStyle: { color: "#f1f5f9" },
756
782
  itemStyle: { color: "#e2e8f0" },
757
- formatter: (M) => _e(M)
783
+ formatter: (_) => x(_)
758
784
  }
759
785
  ),
760
- fe.length > 1 && /* @__PURE__ */ e(X, { wrapperStyle: { fontSize: 11 } }),
761
- fe.map((M, z) => /* @__PURE__ */ e(
762
- v,
786
+ be.length > 1 && /* @__PURE__ */ e(P, { wrapperStyle: { fontSize: 11 } }),
787
+ be.map((_, D) => /* @__PURE__ */ e(
788
+ S,
763
789
  {
764
790
  type: "monotone",
765
- dataKey: M.field,
766
- name: M.label ?? M.field,
767
- stroke: M.color ?? ce[z % ce.length],
791
+ dataKey: _.field,
792
+ name: _.label ?? _.field,
793
+ stroke: _.color ?? oe[D % oe.length],
768
794
  strokeWidth: 2,
769
- strokeDasharray: M.dash ? "4 3" : void 0,
770
- fill: M.color ?? ce[z % ce.length],
771
- fillOpacity: t.display === "area" && !M.dash ? 0.12 : 0
795
+ strokeDasharray: _.dash ? "4 3" : void 0,
796
+ fill: _.color ?? oe[D % oe.length],
797
+ fillOpacity: t.display === "area" && !_.dash ? 0.12 : 0
772
798
  },
773
- M.field
799
+ _.field
774
800
  ))
775
801
  ] }) }) }),
776
- ae
802
+ V
777
803
  ] });
778
- const Y = t.display === "stacked_bar";
804
+ const he = t.display === "stacked_bar";
779
805
  return /* @__PURE__ */ i("div", { className: "min-h-[110px] min-w-0 flex-1", children: [
780
- /* @__PURE__ */ e(Le, { fallback: /* @__PURE__ */ e(Oe, { className: "h-full w-full", "aria-busy": "true" }), children: ({ Bar: v, BarChart: A, Cell: X, Legend: K, ResponsiveContainer: ie, Tooltip: oe, XAxis: pe, YAxis: M }) => /* @__PURE__ */ e(ie, { width: "100%", height: "100%", children: /* @__PURE__ */ i(
781
- A,
806
+ /* @__PURE__ */ e(Re, { fallback: /* @__PURE__ */ e(Oe, { className: "h-full w-full", "aria-busy": "true" }), children: ({ Bar: S, BarChart: T, Cell: P, Legend: Y, ResponsiveContainer: ne, Tooltip: ce, XAxis: fe, YAxis: _ }) => /* @__PURE__ */ e(ne, { width: "100%", height: "100%", children: /* @__PURE__ */ i(
807
+ T,
782
808
  {
783
- data: be,
784
- layout: x ? "vertical" : "horizontal",
785
- margin: { top: 6, right: 8, left: x ? 30 : -6, bottom: 0 },
809
+ data: ge,
810
+ layout: Z ? "vertical" : "horizontal",
811
+ margin: { top: 6, right: 8, left: Z ? 30 : -6, bottom: 0 },
786
812
  children: [
787
- x ? /* @__PURE__ */ i(Ge, { children: [
813
+ Z ? /* @__PURE__ */ i(He, { children: [
788
814
  /* @__PURE__ */ e(
789
- pe,
815
+ fe,
790
816
  {
791
817
  type: "number",
792
818
  tick: { fontSize: 10 },
793
819
  stroke: "#94a3b8",
794
- tickFormatter: Se
820
+ tickFormatter: $e
795
821
  }
796
822
  ),
797
823
  /* @__PURE__ */ e(
798
- M,
824
+ _,
799
825
  {
800
826
  type: "category",
801
- dataKey: se,
827
+ dataKey: xe,
802
828
  tick: { fontSize: 10 },
803
829
  stroke: "#94a3b8",
804
830
  width: 120
805
831
  }
806
832
  )
807
- ] }) : /* @__PURE__ */ i(Ge, { children: [
833
+ ] }) : /* @__PURE__ */ i(He, { children: [
808
834
  /* @__PURE__ */ e(
809
- pe,
835
+ fe,
810
836
  {
811
- dataKey: se,
837
+ dataKey: xe,
812
838
  tick: { fontSize: 10 },
813
839
  stroke: "#94a3b8",
814
- ..._t(be.length)
840
+ ..._t(ge.length)
815
841
  }
816
842
  ),
817
- /* @__PURE__ */ e(M, { tick: { fontSize: 10 }, stroke: "#94a3b8", tickFormatter: Se, width: 48 })
843
+ /* @__PURE__ */ e(_, { tick: { fontSize: 10 }, stroke: "#94a3b8", tickFormatter: $e, width: 48 })
818
844
  ] }),
819
845
  /* @__PURE__ */ e(
820
- oe,
846
+ ce,
821
847
  {
822
848
  contentStyle: {
823
849
  fontSize: 12,
@@ -828,38 +854,38 @@ function sl({
828
854
  },
829
855
  labelStyle: { color: "#f1f5f9" },
830
856
  itemStyle: { color: "#e2e8f0" },
831
- formatter: (z) => _e(z)
857
+ formatter: (D) => x(D)
832
858
  }
833
859
  ),
834
- fe.length > 1 && /* @__PURE__ */ e(K, { wrapperStyle: { fontSize: 11 } }),
835
- fe.map((z, de) => /* @__PURE__ */ e(
836
- v,
860
+ be.length > 1 && /* @__PURE__ */ e(Y, { wrapperStyle: { fontSize: 11 } }),
861
+ be.map((D, me) => /* @__PURE__ */ e(
862
+ S,
837
863
  {
838
- className: u ? "cursor-pointer" : void 0,
839
- onClick: (ge) => {
864
+ className: m ? "cursor-pointer" : void 0,
865
+ onClick: (ve) => {
840
866
  var Te;
841
- const ve = (Te = ge == null ? void 0 : ge.payload) == null ? void 0 : Te[se];
842
- ve != null && I(String(ve));
867
+ const we = (Te = ve == null ? void 0 : ve.payload) == null ? void 0 : Te[xe];
868
+ we != null && te(String(we));
843
869
  },
844
- dataKey: z.field,
845
- name: z.label ?? z.field,
846
- stackId: Y ? "stack" : void 0,
847
- fill: z.color ?? ce[de % ce.length],
848
- radius: Y ? 0 : x ? [0, 3, 3, 0] : [3, 3, 0, 0],
849
- children: fe.length === 1 && !z.color && be.map((ge, ve) => /* @__PURE__ */ e(X, { fill: ce[ve % ce.length] }, ve))
870
+ dataKey: D.field,
871
+ name: D.label ?? D.field,
872
+ stackId: he ? "stack" : void 0,
873
+ fill: D.color ?? oe[me % oe.length],
874
+ radius: he ? 0 : Z ? [0, 3, 3, 0] : [3, 3, 0, 0],
875
+ children: be.length === 1 && !D.color && ge.map((ve, we) => /* @__PURE__ */ e(P, { fill: oe[we % oe.length] }, we))
850
876
  },
851
- z.field
877
+ D.field
852
878
  ))
853
879
  ]
854
880
  }
855
881
  ) }) }),
856
- ae
882
+ V
857
883
  ] });
858
884
  }
859
- const il = ["gt", "gte", "lt", "lte", "eq"], da = { gt: ">", gte: "≥", lt: "<", lte: "≤", eq: "=" }, ol = ["sum", "avg", "max", "min"];
860
- function dl(t) {
861
- var o, m, u;
862
- const s = [
885
+ const dl = ["gt", "gte", "lt", "lte", "eq"], ca = { gt: ">", gte: "≥", lt: "<", lte: "≤", eq: "=" }, cl = ["sum", "avg", "max", "min"];
886
+ function ml(t) {
887
+ var o, c, m;
888
+ const n = [
863
889
  { value: "value", label: "Value (widget metric)" },
864
890
  { value: "row_count", label: "Row count" }
865
891
  ], a = (o = t.config) == null ? void 0 : o.query;
@@ -869,49 +895,49 @@ function dl(t) {
869
895
  label: f.label ?? f.field,
870
896
  aggregatable: !0
871
897
  }));
872
- return [...s, ...h];
898
+ return [...n, ...h];
873
899
  }
874
900
  if (t.type === "kpi_group")
875
901
  return [
876
- ...s,
877
- ...(((m = t.config) == null ? void 0 : m.metrics) ?? []).map((h) => ({
902
+ ...n,
903
+ ...(((c = t.config) == null ? void 0 : c.metrics) ?? []).map((h) => ({
878
904
  value: `tile:${h.label}`,
879
905
  label: `Tile: ${h.label}`
880
906
  }))
881
907
  ];
882
908
  if (t.type === "table") {
883
- const h = (((u = t.config) == null ? void 0 : u.columns) ?? []).map((f) => typeof f == "string" ? { field: f } : f).map((f) => ({ value: f.field, label: f.label ?? f.field, aggregatable: !0 }));
884
- return [...s, ...h];
909
+ const h = (((m = t.config) == null ? void 0 : m.columns) ?? []).map((f) => typeof f == "string" ? { field: f } : f).map((f) => ({ value: f.field, label: f.label ?? f.field, aggregatable: !0 }));
910
+ return [...n, ...h];
885
911
  }
886
- return s;
912
+ return n;
887
913
  }
888
- function zt(t, s) {
914
+ function jt(t, n) {
889
915
  var h;
890
- const a = /^(sum|avg|max|min|tile):(.+)$/.exec(t.field), o = a ? a[2] : t.field, m = ((h = s.find((f) => f.value === t.field || f.value === o)) == null ? void 0 : h.label) ?? o;
891
- return `${a && a[1] !== "sum" && a[1] !== "tile" ? `${a[1]} ` : ""}${m} ${da[t.op] ?? t.op} ${t.value.toLocaleString()}`;
916
+ const a = /^(sum|avg|max|min|tile):(.+)$/.exec(t.field), o = a ? a[2] : t.field, c = ((h = n.find((f) => f.value === t.field || f.value === o)) == null ? void 0 : h.label) ?? o;
917
+ return `${a && a[1] !== "sum" && a[1] !== "tile" ? `${a[1]} ` : ""}${c} ${ca[t.op] ?? t.op} ${t.value.toLocaleString()}`;
892
918
  }
893
- function cl({ reportId: t, alert: s }) {
894
- const a = Ke(), o = Ct(), { data: m = [] } = ke({
895
- queryKey: ["nivaro-report-alert-log", t, s.id],
896
- queryFn: () => a.request(Na(t, s.id)).then((h) => h.data),
919
+ function ul({ reportId: t, alert: n }) {
920
+ const a = Ke(), o = Ct(), { data: c = [] } = Ne({
921
+ queryKey: ["nivaro-report-alert-log", t, n.id],
922
+ queryFn: () => a.request(wa(t, n.id)).then((h) => h.data),
897
923
  staleTime: 3e4
898
- }), u = Me({
899
- mutationFn: () => a.request(wa(t, s.id)),
924
+ }), m = Me({
925
+ mutationFn: () => a.request(Sa(t, n.id)),
900
926
  onSuccess: () => {
901
- o.invalidateQueries({ queryKey: ["nivaro-report-alert-log", t, s.id] }), o.invalidateQueries({ queryKey: ["nivaro-report-alerts", t] });
927
+ o.invalidateQueries({ queryKey: ["nivaro-report-alert-log", t, n.id] }), o.invalidateQueries({ queryKey: ["nivaro-report-alerts", t] });
902
928
  }
903
929
  });
904
- return m.length === 0 ? /* @__PURE__ */ e("p", { className: "px-1 py-1 text-[10.5px] text-slate-400", children: "Never fired." }) : /* @__PURE__ */ e("div", { className: "max-h-36 space-y-1 overflow-y-auto py-1", children: m.slice(0, 20).map((h) => /* @__PURE__ */ i("div", { className: "flex items-center gap-1.5 text-[10.5px]", children: [
930
+ return c.length === 0 ? /* @__PURE__ */ e("p", { className: "px-1 py-1 text-[10.5px] text-slate-400", children: "Never fired." }) : /* @__PURE__ */ e("div", { className: "max-h-36 space-y-1 overflow-y-auto py-1", children: c.slice(0, 20).map((h) => /* @__PURE__ */ i("div", { className: "flex items-center gap-1.5 text-[10.5px]", children: [
905
931
  /* @__PURE__ */ e(
906
932
  "span",
907
933
  {
908
- className: Q(
934
+ className: j(
909
935
  "h-1.5 w-1.5 shrink-0 rounded-full",
910
936
  h.status === "firing" ? "bg-amber-500" : "bg-emerald-500"
911
937
  )
912
938
  }
913
939
  ),
914
- /* @__PURE__ */ e("span", { className: Q(h.status === "firing" ? "text-amber-600" : "text-slate-500"), children: h.status === "firing" ? "Firing" : "Resolved" }),
940
+ /* @__PURE__ */ e("span", { className: j(h.status === "firing" ? "text-amber-600" : "text-slate-500"), children: h.status === "firing" ? "Firing" : "Resolved" }),
915
941
  /* @__PURE__ */ i("span", { className: "min-w-0 flex-1 truncate text-slate-400", children: [
916
942
  new Date(h.fired_at).toLocaleString(),
917
943
  h.resolved_at ? ` → ${new Date(h.resolved_at).toLocaleString()}` : ""
@@ -921,70 +947,70 @@ function cl({ reportId: t, alert: s }) {
921
947
  {
922
948
  type: "button",
923
949
  className: "shrink-0 text-[10px] text-slate-400 underline hover:text-emerald-600",
924
- onClick: () => u.mutate(),
950
+ onClick: () => m.mutate(),
925
951
  children: "Mark resolved"
926
952
  }
927
953
  )
928
954
  ] }, h.id)) });
929
955
  }
930
- function ml({
956
+ function pl({
931
957
  reportId: t,
932
- widget: s,
958
+ widget: n,
933
959
  filterBar: a
934
960
  }) {
935
- const o = Ke(), m = Ct(), [u, h] = C(!1), [f, p] = C(""), [L, $] = C([
961
+ const o = Ke(), c = Ct(), [m, h] = C(!1), [f, p] = C(""), [L, q] = C([
936
962
  { field: "value", agg: "sum", op: "gt", value: "" }
937
- ]), [w, P] = C([]), [c, S] = C(!1), [J, O] = C(null), G = dl(s), { data: H = [] } = ke({
963
+ ]), [w, E] = C([]), [u, N] = C(!1), [U, O] = C(null), ee = ml(n), { data: H = [] } = Ne({
938
964
  queryKey: ["nivaro-report-alerts", t],
939
- queryFn: () => o.request(ga(t)).then((x) => x.data),
940
- enabled: u,
965
+ queryFn: () => o.request(va(t)).then((x) => x.data),
966
+ enabled: m,
941
967
  staleTime: 3e4
942
- }), me = H.filter((x) => x.widget === s.id), Z = () => void m.invalidateQueries({ queryKey: ["nivaro-report-alerts", t] }), te = () => L.filter((x) => x.value.trim() !== "" && !Number.isNaN(Number(x.value))).map((x) => {
943
- const I = G.find((Y) => Y.value === x.field);
944
- return { field: I != null && I.aggregatable && x.agg !== "sum" ? `${x.agg}:${x.field}` : x.field, op: x.op, value: Number(x.value) };
945
- }), se = Me({
968
+ }), ue = H.filter((x) => x.widget === n.id), pe = () => void c.invalidateQueries({ queryKey: ["nivaro-report-alerts", t] }), X = () => L.filter((x) => x.value.trim() !== "" && !Number.isNaN(Number(x.value))).map((x) => {
969
+ const Z = ee.find((V) => V.value === x.field);
970
+ return { field: Z != null && Z.aggregatable && x.agg !== "sum" ? `${x.agg}:${x.field}` : x.field, op: x.op, value: Number(x.value) };
971
+ }), de = Me({
946
972
  mutationFn: () => {
947
- const x = te(), I = x.map((ae) => zt(ae, G)).join(" & ");
973
+ const x = X(), Z = x.map((te) => jt(te, ee)).join(" & ");
948
974
  return o.request(
949
- va(t, {
950
- widget: s.id,
951
- name: f.trim() || I.slice(0, 120),
975
+ ya(t, {
976
+ widget: n.id,
977
+ name: f.trim() || Z.slice(0, 120),
952
978
  conditions: x,
953
- filters: w.filter((ae) => ae.values.length > 0),
954
- delivery_email: c,
979
+ filters: w.filter((te) => te.values.length > 0),
980
+ delivery_email: u,
955
981
  delivery_inapp: !0
956
982
  })
957
983
  );
958
984
  },
959
985
  onSuccess: () => {
960
- p(""), $([{ field: "value", agg: "sum", op: "gt", value: "" }]), P([]), Z();
986
+ p(""), q([{ field: "value", agg: "sum", op: "gt", value: "" }]), E([]), pe();
961
987
  }
962
- }), fe = Me({
963
- mutationFn: (x) => o.request(ya(t, x.id, !x.is_active)),
964
- onSuccess: Z
988
+ }), xe = Me({
989
+ mutationFn: (x) => o.request(ka(t, x.id, !x.is_active)),
990
+ onSuccess: pe
965
991
  }), be = Me({
966
- mutationFn: (x) => o.request(ka(t, x.id)),
967
- onSuccess: Z
968
- }), Se = te().length > 0, _e = me.some((x) => x.firing);
969
- return /* @__PURE__ */ i(ta, { open: u, onOpenChange: h, children: [
970
- /* @__PURE__ */ e(aa, { asChild: !0, children: /* @__PURE__ */ e(
992
+ mutationFn: (x) => o.request(Na(t, x.id)),
993
+ onSuccess: pe
994
+ }), ge = X().length > 0, $e = ue.some((x) => x.firing);
995
+ return /* @__PURE__ */ i(aa, { open: m, onOpenChange: h, children: [
996
+ /* @__PURE__ */ e(la, { asChild: !0, children: /* @__PURE__ */ e(
971
997
  "button",
972
998
  {
973
999
  type: "button",
974
1000
  title: "Alerts on this widget",
975
- className: Q(
1001
+ className: j(
976
1002
  "rounded p-0.5",
977
- _e ? "text-amber-500" : "text-slate-300 hover:text-amber-500 dark:text-slate-600"
1003
+ $e ? "text-amber-500" : "text-slate-300 hover:text-amber-500 dark:text-slate-600"
978
1004
  ),
979
1005
  children: /* @__PURE__ */ e(Yt, { className: "h-3 w-3" })
980
1006
  }
981
1007
  ) }),
982
- /* @__PURE__ */ i(la, { className: "w-[380px] p-3", align: "end", children: [
1008
+ /* @__PURE__ */ i(ra, { className: "w-[380px] p-3", align: "end", children: [
983
1009
  /* @__PURE__ */ i("p", { className: "mb-2 text-[12px] font-semibold text-slate-700 dark:text-slate-200", children: [
984
1010
  "Alerts · ",
985
- s.title
1011
+ n.title
986
1012
  ] }),
987
- me.length > 0 && /* @__PURE__ */ e("div", { className: "mb-2 space-y-1.5", children: me.map((x) => /* @__PURE__ */ i(
1013
+ ue.length > 0 && /* @__PURE__ */ e("div", { className: "mb-2 space-y-1.5", children: ue.map((x) => /* @__PURE__ */ i(
988
1014
  "div",
989
1015
  {
990
1016
  className: "rounded-md border border-slate-100 px-2 py-1.5 dark:border-border/60",
@@ -993,7 +1019,7 @@ function ml({
993
1019
  /* @__PURE__ */ e(
994
1020
  "span",
995
1021
  {
996
- className: Q(
1022
+ className: j(
997
1023
  "h-1.5 w-1.5 shrink-0 rounded-full",
998
1024
  x.firing ? "bg-amber-500" : x.is_active ? "bg-emerald-500" : "bg-slate-300"
999
1025
  )
@@ -1005,7 +1031,7 @@ function ml({
1005
1031
  {
1006
1032
  type: "button",
1007
1033
  className: "text-[10.5px] text-slate-400 hover:text-slate-600",
1008
- onClick: () => O(J === x.id ? null : x.id),
1034
+ onClick: () => O(U === x.id ? null : x.id),
1009
1035
  children: "History"
1010
1036
  }
1011
1037
  ),
@@ -1014,7 +1040,7 @@ function ml({
1014
1040
  {
1015
1041
  type: "button",
1016
1042
  className: "text-[10.5px] text-slate-400 hover:text-slate-600",
1017
- onClick: () => fe.mutate(x),
1043
+ onClick: () => xe.mutate(x),
1018
1044
  children: x.is_active ? "Pause" : "Resume"
1019
1045
  }
1020
1046
  ),
@@ -1024,19 +1050,19 @@ function ml({
1024
1050
  type: "button",
1025
1051
  className: "text-slate-300 hover:text-red-500",
1026
1052
  onClick: () => be.mutate(x),
1027
- children: /* @__PURE__ */ e(Fa, { className: "h-3 w-3" })
1053
+ children: /* @__PURE__ */ e(Aa, { className: "h-3 w-3" })
1028
1054
  }
1029
1055
  )
1030
1056
  ] }),
1031
1057
  /* @__PURE__ */ i("p", { className: "mt-0.5 truncate pl-3 text-[10.5px] text-slate-400", children: [
1032
- (x.conditions ?? []).map((I) => zt(I, G)).join(" & "),
1033
- x.filters && x.filters.length > 0 && ` · scoped: ${x.filters.map((I) => (I.labels ?? I.values).join("/")).join(", ")}`,
1058
+ (x.conditions ?? []).map((Z) => jt(Z, ee)).join(" & "),
1059
+ x.filters && x.filters.length > 0 && ` · scoped: ${x.filters.map((Z) => (Z.labels ?? Z.values).join("/")).join(", ")}`,
1034
1060
  " · ",
1035
1061
  x.delivery_email ? "In-app + Email" : "In-app",
1036
1062
  " · Last fired: ",
1037
1063
  x.last_fired ? new Date(x.last_fired).toLocaleString() : "Never"
1038
1064
  ] }),
1039
- J === x.id && /* @__PURE__ */ e(cl, { reportId: t, alert: x })
1065
+ U === x.id && /* @__PURE__ */ e(ul, { reportId: t, alert: x })
1040
1066
  ]
1041
1067
  },
1042
1068
  x.id
@@ -1051,39 +1077,39 @@ function ml({
1051
1077
  className: "h-7 w-full rounded-md border border-slate-200 bg-white px-2 text-[11.5px] dark:border-border dark:bg-card"
1052
1078
  }
1053
1079
  ),
1054
- L.map((x, I) => {
1055
- const ae = G.find((Y) => Y.value === x.field);
1080
+ L.map((x, Z) => {
1081
+ const te = ee.find((V) => V.value === x.field);
1056
1082
  return /* @__PURE__ */ i("div", { className: "flex items-center gap-1", children: [
1057
1083
  /* @__PURE__ */ e(
1058
- kt,
1084
+ Nt,
1059
1085
  {
1060
1086
  value: x.field,
1061
- onChange: (Y) => $((ue) => ue.map((le, v) => v === I ? { ...le, field: Y } : le)),
1062
- options: G.map((Y) => ({ value: Y.value, label: Y.label })),
1087
+ onChange: (V) => q((he) => he.map((le, ae) => ae === Z ? { ...le, field: V } : le)),
1088
+ options: ee.map((V) => ({ value: V.value, label: V.label })),
1063
1089
  ariaLabel: "Alert metric field",
1064
1090
  className: "h-7 min-w-0 flex-1 rounded-md px-1.5 py-0 text-[11.5px] dark:border-border dark:bg-card"
1065
1091
  }
1066
1092
  ),
1067
- (ae == null ? void 0 : ae.aggregatable) && /* @__PURE__ */ e(
1068
- kt,
1093
+ (te == null ? void 0 : te.aggregatable) && /* @__PURE__ */ e(
1094
+ Nt,
1069
1095
  {
1070
1096
  value: x.agg,
1071
- onChange: (Y) => $(
1072
- (ue) => ue.map((le, v) => v === I ? { ...le, agg: Y } : le)
1097
+ onChange: (V) => q(
1098
+ (he) => he.map((le, ae) => ae === Z ? { ...le, agg: V } : le)
1073
1099
  ),
1074
- options: ol.map((Y) => ({ value: Y, label: Y })),
1100
+ options: cl.map((V) => ({ value: V, label: V })),
1075
1101
  ariaLabel: "Aggregate",
1076
1102
  className: "h-7 w-[62px] rounded-md px-1.5 py-0 text-[11.5px] dark:border-border dark:bg-card"
1077
1103
  }
1078
1104
  ),
1079
1105
  /* @__PURE__ */ e(
1080
- kt,
1106
+ Nt,
1081
1107
  {
1082
1108
  value: x.op,
1083
- onChange: (Y) => $(
1084
- (ue) => ue.map((le, v) => v === I ? { ...le, op: Y } : le)
1109
+ onChange: (V) => q(
1110
+ (he) => he.map((le, ae) => ae === Z ? { ...le, op: V } : le)
1085
1111
  ),
1086
- options: il.map((Y) => ({ value: Y, label: da[Y] })),
1112
+ options: dl.map((V) => ({ value: V, label: ca[V] })),
1087
1113
  ariaLabel: "Operator",
1088
1114
  className: "h-7 w-[52px] rounded-md px-1.5 py-0 text-[11.5px] dark:border-border dark:bg-card"
1089
1115
  }
@@ -1092,8 +1118,8 @@ function ml({
1092
1118
  "input",
1093
1119
  {
1094
1120
  value: x.value,
1095
- onChange: (Y) => $(
1096
- (ue) => ue.map((le, v) => v === I ? { ...le, value: Y.target.value } : le)
1121
+ onChange: (V) => q(
1122
+ (he) => he.map((le, ae) => ae === Z ? { ...le, value: V.target.value } : le)
1097
1123
  ),
1098
1124
  placeholder: "0",
1099
1125
  inputMode: "decimal",
@@ -1105,36 +1131,36 @@ function ml({
1105
1131
  {
1106
1132
  type: "button",
1107
1133
  className: "text-slate-300 hover:text-red-500",
1108
- onClick: () => $((Y) => Y.filter((ue, le) => le !== I)),
1134
+ onClick: () => q((V) => V.filter((he, le) => le !== Z)),
1109
1135
  children: /* @__PURE__ */ e(Ae, { className: "h-3 w-3" })
1110
1136
  }
1111
1137
  )
1112
- ] }, I);
1138
+ ] }, Z);
1113
1139
  }),
1114
1140
  /* @__PURE__ */ e(
1115
1141
  "button",
1116
1142
  {
1117
1143
  type: "button",
1118
1144
  className: "text-[10.5px] text-slate-400 hover:text-nvr-navy dark:hover:text-nvr-cyan",
1119
- onClick: () => $((x) => [...x, { field: "value", agg: "sum", op: "gt", value: "" }]),
1145
+ onClick: () => q((x) => [...x, { field: "value", agg: "sum", op: "gt", value: "" }]),
1120
1146
  children: "+ condition (all must match)"
1121
1147
  }
1122
1148
  ),
1123
1149
  a.length > 0 && /* @__PURE__ */ i("div", { children: [
1124
1150
  /* @__PURE__ */ e("p", { className: "mb-1 text-[10.5px] font-medium uppercase tracking-wide text-slate-400", children: "Alert scope (optional)" }),
1125
1151
  /* @__PURE__ */ e("div", { className: "flex flex-wrap gap-1", children: a.map((x) => {
1126
- var I;
1152
+ var Z;
1127
1153
  return /* @__PURE__ */ e(
1128
- ra,
1154
+ na,
1129
1155
  {
1130
1156
  reportId: t,
1131
1157
  field: x.field,
1132
1158
  label: x.label,
1133
1159
  optionSource: x.options,
1134
- selected: ((I = w.find((ae) => ae.field === x.field)) == null ? void 0 : I.values) ?? [],
1135
- onChange: (ae, Y) => P((ue) => [
1136
- ...ue.filter((le) => le.field !== x.field),
1137
- ...ae.length > 0 ? [{ field: x.field, values: ae, labels: Y }] : []
1160
+ selected: ((Z = w.find((te) => te.field === x.field)) == null ? void 0 : Z.values) ?? [],
1161
+ onChange: (te, V) => E((he) => [
1162
+ ...he.filter((le) => le.field !== x.field),
1163
+ ...te.length > 0 ? [{ field: x.field, values: te, labels: V }] : []
1138
1164
  ])
1139
1165
  },
1140
1166
  x.field
@@ -1147,8 +1173,8 @@ function ml({
1147
1173
  "input",
1148
1174
  {
1149
1175
  type: "checkbox",
1150
- checked: c,
1151
- onChange: (x) => S(x.target.checked),
1176
+ checked: u,
1177
+ onChange: (x) => N(x.target.checked),
1152
1178
  className: "h-3 w-3 accent-nvr-cyan"
1153
1179
  }
1154
1180
  ),
@@ -1158,11 +1184,11 @@ function ml({
1158
1184
  "button",
1159
1185
  {
1160
1186
  type: "button",
1161
- disabled: !Se || se.isPending,
1162
- onClick: () => se.mutate(),
1187
+ disabled: !ge || de.isPending,
1188
+ onClick: () => de.mutate(),
1163
1189
  className: "inline-flex h-7 items-center gap-1 rounded-md bg-nvr-cyan px-2 text-[11.5px] font-semibold text-white disabled:opacity-50",
1164
1190
  children: [
1165
- /* @__PURE__ */ e(Ut, { className: "h-3 w-3" }),
1191
+ /* @__PURE__ */ e(Vt, { className: "h-3 w-3" }),
1166
1192
  " Add alert"
1167
1193
  ]
1168
1194
  }
@@ -1173,7 +1199,7 @@ function ml({
1173
1199
  ] })
1174
1200
  ] });
1175
1201
  }
1176
- const ul = {
1202
+ const hl = {
1177
1203
  eq: "_eq",
1178
1204
  neq: "_neq",
1179
1205
  gt: "_gt",
@@ -1185,80 +1211,80 @@ const ul = {
1185
1211
  null: "_null",
1186
1212
  nnull: "_nnull"
1187
1213
  };
1188
- function qt(t, s, a, o) {
1189
- var L, $;
1190
- const m = t.config ?? {}, u = [];
1191
- for (const w of m.filters ?? []) {
1192
- const P = ul[w.op];
1193
- if (!P) continue;
1194
- let c = w.value;
1195
- w.op === "in" && typeof c == "string" && (c = c.split(",").map((S) => S.trim())), u.push({ path: [w.field], op: P, value: c });
1214
+ function Mt(t, n, a, o) {
1215
+ var L, q;
1216
+ const c = t.config ?? {}, m = [];
1217
+ for (const w of c.filters ?? []) {
1218
+ const E = hl[w.op];
1219
+ if (!E) continue;
1220
+ let u = w.value;
1221
+ w.op === "in" && typeof u == "string" && (u = u.split(",").map((N) => N.trim())), m.push({ path: [w.field], op: E, value: u });
1196
1222
  }
1197
- for (const w of s)
1198
- (L = w.values) != null && L.length && u.push({ path: [w.field], op: "_in", value: w.values });
1199
- const h = m.date_field || (($ = m.dimension) != null && $.bucket ? m.dimension.field : null), f = na(a);
1200
- f && h && (u.push({ path: [h], op: "_gte", value: f.start }), u.push({ path: [h], op: "_lte", value: `${f.end}T23:59:59` }));
1201
- const p = m.dimension;
1223
+ for (const w of n)
1224
+ (L = w.values) != null && L.length && m.push({ path: [w.field], op: "_in", value: w.values });
1225
+ const h = c.date_field || ((q = c.dimension) != null && q.bucket ? c.dimension.field : null), f = sa(a);
1226
+ f && h && (m.push({ path: [h], op: "_gte", value: f.start }), m.push({ path: [h], op: "_lte", value: `${f.end}T23:59:59` }));
1227
+ const p = c.dimension;
1202
1228
  if (o !== void 0 && (p != null && p.field))
1203
1229
  if (p.bucket) {
1204
1230
  const w = String(o);
1205
1231
  if (/^\d{4}-\d{2}-\d{2}$/.test(w))
1206
- u.push({ path: [p.field], op: "_gte", value: w }), u.push({ path: [p.field], op: "_lte", value: `${w}T23:59:59` });
1232
+ m.push({ path: [p.field], op: "_gte", value: w }), m.push({ path: [p.field], op: "_lte", value: `${w}T23:59:59` });
1207
1233
  else if (/^\d{4}-\d{2}$/.test(w)) {
1208
- const [P, c] = w.split("-").map(Number), S = new Date(P, c, 0).getDate();
1209
- u.push({ path: [p.field], op: "_gte", value: `${w}-01` }), u.push({
1234
+ const [E, u] = w.split("-").map(Number), N = new Date(E, u, 0).getDate();
1235
+ m.push({ path: [p.field], op: "_gte", value: `${w}-01` }), m.push({
1210
1236
  path: [p.field],
1211
1237
  op: "_lte",
1212
- value: `${w}-${String(S).padStart(2, "0")}T23:59:59`
1238
+ value: `${w}-${String(N).padStart(2, "0")}T23:59:59`
1213
1239
  });
1214
1240
  }
1215
- } else o === null ? u.push({ path: [p.field], op: "_null", value: !0 }) : u.push({ path: [p.field], op: "_eq", value: o });
1216
- return u;
1241
+ } else o === null ? m.push({ path: [p.field], op: "_null", value: !0 }) : m.push({ path: [p.field], op: "_eq", value: o });
1242
+ return m;
1217
1243
  }
1218
- function jt(t) {
1219
- const s = t.config ?? {}, a = [], o = s.query;
1244
+ function Et(t) {
1245
+ const n = t.config ?? {}, a = [], o = n.query;
1220
1246
  if (t.type === "query" && (o != null && o.slug))
1221
1247
  a.push(`Custom query: ${o.slug}`);
1222
1248
  else if (t.collection) {
1223
- const m = s.metric, u = (m == null ? void 0 : m.aggregate) ?? "count";
1249
+ const c = n.metric, m = (c == null ? void 0 : c.aggregate) ?? "count";
1224
1250
  a.push(
1225
- `${u === "count" ? "Count of" : `${u.toUpperCase()} of ${(m == null ? void 0 : m.field) ?? "?"} on`} ${t.collection.replace(/_/g, " ")}`
1251
+ `${m === "count" ? "Count of" : `${m.toUpperCase()} of ${(c == null ? void 0 : c.field) ?? "?"} on`} ${t.collection.replace(/_/g, " ")}`
1226
1252
  );
1227
- const h = s.dimension;
1253
+ const h = n.dimension;
1228
1254
  h != null && h.field && a.push(`by ${h.field}${h.bucket ? ` (${h.bucket})` : ""}`);
1229
- const f = s.filters ?? [];
1255
+ const f = n.filters ?? [];
1230
1256
  for (const p of f) a.push(`${p.field} ${p.op} ${String(p.value ?? "")}`);
1231
- s.date_field && a.push(`dated by ${s.date_field}`), s.compare && a.push(`compared to ${String(s.compare).replace(/_/g, " ")}`);
1257
+ n.date_field && a.push(`dated by ${n.date_field}`), n.compare && a.push(`compared to ${String(n.compare).replace(/_/g, " ")}`);
1232
1258
  }
1233
1259
  return a.length > 0 ? a.join(" · ") : "No configuration details";
1234
1260
  }
1235
- function pl(t) {
1236
- var s, a;
1237
- return t ? t.value != null ? Number(t.value) : t.series ? t.series.reduce((o, m) => o + (Number(m.value) || 0), 0) : (s = t.tiles) != null && s.length ? Number(((a = t.tiles[0]) == null ? void 0 : a.value) ?? 0) : t.row_count != null ? Number(t.row_count) : null : null;
1261
+ function fl(t) {
1262
+ var n, a;
1263
+ return t ? t.value != null ? Number(t.value) : t.series ? t.series.reduce((o, c) => o + (Number(c.value) || 0), 0) : (n = t.tiles) != null && n.length ? Number(((a = t.tiles[0]) == null ? void 0 : a.value) ?? 0) : t.row_count != null ? Number(t.row_count) : null : null;
1238
1264
  }
1239
- function Et(t, s, a) {
1240
- var $, w, P;
1265
+ function Wt(t, n, a) {
1266
+ var q, w, E;
1241
1267
  const o = a ? [...a] : [];
1242
- if (o.length === 0 && (($ = s == null ? void 0 : s.rows) != null && $.length) && o.push(...s.rows), o.length === 0 && ((w = s == null ? void 0 : s.series) != null && w.length))
1243
- for (const c of s.series)
1268
+ if (o.length === 0 && ((q = n == null ? void 0 : n.rows) != null && q.length) && o.push(...n.rows), o.length === 0 && ((w = n == null ? void 0 : n.series) != null && w.length))
1269
+ for (const u of n.series)
1244
1270
  o.push({
1245
- dim: c.dim,
1246
- value: c.value,
1247
- ...c.prev != null ? { previous: c.prev } : {},
1248
- ...c.value2 != null ? { value2: c.value2 } : {}
1271
+ dim: u.dim,
1272
+ value: u.value,
1273
+ ...u.prev != null ? { previous: u.prev } : {},
1274
+ ...u.value2 != null ? { value2: u.value2 } : {}
1249
1275
  });
1250
- if (o.length === 0 && ((P = s == null ? void 0 : s.tiles) != null && P.length))
1251
- for (const c of s.tiles) o.push({ label: c.label, value: c.value });
1252
- if (o.length === 0 && (s == null ? void 0 : s.value) != null && o.push({ value: s.value }), o.length === 0) {
1253
- Ht.info("Nothing to download yet", {
1276
+ if (o.length === 0 && ((E = n == null ? void 0 : n.tiles) != null && E.length))
1277
+ for (const u of n.tiles) o.push({ label: u.label, value: u.value });
1278
+ if (o.length === 0 && (n == null ? void 0 : n.value) != null && o.push({ value: n.value }), o.length === 0) {
1279
+ Xt.info("Nothing to download yet", {
1254
1280
  description: "This widget has no rows for these filters."
1255
1281
  });
1256
1282
  return;
1257
1283
  }
1258
- const m = [...new Set(o.flatMap((c) => Object.keys(c)))], u = (c) => {
1259
- const S = String(c ?? "");
1260
- return /[",\n]/.test(S) ? `"${S.replace(/"/g, '""')}"` : S;
1261
- }, h = [m.join(","), ...o.map((c) => m.map((S) => u(c[S])).join(","))].join(
1284
+ const c = [...new Set(o.flatMap((u) => Object.keys(u)))], m = (u) => {
1285
+ const N = String(u ?? "");
1286
+ return /[",\n]/.test(N) ? `"${N.replace(/"/g, '""')}"` : N;
1287
+ }, h = [c.join(","), ...o.map((u) => c.map((N) => m(u[N])).join(","))].join(
1262
1288
  `
1263
1289
  `
1264
1290
  ), f = new Blob([h], { type: "text/csv;charset=utf-8" }), p = document.createElement("a");
@@ -1266,23 +1292,23 @@ function Et(t, s, a) {
1266
1292
  const L = p.href;
1267
1293
  setTimeout(() => URL.revokeObjectURL(L), 1e4);
1268
1294
  }
1269
- function hl({
1295
+ function xl({
1270
1296
  collection: t,
1271
- conditions: s,
1297
+ conditions: n,
1272
1298
  title: a,
1273
1299
  onClose: o,
1274
- onOpen: m,
1275
- crossFilter: u
1300
+ onOpen: c,
1301
+ crossFilter: m
1276
1302
  }) {
1277
- const h = Ke(), { data: f, isLoading: p } = ke({
1278
- queryKey: ["nvr-report-drill", t, JSON.stringify(s)],
1303
+ const h = Ke(), { data: f, isLoading: p } = Ne({
1304
+ queryKey: ["nvr-report-drill", t, JSON.stringify(n)],
1279
1305
  queryFn: () => h.request(
1280
- ot(`/items/${t}`, { limit: 50, conditions: JSON.stringify(s) })
1306
+ ct(`/items/${t}`, { limit: 50, conditions: JSON.stringify(n) })
1281
1307
  ),
1282
1308
  staleTime: 3e4,
1283
1309
  retry: !1
1284
- }), L = (f == null ? void 0 : f.data) ?? [], $ = (w) => {
1285
- for (const c of [
1310
+ }), L = (f == null ? void 0 : f.data) ?? [], q = (w) => {
1311
+ for (const u of [
1286
1312
  "title",
1287
1313
  "name",
1288
1314
  "label",
@@ -1291,13 +1317,13 @@ function hl({
1291
1317
  "project_id",
1292
1318
  "description"
1293
1319
  ]) {
1294
- const S = w[c];
1295
- if (typeof S == "string" && S.trim()) return S.slice(0, 90);
1320
+ const N = w[u];
1321
+ if (typeof N == "string" && N.trim()) return N.slice(0, 90);
1296
1322
  }
1297
- const P = Object.entries(w).find(
1298
- ([c, S]) => c !== "id" && typeof S == "string" && S.trim()
1323
+ const E = Object.entries(w).find(
1324
+ ([u, N]) => u !== "id" && typeof N == "string" && N.trim()
1299
1325
  );
1300
- return P ? String(P[1]).slice(0, 90) : `#${w.id}`;
1326
+ return E ? String(E[1]).slice(0, 90) : `#${w.id}`;
1301
1327
  };
1302
1328
  return /* @__PURE__ */ e(
1303
1329
  "div",
@@ -1313,11 +1339,11 @@ function hl({
1313
1339
  /* @__PURE__ */ i("div", { className: "flex items-center gap-2 border-b border-slate-100 px-4 py-2.5 dark:border-border", children: [
1314
1340
  /* @__PURE__ */ e("p", { className: "min-w-0 flex-1 truncate text-[13px] font-semibold text-slate-800 dark:text-slate-100", children: a }),
1315
1341
  /* @__PURE__ */ e("span", { className: "text-[11.5px] tabular-nums text-slate-400", children: f ? `${L.length}${(f.total ?? 0) > L.length ? ` of ${f.total.toLocaleString()}` : ""} records` : "" }),
1316
- u && /* @__PURE__ */ e(
1342
+ m && /* @__PURE__ */ e(
1317
1343
  "button",
1318
1344
  {
1319
1345
  type: "button",
1320
- onClick: u,
1346
+ onClick: m,
1321
1347
  title: "Apply this value as a filter across the whole report",
1322
1348
  className: "shrink-0 rounded-md border border-nvr-cyan/40 bg-nvr-cyan/[0.08] px-2 py-0.5 text-[11px] font-medium text-[#007a99] hover:brightness-105 dark:text-nvr-cyan",
1323
1349
  children: "Filter report"
@@ -1340,9 +1366,9 @@ function hl({
1340
1366
  "button",
1341
1367
  {
1342
1368
  type: "button",
1343
- onClick: () => m({ collection: t, itemId: String(w.id) }),
1369
+ onClick: () => c({ collection: t, itemId: String(w.id) }),
1344
1370
  className: "block w-full truncate rounded-md px-2.5 py-1.5 text-left text-[12.5px] text-slate-700 hover:bg-slate-50 dark:text-slate-200 dark:hover:bg-muted",
1345
- children: $(w)
1371
+ children: q(w)
1346
1372
  },
1347
1373
  String(w.id)
1348
1374
  ))
@@ -1353,7 +1379,7 @@ function hl({
1353
1379
  }
1354
1380
  );
1355
1381
  }
1356
- const Wt = {
1382
+ const Bt = {
1357
1383
  red: {
1358
1384
  cell: "bg-red-50 text-red-700 dark:bg-red-500/15 dark:text-red-300",
1359
1385
  row: "bg-red-50/70 dark:bg-red-500/10"
@@ -1371,212 +1397,215 @@ const Wt = {
1371
1397
  row: "bg-sky-50/70 dark:bg-sky-500/10"
1372
1398
  }
1373
1399
  };
1374
- function Bt(t, s) {
1375
- const a = Number(s);
1400
+ function Qt(t, n) {
1401
+ const a = Number(n);
1376
1402
  return Number.isFinite(a) ? t.op === "gt" ? a > t.value : t.op === "gte" ? a >= t.value : t.op === "lt" ? a < t.value : t.op === "lte" ? a <= t.value : a === t.value : !1;
1377
1403
  }
1378
- const Tt = Aa(function({
1379
- reportId: s,
1404
+ const Lt = Ta(function({
1405
+ reportId: n,
1380
1406
  widget: a,
1381
1407
  dateRange: o,
1382
- entityFilters: m,
1383
- refetchInterval: u,
1408
+ entityFilters: c,
1409
+ refetchInterval: m,
1384
1410
  filterBar: h = [],
1385
1411
  onDrill: f,
1386
1412
  snapshot: p,
1387
1413
  asOf: L,
1388
- annotations: $,
1414
+ annotations: q,
1389
1415
  onAddAnnotation: w,
1390
- onDeleteAnnotation: P,
1391
- onCrossFilter: c,
1392
- reportUrl: S,
1393
- currentFilters: J
1416
+ onDeleteAnnotation: E,
1417
+ onCrossFilter: u,
1418
+ reportUrl: N,
1419
+ currentFilters: U
1394
1420
  }) {
1395
- var Be, ht, Qe, ft, Ue, xt, bt, Ie, gt, Ye, et, Je, tt, at, lt, re, vt, rt, nt, st;
1396
- const O = Ke(), [G, H] = C(""), [me, Z] = C(0), [te, se] = C(null), [fe, be] = C(!1), [Se, _e] = C(""), [x, I] = C(""), [ae, Y] = C(!1), [ue, le] = C(!1), [v, A] = C([]), X = St(null), [K, ie] = C(!1), [oe, pe] = C(null), [M, z] = C(!1), [de, ge] = C(null), ve = ["bar", "line", "donut", "pareto", "area"].includes(a.type) || a.type === "kpi" && !!((Be = a.config) != null && Be.compare || (ht = a.config) != null && ht.sparkline), Te = Ct(), [He, mt] = C(!1), Ne = async () => {
1397
- mt(!0);
1421
+ var ft, Ue, xt, Ve, bt, gt, tt, vt, Ye, at, Je, lt, rt, nt, re, yt, st, it, ot, Le;
1422
+ const O = Ke(), [ee, H] = C(""), [ue, pe] = C(0), [X, de] = C(null), [xe, be] = C(!1), [ge, $e] = C(""), [x, Z] = C(""), [te, V] = C(!1), [he, le] = C(!1), [ae, S] = C([]), T = St(null), P = sl(T), [Y, ne] = C(!1), [ce, fe] = C(null), [_, D] = C(!1), [me, ve] = C(null), we = ["bar", "line", "donut", "pareto", "area"].includes(a.type) || a.type === "kpi" && !!((ft = a.config) != null && ft.compare || (Ue = a.config) != null && Ue.sparkline), Te = Ct(), [Xe, ye] = C(!1), Ze = async () => {
1423
+ ye(!0);
1398
1424
  try {
1399
1425
  const l = await O.request(
1400
- yt(s, a.id, {
1426
+ kt(n, a.id, {
1401
1427
  date_range: o,
1402
- entity_filters: m,
1428
+ entity_filters: c,
1403
1429
  fresh: 1
1404
1430
  })
1405
1431
  );
1406
1432
  Te.setQueryData(
1407
- ["nivaro-report-widget", s, a.id, o, m],
1433
+ ["nivaro-report-widget", n, a.id, o, c],
1408
1434
  l.data
1409
1435
  );
1410
1436
  } catch {
1411
1437
  }
1412
- mt(!1);
1413
- }, Xe = dt(
1414
- () => ({ date_range: o ?? null, entity_filters: m }),
1415
- [o, m]
1416
- ), ye = Oa({
1438
+ ye(!1);
1439
+ }, ke = ut(
1440
+ () => ({ date_range: o ?? null, entity_filters: c }),
1441
+ [o, c]
1442
+ ), Fe = Ka({
1417
1443
  kind: "report",
1418
1444
  widget: a.id,
1419
- report: s,
1420
- params: Xe,
1421
- enabled: a.type !== "divider" && a.type !== "query",
1445
+ report: n,
1446
+ params: ke,
1447
+ enabled: P && a.type !== "divider" && a.type !== "query",
1422
1448
  onData: (l) => Te.setQueryData(
1423
- ["nivaro-report-widget", s, a.id, o, m],
1449
+ ["nivaro-report-widget", n, a.id, o, c],
1424
1450
  l
1425
1451
  ),
1426
- onStale: () => void De()
1452
+ onStale: () => void We()
1427
1453
  }), {
1428
- data: Fe,
1429
- isLoading: Ze,
1430
- error: Re,
1431
- refetch: De,
1432
- isFetching: ut
1433
- } = ke({
1434
- queryKey: ["nivaro-report-widget", s, a.id, o, m],
1454
+ data: Ie,
1455
+ isLoading: Ee,
1456
+ error: De,
1457
+ refetch: We,
1458
+ isFetching: $t
1459
+ } = Ne({
1460
+ queryKey: ["nivaro-report-widget", n, a.id, o, c],
1435
1461
  queryFn: () => O.request(
1436
- yt(s, a.id, {
1462
+ kt(n, a.id, {
1437
1463
  date_range: o,
1438
- entity_filters: m
1464
+ entity_filters: c
1439
1465
  })
1440
1466
  ).then((l) => l.data),
1441
1467
  // Query widgets resolve client-side in QueryWidgetBody — but when a
1442
1468
  // snapshot comparison is active, the server-resolved value (the same
1443
1469
  // number the snapshot stored) is fetched so the delta badge can render.
1444
- enabled: a.type !== "divider" && (a.type !== "query" || !!p),
1470
+ enabled: P && a.type !== "divider" && (a.type !== "query" || !!p),
1445
1471
  staleTime: 6e4,
1446
1472
  // Per-widget auto-refresh (#168) overrides the report-level interval.
1447
- refetchInterval: Ka(
1448
- ye,
1449
- Number((Qe = a.config) == null ? void 0 : Qe.refresh_secs) >= 10 ? Number(a.config.refresh_secs) * 1e3 : u
1473
+ refetchInterval: Da(
1474
+ Fe,
1475
+ Number((xt = a.config) == null ? void 0 : xt.refresh_secs) >= 10 ? Number(a.config.refresh_secs) * 1e3 : m
1450
1476
  ),
1451
1477
  retry: !1
1452
- }), We = (((ft = a.config) == null ? void 0 : ft.drill_levels) ?? []).filter(
1478
+ }), Be = (((Ve = a.config) == null ? void 0 : Ve.drill_levels) ?? []).filter(
1453
1479
  (l) => typeof l == "string" && l
1454
- ), { data: pt } = ke({
1455
- queryKey: ["nvr-report-drill", s, a.id, v, o, m],
1480
+ ), { data: ht } = Ne({
1481
+ queryKey: ["nvr-report-drill", n, a.id, ae, o, c],
1456
1482
  queryFn: () => O.request(
1457
- yt(s, a.id, {
1483
+ kt(n, a.id, {
1458
1484
  date_range: o,
1459
1485
  entity_filters: [
1460
- ...m,
1461
- ...v.map((l) => ({ field: l.field, values: [l.value] }))
1486
+ ...c,
1487
+ ...ae.map((l) => ({ field: l.field, values: [l.value] }))
1462
1488
  ],
1463
- dimension_override: We[v.length - 1]
1489
+ dimension_override: Be[ae.length - 1]
1464
1490
  })
1465
1491
  ).then((l) => l.data),
1466
- enabled: v.length > 0 && We.length > 0,
1492
+ enabled: ae.length > 0 && Be.length > 0,
1467
1493
  staleTime: 6e4,
1468
1494
  retry: !1
1469
- }), j = v.length > 0 && pt ? pt : Fe, xe = (Ue = a.config) == null ? void 0 : Ue.format, he = {
1495
+ }), R = ae.length > 0 && ht ? ht : Ie, se = (bt = a.config) == null ? void 0 : bt.format, et = {
1470
1496
  gridColumn: `${Math.max(1, (a.x ?? 0) + 1)} / span ${Math.min(12, Math.max(2, a.w || 4))}`,
1471
1497
  gridRow: `span ${Math.max(1, a.h || 3)}`
1472
1498
  };
1473
1499
  if (a.type === "divider")
1474
- return /* @__PURE__ */ e("div", { style: he, className: "self-end border-b border-slate-200 pb-1 dark:border-border", children: /* @__PURE__ */ e("h3", { className: "text-[13px] font-semibold text-slate-700 dark:text-slate-200", children: a.title }) });
1475
- const Pe = a.type === "query" ? (xt = a.config) == null ? void 0 : xt.query : null, $e = Pe ? {
1476
- ...Pe,
1477
- slug: Pe.slug || Pe.query_slug || ""
1500
+ return /* @__PURE__ */ e("div", { style: et, className: "self-end border-b border-slate-200 pb-1 dark:border-border", children: /* @__PURE__ */ e("h3", { className: "text-[13px] font-semibold text-slate-700 dark:text-slate-200", children: a.title }) });
1501
+ const Qe = a.type === "query" ? (gt = a.config) == null ? void 0 : gt.query : null, _e = Qe ? {
1502
+ ...Qe,
1503
+ slug: Qe.slug || Qe.query_slug || ""
1478
1504
  } : null;
1479
- let V = null;
1480
- if ($e != null && $e.slug)
1481
- V = /* @__PURE__ */ e(
1482
- sl,
1505
+ let J = null;
1506
+ if (_e != null && _e.slug)
1507
+ J = /* @__PURE__ */ e(
1508
+ ol,
1483
1509
  {
1484
- cfg: $e,
1510
+ cfg: _e,
1485
1511
  dateRange: o,
1486
- entityFilters: m,
1487
- refetchInterval: u,
1488
- onDrill: f
1512
+ entityFilters: c,
1513
+ refetchInterval: m,
1514
+ onDrill: f,
1515
+ deferred: !P
1489
1516
  }
1490
1517
  );
1491
1518
  else if (a.type === "query")
1492
- V = /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-400", children: "No query configured." });
1493
- else if (Ze)
1494
- V = /* @__PURE__ */ i("div", { className: "flex flex-col gap-2 px-1", children: [
1519
+ J = /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-400", children: "No query configured." });
1520
+ else if (!P && R === void 0)
1521
+ J = /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-300", children: "Loading…" });
1522
+ else if (Ee)
1523
+ J = /* @__PURE__ */ i("div", { className: "flex flex-col gap-2 px-1", children: [
1495
1524
  /* @__PURE__ */ e("p", { className: "text-[12px] text-slate-300", children: "Loading…" }),
1496
1525
  /* @__PURE__ */ e(
1497
- It,
1526
+ ea,
1498
1527
  {
1499
1528
  pending: !0,
1500
1529
  request: {
1501
1530
  method: "POST",
1502
- url: `/report-studio/${s}/widgets/${a.id}/data`,
1503
- body: { date_range: o, entity_filters: m }
1531
+ url: `/report-studio/${n}/widgets/${a.id}/data`,
1532
+ body: { date_range: o, entity_filters: c }
1504
1533
  },
1505
1534
  label: a.title || "Report widget",
1506
- queryKey: ["nivaro-report-widget", s, a.id, o, m],
1535
+ queryKey: ["nivaro-report-widget", n, a.id, o, c],
1507
1536
  select: (l) => l == null ? void 0 : l.data
1508
1537
  }
1509
1538
  )
1510
1539
  ] });
1511
- else if (Re)
1512
- V = /* @__PURE__ */ e(
1513
- ea,
1540
+ else if (De)
1541
+ J = /* @__PURE__ */ e(
1542
+ ta,
1514
1543
  {
1515
1544
  className: "px-1",
1516
- message: Zt(Re) ?? At(Re, "this widget"),
1517
- onRetry: () => void De()
1545
+ message: It(De) ?? Tt(De, "this widget"),
1546
+ onRetry: () => void We()
1518
1547
  }
1519
1548
  );
1520
- else if (j)
1549
+ else if (R)
1521
1550
  if (a.type === "queue") {
1522
- const l = j.series ?? [], n = Math.max(...l.map((R) => R.value), 1), g = Math.min(...l.map((R) => R.value), 0), q = Math.max(n - g, 1), _ = l.map(
1523
- (R, ne) => `${ne / Math.max(1, l.length - 1) * 100},${28 - (R.value - g) / q * 26}`
1551
+ const l = R.series ?? [], s = Math.max(...l.map((K) => K.value), 1), b = Math.min(...l.map((K) => K.value), 0), M = Math.max(s - b, 1), $ = l.map(
1552
+ (K, ie) => `${ie / Math.max(1, l.length - 1) * 100},${28 - (K.value - b) / M * 26}`
1524
1553
  ).join(" ");
1525
- V = /* @__PURE__ */ i("div", { className: "flex min-h-0 flex-1 flex-col justify-center", children: [
1526
- /* @__PURE__ */ e("p", { className: "text-[28px] font-semibold leading-none tracking-tight tabular-nums text-slate-900 dark:text-foreground", children: j.value == null ? "—" : Number(j.value).toLocaleString() }),
1554
+ J = /* @__PURE__ */ i("div", { className: "flex min-h-0 flex-1 flex-col justify-center", children: [
1555
+ /* @__PURE__ */ e("p", { className: "text-[28px] font-semibold leading-none tracking-tight tabular-nums text-slate-900 dark:text-foreground", children: R.value == null ? "—" : Number(R.value).toLocaleString() }),
1527
1556
  l.length >= 3 && /* @__PURE__ */ e("svg", { viewBox: "0 0 100 30", preserveAspectRatio: "none", className: "mt-1.5 h-7 w-full", children: /* @__PURE__ */ e(
1528
1557
  "polyline",
1529
1558
  {
1530
- points: _,
1559
+ points: $,
1531
1560
  fill: "none",
1532
- stroke: Ve,
1561
+ stroke: Ge,
1533
1562
  strokeWidth: "2",
1534
1563
  vectorEffect: "non-scaling-stroke"
1535
1564
  }
1536
1565
  ) }),
1537
1566
  /* @__PURE__ */ i("p", { className: "mt-0.5 text-[10.5px] text-slate-400", children: [
1538
- ((bt = a.config) == null ? void 0 : bt.metric) ?? "total",
1567
+ ((tt = a.config) == null ? void 0 : tt.metric) ?? "total",
1539
1568
  " · daily snapshots"
1540
1569
  ] })
1541
1570
  ] });
1542
1571
  } else if (a.type === "kpi" || a.type === "calc") {
1543
- if (V = /* @__PURE__ */ i("div", { className: "flex items-baseline gap-2", children: [
1572
+ if (J = /* @__PURE__ */ i("div", { className: "flex items-baseline gap-2", children: [
1544
1573
  /* @__PURE__ */ e(
1545
1574
  "p",
1546
1575
  {
1547
- className: Q(
1576
+ className: j(
1548
1577
  "text-[28px] font-semibold leading-none tracking-tight text-slate-900 dark:text-foreground",
1549
1578
  a.collection && "cursor-pointer decoration-dotted underline-offset-4 hover:underline",
1550
1579
  // KPI threshold colors (#211): first matching gte-descending rule wins.
1551
1580
  (() => {
1552
- var g;
1553
- const l = (g = a.config) == null ? void 0 : g.thresholds;
1554
- if (!(l != null && l.length) || j.value == null) return null;
1555
- const n = [...l].filter((q) => Number.isFinite(q.gte)).sort((q, _) => _.gte - q.gte).find((q) => j.value >= q.gte);
1556
- return (n == null ? void 0 : n.color) === "red" ? "!text-red-600 dark:!text-red-400" : (n == null ? void 0 : n.color) === "amber" ? "!text-amber-600 dark:!text-amber-400" : (n == null ? void 0 : n.color) === "green" ? "!text-emerald-600 dark:!text-emerald-400" : null;
1581
+ var b;
1582
+ const l = (b = a.config) == null ? void 0 : b.thresholds;
1583
+ if (!(l != null && l.length) || R.value == null) return null;
1584
+ const s = [...l].filter((M) => Number.isFinite(M.gte)).sort((M, $) => $.gte - M.gte).find((M) => R.value >= M.gte);
1585
+ return (s == null ? void 0 : s.color) === "red" ? "!text-red-600 dark:!text-red-400" : (s == null ? void 0 : s.color) === "amber" ? "!text-amber-600 dark:!text-amber-400" : (s == null ? void 0 : s.color) === "green" ? "!text-emerald-600 dark:!text-emerald-400" : null;
1557
1586
  })()
1558
1587
  ),
1559
1588
  title: a.collection ? "See the records behind this number" : void 0,
1560
1589
  onClick: () => {
1561
- a.collection && se({
1562
- conditions: qt(a, m, o),
1590
+ a.collection && de({
1591
+ conditions: Mt(a, c, o),
1563
1592
  title: a.title || a.collection
1564
1593
  });
1565
1594
  },
1566
- children: qe(j.value, xe)
1595
+ children: qe(R.value, se)
1567
1596
  }
1568
1597
  ),
1569
- /* @__PURE__ */ e(Pt, { pct: j.change_pct })
1570
- ] }), j.spark && j.spark.length >= 3) {
1571
- const l = j.spark, n = Math.max(...l.map((R) => R.value), 1), g = Math.min(...l.map((R) => R.value), 0), q = Math.max(n - g, 1), _ = l.map((R, ne) => `${ne / (l.length - 1) * 100},${28 - (R.value - g) / q * 26}`).join(" ");
1572
- V = /* @__PURE__ */ i("div", { className: "flex min-h-0 flex-1 flex-col justify-center", children: [
1573
- V,
1598
+ /* @__PURE__ */ e(zt, { pct: R.change_pct })
1599
+ ] }), R.spark && R.spark.length >= 3) {
1600
+ const l = R.spark, s = Math.max(...l.map((K) => K.value), 1), b = Math.min(...l.map((K) => K.value), 0), M = Math.max(s - b, 1), $ = l.map((K, ie) => `${ie / (l.length - 1) * 100},${28 - (K.value - b) / M * 26}`).join(" ");
1601
+ J = /* @__PURE__ */ i("div", { className: "flex min-h-0 flex-1 flex-col justify-center", children: [
1602
+ J,
1574
1603
  /* @__PURE__ */ e("svg", { viewBox: "0 0 100 30", preserveAspectRatio: "none", className: "mt-1.5 h-7 w-full", children: /* @__PURE__ */ e(
1575
1604
  "polyline",
1576
1605
  {
1577
- points: _,
1606
+ points: $,
1578
1607
  fill: "none",
1579
- stroke: Ve,
1608
+ stroke: Ge,
1580
1609
  strokeWidth: "2",
1581
1610
  vectorEffect: "non-scaling-stroke"
1582
1611
  }
@@ -1584,133 +1613,133 @@ const Tt = Aa(function({
1584
1613
  ] });
1585
1614
  }
1586
1615
  } else if (a.type === "kpi_group") {
1587
- const l = j.tiles ?? [];
1588
- V = /* @__PURE__ */ e(
1616
+ const l = R.tiles ?? [];
1617
+ J = /* @__PURE__ */ e(
1589
1618
  "div",
1590
1619
  {
1591
1620
  className: "grid gap-2",
1592
1621
  style: { gridTemplateColumns: `repeat(${Math.max(1, l.length)}, 1fr)` },
1593
- children: l.map((n, g) => /* @__PURE__ */ i(
1622
+ children: l.map((s, b) => /* @__PURE__ */ i(
1594
1623
  "div",
1595
1624
  {
1596
1625
  className: "flex flex-col justify-center rounded-md border border-slate-100 px-3 py-2 dark:border-border/60",
1597
1626
  style: {
1598
- borderTopColor: n.color ?? ce[g % ce.length],
1627
+ borderTopColor: s.color ?? oe[b % oe.length],
1599
1628
  borderTopWidth: 2
1600
1629
  },
1601
1630
  children: [
1602
- /* @__PURE__ */ e("p", { className: "truncate text-[10.5px] uppercase tracking-wide text-slate-400", children: n.label }),
1631
+ /* @__PURE__ */ e("p", { className: "truncate text-[10.5px] uppercase tracking-wide text-slate-400", children: s.label }),
1603
1632
  /* @__PURE__ */ i("div", { className: "flex items-baseline gap-1.5", children: [
1604
- /* @__PURE__ */ e("p", { className: "text-[19px] font-semibold leading-tight text-slate-900 dark:text-foreground", children: qe(n.value, n.format) }),
1605
- /* @__PURE__ */ e(Pt, { pct: n.change_pct })
1633
+ /* @__PURE__ */ e("p", { className: "text-[19px] font-semibold leading-tight text-slate-900 dark:text-foreground", children: qe(s.value, s.format) }),
1634
+ /* @__PURE__ */ e(zt, { pct: s.change_pct })
1606
1635
  ] })
1607
1636
  ]
1608
1637
  },
1609
- n.label
1638
+ s.label
1610
1639
  ))
1611
1640
  }
1612
1641
  );
1613
1642
  } else if (a.type === "narrative")
1614
- V = /* @__PURE__ */ e("div", { className: "min-h-0 flex-1 overflow-y-auto whitespace-pre-wrap text-[12.5px] leading-relaxed text-slate-700 dark:text-slate-300", children: (j.narrative ?? "").split(/(\*\*[^*]+\*\*)/g).map(
1615
- (l, n) => l.startsWith("**") && l.endsWith("**") ? /* @__PURE__ */ e("strong", { className: "font-semibold text-slate-900 dark:text-foreground", children: l.slice(2, -2) }, n) : /* @__PURE__ */ e("span", { children: l }, n)
1643
+ J = /* @__PURE__ */ e("div", { className: "min-h-0 flex-1 overflow-y-auto whitespace-pre-wrap text-[12.5px] leading-relaxed text-slate-700 dark:text-slate-300", children: (R.narrative ?? "").split(/(\*\*[^*]+\*\*)/g).map(
1644
+ (l, s) => l.startsWith("**") && l.endsWith("**") ? /* @__PURE__ */ e("strong", { className: "font-semibold text-slate-900 dark:text-foreground", children: l.slice(2, -2) }, s) : /* @__PURE__ */ e("span", { children: l }, s)
1616
1645
  ) });
1617
1646
  else if (a.type === "heatmap") {
1618
- const l = j.cells ?? [], n = [...new Set(l.map((R) => R.dim))], g = [...new Set(l.map((R) => R.dim2))], q = Math.max(1, ...l.map((R) => R.value)), _ = (R, ne) => l.find((ee) => ee.dim === R && ee.dim2 === ne);
1619
- V = l.length === 0 ? /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-400", children: "No data." }) : /* @__PURE__ */ e("div", { className: "min-h-0 flex-1 overflow-auto", children: /* @__PURE__ */ i("table", { className: "w-full text-[10.5px]", children: [
1647
+ const l = R.cells ?? [], s = [...new Set(l.map((K) => K.dim))], b = [...new Set(l.map((K) => K.dim2))], M = Math.max(1, ...l.map((K) => K.value)), $ = (K, ie) => l.find((I) => I.dim === K && I.dim2 === ie);
1648
+ J = l.length === 0 ? /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-400", children: "No data." }) : /* @__PURE__ */ e("div", { className: "min-h-0 flex-1 overflow-auto", children: /* @__PURE__ */ i("table", { className: "w-full text-[10.5px]", children: [
1620
1649
  /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ i("tr", { children: [
1621
1650
  /* @__PURE__ */ e("th", {}),
1622
- g.map((R) => /* @__PURE__ */ e(
1651
+ b.map((K) => /* @__PURE__ */ e(
1623
1652
  "th",
1624
1653
  {
1625
1654
  className: "max-w-[80px] truncate px-1 pb-1 text-left font-medium text-slate-400",
1626
- children: R
1655
+ children: K
1627
1656
  },
1628
- R
1657
+ K
1629
1658
  ))
1630
1659
  ] }) }),
1631
- /* @__PURE__ */ e("tbody", { children: n.map((R) => /* @__PURE__ */ i("tr", { children: [
1632
- /* @__PURE__ */ e("td", { className: "max-w-[110px] truncate pr-1.5 text-slate-500 dark:text-slate-400", children: R }),
1633
- g.map((ne) => {
1634
- const ee = _(R, ne), F = ee ? ee.value / q : 0;
1660
+ /* @__PURE__ */ e("tbody", { children: s.map((K) => /* @__PURE__ */ i("tr", { children: [
1661
+ /* @__PURE__ */ e("td", { className: "max-w-[110px] truncate pr-1.5 text-slate-500 dark:text-slate-400", children: K }),
1662
+ b.map((ie) => {
1663
+ const I = $(K, ie), A = I ? I.value / M : 0;
1635
1664
  return /* @__PURE__ */ e("td", { className: "p-0.5", children: /* @__PURE__ */ e(
1636
1665
  "div",
1637
1666
  {
1638
- "data-tip": ee ? `${R} × ${ne}: ${ee.value.toLocaleString()}` : void 0,
1667
+ "data-tip": I ? `${K} × ${ie}: ${I.value.toLocaleString()}` : void 0,
1639
1668
  className: "flex h-6 items-center justify-center rounded text-[9.5px] tabular-nums",
1640
1669
  style: {
1641
- backgroundColor: ee ? `rgba(0, 165, 204, ${0.08 + F * 0.85})` : "transparent",
1642
- color: F > 0.55 ? "#fff" : void 0,
1643
- border: ee ? void 0 : "1px dashed rgba(148,163,184,0.25)"
1670
+ backgroundColor: I ? `rgba(0, 165, 204, ${0.08 + A * 0.85})` : "transparent",
1671
+ color: A > 0.55 ? "#fff" : void 0,
1672
+ border: I ? void 0 : "1px dashed rgba(148,163,184,0.25)"
1644
1673
  },
1645
- children: ee ? Ce(Math.round(ee.value)) : ""
1674
+ children: I ? Ce(Math.round(I.value)) : ""
1646
1675
  }
1647
- ) }, ne);
1676
+ ) }, ie);
1648
1677
  })
1649
- ] }, R)) })
1678
+ ] }, K)) })
1650
1679
  ] }) });
1651
1680
  } else if (a.type === "ai_insight") {
1652
- const l = j.narrative ?? "";
1653
- V = /* @__PURE__ */ i("div", { className: "flex min-h-0 flex-1 flex-col", children: [
1681
+ const l = R.narrative ?? "";
1682
+ J = /* @__PURE__ */ i("div", { className: "flex min-h-0 flex-1 flex-col", children: [
1654
1683
  /* @__PURE__ */ i("div", { className: "mb-1 flex items-center gap-1.5", children: [
1655
- /* @__PURE__ */ e(Kt, { className: "h-3.5 w-3.5 text-[#00a5cc]" }),
1684
+ /* @__PURE__ */ e(Dt, { className: "h-3.5 w-3.5 text-[#00a5cc]" }),
1656
1685
  /* @__PURE__ */ e("span", { className: "text-[10px] uppercase tracking-wide text-slate-400", children: "AI-generated" }),
1657
1686
  /* @__PURE__ */ e(
1658
1687
  "button",
1659
1688
  {
1660
1689
  type: "button",
1661
1690
  title: "Regenerate this summary",
1662
- disabled: He,
1663
- onClick: () => void Ne(),
1691
+ disabled: Xe,
1692
+ onClick: () => void Ze(),
1664
1693
  className: "ml-auto rounded p-0.5 text-slate-300 hover:text-[#00a5cc] disabled:opacity-50",
1665
- children: /* @__PURE__ */ e(Mt, { className: Q("h-3 w-3", He && "animate-spin") })
1694
+ children: /* @__PURE__ */ e(Ft, { className: j("h-3 w-3", Xe && "animate-spin") })
1666
1695
  }
1667
1696
  )
1668
1697
  ] }),
1669
- /* @__PURE__ */ e("div", { className: "min-h-0 flex-1 overflow-y-auto whitespace-pre-wrap text-[12.5px] leading-relaxed text-slate-700 dark:text-slate-300", children: He ? "Regenerating…" : l })
1698
+ /* @__PURE__ */ e("div", { className: "min-h-0 flex-1 overflow-y-auto whitespace-pre-wrap text-[12.5px] leading-relaxed text-slate-700 dark:text-slate-300", children: Xe ? "Regenerating…" : l })
1670
1699
  ] });
1671
1700
  } else if (a.type === "pivot") {
1672
- const l = j.pivot;
1673
- V = !l || l.rows.length === 0 ? /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-400", children: "No data." }) : /* @__PURE__ */ i("div", { className: "flex min-h-0 flex-1 flex-col", children: [
1701
+ const l = R.pivot;
1702
+ J = !l || l.rows.length === 0 ? /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-400", children: "No data." }) : /* @__PURE__ */ i("div", { className: "flex min-h-0 flex-1 flex-col", children: [
1674
1703
  /* @__PURE__ */ e("div", { className: "min-h-0 flex-1 overflow-auto", children: /* @__PURE__ */ i("table", { className: "w-full border-collapse text-[10.5px]", children: [
1675
1704
  /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ i("tr", { children: [
1676
1705
  /* @__PURE__ */ e("th", { className: "sticky left-0 top-0 z-[2] bg-white dark:bg-card" }),
1677
- l.cols.map((n) => /* @__PURE__ */ e(
1706
+ l.cols.map((s) => /* @__PURE__ */ e(
1678
1707
  "th",
1679
1708
  {
1680
1709
  className: "sticky top-0 z-[1] whitespace-nowrap bg-white px-1.5 pb-1 text-right font-medium text-slate-400 dark:bg-card",
1681
- children: n
1710
+ children: s
1682
1711
  },
1683
- n
1712
+ s
1684
1713
  )),
1685
1714
  /* @__PURE__ */ e("th", { className: "sticky top-0 z-[1] bg-white px-1.5 pb-1 text-right font-semibold text-slate-500 dark:bg-card dark:text-slate-300", children: "Total" })
1686
1715
  ] }) }),
1687
- /* @__PURE__ */ e("tbody", { children: l.rows.map((n) => /* @__PURE__ */ i("tr", { className: "hover:bg-muted", children: [
1688
- /* @__PURE__ */ e("td", { className: "sticky left-0 z-[1] max-w-[150px] truncate bg-white pr-1.5 text-slate-500 dark:bg-card dark:text-slate-400", children: n }),
1689
- l.cols.map((g) => {
1690
- var _;
1691
- const q = (_ = l.cells[n]) == null ? void 0 : _[g];
1716
+ /* @__PURE__ */ e("tbody", { children: l.rows.map((s) => /* @__PURE__ */ i("tr", { className: "hover:bg-muted", children: [
1717
+ /* @__PURE__ */ e("td", { className: "sticky left-0 z-[1] max-w-[150px] truncate bg-white pr-1.5 text-slate-500 dark:bg-card dark:text-slate-400", children: s }),
1718
+ l.cols.map((b) => {
1719
+ var $;
1720
+ const M = ($ = l.cells[s]) == null ? void 0 : $[b];
1692
1721
  return /* @__PURE__ */ e(
1693
1722
  "td",
1694
1723
  {
1695
1724
  className: "px-1.5 py-0.5 text-right tabular-nums text-slate-700 dark:text-slate-300",
1696
- children: q == null ? "" : qe(q, xe)
1725
+ children: M == null ? "" : qe(M, se)
1697
1726
  },
1698
- g
1727
+ b
1699
1728
  );
1700
1729
  }),
1701
- /* @__PURE__ */ e("td", { className: "px-1.5 py-0.5 text-right font-semibold tabular-nums text-slate-800 dark:text-slate-200", children: qe(l.row_totals[n] ?? 0, xe) })
1702
- ] }, n)) }),
1730
+ /* @__PURE__ */ e("td", { className: "px-1.5 py-0.5 text-right font-semibold tabular-nums text-slate-800 dark:text-slate-200", children: qe(l.row_totals[s] ?? 0, se) })
1731
+ ] }, s)) }),
1703
1732
  /* @__PURE__ */ e("tfoot", { children: /* @__PURE__ */ i("tr", { className: "border-t border-slate-200 dark:border-border", children: [
1704
1733
  /* @__PURE__ */ e("td", { className: "sticky left-0 z-[1] bg-white pr-1.5 font-semibold text-slate-600 dark:bg-card dark:text-slate-300", children: "Total" }),
1705
- l.cols.map((n) => /* @__PURE__ */ e(
1734
+ l.cols.map((s) => /* @__PURE__ */ e(
1706
1735
  "td",
1707
1736
  {
1708
1737
  className: "px-1.5 py-0.5 text-right font-semibold tabular-nums text-slate-800 dark:text-slate-200",
1709
- children: qe(l.col_totals[n] ?? 0, xe)
1738
+ children: qe(l.col_totals[s] ?? 0, se)
1710
1739
  },
1711
- n
1740
+ s
1712
1741
  )),
1713
- /* @__PURE__ */ e("td", { className: "px-1.5 py-0.5 text-right font-semibold tabular-nums text-slate-900 dark:text-foreground", children: qe(l.grand_total, xe) })
1742
+ /* @__PURE__ */ e("td", { className: "px-1.5 py-0.5 text-right font-semibold tabular-nums text-slate-900 dark:text-foreground", children: qe(l.grand_total, se) })
1714
1743
  ] }) })
1715
1744
  ] }) }),
1716
1745
  (l.truncated_rows > 0 || l.truncated_cols > 0) && /* @__PURE__ */ i("p", { className: "mt-1 shrink-0 px-1 text-[10px] text-amber-600 dark:text-amber-400", children: [
@@ -1729,98 +1758,98 @@ const Tt = Aa(function({
1729
1758
  ] })
1730
1759
  ] });
1731
1760
  } else if (a.type === "waterfall") {
1732
- const l = j.waterfall;
1733
- V = l ? (() => {
1734
- const n = [];
1735
- n.push({ label: "Previous", from: 0, to: l.start, kind: "total" });
1736
- let g = l.start;
1737
- for (const _ of l.steps)
1738
- n.push({
1739
- label: _.dim,
1740
- from: g,
1741
- to: g + _.delta,
1742
- kind: _.delta >= 0 ? "up" : "down"
1743
- }), g += _.delta;
1744
- n.push({ label: "Current", from: 0, to: l.end, kind: "total" });
1745
- const q = Math.max(1, ...n.map((_) => Math.max(_.from, _.to)));
1746
- return /* @__PURE__ */ e("div", { className: "flex min-h-0 flex-1 items-end gap-1 overflow-x-auto px-1 pb-4", children: n.map((_, R) => {
1747
- const ne = Math.max(_.from, _.to) / q * 100, ee = Math.abs(_.to - _.from) / q * 100;
1761
+ const l = R.waterfall;
1762
+ J = l ? (() => {
1763
+ const s = [];
1764
+ s.push({ label: "Previous", from: 0, to: l.start, kind: "total" });
1765
+ let b = l.start;
1766
+ for (const $ of l.steps)
1767
+ s.push({
1768
+ label: $.dim,
1769
+ from: b,
1770
+ to: b + $.delta,
1771
+ kind: $.delta >= 0 ? "up" : "down"
1772
+ }), b += $.delta;
1773
+ s.push({ label: "Current", from: 0, to: l.end, kind: "total" });
1774
+ const M = Math.max(1, ...s.map(($) => Math.max($.from, $.to)));
1775
+ return /* @__PURE__ */ e("div", { className: "flex min-h-0 flex-1 items-end gap-1 overflow-x-auto px-1 pb-4", children: s.map(($, K) => {
1776
+ const ie = Math.max($.from, $.to) / M * 100, I = Math.abs($.to - $.from) / M * 100;
1748
1777
  return /* @__PURE__ */ i(
1749
1778
  "div",
1750
1779
  {
1751
1780
  className: "relative flex h-full min-w-[46px] flex-1 flex-col justify-end",
1752
1781
  children: [
1753
- /* @__PURE__ */ e("div", { style: { height: `${Math.max(ne, 0.5)}%` }, className: "relative w-full", children: /* @__PURE__ */ e(
1782
+ /* @__PURE__ */ e("div", { style: { height: `${Math.max(ie, 0.5)}%` }, className: "relative w-full", children: /* @__PURE__ */ e(
1754
1783
  "div",
1755
1784
  {
1756
- "data-tip": `${_.label}: ${(_.to - _.from).toLocaleString()}`,
1785
+ "data-tip": `${$.label}: ${($.to - $.from).toLocaleString()}`,
1757
1786
  className: "absolute inset-x-0 top-0 rounded-sm",
1758
1787
  style: {
1759
- height: `${Math.max(ee / Math.max(ne, 1e-3) * 100, 2)}%`,
1760
- backgroundColor: _.kind === "total" ? "#172940" : _.kind === "up" ? "#10b981" : "#ef4444"
1788
+ height: `${Math.max(I / Math.max(ie, 1e-3) * 100, 2)}%`,
1789
+ backgroundColor: $.kind === "total" ? "#172940" : $.kind === "up" ? "#10b981" : "#ef4444"
1761
1790
  }
1762
1791
  }
1763
1792
  ) }),
1764
- /* @__PURE__ */ e("p", { className: "absolute -bottom-4 left-0 right-0 truncate text-center text-[9px] text-slate-400", children: _.label })
1793
+ /* @__PURE__ */ e("p", { className: "absolute -bottom-4 left-0 right-0 truncate text-center text-[9px] text-slate-400", children: $.label })
1765
1794
  ]
1766
1795
  },
1767
- R
1796
+ K
1768
1797
  );
1769
1798
  }) });
1770
1799
  })() : /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-400", children: "No data." });
1771
1800
  } else if (a.type === "stats") {
1772
- const l = j.rows ?? [];
1773
- V = l.length === 0 ? /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-400", children: "No data." }) : /* @__PURE__ */ e("div", { className: "grid min-h-0 flex-1 grid-cols-2 content-start gap-x-4 gap-y-1.5 overflow-auto px-1", children: l.map((n) => /* @__PURE__ */ i(
1801
+ const l = R.rows ?? [];
1802
+ J = l.length === 0 ? /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-400", children: "No data." }) : /* @__PURE__ */ e("div", { className: "grid min-h-0 flex-1 grid-cols-2 content-start gap-x-4 gap-y-1.5 overflow-auto px-1", children: l.map((s) => /* @__PURE__ */ i(
1774
1803
  "div",
1775
1804
  {
1776
1805
  className: "flex items-baseline justify-between border-b border-slate-100 pb-1 dark:border-border/50",
1777
1806
  children: [
1778
- /* @__PURE__ */ e("span", { className: "text-[11px] text-slate-500", children: n.stat }),
1779
- /* @__PURE__ */ e("span", { className: "text-[13px] font-semibold tabular-nums text-slate-800 dark:text-slate-100", children: n.value == null ? "—" : qe(n.value, xe) })
1807
+ /* @__PURE__ */ e("span", { className: "text-[11px] text-slate-500", children: s.stat }),
1808
+ /* @__PURE__ */ e("span", { className: "text-[13px] font-semibold tabular-nums text-slate-800 dark:text-slate-100", children: s.value == null ? "—" : qe(s.value, se) })
1780
1809
  ]
1781
1810
  },
1782
- n.stat
1811
+ s.stat
1783
1812
  )) });
1784
1813
  } else if (a.type === "hot_records") {
1785
- const l = j.rows ?? [], n = Math.max(1, ...l.map((g) => g.views));
1786
- V = l.length === 0 ? /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-400", children: "No views recorded in the window." }) : /* @__PURE__ */ e("div", { className: "min-h-0 flex-1 space-y-1 overflow-auto px-1", children: l.map((g) => /* @__PURE__ */ i(
1814
+ const l = R.rows ?? [], s = Math.max(1, ...l.map((b) => b.views));
1815
+ J = l.length === 0 ? /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-400", children: "No views recorded in the window." }) : /* @__PURE__ */ e("div", { className: "min-h-0 flex-1 space-y-1 overflow-auto px-1", children: l.map((b) => /* @__PURE__ */ i(
1787
1816
  "button",
1788
1817
  {
1789
1818
  type: "button",
1790
- onClick: () => a.collection && (f == null ? void 0 : f({ collection: a.collection, itemId: String(g.id), title: g.label })),
1819
+ onClick: () => a.collection && (f == null ? void 0 : f({ collection: a.collection, itemId: String(b.id), title: b.label })),
1791
1820
  className: "group flex w-full items-center gap-2 rounded px-1 py-0.5 text-left hover:bg-muted",
1792
1821
  children: [
1793
- /* @__PURE__ */ e("span", { className: "min-w-0 flex-1 truncate text-[12px] text-slate-700 group-hover:text-[#0284c7] dark:text-slate-200", children: g.label }),
1822
+ /* @__PURE__ */ e("span", { className: "min-w-0 flex-1 truncate text-[12px] text-slate-700 group-hover:text-[#0284c7] dark:text-slate-200", children: b.label }),
1794
1823
  /* @__PURE__ */ e("span", { className: "relative h-2 w-20 overflow-hidden rounded-full bg-slate-100 dark:bg-white/10", children: /* @__PURE__ */ e(
1795
1824
  "span",
1796
1825
  {
1797
1826
  className: "absolute inset-y-0 left-0 rounded-full bg-[#00a5cc]",
1798
- style: { width: `${g.views / n * 100}%` }
1827
+ style: { width: `${b.views / s * 100}%` }
1799
1828
  }
1800
1829
  ) }),
1801
- /* @__PURE__ */ e("span", { className: "w-8 text-right text-[11px] tabular-nums text-slate-400", children: g.views })
1830
+ /* @__PURE__ */ e("span", { className: "w-8 text-right text-[11px] tabular-nums text-slate-400", children: b.views })
1802
1831
  ]
1803
1832
  },
1804
- g.id
1833
+ b.id
1805
1834
  )) });
1806
1835
  } else if (a.type === "scatter") {
1807
- const l = j.rows ?? [];
1808
- V = l.length === 0 ? /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-400", children: "No data." }) : (() => {
1809
- const n = l.length, g = l.reduce((b, y) => b + y.x, 0), q = l.reduce((b, y) => b + y.y, 0), _ = l.reduce((b, y) => b + y.x * y.x, 0), R = l.reduce((b, y) => b + y.x * y.y, 0), ne = n * _ - g * g, ee = ne !== 0 ? (n * R - g * q) / ne : 0, F = n > 0 ? (q - ee * g) / n : 0, U = l.map((b) => b.x), W = Math.min(...U), D = Math.max(...U), r = [
1810
- { x: W, y: F + ee * W },
1811
- { x: D, y: F + ee * D }
1836
+ const l = R.rows ?? [];
1837
+ J = l.length === 0 ? /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-400", children: "No data." }) : (() => {
1838
+ const s = l.length, b = l.reduce((g, k) => g + k.x, 0), M = l.reduce((g, k) => g + k.y, 0), $ = l.reduce((g, k) => g + k.x * k.x, 0), K = l.reduce((g, k) => g + k.x * k.y, 0), ie = s * $ - b * b, I = ie !== 0 ? (s * K - b * M) / ie : 0, A = s > 0 ? (M - I * b) / s : 0, W = l.map((g) => g.x), z = Math.min(...W), r = Math.max(...W), v = [
1839
+ { x: z, y: A + I * z },
1840
+ { x: r, y: A + I * r }
1812
1841
  ];
1813
- return /* @__PURE__ */ e("div", { className: "min-h-0 flex-1", children: /* @__PURE__ */ e(Le, { fallback: /* @__PURE__ */ e(Oe, { className: "h-full w-full", "aria-busy": "true" }), children: ({
1814
- ComposedChart: b,
1815
- Line: y,
1842
+ return /* @__PURE__ */ e("div", { className: "min-h-0 flex-1", children: /* @__PURE__ */ e(Re, { fallback: /* @__PURE__ */ e(Oe, { className: "h-full w-full", "aria-busy": "true" }), children: ({
1843
+ ComposedChart: g,
1844
+ Line: k,
1816
1845
  ResponsiveContainer: d,
1817
- Scatter: k,
1818
- Tooltip: N,
1819
- XAxis: E,
1820
- YAxis: B
1821
- }) => /* @__PURE__ */ e(d, { width: "100%", height: "100%", children: /* @__PURE__ */ i(b, { data: l, margin: { top: 6, right: 8, left: -6, bottom: 0 }, children: [
1846
+ Scatter: y,
1847
+ Tooltip: F,
1848
+ XAxis: B,
1849
+ YAxis: G
1850
+ }) => /* @__PURE__ */ e(d, { width: "100%", height: "100%", children: /* @__PURE__ */ i(g, { data: l, margin: { top: 6, right: 8, left: -6, bottom: 0 }, children: [
1822
1851
  /* @__PURE__ */ e(
1823
- E,
1852
+ B,
1824
1853
  {
1825
1854
  dataKey: "x",
1826
1855
  type: "number",
@@ -1829,9 +1858,9 @@ const Tt = Aa(function({
1829
1858
  domain: ["dataMin", "dataMax"]
1830
1859
  }
1831
1860
  ),
1832
- /* @__PURE__ */ e(B, { tick: { fontSize: 10 }, tickFormatter: Ce }),
1861
+ /* @__PURE__ */ e(G, { tick: { fontSize: 10 }, tickFormatter: Ce }),
1833
1862
  /* @__PURE__ */ e(
1834
- N,
1863
+ F,
1835
1864
  {
1836
1865
  contentStyle: {
1837
1866
  fontSize: 12,
@@ -1842,11 +1871,11 @@ const Tt = Aa(function({
1842
1871
  }
1843
1872
  }
1844
1873
  ),
1845
- /* @__PURE__ */ e(k, { data: l, dataKey: "y", fill: "#00a5cc", opacity: 0.7 }),
1874
+ /* @__PURE__ */ e(y, { data: l, dataKey: "y", fill: "#00a5cc", opacity: 0.7 }),
1846
1875
  /* @__PURE__ */ e(
1847
- y,
1876
+ k,
1848
1877
  {
1849
- data: r,
1878
+ data: v,
1850
1879
  dataKey: "y",
1851
1880
  stroke: "#f59e0b",
1852
1881
  strokeWidth: 2,
@@ -1857,10 +1886,10 @@ const Tt = Aa(function({
1857
1886
  ] }) }) }) });
1858
1887
  })();
1859
1888
  } else if (a.type === "pareto") {
1860
- const l = j.series ?? [];
1861
- V = l.length === 0 ? /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-400", children: "No data." }) : /* @__PURE__ */ e("div", { className: "min-h-0 flex-1", children: /* @__PURE__ */ e(Le, { fallback: /* @__PURE__ */ e(Oe, { className: "h-full w-full", "aria-busy": "true" }), children: ({ Bar: n, ComposedChart: g, Line: q, ResponsiveContainer: _, Tooltip: R, XAxis: ne, YAxis: ee }) => /* @__PURE__ */ e(_, { width: "100%", height: "100%", children: /* @__PURE__ */ i(g, { data: l, margin: { top: 6, right: 4, left: -10, bottom: 0 }, children: [
1889
+ const l = R.series ?? [];
1890
+ J = l.length === 0 ? /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-400", children: "No data." }) : /* @__PURE__ */ e("div", { className: "min-h-0 flex-1", children: /* @__PURE__ */ e(Re, { fallback: /* @__PURE__ */ e(Oe, { className: "h-full w-full", "aria-busy": "true" }), children: ({ Bar: s, ComposedChart: b, Line: M, ResponsiveContainer: $, Tooltip: K, XAxis: ie, YAxis: I }) => /* @__PURE__ */ e($, { width: "100%", height: "100%", children: /* @__PURE__ */ i(b, { data: l, margin: { top: 6, right: 4, left: -10, bottom: 0 }, children: [
1862
1891
  /* @__PURE__ */ e(
1863
- ne,
1892
+ ie,
1864
1893
  {
1865
1894
  dataKey: "dim",
1866
1895
  tick: { fontSize: 10 },
@@ -1870,19 +1899,19 @@ const Tt = Aa(function({
1870
1899
  height: 42
1871
1900
  }
1872
1901
  ),
1873
- /* @__PURE__ */ e(ee, { yAxisId: "v", tick: { fontSize: 10 }, tickFormatter: Ce }),
1902
+ /* @__PURE__ */ e(I, { yAxisId: "v", tick: { fontSize: 10 }, tickFormatter: Ce }),
1874
1903
  /* @__PURE__ */ e(
1875
- ee,
1904
+ I,
1876
1905
  {
1877
1906
  yAxisId: "pct",
1878
1907
  orientation: "right",
1879
1908
  domain: [0, 100],
1880
1909
  tick: { fontSize: 10 },
1881
- tickFormatter: (F) => `${F}%`
1910
+ tickFormatter: (A) => `${A}%`
1882
1911
  }
1883
1912
  ),
1884
1913
  /* @__PURE__ */ e(
1885
- R,
1914
+ K,
1886
1915
  {
1887
1916
  contentStyle: {
1888
1917
  fontSize: 12,
@@ -1894,7 +1923,7 @@ const Tt = Aa(function({
1894
1923
  }
1895
1924
  ),
1896
1925
  /* @__PURE__ */ e(
1897
- n,
1926
+ s,
1898
1927
  {
1899
1928
  yAxisId: "v",
1900
1929
  dataKey: "value",
@@ -1904,7 +1933,7 @@ const Tt = Aa(function({
1904
1933
  }
1905
1934
  ),
1906
1935
  /* @__PURE__ */ e(
1907
- q,
1936
+ M,
1908
1937
  {
1909
1938
  yAxisId: "pct",
1910
1939
  dataKey: "cum_pct",
@@ -1916,94 +1945,94 @@ const Tt = Aa(function({
1916
1945
  )
1917
1946
  ] }) }) }) });
1918
1947
  } else if (a.type === "metric")
1919
- V = /* @__PURE__ */ i("div", { className: "flex min-h-0 flex-1 flex-col justify-center px-1", children: [
1920
- /* @__PURE__ */ e("p", { className: "text-[26px] font-bold tabular-nums text-slate-900 dark:text-slate-50", children: j.value == null ? "—" : qe(j.value, xe) }),
1921
- /* @__PURE__ */ e("p", { className: "text-[11px] text-slate-400", children: String(((Ie = a.config) == null ? void 0 : Ie.metric_key) ?? "") })
1948
+ J = /* @__PURE__ */ i("div", { className: "flex min-h-0 flex-1 flex-col justify-center px-1", children: [
1949
+ /* @__PURE__ */ e("p", { className: "text-[26px] font-bold tabular-nums text-slate-900 dark:text-slate-50", children: R.value == null ? "—" : qe(R.value, se) }),
1950
+ /* @__PURE__ */ e("p", { className: "text-[11px] text-slate-400", children: String(((vt = a.config) == null ? void 0 : vt.metric_key) ?? "") })
1922
1951
  ] });
1923
1952
  else if (a.type === "movers") {
1924
- const l = j.rows ?? [];
1925
- V = l.length === 0 ? /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-400", children: "No movement in this window." }) : /* @__PURE__ */ e("div", { className: "min-h-0 flex-1 space-y-0.5 overflow-y-auto", children: l.map((n) => /* @__PURE__ */ i("div", { className: "flex items-center gap-2 text-[11.5px]", children: [
1926
- /* @__PURE__ */ e("span", { className: "min-w-0 flex-1 truncate text-slate-600 dark:text-slate-300", children: n.dim }),
1953
+ const l = R.rows ?? [];
1954
+ J = l.length === 0 ? /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-400", children: "No movement in this window." }) : /* @__PURE__ */ e("div", { className: "min-h-0 flex-1 space-y-0.5 overflow-y-auto", children: l.map((s) => /* @__PURE__ */ i("div", { className: "flex items-center gap-2 text-[11.5px]", children: [
1955
+ /* @__PURE__ */ e("span", { className: "min-w-0 flex-1 truncate text-slate-600 dark:text-slate-300", children: s.dim }),
1927
1956
  /* @__PURE__ */ i("span", { className: "tabular-nums text-slate-400", children: [
1928
- n.previous.toLocaleString(),
1957
+ s.previous.toLocaleString(),
1929
1958
  " → ",
1930
- n.current.toLocaleString()
1959
+ s.current.toLocaleString()
1931
1960
  ] }),
1932
1961
  /* @__PURE__ */ i(
1933
1962
  "span",
1934
1963
  {
1935
- className: Q(
1964
+ className: j(
1936
1965
  "w-[74px] shrink-0 text-right font-semibold tabular-nums",
1937
- n.delta > 0 ? "text-emerald-600 dark:text-emerald-400" : "text-red-500"
1966
+ s.delta > 0 ? "text-emerald-600 dark:text-emerald-400" : "text-red-500"
1938
1967
  ),
1939
1968
  children: [
1940
- n.delta > 0 ? "+" : "",
1941
- n.delta.toLocaleString(),
1942
- n.delta_pct != null && /* @__PURE__ */ i("span", { className: "ml-1 text-[10px] font-normal text-slate-400", children: [
1943
- n.delta_pct > 0 ? "+" : "",
1944
- n.delta_pct.toFixed(0),
1969
+ s.delta > 0 ? "+" : "",
1970
+ s.delta.toLocaleString(),
1971
+ s.delta_pct != null && /* @__PURE__ */ i("span", { className: "ml-1 text-[10px] font-normal text-slate-400", children: [
1972
+ s.delta_pct > 0 ? "+" : "",
1973
+ s.delta_pct.toFixed(0),
1945
1974
  "%"
1946
1975
  ] })
1947
1976
  ]
1948
1977
  }
1949
1978
  )
1950
- ] }, n.dim)) });
1979
+ ] }, s.dim)) });
1951
1980
  } else if (a.type === "table") {
1952
- const l = j.rows ?? [], n = (gt = a.config) != null && gt.columns && a.config.columns.length > 0 ? a.config.columns.map((d) => typeof d == "string" ? { field: d } : d) : l[0] ? Object.keys(l[0]).filter((d) => d !== "id").map((d) => ({ field: d })) : [], g = n.map((d) => d.field), q = (d) => n.find((k) => k.field === d), _ = ((Ye = a.config) == null ? void 0 : Ye.format_rules) ?? [], R = (d) => {
1953
- var k;
1954
- for (const N of _)
1955
- if ((N.scope ?? "cell") === "row" && Bt(N, d[N.field]))
1956
- return ((k = Wt[N.color]) == null ? void 0 : k.row) ?? null;
1981
+ const l = R.rows ?? [], s = (Ye = a.config) != null && Ye.columns && a.config.columns.length > 0 ? a.config.columns.map((d) => typeof d == "string" ? { field: d } : d) : l[0] ? Object.keys(l[0]).filter((d) => d !== "id").map((d) => ({ field: d })) : [], b = s.map((d) => d.field), M = (d) => s.find((y) => y.field === d), $ = ((at = a.config) == null ? void 0 : at.format_rules) ?? [], K = (d) => {
1982
+ var y;
1983
+ for (const F of $)
1984
+ if ((F.scope ?? "cell") === "row" && Qt(F, d[F.field]))
1985
+ return ((y = Bt[F.color]) == null ? void 0 : y.row) ?? null;
1957
1986
  return null;
1958
- }, ne = (d, k) => {
1959
- var N;
1960
- for (const E of _)
1961
- if ((E.scope ?? "cell") === "cell" && E.field === k && Bt(E, d[k]))
1962
- return ((N = Wt[E.color]) == null ? void 0 : N.cell) ?? null;
1987
+ }, ie = (d, y) => {
1988
+ var F;
1989
+ for (const B of $)
1990
+ if ((B.scope ?? "cell") === "cell" && B.field === y && Qt(B, d[y]))
1991
+ return ((F = Bt[B.color]) == null ? void 0 : F.cell) ?? null;
1963
1992
  return null;
1964
- }, ee = G.trim().toLowerCase(), F = a.config, U = F != null && F.suppress_zero ? l.filter(
1965
- (d) => g.some((k) => {
1966
- const N = Number(d[k]);
1967
- return Number.isFinite(N) && N !== 0;
1993
+ }, I = ee.trim().toLowerCase(), A = a.config, W = A != null && A.suppress_zero ? l.filter(
1994
+ (d) => b.some((y) => {
1995
+ const F = Number(d[y]);
1996
+ return Number.isFinite(F) && F !== 0;
1968
1997
  })
1969
- ) : l, W = ee ? U.filter(
1998
+ ) : l, z = I ? W.filter(
1970
1999
  (d) => Object.values(d).some(
1971
- (k) => String(k ?? "").toLowerCase().includes(ee)
2000
+ (y) => String(y ?? "").toLowerCase().includes(I)
1972
2001
  )
1973
- ) : U, D = 12, r = Math.max(1, Math.ceil(W.length / D)), b = Math.min(me, r - 1), y = W.length > D ? W.slice(b * D, b * D + D) : W;
1974
- V = l.length === 0 ? /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-400", children: "No rows." }) : /* @__PURE__ */ i("div", { className: "flex min-h-0 flex-1 flex-col", children: [
1975
- l.length > D && /* @__PURE__ */ i("div", { className: "mb-1 flex items-center gap-2", children: [
2002
+ ) : W, r = 12, v = Math.max(1, Math.ceil(z.length / r)), g = Math.min(ue, v - 1), k = z.length > r ? z.slice(g * r, g * r + r) : z;
2003
+ J = l.length === 0 ? /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-400", children: "No rows." }) : /* @__PURE__ */ i("div", { className: "flex min-h-0 flex-1 flex-col", children: [
2004
+ l.length > r && /* @__PURE__ */ i("div", { className: "mb-1 flex items-center gap-2", children: [
1976
2005
  /* @__PURE__ */ e(
1977
2006
  "input",
1978
2007
  {
1979
- value: G,
2008
+ value: ee,
1980
2009
  onChange: (d) => {
1981
- H(d.target.value), Z(0);
2010
+ H(d.target.value), pe(0);
1982
2011
  },
1983
2012
  placeholder: "Search rows…",
1984
2013
  className: "h-6 w-40 rounded border border-slate-200 bg-white px-1.5 text-[11px] dark:border-border dark:bg-card dark:text-slate-200"
1985
2014
  }
1986
2015
  ),
1987
- r > 1 && /* @__PURE__ */ i("span", { className: "ml-auto flex items-center gap-1 text-[10.5px] text-slate-400", children: [
2016
+ v > 1 && /* @__PURE__ */ i("span", { className: "ml-auto flex items-center gap-1 text-[10.5px] text-slate-400", children: [
1988
2017
  /* @__PURE__ */ e(
1989
2018
  "button",
1990
2019
  {
1991
2020
  type: "button",
1992
- disabled: b <= 0,
1993
- onClick: () => Z(b - 1),
2021
+ disabled: g <= 0,
2022
+ onClick: () => pe(g - 1),
1994
2023
  className: "rounded px-1 disabled:opacity-30",
1995
2024
  children: "←"
1996
2025
  }
1997
2026
  ),
1998
- b + 1,
2027
+ g + 1,
1999
2028
  "/",
2000
- r,
2029
+ v,
2001
2030
  /* @__PURE__ */ e(
2002
2031
  "button",
2003
2032
  {
2004
2033
  type: "button",
2005
- disabled: b >= r - 1,
2006
- onClick: () => Z(b + 1),
2034
+ disabled: g >= v - 1,
2035
+ onClick: () => pe(g + 1),
2007
2036
  className: "rounded px-1 disabled:opacity-30",
2008
2037
  children: "→"
2009
2038
  }
@@ -2011,56 +2040,56 @@ const Tt = Aa(function({
2011
2040
  ] })
2012
2041
  ] }),
2013
2042
  /* @__PURE__ */ e("div", { className: "min-h-0 flex-1 overflow-auto", children: /* @__PURE__ */ i("table", { className: "w-full text-[11.5px]", children: [
2014
- /* @__PURE__ */ e("thead", { className: "sticky top-0 bg-white dark:bg-card", children: /* @__PURE__ */ e("tr", { children: g.map((d) => {
2015
- var k;
2043
+ /* @__PURE__ */ e("thead", { className: "sticky top-0 bg-white dark:bg-card", children: /* @__PURE__ */ e("tr", { children: b.map((d) => {
2044
+ var y;
2016
2045
  return /* @__PURE__ */ e(
2017
2046
  "th",
2018
2047
  {
2019
2048
  className: "border-b border-slate-100 px-1.5 py-1 text-left font-medium text-slate-400 dark:border-border",
2020
- children: ((k = q(d)) == null ? void 0 : k.label) ?? d
2049
+ children: ((y = M(d)) == null ? void 0 : y.label) ?? d
2021
2050
  },
2022
2051
  d
2023
2052
  );
2024
2053
  }) }) }),
2025
- /* @__PURE__ */ e("tbody", { children: y.map((d) => /* @__PURE__ */ e(
2054
+ /* @__PURE__ */ e("tbody", { children: k.map((d) => /* @__PURE__ */ e(
2026
2055
  "tr",
2027
2056
  {
2028
- className: Q(
2029
- R(d),
2057
+ className: j(
2058
+ K(d),
2030
2059
  a.collection && d.id != null && "cursor-pointer hover:bg-slate-50 dark:hover:bg-muted/60"
2031
2060
  ),
2032
2061
  onClick: () => {
2033
2062
  a.collection && d.id != null && (f == null || f({ collection: a.collection, itemId: String(d.id) }));
2034
2063
  },
2035
- children: g.map((k) => {
2036
- var N, E, B, T;
2064
+ children: b.map((y) => {
2065
+ var F, B, G, Q;
2037
2066
  return /* @__PURE__ */ e(
2038
2067
  "td",
2039
2068
  {
2040
- className: Q(
2069
+ className: j(
2041
2070
  "max-w-[180px] truncate border-b border-slate-50 px-1.5 py-1 text-slate-700 dark:border-border/40 dark:text-slate-300",
2042
- (typeof d[k] == "number" || je.has(((N = q(k)) == null ? void 0 : N.format) ?? "")) && "text-right tabular-nums",
2043
- ne(d, k)
2071
+ (typeof d[y] == "number" || ze.has(((F = M(y)) == null ? void 0 : F.format) ?? "")) && "text-right tabular-nums",
2072
+ ie(d, y)
2044
2073
  ),
2045
- children: (E = q(k)) != null && E.format ? Ee(d[k], (B = q(k)) == null ? void 0 : B.format, (T = q(k)) == null ? void 0 : T.decimals) : String(d[k] ?? "")
2074
+ children: (B = M(y)) != null && B.format ? je(d[y], (G = M(y)) == null ? void 0 : G.format, (Q = M(y)) == null ? void 0 : Q.decimals) : String(d[y] ?? "")
2046
2075
  },
2047
- k
2076
+ y
2048
2077
  );
2049
2078
  })
2050
2079
  },
2051
2080
  String(d.id)
2052
2081
  )) }),
2053
- (F == null ? void 0 : F.grand_total) && W.length > 1 && /* @__PURE__ */ e("tfoot", { children: /* @__PURE__ */ e("tr", { className: "border-t border-slate-200 font-semibold dark:border-border", children: g.map((d, k) => {
2054
- var T, we, ze;
2055
- const N = W.map((it) => Number(it[d])).filter((it) => Number.isFinite(it)), E = N.length > W.length / 2, B = N.reduce((it, ca) => it + ca, 0);
2082
+ (A == null ? void 0 : A.grand_total) && z.length > 1 && /* @__PURE__ */ e("tfoot", { children: /* @__PURE__ */ e("tr", { className: "border-t border-slate-200 font-semibold dark:border-border", children: b.map((d, y) => {
2083
+ var Q, Se, Pe;
2084
+ const F = z.map((dt) => Number(dt[d])).filter((dt) => Number.isFinite(dt)), B = F.length > z.length / 2, G = F.reduce((dt, ma) => dt + ma, 0);
2056
2085
  return /* @__PURE__ */ e(
2057
2086
  "td",
2058
2087
  {
2059
- className: Q(
2088
+ className: j(
2060
2089
  "px-1.5 py-1 text-slate-800 dark:text-slate-100",
2061
- E && "text-right tabular-nums"
2090
+ B && "text-right tabular-nums"
2062
2091
  ),
2063
- children: k === 0 && !E ? "Total" : E ? (T = q(d)) != null && T.format ? Ee(B, (we = q(d)) == null ? void 0 : we.format, (ze = q(d)) == null ? void 0 : ze.decimals) : B.toLocaleString() : ""
2092
+ children: y === 0 && !B ? "Total" : B ? (Q = M(d)) != null && Q.format ? je(G, (Se = M(d)) == null ? void 0 : Se.format, (Pe = M(d)) == null ? void 0 : Pe.decimals) : G.toLocaleString() : ""
2064
2093
  },
2065
2094
  d
2066
2095
  );
@@ -2068,38 +2097,38 @@ const Tt = Aa(function({
2068
2097
  ] }) })
2069
2098
  ] });
2070
2099
  } else {
2071
- let l = j.series ?? [];
2072
- const n = !!((Je = (et = a.config) == null ? void 0 : et.dimension) != null && Je.bucket), g = Number((tt = a.config) == null ? void 0 : tt.rolling_avg) || 0;
2073
- if (g >= 2 && n && !ae && l.length >= g && (l = l.map((F, U) => {
2074
- if (U < g - 1) return F;
2075
- const W = l.slice(U - g + 1, U + 1);
2076
- return { ...F, ma: W.reduce((D, r) => D + r.value, 0) / g };
2077
- })), ae && n) {
2078
- let F = 0, U = 0, W = 0;
2079
- l = l.map((D) => (F += D.value, U += D.prev ?? 0, W += D.value2 ?? 0, {
2080
- ...D,
2081
- value: F,
2082
- ...D.prev != null ? { prev: U } : {},
2083
- ...D.value2 != null ? { value2: W } : {}
2100
+ let l = R.series ?? [];
2101
+ const s = !!((lt = (Je = a.config) == null ? void 0 : Je.dimension) != null && lt.bucket), b = Number((rt = a.config) == null ? void 0 : rt.rolling_avg) || 0;
2102
+ if (b >= 2 && s && !te && l.length >= b && (l = l.map((A, W) => {
2103
+ if (W < b - 1) return A;
2104
+ const z = l.slice(W - b + 1, W + 1);
2105
+ return { ...A, ma: z.reduce((r, v) => r + v.value, 0) / b };
2106
+ })), te && s) {
2107
+ let A = 0, W = 0, z = 0;
2108
+ l = l.map((r) => (A += r.value, W += r.prev ?? 0, z += r.value2 ?? 0, {
2109
+ ...r,
2110
+ value: A,
2111
+ ...r.prev != null ? { prev: W } : {},
2112
+ ...r.value2 != null ? { value2: z } : {}
2084
2113
  }));
2085
2114
  }
2086
- const q = l.some((F) => F.value2 != null), _ = ((lt = (at = a.config) == null ? void 0 : at.metric2) == null ? void 0 : lt.label) ?? "secondary", R = l.some((F) => F.band != null), ne = (() => {
2087
- if (!n || ae || l.length < 8) return /* @__PURE__ */ new Set();
2088
- const F = l.map((D) => D.value), U = F.reduce((D, r) => D + r, 0) / F.length, W = Math.sqrt(F.reduce((D, r) => D + (r - U) ** 2, 0) / F.length);
2089
- return W === 0 ? /* @__PURE__ */ new Set() : new Set(
2090
- l.filter((D) => Math.abs(D.value - U) > 2 * W).map((D) => D.dim)
2115
+ const M = l.some((A) => A.value2 != null), $ = ((re = (nt = a.config) == null ? void 0 : nt.metric2) == null ? void 0 : re.label) ?? "secondary", K = l.some((A) => A.band != null), ie = (() => {
2116
+ if (!s || te || l.length < 8) return /* @__PURE__ */ new Set();
2117
+ const A = l.map((r) => r.value), W = A.reduce((r, v) => r + v, 0) / A.length, z = Math.sqrt(A.reduce((r, v) => r + (v - W) ** 2, 0) / A.length);
2118
+ return z === 0 ? /* @__PURE__ */ new Set() : new Set(
2119
+ l.filter((r) => Math.abs(r.value - W) > 2 * z).map((r) => r.dim)
2091
2120
  );
2092
- })(), ee = ($ ?? []).filter(
2093
- (F) => F.anchor_date && l.some((U) => U.dim === F.anchor_date)
2121
+ })(), I = (q ?? []).filter(
2122
+ (A) => A.anchor_date && l.some((W) => W.dim === A.anchor_date)
2094
2123
  );
2095
- if (l.length === 0) V = /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-400", children: "No data." });
2124
+ if (l.length === 0) J = /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-400", children: "No data." });
2096
2125
  else if (a.type === "donut") {
2097
- const F = l.reduce((U, W) => U + W.value, 0);
2098
- V = /* @__PURE__ */ i("div", { className: "flex min-h-0 flex-1 items-stretch gap-3", children: [
2126
+ const A = l.reduce((W, z) => W + z.value, 0);
2127
+ J = /* @__PURE__ */ i("div", { className: "flex min-h-0 flex-1 items-stretch gap-3", children: [
2099
2128
  /* @__PURE__ */ i("div", { className: "relative min-h-[110px] min-w-0 flex-1", children: [
2100
- /* @__PURE__ */ e(Le, { fallback: /* @__PURE__ */ e(Oe, { className: "h-full w-full", "aria-busy": "true" }), children: ({ Cell: U, Pie: W, PieChart: D, ResponsiveContainer: r, Tooltip: b }) => /* @__PURE__ */ e(r, { width: "100%", height: "100%", children: /* @__PURE__ */ i(D, { children: [
2129
+ /* @__PURE__ */ e(Re, { fallback: /* @__PURE__ */ e(Oe, { className: "h-full w-full", "aria-busy": "true" }), children: ({ Cell: W, Pie: z, PieChart: r, ResponsiveContainer: v, Tooltip: g }) => /* @__PURE__ */ e(v, { width: "100%", height: "100%", children: /* @__PURE__ */ i(r, { children: [
2101
2130
  /* @__PURE__ */ e(
2102
- W,
2131
+ z,
2103
2132
  {
2104
2133
  data: l,
2105
2134
  dataKey: "value",
@@ -2109,46 +2138,46 @@ const Tt = Aa(function({
2109
2138
  paddingAngle: 2,
2110
2139
  strokeWidth: 0,
2111
2140
  className: a.collection ? "cursor-pointer" : void 0,
2112
- onClick: (y) => {
2113
- var N, E, B, T;
2141
+ onClick: (k) => {
2142
+ var F, B, G, Q;
2114
2143
  if (!a.collection) return;
2115
- const d = y == null ? void 0 : y.payload;
2144
+ const d = k == null ? void 0 : k.payload;
2116
2145
  if (d != null && d.other) return;
2117
- if (We.length > v.length) {
2118
- const we = v.length === 0 ? (E = (N = a.config) == null ? void 0 : N.dimension) == null ? void 0 : E.field : We[v.length - 1];
2119
- if (we) {
2120
- A((ze) => [
2121
- ...ze,
2122
- { field: we, value: String((d == null ? void 0 : d.raw) ?? (d == null ? void 0 : d.dim) ?? "") }
2146
+ if (Be.length > ae.length) {
2147
+ const Se = ae.length === 0 ? (B = (F = a.config) == null ? void 0 : F.dimension) == null ? void 0 : B.field : Be[ae.length - 1];
2148
+ if (Se) {
2149
+ S((Pe) => [
2150
+ ...Pe,
2151
+ { field: Se, value: String((d == null ? void 0 : d.raw) ?? (d == null ? void 0 : d.dim) ?? "") }
2123
2152
  ]);
2124
2153
  return;
2125
2154
  }
2126
2155
  }
2127
- const k = (T = (B = a.config) == null ? void 0 : B.dimension) == null ? void 0 : T.field;
2128
- se({
2129
- conditions: qt(
2156
+ const y = (Q = (G = a.config) == null ? void 0 : G.dimension) == null ? void 0 : Q.field;
2157
+ de({
2158
+ conditions: Mt(
2130
2159
  a,
2131
- m,
2160
+ c,
2132
2161
  o,
2133
2162
  (d == null ? void 0 : d.raw) ?? (d == null ? void 0 : d.dim)
2134
2163
  ),
2135
2164
  title: `${a.title || a.collection} — ${(d == null ? void 0 : d.dim) ?? ""}`,
2136
- dimField: k,
2165
+ dimField: y,
2137
2166
  dimRaw: (d == null ? void 0 : d.raw) ?? (d == null ? void 0 : d.dim),
2138
2167
  dimLabel: d == null ? void 0 : d.dim
2139
2168
  });
2140
2169
  },
2141
- children: l.map((y, d) => /* @__PURE__ */ e(
2142
- U,
2170
+ children: l.map((k, d) => /* @__PURE__ */ e(
2171
+ W,
2143
2172
  {
2144
- fill: y.other ? "#94a3b8" : ce[d % ce.length]
2173
+ fill: k.other ? "#94a3b8" : oe[d % oe.length]
2145
2174
  },
2146
- y.dim
2175
+ k.dim
2147
2176
  ))
2148
2177
  }
2149
2178
  ),
2150
2179
  /* @__PURE__ */ e(
2151
- b,
2180
+ g,
2152
2181
  {
2153
2182
  contentStyle: {
2154
2183
  fontSize: 12,
@@ -2163,42 +2192,42 @@ const Tt = Aa(function({
2163
2192
  )
2164
2193
  ] }) }) }),
2165
2194
  /* @__PURE__ */ i("div", { className: "pointer-events-none absolute inset-0 flex flex-col items-center justify-center", children: [
2166
- /* @__PURE__ */ e("span", { className: "text-[17px] font-semibold leading-none text-slate-900 dark:text-foreground", children: F.toLocaleString() }),
2195
+ /* @__PURE__ */ e("span", { className: "text-[17px] font-semibold leading-none text-slate-900 dark:text-foreground", children: A.toLocaleString() }),
2167
2196
  /* @__PURE__ */ e("span", { className: "text-[9.5px] text-slate-400", children: "total" })
2168
2197
  ] })
2169
2198
  ] }),
2170
- /* @__PURE__ */ e("div", { className: "max-h-full w-[40%] shrink-0 space-y-0.5 self-center overflow-y-auto pr-1", children: l.slice(0, 10).map((U, W) => /* @__PURE__ */ i("div", { className: "flex items-center gap-1.5 text-[10.5px]", children: [
2199
+ /* @__PURE__ */ e("div", { className: "max-h-full w-[40%] shrink-0 space-y-0.5 self-center overflow-y-auto pr-1", children: l.slice(0, 10).map((W, z) => /* @__PURE__ */ i("div", { className: "flex items-center gap-1.5 text-[10.5px]", children: [
2171
2200
  /* @__PURE__ */ e(
2172
2201
  "span",
2173
2202
  {
2174
2203
  className: "h-2 w-2 shrink-0 rounded-sm",
2175
- style: { background: ce[W % ce.length] }
2204
+ style: { background: oe[z % oe.length] }
2176
2205
  }
2177
2206
  ),
2178
- /* @__PURE__ */ e("span", { className: "truncate text-slate-600 dark:text-slate-300", children: U.dim }),
2179
- /* @__PURE__ */ e("span", { className: "ml-auto tabular-nums text-slate-400", children: U.value.toLocaleString() })
2180
- ] }, U.dim)) })
2207
+ /* @__PURE__ */ e("span", { className: "truncate text-slate-600 dark:text-slate-300", children: W.dim }),
2208
+ /* @__PURE__ */ e("span", { className: "ml-auto tabular-nums text-slate-400", children: W.value.toLocaleString() })
2209
+ ] }, W.dim)) })
2181
2210
  ] });
2182
2211
  } else if (a.type === "line")
2183
- V = /* @__PURE__ */ e("div", { className: "min-h-[110px] flex-1", children: /* @__PURE__ */ e(Le, { fallback: /* @__PURE__ */ e(Oe, { className: "h-full w-full", "aria-busy": "true" }), children: ({
2184
- Area: F,
2185
- ComposedChart: U,
2186
- Line: W,
2187
- ReferenceLine: D,
2188
- ResponsiveContainer: r,
2189
- Tooltip: b,
2190
- XAxis: y,
2212
+ J = /* @__PURE__ */ e("div", { className: "min-h-[110px] flex-1", children: /* @__PURE__ */ e(Re, { fallback: /* @__PURE__ */ e(Oe, { className: "h-full w-full", "aria-busy": "true" }), children: ({
2213
+ Area: A,
2214
+ ComposedChart: W,
2215
+ Line: z,
2216
+ ReferenceLine: r,
2217
+ ResponsiveContainer: v,
2218
+ Tooltip: g,
2219
+ XAxis: k,
2191
2220
  YAxis: d
2192
2221
  }) => {
2193
- var k;
2194
- return /* @__PURE__ */ e(r, { width: "100%", height: "100%", children: /* @__PURE__ */ i(
2195
- U,
2222
+ var y;
2223
+ return /* @__PURE__ */ e(v, { width: "100%", height: "100%", children: /* @__PURE__ */ i(
2224
+ W,
2196
2225
  {
2197
2226
  data: l,
2198
- margin: { top: 6, right: q ? 4 : 8, left: -10, bottom: 0 },
2227
+ margin: { top: 6, right: M ? 4 : 8, left: -10, bottom: 0 },
2199
2228
  children: [
2200
2229
  /* @__PURE__ */ e(
2201
- y,
2230
+ k,
2202
2231
  {
2203
2232
  dataKey: "dim",
2204
2233
  tick: { fontSize: 10 },
@@ -2215,7 +2244,7 @@ const Tt = Aa(function({
2215
2244
  width: 44
2216
2245
  }
2217
2246
  ),
2218
- q && /* @__PURE__ */ e(
2247
+ M && /* @__PURE__ */ e(
2219
2248
  d,
2220
2249
  {
2221
2250
  yAxisId: "right",
@@ -2226,18 +2255,18 @@ const Tt = Aa(function({
2226
2255
  width: 44
2227
2256
  }
2228
2257
  ),
2229
- ee.map((N) => /* @__PURE__ */ e(
2230
- D,
2258
+ I.map((F) => /* @__PURE__ */ e(
2259
+ r,
2231
2260
  {
2232
- x: N.anchor_date,
2261
+ x: F.anchor_date,
2233
2262
  stroke: "#f59e0b",
2234
2263
  strokeDasharray: "4 3",
2235
2264
  label: { value: "✎", position: "top", fontSize: 11, fill: "#f59e0b" }
2236
2265
  },
2237
- N.id
2266
+ F.id
2238
2267
  )),
2239
2268
  /* @__PURE__ */ e(
2240
- b,
2269
+ g,
2241
2270
  {
2242
2271
  contentStyle: {
2243
2272
  fontSize: 12,
@@ -2250,8 +2279,8 @@ const Tt = Aa(function({
2250
2279
  itemStyle: { color: "#e2e8f0" }
2251
2280
  }
2252
2281
  ),
2253
- R && /* @__PURE__ */ e(
2254
- F,
2282
+ K && /* @__PURE__ */ e(
2283
+ A,
2255
2284
  {
2256
2285
  type: "monotone",
2257
2286
  dataKey: "band",
@@ -2262,8 +2291,8 @@ const Tt = Aa(function({
2262
2291
  activeDot: !1
2263
2292
  }
2264
2293
  ),
2265
- ((k = a.config) == null ? void 0 : k.compare) && /* @__PURE__ */ e(
2266
- W,
2294
+ ((y = a.config) == null ? void 0 : y.compare) && /* @__PURE__ */ e(
2295
+ z,
2267
2296
  {
2268
2297
  type: "monotone",
2269
2298
  dataKey: "prev",
@@ -2275,31 +2304,31 @@ const Tt = Aa(function({
2275
2304
  }
2276
2305
  ),
2277
2306
  /* @__PURE__ */ e(
2278
- W,
2307
+ z,
2279
2308
  {
2280
2309
  type: "monotone",
2281
2310
  dataKey: "value",
2282
- stroke: Ve,
2311
+ stroke: Ge,
2283
2312
  strokeWidth: 2,
2284
- dot: (N) => {
2285
- var E, B, T;
2286
- return ne.has(((E = N.payload) == null ? void 0 : E.dim) ?? "") ? /* @__PURE__ */ e(
2313
+ dot: (F) => {
2314
+ var B, G, Q;
2315
+ return ie.has(((B = F.payload) == null ? void 0 : B.dim) ?? "") ? /* @__PURE__ */ e(
2287
2316
  "circle",
2288
2317
  {
2289
- cx: N.cx,
2290
- cy: N.cy,
2318
+ cx: F.cx,
2319
+ cy: F.cy,
2291
2320
  r: 3.5,
2292
2321
  fill: "#ef4444",
2293
2322
  stroke: "#fff",
2294
2323
  strokeWidth: 1
2295
2324
  },
2296
- (B = N.payload) == null ? void 0 : B.dim
2297
- ) : /* @__PURE__ */ e("g", {}, (T = N.payload) == null ? void 0 : T.dim);
2325
+ (G = F.payload) == null ? void 0 : G.dim
2326
+ ) : /* @__PURE__ */ e("g", {}, (Q = F.payload) == null ? void 0 : Q.dim);
2298
2327
  }
2299
2328
  }
2300
2329
  ),
2301
- q && /* @__PURE__ */ e(
2302
- W,
2330
+ M && /* @__PURE__ */ e(
2331
+ z,
2303
2332
  {
2304
2333
  yAxisId: "right",
2305
2334
  type: "monotone",
@@ -2307,11 +2336,11 @@ const Tt = Aa(function({
2307
2336
  stroke: "#8b5cf6",
2308
2337
  strokeWidth: 1.5,
2309
2338
  dot: !1,
2310
- name: _
2339
+ name: $
2311
2340
  }
2312
2341
  ),
2313
- g >= 2 && /* @__PURE__ */ e(
2314
- W,
2342
+ b >= 2 && /* @__PURE__ */ e(
2343
+ z,
2315
2344
  {
2316
2345
  type: "monotone",
2317
2346
  dataKey: "ma",
@@ -2319,7 +2348,7 @@ const Tt = Aa(function({
2319
2348
  strokeWidth: 1.5,
2320
2349
  strokeDasharray: "5 3",
2321
2350
  dot: !1,
2322
- name: `${g}-bucket avg`,
2351
+ name: `${b}-bucket avg`,
2323
2352
  isAnimationActive: !1
2324
2353
  }
2325
2354
  )
@@ -2328,30 +2357,30 @@ const Tt = Aa(function({
2328
2357
  ) });
2329
2358
  } }) });
2330
2359
  else {
2331
- const F = ((re = a.config) == null ? void 0 : re.orientation) === "horizontal";
2332
- V = /* @__PURE__ */ e("div", { className: "min-h-[110px] flex-1", children: /* @__PURE__ */ e(Le, { fallback: /* @__PURE__ */ e(Oe, { className: "h-full w-full", "aria-busy": "true" }), children: ({
2333
- Bar: U,
2334
- Cell: W,
2335
- ComposedChart: D,
2336
- Line: r,
2337
- ReferenceLine: b,
2338
- ResponsiveContainer: y,
2360
+ const A = ((yt = a.config) == null ? void 0 : yt.orientation) === "horizontal";
2361
+ J = /* @__PURE__ */ e("div", { className: "min-h-[110px] flex-1", children: /* @__PURE__ */ e(Re, { fallback: /* @__PURE__ */ e(Oe, { className: "h-full w-full", "aria-busy": "true" }), children: ({
2362
+ Bar: W,
2363
+ Cell: z,
2364
+ ComposedChart: r,
2365
+ Line: v,
2366
+ ReferenceLine: g,
2367
+ ResponsiveContainer: k,
2339
2368
  Tooltip: d,
2340
- XAxis: k,
2341
- YAxis: N
2369
+ XAxis: y,
2370
+ YAxis: F
2342
2371
  }) => {
2343
- var E;
2344
- return /* @__PURE__ */ e(y, { width: "100%", height: "100%", children: /* @__PURE__ */ i(
2345
- D,
2372
+ var B;
2373
+ return /* @__PURE__ */ e(k, { width: "100%", height: "100%", children: /* @__PURE__ */ i(
2374
+ r,
2346
2375
  {
2347
2376
  data: l,
2348
- layout: F ? "vertical" : "horizontal",
2349
- margin: { top: 6, right: 8, left: F ? 30 : -10, bottom: 0 },
2377
+ layout: A ? "vertical" : "horizontal",
2378
+ margin: { top: 6, right: 8, left: A ? 30 : -10, bottom: 0 },
2350
2379
  children: [
2351
- F ? /* @__PURE__ */ i(Ge, { children: [
2352
- /* @__PURE__ */ e(k, { type: "number", tick: { fontSize: 10 }, stroke: "#94a3b8" }),
2380
+ A ? /* @__PURE__ */ i(He, { children: [
2381
+ /* @__PURE__ */ e(y, { type: "number", tick: { fontSize: 10 }, stroke: "#94a3b8" }),
2353
2382
  /* @__PURE__ */ e(
2354
- N,
2383
+ F,
2355
2384
  {
2356
2385
  type: "category",
2357
2386
  dataKey: "dim",
@@ -2360,9 +2389,9 @@ const Tt = Aa(function({
2360
2389
  width: 90
2361
2390
  }
2362
2391
  )
2363
- ] }) : /* @__PURE__ */ i(Ge, { children: [
2392
+ ] }) : /* @__PURE__ */ i(He, { children: [
2364
2393
  /* @__PURE__ */ e(
2365
- k,
2394
+ y,
2366
2395
  {
2367
2396
  dataKey: "dim",
2368
2397
  tick: { fontSize: 10 },
@@ -2371,7 +2400,7 @@ const Tt = Aa(function({
2371
2400
  }
2372
2401
  ),
2373
2402
  /* @__PURE__ */ e(
2374
- N,
2403
+ F,
2375
2404
  {
2376
2405
  tick: { fontSize: 10 },
2377
2406
  stroke: "#94a3b8",
@@ -2379,8 +2408,8 @@ const Tt = Aa(function({
2379
2408
  width: 44
2380
2409
  }
2381
2410
  ),
2382
- q && /* @__PURE__ */ e(
2383
- N,
2411
+ M && /* @__PURE__ */ e(
2412
+ F,
2384
2413
  {
2385
2414
  yAxisId: "right",
2386
2415
  orientation: "right",
@@ -2391,15 +2420,15 @@ const Tt = Aa(function({
2391
2420
  }
2392
2421
  )
2393
2422
  ] }),
2394
- !F && ee.map((B) => /* @__PURE__ */ e(
2395
- b,
2423
+ !A && I.map((G) => /* @__PURE__ */ e(
2424
+ g,
2396
2425
  {
2397
- x: B.anchor_date,
2426
+ x: G.anchor_date,
2398
2427
  stroke: "#f59e0b",
2399
2428
  strokeDasharray: "4 3",
2400
2429
  label: { value: "✎", position: "top", fontSize: 11, fill: "#f59e0b" }
2401
2430
  },
2402
- B.id
2431
+ G.id
2403
2432
  )),
2404
2433
  /* @__PURE__ */ e(
2405
2434
  d,
@@ -2415,46 +2444,46 @@ const Tt = Aa(function({
2415
2444
  itemStyle: { color: "#e2e8f0" }
2416
2445
  }
2417
2446
  ),
2418
- ((E = a.config) == null ? void 0 : E.compare) && /* @__PURE__ */ e(U, { dataKey: "prev", fill: "#cbd5e1", radius: [3, 3, 0, 0], name: "previous" }),
2447
+ ((B = a.config) == null ? void 0 : B.compare) && /* @__PURE__ */ e(W, { dataKey: "prev", fill: "#cbd5e1", radius: [3, 3, 0, 0], name: "previous" }),
2419
2448
  /* @__PURE__ */ e(
2420
- U,
2449
+ W,
2421
2450
  {
2422
2451
  dataKey: "value",
2423
- fill: Ve,
2452
+ fill: Ge,
2424
2453
  radius: [3, 3, 0, 0],
2425
2454
  className: a.collection ? "cursor-pointer" : void 0,
2426
- onClick: (B) => {
2427
- var ze;
2455
+ onClick: (G) => {
2456
+ var Pe;
2428
2457
  if (!a.collection) return;
2429
- const T = B == null ? void 0 : B.payload;
2430
- if (T != null && T.other) return;
2431
- const we = (ze = a.config) == null ? void 0 : ze.dimension;
2432
- se({
2433
- conditions: qt(
2458
+ const Q = G == null ? void 0 : G.payload;
2459
+ if (Q != null && Q.other) return;
2460
+ const Se = (Pe = a.config) == null ? void 0 : Pe.dimension;
2461
+ de({
2462
+ conditions: Mt(
2434
2463
  a,
2435
- m,
2464
+ c,
2436
2465
  o,
2437
- (T == null ? void 0 : T.raw) ?? (T == null ? void 0 : T.dim)
2466
+ (Q == null ? void 0 : Q.raw) ?? (Q == null ? void 0 : Q.dim)
2438
2467
  ),
2439
- title: `${a.title || a.collection} — ${(T == null ? void 0 : T.dim) ?? ""}`,
2440
- dimField: we != null && we.bucket || we == null ? void 0 : we.field,
2441
- dimRaw: (T == null ? void 0 : T.raw) ?? (T == null ? void 0 : T.dim),
2442
- dimLabel: T == null ? void 0 : T.dim
2468
+ title: `${a.title || a.collection} — ${(Q == null ? void 0 : Q.dim) ?? ""}`,
2469
+ dimField: Se != null && Se.bucket || Se == null ? void 0 : Se.field,
2470
+ dimRaw: (Q == null ? void 0 : Q.raw) ?? (Q == null ? void 0 : Q.dim),
2471
+ dimLabel: Q == null ? void 0 : Q.dim
2443
2472
  });
2444
2473
  },
2445
- children: l.map((B) => /* @__PURE__ */ e(W, { fill: B.other ? "#94a3b8" : Ve }, B.dim))
2474
+ children: l.map((G) => /* @__PURE__ */ e(z, { fill: G.other ? "#94a3b8" : Ge }, G.dim))
2446
2475
  }
2447
2476
  ),
2448
- q && /* @__PURE__ */ e(
2449
- r,
2477
+ M && /* @__PURE__ */ e(
2478
+ v,
2450
2479
  {
2451
- yAxisId: F ? void 0 : "right",
2480
+ yAxisId: A ? void 0 : "right",
2452
2481
  type: "monotone",
2453
2482
  dataKey: "value2",
2454
2483
  stroke: "#8b5cf6",
2455
2484
  strokeWidth: 1.5,
2456
2485
  dot: !1,
2457
- name: _
2486
+ name: $
2458
2487
  }
2459
2488
  )
2460
2489
  ]
@@ -2463,8 +2492,8 @@ const Tt = Aa(function({
2463
2492
  } }) });
2464
2493
  }
2465
2494
  }
2466
- return L && p && (V = /* @__PURE__ */ i("div", { className: "flex min-h-0 flex-1 flex-col justify-center px-1", children: [
2467
- /* @__PURE__ */ e("p", { className: "text-[26px] font-bold tabular-nums text-amber-700 dark:text-amber-400", children: p.value == null ? "—" : qe(p.value, xe) }),
2495
+ return L && p && (J = /* @__PURE__ */ i("div", { className: "flex min-h-0 flex-1 flex-col justify-center px-1", children: [
2496
+ /* @__PURE__ */ e("p", { className: "text-[26px] font-bold tabular-nums text-amber-700 dark:text-amber-400", children: p.value == null ? "—" : qe(p.value, se) }),
2468
2497
  /* @__PURE__ */ i("p", { className: "text-[10.5px] text-slate-400", children: [
2469
2498
  "As of ",
2470
2499
  p.name,
@@ -2474,21 +2503,21 @@ const Tt = Aa(function({
2474
2503
  "div",
2475
2504
  {
2476
2505
  className: "flex min-h-0 flex-col overflow-hidden rounded-lg border border-slate-200 bg-white p-3 dark:border-border dark:bg-card",
2477
- style: he,
2506
+ style: et,
2478
2507
  children: [
2479
2508
  /* @__PURE__ */ i("div", { className: "mb-1.5 flex items-center gap-1.5", children: [
2480
2509
  (() => {
2481
- var n;
2482
- const l = (n = a.config) == null ? void 0 : n.link_report;
2483
- return l != null && l.report_id && S ? /* @__PURE__ */ i(
2510
+ var s;
2511
+ const l = (s = a.config) == null ? void 0 : s.link_report;
2512
+ return l != null && l.report_id && N ? /* @__PURE__ */ i(
2484
2513
  "a",
2485
2514
  {
2486
- href: S(l.report_id),
2515
+ href: N(l.report_id),
2487
2516
  onClick: () => {
2488
2517
  try {
2489
2518
  sessionStorage.setItem(
2490
2519
  `nvr-report-xf:${l.report_id}`,
2491
- JSON.stringify(J ?? [])
2520
+ JSON.stringify(U ?? [])
2492
2521
  );
2493
2522
  } catch {
2494
2523
  }
@@ -2505,9 +2534,9 @@ const Tt = Aa(function({
2505
2534
  /* @__PURE__ */ e(
2506
2535
  "span",
2507
2536
  {
2508
- "data-tip": jt(a),
2537
+ "data-tip": Et(a),
2509
2538
  className: "shrink-0 cursor-help text-slate-300 hover:text-slate-500",
2510
- children: /* @__PURE__ */ e(_a, { className: "h-3 w-3" })
2539
+ children: /* @__PURE__ */ e(Ca, { className: "h-3 w-3" })
2511
2540
  }
2512
2541
  ),
2513
2542
  /* @__PURE__ */ i("span", { className: "ml-auto flex items-center gap-0.5", children: [
@@ -2515,13 +2544,13 @@ const Tt = Aa(function({
2515
2544
  "button",
2516
2545
  {
2517
2546
  type: "button",
2518
- title: ue ? "Back to the chart" : "View as table (#383)",
2519
- className: Q(
2547
+ title: he ? "Back to the chart" : "View as table (#383)",
2548
+ className: j(
2520
2549
  "rounded p-0.5",
2521
- ue ? "text-[#00a5cc]" : "text-slate-300 hover:text-[#00a5cc]"
2550
+ he ? "text-[#00a5cc]" : "text-slate-300 hover:text-[#00a5cc]"
2522
2551
  ),
2523
2552
  onClick: () => le((l) => !l),
2524
- children: /* @__PURE__ */ e(Ca, { className: "h-3 w-3" })
2553
+ children: /* @__PURE__ */ e($a, { className: "h-3 w-3" })
2525
2554
  }
2526
2555
  ),
2527
2556
  ["bar", "line", "donut", "pareto", "scatter", "heatmap", "waterfall"].includes(
@@ -2532,85 +2561,85 @@ const Tt = Aa(function({
2532
2561
  type: "button",
2533
2562
  title: "Copy chart as image",
2534
2563
  className: "rounded p-0.5 text-slate-300 hover:text-[#00a5cc]",
2535
- onClick: () => void Ga(X.current, a.title),
2536
- children: /* @__PURE__ */ e(Nt, { className: "h-3 w-3" })
2564
+ onClick: () => void Ha(T.current, a.title),
2565
+ children: /* @__PURE__ */ e(wt, { className: "h-3 w-3" })
2537
2566
  }
2538
2567
  ),
2539
2568
  /* @__PURE__ */ e(
2540
2569
  "button",
2541
2570
  {
2542
2571
  type: "button",
2543
- title: ve ? "Explain the trend" : "Explain this number",
2544
- "data-explain-trend": ve ? "1" : void 0,
2572
+ title: we ? "Explain the trend" : "Explain this number",
2573
+ "data-explain-trend": we ? "1" : void 0,
2545
2574
  className: "rounded p-0.5 text-slate-300 hover:text-[#00a5cc]",
2546
2575
  onClick: () => {
2547
- if (K) {
2548
- ie(!1);
2576
+ if (Y) {
2577
+ ne(!1);
2549
2578
  return;
2550
2579
  }
2551
- if (ie(!0), oe || M) return;
2552
- if (z(!0), ve) {
2580
+ if (ne(!0), ce || _) return;
2581
+ if (D(!0), we) {
2553
2582
  O.request(
2554
- ct(`/report-studio/${s}/widgets/${a.id}/explain-trend`, {
2583
+ pt(`/report-studio/${n}/widgets/${a.id}/explain-trend`, {
2555
2584
  date_range: o,
2556
- entity_filters: m
2585
+ entity_filters: c
2557
2586
  })
2558
- ).then((n) => {
2559
- pe(n.data.explanation || "No explanation available."), ge(n.data.movers ?? null);
2587
+ ).then((s) => {
2588
+ fe(s.data.explanation || "No explanation available."), ve(s.data.movers ?? null);
2560
2589
  }).catch(
2561
- (n) => pe(
2562
- (n == null ? void 0 : n.status) === 503 ? "AI is not configured on this instance." : (n == null ? void 0 : n.status) === 400 ? n.message ?? "Not enough data to describe a trend." : "AI is not configured or unavailable."
2590
+ (s) => fe(
2591
+ (s == null ? void 0 : s.status) === 503 ? "AI is not configured on this instance." : (s == null ? void 0 : s.status) === 400 ? s.message ?? "Not enough data to describe a trend." : "AI is not configured or unavailable."
2563
2592
  )
2564
- ).finally(() => z(!1));
2593
+ ).finally(() => D(!1));
2565
2594
  return;
2566
2595
  }
2567
- (j ? Promise.resolve(j) : O.request(
2568
- yt(s, a.id, {
2596
+ (R ? Promise.resolve(R) : O.request(
2597
+ kt(n, a.id, {
2569
2598
  date_range: o,
2570
- entity_filters: m
2599
+ entity_filters: c
2571
2600
  })
2572
- ).then((n) => n.data).catch(() => {
2573
- })).then((n) => {
2574
- const g = {
2601
+ ).then((s) => s.data).catch(() => {
2602
+ })).then((s) => {
2603
+ const b = {
2575
2604
  widget: a.title,
2576
- how_computed: jt(a),
2577
- value: (n == null ? void 0 : n.value) ?? null,
2578
- previous_value: (n == null ? void 0 : n.prev_value) ?? null,
2579
- change_pct: (n == null ? void 0 : n.change_pct) ?? null,
2580
- row_count: (n == null ? void 0 : n.row_count) ?? null,
2581
- series: ((n == null ? void 0 : n.series) ?? []).slice(0, 15),
2582
- rows: ((n == null ? void 0 : n.rows) ?? []).slice(0, 10),
2583
- tiles: (n == null ? void 0 : n.tiles) ?? null
2584
- }, q = (n == null ? void 0 : n.prev_value) != null || ((n == null ? void 0 : n.series) ?? []).some((_) => _.prev != null);
2605
+ how_computed: Et(a),
2606
+ value: (s == null ? void 0 : s.value) ?? null,
2607
+ previous_value: (s == null ? void 0 : s.prev_value) ?? null,
2608
+ change_pct: (s == null ? void 0 : s.change_pct) ?? null,
2609
+ row_count: (s == null ? void 0 : s.row_count) ?? null,
2610
+ series: ((s == null ? void 0 : s.series) ?? []).slice(0, 15),
2611
+ rows: ((s == null ? void 0 : s.rows) ?? []).slice(0, 10),
2612
+ tiles: (s == null ? void 0 : s.tiles) ?? null
2613
+ }, M = (s == null ? void 0 : s.prev_value) != null || ((s == null ? void 0 : s.series) ?? []).some(($) => $.prev != null);
2585
2614
  return O.request(
2586
- ct("/ai/brief", {
2587
- context: JSON.stringify(g),
2615
+ pt("/ai/brief", {
2616
+ context: JSON.stringify(b),
2588
2617
  // `template` picks the server's prompt; `instructions` (the same
2589
2618
  // text) keeps an older API answering the same way.
2590
- template: q ? "report-compare" : "report-explain",
2591
- instructions: q ? "Compare the current period against the previous one in 2-4 plain sentences: overall direction, the biggest movers up and down, and anything anomalous. No preamble." : "In 2-3 plain sentences, explain what this report metric shows and what stands out (biggest contributor, direction of change). No preamble."
2619
+ template: M ? "report-compare" : "report-explain",
2620
+ instructions: M ? "Compare the current period against the previous one in 2-4 plain sentences: overall direction, the biggest movers up and down, and anything anomalous. No preamble." : "In 2-3 plain sentences, explain what this report metric shows and what stands out (biggest contributor, direction of change). No preamble."
2592
2621
  })
2593
2622
  );
2594
- }).then((n) => {
2595
- var q, _;
2596
- const g = ((q = n.data) == null ? void 0 : q.brief) ?? ((_ = n.data) == null ? void 0 : _.text) ?? null;
2597
- pe(g || "No explanation available.");
2598
- }).catch(() => pe("AI is not configured or unavailable.")).finally(() => z(!1));
2623
+ }).then((s) => {
2624
+ var M, $;
2625
+ const b = ((M = s.data) == null ? void 0 : M.brief) ?? (($ = s.data) == null ? void 0 : $.text) ?? null;
2626
+ fe(b || "No explanation available.");
2627
+ }).catch(() => fe("AI is not configured or unavailable.")).finally(() => D(!1));
2599
2628
  },
2600
- children: /* @__PURE__ */ e(Kt, { className: "h-3 w-3" })
2629
+ children: /* @__PURE__ */ e(Dt, { className: "h-3 w-3" })
2601
2630
  }
2602
2631
  ),
2603
- ((rt = (vt = a.config) == null ? void 0 : vt.dimension) == null ? void 0 : rt.bucket) && /* @__PURE__ */ e(
2632
+ ((it = (st = a.config) == null ? void 0 : st.dimension) == null ? void 0 : it.bucket) && /* @__PURE__ */ e(
2604
2633
  "button",
2605
2634
  {
2606
2635
  type: "button",
2607
- title: ae ? "Show per-period values" : "Show running total",
2608
- className: Q(
2636
+ title: te ? "Show per-period values" : "Show running total",
2637
+ className: j(
2609
2638
  "rounded p-0.5",
2610
- ae ? "text-[#00a5cc]" : "text-slate-300 hover:text-slate-500"
2639
+ te ? "text-[#00a5cc]" : "text-slate-300 hover:text-slate-500"
2611
2640
  ),
2612
- onClick: () => Y((l) => !l),
2613
- children: /* @__PURE__ */ e($a, { className: "h-3 w-3" })
2641
+ onClick: () => V((l) => !l),
2642
+ children: /* @__PURE__ */ e(qa, { className: "h-3 w-3" })
2614
2643
  }
2615
2644
  ),
2616
2645
  w && /* @__PURE__ */ e(
@@ -2618,12 +2647,12 @@ const Tt = Aa(function({
2618
2647
  {
2619
2648
  type: "button",
2620
2649
  title: "Notes on this widget",
2621
- className: Q(
2650
+ className: j(
2622
2651
  "relative rounded p-0.5",
2623
- (($ == null ? void 0 : $.length) ?? 0) > 0 ? "text-amber-500" : "text-slate-300 hover:text-slate-500"
2652
+ ((q == null ? void 0 : q.length) ?? 0) > 0 ? "text-amber-500" : "text-slate-300 hover:text-slate-500"
2624
2653
  ),
2625
2654
  onClick: () => be((l) => !l),
2626
- children: /* @__PURE__ */ e(qa, { className: "h-3 w-3" })
2655
+ children: /* @__PURE__ */ e(Ma, { className: "h-3 w-3" })
2627
2656
  }
2628
2657
  ),
2629
2658
  /* @__PURE__ */ e(
@@ -2633,37 +2662,37 @@ const Tt = Aa(function({
2633
2662
  title: "Download as CSV",
2634
2663
  className: "rounded p-0.5 text-slate-300 hover:text-slate-500",
2635
2664
  onClick: () => {
2636
- if (!($e != null && $e.slug)) {
2637
- Et(a, j);
2665
+ if (!(_e != null && _e.slug)) {
2666
+ Wt(a, R);
2638
2667
  return;
2639
2668
  }
2640
- const l = $e, n = sa(l, o, m);
2669
+ const l = _e, s = ia(l, o, c);
2641
2670
  Te.fetchQuery({
2642
- queryKey: ["nivaro-report-query", l.slug, n],
2643
- queryFn: () => oa(O, l.slug, n),
2671
+ queryKey: ["nivaro-report-query", l.slug, s],
2672
+ queryFn: () => da(O, l.slug, s),
2644
2673
  staleTime: 6e4
2645
- }).then((g) => Et(a, void 0, ia(l, g))).catch((g) => {
2646
- Sa(g) || Ht.error(At(g, "this widget"));
2674
+ }).then((b) => Wt(a, void 0, oa(l, b))).catch((b) => {
2675
+ _a(b) || Xt.error(Tt(b, "this widget"));
2647
2676
  });
2648
2677
  },
2649
- children: /* @__PURE__ */ e(Ma, { className: "h-3 w-3" })
2678
+ children: /* @__PURE__ */ e(Fa, { className: "h-3 w-3" })
2650
2679
  }
2651
2680
  ),
2652
- /* @__PURE__ */ e(ml, { reportId: s, widget: a, filterBar: h }),
2681
+ /* @__PURE__ */ e(pl, { reportId: n, widget: a, filterBar: h }),
2653
2682
  /* @__PURE__ */ e(
2654
2683
  "button",
2655
2684
  {
2656
2685
  type: "button",
2657
2686
  title: "Refresh",
2658
2687
  className: "rounded p-0.5 text-slate-300 hover:text-slate-500",
2659
- onClick: () => De(),
2660
- children: /* @__PURE__ */ e(Mt, { className: Q("h-3 w-3", ut && "animate-spin") })
2688
+ onClick: () => We(),
2689
+ children: /* @__PURE__ */ e(Ft, { className: j("h-3 w-3", $t && "animate-spin") })
2661
2690
  }
2662
2691
  )
2663
2692
  ] })
2664
2693
  ] }),
2665
- fe && /* @__PURE__ */ i("div", { className: "mb-1.5 space-y-1 rounded-md border border-amber-200 bg-amber-50/60 p-2 dark:border-amber-500/30 dark:bg-amber-500/10", children: [
2666
- ($ ?? []).map((l) => /* @__PURE__ */ i(
2694
+ xe && /* @__PURE__ */ i("div", { className: "mb-1.5 space-y-1 rounded-md border border-amber-200 bg-amber-50/60 p-2 dark:border-amber-500/30 dark:bg-amber-500/10", children: [
2695
+ (q ?? []).map((l) => /* @__PURE__ */ i(
2667
2696
  "div",
2668
2697
  {
2669
2698
  className: "group/note flex items-start gap-1.5 text-[11px] text-slate-600 dark:text-slate-300",
@@ -2677,11 +2706,11 @@ const Tt = Aa(function({
2677
2706
  l.note,
2678
2707
  /* @__PURE__ */ e("span", { className: "ml-1 text-[10px] text-slate-400", children: l.created_by_name ?? "" })
2679
2708
  ] }),
2680
- P && /* @__PURE__ */ e(
2709
+ E && /* @__PURE__ */ e(
2681
2710
  "button",
2682
2711
  {
2683
2712
  type: "button",
2684
- onClick: () => P(l.id),
2713
+ onClick: () => E(l.id),
2685
2714
  className: "shrink-0 rounded p-0.5 text-slate-300 opacity-0 hover:text-red-500 group-hover/note:opacity-100",
2686
2715
  children: /* @__PURE__ */ e(Ae, { className: "h-2.5 w-2.5" })
2687
2716
  }
@@ -2690,13 +2719,13 @@ const Tt = Aa(function({
2690
2719
  },
2691
2720
  l.id
2692
2721
  )),
2693
- ($ ?? []).length === 0 && /* @__PURE__ */ e("p", { className: "text-[11px] text-slate-400", children: "No notes yet — record why a number moved." }),
2722
+ (q ?? []).length === 0 && /* @__PURE__ */ e("p", { className: "text-[11px] text-slate-400", children: "No notes yet — record why a number moved." }),
2694
2723
  w && /* @__PURE__ */ i("div", { className: "flex items-center gap-1 pt-0.5", children: [
2695
2724
  /* @__PURE__ */ e(
2696
2725
  "input",
2697
2726
  {
2698
- value: Se,
2699
- onChange: (l) => _e(l.target.value),
2727
+ value: ge,
2728
+ onChange: (l) => $e(l.target.value),
2700
2729
  placeholder: "Add a note…",
2701
2730
  className: "h-6 min-w-0 flex-1 rounded border border-amber-200 bg-white px-1.5 text-[11px] dark:border-amber-500/30 dark:bg-card dark:text-slate-200"
2702
2731
  }
@@ -2705,7 +2734,7 @@ const Tt = Aa(function({
2705
2734
  "input",
2706
2735
  {
2707
2736
  value: x,
2708
- onChange: (l) => I(l.target.value),
2737
+ onChange: (l) => Z(l.target.value),
2709
2738
  placeholder: "2026-03",
2710
2739
  title: "Optional chart anchor (YYYY-MM or YYYY-MM-DD bucket key)",
2711
2740
  className: "h-6 w-[76px] rounded border border-amber-200 bg-white px-1.5 text-[10.5px] dark:border-amber-500/30 dark:bg-card dark:text-slate-200"
@@ -2715,9 +2744,9 @@ const Tt = Aa(function({
2715
2744
  "button",
2716
2745
  {
2717
2746
  type: "button",
2718
- disabled: !Se.trim(),
2747
+ disabled: !ge.trim(),
2719
2748
  onClick: () => {
2720
- w(a.id, Se.trim(), x.trim() || null), _e(""), I("");
2749
+ w(a.id, ge.trim(), x.trim() || null), $e(""), Z("");
2721
2750
  },
2722
2751
  className: "h-6 rounded bg-amber-500 px-2 text-[11px] font-medium text-white hover:brightness-105 disabled:opacity-40",
2723
2752
  children: "Add"
@@ -2726,47 +2755,47 @@ const Tt = Aa(function({
2726
2755
  ] })
2727
2756
  ] }),
2728
2757
  p && (() => {
2729
- const l = pl(j), n = p.value;
2730
- if (l == null || n == null) return null;
2731
- const g = n === 0 ? null : (l - n) / Math.abs(n) * 100;
2758
+ const l = fl(R), s = p.value;
2759
+ if (l == null || s == null) return null;
2760
+ const b = s === 0 ? null : (l - s) / Math.abs(s) * 100;
2732
2761
  return /* @__PURE__ */ i("p", { className: "mb-1 flex items-center gap-1 text-[10.5px] text-slate-400", children: [
2733
- /* @__PURE__ */ e(Nt, { className: "h-2.5 w-2.5" }),
2762
+ /* @__PURE__ */ e(wt, { className: "h-2.5 w-2.5" }),
2734
2763
  "vs ",
2735
2764
  p.name,
2736
2765
  ": ",
2737
- n.toLocaleString(),
2766
+ s.toLocaleString(),
2738
2767
  " →",
2739
2768
  " ",
2740
2769
  /* @__PURE__ */ e(
2741
2770
  "span",
2742
2771
  {
2743
- className: Q(
2772
+ className: j(
2744
2773
  "font-semibold",
2745
- g != null && g > 0 && "text-emerald-600 dark:text-emerald-400",
2746
- g != null && g < 0 && "text-red-500"
2774
+ b != null && b > 0 && "text-emerald-600 dark:text-emerald-400",
2775
+ b != null && b < 0 && "text-red-500"
2747
2776
  ),
2748
- children: g == null ? "—" : `${g > 0 ? "+" : ""}${g.toFixed(1)}%`
2777
+ children: b == null ? "—" : `${b > 0 ? "+" : ""}${b.toFixed(1)}%`
2749
2778
  }
2750
2779
  )
2751
2780
  ] });
2752
2781
  })(),
2753
- K && /* @__PURE__ */ i(
2782
+ Y && /* @__PURE__ */ i(
2754
2783
  "div",
2755
2784
  {
2756
2785
  className: "mb-1.5 rounded-md border border-nvr-cyan/25 bg-nvr-cyan/5 px-2.5 py-1.5 text-[11.5px] leading-snug text-slate-600 dark:text-slate-300",
2757
- "data-explain-panel": ve ? "trend" : "number",
2786
+ "data-explain-panel": we ? "trend" : "number",
2758
2787
  children: [
2759
- M ? "Thinking…" : oe,
2760
- !M && de && de.length > 0 && /* @__PURE__ */ e("div", { className: "mt-1.5 flex flex-wrap gap-1", "data-explain-movers": !0, children: de.slice(0, 4).map((l) => /* @__PURE__ */ i(
2788
+ _ ? "Thinking…" : ce,
2789
+ !_ && me && me.length > 0 && /* @__PURE__ */ e("div", { className: "mt-1.5 flex flex-wrap gap-1", "data-explain-movers": !0, children: me.slice(0, 4).map((l) => /* @__PURE__ */ i(
2761
2790
  "span",
2762
2791
  {
2763
- className: Q(
2792
+ className: j(
2764
2793
  "inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10.5px] tabular-nums",
2765
2794
  l.delta == null ? "border-slate-200 text-slate-500 dark:border-border dark:text-slate-400" : l.delta >= 0 ? "border-emerald-200 text-emerald-700 dark:border-emerald-500/30 dark:text-emerald-300" : "border-red-200 text-red-700 dark:border-red-500/30 dark:text-red-300"
2766
2795
  ),
2767
2796
  "data-explain-mover": l.label,
2768
2797
  children: [
2769
- l.delta != null && (l.delta >= 0 ? /* @__PURE__ */ e(Vt, { className: "h-3 w-3" }) : /* @__PURE__ */ e(Gt, { className: "h-3 w-3" })),
2798
+ l.delta != null && (l.delta >= 0 ? /* @__PURE__ */ e(Gt, { className: "h-3 w-3" }) : /* @__PURE__ */ e(Ht, { className: "h-3 w-3" })),
2770
2799
  /* @__PURE__ */ e("span", { className: "font-medium", children: l.label }),
2771
2800
  l.delta != null ? /* @__PURE__ */ i("span", { children: [
2772
2801
  l.delta >= 0 ? "+" : "",
@@ -2783,56 +2812,56 @@ const Tt = Aa(function({
2783
2812
  ]
2784
2813
  }
2785
2814
  ),
2786
- v.length > 0 && /* @__PURE__ */ i("div", { className: "mb-1 flex flex-wrap items-center gap-1 text-[10.5px] text-slate-500", children: [
2815
+ ae.length > 0 && /* @__PURE__ */ i("div", { className: "mb-1 flex flex-wrap items-center gap-1 text-[10.5px] text-slate-500", children: [
2787
2816
  /* @__PURE__ */ e(
2788
2817
  "button",
2789
2818
  {
2790
2819
  type: "button",
2791
- onClick: () => A([]),
2820
+ onClick: () => S([]),
2792
2821
  className: "rounded px-1 hover:bg-muted",
2793
2822
  children: "⌂ All"
2794
2823
  }
2795
2824
  ),
2796
- v.map((l, n) => /* @__PURE__ */ i("span", { className: "flex items-center gap-1", children: [
2825
+ ae.map((l, s) => /* @__PURE__ */ i("span", { className: "flex items-center gap-1", children: [
2797
2826
  /* @__PURE__ */ e("span", { className: "text-slate-300", children: "›" }),
2798
2827
  /* @__PURE__ */ e(
2799
2828
  "button",
2800
2829
  {
2801
2830
  type: "button",
2802
- onClick: () => A(v.slice(0, n + 1)),
2831
+ onClick: () => S(ae.slice(0, s + 1)),
2803
2832
  className: "rounded bg-nvr-cyan/[0.08] px-1.5 py-0.5 font-medium text-[#007a99] dark:text-nvr-cyan",
2804
2833
  children: l.value
2805
2834
  }
2806
2835
  )
2807
- ] }, `${l.field}-${n}`))
2836
+ ] }, `${l.field}-${s}`))
2808
2837
  ] }),
2809
- /* @__PURE__ */ e("div", { ref: X, className: "flex min-h-0 flex-1 flex-col", children: ue && ((nt = j == null ? void 0 : j.series) != null && nt.length) ? /* @__PURE__ */ e("div", { className: "min-h-0 flex-1 overflow-auto", children: /* @__PURE__ */ i("table", { className: "w-full text-[11.5px]", children: [
2838
+ /* @__PURE__ */ e("div", { ref: T, className: "flex min-h-0 flex-1 flex-col", children: he && ((ot = R == null ? void 0 : R.series) != null && ot.length) ? /* @__PURE__ */ e("div", { className: "min-h-0 flex-1 overflow-auto", children: /* @__PURE__ */ i("table", { className: "w-full text-[11.5px]", children: [
2810
2839
  /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ i("tr", { className: "text-left text-[10px] uppercase tracking-wide text-slate-400", children: [
2811
2840
  /* @__PURE__ */ e("th", { className: "px-1.5 pb-1", children: "Dimension" }),
2812
2841
  /* @__PURE__ */ e("th", { className: "px-1.5 pb-1 text-right", children: "Value" })
2813
2842
  ] }) }),
2814
- /* @__PURE__ */ e("tbody", { children: (j.series ?? []).map((l) => /* @__PURE__ */ i("tr", { className: "border-b border-slate-50 dark:border-border/40", children: [
2843
+ /* @__PURE__ */ e("tbody", { children: (R.series ?? []).map((l) => /* @__PURE__ */ i("tr", { className: "border-b border-slate-50 dark:border-border/40", children: [
2815
2844
  /* @__PURE__ */ e("td", { className: "max-w-[220px] truncate px-1.5 py-1 text-slate-700 dark:text-slate-300", children: l.dim }),
2816
- /* @__PURE__ */ e("td", { className: "px-1.5 py-1 text-right tabular-nums text-slate-800 dark:text-slate-100", children: qe(l.value, xe) })
2845
+ /* @__PURE__ */ e("td", { className: "px-1.5 py-1 text-right tabular-nums text-slate-800 dark:text-slate-100", children: qe(l.value, se) })
2817
2846
  ] }, l.dim)) })
2818
- ] }) }) : V }),
2819
- ((st = a.config) == null ? void 0 : st.footnote) && /* @__PURE__ */ e("p", { className: "mt-1 border-t border-slate-100 pt-1 text-[10.5px] leading-snug text-slate-400 dark:border-border/50", children: a.config.footnote }),
2820
- te && /* @__PURE__ */ e(
2821
- hl,
2847
+ ] }) }) : J }),
2848
+ ((Le = a.config) == null ? void 0 : Le.footnote) && /* @__PURE__ */ e("p", { className: "mt-1 border-t border-slate-100 pt-1 text-[10.5px] leading-snug text-slate-400 dark:border-border/50", children: a.config.footnote }),
2849
+ X && /* @__PURE__ */ e(
2850
+ xl,
2822
2851
  {
2823
2852
  collection: a.collection ?? "",
2824
- conditions: te.conditions,
2825
- title: te.title,
2826
- onClose: () => se(null),
2853
+ conditions: X.conditions,
2854
+ title: X.title,
2855
+ onClose: () => de(null),
2827
2856
  onOpen: (l) => {
2828
- se(null), f == null || f(l);
2857
+ de(null), f == null || f(l);
2829
2858
  },
2830
- crossFilter: c && te.dimField && te.dimRaw != null ? () => {
2831
- c(
2832
- te.dimField,
2833
- te.dimRaw,
2834
- te.dimLabel ?? String(te.dimRaw)
2835
- ), se(null);
2859
+ crossFilter: u && X.dimField && X.dimRaw != null ? () => {
2860
+ u(
2861
+ X.dimField,
2862
+ X.dimRaw,
2863
+ X.dimLabel ?? String(X.dimRaw)
2864
+ ), de(null);
2836
2865
  } : void 0
2837
2866
  }
2838
2867
  )
@@ -2840,53 +2869,53 @@ const Tt = Aa(function({
2840
2869
  }
2841
2870
  );
2842
2871
  });
2843
- function Pl({
2872
+ function jl({
2844
2873
  reportId: t,
2845
- widget: s,
2874
+ widget: n,
2846
2875
  dateRange: a = null,
2847
2876
  entityFilters: o = []
2848
2877
  }) {
2849
- const m = Xt(), u = Ft(
2850
- (f) => m == null ? void 0 : m.open(f),
2851
- [m]
2852
- ), h = dt(() => ({ ...s, x: 0 }), [s]);
2878
+ const c = Zt(), m = At(
2879
+ (f) => c == null ? void 0 : c.open(f),
2880
+ [c]
2881
+ ), h = ut(() => ({ ...n, x: 0 }), [n]);
2853
2882
  return /* @__PURE__ */ e(
2854
- Tt,
2883
+ Lt,
2855
2884
  {
2856
2885
  reportId: t,
2857
2886
  widget: h,
2858
2887
  dateRange: a,
2859
2888
  entityFilters: o,
2860
- onDrill: m ? u : void 0
2889
+ onDrill: c ? m : void 0
2861
2890
  }
2862
2891
  );
2863
2892
  }
2864
- function zl({
2893
+ function El({
2865
2894
  reportId: t,
2866
- showFilterBar: s = !0,
2895
+ showFilterBar: n = !0,
2867
2896
  dateRange: a,
2868
2897
  initialEntityFilters: o = [],
2869
- refetchInterval: m,
2870
- className: u,
2898
+ refetchInterval: c,
2899
+ className: m,
2871
2900
  emptyState: h,
2872
2901
  reportUrl: f
2873
2902
  }) {
2874
- var W, D;
2875
- const p = Ke(), L = Xt(), $ = Ta("drill.report"), w = $.value, P = Ft(
2876
- (r) => L ? L.open(r) : $.push([r]),
2877
- [L, $.push]
2878
- ), [c, S] = C(void 0), [J, O] = C(o), [G, H] = C(void 0), [me, Z] = C(o), { scopes: te, ready: se } = za(), [fe, be] = C(!1), [Se, _e] = C({}), x = Ct(), { data: I = [] } = ke({
2903
+ var W, z;
2904
+ const p = Ke(), L = Zt(), q = La("drill.report"), w = q.value, E = At(
2905
+ (r) => L ? L.open(r) : q.push([r]),
2906
+ [L, q.push]
2907
+ ), [u, N] = C(void 0), [U, O] = C(o), [ee, H] = C(void 0), [ue, pe] = C(o), { scopes: X, ready: de } = ja(), [xe, be] = C(!1), [ge, $e] = C({}), x = Ct(), { data: Z = [] } = Ne({
2879
2908
  queryKey: ["nivaro-report-presets", t],
2880
2909
  queryFn: async () => {
2881
2910
  try {
2882
2911
  const r = JSON.parse(localStorage.getItem(`nvr-report-presets:${t}`) ?? "[]");
2883
2912
  if (Array.isArray(r) && r.length > 0) {
2884
- for (const b of r)
2885
- b != null && b.name && await p.request(
2886
- Ot(t, {
2887
- name: String(b.name),
2888
- date_range: b.date_range ?? null,
2889
- entity_filters: b.entity_filters ?? []
2913
+ for (const v of r)
2914
+ v != null && v.name && await p.request(
2915
+ Kt(t, {
2916
+ name: String(v.name),
2917
+ date_range: v.date_range ?? null,
2918
+ entity_filters: v.entity_filters ?? []
2890
2919
  })
2891
2920
  ).catch(() => {
2892
2921
  });
@@ -2894,214 +2923,214 @@ function zl({
2894
2923
  }
2895
2924
  } catch {
2896
2925
  }
2897
- return p.request(ma(t)).then((r) => r.data);
2926
+ return p.request(ua(t)).then((r) => r.data);
2898
2927
  },
2899
2928
  staleTime: 6e4
2900
- }), ae = () => void x.invalidateQueries({ queryKey: ["nivaro-report-presets", t] }), Y = Me({
2929
+ }), te = () => void x.invalidateQueries({ queryKey: ["nivaro-report-presets", t] }), V = Me({
2901
2930
  mutationFn: (r) => p.request(
2902
- Ot(t, {
2931
+ Kt(t, {
2903
2932
  name: r,
2904
- date_range: rt.current ?? null,
2905
- entity_filters: nt.current
2933
+ date_range: st.current ?? null,
2934
+ entity_filters: it.current
2906
2935
  })
2907
2936
  ),
2908
- onSuccess: ae
2909
- }), ue = Me({
2910
- mutationFn: (r) => p.request(ua(t, r)),
2911
- onSuccess: ae
2912
- }), [le, v] = C(""), [A, X] = C(!1), [K, ie] = C(null), [oe, pe] = C(!1), { data: M = [] } = ke({
2937
+ onSuccess: te
2938
+ }), he = Me({
2939
+ mutationFn: (r) => p.request(pa(t, r)),
2940
+ onSuccess: te
2941
+ }), [le, ae] = C(""), [S, T] = C(!1), [P, Y] = C(null), [ne, ce] = C(!1), { data: fe = [] } = Ne({
2913
2942
  queryKey: ["nvr-report-snaps", t],
2914
2943
  queryFn: () => p.request(
2915
- ot(`/report-studio/${t}/snapshots`)
2944
+ ct(`/report-studio/${t}/snapshots`)
2916
2945
  ).then((r) => r.data ?? []),
2917
2946
  staleTime: 6e4,
2918
2947
  retry: !1
2919
- }), { data: z } = ke({
2920
- queryKey: ["nvr-report-snap", t, K],
2948
+ }), { data: _ } = Ne({
2949
+ queryKey: ["nvr-report-snap", t, P],
2921
2950
  queryFn: () => p.request(
2922
- ot(`/report-studio/${t}/snapshots/${K}`)
2951
+ ct(`/report-studio/${t}/snapshots/${P}`)
2923
2952
  ).then((r) => r.data),
2924
- enabled: K != null,
2953
+ enabled: P != null,
2925
2954
  staleTime: 5 * 6e4,
2926
2955
  retry: !1
2927
- }), de = Me({
2928
- mutationFn: () => p.request(ct(`/report-studio/${t}/snapshots`, {})),
2956
+ }), D = Me({
2957
+ mutationFn: () => p.request(pt(`/report-studio/${t}/snapshots`, {})),
2929
2958
  onSuccess: () => void x.invalidateQueries({ queryKey: ["nvr-report-snaps", t] })
2930
- }), { data: ge = [] } = ke({
2959
+ }), { data: me = [] } = Ne({
2931
2960
  queryKey: ["nvr-report-notes", t],
2932
- queryFn: () => p.request(ot(`/report-studio/${t}/annotations`)).then((r) => r.data ?? []),
2961
+ queryFn: () => p.request(ct(`/report-studio/${t}/annotations`)).then((r) => r.data ?? []),
2933
2962
  staleTime: 6e4,
2934
2963
  retry: !1
2935
- }), ve = () => void x.invalidateQueries({ queryKey: ["nvr-report-notes", t] }), Te = Me({
2936
- mutationFn: (r) => p.request(ct(`/report-studio/${t}/annotations`, r)),
2964
+ }), ve = () => void x.invalidateQueries({ queryKey: ["nvr-report-notes", t] }), we = Me({
2965
+ mutationFn: (r) => p.request(pt(`/report-studio/${t}/annotations`, r)),
2937
2966
  onSuccess: ve
2938
- }), He = Me({
2967
+ }), Te = Me({
2939
2968
  mutationFn: (r) => p.request(Ra(`/report-studio/${t}/annotations/${r}`)),
2940
2969
  onSuccess: ve
2941
- }), mt = Ft((r, b, y) => {
2942
- const d = {
2970
+ }), Xe = At((r, v, g) => {
2971
+ const k = {
2943
2972
  field: r,
2944
- values: [b],
2945
- labels: [y]
2973
+ values: [v],
2974
+ labels: [g]
2946
2975
  };
2947
- O((k) => [...k.filter((N) => N.field !== r), d]), Z((k) => [...k.filter((N) => N.field !== r), d]);
2948
- }, []), [Ne, Xe] = C(!1), [ye, Fe] = C(null), [Ze, Re] = C(null), De = Me({
2976
+ O((d) => [...d.filter((y) => y.field !== r), k]), pe((d) => [...d.filter((y) => y.field !== r), k]);
2977
+ }, []), [ye, Ze] = C(!1), [ke, Fe] = C(null), [Ie, Ee] = C(null), De = Me({
2949
2978
  mutationFn: (r) => p.request(
2950
- La(`/report-studio/${t}/widgets`, {
2951
- widgets: r.map((b, y) => ({ ...b, sort: y }))
2979
+ Oa(`/report-studio/${t}/widgets`, {
2980
+ widgets: r.map((v, g) => ({ ...v, sort: g }))
2952
2981
  })
2953
2982
  ),
2954
2983
  onSuccess: () => {
2955
- Xe(!1), Fe(null), Re(null), x.invalidateQueries({ queryKey: ["nivaro-report", t] }), x.invalidateQueries({ queryKey: ["nivaro-report-widget"] });
2984
+ Ze(!1), Fe(null), Ee(null), x.invalidateQueries({ queryKey: ["nivaro-report", t] }), x.invalidateQueries({ queryKey: ["nivaro-report-widget"] });
2956
2985
  }
2957
- }), ut = (r) => [...r].sort((b, y) => (b.y ?? 0) - (y.y ?? 0) || (b.x ?? 0) - (y.x ?? 0)), [We, pt] = C(() => /* @__PURE__ */ new Date()), j = () => {
2958
- x.invalidateQueries({ queryKey: ["nivaro-report-widget", t] }), x.invalidateQueries({ queryKey: ["nivaro-report-query"] }), pt(/* @__PURE__ */ new Date());
2959
- }, { data: xe = [] } = ke({
2986
+ }), We = (r) => [...r].sort((v, g) => (v.y ?? 0) - (g.y ?? 0) || (v.x ?? 0) - (g.x ?? 0)), [$t, Be] = C(() => /* @__PURE__ */ new Date()), ht = () => {
2987
+ x.invalidateQueries({ queryKey: ["nivaro-report-widget", t] }), x.invalidateQueries({ queryKey: ["nivaro-report-query"] }), Be(/* @__PURE__ */ new Date());
2988
+ }, { data: R = [] } = Ne({
2960
2989
  queryKey: ["nvr-report-firing", t],
2961
- queryFn: () => p.request(ot(`/report-studio/${t}/firing`)).then((r) => r.data ?? []).catch(() => []),
2990
+ queryFn: () => p.request(ct(`/report-studio/${t}/firing`)).then((r) => r.data ?? []).catch(() => []),
2962
2991
  staleTime: 6e4,
2963
2992
  refetchInterval: 5 * 6e4,
2964
2993
  retry: !1
2965
- }), [he, Pe] = C(null), [$e, V] = C(!1), [Be, ht] = C(""), [Qe, ft] = C(""), [Ue, xt] = C("");
2966
- wt(() => {
2994
+ }), [se, et] = C(null), [Qe, _e] = C(!1), [J, ft] = C(""), [Ue, xt] = C(""), [Ve, bt] = C("");
2995
+ mt(() => {
2967
2996
  try {
2968
2997
  const r = sessionStorage.getItem(`nvr-report-xf:${t}`);
2969
2998
  if (r) {
2970
2999
  sessionStorage.removeItem(`nvr-report-xf:${t}`);
2971
- const b = JSON.parse(r);
2972
- Array.isArray(b) && b.length > 0 && (O(b), Z(b));
3000
+ const v = JSON.parse(r);
3001
+ Array.isArray(v) && v.length > 0 && (O(v), pe(v));
2973
3002
  }
2974
3003
  } catch {
2975
3004
  }
2976
3005
  }, [t]);
2977
- const bt = () => {
2978
- Fe(ut((re == null ? void 0 : re.widgets) ?? [])), Xe(!0), window.__nvrReportId = t;
2979
- }, Ie = (r) => Fe((b) => (b ?? []).map((y) => y.id === r.id ? r : y)), gt = (r, b) => Fe((y) => {
2980
- const d = [...y ?? []], k = d.findIndex((T) => T.id === r), N = k + b;
2981
- if (k < 0 || N < 0 || N >= d.length) return d;
2982
- const E = d[k], B = d[N];
2983
- return d[k] = { ...B, x: E.x, y: E.y }, d[N] = { ...E, x: B.x, y: B.y }, d;
2984
- }), [Ye, et] = C(""), [Je, tt] = C(!1), [at, lt] = C(null), { data: re, isLoading: vt } = ke({
3006
+ const gt = () => {
3007
+ Fe(We((re == null ? void 0 : re.widgets) ?? [])), Ze(!0), window.__nvrReportId = t;
3008
+ }, tt = (r) => Fe((v) => (v ?? []).map((g) => g.id === r.id ? r : g)), vt = (r, v) => Fe((g) => {
3009
+ const k = [...g ?? []], d = k.findIndex((G) => G.id === r), y = d + v;
3010
+ if (d < 0 || y < 0 || y >= k.length) return k;
3011
+ const F = k[d], B = k[y];
3012
+ return k[d] = { ...B, x: F.x, y: F.y }, k[y] = { ...F, x: B.x, y: B.y }, k;
3013
+ }), [Ye, at] = C(""), [Je, lt] = C(!1), [rt, nt] = C(null), { data: re, isLoading: yt } = Ne({
2985
3014
  queryKey: ["nivaro-report", t],
2986
- queryFn: () => p.request(pa(t)).then((r) => r.data),
3015
+ queryFn: () => p.request(ha(t)).then((r) => r.data),
2987
3016
  staleTime: 3e4
2988
- }), rt = St(null), nt = St([]), st = ((W = re == null ? void 0 : re.global_filters) == null ? void 0 : W.date_range) ?? null, l = dt(() => c !== void 0 ? c : a !== void 0 ? a : st, [c, a, st]);
2989
- rt.current = l ?? null, nt.current = J;
2990
- const n = dt(
3017
+ }), st = St(null), it = St([]), ot = ((W = re == null ? void 0 : re.global_filters) == null ? void 0 : W.date_range) ?? null, Le = ut(() => u !== void 0 ? u : a !== void 0 ? a : ot, [u, a, ot]);
3018
+ st.current = Le ?? null, it.current = U;
3019
+ const l = ut(
2991
3020
  () => {
2992
3021
  var r;
2993
3022
  return ((r = re == null ? void 0 : re.global_filters) == null ? void 0 : r.filter_bar) ?? [];
2994
3023
  },
2995
- [(D = re == null ? void 0 : re.global_filters) == null ? void 0 : D.filter_bar]
3024
+ [(z = re == null ? void 0 : re.global_filters) == null ? void 0 : z.filter_bar]
2996
3025
  );
2997
- wt(() => {
2998
- if (!fe && !(!se || !re)) {
2999
- if (!te || n.length === 0) {
3026
+ mt(() => {
3027
+ if (!xe && !(!de || !re)) {
3028
+ if (!X || l.length === 0) {
3000
3029
  be(!0);
3001
3030
  return;
3002
3031
  }
3003
3032
  (async () => {
3004
- var y;
3005
- const r = [], b = {};
3006
- for (const d of n) {
3007
- const k = ja(te, {
3008
- key: d.field,
3009
- collection: (y = d.options) == null ? void 0 : y.collection
3033
+ var g;
3034
+ const r = [], v = {};
3035
+ for (const k of l) {
3036
+ const d = Ea(X, {
3037
+ key: k.field,
3038
+ collection: (g = k.options) == null ? void 0 : g.collection
3010
3039
  });
3011
- if (!k) continue;
3012
- const N = d.options ? d.options.value_field ?? "id" : "id", E = te.restricted[k.name] ?? [];
3013
- if (E.length > 0) {
3014
- const T = await Dt(p, k, E, N).catch(
3040
+ if (!d) continue;
3041
+ const y = k.options ? k.options.value_field ?? "id" : "id", F = X.restricted[d.name] ?? [];
3042
+ if (F.length > 0) {
3043
+ const G = await Pt(p, d, F, y).catch(
3015
3044
  () => []
3016
3045
  );
3017
- T.length > 0 && (b[d.field] = T);
3046
+ G.length > 0 && (v[k.field] = G);
3018
3047
  }
3019
- const B = Ea(te, k.name);
3048
+ const B = Wa(X, d.name);
3020
3049
  if (B.length > 0) {
3021
- const T = await Dt(p, k, B, N).catch(
3050
+ const G = await Pt(p, d, B, y).catch(
3022
3051
  () => []
3023
3052
  );
3024
- T.length > 0 && r.push({ field: d.field, values: T, labels: T.map(String) });
3053
+ G.length > 0 && r.push({ field: k.field, values: G, labels: G.map(String) });
3025
3054
  }
3026
3055
  }
3027
- if (Object.keys(b).length > 0 && _e(b), r.length > 0) {
3028
- const d = (k) => {
3029
- const N = [...k];
3030
- for (const E of r) N.some((B) => B.field === E.field) || N.push(E);
3031
- return N;
3056
+ if (Object.keys(v).length > 0 && $e(v), r.length > 0) {
3057
+ const k = (d) => {
3058
+ const y = [...d];
3059
+ for (const F of r) y.some((B) => B.field === F.field) || y.push(F);
3060
+ return y;
3032
3061
  };
3033
- Z(d), O(d);
3062
+ pe(k), O(k);
3034
3063
  }
3035
3064
  be(!0);
3036
3065
  })();
3037
3066
  }
3038
- }, [fe, se, re, te, n]);
3039
- const g = (re == null ? void 0 : re.widgets) ?? [], q = G !== void 0 ? G : l, _ = J.filter((r) => r.values.length > 0).length + (l ? 1 : 0), R = JSON.stringify(me) !== JSON.stringify(J) || G !== void 0, ne = () => {
3040
- O(me), G !== void 0 && (S(G), H(void 0));
3041
- }, ee = () => {
3042
- Z([]), O([]), S(null), H(void 0);
3043
- }, F = (r) => {
3044
- Z(r.entity_filters), O(r.entity_filters), S(r.date_range), H(void 0);
3045
- }, U = async () => {
3046
- var b, y;
3067
+ }, [xe, de, re, X, l]);
3068
+ const s = (re == null ? void 0 : re.widgets) ?? [], b = ee !== void 0 ? ee : Le, M = U.filter((r) => r.values.length > 0).length + (Le ? 1 : 0), $ = JSON.stringify(ue) !== JSON.stringify(U) || ee !== void 0, K = () => {
3069
+ O(ue), ee !== void 0 && (N(ee), H(void 0));
3070
+ }, ie = () => {
3071
+ pe([]), O([]), N(null), H(void 0);
3072
+ }, I = (r) => {
3073
+ pe(r.entity_filters), O(r.entity_filters), N(r.date_range), H(void 0);
3074
+ }, A = async () => {
3075
+ var v, g;
3047
3076
  const r = Ye.trim();
3048
3077
  if (!(!r || Je)) {
3049
- tt(!0), lt(null);
3078
+ lt(!0), nt(null);
3050
3079
  try {
3051
- const d = await p.request(
3052
- ba(
3080
+ const k = await p.request(
3081
+ ga(
3053
3082
  t,
3054
3083
  r,
3055
- n.map((N) => ({ field: N.field, label: N.label }))
3084
+ l.map((y) => ({ field: y.field, label: y.label }))
3056
3085
  )
3057
- ), k = (d.data.entity_filters ?? []).filter((N) => {
3058
- var E;
3059
- return n.some((B) => B.field === N.field) && ((E = N.values) == null ? void 0 : E.length) > 0;
3060
- }).map((N) => ({ field: N.field, values: N.values, labels: N.values.map(String) }));
3061
- Z(k), O(k), S(d.data.date_range ?? null), H(void 0), et("");
3062
- } catch (d) {
3063
- lt(
3064
- ((y = (b = d.response) == null ? void 0 : b.data) == null ? void 0 : y.error) ?? "Could not parse that"
3086
+ ), d = (k.data.entity_filters ?? []).filter((y) => {
3087
+ var F;
3088
+ return l.some((B) => B.field === y.field) && ((F = y.values) == null ? void 0 : F.length) > 0;
3089
+ }).map((y) => ({ field: y.field, values: y.values, labels: y.values.map(String) }));
3090
+ pe(d), O(d), N(k.data.date_range ?? null), H(void 0), at("");
3091
+ } catch (k) {
3092
+ nt(
3093
+ ((g = (v = k.response) == null ? void 0 : v.data) == null ? void 0 : g.error) ?? "Could not parse that"
3065
3094
  );
3066
3095
  } finally {
3067
- tt(!1);
3096
+ lt(!1);
3068
3097
  }
3069
3098
  }
3070
3099
  };
3071
- return vt || !fe ? /* @__PURE__ */ e("div", { className: Q("p-6 text-[13px] text-slate-400", u), children: "Loading report…" }) : re ? /* @__PURE__ */ i("div", { className: Q("flex flex-col gap-3", u), children: [
3072
- s && (g.length > 0 || n.length > 0) && /* @__PURE__ */ i("div", { className: "space-y-1.5", children: [
3100
+ return yt || !xe ? /* @__PURE__ */ e("div", { className: j("p-6 text-[13px] text-slate-400", m), children: "Loading report…" }) : re ? /* @__PURE__ */ i("div", { className: j("flex flex-col gap-3", m), children: [
3101
+ n && (s.length > 0 || l.length > 0) && /* @__PURE__ */ i("div", { className: "space-y-1.5", children: [
3073
3102
  /* @__PURE__ */ i("div", { className: "flex flex-wrap items-center gap-1.5", children: [
3074
3103
  /* @__PURE__ */ i("span", { className: "flex items-center gap-1.5 text-[11.5px] font-semibold text-slate-500 dark:text-slate-300", children: [
3075
3104
  "Filters",
3076
- _ > 0 && /* @__PURE__ */ i("span", { className: "rounded-full bg-emerald-50 px-1.5 py-px text-[10px] font-semibold text-emerald-600 dark:bg-emerald-500/10 dark:text-emerald-400", children: [
3105
+ M > 0 && /* @__PURE__ */ i("span", { className: "rounded-full bg-emerald-50 px-1.5 py-px text-[10px] font-semibold text-emerald-600 dark:bg-emerald-500/10 dark:text-emerald-400", children: [
3077
3106
  "Active · ",
3078
- _
3107
+ M
3079
3108
  ] })
3080
3109
  ] }),
3081
3110
  /* @__PURE__ */ e(
3082
- kt,
3111
+ Nt,
3083
3112
  {
3084
- value: (q == null ? void 0 : q.preset) ?? "",
3113
+ value: (b == null ? void 0 : b.preset) ?? "",
3085
3114
  onChange: (r) => H(r ? { preset: r } : null),
3086
- options: tl.map((r) => ({ value: r.id, label: r.label })),
3115
+ options: al.map((r) => ({ value: r.id, label: r.label })),
3087
3116
  ariaLabel: "Date range",
3088
3117
  className: "h-7 w-auto rounded-md px-1.5 py-0 text-[12px] text-slate-600 dark:border-border dark:bg-card dark:text-slate-300"
3089
3118
  }
3090
3119
  ),
3091
- n.map((r) => {
3092
- var b;
3120
+ l.map((r) => {
3121
+ var v;
3093
3122
  return /* @__PURE__ */ e(
3094
- ra,
3123
+ na,
3095
3124
  {
3096
3125
  reportId: t,
3097
3126
  field: r.field,
3098
3127
  label: r.label,
3099
3128
  optionSource: r.options,
3100
- allowedValues: Se[r.field],
3101
- selected: ((b = me.find((y) => y.field === r.field)) == null ? void 0 : b.values) ?? [],
3102
- onChange: (y, d) => Z((k) => [
3103
- ...k.filter((N) => N.field !== r.field),
3104
- ...y.length > 0 ? [{ field: r.field, values: y, labels: d }] : []
3129
+ allowedValues: ge[r.field],
3130
+ selected: ((v = ue.find((g) => g.field === r.field)) == null ? void 0 : v.values) ?? [],
3131
+ onChange: (g, k) => pe((d) => [
3132
+ ...d.filter((y) => y.field !== r.field),
3133
+ ...g.length > 0 ? [{ field: r.field, values: g, labels: k }] : []
3105
3134
  ])
3106
3135
  },
3107
3136
  r.field
@@ -3111,24 +3140,24 @@ function zl({
3111
3140
  "button",
3112
3141
  {
3113
3142
  type: "button",
3114
- disabled: !R,
3115
- onClick: ne,
3116
- className: Q(
3143
+ disabled: !$,
3144
+ onClick: K,
3145
+ className: j(
3117
3146
  "inline-flex h-7 items-center gap-1 rounded-md px-2.5 text-[11.5px] font-semibold",
3118
- R ? "bg-nvr-cyan text-white" : "bg-slate-100 text-slate-400 dark:bg-muted dark:text-slate-500"
3147
+ $ ? "bg-nvr-cyan text-white" : "bg-slate-100 text-slate-400 dark:bg-muted dark:text-slate-500"
3119
3148
  ),
3120
3149
  children: [
3121
- /* @__PURE__ */ e(Qt, { className: "h-3 w-3" }),
3150
+ /* @__PURE__ */ e(Ut, { className: "h-3 w-3" }),
3122
3151
  " Apply"
3123
3152
  ]
3124
3153
  }
3125
3154
  ),
3126
- (_ > 0 || R) && /* @__PURE__ */ i(
3155
+ (M > 0 || $) && /* @__PURE__ */ i(
3127
3156
  "button",
3128
3157
  {
3129
3158
  type: "button",
3130
3159
  className: "flex items-center gap-1 text-[11.5px] text-slate-400 hover:text-red-500",
3131
- onClick: ee,
3160
+ onClick: ie,
3132
3161
  children: [
3133
3162
  /* @__PURE__ */ e(Ae, { className: "h-3 w-3" }),
3134
3163
  " Clear"
@@ -3137,19 +3166,19 @@ function zl({
3137
3166
  )
3138
3167
  ] }),
3139
3168
  /* @__PURE__ */ i("div", { className: "flex flex-wrap items-center gap-1.5", children: [
3140
- I.map((r) => /* @__PURE__ */ i(
3169
+ Z.map((r) => /* @__PURE__ */ i(
3141
3170
  "span",
3142
3171
  {
3143
3172
  className: "group/preset inline-flex h-6 items-center gap-1 rounded-full border border-slate-200 pl-2 pr-1 text-[11px] text-slate-500 hover:border-nvr-cyan hover:text-nvr-navy dark:border-border dark:hover:text-nvr-cyan",
3144
3173
  children: [
3145
- /* @__PURE__ */ e("button", { type: "button", onClick: () => F(r), children: r.name }),
3174
+ /* @__PURE__ */ e("button", { type: "button", onClick: () => I(r), children: r.name }),
3146
3175
  /* @__PURE__ */ e(
3147
3176
  "button",
3148
3177
  {
3149
3178
  type: "button",
3150
3179
  title: "Delete preset",
3151
3180
  className: "rounded-full p-0.5 text-slate-300 opacity-0 hover:text-red-500 group-hover/preset:opacity-100",
3152
- onClick: () => ue.mutate(r.id),
3181
+ onClick: () => he.mutate(r.id),
3153
3182
  children: /* @__PURE__ */ e(Ae, { className: "h-2.5 w-2.5" })
3154
3183
  }
3155
3184
  )
@@ -3157,15 +3186,15 @@ function zl({
3157
3186
  },
3158
3187
  r.name
3159
3188
  )),
3160
- A ? /* @__PURE__ */ e("span", { className: "inline-flex items-center gap-1", children: /* @__PURE__ */ e(
3189
+ S ? /* @__PURE__ */ e("span", { className: "inline-flex items-center gap-1", children: /* @__PURE__ */ e(
3161
3190
  "input",
3162
3191
  {
3163
3192
  value: le,
3164
- onChange: (r) => v(r.target.value),
3193
+ onChange: (r) => ae(r.target.value),
3165
3194
  placeholder: "Preset name",
3166
3195
  autoFocus: !0,
3167
3196
  onKeyDown: (r) => {
3168
- r.key === "Enter" && le.trim() && (Y.mutate(le.trim()), v(""), X(!1)), r.key === "Escape" && X(!1);
3197
+ r.key === "Enter" && le.trim() && (V.mutate(le.trim()), ae(""), T(!1)), r.key === "Escape" && T(!1);
3169
3198
  },
3170
3199
  className: "h-6 w-[130px] rounded-md border border-slate-200 bg-white px-2 text-[11px] dark:border-border dark:bg-card"
3171
3200
  }
@@ -3174,9 +3203,9 @@ function zl({
3174
3203
  {
3175
3204
  type: "button",
3176
3205
  className: "inline-flex h-6 items-center gap-1 rounded-full border border-dashed border-slate-200 px-2 text-[11px] text-slate-400 hover:border-slate-300 hover:text-slate-600 dark:border-border",
3177
- onClick: () => X(!0),
3206
+ onClick: () => T(!0),
3178
3207
  children: [
3179
- /* @__PURE__ */ e(Ut, { className: "h-2.5 w-2.5" }),
3208
+ /* @__PURE__ */ e(Vt, { className: "h-2.5 w-2.5" }),
3180
3209
  " Save preset"
3181
3210
  ]
3182
3211
  }
@@ -3187,44 +3216,44 @@ function zl({
3187
3216
  {
3188
3217
  type: "button",
3189
3218
  title: "Save the current numbers as a snapshot to compare against later",
3190
- disabled: de.isPending,
3191
- onClick: () => de.mutate(),
3219
+ disabled: D.isPending,
3220
+ onClick: () => D.mutate(),
3192
3221
  className: "inline-flex h-6 items-center gap-1 rounded-full border border-dashed border-slate-200 px-2 text-[11px] text-slate-400 hover:border-slate-300 hover:text-slate-600 disabled:opacity-40 dark:border-border",
3193
3222
  children: [
3194
- /* @__PURE__ */ e(Nt, { className: "h-2.5 w-2.5" }),
3223
+ /* @__PURE__ */ e(wt, { className: "h-2.5 w-2.5" }),
3195
3224
  " ",
3196
- de.isPending ? "Saving…" : "Snapshot"
3225
+ D.isPending ? "Saving…" : "Snapshot"
3197
3226
  ]
3198
3227
  }
3199
3228
  ),
3200
- M.map((r) => /* @__PURE__ */ i(
3229
+ fe.map((r) => /* @__PURE__ */ i(
3201
3230
  "button",
3202
3231
  {
3203
3232
  type: "button",
3204
3233
  title: `Compare against ${r.name} (${new Date(r.taken_at).toLocaleDateString()})`,
3205
- onClick: () => ie((b) => b === r.id ? null : r.id),
3206
- className: Q(
3234
+ onClick: () => Y((v) => v === r.id ? null : r.id),
3235
+ className: j(
3207
3236
  "inline-flex h-6 items-center gap-1 rounded-full border px-2 text-[11px]",
3208
- K === r.id ? "border-nvr-cyan/40 bg-nvr-cyan/[0.08] font-medium text-[#007a99] dark:text-nvr-cyan" : "border-slate-200 text-slate-400 hover:text-slate-600 dark:border-border"
3237
+ P === r.id ? "border-nvr-cyan/40 bg-nvr-cyan/[0.08] font-medium text-[#007a99] dark:text-nvr-cyan" : "border-slate-200 text-slate-400 hover:text-slate-600 dark:border-border"
3209
3238
  ),
3210
3239
  children: [
3211
- /* @__PURE__ */ e(Nt, { className: "h-2.5 w-2.5" }),
3240
+ /* @__PURE__ */ e(wt, { className: "h-2.5 w-2.5" }),
3212
3241
  " ",
3213
3242
  r.name,
3214
- K === r.id && /* @__PURE__ */ e(Ae, { className: "h-2.5 w-2.5" })
3243
+ P === r.id && /* @__PURE__ */ e(Ae, { className: "h-2.5 w-2.5" })
3215
3244
  ]
3216
3245
  },
3217
3246
  r.id
3218
3247
  )),
3219
- K != null && /* @__PURE__ */ e(
3248
+ P != null && /* @__PURE__ */ e(
3220
3249
  "button",
3221
3250
  {
3222
3251
  type: "button",
3223
3252
  title: "Time machine (#404): show the snapshot values AS the numbers, not as delta badges",
3224
- onClick: () => pe((r) => !r),
3225
- className: Q(
3253
+ onClick: () => ce((r) => !r),
3254
+ className: j(
3226
3255
  "inline-flex h-6 items-center gap-1 rounded-full border px-2 text-[11px]",
3227
- oe ? "border-amber-400 bg-amber-50 font-medium text-amber-700 dark:bg-amber-400/10 dark:text-amber-400" : "border-dashed border-slate-200 text-slate-400 hover:text-slate-600 dark:border-border"
3256
+ ne ? "border-amber-400 bg-amber-50 font-medium text-amber-700 dark:bg-amber-400/10 dark:text-amber-400" : "border-dashed border-slate-200 text-slate-400 hover:text-slate-600 dark:border-border"
3228
3257
  ),
3229
3258
  children: "As of"
3230
3259
  }
@@ -3236,9 +3265,9 @@ function zl({
3236
3265
  "input",
3237
3266
  {
3238
3267
  value: Ye,
3239
- onChange: (r) => et(r.target.value),
3268
+ onChange: (r) => at(r.target.value),
3240
3269
  onKeyDown: (r) => {
3241
- r.key === "Enter" && U();
3270
+ r.key === "Enter" && A();
3242
3271
  },
3243
3272
  placeholder: 'Describe filters… e.g. "Zone 1 CRAN this year"',
3244
3273
  className: "h-full min-w-0 flex-1 bg-transparent text-[11.5px] outline-none placeholder:text-slate-300 dark:text-slate-200"
@@ -3249,32 +3278,32 @@ function zl({
3249
3278
  {
3250
3279
  type: "button",
3251
3280
  disabled: Je || !Ye.trim(),
3252
- onClick: () => void U(),
3281
+ onClick: () => void A(),
3253
3282
  className: "text-[11px] font-semibold text-nvr-navy disabled:opacity-40 dark:text-nvr-cyan",
3254
3283
  children: Je ? "…" : "Set"
3255
3284
  }
3256
3285
  )
3257
3286
  ] }),
3258
- at && /* @__PURE__ */ e("span", { className: "text-[10.5px] text-red-400", children: at })
3287
+ rt && /* @__PURE__ */ e("span", { className: "text-[10.5px] text-red-400", children: rt })
3259
3288
  ] })
3260
3289
  ] }),
3261
- xe.length > 0 && /* @__PURE__ */ i("div", { className: "mb-2 flex items-center gap-2 rounded-lg border border-red-300 bg-red-50 px-3 py-2 dark:border-red-500/40 dark:bg-red-500/10", children: [
3290
+ R.length > 0 && /* @__PURE__ */ i("div", { className: "mb-2 flex items-center gap-2 rounded-lg border border-red-300 bg-red-50 px-3 py-2 dark:border-red-500/40 dark:bg-red-500/10", children: [
3262
3291
  /* @__PURE__ */ e(Yt, { className: "h-3.5 w-3.5 shrink-0 text-red-500" }),
3263
- /* @__PURE__ */ e("p", { className: "min-w-0 flex-1 truncate text-[12px] text-red-700 dark:text-red-300", children: xe.length === 1 ? `Alert firing: ${xe[0].name}` : `${xe.length} alerts firing: ${xe.map((r) => r.name).join(" · ")}` })
3292
+ /* @__PURE__ */ e("p", { className: "min-w-0 flex-1 truncate text-[12px] text-red-700 dark:text-red-300", children: R.length === 1 ? `Alert firing: ${R[0].name}` : `${R.length} alerts firing: ${R.map((r) => r.name).join(" · ")}` })
3264
3293
  ] }),
3265
3294
  /* @__PURE__ */ i("div", { className: "mb-2 flex flex-wrap items-center gap-2", children: [
3266
3295
  /* @__PURE__ */ i("span", { className: "text-[10.5px] text-slate-400", children: [
3267
3296
  "Data as of ",
3268
- We.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" })
3297
+ $t.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" })
3269
3298
  ] }),
3270
3299
  /* @__PURE__ */ i(
3271
3300
  "button",
3272
3301
  {
3273
3302
  type: "button",
3274
- onClick: j,
3303
+ onClick: ht,
3275
3304
  className: "inline-flex items-center gap-1 rounded-md border border-slate-200 px-2 py-0.5 text-[11px] text-slate-500 hover:text-slate-700 dark:border-border dark:text-slate-400",
3276
3305
  children: [
3277
- /* @__PURE__ */ e(Mt, { className: "h-2.5 w-2.5" }),
3306
+ /* @__PURE__ */ e(Ft, { className: "h-2.5 w-2.5" }),
3278
3307
  " Refresh all"
3279
3308
  ]
3280
3309
  }
@@ -3284,31 +3313,31 @@ function zl({
3284
3313
  "button",
3285
3314
  {
3286
3315
  type: "button",
3287
- onClick: () => V((r) => !r),
3288
- className: Q(
3316
+ onClick: () => _e((r) => !r),
3317
+ className: j(
3289
3318
  "inline-flex items-center gap-1 rounded-md border px-2 py-0.5 text-[11px]",
3290
- he ? "border-nvr-cyan/40 bg-nvr-cyan/[0.08] font-medium text-[#007a99] dark:text-nvr-cyan" : "border-slate-200 text-slate-500 hover:text-slate-700 dark:border-border dark:text-slate-400"
3319
+ se ? "border-nvr-cyan/40 bg-nvr-cyan/[0.08] font-medium text-[#007a99] dark:text-nvr-cyan" : "border-slate-200 text-slate-500 hover:text-slate-700 dark:border-border dark:text-slate-400"
3291
3320
  ),
3292
3321
  children: [
3293
- he ? `Comparing ${he.a} vs ${he.b}` : "Compare A/B",
3294
- he && /* @__PURE__ */ e(
3322
+ se ? `Comparing ${se.a} vs ${se.b}` : "Compare A/B",
3323
+ se && /* @__PURE__ */ e(
3295
3324
  Ae,
3296
3325
  {
3297
3326
  className: "h-2.5 w-2.5",
3298
3327
  onClick: (r) => {
3299
- r.stopPropagation(), Pe(null);
3328
+ r.stopPropagation(), et(null);
3300
3329
  }
3301
3330
  }
3302
3331
  )
3303
3332
  ]
3304
3333
  }
3305
3334
  ),
3306
- $e && /* @__PURE__ */ i("span", { className: "absolute left-0 top-full z-50 mt-1 flex w-72 flex-col gap-1.5 rounded-xl border border-slate-200 bg-white p-2.5 shadow-lg dark:border-border dark:bg-card", children: [
3335
+ Qe && /* @__PURE__ */ i("span", { className: "absolute left-0 top-full z-50 mt-1 flex w-72 flex-col gap-1.5 rounded-xl border border-slate-200 bg-white p-2.5 shadow-lg dark:border-border dark:bg-card", children: [
3307
3336
  /* @__PURE__ */ e(
3308
3337
  "input",
3309
3338
  {
3310
- value: Be,
3311
- onChange: (r) => ht(r.target.value),
3339
+ value: J,
3340
+ onChange: (r) => ft(r.target.value),
3312
3341
  placeholder: "Filter field (e.g. division)",
3313
3342
  className: "h-7 rounded-md border border-slate-200 bg-white px-2 text-[12px] dark:border-border dark:bg-card dark:text-slate-200"
3314
3343
  }
@@ -3317,8 +3346,8 @@ function zl({
3317
3346
  /* @__PURE__ */ e(
3318
3347
  "input",
3319
3348
  {
3320
- value: Qe,
3321
- onChange: (r) => ft(r.target.value),
3349
+ value: Ue,
3350
+ onChange: (r) => xt(r.target.value),
3322
3351
  placeholder: "Value A",
3323
3352
  className: "h-7 min-w-0 flex-1 rounded-md border border-slate-200 bg-white px-2 text-[12px] dark:border-border dark:bg-card dark:text-slate-200"
3324
3353
  }
@@ -3326,8 +3355,8 @@ function zl({
3326
3355
  /* @__PURE__ */ e(
3327
3356
  "input",
3328
3357
  {
3329
- value: Ue,
3330
- onChange: (r) => xt(r.target.value),
3358
+ value: Ve,
3359
+ onChange: (r) => bt(r.target.value),
3331
3360
  placeholder: "Value B",
3332
3361
  className: "h-7 min-w-0 flex-1 rounded-md border border-slate-200 bg-white px-2 text-[12px] dark:border-border dark:bg-card dark:text-slate-200"
3333
3362
  }
@@ -3337,9 +3366,9 @@ function zl({
3337
3366
  "button",
3338
3367
  {
3339
3368
  type: "button",
3340
- disabled: !Be.trim() || !Qe.trim() || !Ue.trim(),
3369
+ disabled: !J.trim() || !Ue.trim() || !Ve.trim(),
3341
3370
  onClick: () => {
3342
- Pe({ field: Be.trim(), a: Qe.trim(), b: Ue.trim() }), V(!1);
3371
+ et({ field: J.trim(), a: Ue.trim(), b: Ve.trim() }), _e(!1);
3343
3372
  },
3344
3373
  className: "h-7 rounded-md bg-nvr-cyan text-[11.5px] font-semibold text-white hover:brightness-110 disabled:opacity-40",
3345
3374
  children: "Compare"
@@ -3348,7 +3377,7 @@ function zl({
3348
3377
  ] })
3349
3378
  ] })
3350
3379
  ] }),
3351
- J.filter((r) => !n.some((b) => b.field === r.field)).length > 0 && /* @__PURE__ */ e("div", { className: "flex flex-wrap items-center gap-1.5 px-1 pb-2", children: J.filter((r) => !n.some((b) => b.field === r.field)).map((r) => /* @__PURE__ */ i(
3380
+ U.filter((r) => !l.some((v) => v.field === r.field)).length > 0 && /* @__PURE__ */ e("div", { className: "flex flex-wrap items-center gap-1.5 px-1 pb-2", children: U.filter((r) => !l.some((v) => v.field === r.field)).map((r) => /* @__PURE__ */ i(
3352
3381
  "span",
3353
3382
  {
3354
3383
  className: "inline-flex items-center gap-1.5 rounded-full border border-nvr-cyan/40 bg-nvr-cyan/[0.08] py-0.5 pl-2.5 pr-1 text-[11.5px] text-[#007a99] dark:text-nvr-cyan",
@@ -3362,7 +3391,7 @@ function zl({
3362
3391
  type: "button",
3363
3392
  "aria-label": "Remove filter",
3364
3393
  onClick: () => {
3365
- O((b) => b.filter((y) => y.field !== r.field)), Z((b) => b.filter((y) => y.field !== r.field));
3394
+ O((v) => v.filter((g) => g.field !== r.field)), pe((v) => v.filter((g) => g.field !== r.field));
3366
3395
  },
3367
3396
  className: "rounded-full p-0.5 hover:bg-nvr-cyan/[0.16]",
3368
3397
  children: /* @__PURE__ */ e(Ae, { className: "h-2.5 w-2.5" })
@@ -3372,13 +3401,13 @@ function zl({
3372
3401
  },
3373
3402
  r.field
3374
3403
  )) }),
3375
- (re == null ? void 0 : re.editable) && /* @__PURE__ */ e("div", { className: "mb-2 flex items-center gap-1.5", children: Ne ? /* @__PURE__ */ i(Ge, { children: [
3404
+ (re == null ? void 0 : re.editable) && /* @__PURE__ */ e("div", { className: "mb-2 flex items-center gap-1.5", children: ye ? /* @__PURE__ */ i(He, { children: [
3376
3405
  /* @__PURE__ */ e(
3377
3406
  "button",
3378
3407
  {
3379
3408
  type: "button",
3380
3409
  disabled: De.isPending,
3381
- onClick: () => ye && De.mutate(ye),
3410
+ onClick: () => ke && De.mutate(ke),
3382
3411
  className: "rounded-md bg-nvr-cyan px-3 py-1 text-[12px] font-semibold text-white hover:brightness-110 disabled:opacity-40",
3383
3412
  children: De.isPending ? "Saving…" : "Save layout"
3384
3413
  }
@@ -3388,7 +3417,7 @@ function zl({
3388
3417
  {
3389
3418
  type: "button",
3390
3419
  onClick: () => {
3391
- Xe(!1), Fe(null), Re(null);
3420
+ Ze(!1), Fe(null), Ee(null);
3392
3421
  },
3393
3422
  className: "rounded-md border border-slate-200 px-3 py-1 text-[12px] text-slate-500 dark:border-border",
3394
3423
  children: "Cancel"
@@ -3399,90 +3428,90 @@ function zl({
3399
3428
  "button",
3400
3429
  {
3401
3430
  type: "button",
3402
- onClick: bt,
3431
+ onClick: gt,
3403
3432
  className: "rounded-md border border-slate-200 px-3 py-1 text-[12px] font-medium text-slate-500 hover:text-slate-700 dark:border-border dark:text-slate-400",
3404
3433
  children: "Edit report"
3405
3434
  }
3406
3435
  ) }),
3407
- Ne && ye && /* @__PURE__ */ e("div", { className: "mb-3", children: /* @__PURE__ */ e($t, { fallback: null, children: /* @__PURE__ */ e(
3408
- Za,
3436
+ ye && ke && /* @__PURE__ */ e("div", { className: "mb-3", children: /* @__PURE__ */ e(qt, { fallback: null, children: /* @__PURE__ */ e(
3437
+ Ia,
3409
3438
  {
3410
- maxY: Math.max(0, ...ye.map((r) => (r.y ?? 0) + (r.h ?? 1))),
3411
- onAdd: (r) => Fe((b) => [...b ?? [], r])
3439
+ maxY: Math.max(0, ...ke.map((r) => (r.y ?? 0) + (r.h ?? 1))),
3440
+ onAdd: (r) => Fe((v) => [...v ?? [], r])
3412
3441
  }
3413
3442
  ) }) }),
3414
- g.length === 0 && !Ne ? /* @__PURE__ */ e("div", { className: "p-6 text-[13px] text-slate-400", children: h ?? "This report has no widgets yet." }) : /* @__PURE__ */ e(
3443
+ s.length === 0 && !ye ? /* @__PURE__ */ e("div", { className: "p-6 text-[13px] text-slate-400", children: h ?? "This report has no widgets yet." }) : /* @__PURE__ */ e(
3415
3444
  "div",
3416
3445
  {
3417
3446
  className: "grid gap-3",
3418
3447
  style: {
3419
3448
  gridTemplateColumns: "repeat(12, minmax(0, 1fr))",
3420
- gridAutoRows: Ne ? void 0 : "72px"
3449
+ gridAutoRows: ye ? void 0 : "72px"
3421
3450
  },
3422
- children: ut(Ne && ye ? ye : g).map((r) => {
3423
- var b;
3451
+ children: We(ye && ke ? ke : s).map((r) => {
3452
+ var v;
3424
3453
  return /* @__PURE__ */ e(
3425
3454
  "div",
3426
3455
  {
3427
3456
  style: {
3428
- gridColumn: he ? "1 / -1" : `${Math.max(1, (r.x ?? 0) + 1)} / span ${Math.min(12, Math.max(2, r.w || 4))}`,
3457
+ gridColumn: se ? "1 / -1" : `${Math.max(1, (r.x ?? 0) + 1)} / span ${Math.min(12, Math.max(2, r.w || 4))}`,
3429
3458
  gridRow: void 0
3430
3459
  },
3431
- className: Ne || he ? "" : "contents",
3432
- children: he && !Ne && r.type !== "divider" ? /* @__PURE__ */ e("div", { className: "grid grid-cols-2 gap-3", children: [he.a, he.b].map((y, d) => /* @__PURE__ */ i("div", { className: "flex min-h-[160px] flex-col", children: [
3460
+ className: ye || se ? "" : "contents",
3461
+ children: se && !ye && r.type !== "divider" ? /* @__PURE__ */ e("div", { className: "grid grid-cols-2 gap-3", children: [se.a, se.b].map((g, k) => /* @__PURE__ */ i("div", { className: "flex min-h-[160px] flex-col", children: [
3433
3462
  /* @__PURE__ */ i("p", { className: "mb-1 text-[10.5px] font-semibold uppercase tracking-wide text-[#007a99] dark:text-nvr-cyan", children: [
3434
- he.field.replace(/_/g, " "),
3463
+ se.field.replace(/_/g, " "),
3435
3464
  ": ",
3436
- y
3465
+ g
3437
3466
  ] }),
3438
3467
  /* @__PURE__ */ e(
3439
- Tt,
3468
+ Lt,
3440
3469
  {
3441
3470
  reportId: t,
3442
3471
  widget: r,
3443
- dateRange: l,
3472
+ dateRange: Le,
3444
3473
  entityFilters: [
3445
- ...J.filter((k) => k.field !== he.field),
3446
- { field: he.field, values: [y], labels: [y] }
3474
+ ...U.filter((d) => d.field !== se.field),
3475
+ { field: se.field, values: [g], labels: [g] }
3447
3476
  ],
3448
- refetchInterval: m,
3449
- filterBar: n,
3450
- onDrill: P
3477
+ refetchInterval: c,
3478
+ filterBar: l,
3479
+ onDrill: E
3451
3480
  }
3452
3481
  )
3453
- ] }, d)) }) : /* @__PURE__ */ i(Ge, { children: [
3454
- Ne && /* @__PURE__ */ e($t, { fallback: null, children: /* @__PURE__ */ e(
3455
- el,
3482
+ ] }, k)) }) : /* @__PURE__ */ i(He, { children: [
3483
+ ye && /* @__PURE__ */ e(qt, { fallback: null, children: /* @__PURE__ */ e(
3484
+ tl,
3456
3485
  {
3457
3486
  widget: r,
3458
- onConfigure: () => Re(r.id),
3459
- onDelete: () => Fe((y) => (y ?? []).filter((d) => d.id !== r.id)),
3460
- onResize: (y, d) => Ie({
3487
+ onConfigure: () => Ee(r.id),
3488
+ onDelete: () => Fe((g) => (g ?? []).filter((k) => k.id !== r.id)),
3489
+ onResize: (g, k) => tt({
3461
3490
  ...r,
3462
- w: Math.min(12, Math.max(2, (r.w || 4) + y)),
3463
- h: Math.min(8, Math.max(1, (r.h || 2) + d))
3491
+ w: Math.min(12, Math.max(2, (r.w || 4) + g)),
3492
+ h: Math.min(8, Math.max(1, (r.h || 2) + k))
3464
3493
  }),
3465
- onMove: (y) => gt(r.id, y)
3494
+ onMove: (g) => vt(r.id, g)
3466
3495
  }
3467
3496
  ) }),
3468
3497
  /* @__PURE__ */ e(
3469
- Tt,
3498
+ Lt,
3470
3499
  {
3471
3500
  reportId: t,
3472
3501
  widget: r,
3473
- dateRange: l,
3474
- entityFilters: J,
3475
- refetchInterval: m,
3476
- filterBar: n,
3477
- onDrill: P,
3478
- snapshot: z && z.data[r.id] !== void 0 ? { name: z.name, value: ((b = z.data[r.id]) == null ? void 0 : b.value) ?? null } : null,
3479
- asOf: oe,
3480
- annotations: ge.filter((y) => y.widget === r.id),
3481
- onAddAnnotation: (y, d, k) => Te.mutate({ widget: y, note: d, anchor_date: k }),
3482
- onDeleteAnnotation: (y) => He.mutate(y),
3483
- onCrossFilter: mt,
3502
+ dateRange: Le,
3503
+ entityFilters: U,
3504
+ refetchInterval: c,
3505
+ filterBar: l,
3506
+ onDrill: E,
3507
+ snapshot: _ && _.data[r.id] !== void 0 ? { name: _.name, value: ((v = _.data[r.id]) == null ? void 0 : v.value) ?? null } : null,
3508
+ asOf: ne,
3509
+ annotations: me.filter((g) => g.widget === r.id),
3510
+ onAddAnnotation: (g, k, d) => we.mutate({ widget: g, note: k, anchor_date: d }),
3511
+ onDeleteAnnotation: (g) => Te.mutate(g),
3512
+ onCrossFilter: Xe,
3484
3513
  reportUrl: f,
3485
- currentFilters: J
3514
+ currentFilters: U
3486
3515
  }
3487
3516
  )
3488
3517
  ] })
@@ -3492,35 +3521,35 @@ function zl({
3492
3521
  })
3493
3522
  }
3494
3523
  ),
3495
- Ne && Ze && (ye == null ? void 0 : ye.some((r) => r.id === Ze)) && /* @__PURE__ */ e($t, { fallback: null, children: /* @__PURE__ */ e(
3496
- Ia,
3524
+ ye && Ie && (ke == null ? void 0 : ke.some((r) => r.id === Ie)) && /* @__PURE__ */ e(qt, { fallback: null, children: /* @__PURE__ */ e(
3525
+ el,
3497
3526
  {
3498
- widget: ye.find((r) => r.id === Ze),
3499
- allWidgets: ye,
3500
- onChange: Ie,
3501
- onClose: () => Re(null)
3527
+ widget: ke.find((r) => r.id === Ie),
3528
+ allWidgets: ke,
3529
+ onChange: tt,
3530
+ onClose: () => Ee(null)
3502
3531
  }
3503
3532
  ) }),
3504
- /* @__PURE__ */ e(Ba, {}),
3533
+ /* @__PURE__ */ e(Qa, {}),
3505
3534
  !L && (w != null && w.length) ? /* @__PURE__ */ e(
3506
- Wa,
3535
+ Ba,
3507
3536
  {
3508
3537
  collection: w[0].collection,
3509
3538
  itemId: w[0].itemId,
3510
3539
  title: w[0].title,
3511
3540
  width: "72%",
3512
3541
  stack: w,
3513
- onPush: (r) => $.push([...w, r]),
3514
- onPop: () => $.back(),
3515
- onClose: () => $.back(w.length)
3542
+ onPush: (r) => q.push([...w, r]),
3543
+ onPop: () => q.back(),
3544
+ onClose: () => q.back(w.length)
3516
3545
  }
3517
3546
  ) : null
3518
- ] }) : /* @__PURE__ */ e("div", { className: Q("p-6 text-[13px] text-slate-400", u), children: "Report not found." });
3547
+ ] }) : /* @__PURE__ */ e("div", { className: j("p-6 text-[13px] text-slate-400", m), children: "Report not found." });
3519
3548
  }
3520
3549
  export {
3521
- ml as AlertBell,
3522
- sl as QueryWidgetBody,
3523
- zl as ReportView,
3524
- Pl as ReportWidgetCard,
3525
- ia as shapeQueryRows
3550
+ pl as AlertBell,
3551
+ ol as QueryWidgetBody,
3552
+ El as ReportView,
3553
+ jl as ReportWidgetCard,
3554
+ oa as shapeQueryRows
3526
3555
  };