react-semaphor 0.1.534 → 0.1.535

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 (42) hide show
  1. package/dist/brand-studio/index.js +25 -25
  2. package/dist/briefings/index.js +1 -1
  3. package/dist/chunks/{calculated-field-identity-Cz1ZU_UL.js → calculated-field-identity-BptYhyOP.js} +4 -4
  4. package/dist/chunks/{card-config-utils-BlIiFn0O.js → card-config-utils-C-QfuqEy.js} +50 -51
  5. package/dist/chunks/{dashboard-CCK80YKL.js → dashboard-B7y_WeF2.js} +1 -1
  6. package/dist/chunks/dashboard-briefing-launcher-DwSxDtgZ.js +4224 -0
  7. package/dist/chunks/{dashboard-controls-CoiTGnEr.js → dashboard-controls-CzTh9J0s.js} +862 -873
  8. package/dist/chunks/{dashboard-json-BRGozO--.js → dashboard-json-o6tOjNhH.js} +1 -1
  9. package/dist/chunks/{edit-dashboard-visual-CZFnhGZQ.js → edit-dashboard-visual-Lp_iKRGH.js} +8983 -8749
  10. package/dist/chunks/{index-BQl5rC54.js → index-P5aUuGF1.js} +1 -1
  11. package/dist/chunks/{matrix-control-sources-Tls-h3AN.js → matrix-control-sources-DTqcA2_L.js} +1 -1
  12. package/dist/chunks/report-preferences-dialog-BaUr346O.js +1623 -0
  13. package/dist/chunks/{layout-grid-CiubineE.js → save-kO6cIaob.js} +20 -2
  14. package/dist/chunks/{semaphor-ready-indicator-z4SNdxiC.js → semaphor-ready-indicator-B017OW6t.js} +61957 -76531
  15. package/dist/chunks/slider-CrLoCpsr.js +2383 -0
  16. package/dist/chunks/{switch-BR3Xgbqr.js → switch-ojmMsFMO.js} +4355 -4779
  17. package/dist/chunks/upload-CAIpsti1.js +15 -0
  18. package/dist/chunks/use-create-flow-overlay-state-BbwQ0gpQ.js +1457 -0
  19. package/dist/dashboard/index.js +1 -1
  20. package/dist/dashboard-authoring/index.js +4 -4
  21. package/dist/index.js +221 -220
  22. package/dist/style.css +1 -1
  23. package/dist/surfboard/index.js +1 -1
  24. package/dist/types/components/surfboard/controls/dashboard-filter-controls-launcher.d.ts +0 -1
  25. package/dist/types/lib/hooks/use-dashboard-query.d.ts +0 -2
  26. package/dist/types/lib/hooks/use-dashboard.d.ts +0 -1
  27. package/dist/types/lib/stores/dashboard-store.d.ts +1 -11
  28. package/dist/types/lib/stores/editor-store.d.ts +1 -10
  29. package/dist/types/lib/types/ai-context-types.d.ts +20 -0
  30. package/dist/types/lib/types/common-types.d.ts +1 -20
  31. package/dist/types/lib/types/token-types.d.ts +0 -7
  32. package/dist/types/lib/utils.d.ts +0 -2
  33. package/package.json +1 -7
  34. package/dist/chunks/dashboard-briefing-launcher-B9Fq2Rf3.js +0 -3489
  35. package/dist/chunks/editor-action-buttons-CVtSO3I3.js +0 -2067
  36. package/dist/chunks/report-preferences-dialog-CWdTlWsr.js +0 -1231
  37. package/dist/chunks/save-DgMfP0j8.js +0 -21
  38. package/dist/chunks/slider-DbwmuVB-.js +0 -875
  39. package/dist/dashboard-assistant/index.js +0 -11
  40. package/dist/types/dashboard-assistant/index.d.ts +0 -80
  41. package/dist/types/dashboard-assistant.d.ts +0 -2
  42. package/dist/types/lib/types/assistant-types.d.ts +0 -127
@@ -0,0 +1,4224 @@
1
+ import { jsx as t, jsxs as s, Fragment as $ } from "react/jsx-runtime";
2
+ import * as ue from "react";
3
+ import _t, { useState as F, useEffect as J, useCallback as j, useMemo as oe, useLayoutEffect as Pt, useRef as ge, useContext as pr } from "react";
4
+ import { B as U, m as Te, r as dt, L as ie, a2 as Je, $ as pe, u as L, aO as R, a1 as ee, k as Ot, d as ut, c as X, j as fr, aY as qe, aP as gr, P as He, a as Qe, b as Ge, aZ as br, S as $t, a_ as vr, a$ as xr, b0 as yr, b1 as Cr, aK as wr } from "./switch-ojmMsFMO.js";
5
+ import { c7 as ht, b7 as Ue, b8 as Re, ba as Ve, c8 as Nr, c9 as Sr, aK as Be, aI as et, ca as Dr, cb as tt, cc as mt, cd as Er, ce as kr, cf as Ar, aV as Ir, cg as Fr, ch as Pr, aE as Se, bN as zt, av as Ke, k as Lr, g as Tr, ci as Ur, b$ as pt, c0 as ft, c1 as gt, c2 as bt, c3 as vt, c4 as xt, c5 as yt, c6 as jt, at as Ct, cj as Rr, ck as Vr, cl as ot, bO as rt, bP as at, cm as Wt, bQ as nt, bu as Y, bZ as Br, bY as Xe, cn as Mr, bs as _r, b9 as wt, bb as Nt, co as Or, b6 as $r, cp as qt, cq as St, cr as zr, bB as jr, u as Wr, cs as qr, z as xe, ao as Le, ak as Ht, al as Ye, ct as Q, A as Qt, aj as Hr, cu as Qr, aq as Gr, R as Gt, cv as Kr, am as Lt, H as Xr, cw as Yr, cx as Zr, cy as Jr, cz as ea, cA as ta, cB as ra, cC as Kt, cD as aa, cE as na, cF as sa, bR as Xt, cG as oa, cH as ze, cI as ia, cJ as la, cK as ca, af as da, ag as ua, X as ha, W as ma, T as pa, Q as fa, N as ga, K as ba, cL as va, cM as xa, cN as ya, cO as Ca, cP as wa, ad as Na, cQ as Sa, cR as Da, a1 as Ea, cS as ka, cT as Aa, cU as Ia } from "./semaphor-ready-indicator-B017OW6t.js";
6
+ import { L as Dt, S as Yt } from "./save-kO6cIaob.js";
7
+ import { c as De, X as Me, C as Zt } from "./x-CXDkqdur.js";
8
+ import { t as Fa } from "./validators-DMSH81OM.js";
9
+ import "./matrix-operation-contract-BKupLHXL.js";
10
+ import "zod";
11
+ import "../value-format-preferences/index.js";
12
+ import { S as Pa } from "./selection-reducer-CiDEtmAq.js";
13
+ import { s as je } from "./normalize-dashboard-for-dirty-check-Bk3VYv_q.js";
14
+ import { f as La, V as Ta, L as Ua, a as Ra, u as Jt, C as er, F as Va, b as Ba } from "./use-create-flow-overlay-state-BbwQ0gpQ.js";
15
+ import "react-dom";
16
+ import "./matrix-continuation-C4sRcjZU.js";
17
+ import "./field-aggregations-CoLzYHeL.js";
18
+ import { v as Tt, s as Ma } from "./card-config-utils-C-QfuqEy.js";
19
+ import { l as _a } from "./bookmark-state-B-I9BDD0.js";
20
+ import { l as Ut } from "./matrix-formatter-DJCk8Znf.js";
21
+ import { d as me, e as Oa, h as $a } from "./index-P5aUuGF1.js";
22
+ /**
23
+ * @license lucide-react v0.453.0 - ISC
24
+ *
25
+ * This source code is licensed under the ISC license.
26
+ * See the LICENSE file in the root directory of this source tree.
27
+ */
28
+ const za = De("ArrowUpRight", [
29
+ ["path", { d: "M7 7h10v10", key: "1tivn9" }],
30
+ ["path", { d: "M7 17 17 7", key: "1vkiza" }]
31
+ ]);
32
+ /**
33
+ * @license lucide-react v0.453.0 - ISC
34
+ *
35
+ * This source code is licensed under the ISC license.
36
+ * See the LICENSE file in the root directory of this source tree.
37
+ */
38
+ const ja = De("CalendarRange", [
39
+ ["rect", { width: "18", height: "18", x: "3", y: "4", rx: "2", key: "1hopcy" }],
40
+ ["path", { d: "M16 2v4", key: "4m81vk" }],
41
+ ["path", { d: "M3 10h18", key: "8toen8" }],
42
+ ["path", { d: "M8 2v4", key: "1cmpym" }],
43
+ ["path", { d: "M17 14h-6", key: "bkmgh3" }],
44
+ ["path", { d: "M13 18H7", key: "bb0bb7" }],
45
+ ["path", { d: "M7 14h.01", key: "1qa3f1" }],
46
+ ["path", { d: "M17 18h.01", key: "1bdyru" }]
47
+ ]);
48
+ /**
49
+ * @license lucide-react v0.453.0 - ISC
50
+ *
51
+ * This source code is licensed under the ISC license.
52
+ * See the LICENSE file in the root directory of this source tree.
53
+ */
54
+ const Wa = De("CodeXml", [
55
+ ["path", { d: "m18 16 4-4-4-4", key: "1inbqp" }],
56
+ ["path", { d: "m6 8-4 4 4 4", key: "15zrgr" }],
57
+ ["path", { d: "m14.5 4-5 16", key: "e7oirm" }]
58
+ ]);
59
+ /**
60
+ * @license lucide-react v0.453.0 - ISC
61
+ *
62
+ * This source code is licensed under the ISC license.
63
+ * See the LICENSE file in the root directory of this source tree.
64
+ */
65
+ const qa = De("FileDown", [
66
+ ["path", { d: "M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z", key: "1rqfz7" }],
67
+ ["path", { d: "M14 2v4a2 2 0 0 0 2 2h4", key: "tnqrlb" }],
68
+ ["path", { d: "M12 18v-6", key: "17g6i2" }],
69
+ ["path", { d: "m9 15 3 3 3-3", key: "1npd3o" }]
70
+ ]);
71
+ /**
72
+ * @license lucide-react v0.453.0 - ISC
73
+ *
74
+ * This source code is licensed under the ISC license.
75
+ * See the LICENSE file in the root directory of this source tree.
76
+ */
77
+ const Ha = De("MousePointer2", [
78
+ [
79
+ "path",
80
+ {
81
+ d: "M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z",
82
+ key: "edeuup"
83
+ }
84
+ ]
85
+ ]);
86
+ /**
87
+ * @license lucide-react v0.453.0 - ISC
88
+ *
89
+ * This source code is licensed under the ISC license.
90
+ * See the LICENSE file in the root directory of this source tree.
91
+ */
92
+ const Qa = De("Newspaper", [
93
+ [
94
+ "path",
95
+ {
96
+ d: "M4 22h16a2 2 0 0 0 2-2V4a2 2 0 0 0-2-2H8a2 2 0 0 0-2 2v16a2 2 0 0 1-2 2Zm0 0a2 2 0 0 1-2-2v-9c0-1.1.9-2 2-2h2",
97
+ key: "7pis2x"
98
+ }
99
+ ],
100
+ ["path", { d: "M18 14h-8", key: "sponae" }],
101
+ ["path", { d: "M15 18h-5", key: "95g1m2" }],
102
+ ["path", { d: "M10 6h8v4h-8V6Z", key: "smlsk5" }]
103
+ ]);
104
+ function Ga() {
105
+ return /* @__PURE__ */ t("div", { className: "space-y-1.5 py-1", children: [...Array(5)].map((e, r) => /* @__PURE__ */ s(
106
+ "div",
107
+ {
108
+ className: "flex animate-pulse items-start gap-3 rounded-xl border border-transparent px-2.5 py-2.5",
109
+ children: [
110
+ /* @__PURE__ */ t("div", { className: "mt-0.5 h-4 w-4 flex-shrink-0 rounded bg-muted/60" }),
111
+ /* @__PURE__ */ s("div", { className: "flex-1 space-y-1.5", children: [
112
+ /* @__PURE__ */ t("div", { className: "h-4 w-3/5 rounded bg-muted/60" }),
113
+ /* @__PURE__ */ t("div", { className: "h-3 w-4/5 rounded bg-muted/40" })
114
+ ] })
115
+ ]
116
+ },
117
+ r
118
+ )) });
119
+ }
120
+ function Ka({
121
+ open: e,
122
+ onOpenChange: r,
123
+ onSubmit: o,
124
+ isCreating: a
125
+ }) {
126
+ const n = ht("interactive"), [i, d] = F(""), [c, l] = F("");
127
+ J(() => {
128
+ e || (d(""), l(""));
129
+ }, [e]);
130
+ const u = () => {
131
+ i.trim() && o({ title: i, description: c });
132
+ }, h = (p) => {
133
+ r(p);
134
+ };
135
+ return /* @__PURE__ */ t(Ue, { open: e, onOpenChange: h, children: /* @__PURE__ */ s(
136
+ Re,
137
+ {
138
+ showCloseButton: !1,
139
+ className: "flex max-w-lg grid-cols-none flex-col gap-0 overflow-hidden rounded-card border-border/60 p-0 shadow-lg sm:rounded-card",
140
+ style: n.dialogStyle,
141
+ children: [
142
+ /* @__PURE__ */ s("div", { className: "flex h-10 shrink-0 items-center justify-between gap-2 border-b border-border/60 px-3", children: [
143
+ /* @__PURE__ */ s("div", { className: "flex min-w-0 items-center gap-2", children: [
144
+ /* @__PURE__ */ t(Dt, { className: "h-3.5 w-3.5 shrink-0 text-muted-foreground" }),
145
+ /* @__PURE__ */ s("div", { className: "flex min-w-0 items-baseline gap-2", children: [
146
+ /* @__PURE__ */ t(Ve, { className: "truncate text-[13px] font-medium leading-none tracking-normal", children: "New library visual" }),
147
+ /* @__PURE__ */ t("span", { className: "shrink-0 text-[10px] font-medium uppercase leading-none tracking-[0.08em] text-muted-foreground", children: "Visual" })
148
+ ] })
149
+ ] }),
150
+ /* @__PURE__ */ t(
151
+ U,
152
+ {
153
+ size: "xs",
154
+ variant: "ghost",
155
+ className: "w-7 px-0 text-muted-foreground hover:text-foreground",
156
+ onClick: () => h(!1),
157
+ "aria-label": "Close",
158
+ disabled: a,
159
+ children: /* @__PURE__ */ t(Me, { className: "h-3.5 w-3.5" })
160
+ }
161
+ )
162
+ ] }),
163
+ /* @__PURE__ */ s("div", { className: "space-y-3 px-4 py-3", children: [
164
+ /* @__PURE__ */ t("p", { className: "text-[12px] text-muted-foreground", children: "Create a saved visual that can be reused across dashboards." }),
165
+ /* @__PURE__ */ s("div", { className: "space-y-1.5", children: [
166
+ /* @__PURE__ */ t(Te, { htmlFor: "visual-title", className: "text-[12px]", children: "Name" }),
167
+ /* @__PURE__ */ t(
168
+ dt,
169
+ {
170
+ id: "visual-title",
171
+ size: "sm",
172
+ placeholder: "Untitled visual",
173
+ value: i,
174
+ onChange: (p) => d(p.target.value),
175
+ disabled: a,
176
+ onKeyDown: (p) => {
177
+ p.key === "Enter" && !p.shiftKey && (p.preventDefault(), u());
178
+ }
179
+ }
180
+ )
181
+ ] }),
182
+ /* @__PURE__ */ s("div", { className: "space-y-1.5", children: [
183
+ /* @__PURE__ */ t(Te, { htmlFor: "visual-description", className: "text-[12px]", children: "Description" }),
184
+ /* @__PURE__ */ t(
185
+ dt,
186
+ {
187
+ id: "visual-description",
188
+ size: "sm",
189
+ placeholder: "Optional",
190
+ value: c,
191
+ onChange: (p) => l(p.target.value),
192
+ disabled: a
193
+ }
194
+ )
195
+ ] })
196
+ ] }),
197
+ /* @__PURE__ */ s("div", { className: "flex shrink-0 justify-end gap-2 border-t border-border/60 px-4 py-2.5", children: [
198
+ /* @__PURE__ */ t(
199
+ U,
200
+ {
201
+ size: "xs",
202
+ variant: "outline",
203
+ onClick: () => h(!1),
204
+ disabled: a,
205
+ children: "Cancel"
206
+ }
207
+ ),
208
+ /* @__PURE__ */ t(
209
+ U,
210
+ {
211
+ size: "xs",
212
+ onClick: u,
213
+ disabled: !i.trim() || a,
214
+ children: a ? /* @__PURE__ */ s($, { children: [
215
+ /* @__PURE__ */ t(ie, { className: "h-3.5 w-3.5 animate-spin" }),
216
+ "Creating..."
217
+ ] }) : "Create library visual"
218
+ }
219
+ )
220
+ ] })
221
+ ]
222
+ }
223
+ ) });
224
+ }
225
+ function Xa(e) {
226
+ const [r, o] = F(null), [a, n] = F(null), i = Nr();
227
+ return J(() => {
228
+ if (!e || e.trim() === "") {
229
+ o(null), n(null);
230
+ return;
231
+ }
232
+ if (!i)
233
+ return;
234
+ (async () => {
235
+ try {
236
+ if (!e.startsWith("http://") && !e.startsWith("https://"))
237
+ throw new Error(`Invalid URL format: ${e}`);
238
+ try {
239
+ new URL(e);
240
+ } catch {
241
+ throw new Error(`Invalid URL: ${e}`);
242
+ }
243
+ const l = `${e.endsWith("/") ? e : `${e}/`}index.js`;
244
+ try {
245
+ if (!(await fetch(l, { method: "HEAD" })).ok)
246
+ throw new Error(`Module not found at ${l}`);
247
+ } catch {
248
+ }
249
+ const u = await import(
250
+ /* @vite-ignore */
251
+ /* webpackIgnore: true */
252
+ l
253
+ );
254
+ if (typeof u.useChartStore != "function")
255
+ throw new Error("useChartStore is not a function");
256
+ o(() => u.useChartStore), n(null);
257
+ } catch (c) {
258
+ const l = c instanceof Error ? c.message : "Unknown error";
259
+ console.error("Failed to load remote chart store:", l), n(l), o(null);
260
+ }
261
+ })();
262
+ }, [e, i]), r;
263
+ }
264
+ function Ya(e, r) {
265
+ if (e.length === 0)
266
+ return "";
267
+ const o = e.find(
268
+ (a) => {
269
+ var n, i;
270
+ return ((n = a.customCardPreferences) == null ? void 0 : n.visualType) === "multiple" || !!((i = a.customCardPreferences) != null && i.dataInputCardIds);
271
+ }
272
+ );
273
+ if (o)
274
+ return o.id;
275
+ if (r) {
276
+ const a = e.find((n) => n.id === r);
277
+ if (a) {
278
+ const n = a.tabTitle;
279
+ if (n == "All__Header")
280
+ return e[0].id;
281
+ if (n && n.endsWith("__Header")) {
282
+ const d = n.split("__")[0], c = e.find(
283
+ (l) => l.tabTitle === d
284
+ );
285
+ return c ? c.id : e[0].id;
286
+ }
287
+ return r;
288
+ }
289
+ }
290
+ return e[0].id;
291
+ }
292
+ function Za(e, r) {
293
+ return r ? {
294
+ ...e,
295
+ settings: r
296
+ } : e;
297
+ }
298
+ function Ja(e, r) {
299
+ const o = r.selectedConnectionId || e.connectionId || "";
300
+ if (!e.dataSource) {
301
+ if (!o)
302
+ return;
303
+ const a = r.selectedDatabaseName || e.lastSelectedDatabase, n = r.selectedSchemaName || e.lastSelectedSchema, i = r.selectedTableName || e.lastSelectedTable;
304
+ return {
305
+ connectionId: o,
306
+ connectionType: "",
307
+ mode: "database",
308
+ selectedEntities: [],
309
+ ...a && n && i ? {
310
+ dbSelection: {
311
+ database: a,
312
+ schema: n,
313
+ entityType: "table"
314
+ }
315
+ } : {}
316
+ };
317
+ }
318
+ return {
319
+ ...e.dataSource,
320
+ connectionId: r.selectedConnectionId || e.dataSource.connectionId || e.connectionId || ""
321
+ };
322
+ }
323
+ function en(e, {
324
+ isDevMode: r,
325
+ cardSql: o,
326
+ selectedSchemaName: a,
327
+ selectedDatamodelId: n,
328
+ selectedDatabaseName: i,
329
+ selectedTableName: d,
330
+ selectedConnectionId: c,
331
+ remoteChartSettings: l,
332
+ stripConfig: u
333
+ }) {
334
+ const h = r || Sr(e);
335
+ return {
336
+ ...e,
337
+ dataSource: Ja(e, {
338
+ selectedConnectionId: c,
339
+ selectedDatabaseName: i,
340
+ selectedSchemaName: a,
341
+ selectedTableName: d
342
+ }),
343
+ lastSelectedSchema: a,
344
+ lastSelectedDatamodelId: n,
345
+ lastSelectedDatabase: i,
346
+ lastSelectedTable: d,
347
+ connectionId: c || e.connectionId,
348
+ sql: h ? o || e.sql : void 0,
349
+ python: h ? e.python : void 0,
350
+ config: r || !e.config ? void 0 : u(e.config),
351
+ customCfg: e.customCfg,
352
+ preferences: e.preferences,
353
+ customCardPreferences: Za(
354
+ e.customCardPreferences,
355
+ l
356
+ )
357
+ };
358
+ }
359
+ const tn = (e) => {
360
+ if (!e || !("detailTableBackup" in e))
361
+ return e;
362
+ const { detailTableBackup: r, ...o } = e;
363
+ return o;
364
+ };
365
+ async function Rt(e, r, o, a, n = "Opening library visual...") {
366
+ if (!r || !o)
367
+ throw new Error("Missing auth token or visual ID");
368
+ const i = ["resource-by-id", "visual", o], d = a.getQueryData(i);
369
+ if (d)
370
+ return console.log("Using cached visual data for:", o), { data: d, fromCache: !0 };
371
+ console.log("Fetching visual data from network for:", o);
372
+ const c = R.loading(n, {
373
+ position: "top-center"
374
+ });
375
+ try {
376
+ const l = await fetch(
377
+ `${e}/management/v1/visuals/${o}`,
378
+ {
379
+ headers: {
380
+ Authorization: `Bearer ${r}`
381
+ }
382
+ }
383
+ );
384
+ if (!l.ok)
385
+ throw new Error("Failed to load visual");
386
+ const u = await l.json();
387
+ return a.setQueryData(i, u), R.dismiss(c), { data: u, fromCache: !1 };
388
+ } catch (l) {
389
+ throw R.dismiss(c), l;
390
+ }
391
+ }
392
+ function tr(e) {
393
+ if (typeof e == "string")
394
+ return JSON.parse(e);
395
+ if (typeof e == "object")
396
+ return e;
397
+ throw new Error("Invalid frame object format");
398
+ }
399
+ function rn(e, r) {
400
+ var i, d;
401
+ const o = (e == null ? void 0 : e.frameObject) ?? ((i = e == null ? void 0 : e.visual) == null ? void 0 : i.frameObject);
402
+ if (!o)
403
+ return !1;
404
+ const a = tr(o);
405
+ if (!(a != null && a.cards) || a.cards.length === 0)
406
+ return !1;
407
+ const n = (d = a.cards) == null ? void 0 : d.find(
408
+ (c) => c.id === a.activeCardId
409
+ );
410
+ return n ? (Ar({
411
+ ...r,
412
+ frame: a,
413
+ card: n,
414
+ visualId: (e == null ? void 0 : e.id) || a.visualId
415
+ }), !0) : !1;
416
+ }
417
+ function an() {
418
+ const e = ee(
419
+ (a) => {
420
+ var n;
421
+ return ((n = a.card.customCardPreferences) == null ? void 0 : n.url) || "";
422
+ }
423
+ ), r = Xa(e);
424
+ return { getUpdatedFrame: j(() => {
425
+ var b;
426
+ La();
427
+ const {
428
+ frame: a,
429
+ card: n,
430
+ isDevMode: i,
431
+ selectedSchemaName: d,
432
+ selectedDatamodelId: c,
433
+ selectedDatabaseName: l,
434
+ selectedTableName: u,
435
+ selectedConnectionId: h
436
+ } = ee.getState(), p = n.sql, m = (b = r == null ? void 0 : r.getState()) == null ? void 0 : b.settings, g = en(n, {
437
+ isDevMode: i,
438
+ cardSql: p,
439
+ selectedSchemaName: d,
440
+ selectedDatamodelId: c,
441
+ selectedDatabaseName: l,
442
+ selectedTableName: u,
443
+ selectedConnectionId: h,
444
+ remoteChartSettings: m,
445
+ stripConfig: tn
446
+ }), f = a.cards.map(
447
+ (k) => k.id === n.id ? g : k
448
+ );
449
+ return {
450
+ ...a,
451
+ cards: f,
452
+ activeCardId: Ya(f, a.activeCardId)
453
+ };
454
+ }, [r]) };
455
+ }
456
+ function Ee() {
457
+ const { authToken: e, tokenProps: r } = Be(), o = et(), a = Dr(), n = tt(), { selectVisual: i } = mt(), {
458
+ setFrame: d,
459
+ setCard: c,
460
+ setIsDevMode: l,
461
+ initializeModeDrafts: u,
462
+ setActiveTabCardId: h,
463
+ updateDataSource: p,
464
+ setQueryResultColumns: m,
465
+ setSelectedConnectionId: g,
466
+ setSelectedDatabaseName: f,
467
+ setSelectedSchemaName: b,
468
+ setSelectedTableName: k,
469
+ setSelectedDatamodelId: v,
470
+ setFilterValues: D,
471
+ setInlineFilterValuesMap: E,
472
+ setApplyFilters: N,
473
+ clearEditorContext: y
474
+ } = Je(), {
475
+ setIsDashboardEditing: w,
476
+ setIsVisualEditing: S,
477
+ setSelectedFrameId: x,
478
+ clearSelectedFrameId: B
479
+ } = pe(), I = L((O) => O.selectedSheetId), W = L((O) => O.selectedFrameId), P = L((O) => O.dashboard), M = L((O) => O.filterValues), Z = L(
480
+ (O) => O.inlineFilterValuesMap
481
+ ), K = Er((n == null ? void 0 : n.id) || "", {
482
+ enabled: !!(n != null && n.id) && !!(e != null && e.accessToken)
483
+ }), Ce = j(
484
+ async (O) => {
485
+ try {
486
+ i(O), B(), y();
487
+ const { data: te, fromCache: re } = await Rt(
488
+ r.apiServiceUrl,
489
+ (e == null ? void 0 : e.accessToken) || "",
490
+ O.id,
491
+ o,
492
+ "Opening library visual..."
493
+ );
494
+ if (!rn(te, {
495
+ setFrame: d,
496
+ setCard: c,
497
+ setIsDevMode: l,
498
+ initializeModeDrafts: u,
499
+ setActiveTabCardId: h,
500
+ updateDataSource: p,
501
+ setQueryResultColumns: m,
502
+ setSelectedConnectionId: g,
503
+ setSelectedDatabaseName: f,
504
+ setSelectedSchemaName: b,
505
+ setSelectedTableName: k,
506
+ setSelectedDatamodelId: v,
507
+ setFilterValues: D,
508
+ setInlineFilterValuesMap: E,
509
+ setApplyFilters: N,
510
+ setIsDashboardEditing: w,
511
+ setIsVisualEditing: S,
512
+ dashboard: P,
513
+ selectedSheetId: I,
514
+ selectedFrameId: W,
515
+ filterValues: M,
516
+ inlineFilterValuesMap: Z
517
+ }))
518
+ throw new Error("Failed to setup editor with visual data");
519
+ return { success: !0, fromCache: re };
520
+ } catch (te) {
521
+ return console.error("Error editing visual:", te), { success: !1, error: "Failed to load visual for editing" };
522
+ }
523
+ },
524
+ [
525
+ e == null ? void 0 : e.accessToken,
526
+ r.apiServiceUrl,
527
+ o,
528
+ i,
529
+ d,
530
+ c,
531
+ w,
532
+ S,
533
+ l,
534
+ u,
535
+ h,
536
+ p,
537
+ m,
538
+ g,
539
+ f,
540
+ b,
541
+ k,
542
+ v,
543
+ D,
544
+ E,
545
+ N,
546
+ y,
547
+ B,
548
+ P,
549
+ I,
550
+ W,
551
+ M,
552
+ Z
553
+ ]
554
+ ), ce = j(
555
+ async (O) => {
556
+ var re;
557
+ const te = (T) => (R.error(T), { success: !1, error: T });
558
+ try {
559
+ if (i(O), !I)
560
+ return te("No sheet selected. Please select a sheet first.");
561
+ const { data: T, fromCache: ae } = await Rt(
562
+ r.apiServiceUrl,
563
+ (e == null ? void 0 : e.accessToken) || "",
564
+ O.id,
565
+ o,
566
+ "Adding visual to dashboard..."
567
+ ), le = (T == null ? void 0 : T.frameObject) ?? ((re = T == null ? void 0 : T.visual) == null ? void 0 : re.frameObject);
568
+ if (!le)
569
+ return te("Visual has no frame data");
570
+ const G = tr(le);
571
+ if (!(G != null && G.cards) || G.cards.length === 0)
572
+ return te("Visual frame is malformed");
573
+ const be = {
574
+ ...kr(G),
575
+ visualId: O.id
576
+ // Link this frame to the library visual
577
+ };
578
+ return await a(
579
+ I,
580
+ be,
581
+ "end"
582
+ ), w(!0), x(be.id), { success: !0, fromCache: ae };
583
+ } catch (T) {
584
+ return console.error("Error adding visual:", T), te(
585
+ T instanceof Error ? T.message : "Failed to add visual to dashboard"
586
+ );
587
+ }
588
+ },
589
+ [
590
+ e == null ? void 0 : e.accessToken,
591
+ r.apiServiceUrl,
592
+ o,
593
+ i,
594
+ I,
595
+ w,
596
+ x,
597
+ a
598
+ ]
599
+ );
600
+ return {
601
+ visual: K.data,
602
+ isLoading: K.isLoading,
603
+ isError: K.isError,
604
+ error: K.error,
605
+ handleEditLibraryVisual: Ce,
606
+ handleAddLibraryVisual: ce,
607
+ getUpdatedFrame: an().getUpdatedFrame,
608
+ refetch: K.refetch
609
+ };
610
+ }
611
+ function rr(e) {
612
+ return e ? new Date(e).toLocaleDateString("en-US", {
613
+ month: "short",
614
+ day: "numeric",
615
+ year: "numeric"
616
+ }) : "Unknown";
617
+ }
618
+ function ar(e, r) {
619
+ var a;
620
+ const o = (a = e.ownership.createdBy) == null ? void 0 : a.type;
621
+ return o === "tenant" || o === "organization" && r;
622
+ }
623
+ function Et(e, r) {
624
+ var o, a;
625
+ return ar(e, r) ? ((o = e.ownership.createdBy) == null ? void 0 : o.name) || ((a = e.createdByTenantUserRel) == null ? void 0 : a.name) || e.lastModifiedBy || "Unknown" : "Organization";
626
+ }
627
+ function nn(e, r) {
628
+ return Et(e, r).split(/\s+/).filter(Boolean).slice(0, 2).map((a) => a.charAt(0).toUpperCase()).join("") || "?";
629
+ }
630
+ function sn(e) {
631
+ const r = (e || "").toLowerCase();
632
+ return r.includes("table") ? Ot : r.includes("pie") || r.includes("donut") ? Rr : r.includes("line") ? Vr : r.includes("bar") ? fr : Dt;
633
+ }
634
+ function on({ visual: e }) {
635
+ const r = e.ownership.status === "public" ? "Public" : e.ownership.status === "shared" || e.ownership.sharedCount > 0 ? "Shared" : "Private";
636
+ return /* @__PURE__ */ t("span", { className: "inline-flex items-center rounded-[4px] border border-border/60 px-1.5 py-px text-[11px] text-muted-foreground", children: r });
637
+ }
638
+ function _s({
639
+ open: e,
640
+ onOpenChange: r
641
+ }) {
642
+ const o = ht("interactive"), [a, n] = F(""), [i, d] = F(/* @__PURE__ */ new Set()), [c, l] = F(!1), [u, h] = F(
643
+ null
644
+ ), [p, m] = F(
645
+ null
646
+ ), [g, f] = F(!1), [b, k] = F(null), [v, D] = F(null), E = () => {
647
+ d(/* @__PURE__ */ new Set()), h(null), m(null), f(!1), k(null);
648
+ }, N = () => {
649
+ r(!1), E();
650
+ }, { selectVisual: y } = mt(), { handleAddLibraryVisual: w, handleEditLibraryVisual: S } = Ee(), { isConsoleMode: x } = Ir(), {
651
+ resources: B,
652
+ isLoading: I,
653
+ isError: W,
654
+ createResource: P,
655
+ updateResource: M,
656
+ deleteResourceAsync: Z,
657
+ duplicateResource: K,
658
+ isCreating: Ce,
659
+ isDeleting: ce
660
+ } = Fr(
661
+ void 0,
662
+ (C) => {
663
+ l(!1), C && (y(C), S(C), N());
664
+ }
665
+ ), {
666
+ startUpdating: O,
667
+ stopUpdating: te,
668
+ isUpdating: re
669
+ } = Pr(), T = B, ae = oe(() => {
670
+ const C = a.trim().toLowerCase();
671
+ return C ? T.filter(
672
+ (V) => {
673
+ var z, de, fe;
674
+ return ((z = V.title) == null ? void 0 : z.toLowerCase().includes(C)) || ((de = V.description) == null ? void 0 : de.toLowerCase().includes(C)) || ((fe = V.kind) == null ? void 0 : fe.toLowerCase().includes(C));
675
+ }
676
+ ) : T;
677
+ }, [a, T]), le = oe(
678
+ () => T.filter(
679
+ (C) => i.has(C.id)
680
+ ),
681
+ [i, T]
682
+ ), G = le.filter(
683
+ (C) => C.permissions.canDelete
684
+ ), be = le.filter(
685
+ (C) => C.permissions.canShare
686
+ ), ke = ae.length > 0 && ae.every(
687
+ (C) => i.has(C.id)
688
+ ), ve = ae.some(
689
+ (C) => i.has(C.id)
690
+ ), we = (C) => {
691
+ const V = new Set(i);
692
+ C(V), d(V);
693
+ }, se = (C) => {
694
+ we((V) => {
695
+ V.has(C) ? V.delete(C) : V.add(C);
696
+ });
697
+ }, Ae = () => {
698
+ d((C) => {
699
+ const V = new Set(C);
700
+ return ke ? ae.forEach(
701
+ (z) => V.delete(z.id)
702
+ ) : ae.forEach(
703
+ (z) => V.add(z.id)
704
+ ), V;
705
+ });
706
+ }, q = async (C) => {
707
+ (await w(C)).success && N();
708
+ }, H = async () => {
709
+ const C = le;
710
+ if (C.length === 0) return;
711
+ let V = !1;
712
+ for (const z of C)
713
+ if (!(await w(z)).success) {
714
+ V = !0;
715
+ break;
716
+ }
717
+ V || N();
718
+ }, he = (C) => {
719
+ S(C), N();
720
+ }, Ne = (C) => {
721
+ D(C), K(C, {
722
+ onSettled: () => D(null)
723
+ });
724
+ }, _e = () => {
725
+ if (G.length === 0) {
726
+ R.error("Select a visual you can delete");
727
+ return;
728
+ }
729
+ k(null), f(!0);
730
+ }, st = async () => {
731
+ const C = b ? [b] : G;
732
+ try {
733
+ for (const V of C)
734
+ await Z(V.id);
735
+ d((V) => {
736
+ const z = new Set(V);
737
+ return C.forEach(
738
+ (de) => z.delete(de.id)
739
+ ), z;
740
+ }), f(!1), k(null);
741
+ } catch {
742
+ }
743
+ }, Ie = () => {
744
+ if (le.length !== 1) {
745
+ R.error("Select one visual to share");
746
+ return;
747
+ }
748
+ const [C] = le;
749
+ if (!C.permissions.canShare) {
750
+ R.error("You do not have permission to share this visual");
751
+ return;
752
+ }
753
+ h(C);
754
+ }, Fe = ({
755
+ title: C,
756
+ description: V
757
+ }) => {
758
+ if (!p) return;
759
+ const z = {};
760
+ if (C !== p.title && (z.title = C), (p.description || "") !== V && (z.description = V), Object.keys(z).length === 0) {
761
+ m(null);
762
+ return;
763
+ }
764
+ const de = Object.keys(z), fe = de.length === 1 ? de[0] : void 0;
765
+ O(p.id, fe), M(
766
+ {
767
+ resourceId: p.id,
768
+ data: z
769
+ },
770
+ {
771
+ onSuccess: () => {
772
+ te(p.id, fe), m(null);
773
+ },
774
+ onError: () => {
775
+ te(p.id, fe);
776
+ }
777
+ }
778
+ );
779
+ }, ne = (C) => {
780
+ r(C), C || E();
781
+ }, Pe = b ? 1 : G.length;
782
+ return /* @__PURE__ */ s($, { children: [
783
+ /* @__PURE__ */ t(Ue, { open: e, onOpenChange: ne, children: /* @__PURE__ */ s(
784
+ Re,
785
+ {
786
+ showCloseButton: !1,
787
+ className: "flex max-h-[80vh] w-[min(72rem,calc(100vw-2rem))] max-w-none grid-cols-none flex-col gap-0 overflow-hidden rounded-card border-border/60 p-0 shadow-lg sm:rounded-card",
788
+ style: o.dialogStyle,
789
+ children: [
790
+ /* @__PURE__ */ s("div", { className: "flex h-10 shrink-0 items-center justify-between gap-2 border-b border-border/60 px-3", children: [
791
+ /* @__PURE__ */ s("div", { className: "flex min-w-0 items-center gap-2", children: [
792
+ /* @__PURE__ */ t(Ot, { className: "h-3.5 w-3.5 shrink-0 text-muted-foreground" }),
793
+ /* @__PURE__ */ s("div", { className: "flex min-w-0 items-baseline gap-2", children: [
794
+ /* @__PURE__ */ t(Ve, { className: "truncate text-[13px] font-medium leading-none tracking-normal", children: "Visuals library" }),
795
+ /* @__PURE__ */ t("span", { className: "shrink-0 text-[10px] font-medium uppercase leading-none tracking-[0.08em] text-muted-foreground", children: "Add to dashboard" })
796
+ ] })
797
+ ] }),
798
+ /* @__PURE__ */ t(
799
+ U,
800
+ {
801
+ size: "xs",
802
+ variant: "ghost",
803
+ className: "w-7 px-0 text-muted-foreground hover:text-foreground",
804
+ onClick: () => ne(!1),
805
+ "aria-label": "Close visuals library",
806
+ children: "×"
807
+ }
808
+ )
809
+ ] }),
810
+ /* @__PURE__ */ s("div", { className: "flex shrink-0 items-center gap-2 border-b border-border/60 px-3 py-2", children: [
811
+ /* @__PURE__ */ s("div", { className: "relative min-w-[12rem] flex-1 md:max-w-md", children: [
812
+ /* @__PURE__ */ t(Pa, { className: "pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground" }),
813
+ /* @__PURE__ */ t(
814
+ "input",
815
+ {
816
+ autoFocus: !0,
817
+ value: a,
818
+ onChange: (C) => n(C.target.value),
819
+ placeholder: "Search visuals...",
820
+ className: "h-7 w-full rounded-control border border-input bg-background pl-7 pr-2 text-[12px] text-foreground placeholder:text-muted-foreground focus:border-ring focus:outline-none",
821
+ "aria-label": "Search visuals"
822
+ }
823
+ )
824
+ ] }),
825
+ /* @__PURE__ */ s(
826
+ U,
827
+ {
828
+ size: "xs",
829
+ variant: "outline",
830
+ className: "ml-auto",
831
+ onClick: () => l(!0),
832
+ children: [
833
+ /* @__PURE__ */ t(Se, { className: "h-3.5 w-3.5" }),
834
+ "New library visual"
835
+ ]
836
+ }
837
+ )
838
+ ] }),
839
+ /* @__PURE__ */ t("div", { className: "min-h-0 flex-1 overflow-auto", children: I ? /* @__PURE__ */ t("div", { className: "p-3", children: /* @__PURE__ */ t(Ga, {}) }) : W ? /* @__PURE__ */ t("div", { className: "flex flex-col items-center gap-2 px-4 py-12 text-center", children: /* @__PURE__ */ t("p", { className: "text-[13px] text-destructive", children: "Failed to load visuals" }) }) : ae.length === 0 ? /* @__PURE__ */ s("div", { className: "flex flex-col items-center gap-2 px-4 py-12 text-center", children: [
840
+ /* @__PURE__ */ t(Dt, { className: "h-5 w-5 text-muted-foreground/60" }),
841
+ /* @__PURE__ */ t("p", { className: "text-[13px] font-medium", children: a ? "No visuals found" : "No visuals yet" }),
842
+ /* @__PURE__ */ t("p", { className: "text-[12px] text-muted-foreground", children: a ? "Try a different search." : "Create a saved visual to add it here." })
843
+ ] }) : /* @__PURE__ */ t(
844
+ ln,
845
+ {
846
+ visuals: ae,
847
+ selectedIds: i,
848
+ allFilteredSelected: ke,
849
+ someFilteredSelected: ve,
850
+ onSelectAll: Ae,
851
+ onToggleSelection: se,
852
+ onAddVisual: q,
853
+ onOpenVisual: he,
854
+ onEditDetails: m,
855
+ onShareVisual: h,
856
+ onDeleteVisual: (C) => {
857
+ k(C), f(!0);
858
+ },
859
+ onDuplicateVisual: Ne,
860
+ duplicatingId: v,
861
+ isDeleting: ce,
862
+ isConsoleMode: x
863
+ }
864
+ ) }),
865
+ /* @__PURE__ */ s("div", { className: "flex shrink-0 items-center justify-between gap-2 border-t border-border/60 px-3 py-2", children: [
866
+ /* @__PURE__ */ t("div", { className: "flex min-w-0 items-center gap-1.5", children: i.size > 0 && /* @__PURE__ */ s($, { children: [
867
+ /* @__PURE__ */ s("span", { className: "text-[12px] text-muted-foreground", children: [
868
+ /* @__PURE__ */ t("span", { className: "font-medium tabular-nums text-foreground", children: i.size }),
869
+ " ",
870
+ "selected"
871
+ ] }),
872
+ /* @__PURE__ */ t(
873
+ U,
874
+ {
875
+ size: "xs",
876
+ variant: "ghost",
877
+ onClick: () => d(/* @__PURE__ */ new Set()),
878
+ children: "Clear"
879
+ }
880
+ ),
881
+ /* @__PURE__ */ s(
882
+ U,
883
+ {
884
+ size: "xs",
885
+ variant: "outline",
886
+ onClick: Ie,
887
+ disabled: le.length !== 1 || be.length !== 1,
888
+ children: [
889
+ /* @__PURE__ */ t(zt, { className: "h-3.5 w-3.5" }),
890
+ "Share"
891
+ ]
892
+ }
893
+ ),
894
+ /* @__PURE__ */ s(
895
+ U,
896
+ {
897
+ size: "xs",
898
+ variant: "outline",
899
+ className: "text-destructive hover:text-destructive",
900
+ onClick: _e,
901
+ disabled: G.length === 0,
902
+ children: [
903
+ /* @__PURE__ */ t(Ke, { className: "h-3.5 w-3.5" }),
904
+ "Delete ",
905
+ G.length || i.size
906
+ ]
907
+ }
908
+ )
909
+ ] }) }),
910
+ /* @__PURE__ */ s("div", { className: "flex items-center gap-2", children: [
911
+ /* @__PURE__ */ t(
912
+ U,
913
+ {
914
+ size: "xs",
915
+ variant: "outline",
916
+ onClick: () => ne(!1),
917
+ children: "Close"
918
+ }
919
+ ),
920
+ /* @__PURE__ */ s(
921
+ U,
922
+ {
923
+ size: "xs",
924
+ onClick: H,
925
+ disabled: i.size === 0,
926
+ children: [
927
+ /* @__PURE__ */ t(ut, { className: "h-3.5 w-3.5" }),
928
+ i.size === 0 ? "Add to dashboard" : `Add ${i.size} visual${i.size === 1 ? "" : "s"}`
929
+ ]
930
+ }
931
+ )
932
+ ] })
933
+ ] })
934
+ ]
935
+ }
936
+ ) }),
937
+ /* @__PURE__ */ t(
938
+ Ka,
939
+ {
940
+ open: c,
941
+ onOpenChange: l,
942
+ onSubmit: P,
943
+ isCreating: Ce
944
+ }
945
+ ),
946
+ u && /* @__PURE__ */ t(
947
+ Lr,
948
+ {
949
+ resource: u,
950
+ resourceType: Tr.VISUAL,
951
+ onClose: () => h(null)
952
+ }
953
+ ),
954
+ p && /* @__PURE__ */ t(
955
+ Ur,
956
+ {
957
+ open: !!p,
958
+ resourceLabel: "Visual",
959
+ initialTitle: p.title || "",
960
+ initialDescription: p.description || "",
961
+ onClose: () => m(null),
962
+ onSave: Fe,
963
+ isSaving: re(p.id)
964
+ }
965
+ ),
966
+ /* @__PURE__ */ t(
967
+ pt,
968
+ {
969
+ open: g,
970
+ onOpenChange: (C) => {
971
+ !C && ce || (f(C), C || k(null));
972
+ },
973
+ children: /* @__PURE__ */ s(ft, { children: [
974
+ /* @__PURE__ */ s(gt, { children: [
975
+ /* @__PURE__ */ s(bt, { children: [
976
+ "Delete ",
977
+ Pe,
978
+ " visual",
979
+ Pe === 1 ? "" : "s",
980
+ "?"
981
+ ] }),
982
+ /* @__PURE__ */ t(vt, { children: "This cannot be undone. Visuals already added to dashboards may need to be removed from those dashboards separately." })
983
+ ] }),
984
+ /* @__PURE__ */ s(xt, { children: [
985
+ /* @__PURE__ */ t(yt, { disabled: ce, children: "Cancel" }),
986
+ /* @__PURE__ */ s(
987
+ jt,
988
+ {
989
+ onClick: (C) => {
990
+ C.preventDefault(), st();
991
+ },
992
+ disabled: ce || Pe === 0,
993
+ children: [
994
+ ce ? /* @__PURE__ */ t(ie, { className: "h-3.5 w-3.5 animate-spin" }) : /* @__PURE__ */ t(Ke, { className: "h-3.5 w-3.5" }),
995
+ ce ? "Deleting..." : "Delete"
996
+ ]
997
+ }
998
+ )
999
+ ] })
1000
+ ] })
1001
+ }
1002
+ )
1003
+ ] });
1004
+ }
1005
+ function ln({
1006
+ visuals: e,
1007
+ selectedIds: r,
1008
+ allFilteredSelected: o,
1009
+ someFilteredSelected: a,
1010
+ onSelectAll: n,
1011
+ onToggleSelection: i,
1012
+ onAddVisual: d,
1013
+ onOpenVisual: c,
1014
+ onEditDetails: l,
1015
+ onShareVisual: u,
1016
+ onDeleteVisual: h,
1017
+ onDuplicateVisual: p,
1018
+ duplicatingId: m,
1019
+ isDeleting: g,
1020
+ isConsoleMode: f
1021
+ }) {
1022
+ return /* @__PURE__ */ s("div", { className: "min-w-[48rem]", children: [
1023
+ /* @__PURE__ */ s("div", { className: "grid h-9 grid-cols-[2.5rem_minmax(14rem,1.8fr)_minmax(10rem,1fr)_8rem_7rem_5rem_5.5rem] items-center border-b border-border/60 px-3 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: [
1024
+ /* @__PURE__ */ t(
1025
+ Ct,
1026
+ {
1027
+ checked: o ? !0 : a ? "indeterminate" : !1,
1028
+ onCheckedChange: n,
1029
+ "aria-label": "Select all visuals"
1030
+ }
1031
+ ),
1032
+ /* @__PURE__ */ t("span", { children: "Name" }),
1033
+ /* @__PURE__ */ t("span", { children: "Created by" }),
1034
+ /* @__PURE__ */ t("span", { children: "Updated" }),
1035
+ /* @__PURE__ */ t("span", { children: "Visibility" }),
1036
+ /* @__PURE__ */ t("span", { className: "text-right", children: "Shared" }),
1037
+ /* @__PURE__ */ t("span", { className: "text-right", children: "Actions" })
1038
+ ] }),
1039
+ e.map((b) => /* @__PURE__ */ t(
1040
+ cn,
1041
+ {
1042
+ visual: b,
1043
+ selected: r.has(b.id),
1044
+ onToggleSelection: i,
1045
+ onAddVisual: d,
1046
+ onOpenVisual: c,
1047
+ onEditDetails: l,
1048
+ onShareVisual: u,
1049
+ onDeleteVisual: h,
1050
+ onDuplicateVisual: p,
1051
+ duplicatingId: m,
1052
+ isDeleting: g,
1053
+ isConsoleMode: f
1054
+ },
1055
+ b.id
1056
+ ))
1057
+ ] });
1058
+ }
1059
+ function cn({
1060
+ visual: e,
1061
+ selected: r,
1062
+ onToggleSelection: o,
1063
+ onAddVisual: a,
1064
+ onOpenVisual: n,
1065
+ onEditDetails: i,
1066
+ onShareVisual: d,
1067
+ onDeleteVisual: c,
1068
+ onDuplicateVisual: l,
1069
+ duplicatingId: u,
1070
+ isDeleting: h,
1071
+ isConsoleMode: p
1072
+ }) {
1073
+ var f;
1074
+ const m = sn(e.kind), g = () => {
1075
+ a(e);
1076
+ };
1077
+ return /* @__PURE__ */ s(
1078
+ "div",
1079
+ {
1080
+ className: X(
1081
+ "group grid min-h-12 grid-cols-[2.5rem_minmax(14rem,1.8fr)_minmax(10rem,1fr)_8rem_7rem_5rem_5.5rem] items-center border-b border-border/50 px-3 text-[13px] hover:bg-muted/50",
1082
+ r && "bg-muted/70"
1083
+ ),
1084
+ children: [
1085
+ /* @__PURE__ */ t("div", { children: /* @__PURE__ */ t(
1086
+ Ct,
1087
+ {
1088
+ checked: r,
1089
+ onCheckedChange: () => o(e.id),
1090
+ "aria-label": `Select ${e.title || "visual"}`
1091
+ }
1092
+ ) }),
1093
+ /* @__PURE__ */ s(
1094
+ "button",
1095
+ {
1096
+ type: "button",
1097
+ className: "flex min-w-0 items-center gap-2 rounded-[4px] text-left outline-none focus-visible:ring-1 focus-visible:ring-ring",
1098
+ onClick: g,
1099
+ "aria-label": `Add ${e.title || "visual"} to dashboard`,
1100
+ children: [
1101
+ /* @__PURE__ */ t(m, { className: "h-3.5 w-3.5 shrink-0 text-muted-foreground" }),
1102
+ /* @__PURE__ */ s("div", { className: "min-w-0", children: [
1103
+ /* @__PURE__ */ t(
1104
+ "div",
1105
+ {
1106
+ className: "truncate font-medium text-foreground",
1107
+ title: e.title || "Untitled Visual",
1108
+ children: e.title || "Untitled Visual"
1109
+ }
1110
+ ),
1111
+ ((f = e.description) == null ? void 0 : f.trim()) && /* @__PURE__ */ t(
1112
+ "div",
1113
+ {
1114
+ className: "truncate text-[11px] text-muted-foreground",
1115
+ title: e.description,
1116
+ children: e.description
1117
+ }
1118
+ )
1119
+ ] })
1120
+ ]
1121
+ }
1122
+ ),
1123
+ /* @__PURE__ */ s("div", { className: "flex min-w-0 items-center gap-2", children: [
1124
+ /* @__PURE__ */ t("div", { className: "flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-muted text-[9px] font-medium text-muted-foreground", children: nn(e, p) }),
1125
+ /* @__PURE__ */ t("span", { className: "truncate text-muted-foreground", children: Et(e, p) })
1126
+ ] }),
1127
+ /* @__PURE__ */ t("span", { className: "text-muted-foreground", children: rr(e.updatedAt) }),
1128
+ /* @__PURE__ */ t(on, { visual: e }),
1129
+ /* @__PURE__ */ t("span", { className: "text-right tabular-nums text-muted-foreground", children: e.ownership.sharedCount > 0 ? e.ownership.sharedCount : "—" }),
1130
+ /* @__PURE__ */ t(
1131
+ dn,
1132
+ {
1133
+ visual: e,
1134
+ onOpenVisual: n,
1135
+ onEditDetails: i,
1136
+ onShareVisual: d,
1137
+ onDeleteVisual: c,
1138
+ onDuplicateVisual: l,
1139
+ duplicatingId: u,
1140
+ isDeleting: h,
1141
+ isConsoleMode: p
1142
+ }
1143
+ )
1144
+ ]
1145
+ }
1146
+ );
1147
+ }
1148
+ function dn({
1149
+ visual: e,
1150
+ onOpenVisual: r,
1151
+ onEditDetails: o,
1152
+ onShareVisual: a,
1153
+ onDeleteVisual: n,
1154
+ onDuplicateVisual: i,
1155
+ duplicatingId: d,
1156
+ isDeleting: c,
1157
+ isConsoleMode: l
1158
+ }) {
1159
+ return /* @__PURE__ */ s(
1160
+ "div",
1161
+ {
1162
+ className: "flex items-center justify-end gap-0.5 opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100",
1163
+ onClick: (u) => u.stopPropagation(),
1164
+ children: [
1165
+ /* @__PURE__ */ t(
1166
+ U,
1167
+ {
1168
+ size: "xs",
1169
+ variant: "ghost",
1170
+ className: "w-7 px-0",
1171
+ onClick: () => r(e),
1172
+ "aria-label": "Edit visual",
1173
+ children: /* @__PURE__ */ t(ot, { className: "h-3.5 w-3.5" })
1174
+ }
1175
+ ),
1176
+ /* @__PURE__ */ s(rt, { modal: !1, children: [
1177
+ /* @__PURE__ */ t(at, { asChild: !0, children: /* @__PURE__ */ t(
1178
+ U,
1179
+ {
1180
+ size: "xs",
1181
+ variant: "ghost",
1182
+ className: "w-7 px-0",
1183
+ "aria-label": "More actions",
1184
+ children: /* @__PURE__ */ t(Wt, { className: "h-3.5 w-3.5" })
1185
+ }
1186
+ ) }),
1187
+ /* @__PURE__ */ s(
1188
+ nt,
1189
+ {
1190
+ align: "end",
1191
+ className: "z-[60] w-44 rounded-[6px] border-border/60 p-1 shadow-sm",
1192
+ children: [
1193
+ /* @__PURE__ */ s(Y, { onClick: () => r(e), children: [
1194
+ /* @__PURE__ */ t(ot, { className: "h-3.5 w-3.5" }),
1195
+ "Edit visual"
1196
+ ] }),
1197
+ /* @__PURE__ */ s(
1198
+ Y,
1199
+ {
1200
+ onClick: () => i(e.id),
1201
+ disabled: d === e.id,
1202
+ children: [
1203
+ d === e.id ? /* @__PURE__ */ t(ie, { className: "h-3.5 w-3.5 animate-spin" }) : /* @__PURE__ */ t(Br, { className: "h-3.5 w-3.5" }),
1204
+ d === e.id ? "Duplicating..." : "Duplicate"
1205
+ ]
1206
+ }
1207
+ ),
1208
+ e.permissions.canEdit && /* @__PURE__ */ s(Y, { onClick: () => o(e), children: [
1209
+ /* @__PURE__ */ t(ot, { className: "h-3.5 w-3.5" }),
1210
+ "Edit details"
1211
+ ] }),
1212
+ e.permissions.canShare && /* @__PURE__ */ s(Y, { onClick: () => a(e), children: [
1213
+ /* @__PURE__ */ t(zt, { className: "h-3.5 w-3.5" }),
1214
+ "Share"
1215
+ ] }),
1216
+ e.permissions.canDelete && /* @__PURE__ */ s($, { children: [
1217
+ /* @__PURE__ */ t(Xe, {}),
1218
+ /* @__PURE__ */ s(
1219
+ Y,
1220
+ {
1221
+ className: "text-destructive focus:bg-destructive/10 focus:text-destructive",
1222
+ onClick: () => n(e),
1223
+ disabled: c,
1224
+ children: [
1225
+ /* @__PURE__ */ t(Ke, { className: "h-3.5 w-3.5" }),
1226
+ c ? "Deleting..." : "Delete"
1227
+ ]
1228
+ }
1229
+ )
1230
+ ] }),
1231
+ /* @__PURE__ */ t(Xe, {}),
1232
+ /* @__PURE__ */ s("div", { className: "space-y-1 px-2 py-1.5 text-[11px] text-muted-foreground", children: [
1233
+ ar(e, l) && /* @__PURE__ */ s("div", { className: "flex items-center gap-1.5", children: [
1234
+ /* @__PURE__ */ t(Mr, { className: "h-3 w-3" }),
1235
+ /* @__PURE__ */ t("span", { className: "truncate", children: Et(e, l) })
1236
+ ] }),
1237
+ /* @__PURE__ */ s("div", { className: "flex items-center gap-1.5", children: [
1238
+ /* @__PURE__ */ t(_r, { className: "h-3 w-3" }),
1239
+ /* @__PURE__ */ t("span", { children: rr(e.updatedAt) })
1240
+ ] })
1241
+ ] })
1242
+ ]
1243
+ }
1244
+ )
1245
+ ] })
1246
+ ]
1247
+ }
1248
+ );
1249
+ }
1250
+ function Os(e, r, o = !1) {
1251
+ const a = L((u) => u.dashboard), n = L(
1252
+ (u) => u.isDashboardEditing
1253
+ ), i = L(
1254
+ (u) => u.onDashboardLifecycleEvent
1255
+ ), d = j(() => {
1256
+ const u = L.getState().dashboard;
1257
+ return r || !e || !u || u.id !== e.id ? !1 : je(u) !== je(e);
1258
+ }, [e, r]);
1259
+ Pt(() => (L.setState({ checkUnsavedDashboardChanges: d }), () => {
1260
+ L.getState().checkUnsavedDashboardChanges === d && L.setState({ checkUnsavedDashboardChanges: null });
1261
+ }), [d]);
1262
+ const c = oe(() => !o || r || !a || n && (!e || a.id !== e.id) ? null : {
1263
+ dashboardId: a.id,
1264
+ dirty: n && e ? je(a) !== je(e) : !1
1265
+ }, [
1266
+ n,
1267
+ r,
1268
+ o,
1269
+ e,
1270
+ a
1271
+ ]), l = ge(null);
1272
+ return Pt(() => {
1273
+ if (!i || !c) {
1274
+ l.current = null;
1275
+ return;
1276
+ }
1277
+ const u = l.current;
1278
+ (u == null ? void 0 : u.callback) === i && u.dashboardId === c.dashboardId && u.dirty === c.dirty || (l.current = {
1279
+ callback: i,
1280
+ dashboardId: c.dashboardId,
1281
+ dirty: c.dirty
1282
+ }, i({
1283
+ type: "dashboard:dirty-state",
1284
+ dashboardId: c.dashboardId,
1285
+ payload: { dirty: c.dirty }
1286
+ }));
1287
+ }, [c, i]), d;
1288
+ }
1289
+ function un({
1290
+ open: e,
1291
+ onOpenChange: r,
1292
+ isLibraryVisual: o,
1293
+ currentVisualName: a,
1294
+ isSaving: n = !1,
1295
+ destinationMode: i = "both",
1296
+ onConfirm: d
1297
+ }) {
1298
+ const [c, l] = F(
1299
+ o && a ? `Copy of ${a}` : a || ""
1300
+ ), [u, h] = F("");
1301
+ _t.useEffect(() => {
1302
+ e && (l(
1303
+ o && a ? `Copy of ${a}` : a || ""
1304
+ ), h(""));
1305
+ }, [e, o, a]);
1306
+ const p = !!c.trim(), m = i === "local" ? {
1307
+ saveToLibrary: !1,
1308
+ saveToCurrentDashboard: !0,
1309
+ badgeType: "local",
1310
+ description: "Creates a local copy on the current dashboard.",
1311
+ actionLabel: "Add to Dashboard (Local)"
1312
+ } : i === "library" ? {
1313
+ saveToLibrary: !0,
1314
+ saveToCurrentDashboard: !1,
1315
+ badgeType: "library",
1316
+ description: "Creates a reusable visual in Visual Library.",
1317
+ actionLabel: "Save as Library Visual"
1318
+ } : {
1319
+ saveToLibrary: !0,
1320
+ saveToCurrentDashboard: !0,
1321
+ badgeType: "linked",
1322
+ description: "Creates a new library visual and adds a linked copy to this dashboard.",
1323
+ actionLabel: "Save Copy as Linked Visual"
1324
+ }, g = () => {
1325
+ !p || n || d({
1326
+ name: c.trim(),
1327
+ description: u.trim() || void 0,
1328
+ saveToLibrary: m.saveToLibrary,
1329
+ saveToCurrentDashboard: m.saveToCurrentDashboard
1330
+ });
1331
+ };
1332
+ return /* @__PURE__ */ t(Ue, { open: e, onOpenChange: r, children: /* @__PURE__ */ s(Re, { className: "sm:max-w-[500px]", children: [
1333
+ /* @__PURE__ */ s(wt, { children: [
1334
+ /* @__PURE__ */ s(Ve, { className: "flex items-center gap-2", children: [
1335
+ /* @__PURE__ */ t("span", { children: "Save Visual As" }),
1336
+ m.badgeType !== "local" && /* @__PURE__ */ t(
1337
+ Ta,
1338
+ {
1339
+ type: m.badgeType,
1340
+ showLabel: !0,
1341
+ className: "px-2 py-0.5"
1342
+ }
1343
+ )
1344
+ ] }),
1345
+ /* @__PURE__ */ t(Nt, { children: m.description })
1346
+ ] }),
1347
+ /* @__PURE__ */ s("div", { className: "grid gap-4 py-4", children: [
1348
+ /* @__PURE__ */ s("div", { className: "grid gap-2", children: [
1349
+ /* @__PURE__ */ t(Te, { htmlFor: "name", children: "Name" }),
1350
+ /* @__PURE__ */ t(
1351
+ dt,
1352
+ {
1353
+ id: "name",
1354
+ value: c,
1355
+ onChange: (f) => l(f.target.value),
1356
+ placeholder: "Enter visual name",
1357
+ disabled: n
1358
+ }
1359
+ )
1360
+ ] }),
1361
+ /* @__PURE__ */ s("div", { className: "grid gap-2", children: [
1362
+ /* @__PURE__ */ t(Te, { htmlFor: "description", children: "Description (optional)" }),
1363
+ /* @__PURE__ */ t(
1364
+ Or,
1365
+ {
1366
+ id: "description",
1367
+ value: u,
1368
+ onChange: (f) => h(f.target.value),
1369
+ placeholder: "Enter visual description",
1370
+ rows: 3,
1371
+ disabled: n
1372
+ }
1373
+ )
1374
+ ] })
1375
+ ] }),
1376
+ /* @__PURE__ */ s($r, { children: [
1377
+ /* @__PURE__ */ t(
1378
+ U,
1379
+ {
1380
+ variant: "outline",
1381
+ onClick: () => r(!1),
1382
+ disabled: n,
1383
+ children: "Cancel"
1384
+ }
1385
+ ),
1386
+ /* @__PURE__ */ s(U, { onClick: g, disabled: !p || n, children: [
1387
+ n && /* @__PURE__ */ t(ie, { className: "mr-2 h-4 w-4 animate-spin" }),
1388
+ m.actionLabel
1389
+ ] })
1390
+ ] })
1391
+ ] }) });
1392
+ }
1393
+ function kt(e) {
1394
+ var r;
1395
+ for (const o of e.cards)
1396
+ if (o.type === "matrixTable" && !Fa.safeParse((r = o.config) == null ? void 0 : r.matrix).success)
1397
+ return R.error("Matrix requires at least one row field, one metric, and valid settings."), !1;
1398
+ return !0;
1399
+ }
1400
+ function it({
1401
+ className: e,
1402
+ variant: r = "outline"
1403
+ }) {
1404
+ const o = ee((i) => i.onSave), { getUpdatedFrame: a } = Ee();
1405
+ function n() {
1406
+ const i = a();
1407
+ kt(i) && (o == null || o(i));
1408
+ }
1409
+ return /* @__PURE__ */ s(
1410
+ U,
1411
+ {
1412
+ onClick: n,
1413
+ className: e,
1414
+ size: "xs",
1415
+ variant: r,
1416
+ children: [
1417
+ /* @__PURE__ */ t(ut, { className: "h-3.5 w-3.5" }),
1418
+ "Done"
1419
+ ]
1420
+ }
1421
+ );
1422
+ }
1423
+ function hn({
1424
+ className: e,
1425
+ variant: r = "default"
1426
+ }) {
1427
+ const o = et(), [a, n] = F(!1), { setIsVisualEditing: i } = pe(), { getUpdatedFrame: d } = Ee(), c = tt(), l = ee((p) => p.frame), u = qt();
1428
+ return /* @__PURE__ */ t(
1429
+ U,
1430
+ {
1431
+ onClick: () => {
1432
+ const p = d();
1433
+ if (!kt(p))
1434
+ return;
1435
+ const m = (l == null ? void 0 : l.visualId) || (c == null ? void 0 : c.id);
1436
+ if (!m) {
1437
+ R.error("No visual to save");
1438
+ return;
1439
+ }
1440
+ n(!0), u.mutate(
1441
+ {
1442
+ visualId: m,
1443
+ data: {
1444
+ frameObject: p
1445
+ }
1446
+ },
1447
+ {
1448
+ onSuccess: () => {
1449
+ n(!1), R.success("Visual updated successfully"), o.invalidateQueries({
1450
+ queryKey: ["resource-by-id", "visual", m],
1451
+ exact: !0
1452
+ });
1453
+ },
1454
+ onError: () => {
1455
+ n(!1), R.error("Failed to update visual");
1456
+ }
1457
+ }
1458
+ );
1459
+ },
1460
+ className: e,
1461
+ size: "xs",
1462
+ variant: r,
1463
+ children: a ? /* @__PURE__ */ s($, { children: [
1464
+ /* @__PURE__ */ t(ie, { className: "h-3.5 w-3.5 animate-spin" }),
1465
+ "Saving"
1466
+ ] }) : /* @__PURE__ */ s($, { children: [
1467
+ /* @__PURE__ */ t(Yt, { className: "h-3.5 w-3.5" }),
1468
+ "Save to Library"
1469
+ ] })
1470
+ }
1471
+ );
1472
+ }
1473
+ function mn({
1474
+ className: e
1475
+ }) {
1476
+ const r = et(), [o, a] = F(!1), n = tt(), i = ee((f) => f.frame), d = L((f) => f.selectedSheetId), c = L((f) => f.dashboard), { updateFrame: l, setIsVisualEditing: u } = pe(), { getUpdatedFrame: h } = Ee(), p = qt(), m = St();
1477
+ return /* @__PURE__ */ t(
1478
+ U,
1479
+ {
1480
+ onClick: async () => {
1481
+ if (!d) {
1482
+ R.error("No sheet selected");
1483
+ return;
1484
+ }
1485
+ const f = (i == null ? void 0 : i.visualId) || (n == null ? void 0 : n.id);
1486
+ if (!f) {
1487
+ R.error("No visual to update");
1488
+ return;
1489
+ }
1490
+ a(!0);
1491
+ try {
1492
+ const b = h();
1493
+ if (!kt(b)) {
1494
+ a(!1);
1495
+ return;
1496
+ }
1497
+ const k = {
1498
+ ...b,
1499
+ visualId: f
1500
+ // Keep the link to library visual
1501
+ }, v = qe(c, k.id), D = await m(k, {
1502
+ previousFrame: v
1503
+ });
1504
+ await p.mutateAsync({
1505
+ visualId: f,
1506
+ data: {
1507
+ frameObject: b
1508
+ }
1509
+ }), l(d, k, {
1510
+ semanticExecutionPayload: D
1511
+ }), r.invalidateQueries({ queryKey: ["visuals"] }), r.invalidateQueries({ queryKey: ["visual", f] }), R.success("Saved to library and applied locally"), setTimeout(() => {
1512
+ u(!1);
1513
+ }, 300);
1514
+ } catch (b) {
1515
+ console.error("Failed to save and apply:", b), R.error(
1516
+ b instanceof Error ? b.message : "Failed to save and apply changes"
1517
+ );
1518
+ } finally {
1519
+ a(!1);
1520
+ }
1521
+ },
1522
+ className: e,
1523
+ size: "xs",
1524
+ variant: "default",
1525
+ disabled: o,
1526
+ children: o ? /* @__PURE__ */ s($, { children: [
1527
+ /* @__PURE__ */ t(ie, { className: "h-3.5 w-3.5 animate-spin" }),
1528
+ "Saving..."
1529
+ ] }) : /* @__PURE__ */ s($, { children: [
1530
+ /* @__PURE__ */ t(Yt, { className: "h-3.5 w-3.5" }),
1531
+ "Save & Apply"
1532
+ ] })
1533
+ }
1534
+ );
1535
+ }
1536
+ function lt({ className: e }) {
1537
+ const { setTempQueryData: r, setSqlGen: o } = Je(), a = et(), n = ee((c) => c.tempQueryData), i = ee((c) => c.onClose);
1538
+ function d() {
1539
+ if (n) {
1540
+ const { queryKey: c, queryData: l } = n;
1541
+ c && l && a.setQueryData(c, l);
1542
+ }
1543
+ o({}), i == null || i();
1544
+ }
1545
+ return /* @__PURE__ */ s(
1546
+ U,
1547
+ {
1548
+ onClick: d,
1549
+ className: e,
1550
+ size: "xs",
1551
+ variant: "outline",
1552
+ children: [
1553
+ /* @__PURE__ */ t(Me, { className: "h-3.5 w-3.5" }),
1554
+ "Close"
1555
+ ]
1556
+ }
1557
+ );
1558
+ }
1559
+ function pn() {
1560
+ const [e, r] = F(!1), [o, a] = F(!1), [n, i] = F(null), [d, c] = F(null), l = ee((S) => S.frame), u = ee((S) => S.card), h = tt(), p = L((S) => S.selectedSheetId), m = L((S) => S.dashboard), { getUpdatedFrame: g } = Ee(), { selectVisual: f } = mt(), { addFrame: b, setSelectedFrameId: k, setIsVisualEditing: v } = pe(), D = St(), E = !!(l != null && l.visualId), N = (() => {
1561
+ var S, x;
1562
+ return ((S = l == null ? void 0 : l.cards) == null ? void 0 : S.length) === 1 && ((x = l.cards[0]) != null && x.title) ? l.cards[0].title : h != null && h.title ? h.title : (u == null ? void 0 : u.title) || "Untitled Visual";
1563
+ })(), y = zr((S) => {
1564
+ S != null && S.id && (f(S), o && n && d && p && (async () => {
1565
+ try {
1566
+ const x = {
1567
+ ...n,
1568
+ id: Tt(),
1569
+ visualId: S.id
1570
+ // Link to the newly created library visual
1571
+ };
1572
+ b(p, x, {
1573
+ position: "end",
1574
+ semanticExecutionPayload: d
1575
+ }), k(x.id), a(!1), i(null), c(null), v(!1);
1576
+ } catch (x) {
1577
+ console.error(
1578
+ "Failed to promote semantic metadata for saved visual:",
1579
+ x
1580
+ ), R.error(
1581
+ x instanceof Error ? x.message : "Failed to prepare semantic metadata for the saved visual"
1582
+ );
1583
+ }
1584
+ })(), r(!1));
1585
+ });
1586
+ return {
1587
+ saveAsDialogOpen: e,
1588
+ setSaveAsDialogOpen: r,
1589
+ handleSaveAs: async (S) => {
1590
+ if (!p) {
1591
+ R.error("No sheet selected");
1592
+ return;
1593
+ }
1594
+ const x = g(), I = x.cards.length === 1 ? {
1595
+ ...x,
1596
+ cards: x.cards.map((W) => ({
1597
+ ...W,
1598
+ title: S.name
1599
+ // Use visual name as card title
1600
+ }))
1601
+ } : x;
1602
+ if (S.saveToLibrary) {
1603
+ let W = null;
1604
+ if (S.saveToCurrentDashboard)
1605
+ try {
1606
+ W = await D(I, {
1607
+ previousFrame: qe(m, I.id)
1608
+ });
1609
+ } catch (M) {
1610
+ console.error(
1611
+ "Failed to prepare semantic metadata before saving visual:",
1612
+ M
1613
+ ), R.error(
1614
+ M instanceof Error ? M.message : "Failed to prepare semantic metadata for the saved visual"
1615
+ );
1616
+ return;
1617
+ }
1618
+ a(S.saveToCurrentDashboard), i(I), c(W);
1619
+ const P = {
1620
+ title: S.name,
1621
+ description: S.description,
1622
+ frameObject: I,
1623
+ // Card title synced for single-card frames
1624
+ isPrivate: !1
1625
+ };
1626
+ y.mutate(P);
1627
+ } else if (S.saveToCurrentDashboard) {
1628
+ const W = {
1629
+ ...I,
1630
+ // Card title already synced
1631
+ id: Tt(),
1632
+ visualId: void 0
1633
+ // Explicitly no visualId for local visuals
1634
+ };
1635
+ try {
1636
+ const P = await D(I, {
1637
+ previousFrame: qe(m, I.id)
1638
+ });
1639
+ b(p, W, {
1640
+ position: "end",
1641
+ semanticExecutionPayload: P
1642
+ }), k(W.id), R.success("Visual saved to dashboard"), r(!1), v(!1);
1643
+ } catch (P) {
1644
+ console.error("Failed to save visual to dashboard:", P), R.error(
1645
+ P instanceof Error ? P.message : "Failed to prepare semantic metadata for the visual"
1646
+ );
1647
+ }
1648
+ }
1649
+ },
1650
+ isLibraryVisual: E,
1651
+ currentVisualName: N,
1652
+ isSaving: y.isPending
1653
+ };
1654
+ }
1655
+ function $s(e = {}) {
1656
+ const { isInspectionMode: r } = jr(), o = ee((P) => P.frame), a = ee((P) => P.editorContext), n = Wr((P) => P.selectedVisual), i = L((P) => P.selectedFrameId), d = L((P) => P.selectedSheetId), c = L((P) => P.dashboard), { setIsVisualEditing: l, updateFrame: u } = pe(), [h, p] = F(!1), [m, g] = F("both"), f = St(), b = (a == null ? void 0 : a.type) === "documentSection", k = !!(o != null && o.visualId || n != null && n.id), v = !!(o != null && o.visualId && i), D = k && !v, {
1657
+ saveAsDialogOpen: E,
1658
+ setSaveAsDialogOpen: N,
1659
+ handleSaveAs: y,
1660
+ isLibraryVisual: w,
1661
+ currentVisualName: S,
1662
+ isSaving: x
1663
+ } = pn(), { getUpdatedFrame: B } = Ee();
1664
+ if (r)
1665
+ return /* @__PURE__ */ s($, { children: [
1666
+ /* @__PURE__ */ t(
1667
+ it,
1668
+ {
1669
+ className: "rounded-control",
1670
+ variant: "default"
1671
+ }
1672
+ ),
1673
+ /* @__PURE__ */ t(lt, {})
1674
+ ] });
1675
+ if (b)
1676
+ return /* @__PURE__ */ s($, { children: [
1677
+ /* @__PURE__ */ t(it, { className: "rounded-control", variant: "default" }),
1678
+ /* @__PURE__ */ t(lt, {})
1679
+ ] });
1680
+ const I = async () => {
1681
+ if (!d) {
1682
+ R.error("No sheet selected");
1683
+ return;
1684
+ }
1685
+ if (h) return;
1686
+ p(!0);
1687
+ const M = {
1688
+ ...B(),
1689
+ visualId: void 0
1690
+ }, Z = qe(c, M.id);
1691
+ try {
1692
+ const K = await f(M, {
1693
+ previousFrame: Z
1694
+ });
1695
+ u(d, M, {
1696
+ semanticExecutionPayload: K
1697
+ });
1698
+ } catch (K) {
1699
+ console.error("Failed to apply local semantic metadata:", K), p(!1), R.error(
1700
+ K instanceof Error ? K.message : "Failed to prepare semantic metadata for this visual"
1701
+ );
1702
+ return;
1703
+ }
1704
+ setTimeout(() => {
1705
+ p(!1), R.success("Changes applied. Visual is now local to this dashboard"), l(!1);
1706
+ }, 300);
1707
+ }, W = (P) => {
1708
+ g(P), N(!0);
1709
+ };
1710
+ return /* @__PURE__ */ s($, { children: [
1711
+ /* @__PURE__ */ s("div", { className: "inline-flex items-center overflow-hidden rounded-control", children: [
1712
+ !k && /* @__PURE__ */ t(it, { className: "!rounded-none", variant: "default" }),
1713
+ k && D && /* @__PURE__ */ t(hn, { className: "!rounded-none", variant: "default" }),
1714
+ k && v && /* @__PURE__ */ t(mn, { className: "!rounded-none" }),
1715
+ /* @__PURE__ */ s(rt, { modal: !1, children: [
1716
+ /* @__PURE__ */ t(at, { asChild: !0, children: /* @__PURE__ */ t(
1717
+ U,
1718
+ {
1719
+ variant: "default",
1720
+ size: "xs",
1721
+ className: "w-7 !rounded-none border-l border-primary-foreground/20 px-0",
1722
+ "aria-label": "Open visual save options",
1723
+ disabled: x || h,
1724
+ children: /* @__PURE__ */ t(Zt, { className: "h-3.5 w-3.5" })
1725
+ }
1726
+ ) }),
1727
+ /* @__PURE__ */ s(
1728
+ nt,
1729
+ {
1730
+ align: "end",
1731
+ className: "min-w-[220px] rounded-control border border-border/60 p-1 shadow-sm",
1732
+ children: [
1733
+ v && /* @__PURE__ */ s($, { children: [
1734
+ /* @__PURE__ */ s(
1735
+ Y,
1736
+ {
1737
+ onClick: I,
1738
+ disabled: h,
1739
+ children: [
1740
+ /* @__PURE__ */ t(ut, { className: "h-3.5 w-3.5" }),
1741
+ h ? "Applying..." : "Apply Locally"
1742
+ ]
1743
+ }
1744
+ ),
1745
+ /* @__PURE__ */ t(Xe, {})
1746
+ ] }),
1747
+ /* @__PURE__ */ s(
1748
+ Y,
1749
+ {
1750
+ onClick: () => W("local"),
1751
+ disabled: x,
1752
+ children: [
1753
+ /* @__PURE__ */ t(Se, { className: "h-3.5 w-3.5" }),
1754
+ "Add to Dashboard (Local)"
1755
+ ]
1756
+ }
1757
+ ),
1758
+ /* @__PURE__ */ s(
1759
+ Y,
1760
+ {
1761
+ onClick: () => W("library"),
1762
+ disabled: x,
1763
+ children: [
1764
+ /* @__PURE__ */ t(Ua, { className: "h-3.5 w-3.5" }),
1765
+ "Save as Library Visual"
1766
+ ]
1767
+ }
1768
+ ),
1769
+ /* @__PURE__ */ s(
1770
+ Y,
1771
+ {
1772
+ onClick: () => W("both"),
1773
+ disabled: x,
1774
+ children: [
1775
+ /* @__PURE__ */ t(Ra, { className: "h-3.5 w-3.5" }),
1776
+ "Save Copy as Linked Visual"
1777
+ ]
1778
+ }
1779
+ )
1780
+ ]
1781
+ }
1782
+ )
1783
+ ] })
1784
+ ] }),
1785
+ /* @__PURE__ */ t(lt, {}),
1786
+ /* @__PURE__ */ t(
1787
+ un,
1788
+ {
1789
+ open: E,
1790
+ onOpenChange: (P) => {
1791
+ x || N(P);
1792
+ },
1793
+ isLibraryVisual: w,
1794
+ currentVisualName: S,
1795
+ isSaving: x,
1796
+ destinationMode: m,
1797
+ onConfirm: y
1798
+ }
1799
+ )
1800
+ ] });
1801
+ }
1802
+ function zs({ className: e }) {
1803
+ const r = ee((h) => h.isDevMode), o = ee((h) => h.card.type), a = L((h) => h.isVisualEditing), { setIsDevMode: n } = Je(), { config: i } = pr(qr).tokenProps, d = (i == null ? void 0 : i.showAdvancedMode) !== !1;
1804
+ if (!a || !d || !Ma(o))
1805
+ return null;
1806
+ const c = r ? Ha : Wa, l = r ? "Visual editor" : "SQL editor", u = r ? "Switch to visual editor" : "Switch to SQL editor";
1807
+ return /* @__PURE__ */ s(
1808
+ "button",
1809
+ {
1810
+ type: "button",
1811
+ "aria-label": u,
1812
+ title: u,
1813
+ onClick: () => n(!r),
1814
+ className: X(
1815
+ "inline-flex h-7 items-center gap-1.5 rounded-control border border-input bg-background px-2 text-[12px] font-medium text-foreground transition-colors hover:bg-muted/40 focus-visible:border-ring focus-visible:outline-none",
1816
+ e
1817
+ ),
1818
+ children: [
1819
+ /* @__PURE__ */ t(c, { className: "h-3 w-3 text-muted-foreground" }),
1820
+ l
1821
+ ]
1822
+ }
1823
+ );
1824
+ }
1825
+ function js({
1826
+ open: e,
1827
+ onOpenChange: r,
1828
+ onSave: o,
1829
+ onDiscard: a,
1830
+ isSaving: n,
1831
+ title: i = "Unsaved changes",
1832
+ description: d = "You have unsaved changes to this dashboard. What would you like to do?",
1833
+ cancelLabel: c = "Cancel",
1834
+ discardLabel: l = "Discard changes",
1835
+ saveLabel: u = "Save"
1836
+ }) {
1837
+ return /* @__PURE__ */ t(pt, { open: e, onOpenChange: (p) => {
1838
+ !p && n || r(p);
1839
+ }, children: /* @__PURE__ */ s(ft, { children: [
1840
+ /* @__PURE__ */ s(gt, { children: [
1841
+ /* @__PURE__ */ t(bt, { children: i }),
1842
+ /* @__PURE__ */ t(vt, { children: d })
1843
+ ] }),
1844
+ /* @__PURE__ */ s(xt, { children: [
1845
+ /* @__PURE__ */ t(
1846
+ U,
1847
+ {
1848
+ type: "button",
1849
+ size: "xs",
1850
+ onClick: a,
1851
+ disabled: n,
1852
+ variant: "outline",
1853
+ className: "mr-auto text-destructive hover:border-destructive/40 hover:bg-destructive/10 hover:text-destructive focus-visible:bg-destructive/10 focus-visible:text-destructive",
1854
+ children: l
1855
+ }
1856
+ ),
1857
+ /* @__PURE__ */ t(yt, { disabled: n, children: c }),
1858
+ /* @__PURE__ */ t(U, { type: "button", size: "xs", onClick: o, disabled: n, children: n ? /* @__PURE__ */ s($, { children: [
1859
+ /* @__PURE__ */ t(ie, { className: "mr-2 h-3.5 w-3.5 animate-spin" }),
1860
+ "Saving..."
1861
+ ] }) : u })
1862
+ ] })
1863
+ ] }) });
1864
+ }
1865
+ function At(e, r) {
1866
+ return {
1867
+ id: e.id,
1868
+ status: e.status,
1869
+ progress: e.progress !== void 0 ? e.progress : e.status === "completed" ? 100 : e.totalChunks === null ? null : e.totalChunks > 0 ? Math.round(e.completedChunks / e.totalChunks * 100) : 0,
1870
+ totalRows: e.totalRows,
1871
+ totalChunks: e.totalChunks,
1872
+ rowsProcessed: e.processedRows,
1873
+ completedChunks: e.completedChunks,
1874
+ completedAt: e.completedAt ? new Date(e.completedAt) : void 0,
1875
+ lastUpdatedAt: /* @__PURE__ */ new Date(),
1876
+ fileSize: e.fileSize,
1877
+ error: e.error,
1878
+ phase: e.phase,
1879
+ deadlineAt: e.deadlineAt ? new Date(e.deadlineAt) : void 0,
1880
+ // A refreshed result replaces prior authorization, including a failed URL fetch.
1881
+ downloadUrl: r
1882
+ };
1883
+ }
1884
+ const fn = 15e3;
1885
+ function ye(e) {
1886
+ const r = new AbortController();
1887
+ let o;
1888
+ const a = new Promise((n, i) => {
1889
+ o = setTimeout(() => {
1890
+ r.abort(), i(new Error("Export request timed out."));
1891
+ }, fn);
1892
+ });
1893
+ return Promise.race([e(r.signal), a]).finally(() => clearTimeout(o));
1894
+ }
1895
+ const gn = 1e4, bn = 15e3, vn = 3e4, xn = 3e4, yn = 12e4, Cn = 5 * 6e4, wn = 2 * 60 * 60 * 1e3;
1896
+ function Nn(e) {
1897
+ return e.deadlineAt ? e.deadlineAt.getTime() + Cn : e.startedAt.getTime() + wn;
1898
+ }
1899
+ function Sn(e) {
1900
+ const r = Date.now() - e.getTime();
1901
+ return r < xn ? gn : r < yn ? bn : vn;
1902
+ }
1903
+ function Ws() {
1904
+ const { authToken: e, tokenProps: r } = Be(), o = xe((m) => m.activeExports), [a, n] = F(
1905
+ typeof document < "u" ? !document.hidden : !0
1906
+ ), i = ge(null), d = ge(!1), c = ge(void 0), l = r == null ? void 0 : r.apiServiceUrl, u = e == null ? void 0 : e.accessToken, h = j(() => {
1907
+ const m = xe.getState().activeExports;
1908
+ return Array.from(m.values()).filter(
1909
+ (g) => Le(g.status)
1910
+ );
1911
+ }, []);
1912
+ J(() => {
1913
+ if (typeof document > "u") return;
1914
+ const m = () => {
1915
+ n(!document.hidden);
1916
+ };
1917
+ return document.addEventListener("visibilitychange", m), () => {
1918
+ document.removeEventListener("visibilitychange", m);
1919
+ };
1920
+ }, []);
1921
+ const p = j(async () => {
1922
+ if (!l || !u) {
1923
+ d.current = !1;
1924
+ return;
1925
+ }
1926
+ const m = h();
1927
+ if (m.length === 0) {
1928
+ d.current = !1;
1929
+ return;
1930
+ }
1931
+ const g = Date.now(), f = await Promise.allSettled(
1932
+ m.map(async (E) => {
1933
+ try {
1934
+ const N = await ye((w) => Ht(l, u, E.id, w));
1935
+ let y;
1936
+ if (N.status === "completed")
1937
+ try {
1938
+ y = await ye((w) => Ye(l, u, E.id, w));
1939
+ } catch (w) {
1940
+ console.error(
1941
+ `[useExportPolling] Failed to get download URL for ${E.id}:`,
1942
+ w
1943
+ );
1944
+ }
1945
+ return At(N, y);
1946
+ } catch (N) {
1947
+ return console.error(
1948
+ `[useExportPolling] Failed to poll export ${E.id}:`,
1949
+ N
1950
+ ), null;
1951
+ }
1952
+ })
1953
+ ), { updateExport: b, applyServerStatus: k } = xe.getState().actions, v = (E) => {
1954
+ const N = xe.getState().activeExports.get(E);
1955
+ return !!N && Le(N.status);
1956
+ };
1957
+ m.forEach((E, N) => {
1958
+ if (!v(E.id)) return;
1959
+ const y = f[N], w = y.status === "fulfilled" ? y.value : null;
1960
+ if (g > Nn(E) && !(w && !Le(w.status))) {
1961
+ b(E.id, {
1962
+ status: "failed",
1963
+ error: Q.unconfirmed,
1964
+ lastUpdatedAt: /* @__PURE__ */ new Date()
1965
+ });
1966
+ return;
1967
+ }
1968
+ w && k(w.id, w);
1969
+ });
1970
+ const D = h();
1971
+ if (D.length > 0 && !document.hidden) {
1972
+ const E = D.reduce(
1973
+ (y, w) => w.startedAt < y ? w.startedAt : y,
1974
+ D[0].startedAt
1975
+ ), N = Sn(E);
1976
+ i.current && clearTimeout(i.current), i.current = setTimeout(() => {
1977
+ var y;
1978
+ (y = c.current) == null || y.call(c);
1979
+ }, N);
1980
+ } else
1981
+ d.current = !1;
1982
+ }, [l, u, h]);
1983
+ return J(() => {
1984
+ c.current = p;
1985
+ }, [p]), J(() => {
1986
+ var g;
1987
+ h().length > 0 && a && !d.current && (d.current = !0, (g = c.current) == null || g.call(c));
1988
+ }, [o, a, h]), J(() => {
1989
+ var g;
1990
+ const m = h();
1991
+ a && m.length > 0 && !d.current && (d.current = !0, (g = c.current) == null || g.call(c));
1992
+ }, [a, h]), J(() => {
1993
+ !a && i.current && (clearTimeout(i.current), i.current = null, d.current = !1);
1994
+ }, [a]), J(() => () => {
1995
+ i.current && (clearTimeout(i.current), i.current = null);
1996
+ }, []), {
1997
+ isPolling: d.current,
1998
+ isTabVisible: a,
1999
+ inProgressCount: h().length
2000
+ };
2001
+ }
2002
+ function qs() {
2003
+ const { authToken: e, tokenProps: r } = Be(), o = xe((c) => c.activeExports), { recoverExport: a } = Qt(), n = ge(!1), i = r == null ? void 0 : r.apiServiceUrl, d = e == null ? void 0 : e.accessToken;
2004
+ J(() => {
2005
+ if (n.current || !i || !d) return;
2006
+ (async () => {
2007
+ try {
2008
+ const { exports: l } = await ye((u) => Hr(i, d, {
2009
+ status: ["pending", "processing", "chunking", "compacting", "completed", "failed", "cancelled"],
2010
+ limit: 20
2011
+ // Limit to recent exports
2012
+ }, u));
2013
+ for (const u of l) {
2014
+ if (o.has(u.id)) continue;
2015
+ let h;
2016
+ if (u.status === "completed")
2017
+ try {
2018
+ h = await ye((m) => Ye(i, d, u.id, m));
2019
+ } catch (m) {
2020
+ console.error(
2021
+ `[useExportRecovery] Failed to get download URL for ${u.id}:`,
2022
+ m
2023
+ );
2024
+ }
2025
+ const p = {
2026
+ ...At(u, h),
2027
+ title: Dn(u),
2028
+ startedAt: new Date(u.createdAt),
2029
+ expiresAt: new Date(u.expiresAt)
2030
+ };
2031
+ a(p);
2032
+ }
2033
+ n.current = !0;
2034
+ } catch (l) {
2035
+ console.error("[useExportRecovery] Failed to recover exports:", l), n.current = !0;
2036
+ }
2037
+ })();
2038
+ }, [i, d, a, o]);
2039
+ }
2040
+ function Dn(e) {
2041
+ return e.title ? e.title : Le(
2042
+ e.status
2043
+ ) ? "Export in progress..." : e.status === "completed" ? "Export completed" : e.status === "failed" ? "Export failed" : "Export";
2044
+ }
2045
+ function En(e, r = []) {
2046
+ let o = [];
2047
+ function a(i, d) {
2048
+ const c = ue.createContext(d);
2049
+ c.displayName = i + "Context";
2050
+ const l = o.length;
2051
+ o = [...o, d];
2052
+ const u = (p) => {
2053
+ var v;
2054
+ const { scope: m, children: g, ...f } = p, b = ((v = m == null ? void 0 : m[e]) == null ? void 0 : v[l]) || c, k = ue.useMemo(() => f, Object.values(f));
2055
+ return /* @__PURE__ */ t(b.Provider, { value: k, children: g });
2056
+ };
2057
+ u.displayName = i + "Provider";
2058
+ function h(p, m) {
2059
+ var b;
2060
+ const g = ((b = m == null ? void 0 : m[e]) == null ? void 0 : b[l]) || c, f = ue.useContext(g);
2061
+ if (f) return f;
2062
+ if (d !== void 0) return d;
2063
+ throw new Error(`\`${p}\` must be used within \`${i}\``);
2064
+ }
2065
+ return [u, h];
2066
+ }
2067
+ const n = () => {
2068
+ const i = o.map((d) => ue.createContext(d));
2069
+ return function(c) {
2070
+ const l = (c == null ? void 0 : c[e]) || i;
2071
+ return ue.useMemo(
2072
+ () => ({ [`__scope${e}`]: { ...c, [e]: l } }),
2073
+ [c, l]
2074
+ );
2075
+ };
2076
+ };
2077
+ return n.scopeName = e, [a, kn(n, ...r)];
2078
+ }
2079
+ function kn(...e) {
2080
+ const r = e[0];
2081
+ if (e.length === 1) return r;
2082
+ const o = () => {
2083
+ const a = e.map((n) => ({
2084
+ useScope: n(),
2085
+ scopeName: n.scopeName
2086
+ }));
2087
+ return function(i) {
2088
+ const d = a.reduce((c, { useScope: l, scopeName: u }) => {
2089
+ const p = l(i)[`__scope${u}`];
2090
+ return { ...c, ...p };
2091
+ }, {});
2092
+ return ue.useMemo(() => ({ [`__scope${r.scopeName}`]: d }), [d]);
2093
+ };
2094
+ };
2095
+ return o.scopeName = r.scopeName, o;
2096
+ }
2097
+ var An = [
2098
+ "a",
2099
+ "button",
2100
+ "div",
2101
+ "form",
2102
+ "h2",
2103
+ "h3",
2104
+ "img",
2105
+ "input",
2106
+ "label",
2107
+ "li",
2108
+ "nav",
2109
+ "ol",
2110
+ "p",
2111
+ "select",
2112
+ "span",
2113
+ "svg",
2114
+ "ul"
2115
+ ], nr = An.reduce((e, r) => {
2116
+ const o = gr(`Primitive.${r}`), a = ue.forwardRef((n, i) => {
2117
+ const { asChild: d, ...c } = n, l = d ? o : r;
2118
+ return typeof window < "u" && (window[Symbol.for("radix-ui")] = !0), /* @__PURE__ */ t(l, { ...c, ref: i });
2119
+ });
2120
+ return a.displayName = `Primitive.${r}`, { ...e, [r]: a };
2121
+ }, {}), It = "Progress", Ft = 100, [In] = En(It), [Fn, Pn] = In(It), sr = ue.forwardRef(
2122
+ (e, r) => {
2123
+ const {
2124
+ __scopeProgress: o,
2125
+ value: a = null,
2126
+ max: n,
2127
+ getValueLabel: i = Ln,
2128
+ ...d
2129
+ } = e;
2130
+ (n || n === 0) && !Vt(n) && console.error(Tn(`${n}`, "Progress"));
2131
+ const c = Vt(n) ? n : Ft;
2132
+ a !== null && !Bt(a, c) && console.error(Un(`${a}`, "Progress"));
2133
+ const l = Bt(a, c) ? a : null, u = Ze(l) ? i(l, c) : void 0;
2134
+ return /* @__PURE__ */ t(Fn, { scope: o, value: l, max: c, children: /* @__PURE__ */ t(
2135
+ nr.div,
2136
+ {
2137
+ "aria-valuemax": c,
2138
+ "aria-valuemin": 0,
2139
+ "aria-valuenow": Ze(l) ? l : void 0,
2140
+ "aria-valuetext": u,
2141
+ role: "progressbar",
2142
+ "data-state": lr(l, c),
2143
+ "data-value": l ?? void 0,
2144
+ "data-max": c,
2145
+ ...d,
2146
+ ref: r
2147
+ }
2148
+ ) });
2149
+ }
2150
+ );
2151
+ sr.displayName = It;
2152
+ var or = "ProgressIndicator", ir = ue.forwardRef(
2153
+ (e, r) => {
2154
+ const { __scopeProgress: o, ...a } = e, n = Pn(or, o);
2155
+ return /* @__PURE__ */ t(
2156
+ nr.div,
2157
+ {
2158
+ "data-state": lr(n.value, n.max),
2159
+ "data-value": n.value ?? void 0,
2160
+ "data-max": n.max,
2161
+ ...a,
2162
+ ref: r
2163
+ }
2164
+ );
2165
+ }
2166
+ );
2167
+ ir.displayName = or;
2168
+ function Ln(e, r) {
2169
+ return `${Math.round(e / r * 100)}%`;
2170
+ }
2171
+ function lr(e, r) {
2172
+ return e == null ? "indeterminate" : e === r ? "complete" : "loading";
2173
+ }
2174
+ function Ze(e) {
2175
+ return typeof e == "number";
2176
+ }
2177
+ function Vt(e) {
2178
+ return Ze(e) && !isNaN(e) && e > 0;
2179
+ }
2180
+ function Bt(e, r) {
2181
+ return Ze(e) && !isNaN(e) && e <= r && e >= 0;
2182
+ }
2183
+ function Tn(e, r) {
2184
+ return `Invalid prop \`max\` of value \`${e}\` supplied to \`${r}\`. Only numbers greater than 0 are valid max values. Defaulting to \`${Ft}\`.`;
2185
+ }
2186
+ function Un(e, r) {
2187
+ return `Invalid prop \`value\` of value \`${e}\` supplied to \`${r}\`. The \`value\` prop must be:
2188
+ - a positive number
2189
+ - less than the value passed to \`max\` (or ${Ft} if no \`max\` prop is set)
2190
+ - \`null\` or \`undefined\` if the progress is indeterminate.
2191
+
2192
+ Defaulting to \`null\`.`;
2193
+ }
2194
+ var cr = sr, Rn = ir;
2195
+ const dr = ue.forwardRef(({ className: e, value: r, ...o }, a) => /* @__PURE__ */ t(
2196
+ cr,
2197
+ {
2198
+ ref: a,
2199
+ className: X(
2200
+ "relative h-4 w-full overflow-hidden rounded-full bg-secondary",
2201
+ e
2202
+ ),
2203
+ ...o,
2204
+ children: /* @__PURE__ */ t(
2205
+ Rn,
2206
+ {
2207
+ className: "h-full w-full flex-1 bg-primary transition-all",
2208
+ style: { transform: `translateX(-${100 - (r || 0)}%)` }
2209
+ }
2210
+ )
2211
+ }
2212
+ ));
2213
+ dr.displayName = cr.displayName;
2214
+ function Vn({
2215
+ export: e,
2216
+ onRemove: r,
2217
+ onDownload: o
2218
+ }) {
2219
+ const [a, n] = F("idle");
2220
+ J(() => {
2221
+ e.downloadUrl && n("idle");
2222
+ }, [e.downloadUrl]);
2223
+ const i = async () => {
2224
+ if (!o) {
2225
+ e.downloadUrl && window.open(e.downloadUrl, "_blank");
2226
+ return;
2227
+ }
2228
+ n("preparing");
2229
+ const b = await o(e);
2230
+ n(b === "denied" ? "denied" : "idle");
2231
+ }, d = (b) => {
2232
+ b.stopPropagation(), r == null || r(e.id);
2233
+ }, c = Le(e.status), l = e.status === "pending" ? { text: Q.queued } : e.status === "compacting" || e.phase === "finalizing" ? { text: Q.finalizing } : e.phase === "preparing" ? { text: Q.preparing } : e.phase === "acquiring" ? { text: Q.fetchingRows(e.rowsProcessed ?? 0) } : {
2234
+ text: Q.processing,
2235
+ detail: e.progress !== null ? Q.percentComplete(e.progress) : e.rowsProcessed !== void 0 ? Q.rowsProcessed(e.rowsProcessed) : void 0,
2236
+ bar: e.progress
2237
+ }, u = c && Date.now() - e.startedAt.getTime() >= Qr, h = e.status === "completed" ? "bg-emerald-500" : e.status === "failed" ? "bg-destructive" : e.status === "pending" || e.status === "cancelled" ? "bg-muted-foreground/40" : "animate-pulse bg-muted-foreground/60", p = e.status === "completed" ? Q.ready : e.status === "failed" ? Q.failed : e.status === "cancelled" ? Q.cancelled : Q.inProgress, m = Ut(e.startedAt, { addSuffix: !0 }), g = [
2238
+ e.status === "completed" && e.totalRows !== null ? `${e.totalRows.toLocaleString()} rows` : null,
2239
+ e.status === "completed" && e.fileSize ? Gr(e.fileSize) : null
2240
+ ].filter((b) => !!b), f = /* @__PURE__ */ t("span", { className: "text-muted-foreground/50", children: "·" });
2241
+ return /* @__PURE__ */ s("div", { className: "group flex items-start gap-2.5 px-3 py-2 transition-colors hover:bg-muted/40 focus-within:bg-muted/40", children: [
2242
+ /* @__PURE__ */ t("span", { className: "flex h-5 shrink-0 items-center", "aria-hidden": "true", children: /* @__PURE__ */ t("span", { className: `h-1.5 w-1.5 rounded-full ${h}` }) }),
2243
+ /* @__PURE__ */ t("span", { className: "sr-only", children: p }),
2244
+ /* @__PURE__ */ s("div", { className: "min-w-0 flex-1", children: [
2245
+ /* @__PURE__ */ s("div", { className: "flex h-5 items-center gap-2", children: [
2246
+ /* @__PURE__ */ t("span", { className: "min-w-0 flex-1 truncate text-[13px] font-medium leading-5", children: e.title }),
2247
+ e.status === "completed" && a === "preparing" && /* @__PURE__ */ s("span", { role: "status", className: "inline-flex shrink-0 items-center gap-1.5 text-[12px] text-muted-foreground", children: [
2248
+ /* @__PURE__ */ t(Gt, { className: "h-3 w-3 animate-spin", strokeWidth: 1.75 }),
2249
+ "Preparing"
2250
+ ] }),
2251
+ e.status === "completed" && a !== "preparing" && /* @__PURE__ */ t(
2252
+ "button",
2253
+ {
2254
+ type: "button",
2255
+ onClick: () => void i(),
2256
+ className: "shrink-0 text-[12px] font-medium text-foreground/80 underline-offset-2 hover:text-foreground hover:underline focus-visible:underline focus-visible:outline-none",
2257
+ children: "Download"
2258
+ }
2259
+ ),
2260
+ /* @__PURE__ */ t(
2261
+ U,
2262
+ {
2263
+ variant: "ghost",
2264
+ size: "xs",
2265
+ className: "-mr-1.5 h-5 w-5 shrink-0 px-0 text-muted-foreground opacity-0 transition-opacity hover:text-foreground focus-visible:opacity-100 group-hover:opacity-100 group-focus-within:opacity-100",
2266
+ onClick: d,
2267
+ "aria-label": "Remove notification",
2268
+ title: "Remove",
2269
+ children: /* @__PURE__ */ t(Me, { className: "h-3.5 w-3.5", strokeWidth: 1.75 })
2270
+ }
2271
+ )
2272
+ ] }),
2273
+ e.status === "completed" && /* @__PURE__ */ s("div", { className: "flex items-center gap-1.5 text-[12px] leading-4 text-muted-foreground", children: [
2274
+ g.length > 0 && // Disclosed on hover or focus only; the time is what a reader scans.
2275
+ /* @__PURE__ */ s("span", { className: "hidden group-hover:contents group-focus-within:contents", children: [
2276
+ g.map((b, k) => /* @__PURE__ */ s(_t.Fragment, { children: [
2277
+ k > 0 && f,
2278
+ /* @__PURE__ */ t("span", { children: b })
2279
+ ] }, k)),
2280
+ f
2281
+ ] }),
2282
+ /* @__PURE__ */ t("span", { children: m })
2283
+ ] }),
2284
+ e.status === "completed" && a === "denied" && /* @__PURE__ */ s("div", { role: "alert", className: "mt-1 flex items-start gap-1.5 text-[12px] leading-4 text-foreground", children: [
2285
+ /* @__PURE__ */ t(Kr, { className: "mt-0.5 h-3 w-3 shrink-0 text-destructive", strokeWidth: 1.75 }),
2286
+ /* @__PURE__ */ t("span", { children: Q.linkExpired })
2287
+ ] }),
2288
+ c && /* @__PURE__ */ s("div", { className: "text-[12px] leading-4 text-muted-foreground", children: [
2289
+ /* @__PURE__ */ t("span", { className: "tabular-nums", children: l.text }),
2290
+ l.detail && /* @__PURE__ */ s($, { children: [
2291
+ " ",
2292
+ f,
2293
+ " ",
2294
+ /* @__PURE__ */ t("span", { className: "tabular-nums", children: l.detail })
2295
+ ] }),
2296
+ " ",
2297
+ f,
2298
+ " ",
2299
+ /* @__PURE__ */ t("span", { children: Q.started(Ut(e.startedAt)) }),
2300
+ l.bar !== void 0 && l.bar !== null && /* @__PURE__ */ t(dr, { value: l.bar, className: "mt-1.5 h-1" }),
2301
+ u && /* @__PURE__ */ t("div", { className: "mt-1", children: Q.longRunning })
2302
+ ] }),
2303
+ e.status === "cancelled" && /* @__PURE__ */ s("div", { className: "flex items-center gap-1.5 text-[12px] leading-4 text-muted-foreground", children: [
2304
+ /* @__PURE__ */ t("span", { children: Q.cancelled }),
2305
+ f,
2306
+ /* @__PURE__ */ t("span", { children: m })
2307
+ ] }),
2308
+ e.status === "failed" && /* @__PURE__ */ s($, { children: [
2309
+ /* @__PURE__ */ s("div", { className: "flex items-center gap-1.5 text-[12px] leading-4 text-muted-foreground", children: [
2310
+ /* @__PURE__ */ t("span", { children: Q.failed }),
2311
+ f,
2312
+ /* @__PURE__ */ t("span", { children: m })
2313
+ ] }),
2314
+ /* @__PURE__ */ t("div", { className: "mt-1 whitespace-pre-wrap break-words text-[12px] leading-4 text-destructive", children: e.error || Q.failedFallback })
2315
+ ] })
2316
+ ] })
2317
+ ] });
2318
+ }
2319
+ function Bn() {
2320
+ const { authToken: e, tokenProps: r } = Be(), o = xe((v) => v.activeExports), { clearCompleted: a, removeExport: n, updateExport: i, applyServerStatus: d } = Qt(), [c, l] = F(!1), [u, h] = F(!1), p = Array.from(o.values()).sort(
2321
+ (v, D) => D.startedAt.getTime() - v.startedAt.getTime()
2322
+ ), m = p.some(
2323
+ (v) => v.status === "completed" || v.status === "failed" || v.status === "cancelled"
2324
+ ), g = j(async () => {
2325
+ const v = r == null ? void 0 : r.apiServiceUrl, D = e == null ? void 0 : e.accessToken;
2326
+ if (!(!v || !D)) {
2327
+ l(!0);
2328
+ try {
2329
+ const E = Array.from(o.values());
2330
+ await Promise.all(
2331
+ E.map(async (N) => {
2332
+ try {
2333
+ const y = await ye((S) => Ht(v, D, N.id, S));
2334
+ let w;
2335
+ if (y.status === "completed")
2336
+ try {
2337
+ w = await ye((S) => Ye(
2338
+ v,
2339
+ D,
2340
+ N.id,
2341
+ S
2342
+ ));
2343
+ } catch (S) {
2344
+ console.error(`Failed to get download URL for ${N.id}:`, S);
2345
+ }
2346
+ d(N.id, At(y, w));
2347
+ } catch (y) {
2348
+ i(N.id, { downloadUrl: void 0 }), console.error(`Failed to refresh export ${N.id}:`, y);
2349
+ }
2350
+ })
2351
+ );
2352
+ } finally {
2353
+ l(!1);
2354
+ }
2355
+ }
2356
+ }, [
2357
+ o,
2358
+ e == null ? void 0 : e.accessToken,
2359
+ r == null ? void 0 : r.apiServiceUrl,
2360
+ i,
2361
+ d
2362
+ ]), f = j(async () => {
2363
+ const v = r == null ? void 0 : r.apiServiceUrl, D = e == null ? void 0 : e.accessToken;
2364
+ if (!v || !D) {
2365
+ a();
2366
+ return;
2367
+ }
2368
+ h(!0);
2369
+ try {
2370
+ const E = p.filter(
2371
+ (y) => y.status === "completed" || y.status === "failed" || y.status === "cancelled"
2372
+ ), N = await Promise.allSettled(
2373
+ E.map(async (y) => (await Lt(v, D, y.id), y.id))
2374
+ );
2375
+ for (const y of N)
2376
+ y.status === "fulfilled" ? n(y.value) : console.error("Failed to delete export:", y.reason);
2377
+ } finally {
2378
+ h(!1);
2379
+ }
2380
+ }, [
2381
+ p,
2382
+ r == null ? void 0 : r.apiServiceUrl,
2383
+ e == null ? void 0 : e.accessToken,
2384
+ a,
2385
+ n
2386
+ ]), b = j(
2387
+ async (v) => {
2388
+ const D = r == null ? void 0 : r.apiServiceUrl, E = e == null ? void 0 : e.accessToken;
2389
+ if (D && E)
2390
+ try {
2391
+ await Lt(D, E, v), n(v);
2392
+ return;
2393
+ } catch (N) {
2394
+ console.error(`Failed to cancel export ${v}:`, N);
2395
+ }
2396
+ n(v);
2397
+ },
2398
+ [r == null ? void 0 : r.apiServiceUrl, e == null ? void 0 : e.accessToken, n]
2399
+ ), k = j(
2400
+ async (v) => {
2401
+ if (v.downloadUrl)
2402
+ return window.open(v.downloadUrl, "_blank"), "opened";
2403
+ const D = r == null ? void 0 : r.apiServiceUrl, E = e == null ? void 0 : e.accessToken;
2404
+ if (!D || !E) return "denied";
2405
+ try {
2406
+ const N = await ye((y) => Ye(D, E, v.id, y));
2407
+ return i(v.id, { downloadUrl: N }), window.open(N, "_blank"), "opened";
2408
+ } catch (N) {
2409
+ return console.error(`Failed to get download URL for ${v.id}:`, N), i(v.id, { downloadUrl: void 0 }), "denied";
2410
+ }
2411
+ },
2412
+ [r == null ? void 0 : r.apiServiceUrl, e == null ? void 0 : e.accessToken, i]
2413
+ );
2414
+ return p.length === 0 ? /* @__PURE__ */ s("div", { className: "flex flex-col items-center gap-1.5 px-6 py-8 text-center", children: [
2415
+ /* @__PURE__ */ t("span", { className: "flex h-8 w-8 items-center justify-center rounded-[6px] border border-border text-muted-foreground", children: /* @__PURE__ */ t(qa, { className: "h-3.5 w-3.5", strokeWidth: 1.75 }) }),
2416
+ /* @__PURE__ */ t("p", { className: "text-[13px] font-medium", children: "No exports yet" }),
2417
+ /* @__PURE__ */ t("p", { className: "text-[12px] text-muted-foreground", children: "Large exports run in the background and land here." })
2418
+ ] }) : /* @__PURE__ */ s("div", { className: "flex flex-col", children: [
2419
+ /* @__PURE__ */ s("div", { className: "flex h-8 items-center gap-2 border-b border-border px-3", children: [
2420
+ /* @__PURE__ */ t("span", { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Exports" }),
2421
+ /* @__PURE__ */ t("span", { className: "text-[10px] tabular-nums text-muted-foreground/70", children: p.length }),
2422
+ /* @__PURE__ */ s("div", { className: "ml-auto flex items-center gap-0.5", children: [
2423
+ m && /* @__PURE__ */ t(
2424
+ U,
2425
+ {
2426
+ variant: "ghost",
2427
+ size: "xs",
2428
+ className: "h-6 px-1.5 text-[12px] text-muted-foreground hover:text-foreground",
2429
+ onClick: f,
2430
+ disabled: u,
2431
+ children: u ? "Clearing" : "Clear all"
2432
+ }
2433
+ ),
2434
+ /* @__PURE__ */ t(
2435
+ U,
2436
+ {
2437
+ variant: "ghost",
2438
+ size: "xs",
2439
+ className: "h-6 w-6 px-0 text-muted-foreground hover:text-foreground",
2440
+ onClick: g,
2441
+ disabled: c,
2442
+ title: "Refresh status",
2443
+ "aria-label": "Refresh status",
2444
+ children: /* @__PURE__ */ t(
2445
+ Gt,
2446
+ {
2447
+ strokeWidth: 1.75,
2448
+ className: `h-3.5 w-3.5 ${c ? "animate-spin" : ""}`
2449
+ }
2450
+ )
2451
+ }
2452
+ )
2453
+ ] })
2454
+ ] }),
2455
+ /* @__PURE__ */ t("div", { className: "max-h-[320px] overflow-y-auto", children: /* @__PURE__ */ t("div", { className: "divide-y divide-border/70", children: p.map((v) => /* @__PURE__ */ t(
2456
+ Vn,
2457
+ {
2458
+ export: v,
2459
+ onRemove: b,
2460
+ onDownload: k
2461
+ },
2462
+ v.id
2463
+ )) }) })
2464
+ ] });
2465
+ }
2466
+ function Hs({
2467
+ variant: e
2468
+ }) {
2469
+ const r = xe((l) => l.activeExports), o = Xr(), a = r.size > 0, n = Array.from(r.values()).some(
2470
+ (l) => l.status === "completed" || l.status === "failed"
2471
+ ), d = o > 0 ? o > 9 ? "9+" : String(o) : null;
2472
+ return /* @__PURE__ */ s(He, { children: [
2473
+ /* @__PURE__ */ t(Qe, { asChild: !0, children: /* @__PURE__ */ s(
2474
+ U,
2475
+ {
2476
+ variant: e ?? "ghost",
2477
+ size: "xs",
2478
+ className: "relative w-7 px-0 text-muted-foreground hover:text-foreground",
2479
+ "aria-label": "Export notifications",
2480
+ children: [
2481
+ /* @__PURE__ */ t(Yr, { className: "h-3.5 w-3.5" }),
2482
+ a && /* @__PURE__ */ t(
2483
+ "span",
2484
+ {
2485
+ className: `absolute flex items-center justify-center rounded-full bg-primary text-primary-foreground ${d ? "-right-0.5 -top-0.5 h-3.5 min-w-3.5 px-0.5 text-[9px] font-semibold" : "right-1 top-1 h-1.5 w-1.5"}`,
2486
+ children: d
2487
+ }
2488
+ )
2489
+ ]
2490
+ }
2491
+ ) }),
2492
+ /* @__PURE__ */ t(Ge, { className: "w-80 p-0", align: "end", sideOffset: 8, children: /* @__PURE__ */ t(Bn, {}) })
2493
+ ] });
2494
+ }
2495
+ function Mn(e) {
2496
+ if (e)
2497
+ return {
2498
+ renamed: e.type === "rename" ? { oldId: e.oldId, newId: e.newId } : void 0,
2499
+ removedControlId: e.type === "remove" ? e.controlId : void 0,
2500
+ cardBindingsById: e.type === "add" || e.type === "update" ? e.cardBindingsById : void 0,
2501
+ affectedBindingControlIds: e.type === "add" || e.type === "update" ? e.affectedBindingControlIds : void 0
2502
+ };
2503
+ }
2504
+ function _n({
2505
+ open: e,
2506
+ onOpenChange: r,
2507
+ trigger: o,
2508
+ showTrigger: a = !0,
2509
+ initialMode: n = "manage"
2510
+ }) {
2511
+ const i = n === "create", {
2512
+ forceClose: d,
2513
+ handleOpenChange: c,
2514
+ isCreateFlowActive: l,
2515
+ preventPassiveDismissDuringCreate: u,
2516
+ resolvedOpen: h,
2517
+ setIsCreateFlowActive: p
2518
+ } = Jt({
2519
+ open: e,
2520
+ onOpenChange: r,
2521
+ initialCreateFlowActive: n === "create",
2522
+ // Dialog mode renders a built-in X close button — allow explicit
2523
+ // closes through `handleOpenChange`. Popover mode has no X; its
2524
+ // only close-via-trigger path is a re-click that would silently
2525
+ // wipe the in-progress create flow, so block everything during
2526
+ // create and make consumers use `forceClose()` from a dedicated
2527
+ // button.
2528
+ dismissMode: a ? "passive" : "explicit-only"
2529
+ }), m = L((x) => x.dashboard), { setDashboardControlsModel: g } = pe(), { participants: f } = Zr(_a(m)), b = Array.from(
2530
+ new Map(
2531
+ f.flatMap(
2532
+ (x) => x.fieldChoices.map((B) => {
2533
+ var I;
2534
+ return [
2535
+ B.value,
2536
+ {
2537
+ option: B,
2538
+ target: (I = x.fieldTargetMap) == null ? void 0 : I[B.value]
2539
+ }
2540
+ ];
2541
+ })
2542
+ )
2543
+ ).values()
2544
+ ), k = Array.from(
2545
+ new Map(
2546
+ f.flatMap(
2547
+ (x) => x.metricChoices.map((B) => {
2548
+ var I;
2549
+ return [
2550
+ B.value,
2551
+ {
2552
+ option: B,
2553
+ target: (I = x.metricTargetMap) == null ? void 0 : I[B.value]
2554
+ }
2555
+ ];
2556
+ })
2557
+ )
2558
+ ).values()
2559
+ ), v = br({
2560
+ ...m || {},
2561
+ controls: []
2562
+ }), D = Jr(m), E = (x, B, I) => {
2563
+ g(
2564
+ x,
2565
+ B,
2566
+ Mn(I)
2567
+ );
2568
+ }, N = j(() => {
2569
+ if (i) {
2570
+ d();
2571
+ return;
2572
+ }
2573
+ p(!1);
2574
+ }, [i, d, p]), y = /* @__PURE__ */ t(
2575
+ er,
2576
+ {
2577
+ scope: "dashboard",
2578
+ controls: m.controls || [],
2579
+ reservedControlIds: v,
2580
+ defaultValues: m.defaultControlValues || {},
2581
+ usageByControlId: ea(m),
2582
+ availableFieldChoices: b,
2583
+ availableMetricChoices: k,
2584
+ structuralParticipants: f,
2585
+ structuralParticipantIdsByControlId: D,
2586
+ initialCreateFlow: n === "create",
2587
+ onCreateFlowActiveChange: p,
2588
+ onCreateFlowComplete: N,
2589
+ onChange: E,
2590
+ emptyMessage: "No dashboard controls yet."
2591
+ }
2592
+ ), w = l ? "Add dashboard control" : "Dashboard Controls", S = /* @__PURE__ */ s($, { children: [
2593
+ /* @__PURE__ */ s("div", { className: "space-y-1", children: [
2594
+ /* @__PURE__ */ t("h4", { className: "text-sm font-medium", children: "Dashboard Controls" }),
2595
+ /* @__PURE__ */ t("p", { className: "text-xs text-muted-foreground", children: "Add shared controls viewers can use across the dashboard. Each card can decide how to respond to the same control." })
2596
+ ] }),
2597
+ y
2598
+ ] });
2599
+ return a ? /* @__PURE__ */ s(He, { open: h, onOpenChange: c, children: [
2600
+ /* @__PURE__ */ t(Qe, { asChild: !0, children: o || /* @__PURE__ */ s(U, { variant: "outline", className: "h-7 px-2", size: "sm", children: [
2601
+ /* @__PURE__ */ t($t, { className: "mr-2 h-4 w-4" }),
2602
+ "Controls"
2603
+ ] }) }),
2604
+ /* @__PURE__ */ t(
2605
+ Ge,
2606
+ {
2607
+ className: "w-[620px] max-w-[95vw] space-y-4",
2608
+ align: "end",
2609
+ onEscapeKeyDown: u,
2610
+ onPointerDownOutside: u,
2611
+ children: S
2612
+ }
2613
+ )
2614
+ ] }) : /* @__PURE__ */ t(Ue, { open: h, onOpenChange: c, children: /* @__PURE__ */ s(
2615
+ Re,
2616
+ {
2617
+ className: "flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",
2618
+ onEscapeKeyDown: u,
2619
+ onPointerDownOutside: u,
2620
+ children: [
2621
+ /* @__PURE__ */ s(
2622
+ wt,
2623
+ {
2624
+ className: l ? "space-y-0" : void 0,
2625
+ children: [
2626
+ /* @__PURE__ */ t(Ve, { className: "text-[15px]", children: w }),
2627
+ /* @__PURE__ */ t(
2628
+ Nt,
2629
+ {
2630
+ className: l ? "sr-only" : "text-[13px]",
2631
+ children: l ? "Configure and add a shared dashboard control." : "Add shared controls viewers can use across the dashboard. Each card can decide how to respond to the same control."
2632
+ }
2633
+ )
2634
+ ]
2635
+ }
2636
+ ),
2637
+ /* @__PURE__ */ t("div", { className: "min-h-0 overflow-y-auto pr-1", children: y })
2638
+ ]
2639
+ }
2640
+ ) });
2641
+ }
2642
+ const On = [
2643
+ "enum",
2644
+ "multi_enum",
2645
+ "text",
2646
+ "number",
2647
+ "boolean",
2648
+ "date"
2649
+ ];
2650
+ function $n({
2651
+ open: e,
2652
+ onOpenChange: r,
2653
+ initialMode: o = "manage"
2654
+ }) {
2655
+ var S;
2656
+ const a = o === "create", {
2657
+ forceClose: n,
2658
+ handleOpenChange: i,
2659
+ isCreateFlowActive: d,
2660
+ preventPassiveDismissDuringCreate: c,
2661
+ resolvedOpen: l,
2662
+ setIsCreateFlowActive: u
2663
+ } = Jt({
2664
+ open: e,
2665
+ onOpenChange: r,
2666
+ initialCreateFlowActive: o === "create",
2667
+ dismissMode: "explicit-only"
2668
+ }), h = L((x) => x.dashboard), p = L((x) => x.selectedSheetId), { setDashboardInputs: m } = pe(), g = (S = h.sheets) == null ? void 0 : S.find(
2669
+ (x) => x.id === p
2670
+ ), f = (g == null ? void 0 : g.kind) === "document" && !!g.document, b = oe(
2671
+ () => f && (g != null && g.document) ? ta(h, g.id) : [],
2672
+ [h, f, g == null ? void 0 : g.document, g == null ? void 0 : g.id]
2673
+ ), k = oe(
2674
+ () => b.filter(
2675
+ (x) => x.kind === "control"
2676
+ ),
2677
+ [b]
2678
+ ), v = oe(
2679
+ () => k.map((x) => x.control),
2680
+ [k]
2681
+ ), D = oe(
2682
+ () => jn(v),
2683
+ [v]
2684
+ ), E = oe(
2685
+ () => zn(h),
2686
+ [h]
2687
+ ), N = j(() => {
2688
+ if (a) {
2689
+ n();
2690
+ return;
2691
+ }
2692
+ u(!1);
2693
+ }, [a, n, u]), y = j(
2694
+ (x, B, I) => {
2695
+ !f || !(g != null && g.document) || m(
2696
+ qn({
2697
+ allInputs: h.inputs || [],
2698
+ documentSheetId: g.id,
2699
+ currentDocumentInputs: b,
2700
+ nextControls: x,
2701
+ nextDefaultValues: B,
2702
+ change: I
2703
+ })
2704
+ );
2705
+ },
2706
+ [
2707
+ h.inputs,
2708
+ b,
2709
+ f,
2710
+ g,
2711
+ m
2712
+ ]
2713
+ );
2714
+ return !f || !(g != null && g.document) ? null : /* @__PURE__ */ t(Ue, { open: l, onOpenChange: i, children: /* @__PURE__ */ s(
2715
+ Re,
2716
+ {
2717
+ className: "flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",
2718
+ onEscapeKeyDown: c,
2719
+ onPointerDownOutside: c,
2720
+ children: [
2721
+ /* @__PURE__ */ s(wt, { className: d ? "space-y-0" : void 0, children: [
2722
+ /* @__PURE__ */ t(Ve, { className: "text-[15px]", children: d ? "Add document control" : "Document Controls" }),
2723
+ /* @__PURE__ */ t(
2724
+ Nt,
2725
+ {
2726
+ className: d ? "sr-only" : "text-[13px]",
2727
+ children: d ? "Configure and add a document-local control input." : "Add document-local control inputs. They are stored on this document sheet and are not dashboard controls."
2728
+ }
2729
+ )
2730
+ ] }),
2731
+ /* @__PURE__ */ t("div", { className: "min-h-0 overflow-y-auto pr-1", children: /* @__PURE__ */ t(
2732
+ er,
2733
+ {
2734
+ scope: "dashboard",
2735
+ controls: v,
2736
+ reservedControlIds: E,
2737
+ defaultValues: D,
2738
+ usageByControlId: {},
2739
+ availableFieldChoices: [],
2740
+ availableMetricChoices: [],
2741
+ structuralParticipants: [],
2742
+ structuralParticipantIdsByControlId: {},
2743
+ allowedControlTypes: On,
2744
+ initialCreateFlow: o === "create",
2745
+ onCreateFlowActiveChange: u,
2746
+ onCreateFlowComplete: N,
2747
+ onChange: y,
2748
+ emptyMessage: "No document controls yet."
2749
+ }
2750
+ ) })
2751
+ ]
2752
+ }
2753
+ ) });
2754
+ }
2755
+ function zn(e) {
2756
+ return (e.controls || []).map((r) => r.id);
2757
+ }
2758
+ function jn(e) {
2759
+ const r = {};
2760
+ for (const o of e)
2761
+ o.defaultValue !== void 0 && (r[o.id] = o.defaultValue);
2762
+ return r;
2763
+ }
2764
+ function Wn(e, r) {
2765
+ return r ? Object.prototype.hasOwnProperty.call(r, e.id) ? {
2766
+ ...e,
2767
+ defaultValue: r[e.id]
2768
+ } : e.defaultValue === void 0 ? e : { ...e, defaultValue: void 0 } : e.defaultValue === void 0 ? e : { ...e, defaultValue: void 0 };
2769
+ }
2770
+ function qn({
2771
+ allInputs: e,
2772
+ documentSheetId: r,
2773
+ currentDocumentInputs: o,
2774
+ nextControls: a,
2775
+ nextDefaultValues: n,
2776
+ change: i
2777
+ }) {
2778
+ const d = new Map(
2779
+ a.map((m) => [
2780
+ m.id,
2781
+ Wn(m, n)
2782
+ ])
2783
+ ), c = (i == null ? void 0 : i.type) === "rename" ? { oldId: i.oldId, newId: i.newId } : null, l = /* @__PURE__ */ new Set(), u = [];
2784
+ for (const m of o) {
2785
+ if (m.kind !== "control") {
2786
+ u.push(m);
2787
+ continue;
2788
+ }
2789
+ const g = d.get(m.control.id) || ((c == null ? void 0 : c.oldId) === m.control.id ? d.get(c.newId) : void 0);
2790
+ if (!g)
2791
+ continue;
2792
+ l.add(g.id);
2793
+ const f = vr(
2794
+ g.id,
2795
+ [...e, ...u].filter(
2796
+ (k) => k.id !== m.id
2797
+ )
2798
+ ), b = g.id === f ? g : { ...g, id: f };
2799
+ u.push({
2800
+ ...m,
2801
+ label: b.label,
2802
+ variableName: f,
2803
+ requiredAtExecution: b.requiredAtExecution,
2804
+ control: b
2805
+ });
2806
+ }
2807
+ for (const m of d.values())
2808
+ l.has(m.id) || u.push(
2809
+ ra({
2810
+ control: m,
2811
+ existingInputs: [...e, ...u],
2812
+ sheetId: r
2813
+ })
2814
+ );
2815
+ const h = new Set(
2816
+ o.map((m) => m.id)
2817
+ );
2818
+ return [...e.filter(
2819
+ (m) => !h.has(m.id)
2820
+ ), ...u];
2821
+ }
2822
+ function Hn({
2823
+ showFilters: e,
2824
+ onShowFiltersChange: r,
2825
+ pickerContent: o,
2826
+ settingsContent: a,
2827
+ size: n = "default",
2828
+ className: i,
2829
+ primaryButtonClassName: d,
2830
+ secondaryButtonClassName: c,
2831
+ pickerContentClassName: l,
2832
+ settingsContentClassName: u
2833
+ }) {
2834
+ const h = n === "toolbar", [p, m] = F(!1), g = ht("interactive");
2835
+ return /* @__PURE__ */ s(
2836
+ "div",
2837
+ {
2838
+ className: X(
2839
+ // Height lives on the shell so the outer border is part of the
2840
+ // h-7 box (matches regular `size="xs"` buttons). Inner triggers
2841
+ // stretch to fill via `h-full`.
2842
+ "relative inline-flex items-stretch overflow-hidden rounded-control border border-input bg-background",
2843
+ h ? "h-8" : "h-7",
2844
+ i
2845
+ ),
2846
+ children: [
2847
+ /* @__PURE__ */ s(He, { open: e, onOpenChange: r, children: [
2848
+ /* @__PURE__ */ t(Qe, { asChild: !0, children: /* @__PURE__ */ s(
2849
+ U,
2850
+ {
2851
+ variant: "ghost",
2852
+ size: "xs",
2853
+ className: X(
2854
+ "h-full rounded-none border-0 bg-transparent pl-2.5 pr-2 shadow-none hover:bg-accent/50 data-[state=open]:bg-accent/60",
2855
+ d
2856
+ ),
2857
+ children: [
2858
+ e ? /* @__PURE__ */ t(Va, { className: "h-3.5 w-3.5" }) : /* @__PURE__ */ t(Kt, { className: "h-3.5 w-3.5" }),
2859
+ "Filter"
2860
+ ]
2861
+ }
2862
+ ) }),
2863
+ /* @__PURE__ */ t(
2864
+ Ge,
2865
+ {
2866
+ align: "end",
2867
+ sideOffset: 6,
2868
+ className: X(
2869
+ "w-auto rounded-card border border-border/60 p-0 shadow-[0_10px_28px_rgba(0,0,0,0.14)] dark:shadow-[0_10px_28px_rgba(0,0,0,0.5)]",
2870
+ l
2871
+ ),
2872
+ style: g.contentStyle,
2873
+ children: o
2874
+ }
2875
+ )
2876
+ ] }),
2877
+ /* @__PURE__ */ s(He, { open: p, onOpenChange: m, children: [
2878
+ /* @__PURE__ */ t(Qe, { asChild: !0, children: /* @__PURE__ */ t(
2879
+ U,
2880
+ {
2881
+ variant: "ghost",
2882
+ size: "xs",
2883
+ className: X(
2884
+ "h-full w-7 rounded-none border-0 border-l border-border/60 bg-transparent px-0 shadow-none hover:bg-accent/50 data-[state=open]:bg-accent/60",
2885
+ c
2886
+ ),
2887
+ "aria-label": "Filter and control actions",
2888
+ children: /* @__PURE__ */ t(Zt, { className: "h-3.5 w-3.5" })
2889
+ }
2890
+ ) }),
2891
+ /* @__PURE__ */ t(
2892
+ Ge,
2893
+ {
2894
+ align: "end",
2895
+ sideOffset: 6,
2896
+ className: X(
2897
+ "w-auto rounded-card border border-border/60 p-0 shadow-[0_10px_28px_rgba(0,0,0,0.14)] dark:shadow-[0_10px_28px_rgba(0,0,0,0.5)]",
2898
+ u
2899
+ ),
2900
+ style: g.contentStyle,
2901
+ children: a(() => m(!1))
2902
+ }
2903
+ )
2904
+ ] })
2905
+ ]
2906
+ }
2907
+ );
2908
+ }
2909
+ function Qn() {
2910
+ Ba();
2911
+ const e = L((l) => l.selectedSheetId), r = L((l) => l.selectedFrameId), o = L((l) => l.dashboard), a = L((l) => l.actions.getSelectedFrame), { setSelectedFrameId: n } = pe(), { setCard: i } = Je(), d = ee((l) => l.card.dataSource);
2912
+ return J(() => {
2913
+ var u, h;
2914
+ let l = a();
2915
+ if (!l) {
2916
+ const p = (u = o == null ? void 0 : o.sheets) == null ? void 0 : u.find((g) => g.id === e), m = (h = p == null ? void 0 : p.frames) == null ? void 0 : h[0];
2917
+ m && (n(m.id), l = m);
2918
+ }
2919
+ if (l) {
2920
+ const p = l.cards.find((m) => m.id === l.activeCardId);
2921
+ p && i(p);
2922
+ }
2923
+ }, [a, e, r, o, n, i]), {
2924
+ hasEntities: !!(d != null && d.selectedEntities && d.selectedEntities.length > 0)
2925
+ };
2926
+ }
2927
+ function Gn() {
2928
+ const e = L((l) => l.dashboard), r = L(
2929
+ (l) => l.semanticExecutionPayload
2930
+ ), o = L((l) => l.actions.addFilter), { hasEntities: a } = Qn(), { isLoading: n } = aa(), i = oe(
2931
+ () => xr(e, r),
2932
+ [e, r]
2933
+ ), c = !yr(e.filters) && i.hasEligibleCards && !n;
2934
+ return /* @__PURE__ */ s("div", { className: "flex h-[520px] w-[400px] flex-col", children: [
2935
+ c && /* @__PURE__ */ t("div", { className: "border-b border-border/60 p-2", children: /* @__PURE__ */ s(
2936
+ "button",
2937
+ {
2938
+ type: "button",
2939
+ onClick: () => o(Cr()),
2940
+ title: `Applies to ${i.eligibleCardCount} of ${i.totalCardCount} date-aware cards`,
2941
+ className: "flex w-full items-start gap-2 rounded-control px-2 py-1.5 text-left outline-none transition-colors hover:bg-muted/40 focus-visible:bg-muted/40 focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-border",
2942
+ children: [
2943
+ /* @__PURE__ */ t(ja, { className: "mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground" }),
2944
+ /* @__PURE__ */ s("span", { className: "flex min-w-0 flex-col", children: [
2945
+ /* @__PURE__ */ t("span", { className: "text-[12px] font-medium text-foreground", children: "Add global date filter" }),
2946
+ /* @__PURE__ */ t("span", { className: "text-[11px] leading-[1.4] text-muted-foreground", children: "One date range across all date-aware cards." })
2947
+ ] })
2948
+ ]
2949
+ }
2950
+ ) }),
2951
+ !a && /* @__PURE__ */ s("div", { className: "flex flex-1 flex-col items-center justify-center px-6 py-8 text-center", children: [
2952
+ /* @__PURE__ */ t(na, { className: "mb-3 h-10 w-10 text-muted-foreground/50" }),
2953
+ /* @__PURE__ */ t("h3", { className: "mb-1 text-[13px] font-medium text-foreground", children: "No fields configured" }),
2954
+ /* @__PURE__ */ t("p", { className: "text-[11px] text-muted-foreground", children: "Configure a data source for this card to enable filtering." })
2955
+ ] }),
2956
+ a && /* @__PURE__ */ t("div", { className: "flex flex-1 overflow-hidden", children: /* @__PURE__ */ t(sa, { context: "filter" }) })
2957
+ ] });
2958
+ }
2959
+ const Mt = !1;
2960
+ function Kn({
2961
+ onAddFilter: e,
2962
+ onAddControl: r,
2963
+ onManageControls: o,
2964
+ onDismiss: a
2965
+ }) {
2966
+ const n = L(
2967
+ (c) => c.dashboard.filterLayout
2968
+ ), { setFilterLayout: i } = pe();
2969
+ n != null && n.displayMode;
2970
+ const d = (n == null ? void 0 : n.toolbarWrap) ?? !1;
2971
+ return n == null || n.showDownloadButton, /* @__PURE__ */ s("div", { className: "w-[300px]", children: [
2972
+ /* @__PURE__ */ s("div", { className: "p-1", children: [
2973
+ /* @__PURE__ */ t(
2974
+ ct,
2975
+ {
2976
+ icon: Kt,
2977
+ label: "Add filter",
2978
+ onClick: () => {
2979
+ e(), a();
2980
+ }
2981
+ }
2982
+ ),
2983
+ /* @__PURE__ */ t(
2984
+ ct,
2985
+ {
2986
+ icon: $t,
2987
+ label: "Add control",
2988
+ onClick: () => {
2989
+ r(), a();
2990
+ }
2991
+ }
2992
+ ),
2993
+ /* @__PURE__ */ t(
2994
+ ct,
2995
+ {
2996
+ icon: Xt,
2997
+ label: "Manage controls",
2998
+ onClick: () => {
2999
+ o(), a();
3000
+ }
3001
+ }
3002
+ )
3003
+ ] }),
3004
+ /* @__PURE__ */ t("div", { className: "border-t border-border/60" }),
3005
+ /* @__PURE__ */ s("div", { className: "space-y-1 p-2", children: [
3006
+ /* @__PURE__ */ t("p", { className: "px-1 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Display" }),
3007
+ Mt,
3008
+ /* @__PURE__ */ t(
3009
+ Xn,
3010
+ {
3011
+ id: "filter-display-wrap",
3012
+ label: "Wrap to multiple lines",
3013
+ checked: d,
3014
+ onCheckedChange: (c) => i({ toolbarWrap: c === !0 })
3015
+ }
3016
+ ),
3017
+ Mt
3018
+ ] })
3019
+ ] });
3020
+ }
3021
+ function ct({
3022
+ icon: e,
3023
+ label: r,
3024
+ onClick: o
3025
+ }) {
3026
+ return /* @__PURE__ */ s(
3027
+ "button",
3028
+ {
3029
+ type: "button",
3030
+ onClick: o,
3031
+ className: "flex w-full items-center gap-2 rounded-control px-2 py-1.5 text-left text-[13px] text-foreground outline-none transition-colors hover:bg-muted/40 focus-visible:bg-muted/40",
3032
+ children: [
3033
+ /* @__PURE__ */ t(e, { className: "h-3.5 w-3.5 text-muted-foreground" }),
3034
+ r
3035
+ ]
3036
+ }
3037
+ );
3038
+ }
3039
+ function Xn({
3040
+ id: e,
3041
+ label: r,
3042
+ checked: o,
3043
+ onCheckedChange: a
3044
+ }) {
3045
+ return /* @__PURE__ */ s("div", { className: "flex items-center gap-2 rounded-control px-1 py-1 transition-colors hover:bg-muted/40 focus-within:bg-muted/40", children: [
3046
+ /* @__PURE__ */ t(Ct, { id: e, checked: o, onCheckedChange: a }),
3047
+ /* @__PURE__ */ t(
3048
+ Te,
3049
+ {
3050
+ htmlFor: e,
3051
+ className: "cursor-pointer text-[12px] font-normal leading-[1.3]",
3052
+ children: r
3053
+ }
3054
+ )
3055
+ ] });
3056
+ }
3057
+ function Qs({
3058
+ size: e,
3059
+ className: r,
3060
+ primaryButtonClassName: o,
3061
+ secondaryButtonClassName: a,
3062
+ pickerContentClassName: n,
3063
+ settingsContentClassName: i
3064
+ }) {
3065
+ var y;
3066
+ const [d, c] = F(null), l = L((w) => w.dashboard), u = L((w) => w.selectedSheetId), h = L((w) => w.showFilters), p = L((w) => w.actions), { setDocumentPanelTarget: m, setShowFilters: g } = p, f = (y = l.sheets) == null ? void 0 : y.find(
3067
+ (w) => w.id === u
3068
+ ), b = wr(f), k = j((w) => {
3069
+ window.setTimeout(() => {
3070
+ c(w);
3071
+ }, 0);
3072
+ }, []), v = j(
3073
+ (w) => {
3074
+ if (b && u) {
3075
+ w && m(u, {
3076
+ kind: "document",
3077
+ group: "inputs"
3078
+ });
3079
+ return;
3080
+ }
3081
+ g(w);
3082
+ },
3083
+ [
3084
+ b,
3085
+ u,
3086
+ m,
3087
+ g
3088
+ ]
3089
+ ), D = j(() => {
3090
+ v(!0);
3091
+ }, [v]), E = j(() => {
3092
+ k("create");
3093
+ }, [k]), N = j(() => {
3094
+ k("manage");
3095
+ }, [k]);
3096
+ return /* @__PURE__ */ s($, { children: [
3097
+ /* @__PURE__ */ t(
3098
+ Hn,
3099
+ {
3100
+ showFilters: b ? !1 : h,
3101
+ onShowFiltersChange: v,
3102
+ pickerContent: /* @__PURE__ */ t(Gn, {}),
3103
+ settingsContent: (w) => /* @__PURE__ */ t(
3104
+ Kn,
3105
+ {
3106
+ onAddFilter: D,
3107
+ onAddControl: E,
3108
+ onManageControls: N,
3109
+ onDismiss: w
3110
+ }
3111
+ ),
3112
+ size: e,
3113
+ className: r,
3114
+ primaryButtonClassName: o,
3115
+ secondaryButtonClassName: a,
3116
+ pickerContentClassName: n,
3117
+ settingsContentClassName: i
3118
+ }
3119
+ ),
3120
+ d ? b ? /* @__PURE__ */ t(
3121
+ $n,
3122
+ {
3123
+ open: !0,
3124
+ onOpenChange: (w) => {
3125
+ w || c(null);
3126
+ },
3127
+ initialMode: d
3128
+ }
3129
+ ) : /* @__PURE__ */ t(
3130
+ _n,
3131
+ {
3132
+ open: !0,
3133
+ onOpenChange: (w) => {
3134
+ w || c(null);
3135
+ },
3136
+ showTrigger: !1,
3137
+ initialMode: d
3138
+ }
3139
+ ) : null
3140
+ ] });
3141
+ }
3142
+ function Yn({
3143
+ disabled: e,
3144
+ briefingCount: r,
3145
+ className: o,
3146
+ onClick: a
3147
+ }) {
3148
+ const n = typeof r == "number" && r > 0;
3149
+ return /* @__PURE__ */ s(
3150
+ U,
3151
+ {
3152
+ type: "button",
3153
+ size: "xs",
3154
+ variant: "outline",
3155
+ disabled: e,
3156
+ className: X("gap-1.5", o),
3157
+ onClick: a,
3158
+ "aria-label": "Reports & briefings",
3159
+ children: [
3160
+ /* @__PURE__ */ t(Qa, { className: "h-3.5 w-3.5" }),
3161
+ "Reports & briefings",
3162
+ n ? /* @__PURE__ */ t("span", { className: "ml-0.5 rounded-control bg-muted px-1 text-[10px] tabular-nums text-foreground/70", children: r }) : null
3163
+ ]
3164
+ }
3165
+ );
3166
+ }
3167
+ const Zn = "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", ur = "inline-flex h-7 items-center gap-1.5 rounded-control px-2 text-[12px] text-muted-foreground hover:bg-muted hover:text-foreground disabled:opacity-50", We = "inline-flex h-7 items-center gap-1.5 rounded-control bg-primary px-3 text-[12px] font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50";
3168
+ function Jn(e) {
3169
+ return e === "dashboard" ? "This dashboard" : "Project";
3170
+ }
3171
+ function es(e) {
3172
+ if (!e) return "Never";
3173
+ const r = new Date(e);
3174
+ if (Number.isNaN(r.getTime())) return "Unknown";
3175
+ const o = Date.now() - r.getTime(), a = Math.round(o / 6e4);
3176
+ if (a < 1) return "now";
3177
+ if (a < 60) return `${a}m ago`;
3178
+ const n = Math.round(a / 60);
3179
+ if (n < 24) return `${n}h ago`;
3180
+ const i = Math.round(n / 24);
3181
+ if (i < 7) return `${i}d ago`;
3182
+ const d = Math.round(i / 7);
3183
+ return d < 5 ? `${d}w ago` : `${Math.round(i / 30)}mo ago`;
3184
+ }
3185
+ function ts(e) {
3186
+ return e.scheduleExpr ? Oa(
3187
+ e.scheduleExpr,
3188
+ e.timezone || "UTC"
3189
+ ) ?? "Invalid schedule" : "On demand";
3190
+ }
3191
+ function rs(e) {
3192
+ if (e.lastRunStatus) {
3193
+ const r = e.lastRunStatus.toString().toUpperCase();
3194
+ return r === "SUCCESS" ? "Last run completed." : r === "FAILED" ? "Last run failed." : `Last run ${e.lastRunStatus.toString().toLowerCase()}`;
3195
+ }
3196
+ return null;
3197
+ }
3198
+ function hr(e) {
3199
+ return e.hasActiveRun ? "Running" : e.lastRunStatus ? `Last run ${e.lastRunStatus.toString().toLowerCase()}` : "Idle";
3200
+ }
3201
+ function as(e) {
3202
+ return e.source.type === "dashboard" ? "This dashboard" : "Project";
3203
+ }
3204
+ function ns({
3205
+ activeView: e,
3206
+ onChange: r
3207
+ }) {
3208
+ return /* @__PURE__ */ t(
3209
+ "div",
3210
+ {
3211
+ className: "flex shrink-0 items-center gap-1 rounded-control bg-muted p-0.5",
3212
+ role: "tablist",
3213
+ "aria-label": "Briefing source view",
3214
+ children: ["dashboard", "project"].map((o) => {
3215
+ const a = e === o;
3216
+ return /* @__PURE__ */ t(
3217
+ "button",
3218
+ {
3219
+ type: "button",
3220
+ role: "tab",
3221
+ "aria-selected": a,
3222
+ onClick: () => r(o),
3223
+ className: X(
3224
+ "h-6 rounded-[3px] px-2 text-[11px] transition-colors",
3225
+ a ? "bg-background font-medium text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"
3226
+ ),
3227
+ children: Jn(o)
3228
+ },
3229
+ o
3230
+ );
3231
+ })
3232
+ }
3233
+ );
3234
+ }
3235
+ function ss({
3236
+ briefings: e,
3237
+ dashboardLabel: r,
3238
+ sourceView: o,
3239
+ error: a,
3240
+ loading: n,
3241
+ onSourceViewChange: i,
3242
+ onClose: d,
3243
+ onEdit: c,
3244
+ onNew: l,
3245
+ canCreate: u,
3246
+ canCreateScheduledReport: h,
3247
+ analyticalBriefingsEnabled: p,
3248
+ onRunNow: m,
3249
+ onTogglePause: g,
3250
+ onDelete: f,
3251
+ selectingId: b,
3252
+ busyId: k,
3253
+ manageBriefingsHref: v,
3254
+ contentKind: D,
3255
+ hideHeader: E = !1
3256
+ }) {
3257
+ const N = e.length, y = e.filter((I) => I.status === "ACTIVE").length, w = D === "reports" ? N === 1 ? "report" : "reports" : D === "briefings" ? N === 1 ? "briefing" : "briefings" : N === 1 ? "item" : "items", S = e.find((I) => I.hasActiveRun) ?? null, x = D ?? "reports & briefings", B = o === "dashboard" ? r : `Project ${x}`;
3258
+ return /* @__PURE__ */ s(
3259
+ "section",
3260
+ {
3261
+ "aria-label": `Dashboard ${x.replace("&", "and")}`,
3262
+ className: "flex h-full min-h-0 flex-col bg-background text-foreground",
3263
+ children: [
3264
+ E ? null : /* @__PURE__ */ s("header", { className: "flex items-start justify-between gap-3 border-b border-border px-4 py-3", children: [
3265
+ /* @__PURE__ */ s("div", { className: "min-w-0", children: [
3266
+ /* @__PURE__ */ t("div", { className: Zn, children: x }),
3267
+ /* @__PURE__ */ t("h2", { className: "mt-0.5 truncate text-[14px] font-semibold leading-5", children: B })
3268
+ ] }),
3269
+ /* @__PURE__ */ t(
3270
+ "button",
3271
+ {
3272
+ type: "button",
3273
+ onClick: d,
3274
+ className: "rounded-control p-1 text-muted-foreground hover:bg-muted hover:text-foreground",
3275
+ "aria-label": `Close ${x.replace("&", "and")} panel`,
3276
+ children: /* @__PURE__ */ t(Me, { className: "h-3.5 w-3.5" })
3277
+ }
3278
+ )
3279
+ ] }),
3280
+ /* @__PURE__ */ s("div", { className: "flex items-center justify-between gap-3 border-b border-border px-4 py-2", children: [
3281
+ /* @__PURE__ */ s("div", { className: "flex min-w-0 items-center gap-3", children: [
3282
+ /* @__PURE__ */ t(
3283
+ ns,
3284
+ {
3285
+ activeView: o,
3286
+ onChange: i
3287
+ }
3288
+ ),
3289
+ /* @__PURE__ */ t("div", { className: "flex min-w-0 items-center gap-1.5 text-[11px] text-muted-foreground", children: n && N === 0 ? /* @__PURE__ */ s("span", { children: [
3290
+ "Loading ",
3291
+ x,
3292
+ "…"
3293
+ ] }) : N === 0 ? /* @__PURE__ */ s("span", { children: [
3294
+ "No ",
3295
+ x,
3296
+ " yet"
3297
+ ] }) : /* @__PURE__ */ s($, { children: [
3298
+ /* @__PURE__ */ s("span", { className: "font-medium text-foreground/80", children: [
3299
+ N,
3300
+ " ",
3301
+ w
3302
+ ] }),
3303
+ /* @__PURE__ */ t("span", { className: "text-border", children: "·" }),
3304
+ /* @__PURE__ */ s("span", { children: [
3305
+ y,
3306
+ " active"
3307
+ ] })
3308
+ ] }) })
3309
+ ] }),
3310
+ /* @__PURE__ */ s("div", { className: "flex items-center gap-1.5", children: [
3311
+ n ? (
3312
+ // Auto-refresh on open; surface a quiet spinner near the count
3313
+ // when a manual reload is in flight, but don't show a separate
3314
+ // refresh button — close+reopen handles the rare "stale list"
3315
+ // case without crowding the toolbar.
3316
+ /* @__PURE__ */ t(ie, { className: "h-3.5 w-3.5 animate-spin text-muted-foreground" })
3317
+ ) : null,
3318
+ N > 0 && u ? p && h ? /* @__PURE__ */ s(rt, { children: [
3319
+ /* @__PURE__ */ t(at, { asChild: !0, children: /* @__PURE__ */ s("button", { className: We, children: [
3320
+ /* @__PURE__ */ t(Se, { className: "h-3 w-3" }),
3321
+ " New"
3322
+ ] }) }),
3323
+ /* @__PURE__ */ s(nt, { align: "end", children: [
3324
+ /* @__PURE__ */ t(Y, { onClick: () => l("scheduled_report"), children: "Schedule a report" }),
3325
+ /* @__PURE__ */ t(
3326
+ Y,
3327
+ {
3328
+ onClick: () => l("analytical_briefing"),
3329
+ children: "Create analytical briefing"
3330
+ }
3331
+ )
3332
+ ] })
3333
+ ] }) : h ? /* @__PURE__ */ s(
3334
+ "button",
3335
+ {
3336
+ onClick: () => l("scheduled_report"),
3337
+ className: We,
3338
+ children: [
3339
+ /* @__PURE__ */ t(Se, { className: "h-3 w-3" }),
3340
+ " Schedule report"
3341
+ ]
3342
+ }
3343
+ ) : p ? /* @__PURE__ */ s(
3344
+ "button",
3345
+ {
3346
+ onClick: () => l("analytical_briefing"),
3347
+ className: We,
3348
+ children: [
3349
+ /* @__PURE__ */ t(Se, { className: "h-3 w-3" }),
3350
+ " New briefing"
3351
+ ]
3352
+ }
3353
+ ) : null : null
3354
+ ] })
3355
+ ] }),
3356
+ S ? /* @__PURE__ */ s("div", { className: "flex items-center gap-2 border-b border-border bg-muted/60 px-4 py-2 text-[12px]", children: [
3357
+ /* @__PURE__ */ t(ie, { className: "h-3 w-3 shrink-0 animate-spin text-muted-foreground" }),
3358
+ /* @__PURE__ */ t("span", { className: "font-medium text-foreground", children: S.name }),
3359
+ /* @__PURE__ */ t("span", { className: "text-border", children: "·" }),
3360
+ /* @__PURE__ */ t("span", { className: "truncate text-muted-foreground", children: hr(S) })
3361
+ ] }) : null,
3362
+ /* @__PURE__ */ s("div", { className: "flex-1 overflow-y-auto", children: [
3363
+ a ? /* @__PURE__ */ t("div", { className: "m-4 rounded-card border border-destructive/30 bg-destructive/10 px-3 py-2 text-[12px] text-destructive", children: a }) : null,
3364
+ !n && e.length === 0 && !a ? /* @__PURE__ */ t(
3365
+ os,
3366
+ {
3367
+ onNew: l,
3368
+ canCreate: u,
3369
+ canCreateScheduledReport: h,
3370
+ analyticalBriefingsEnabled: p,
3371
+ contentKind: D
3372
+ }
3373
+ ) : null,
3374
+ e.map((I) => /* @__PURE__ */ t(
3375
+ ls,
3376
+ {
3377
+ briefing: I,
3378
+ isOpening: b === I.id,
3379
+ isBusy: k === I.id,
3380
+ onOpen: () => c(I.id),
3381
+ onRunNow: () => m(I),
3382
+ onTogglePause: () => g(I),
3383
+ onDelete: () => f(I)
3384
+ },
3385
+ I.id
3386
+ ))
3387
+ ] }),
3388
+ v ? /* @__PURE__ */ t("div", { className: "border-t border-border px-4 py-2.5", children: /* @__PURE__ */ s(
3389
+ "a",
3390
+ {
3391
+ href: v,
3392
+ className: X(ur, "h-6 px-1 text-[11px]"),
3393
+ children: [
3394
+ "Manage all reports & briefings",
3395
+ /* @__PURE__ */ t(za, { className: "h-3 w-3" })
3396
+ ]
3397
+ }
3398
+ ) }) : null
3399
+ ]
3400
+ }
3401
+ );
3402
+ }
3403
+ function os({
3404
+ onNew: e,
3405
+ canCreate: r,
3406
+ canCreateScheduledReport: o,
3407
+ analyticalBriefingsEnabled: a,
3408
+ contentKind: n
3409
+ }) {
3410
+ const i = n === "reports" ? {
3411
+ title: "No reports yet",
3412
+ description: "Schedule an emailed dashboard or visual report to see it here."
3413
+ } : n === "briefings" ? {
3414
+ title: "No briefings yet",
3415
+ description: "Create an analytical briefing to monitor this dashboard and brief your team."
3416
+ } : null;
3417
+ return /* @__PURE__ */ s("div", { className: "flex h-full flex-col items-center justify-center px-8 py-12 text-center", children: [
3418
+ /* @__PURE__ */ t(is, { className: "mb-5 h-[88px] w-[112px] text-border" }),
3419
+ /* @__PURE__ */ t("div", { className: "text-[13px] font-medium text-foreground", children: (i == null ? void 0 : i.title) ?? "Have an analyst brief your team" }),
3420
+ /* @__PURE__ */ t("p", { className: "mt-1.5 max-w-[320px] text-[12px] leading-5 text-muted-foreground", children: (i == null ? void 0 : i.description) ?? "Describe what to watch. An analyst digs into this dashboard and the data behind it, then briefs your team on the cadence you choose." }),
3421
+ r ? /* @__PURE__ */ s("div", { className: "mt-4 flex flex-wrap justify-center gap-2", children: [
3422
+ o ? /* @__PURE__ */ s(
3423
+ "button",
3424
+ {
3425
+ onClick: () => e("scheduled_report"),
3426
+ className: We,
3427
+ children: [
3428
+ /* @__PURE__ */ t(Se, { className: "h-3 w-3" }),
3429
+ " Schedule a report"
3430
+ ]
3431
+ }
3432
+ ) : null,
3433
+ a ? /* @__PURE__ */ t(
3434
+ "button",
3435
+ {
3436
+ onClick: () => e("analytical_briefing"),
3437
+ className: ur,
3438
+ children: "Create analytical briefing"
3439
+ }
3440
+ ) : null
3441
+ ] }) : null
3442
+ ] });
3443
+ }
3444
+ function is({ className: e }) {
3445
+ return /* @__PURE__ */ s(
3446
+ "svg",
3447
+ {
3448
+ viewBox: "0 0 112 88",
3449
+ fill: "none",
3450
+ xmlns: "http://www.w3.org/2000/svg",
3451
+ role: "presentation",
3452
+ "aria-hidden": "true",
3453
+ className: e,
3454
+ children: [
3455
+ /* @__PURE__ */ t(
3456
+ "rect",
3457
+ {
3458
+ x: "22",
3459
+ y: "6",
3460
+ width: "60",
3461
+ height: "72",
3462
+ rx: "3",
3463
+ stroke: "currentColor",
3464
+ strokeWidth: "1.25"
3465
+ }
3466
+ ),
3467
+ /* @__PURE__ */ t(
3468
+ "line",
3469
+ {
3470
+ x1: "30",
3471
+ y1: "16",
3472
+ x2: "64",
3473
+ y2: "16",
3474
+ stroke: "currentColor",
3475
+ strokeWidth: "1.5",
3476
+ strokeLinecap: "round"
3477
+ }
3478
+ ),
3479
+ /* @__PURE__ */ t(
3480
+ "line",
3481
+ {
3482
+ x1: "30",
3483
+ y1: "21",
3484
+ x2: "52",
3485
+ y2: "21",
3486
+ stroke: "currentColor",
3487
+ strokeWidth: "1",
3488
+ strokeLinecap: "round",
3489
+ opacity: "0.5"
3490
+ }
3491
+ ),
3492
+ /* @__PURE__ */ t("circle", { cx: "31", cy: "32", r: "1", fill: "currentColor", opacity: "0.6" }),
3493
+ /* @__PURE__ */ t(
3494
+ "line",
3495
+ {
3496
+ x1: "35",
3497
+ y1: "32",
3498
+ x2: "72",
3499
+ y2: "32",
3500
+ stroke: "currentColor",
3501
+ strokeWidth: "1",
3502
+ opacity: "0.4",
3503
+ strokeLinecap: "round"
3504
+ }
3505
+ ),
3506
+ /* @__PURE__ */ t("circle", { cx: "31", cy: "38", r: "1", fill: "currentColor", opacity: "0.6" }),
3507
+ /* @__PURE__ */ t(
3508
+ "line",
3509
+ {
3510
+ x1: "35",
3511
+ y1: "38",
3512
+ x2: "68",
3513
+ y2: "38",
3514
+ stroke: "currentColor",
3515
+ strokeWidth: "1",
3516
+ opacity: "0.4",
3517
+ strokeLinecap: "round"
3518
+ }
3519
+ ),
3520
+ /* @__PURE__ */ t("circle", { cx: "31", cy: "44", r: "1", fill: "currentColor", opacity: "0.6" }),
3521
+ /* @__PURE__ */ t(
3522
+ "line",
3523
+ {
3524
+ x1: "35",
3525
+ y1: "44",
3526
+ x2: "74",
3527
+ y2: "44",
3528
+ stroke: "currentColor",
3529
+ strokeWidth: "1",
3530
+ opacity: "0.4",
3531
+ strokeLinecap: "round"
3532
+ }
3533
+ ),
3534
+ /* @__PURE__ */ t(
3535
+ "rect",
3536
+ {
3537
+ x: "30",
3538
+ y: "64",
3539
+ width: "5",
3540
+ height: "8",
3541
+ rx: "0.5",
3542
+ fill: "currentColor",
3543
+ opacity: "0.55"
3544
+ }
3545
+ ),
3546
+ /* @__PURE__ */ t(
3547
+ "rect",
3548
+ {
3549
+ x: "38",
3550
+ y: "60",
3551
+ width: "5",
3552
+ height: "12",
3553
+ rx: "0.5",
3554
+ fill: "currentColor",
3555
+ opacity: "0.7"
3556
+ }
3557
+ ),
3558
+ /* @__PURE__ */ t(
3559
+ "rect",
3560
+ {
3561
+ x: "46",
3562
+ y: "56",
3563
+ width: "5",
3564
+ height: "16",
3565
+ rx: "0.5",
3566
+ fill: "currentColor",
3567
+ opacity: "0.85"
3568
+ }
3569
+ ),
3570
+ /* @__PURE__ */ t(
3571
+ "rect",
3572
+ {
3573
+ x: "54",
3574
+ y: "62",
3575
+ width: "5",
3576
+ height: "10",
3577
+ rx: "0.5",
3578
+ fill: "currentColor",
3579
+ opacity: "0.6"
3580
+ }
3581
+ ),
3582
+ /* @__PURE__ */ t(
3583
+ "rect",
3584
+ {
3585
+ x: "62",
3586
+ y: "58",
3587
+ width: "5",
3588
+ height: "14",
3589
+ rx: "0.5",
3590
+ fill: "currentColor",
3591
+ opacity: "0.75"
3592
+ }
3593
+ ),
3594
+ /* @__PURE__ */ t(
3595
+ "circle",
3596
+ {
3597
+ cx: "86",
3598
+ cy: "62",
3599
+ r: "10",
3600
+ fill: "var(--background, white)",
3601
+ stroke: "currentColor",
3602
+ strokeWidth: "1.25"
3603
+ }
3604
+ ),
3605
+ /* @__PURE__ */ t(
3606
+ "line",
3607
+ {
3608
+ x1: "93.5",
3609
+ y1: "69.5",
3610
+ x2: "100",
3611
+ y2: "76",
3612
+ stroke: "currentColor",
3613
+ strokeWidth: "1.5",
3614
+ strokeLinecap: "round"
3615
+ }
3616
+ )
3617
+ ]
3618
+ }
3619
+ );
3620
+ }
3621
+ function ls({
3622
+ briefing: e,
3623
+ isOpening: r,
3624
+ isBusy: o,
3625
+ onOpen: a,
3626
+ onRunNow: n,
3627
+ onTogglePause: i,
3628
+ onDelete: d
3629
+ }) {
3630
+ const c = e.status === "PAUSED", l = e.hasActiveRun, u = rs(e), h = es(e.lastRunAt), p = e.lastRunStatus, m = me(e), g = p === "SUCCESS" ? ze.success.dot : p === "FAILED" ? ze.danger.dot : p ? ze.warning.dot : ze.neutral.dot;
3631
+ return /* @__PURE__ */ s(
3632
+ "div",
3633
+ {
3634
+ className: X(
3635
+ "group relative border-b border-border/60 px-4 py-3 transition-colors hover:bg-muted/60",
3636
+ c && "opacity-70"
3637
+ ),
3638
+ children: [
3639
+ /* @__PURE__ */ s(
3640
+ "div",
3641
+ {
3642
+ role: "button",
3643
+ tabIndex: 0,
3644
+ onClick: a,
3645
+ onKeyDown: (f) => {
3646
+ (f.key === "Enter" || f.key === " ") && (f.preventDefault(), a());
3647
+ },
3648
+ className: "cursor-pointer pr-8",
3649
+ children: [
3650
+ /* @__PURE__ */ s("div", { className: "flex min-w-0 items-center gap-2", children: [
3651
+ /* @__PURE__ */ t("span", { className: "truncate text-[13px] font-medium text-foreground", children: e.name }),
3652
+ c ? /* @__PURE__ */ t("span", { className: "shrink-0 text-[11px] text-muted-foreground", children: "· Paused" }) : null
3653
+ ] }),
3654
+ /* @__PURE__ */ s("div", { className: "mt-1 flex flex-wrap items-center gap-x-1.5 text-[11px] text-muted-foreground", children: [
3655
+ /* @__PURE__ */ t("span", { children: m.typeLabel }),
3656
+ /* @__PURE__ */ t("span", { className: "text-border", children: "·" }),
3657
+ /* @__PURE__ */ t("span", { children: as(e) }),
3658
+ /* @__PURE__ */ t("span", { className: "text-border", children: "·" }),
3659
+ /* @__PURE__ */ t(oa, { className: "h-3 w-3" }),
3660
+ /* @__PURE__ */ t("span", { className: "truncate", children: ts(e) }),
3661
+ e.lastRunAt ? /* @__PURE__ */ s($, { children: [
3662
+ /* @__PURE__ */ t("span", { className: "text-border", children: "·" }),
3663
+ /* @__PURE__ */ s("span", { children: [
3664
+ "Last run ",
3665
+ h
3666
+ ] })
3667
+ ] }) : null
3668
+ ] }),
3669
+ u || l ? /* @__PURE__ */ s("div", { className: "mt-1.5 flex items-center gap-1.5 text-[12px] leading-[1.5] text-foreground/80", children: [
3670
+ l ? /* @__PURE__ */ t(ie, { className: "h-3 w-3 shrink-0 animate-spin text-muted-foreground/70" }) : /* @__PURE__ */ t(
3671
+ "span",
3672
+ {
3673
+ className: X(
3674
+ "inline-block h-1.5 w-1.5 shrink-0 rounded-full",
3675
+ g
3676
+ )
3677
+ }
3678
+ ),
3679
+ /* @__PURE__ */ t("span", { className: "truncate", children: l ? hr(e) : u })
3680
+ ] }) : null
3681
+ ]
3682
+ }
3683
+ ),
3684
+ /* @__PURE__ */ t("div", { className: "absolute right-3 top-3", children: o ? /* @__PURE__ */ t(ie, { className: "h-3.5 w-3.5 animate-spin text-muted-foreground/70" }) : r ? /* @__PURE__ */ t(ie, { className: "h-3.5 w-3.5 animate-spin text-muted-foreground/70" }) : /* @__PURE__ */ s(rt, { children: [
3685
+ /* @__PURE__ */ t(at, { asChild: !0, children: /* @__PURE__ */ t(
3686
+ "button",
3687
+ {
3688
+ type: "button",
3689
+ onClick: (f) => f.stopPropagation(),
3690
+ className: "inline-flex h-6 w-6 items-center justify-center rounded-control text-muted-foreground/70 opacity-60 hover:bg-muted hover:text-foreground/80 focus-visible:opacity-100 group-hover:opacity-100",
3691
+ "aria-label": `${m.noun === "report" ? "Report" : "Briefing"} actions`,
3692
+ children: /* @__PURE__ */ t(Wt, { className: "h-3.5 w-3.5" })
3693
+ }
3694
+ ) }),
3695
+ /* @__PURE__ */ s(nt, { align: "end", className: "w-44", children: [
3696
+ /* @__PURE__ */ s(Y, { onClick: a, children: [
3697
+ /* @__PURE__ */ t(Xt, { className: "h-3.5 w-3.5" }),
3698
+ "Edit ",
3699
+ m.noun
3700
+ ] }),
3701
+ /* @__PURE__ */ s(
3702
+ Y,
3703
+ {
3704
+ onClick: (f) => {
3705
+ f.preventDefault(), n();
3706
+ },
3707
+ children: [
3708
+ /* @__PURE__ */ t(ia, { className: "h-3.5 w-3.5" }),
3709
+ "Run now"
3710
+ ]
3711
+ }
3712
+ ),
3713
+ e.scheduleExpr ? /* @__PURE__ */ t(
3714
+ Y,
3715
+ {
3716
+ onClick: (f) => {
3717
+ f.preventDefault(), i();
3718
+ },
3719
+ children: c ? /* @__PURE__ */ s($, { children: [
3720
+ /* @__PURE__ */ t(la, { className: "h-3.5 w-3.5" }),
3721
+ "Resume"
3722
+ ] }) : /* @__PURE__ */ s($, { children: [
3723
+ /* @__PURE__ */ t(ca, { className: "h-3.5 w-3.5" }),
3724
+ "Pause"
3725
+ ] })
3726
+ }
3727
+ ) : null,
3728
+ /* @__PURE__ */ t(Xe, {}),
3729
+ /* @__PURE__ */ s(
3730
+ Y,
3731
+ {
3732
+ onClick: (f) => {
3733
+ f.preventDefault(), d();
3734
+ },
3735
+ className: "text-destructive focus:bg-destructive/10 focus:text-destructive",
3736
+ children: [
3737
+ /* @__PURE__ */ t(Ke, { className: "h-3.5 w-3.5" }),
3738
+ "Delete ",
3739
+ m.noun
3740
+ ]
3741
+ }
3742
+ )
3743
+ ] })
3744
+ ] }) })
3745
+ ]
3746
+ }
3747
+ );
3748
+ }
3749
+ const cs = 2e3, ds = 20 * 6e4;
3750
+ function us(e) {
3751
+ return (e == null ? void 0 : e.trim()) || "This dashboard";
3752
+ }
3753
+ function hs(e) {
3754
+ return e === "This dashboard" ? "Watch this dashboard" : `Watch ${e}`;
3755
+ }
3756
+ function ms(e, r, o) {
3757
+ return r !== "dashboard" ? e : e.filter(
3758
+ (a) => a.source.type === "dashboard" && a.source.dashboardId === o
3759
+ );
3760
+ }
3761
+ async function ps(e) {
3762
+ const o = [];
3763
+ let a = 1, n = 0, i = Number.POSITIVE_INFINITY;
3764
+ for (; n < i; ) {
3765
+ const d = await e.apiClient.listBriefings(
3766
+ e.apiServiceUrl,
3767
+ e.token,
3768
+ { scope: "organization", page: a, pageSize: 100 }
3769
+ );
3770
+ if (o.push(...d.briefings), n += d.briefings.length, i = d.total, d.briefings.length === 0 || n >= i) break;
3771
+ a += 1;
3772
+ }
3773
+ return o;
3774
+ }
3775
+ const fs = {
3776
+ listBriefings: ba,
3777
+ getBriefing: ga,
3778
+ pauseBriefing: fa,
3779
+ resumeBriefing: pa,
3780
+ deleteBriefing: ma,
3781
+ runBriefingNow: ha
3782
+ };
3783
+ function gs({
3784
+ briefingId: e,
3785
+ initialRun: r,
3786
+ apiServiceUrl: o,
3787
+ token: a,
3788
+ onTerminal: n,
3789
+ onTimeout: i,
3790
+ onExpand: d
3791
+ }) {
3792
+ const [c, l] = F(r), { startRun: u } = Da({
3793
+ apiServiceUrl: o,
3794
+ token: a,
3795
+ intervalMs: cs,
3796
+ timeoutMs: ds,
3797
+ fetchRun: ({
3798
+ apiServiceUrl: p,
3799
+ token: m,
3800
+ runId: g
3801
+ }) => Ea(p, m, e, g),
3802
+ onRun: (p) => {
3803
+ l(p);
3804
+ },
3805
+ onTerminalRun: (p) => {
3806
+ n(p);
3807
+ },
3808
+ onTimeout: () => {
3809
+ i();
3810
+ }
3811
+ }), h = ge(!1);
3812
+ return J(() => {
3813
+ h.current || (h.current = !0, ka(r.status) ? u(r) : Aa(r.status) && n(r));
3814
+ }, [r, n, u]), /* @__PURE__ */ t(Ia, { run: c, onExpand: d });
3815
+ }
3816
+ function Gs(e) {
3817
+ return /* @__PURE__ */ t(da, { children: /* @__PURE__ */ t(bs, { ...e }) });
3818
+ }
3819
+ function bs({
3820
+ dashboardId: e,
3821
+ dashboardTitle: r,
3822
+ apiServiceUrl: o,
3823
+ token: a,
3824
+ disabled: n,
3825
+ className: i,
3826
+ manageBriefingsHref: d,
3827
+ open: c,
3828
+ onOpenChange: l,
3829
+ hideTrigger: u = !1,
3830
+ workflowIntent: h,
3831
+ client: p
3832
+ }) {
3833
+ const { authToken: m, tokenProps: g } = Be(), f = ua(), b = !h || f.canCreate && (h === "scheduled_report" || f.analyticalBriefingsEnabled), [k, v] = F(!1), D = c ?? k, E = (A) => {
3834
+ c === void 0 && v(A), l == null || l(A);
3835
+ }, [N, y] = F(
3836
+ h ? "author" : "list"
3837
+ ), [w, S] = F(
3838
+ h ?? "analytical_briefing"
3839
+ ), [x, B] = F("dashboard"), [I, W] = F(
3840
+ []
3841
+ ), [P, M] = F(null), Z = h && !b && !P ? "list" : N, [K, Ce] = F(!1), [ce, O] = F(null), [te, re] = F(null), [T, ae] = F(
3842
+ null
3843
+ ), [le, G] = F(null), be = ge(null), ke = ge(D);
3844
+ J(() => {
3845
+ const A = D && !ke.current;
3846
+ ke.current = D, !(!A || !h) && (M(null), B("dashboard"), S(h), y("author"), G(null));
3847
+ }, [D, h]);
3848
+ const [ve, we] = F(
3849
+ null
3850
+ ), [se, Ae] = F(null), q = o ?? (g == null ? void 0 : g.apiServiceUrl), H = a ?? (m == null ? void 0 : m.accessToken), he = oe(() => ({ ...fs, ...p }), [p]), Ne = us(r), _e = oe(() => {
3851
+ const A = ms(
3852
+ I,
3853
+ x,
3854
+ e
3855
+ );
3856
+ if (!h)
3857
+ return A;
3858
+ const _ = h === "scheduled_report" ? "report" : "briefing";
3859
+ return A.filter(
3860
+ (Oe) => me(Oe).noun === _
3861
+ );
3862
+ }, [e, I, x, h]), st = oe(() => x === "dashboard" ? {
3863
+ source: { type: "dashboard", dashboardId: e },
3864
+ label: Ne,
3865
+ detail: hs(Ne)
3866
+ } : {
3867
+ source: { type: "project" },
3868
+ label: "This project",
3869
+ detail: "Use any data in this project."
3870
+ }, [e, Ne, x]), Ie = !!(q && H), Fe = $a({
3871
+ canCreate: f.canCreate,
3872
+ analyticalBriefingsEnabled: f.analyticalBriefingsEnabled,
3873
+ scheduledReportAvailable: x === "dashboard"
3874
+ }), ne = j(async () => {
3875
+ if (!(!q || !H)) {
3876
+ Ce(!0), G(null);
3877
+ try {
3878
+ W(
3879
+ await ps({
3880
+ apiClient: he,
3881
+ apiServiceUrl: q,
3882
+ token: H
3883
+ })
3884
+ );
3885
+ } catch (A) {
3886
+ G(
3887
+ A instanceof Error ? A.message : "Could not load briefings."
3888
+ );
3889
+ } finally {
3890
+ Ce(!1);
3891
+ }
3892
+ }
3893
+ }, [he, q, H]);
3894
+ J(() => {
3895
+ !D || Z !== "list" || !Ie || ne();
3896
+ }, [Ie, Z, ne, D]);
3897
+ const Pe = () => {
3898
+ M(null), B("dashboard"), y("list"), E(!0);
3899
+ }, C = (A) => {
3900
+ M(null), S(A), y("author");
3901
+ }, V = async (A) => {
3902
+ if (!(!q || !H)) {
3903
+ O(A), G(null);
3904
+ try {
3905
+ const _ = await he.getBriefing(
3906
+ q,
3907
+ H,
3908
+ A
3909
+ );
3910
+ M(_.briefing), y("author");
3911
+ } catch (_) {
3912
+ G(
3913
+ _ instanceof Error ? _.message : "Could not open briefing."
3914
+ );
3915
+ } finally {
3916
+ O(null);
3917
+ }
3918
+ }
3919
+ }, z = async (A) => {
3920
+ if (!(!q || !H)) {
3921
+ re(A.id);
3922
+ try {
3923
+ await he.runBriefingNow(
3924
+ q,
3925
+ H,
3926
+ A.id,
3927
+ { requestId: vs() }
3928
+ ), ne();
3929
+ } catch (_) {
3930
+ R.error(
3931
+ _ instanceof Error ? _.message : "Could not start the run."
3932
+ );
3933
+ } finally {
3934
+ re(null);
3935
+ }
3936
+ }
3937
+ }, de = async (A) => {
3938
+ if (!q || !H) return;
3939
+ const { noun: _ } = me(A), Oe = _ === "report" ? "Report" : "Briefing";
3940
+ re(A.id);
3941
+ try {
3942
+ const $e = A.status === "PAUSED" ? await he.resumeBriefing(
3943
+ q,
3944
+ H,
3945
+ A.id
3946
+ ) : await he.pauseBriefing(
3947
+ q,
3948
+ H,
3949
+ A.id
3950
+ );
3951
+ R.success(
3952
+ $e.briefing.status === "PAUSED" ? `${Oe} paused` : `${Oe} resumed`
3953
+ ), ne();
3954
+ } catch ($e) {
3955
+ R.error(
3956
+ $e instanceof Error ? $e.message : `Could not update the ${_} status.`
3957
+ );
3958
+ } finally {
3959
+ re(null);
3960
+ }
3961
+ }, fe = async () => {
3962
+ if (!T || !q || !H) return;
3963
+ const A = T;
3964
+ re(A.id);
3965
+ try {
3966
+ await he.deleteBriefing(
3967
+ q,
3968
+ H,
3969
+ A.id
3970
+ );
3971
+ const { noun: _ } = me(A);
3972
+ R.success(`${_ === "report" ? "Report" : "Briefing"} deleted`), ae(null), ne();
3973
+ } catch (_) {
3974
+ R.error(
3975
+ _ instanceof Error ? _.message : "Could not delete the briefing."
3976
+ );
3977
+ } finally {
3978
+ re(null);
3979
+ }
3980
+ }, mr = _e.length;
3981
+ return f.surfaceVisible ? /* @__PURE__ */ s(va, { open: D, onOpenChange: E, children: [
3982
+ u ? null : /* @__PURE__ */ t(
3983
+ Yn,
3984
+ {
3985
+ disabled: n || !Ie,
3986
+ briefingCount: mr,
3987
+ className: i,
3988
+ onClick: Pe
3989
+ }
3990
+ ),
3991
+ /* @__PURE__ */ s(
3992
+ xa,
3993
+ {
3994
+ ref: be,
3995
+ side: "right",
3996
+ hideClose: !0,
3997
+ className: "flex h-full w-full flex-col overflow-hidden p-0 outline-none sm:max-w-[560px]",
3998
+ onOpenAutoFocus: (A) => {
3999
+ var _;
4000
+ A.preventDefault(), (_ = be.current) == null || _.focus({ preventScroll: !0 });
4001
+ },
4002
+ children: [
4003
+ /* @__PURE__ */ s(ya, { className: "sr-only", children: [
4004
+ /* @__PURE__ */ t(Ca, { children: "Reports & briefings" }),
4005
+ /* @__PURE__ */ t(wa, { children: "Manage reports and briefings for this dashboard." })
4006
+ ] }),
4007
+ h ? /* @__PURE__ */ s("div", { className: "flex shrink-0 items-start justify-between gap-3 border-b border-border pl-4 pr-3 pt-2", children: [
4008
+ /* @__PURE__ */ s(
4009
+ "div",
4010
+ {
4011
+ className: "flex items-center gap-5",
4012
+ role: "tablist",
4013
+ "aria-label": h === "scheduled_report" ? "Email report workflow" : "Analytical briefing workflow",
4014
+ children: [
4015
+ /* @__PURE__ */ t(
4016
+ "button",
4017
+ {
4018
+ type: "button",
4019
+ role: "tab",
4020
+ "aria-selected": Z === "author",
4021
+ disabled: !b,
4022
+ className: X(
4023
+ "-mb-px border-b-2 px-0.5 pb-2 text-[12px] transition-colors",
4024
+ Z === "author" ? "border-foreground font-medium text-foreground" : "border-transparent text-muted-foreground hover:text-foreground",
4025
+ !b && "cursor-not-allowed opacity-50"
4026
+ ),
4027
+ onClick: () => {
4028
+ b && (M(null), S(h), B("dashboard"), y("author"));
4029
+ },
4030
+ children: P ? `Edit ${me(P).noun}` : h === "scheduled_report" ? "Schedule report" : "Create briefing"
4031
+ }
4032
+ ),
4033
+ /* @__PURE__ */ t(
4034
+ "button",
4035
+ {
4036
+ type: "button",
4037
+ role: "tab",
4038
+ "aria-selected": Z === "list",
4039
+ className: X(
4040
+ "-mb-px border-b-2 px-0.5 pb-2 text-[12px] transition-colors",
4041
+ Z === "list" ? "border-foreground font-medium text-foreground" : "border-transparent text-muted-foreground hover:text-foreground"
4042
+ ),
4043
+ onClick: () => y("list"),
4044
+ children: h === "scheduled_report" ? "Manage reports" : "Manage briefings"
4045
+ }
4046
+ )
4047
+ ]
4048
+ }
4049
+ ),
4050
+ /* @__PURE__ */ t(
4051
+ "button",
4052
+ {
4053
+ type: "button",
4054
+ onClick: () => E(!1),
4055
+ className: "rounded-control p-1 text-muted-foreground hover:bg-muted hover:text-foreground",
4056
+ "aria-label": h === "scheduled_report" ? "Close email report workflow" : "Close analytical briefing workflow",
4057
+ children: /* @__PURE__ */ t(Me, { className: "h-3.5 w-3.5" })
4058
+ }
4059
+ )
4060
+ ] }) : null,
4061
+ Z === "list" ? /* @__PURE__ */ t(
4062
+ ss,
4063
+ {
4064
+ briefings: _e,
4065
+ dashboardLabel: Ne,
4066
+ sourceView: x,
4067
+ error: le,
4068
+ loading: K,
4069
+ onSourceViewChange: B,
4070
+ onClose: () => E(!1),
4071
+ onEdit: (A) => {
4072
+ V(A);
4073
+ },
4074
+ onNew: C,
4075
+ canCreate: !h && Fe.length > 0,
4076
+ canCreateScheduledReport: Fe.includes(
4077
+ "scheduled_report"
4078
+ ),
4079
+ analyticalBriefingsEnabled: Fe.includes(
4080
+ "analytical_briefing"
4081
+ ),
4082
+ onRunNow: (A) => {
4083
+ z(A);
4084
+ },
4085
+ onTogglePause: (A) => {
4086
+ de(A);
4087
+ },
4088
+ onDelete: (A) => ae(A),
4089
+ selectingId: ce,
4090
+ busyId: te,
4091
+ manageBriefingsHref: d,
4092
+ contentKind: h === "scheduled_report" ? "reports" : h === "analytical_briefing" ? "briefings" : void 0,
4093
+ hideHeader: !!h
4094
+ }
4095
+ ) : /* @__PURE__ */ t(
4096
+ Na,
4097
+ {
4098
+ apiServiceUrl: q,
4099
+ token: H,
4100
+ briefing: P,
4101
+ intent: w,
4102
+ sourceContext: P ? void 0 : st,
4103
+ title: P ? `Edit ${me(P).noun}` : w === "scheduled_report" ? "Schedule report" : "Create analytical briefing",
4104
+ hideHeader: !!h,
4105
+ className: "h-full min-h-0 max-w-none border-0 shadow-none",
4106
+ onBack: h ? void 0 : () => y("list"),
4107
+ onCancel: () => E(!1),
4108
+ onDeleted: () => {
4109
+ const A = P ? me(P).noun : "briefing";
4110
+ R.success(`${A === "report" ? "Report" : "Briefing"} deleted`), M(null), y("list"), ne();
4111
+ },
4112
+ onRunStarted: () => {
4113
+ },
4114
+ onSaved: (A) => {
4115
+ M(A), ne();
4116
+ },
4117
+ onMinimizeRun: ({ briefing: A, run: _ }) => {
4118
+ we({ briefing: A, run: _ }), E(!1);
4119
+ }
4120
+ }
4121
+ )
4122
+ ]
4123
+ }
4124
+ ),
4125
+ ve && q && H ? /* @__PURE__ */ t(
4126
+ gs,
4127
+ {
4128
+ briefingId: ve.briefing.id,
4129
+ initialRun: ve.run,
4130
+ apiServiceUrl: q,
4131
+ token: H,
4132
+ onTerminal: (A) => {
4133
+ Ae({
4134
+ briefing: ve.briefing,
4135
+ run: A
4136
+ }), we(null), ne();
4137
+ },
4138
+ onTimeout: () => {
4139
+ we(null), ne();
4140
+ },
4141
+ onExpand: () => {
4142
+ M(ve.briefing), y("author"), we(null), E(!0);
4143
+ }
4144
+ }
4145
+ ) : null,
4146
+ se ? /* @__PURE__ */ t("div", { className: "fixed bottom-4 right-4 z-50 w-[360px]", children: /* @__PURE__ */ t(
4147
+ Sa,
4148
+ {
4149
+ title: se.run.status === "SUCCESS" ? `${se.briefing.name} is ready` : `${se.briefing.name} run failed`,
4150
+ durationSeconds: se.run.startedAt && se.run.completedAt ? Math.max(
4151
+ 0,
4152
+ Math.floor(
4153
+ (new Date(se.run.completedAt).getTime() - new Date(se.run.startedAt).getTime()) / 1e3
4154
+ )
4155
+ ) : null,
4156
+ status: se.run.status === "SUCCESS" ? "success" : "failed",
4157
+ onView: () => {
4158
+ M(se.briefing), y("author"), Ae(null), E(!0);
4159
+ },
4160
+ onDismiss: () => Ae(null)
4161
+ }
4162
+ ) }) : null,
4163
+ /* @__PURE__ */ t(
4164
+ pt,
4165
+ {
4166
+ open: !!T,
4167
+ onOpenChange: (A) => {
4168
+ A || ae(null);
4169
+ },
4170
+ children: /* @__PURE__ */ s(ft, { children: [
4171
+ /* @__PURE__ */ s(gt, { children: [
4172
+ /* @__PURE__ */ s(bt, { children: [
4173
+ "Delete",
4174
+ " ",
4175
+ T ? me(T).noun : "briefing",
4176
+ "?"
4177
+ ] }),
4178
+ /* @__PURE__ */ s(vt, { children: [
4179
+ "This permanently deletes ",
4180
+ /* @__PURE__ */ t("strong", { children: T == null ? void 0 : T.name }),
4181
+ ". Recipients will stop receiving it."
4182
+ ] })
4183
+ ] }),
4184
+ /* @__PURE__ */ s(xt, { children: [
4185
+ /* @__PURE__ */ t(yt, { children: "Cancel" }),
4186
+ /* @__PURE__ */ s(
4187
+ jt,
4188
+ {
4189
+ className: "bg-destructive/90 hover:bg-destructive",
4190
+ onClick: fe,
4191
+ children: [
4192
+ "Delete",
4193
+ " ",
4194
+ T ? me(T).noun : "briefing"
4195
+ ]
4196
+ }
4197
+ )
4198
+ ] })
4199
+ ] })
4200
+ }
4201
+ )
4202
+ ] }) : null;
4203
+ }
4204
+ function vs() {
4205
+ return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `briefing-run-now-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
4206
+ }
4207
+ export {
4208
+ zs as A,
4209
+ _n as D,
4210
+ Bn as E,
4211
+ Hs as N,
4212
+ js as U,
4213
+ _s as V,
4214
+ Yn as W,
4215
+ $s as a,
4216
+ Vn as b,
4217
+ Ws as c,
4218
+ qs as d,
4219
+ $n as e,
4220
+ Hn as f,
4221
+ Qs as g,
4222
+ Gs as h,
4223
+ Os as u
4224
+ };