@nivaro/react 0.3.24 → 0.3.26

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 (27) hide show
  1. package/dist/hooks/useSessionRecorder.js +1 -1
  2. package/dist/index.d.ts +45 -26
  3. package/dist/shared/components/FilePreviewLightbox.js +56 -35
  4. package/dist/shared/components/ItemEditForm.js +4309 -4263
  5. package/dist/shared/components/PageRenderer.js +63 -62
  6. package/dist/shared/components/RecordReadView.js +229 -229
  7. package/dist/shared/components/ReportView.js +123 -120
  8. package/dist/shared/components/ai/AiMarkdown.js +168 -148
  9. package/dist/shared/components/chat/RoomParts.js +120 -119
  10. package/dist/shared/components/chat/chat-core.js +228 -224
  11. package/dist/shared/components/item-edit/FieldRenderer.js +333 -333
  12. package/dist/shared/components/item-edit/FieldRow.js +413 -394
  13. package/dist/shared/components/item-edit/GroupSection.js +637 -635
  14. package/dist/shared/components/item-edit/InlineGridField.js +89 -90
  15. package/dist/shared/components/item-edit/M2MCombobox.js +117 -116
  16. package/dist/shared/components/item-edit/QuickPicker.js +9 -9
  17. package/dist/shared/components/item-edit/RawEditSheet.js +80 -79
  18. package/dist/shared/components/item-edit/RelationCombobox.js +173 -167
  19. package/dist/shared/components/item-edit/RowMatchPanel.js +1 -1
  20. package/dist/shared/components/item-edit/m2m-invalidate.js +19 -0
  21. package/dist/shared/components/item-edit/record-lookups.js +15 -0
  22. package/dist/shared/components/item-edit/render-stability.js +147 -0
  23. package/dist/shared/components/layout-editor/FormMapButton.js +5 -4
  24. package/dist/shared/lib/picker-rank.js +21 -0
  25. package/dist/shared/lib/safe-href.js +10 -0
  26. package/dist/shared/lib/socket-realtime.js +107 -78
  27. package/package.json +6 -6
@@ -2,7 +2,7 @@ import { jsxs as i, jsx as e, Fragment as Ge } from "react/jsx-runtime";
2
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
3
  import { useQuery as ke, useQueryClient as Ct, useMutation as Me } from "@tanstack/react-query";
4
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 Sa, Table as _a, Sigma as Ca, StickyNote as $a, Download as qa, TrendingUp as Vt, TrendingDown as Gt, Trash2 as Ma } from "lucide-react";
5
- import { useState as _, useEffect as wt, useCallback as Ft, useRef as St, useMemo as dt, Suspense as $t, lazy as Rt, memo as Fa } from "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 Fa } from "react";
6
6
  import { toast as Ht } from "sonner";
7
7
  import { useNivaroClient as Ke, useDrilldown as Xt, useOverlayState as Aa } from "../context.js";
8
8
  import { get as ot, post as ct, del as Ta, put as Ra } from "../lib/commands.js";
@@ -33,9 +33,9 @@ async function Va(t, s) {
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 C = L.getContext("2d");
37
- if (!C) return;
38
- C.fillStyle = "#ffffff", C.fillRect(0, 0, L.width, L.height), C.fillStyle = "#172940", C.font = `${12 * p}px system-ui, sans-serif`, C.fillText(s || "Chart", 8 * p, 18 * p), C.drawImage(f, 0, 28 * p, o.width * p, o.height * p), URL.revokeObjectURL(h);
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
39
  const w = await new Promise((P) => L.toBlob(P, "image/png"));
40
40
  w && await navigator.clipboard.write([new ClipboardItem({ "image/png": w })]);
41
41
  } catch {
@@ -109,7 +109,7 @@ function ra({
109
109
  onChange: m,
110
110
  allowedValues: h
111
111
  }) {
112
- const f = Ke(), [p, L] = _(!1), { data: C = [] } = ke({
112
+ const f = Ke(), [p, L] = C(!1), { data: $ = [] } = ke({
113
113
  queryKey: ["nivaro-report-filter-opts", t, s, o ?? null],
114
114
  queryFn: async () => {
115
115
  if (o) {
@@ -132,7 +132,7 @@ function ra({
132
132
  },
133
133
  enabled: p,
134
134
  staleTime: 12e4
135
- }), w = h != null && h.length ? C.filter((c) => h.some((S) => String(S) === c.value)) : C, P = u.length > 0;
135
+ }), w = h != null && h.length ? $.filter((c) => h.some((S) => String(S) === c.value)) : $, P = u.length > 0;
136
136
  return /* @__PURE__ */ i(ta, { open: p, onOpenChange: L, children: [
137
137
  /* @__PURE__ */ e(aa, { asChild: !0, children: /* @__PURE__ */ i(
138
138
  "button",
@@ -162,7 +162,7 @@ function ra({
162
162
  onSelect: () => {
163
163
  const J = S ? u.filter((G) => String(G) !== c.value) : [...u, c.value], O = (G) => {
164
164
  var H;
165
- return ((H = C.find((me) => me.value === String(G))) == null ? void 0 : H.label) ?? String(G);
165
+ return ((H = $.find((me) => me.value === String(G))) == null ? void 0 : H.label) ?? String(G);
166
166
  };
167
167
  m(J, J.map(O));
168
168
  },
@@ -240,7 +240,7 @@ function sa(t, s, a) {
240
240
  }
241
241
  const f = /^\$filters\.([\w.]+?)(:values)?$/.exec(h);
242
242
  if (f) {
243
- const p = a.find((C) => C.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;
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
244
  L && L.length > 0 && (o[m] = L.join(","));
245
245
  continue;
246
246
  }
@@ -269,7 +269,7 @@ function ll({
269
269
  ) : [],
270
270
  // eslint-disable-next-line react-hooks/exhaustive-deps
271
271
  [t, o]
272
- ), [h, f] = _(() => /* @__PURE__ */ new Set()), [p, L] = _(!1);
272
+ ), [h, f] = C(() => /* @__PURE__ */ new Set()), [p, L] = C(!1);
273
273
  wt(() => {
274
274
  if (p || m.length === 0) return;
275
275
  const c = /* @__PURE__ */ new Set(), S = (J) => {
@@ -278,9 +278,9 @@ function ll({
278
278
  };
279
279
  S(m), f(c), L(!0);
280
280
  }, [m, p]);
281
- const C = (o == null ? void 0 : o.thresholds) ?? al, w = (c) => {
281
+ const $ = (o == null ? void 0 : o.thresholds) ?? al, w = (c) => {
282
282
  var S;
283
- return c == null ? void 0 : ((S = C.find((J) => c >= J.gte)) == null ? void 0 : S.color) ?? "#10b981";
283
+ return c == null ? void 0 : ((S = $.find((J) => c >= J.gte)) == null ? void 0 : S.color) ?? "#10b981";
284
284
  }, P = (c) => {
285
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
286
  return /* @__PURE__ */ i("div", { style: { paddingLeft: c.depth === 0 ? 0 : 14 }, children: [
@@ -424,7 +424,7 @@ function nl({
424
424
  onDrill: m
425
425
  }) {
426
426
  var ue, le;
427
- const h = Ke(), f = rl(m), [p, L] = _(""), [C, w] = _(0), [P, c] = _(null), S = sa(t, s, a), { data: J, isLoading: O, error: G, isFetching: H, refetch: me } = ke({
427
+ const h = Ke(), f = rl(m), [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({
428
428
  queryKey: ["nivaro-report-query", t.slug, S],
429
429
  queryFn: () => oa(h, t.slug, S),
430
430
  staleTime: 6e4,
@@ -465,11 +465,11 @@ function nl({
465
465
  const te = t.columns && t.columns.length > 0 ? t.columns : Object.keys(Z[0] ?? {}).map((v) => ({ field: v }));
466
466
  if (t.display === "kpis") {
467
467
  const v = t.x_field ? Z.map((A, X) => {
468
- var K, ie, oe, pe, $;
468
+ var K, ie, oe, pe, M;
469
469
  return {
470
470
  label: String(A[t.x_field] ?? ""),
471
471
  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) ?? ""],
472
- color: (($ = (pe = t.series) == null ? void 0 : pe[0]) == null ? void 0 : $.color) ?? ce[X % ce.length],
472
+ color: ((M = (pe = t.series) == null ? void 0 : pe[0]) == null ? void 0 : M.color) ?? ce[X % ce.length],
473
473
  format: t.value_format
474
474
  };
475
475
  }) : te.map((A, X) => {
@@ -504,19 +504,19 @@ function nl({
504
504
  if (t.display === "tree")
505
505
  return /* @__PURE__ */ e(ll, { rows: Z, cfg: t, onDrill: (v) => m == null ? void 0 : m(v) });
506
506
  if (t.display === "table") {
507
- const v = te.filter(($) => je.has($.format ?? "")), A = p.trim().toLowerCase(), X = A ? Z.filter(
508
- ($) => Object.values($).some(
507
+ const v = te.filter((M) => je.has(M.format ?? "")), A = p.trim().toLowerCase(), X = A ? Z.filter(
508
+ (M) => Object.values(M).some(
509
509
  (z) => String(z ?? "").toLowerCase().includes(A)
510
510
  )
511
- ) : Z, K = 12, ie = Math.max(1, Math.ceil(X.length / K)), oe = Math.min(C, ie - 1), pe = X.length > K ? X.slice(oe * K, oe * K + K) : X;
511
+ ) : 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;
512
512
  return /* @__PURE__ */ i("div", { className: "flex min-h-0 flex-1 flex-col", children: [
513
513
  Z.length > K && /* @__PURE__ */ i("div", { className: "mb-1 flex items-center gap-2", children: [
514
514
  /* @__PURE__ */ e(
515
515
  "input",
516
516
  {
517
517
  value: p,
518
- onChange: ($) => {
519
- L($.target.value), w(0);
518
+ onChange: (M) => {
519
+ L(M.target.value), w(0);
520
520
  },
521
521
  placeholder: "Search rows…",
522
522
  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"
@@ -549,22 +549,22 @@ function nl({
549
549
  ] })
550
550
  ] }),
551
551
  /* @__PURE__ */ e("div", { className: "min-h-0 flex-1 overflow-auto", children: /* @__PURE__ */ i("table", { className: "w-full text-[11.5px]", children: [
552
- /* @__PURE__ */ e("thead", { className: "sticky top-0 z-[1] bg-white dark:bg-card", children: /* @__PURE__ */ e("tr", { children: te.map(($) => /* @__PURE__ */ e(
552
+ /* @__PURE__ */ e("thead", { className: "sticky top-0 z-[1] bg-white dark:bg-card", children: /* @__PURE__ */ e("tr", { children: te.map((M) => /* @__PURE__ */ e(
553
553
  "th",
554
554
  {
555
555
  className: Q(
556
556
  "whitespace-nowrap border-b border-slate-100 px-1.5 py-1 text-left font-medium text-slate-400 dark:border-border",
557
- je.has($.format ?? "") && "text-right"
557
+ je.has(M.format ?? "") && "text-right"
558
558
  ),
559
- children: $.label ?? $.field
559
+ children: M.label ?? M.field
560
560
  },
561
- $.field
561
+ M.field
562
562
  )) }) }),
563
- /* @__PURE__ */ e("tbody", { children: pe.map(($, z) => /* @__PURE__ */ e(
563
+ /* @__PURE__ */ e("tbody", { children: pe.map((M, z) => /* @__PURE__ */ e(
564
564
  "tr",
565
565
  {
566
566
  className: m ? "cursor-pointer hover:bg-slate-50 dark:hover:bg-muted/60" : void 0,
567
- onClick: () => void f($),
567
+ onClick: () => void f(M),
568
568
  title: m ? "Open the record behind this row" : void 0,
569
569
  children: te.map((de) => /* @__PURE__ */ e(
570
570
  "td",
@@ -573,27 +573,27 @@ function nl({
573
573
  "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",
574
574
  je.has(de.format ?? "") && "text-right tabular-nums"
575
575
  ),
576
- children: Ee($[de.field], de.format, de.decimals)
576
+ children: Ee(M[de.field], de.format, de.decimals)
577
577
  },
578
578
  de.field
579
579
  ))
580
580
  },
581
581
  z
582
582
  )) }),
583
- t.totals && v.length > 0 && /* @__PURE__ */ e("tfoot", { className: "sticky bottom-0 bg-white dark:bg-card", children: /* @__PURE__ */ e("tr", { children: te.map(($, z) => /* @__PURE__ */ e(
583
+ 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(
584
584
  "td",
585
585
  {
586
586
  className: Q(
587
587
  "border-t border-slate-200 px-1.5 py-1 font-semibold text-slate-800 dark:border-border dark:text-slate-200",
588
- je.has($.format ?? "") && "text-right tabular-nums"
588
+ je.has(M.format ?? "") && "text-right tabular-nums"
589
589
  ),
590
- children: z === 0 && !je.has($.format ?? "") ? "Total" : je.has($.format ?? "") ? Ee(
591
- Z.reduce((de, ge) => de + (Number(ge[$.field]) || 0), 0),
592
- $.format,
593
- $.decimals
590
+ children: z === 0 && !je.has(M.format ?? "") ? "Total" : je.has(M.format ?? "") ? Ee(
591
+ Z.reduce((de, ge) => de + (Number(ge[M.field]) || 0), 0),
592
+ M.format,
593
+ M.decimals
594
594
  ) : ""
595
595
  },
596
- $.field
596
+ M.field
597
597
  )) }) })
598
598
  ] }) })
599
599
  ] });
@@ -673,7 +673,7 @@ function nl({
673
673
  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);
674
674
  return /* @__PURE__ */ i("div", { className: "flex min-h-0 flex-1 items-stretch gap-3", children: [
675
675
  /* @__PURE__ */ i("div", { className: "relative min-h-[110px] min-w-0 flex-1", children: [
676
- /* @__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: $ }) => /* @__PURE__ */ e(pe, { width: "100%", height: "100%", children: /* @__PURE__ */ i(oe, { children: [
676
+ /* @__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: [
677
677
  /* @__PURE__ */ e(
678
678
  ie,
679
679
  {
@@ -694,7 +694,7 @@ function nl({
694
694
  }
695
695
  ),
696
696
  /* @__PURE__ */ e(
697
- $,
697
+ M,
698
698
  {
699
699
  contentStyle: {
700
700
  fontSize: 12,
@@ -753,30 +753,30 @@ function nl({
753
753
  },
754
754
  labelStyle: { color: "#f1f5f9" },
755
755
  itemStyle: { color: "#e2e8f0" },
756
- formatter: ($) => _e($)
756
+ formatter: (M) => _e(M)
757
757
  }
758
758
  ),
759
759
  fe.length > 1 && /* @__PURE__ */ e(X, { wrapperStyle: { fontSize: 11 } }),
760
- fe.map(($, z) => /* @__PURE__ */ e(
760
+ fe.map((M, z) => /* @__PURE__ */ e(
761
761
  v,
762
762
  {
763
763
  type: "monotone",
764
- dataKey: $.field,
765
- name: $.label ?? $.field,
766
- stroke: $.color ?? ce[z % ce.length],
764
+ dataKey: M.field,
765
+ name: M.label ?? M.field,
766
+ stroke: M.color ?? ce[z % ce.length],
767
767
  strokeWidth: 2,
768
- strokeDasharray: $.dash ? "4 3" : void 0,
769
- fill: $.color ?? ce[z % ce.length],
770
- fillOpacity: t.display === "area" && !$.dash ? 0.12 : 0
768
+ strokeDasharray: M.dash ? "4 3" : void 0,
769
+ fill: M.color ?? ce[z % ce.length],
770
+ fillOpacity: t.display === "area" && !M.dash ? 0.12 : 0
771
771
  },
772
- $.field
772
+ M.field
773
773
  ))
774
774
  ] }) }) }),
775
775
  ae
776
776
  ] });
777
777
  const Y = t.display === "stacked_bar";
778
778
  return /* @__PURE__ */ i("div", { className: "min-h-[110px] min-w-0 flex-1", children: [
779
- /* @__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: $ }) => /* @__PURE__ */ e(ie, { width: "100%", height: "100%", children: /* @__PURE__ */ i(
779
+ /* @__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(
780
780
  A,
781
781
  {
782
782
  data: be,
@@ -794,7 +794,7 @@ function nl({
794
794
  }
795
795
  ),
796
796
  /* @__PURE__ */ e(
797
- $,
797
+ M,
798
798
  {
799
799
  type: "category",
800
800
  dataKey: se,
@@ -813,7 +813,7 @@ function nl({
813
813
  ..._t(be.length)
814
814
  }
815
815
  ),
816
- /* @__PURE__ */ e($, { tick: { fontSize: 10 }, stroke: "#94a3b8", tickFormatter: Se, width: 48 })
816
+ /* @__PURE__ */ e(M, { tick: { fontSize: 10 }, stroke: "#94a3b8", tickFormatter: Se, width: 48 })
817
817
  ] }),
818
818
  /* @__PURE__ */ e(
819
819
  oe,
@@ -931,9 +931,9 @@ function cl({
931
931
  widget: s,
932
932
  filterBar: a
933
933
  }) {
934
- const o = Ke(), u = Ct(), [m, h] = _(!1), [f, p] = _(""), [L, C] = _([
934
+ const o = Ke(), u = Ct(), [m, h] = C(!1), [f, p] = C(""), [L, $] = C([
935
935
  { field: "value", agg: "sum", op: "gt", value: "" }
936
- ]), [w, P] = _([]), [c, S] = _(!1), [J, O] = _(null), G = ol(s), { data: H = [] } = ke({
936
+ ]), [w, P] = C([]), [c, S] = C(!1), [J, O] = C(null), G = ol(s), { data: H = [] } = ke({
937
937
  queryKey: ["nivaro-report-alerts", t],
938
938
  queryFn: () => o.request(ga(t)).then((x) => x.data),
939
939
  enabled: m,
@@ -956,7 +956,7 @@ function cl({
956
956
  );
957
957
  },
958
958
  onSuccess: () => {
959
- p(""), C([{ field: "value", agg: "sum", op: "gt", value: "" }]), P([]), Z();
959
+ p(""), $([{ field: "value", agg: "sum", op: "gt", value: "" }]), P([]), Z();
960
960
  }
961
961
  }), fe = Me({
962
962
  mutationFn: (x) => o.request(ya(t, x.id, !x.is_active)),
@@ -1057,7 +1057,7 @@ function cl({
1057
1057
  kt,
1058
1058
  {
1059
1059
  value: x.field,
1060
- onChange: (Y) => C((ue) => ue.map((le, v) => v === I ? { ...le, field: Y } : le)),
1060
+ onChange: (Y) => $((ue) => ue.map((le, v) => v === I ? { ...le, field: Y } : le)),
1061
1061
  options: G.map((Y) => ({ value: Y.value, label: Y.label })),
1062
1062
  ariaLabel: "Alert metric field",
1063
1063
  className: "h-7 min-w-0 flex-1 rounded-md px-1.5 py-0 text-[11.5px] dark:border-border dark:bg-card"
@@ -1067,7 +1067,7 @@ function cl({
1067
1067
  kt,
1068
1068
  {
1069
1069
  value: x.agg,
1070
- onChange: (Y) => C(
1070
+ onChange: (Y) => $(
1071
1071
  (ue) => ue.map((le, v) => v === I ? { ...le, agg: Y } : le)
1072
1072
  ),
1073
1073
  options: il.map((Y) => ({ value: Y, label: Y })),
@@ -1079,7 +1079,7 @@ function cl({
1079
1079
  kt,
1080
1080
  {
1081
1081
  value: x.op,
1082
- onChange: (Y) => C(
1082
+ onChange: (Y) => $(
1083
1083
  (ue) => ue.map((le, v) => v === I ? { ...le, op: Y } : le)
1084
1084
  ),
1085
1085
  options: sl.map((Y) => ({ value: Y, label: da[Y] })),
@@ -1091,7 +1091,7 @@ function cl({
1091
1091
  "input",
1092
1092
  {
1093
1093
  value: x.value,
1094
- onChange: (Y) => C(
1094
+ onChange: (Y) => $(
1095
1095
  (ue) => ue.map((le, v) => v === I ? { ...le, value: Y.target.value } : le)
1096
1096
  ),
1097
1097
  placeholder: "0",
@@ -1104,7 +1104,7 @@ function cl({
1104
1104
  {
1105
1105
  type: "button",
1106
1106
  className: "text-slate-300 hover:text-red-500",
1107
- onClick: () => C((Y) => Y.filter((ue, le) => le !== I)),
1107
+ onClick: () => $((Y) => Y.filter((ue, le) => le !== I)),
1108
1108
  children: /* @__PURE__ */ e(Ae, { className: "h-3 w-3" })
1109
1109
  }
1110
1110
  )
@@ -1115,7 +1115,7 @@ function cl({
1115
1115
  {
1116
1116
  type: "button",
1117
1117
  className: "text-[10.5px] text-slate-400 hover:text-nvr-navy dark:hover:text-nvr-cyan",
1118
- onClick: () => C((x) => [...x, { field: "value", agg: "sum", op: "gt", value: "" }]),
1118
+ onClick: () => $((x) => [...x, { field: "value", agg: "sum", op: "gt", value: "" }]),
1119
1119
  children: "+ condition (all must match)"
1120
1120
  }
1121
1121
  ),
@@ -1185,7 +1185,7 @@ const ml = {
1185
1185
  nnull: "_nnull"
1186
1186
  };
1187
1187
  function qt(t, s, a, o) {
1188
- var L, C;
1188
+ var L, $;
1189
1189
  const u = t.config ?? {}, m = [];
1190
1190
  for (const w of u.filters ?? []) {
1191
1191
  const P = ml[w.op];
@@ -1195,7 +1195,7 @@ function qt(t, s, a, o) {
1195
1195
  }
1196
1196
  for (const w of s)
1197
1197
  (L = w.values) != null && L.length && m.push({ path: [w.field], op: "_in", value: w.values });
1198
- const h = u.date_field || ((C = u.dimension) != null && C.bucket ? u.dimension.field : null), f = na(a);
1198
+ const h = u.date_field || (($ = u.dimension) != null && $.bucket ? u.dimension.field : null), f = na(a);
1199
1199
  f && h && (m.push({ path: [h], op: "_gte", value: f.start }), m.push({ path: [h], op: "_lte", value: `${f.end}T23:59:59` }));
1200
1200
  const p = u.dimension;
1201
1201
  if (o !== void 0 && (p != null && p.field))
@@ -1236,9 +1236,9 @@ function ul(t) {
1236
1236
  return t ? t.value != null ? Number(t.value) : t.series ? t.series.reduce((o, u) => o + (Number(u.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;
1237
1237
  }
1238
1238
  function Et(t, s, a) {
1239
- var C, w, P;
1239
+ var $, w, P;
1240
1240
  const o = a ? [...a] : [];
1241
- if (o.length === 0 && ((C = s == null ? void 0 : s.rows) != null && C.length) && o.push(...s.rows), o.length === 0 && ((w = s == null ? void 0 : s.series) != null && w.length))
1241
+ 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))
1242
1242
  for (const c of s.series)
1243
1243
  o.push({
1244
1244
  dim: c.dim,
@@ -1280,7 +1280,7 @@ function pl({
1280
1280
  ),
1281
1281
  staleTime: 3e4,
1282
1282
  retry: !1
1283
- }), L = (f == null ? void 0 : f.data) ?? [], C = (w) => {
1283
+ }), L = (f == null ? void 0 : f.data) ?? [], $ = (w) => {
1284
1284
  for (const c of [
1285
1285
  "title",
1286
1286
  "name",
@@ -1341,7 +1341,7 @@ function pl({
1341
1341
  type: "button",
1342
1342
  onClick: () => u({ collection: t, itemId: String(w.id) }),
1343
1343
  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",
1344
- children: C(w)
1344
+ children: $(w)
1345
1345
  },
1346
1346
  String(w.id)
1347
1347
  ))
@@ -1384,7 +1384,7 @@ const Tt = Fa(function({
1384
1384
  onDrill: f,
1385
1385
  snapshot: p,
1386
1386
  asOf: L,
1387
- annotations: C,
1387
+ annotations: $,
1388
1388
  onAddAnnotation: w,
1389
1389
  onDeleteAnnotation: P,
1390
1390
  onCrossFilter: c,
@@ -1392,7 +1392,7 @@ const Tt = Fa(function({
1392
1392
  currentFilters: J
1393
1393
  }) {
1394
1394
  var Be, ht, Qe, ft, Ue, xt, bt, Ie, gt, Ye, et, Je, tt, at, lt, re, vt, rt, nt, st;
1395
- const O = Ke(), [G, H] = _(""), [me, Z] = _(0), [te, se] = _(null), [fe, be] = _(!1), [Se, _e] = _(""), [x, I] = _(""), [ae, Y] = _(!1), [ue, le] = _(!1), [v, A] = _([]), X = St(null), [K, ie] = _(!1), [oe, pe] = _(null), [$, z] = _(!1), [de, ge] = _(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] = _(!1), Ne = async () => {
1395
+ 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 () => {
1396
1396
  mt(!0);
1397
1397
  try {
1398
1398
  const l = await O.request(
@@ -1518,7 +1518,7 @@ const Tt = Fa(function({
1518
1518
  );
1519
1519
  else if (j)
1520
1520
  if (a.type === "queue") {
1521
- 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), M = l.map(
1521
+ 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(
1522
1522
  (R, ne) => `${ne / Math.max(1, l.length - 1) * 100},${28 - (R.value - g) / q * 26}`
1523
1523
  ).join(" ");
1524
1524
  V = /* @__PURE__ */ i("div", { className: "flex min-h-0 flex-1 flex-col justify-center", children: [
@@ -1526,7 +1526,7 @@ const Tt = Fa(function({
1526
1526
  l.length >= 3 && /* @__PURE__ */ e("svg", { viewBox: "0 0 100 30", preserveAspectRatio: "none", className: "mt-1.5 h-7 w-full", children: /* @__PURE__ */ e(
1527
1527
  "polyline",
1528
1528
  {
1529
- points: M,
1529
+ points: _,
1530
1530
  fill: "none",
1531
1531
  stroke: Ve,
1532
1532
  strokeWidth: "2",
@@ -1551,7 +1551,7 @@ const Tt = Fa(function({
1551
1551
  var g;
1552
1552
  const l = (g = a.config) == null ? void 0 : g.thresholds;
1553
1553
  if (!(l != null && l.length) || j.value == null) return null;
1554
- const n = [...l].filter((q) => Number.isFinite(q.gte)).sort((q, M) => M.gte - q.gte).find((q) => j.value >= q.gte);
1554
+ const n = [...l].filter((q) => Number.isFinite(q.gte)).sort((q, _) => _.gte - q.gte).find((q) => j.value >= q.gte);
1555
1555
  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;
1556
1556
  })()
1557
1557
  ),
@@ -1567,13 +1567,13 @@ const Tt = Fa(function({
1567
1567
  ),
1568
1568
  /* @__PURE__ */ e(Pt, { pct: j.change_pct })
1569
1569
  ] }), j.spark && j.spark.length >= 3) {
1570
- 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), M = l.map((R, ne) => `${ne / (l.length - 1) * 100},${28 - (R.value - g) / q * 26}`).join(" ");
1570
+ 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(" ");
1571
1571
  V = /* @__PURE__ */ i("div", { className: "flex min-h-0 flex-1 flex-col justify-center", children: [
1572
1572
  V,
1573
1573
  /* @__PURE__ */ e("svg", { viewBox: "0 0 100 30", preserveAspectRatio: "none", className: "mt-1.5 h-7 w-full", children: /* @__PURE__ */ e(
1574
1574
  "polyline",
1575
1575
  {
1576
- points: M,
1576
+ points: _,
1577
1577
  fill: "none",
1578
1578
  stroke: Ve,
1579
1579
  strokeWidth: "2",
@@ -1614,7 +1614,7 @@ const Tt = Fa(function({
1614
1614
  (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)
1615
1615
  ) });
1616
1616
  else if (a.type === "heatmap") {
1617
- 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)), M = (R, ne) => l.find((ee) => ee.dim === R && ee.dim2 === ne);
1617
+ 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);
1618
1618
  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: [
1619
1619
  /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ i("tr", { children: [
1620
1620
  /* @__PURE__ */ e("th", {}),
@@ -1630,7 +1630,7 @@ const Tt = Fa(function({
1630
1630
  /* @__PURE__ */ e("tbody", { children: n.map((R) => /* @__PURE__ */ i("tr", { children: [
1631
1631
  /* @__PURE__ */ e("td", { className: "max-w-[110px] truncate pr-1.5 text-slate-500 dark:text-slate-400", children: R }),
1632
1632
  g.map((ne) => {
1633
- const ee = M(R, ne), F = ee ? ee.value / q : 0;
1633
+ const ee = _(R, ne), F = ee ? ee.value / q : 0;
1634
1634
  return /* @__PURE__ */ e("td", { className: "p-0.5", children: /* @__PURE__ */ e(
1635
1635
  "div",
1636
1636
  {
@@ -1686,8 +1686,8 @@ const Tt = Fa(function({
1686
1686
  /* @__PURE__ */ e("tbody", { children: l.rows.map((n) => /* @__PURE__ */ i("tr", { className: "hover:bg-muted", children: [
1687
1687
  /* @__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 }),
1688
1688
  l.cols.map((g) => {
1689
- var M;
1690
- const q = (M = l.cells[n]) == null ? void 0 : M[g];
1689
+ var _;
1690
+ const q = (_ = l.cells[n]) == null ? void 0 : _[g];
1691
1691
  return /* @__PURE__ */ e(
1692
1692
  "td",
1693
1693
  {
@@ -1733,17 +1733,17 @@ const Tt = Fa(function({
1733
1733
  const n = [];
1734
1734
  n.push({ label: "Previous", from: 0, to: l.start, kind: "total" });
1735
1735
  let g = l.start;
1736
- for (const M of l.steps)
1736
+ for (const _ of l.steps)
1737
1737
  n.push({
1738
- label: M.dim,
1738
+ label: _.dim,
1739
1739
  from: g,
1740
- to: g + M.delta,
1741
- kind: M.delta >= 0 ? "up" : "down"
1742
- }), g += M.delta;
1740
+ to: g + _.delta,
1741
+ kind: _.delta >= 0 ? "up" : "down"
1742
+ }), g += _.delta;
1743
1743
  n.push({ label: "Current", from: 0, to: l.end, kind: "total" });
1744
- const q = Math.max(1, ...n.map((M) => Math.max(M.from, M.to)));
1745
- 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((M, R) => {
1746
- const ne = Math.max(M.from, M.to) / q * 100, ee = Math.abs(M.to - M.from) / q * 100;
1744
+ const q = Math.max(1, ...n.map((_) => Math.max(_.from, _.to)));
1745
+ 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) => {
1746
+ const ne = Math.max(_.from, _.to) / q * 100, ee = Math.abs(_.to - _.from) / q * 100;
1747
1747
  return /* @__PURE__ */ i(
1748
1748
  "div",
1749
1749
  {
@@ -1752,15 +1752,15 @@ const Tt = Fa(function({
1752
1752
  /* @__PURE__ */ e("div", { style: { height: `${Math.max(ne, 0.5)}%` }, className: "relative w-full", children: /* @__PURE__ */ e(
1753
1753
  "div",
1754
1754
  {
1755
- "data-tip": `${M.label}: ${(M.to - M.from).toLocaleString()}`,
1755
+ "data-tip": `${_.label}: ${(_.to - _.from).toLocaleString()}`,
1756
1756
  className: "absolute inset-x-0 top-0 rounded-sm",
1757
1757
  style: {
1758
1758
  height: `${Math.max(ee / Math.max(ne, 1e-3) * 100, 2)}%`,
1759
- backgroundColor: M.kind === "total" ? "#172940" : M.kind === "up" ? "#10b981" : "#ef4444"
1759
+ backgroundColor: _.kind === "total" ? "#172940" : _.kind === "up" ? "#10b981" : "#ef4444"
1760
1760
  }
1761
1761
  }
1762
1762
  ) }),
1763
- /* @__PURE__ */ e("p", { className: "absolute -bottom-4 left-0 right-0 truncate text-center text-[9px] text-slate-400", children: M.label })
1763
+ /* @__PURE__ */ e("p", { className: "absolute -bottom-4 left-0 right-0 truncate text-center text-[9px] text-slate-400", children: _.label })
1764
1764
  ]
1765
1765
  },
1766
1766
  R
@@ -1805,7 +1805,7 @@ const Tt = Fa(function({
1805
1805
  } else if (a.type === "scatter") {
1806
1806
  const l = j.rows ?? [];
1807
1807
  V = l.length === 0 ? /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-400", children: "No data." }) : (() => {
1808
- const n = l.length, g = l.reduce((b, y) => b + y.x, 0), q = l.reduce((b, y) => b + y.y, 0), M = l.reduce((b, y) => b + y.x * y.x, 0), R = l.reduce((b, y) => b + y.x * y.y, 0), ne = n * M - 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 = [
1808
+ 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 = [
1809
1809
  { x: W, y: F + ee * W },
1810
1810
  { x: D, y: F + ee * D }
1811
1811
  ];
@@ -1857,7 +1857,7 @@ const Tt = Fa(function({
1857
1857
  })();
1858
1858
  } else if (a.type === "pareto") {
1859
1859
  const l = j.series ?? [];
1860
- 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: M, Tooltip: R, XAxis: ne, YAxis: ee }) => /* @__PURE__ */ e(M, { width: "100%", height: "100%", children: /* @__PURE__ */ i(g, { data: l, margin: { top: 6, right: 4, left: -10, bottom: 0 }, children: [
1860
+ 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: [
1861
1861
  /* @__PURE__ */ e(
1862
1862
  ne,
1863
1863
  {
@@ -1948,15 +1948,15 @@ const Tt = Fa(function({
1948
1948
  )
1949
1949
  ] }, n.dim)) });
1950
1950
  } else if (a.type === "table") {
1951
- 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), M = ((Ye = a.config) == null ? void 0 : Ye.format_rules) ?? [], R = (d) => {
1951
+ 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) => {
1952
1952
  var k;
1953
- for (const N of M)
1953
+ for (const N of _)
1954
1954
  if ((N.scope ?? "cell") === "row" && Bt(N, d[N.field]))
1955
1955
  return ((k = Wt[N.color]) == null ? void 0 : k.row) ?? null;
1956
1956
  return null;
1957
1957
  }, ne = (d, k) => {
1958
1958
  var N;
1959
- for (const E of M)
1959
+ for (const E of _)
1960
1960
  if ((E.scope ?? "cell") === "cell" && E.field === k && Bt(E, d[k]))
1961
1961
  return ((N = Wt[E.color]) == null ? void 0 : N.cell) ?? null;
1962
1962
  return null;
@@ -2082,13 +2082,13 @@ const Tt = Fa(function({
2082
2082
  ...D.value2 != null ? { value2: W } : {}
2083
2083
  }));
2084
2084
  }
2085
- const q = l.some((F) => F.value2 != null), M = ((lt = (at = a.config) == null ? void 0 : at.metric2) == null ? void 0 : lt.label) ?? "secondary", R = l.some((F) => F.band != null), ne = (() => {
2085
+ 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 = (() => {
2086
2086
  if (!n || ae || l.length < 8) return /* @__PURE__ */ new Set();
2087
2087
  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);
2088
2088
  return W === 0 ? /* @__PURE__ */ new Set() : new Set(
2089
2089
  l.filter((D) => Math.abs(D.value - U) > 2 * W).map((D) => D.dim)
2090
2090
  );
2091
- })(), ee = (C ?? []).filter(
2091
+ })(), ee = ($ ?? []).filter(
2092
2092
  (F) => F.anchor_date && l.some((U) => U.dim === F.anchor_date)
2093
2093
  );
2094
2094
  if (l.length === 0) V = /* @__PURE__ */ e("p", { className: "px-1 text-[12px] text-slate-400", children: "No data." });
@@ -2306,7 +2306,7 @@ const Tt = Fa(function({
2306
2306
  stroke: "#8b5cf6",
2307
2307
  strokeWidth: 1.5,
2308
2308
  dot: !1,
2309
- name: M
2309
+ name: _
2310
2310
  }
2311
2311
  ),
2312
2312
  g >= 2 && /* @__PURE__ */ e(
@@ -2453,7 +2453,7 @@ const Tt = Fa(function({
2453
2453
  stroke: "#8b5cf6",
2454
2454
  strokeWidth: 1.5,
2455
2455
  dot: !1,
2456
- name: M
2456
+ name: _
2457
2457
  }
2458
2458
  )
2459
2459
  ]
@@ -2547,7 +2547,7 @@ const Tt = Fa(function({
2547
2547
  ie(!1);
2548
2548
  return;
2549
2549
  }
2550
- if (ie(!0), oe || $) return;
2550
+ if (ie(!0), oe || M) return;
2551
2551
  if (z(!0), ve) {
2552
2552
  O.request(
2553
2553
  ct(`/report-studio/${s}/widgets/${a.id}/explain-trend`, {
@@ -2580,16 +2580,19 @@ const Tt = Fa(function({
2580
2580
  series: ((n == null ? void 0 : n.series) ?? []).slice(0, 15),
2581
2581
  rows: ((n == null ? void 0 : n.rows) ?? []).slice(0, 10),
2582
2582
  tiles: (n == null ? void 0 : n.tiles) ?? null
2583
- };
2583
+ }, q = (n == null ? void 0 : n.prev_value) != null || ((n == null ? void 0 : n.series) ?? []).some((_) => _.prev != null);
2584
2584
  return O.request(
2585
2585
  ct("/ai/brief", {
2586
2586
  context: JSON.stringify(g),
2587
- instructions: (n == null ? void 0 : n.prev_value) != null || ((n == null ? void 0 : n.series) ?? []).some((q) => q.prev != null) ? "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."
2587
+ // `template` picks the server's prompt; `instructions` (the same
2588
+ // text) keeps an older API answering the same way.
2589
+ template: q ? "report-compare" : "report-explain",
2590
+ 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."
2588
2591
  })
2589
2592
  );
2590
2593
  }).then((n) => {
2591
- var q, M;
2592
- const g = ((q = n.data) == null ? void 0 : q.brief) ?? ((M = n.data) == null ? void 0 : M.text) ?? null;
2594
+ var q, _;
2595
+ const g = ((q = n.data) == null ? void 0 : q.brief) ?? ((_ = n.data) == null ? void 0 : _.text) ?? null;
2593
2596
  pe(g || "No explanation available.");
2594
2597
  }).catch(() => pe("AI is not configured or unavailable.")).finally(() => z(!1));
2595
2598
  },
@@ -2616,7 +2619,7 @@ const Tt = Fa(function({
2616
2619
  title: "Notes on this widget",
2617
2620
  className: Q(
2618
2621
  "relative rounded p-0.5",
2619
- ((C == null ? void 0 : C.length) ?? 0) > 0 ? "text-amber-500" : "text-slate-300 hover:text-slate-500"
2622
+ (($ == null ? void 0 : $.length) ?? 0) > 0 ? "text-amber-500" : "text-slate-300 hover:text-slate-500"
2620
2623
  ),
2621
2624
  onClick: () => be((l) => !l),
2622
2625
  children: /* @__PURE__ */ e($a, { className: "h-3 w-3" })
@@ -2657,7 +2660,7 @@ const Tt = Fa(function({
2657
2660
  ] })
2658
2661
  ] }),
2659
2662
  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: [
2660
- (C ?? []).map((l) => /* @__PURE__ */ i(
2663
+ ($ ?? []).map((l) => /* @__PURE__ */ i(
2661
2664
  "div",
2662
2665
  {
2663
2666
  className: "group/note flex items-start gap-1.5 text-[11px] text-slate-600 dark:text-slate-300",
@@ -2684,7 +2687,7 @@ const Tt = Fa(function({
2684
2687
  },
2685
2688
  l.id
2686
2689
  )),
2687
- (C ?? []).length === 0 && /* @__PURE__ */ e("p", { className: "text-[11px] text-slate-400", children: "No notes yet — record why a number moved." }),
2690
+ ($ ?? []).length === 0 && /* @__PURE__ */ e("p", { className: "text-[11px] text-slate-400", children: "No notes yet — record why a number moved." }),
2688
2691
  w && /* @__PURE__ */ i("div", { className: "flex items-center gap-1 pt-0.5", children: [
2689
2692
  /* @__PURE__ */ e(
2690
2693
  "input",
@@ -2750,8 +2753,8 @@ const Tt = Fa(function({
2750
2753
  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",
2751
2754
  "data-explain-panel": ve ? "trend" : "number",
2752
2755
  children: [
2753
- $ ? "Thinking…" : oe,
2754
- !$ && 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(
2756
+ M ? "Thinking…" : oe,
2757
+ !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(
2755
2758
  "span",
2756
2759
  {
2757
2760
  className: Q(
@@ -2866,10 +2869,10 @@ function Pl({
2866
2869
  reportUrl: f
2867
2870
  }) {
2868
2871
  var W, D;
2869
- const p = Ke(), L = Xt(), C = Aa("drill.report"), w = C.value, P = Ft(
2870
- (r) => L ? L.open(r) : C.push([r]),
2871
- [L, C.push]
2872
- ), [c, S] = _(void 0), [J, O] = _(o), [G, H] = _(void 0), [me, Z] = _(o), { scopes: te, ready: se } = Pa(), [fe, be] = _(!1), [Se, _e] = _({}), x = Ct(), { data: I = [] } = ke({
2872
+ const p = Ke(), L = Xt(), $ = Aa("drill.report"), w = $.value, P = Ft(
2873
+ (r) => L ? L.open(r) : $.push([r]),
2874
+ [L, $.push]
2875
+ ), [c, S] = C(void 0), [J, O] = C(o), [G, H] = C(void 0), [me, Z] = C(o), { scopes: te, ready: se } = Pa(), [fe, be] = C(!1), [Se, _e] = C({}), x = Ct(), { data: I = [] } = ke({
2873
2876
  queryKey: ["nivaro-report-presets", t],
2874
2877
  queryFn: async () => {
2875
2878
  try {
@@ -2903,7 +2906,7 @@ function Pl({
2903
2906
  }), ue = Me({
2904
2907
  mutationFn: (r) => p.request(ua(t, r)),
2905
2908
  onSuccess: ae
2906
- }), [le, v] = _(""), [A, X] = _(!1), [K, ie] = _(null), [oe, pe] = _(!1), { data: $ = [] } = ke({
2909
+ }), [le, v] = C(""), [A, X] = C(!1), [K, ie] = C(null), [oe, pe] = C(!1), { data: M = [] } = ke({
2907
2910
  queryKey: ["nvr-report-snaps", t],
2908
2911
  queryFn: () => p.request(
2909
2912
  ot(`/report-studio/${t}/snapshots`)
@@ -2939,7 +2942,7 @@ function Pl({
2939
2942
  labels: [y]
2940
2943
  };
2941
2944
  O((k) => [...k.filter((N) => N.field !== r), d]), Z((k) => [...k.filter((N) => N.field !== r), d]);
2942
- }, []), [Ne, Xe] = _(!1), [ye, Fe] = _(null), [Ze, Re] = _(null), De = Me({
2945
+ }, []), [Ne, Xe] = C(!1), [ye, Fe] = C(null), [Ze, Re] = C(null), De = Me({
2943
2946
  mutationFn: (r) => p.request(
2944
2947
  Ra(`/report-studio/${t}/widgets`, {
2945
2948
  widgets: r.map((b, y) => ({ ...b, sort: y }))
@@ -2948,7 +2951,7 @@ function Pl({
2948
2951
  onSuccess: () => {
2949
2952
  Xe(!1), Fe(null), Re(null), x.invalidateQueries({ queryKey: ["nivaro-report", t] }), x.invalidateQueries({ queryKey: ["nivaro-report-widget"] });
2950
2953
  }
2951
- }), ut = (r) => [...r].sort((b, y) => (b.y ?? 0) - (y.y ?? 0) || (b.x ?? 0) - (y.x ?? 0)), [We, pt] = _(() => /* @__PURE__ */ new Date()), j = () => {
2954
+ }), 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 = () => {
2952
2955
  x.invalidateQueries({ queryKey: ["nivaro-report-widget", t] }), x.invalidateQueries({ queryKey: ["nivaro-report-query"] }), pt(/* @__PURE__ */ new Date());
2953
2956
  }, { data: xe = [] } = ke({
2954
2957
  queryKey: ["nvr-report-firing", t],
@@ -2956,7 +2959,7 @@ function Pl({
2956
2959
  staleTime: 6e4,
2957
2960
  refetchInterval: 5 * 6e4,
2958
2961
  retry: !1
2959
- }), [he, Pe] = _(null), [$e, V] = _(!1), [Be, ht] = _(""), [Qe, ft] = _(""), [Ue, xt] = _("");
2962
+ }), [he, Pe] = C(null), [$e, V] = C(!1), [Be, ht] = C(""), [Qe, ft] = C(""), [Ue, xt] = C("");
2960
2963
  wt(() => {
2961
2964
  try {
2962
2965
  const r = sessionStorage.getItem(`nvr-report-xf:${t}`);
@@ -2975,7 +2978,7 @@ function Pl({
2975
2978
  if (k < 0 || N < 0 || N >= d.length) return d;
2976
2979
  const E = d[k], B = d[N];
2977
2980
  return d[k] = { ...B, x: E.x, y: E.y }, d[N] = { ...E, x: B.x, y: B.y }, d;
2978
- }), [Ye, et] = _(""), [Je, tt] = _(!1), [at, lt] = _(null), { data: re, isLoading: vt } = ke({
2981
+ }), [Ye, et] = C(""), [Je, tt] = C(!1), [at, lt] = C(null), { data: re, isLoading: vt } = ke({
2979
2982
  queryKey: ["nivaro-report", t],
2980
2983
  queryFn: () => p.request(pa(t)).then((r) => r.data),
2981
2984
  staleTime: 3e4
@@ -3030,7 +3033,7 @@ function Pl({
3030
3033
  })();
3031
3034
  }
3032
3035
  }, [fe, se, re, te, n]);
3033
- const g = (re == null ? void 0 : re.widgets) ?? [], q = G !== void 0 ? G : l, M = J.filter((r) => r.values.length > 0).length + (l ? 1 : 0), R = JSON.stringify(me) !== JSON.stringify(J) || G !== void 0, ne = () => {
3036
+ 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 = () => {
3034
3037
  O(me), G !== void 0 && (S(G), H(void 0));
3035
3038
  }, ee = () => {
3036
3039
  Z([]), O([]), S(null), H(void 0);
@@ -3067,9 +3070,9 @@ function Pl({
3067
3070
  /* @__PURE__ */ i("div", { className: "flex flex-wrap items-center gap-1.5", children: [
3068
3071
  /* @__PURE__ */ i("span", { className: "flex items-center gap-1.5 text-[11.5px] font-semibold text-slate-500 dark:text-slate-300", children: [
3069
3072
  "Filters",
3070
- 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: [
3073
+ _ > 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: [
3071
3074
  "Active · ",
3072
- M
3075
+ _
3073
3076
  ] })
3074
3077
  ] }),
3075
3078
  /* @__PURE__ */ e(
@@ -3117,7 +3120,7 @@ function Pl({
3117
3120
  ]
3118
3121
  }
3119
3122
  ),
3120
- (M > 0 || R) && /* @__PURE__ */ i(
3123
+ (_ > 0 || R) && /* @__PURE__ */ i(
3121
3124
  "button",
3122
3125
  {
3123
3126
  type: "button",
@@ -3191,7 +3194,7 @@ function Pl({
3191
3194
  ]
3192
3195
  }
3193
3196
  ),
3194
- $.map((r) => /* @__PURE__ */ i(
3197
+ M.map((r) => /* @__PURE__ */ i(
3195
3198
  "button",
3196
3199
  {
3197
3200
  type: "button",
@@ -3504,9 +3507,9 @@ function Pl({
3504
3507
  title: w[0].title,
3505
3508
  width: "72%",
3506
3509
  stack: w,
3507
- onPush: (r) => C.push([...w, r]),
3508
- onPop: () => C.back(),
3509
- onClose: () => C.back(w.length)
3510
+ onPush: (r) => $.push([...w, r]),
3511
+ onPop: () => $.back(),
3512
+ onClose: () => $.back(w.length)
3510
3513
  }
3511
3514
  ) : null
3512
3515
  ] }) : /* @__PURE__ */ e("div", { className: Q("p-6 text-[13px] text-slate-400", m), children: "Report not found." });