react-semaphor 0.1.421 → 0.1.423

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 (67) hide show
  1. package/dist/analytics-protocol/index.cjs +1 -1
  2. package/dist/analytics-protocol/index.js +2 -2
  3. package/dist/brand-studio/index.cjs +1 -1
  4. package/dist/brand-studio/index.js +2 -2
  5. package/dist/briefings/index.cjs +1 -1
  6. package/dist/briefings/index.js +913 -712
  7. package/dist/chunks/{analyze-result-contract-sWcmvBOA.js → analyze-result-contract-D7pjjYPy.js} +45 -46
  8. package/dist/chunks/{analyze-result-contract-B5Eeu7vD.js → analyze-result-contract-DpDcImgk.js} +1 -1
  9. package/dist/chunks/{calendar-preferences-dialog-CscmhyuZ.js → calendar-preferences-dialog-CTmeASaM.js} +1 -1
  10. package/dist/chunks/{calendar-preferences-dialog-cN3_2C-u.js → calendar-preferences-dialog-t5ET6MON.js} +3 -3
  11. package/dist/chunks/card-config-utils-15sRtebL.js +1 -0
  12. package/dist/chunks/card-config-utils-BYZ5MJOh.js +16 -0
  13. package/dist/chunks/dashboard-briefing-launcher-Cavd0QJb.js +3401 -0
  14. package/dist/chunks/dashboard-briefing-launcher-S2akO-ub.js +26 -0
  15. package/dist/chunks/dashboard-controls-BJLrErjW.js +2322 -0
  16. package/dist/chunks/dashboard-controls-DzbP8AXA.js +52 -0
  17. package/dist/chunks/dashboard-json-5tWb5KD6.js +1 -0
  18. package/dist/chunks/{dashboard-json-Cxhw2TZc.js → dashboard-json-Do2-pdPZ.js} +12 -11
  19. package/dist/chunks/{edit-dashboard-visual-BigSJ3-x.js → edit-dashboard-visual-Cw6bq4_w.js} +7058 -6989
  20. package/dist/chunks/edit-dashboard-visual-Yh5YFgMF.js +178 -0
  21. package/dist/chunks/index-BPM3gDRw.js +1406 -0
  22. package/dist/chunks/{index-CH2ZzQo4.js → index-yHe0SeLO.js} +81534 -75430
  23. package/dist/chunks/{switch-TbCsyhv9.js → switch-2bh3Hka1.js} +620 -633
  24. package/dist/chunks/{switch-CiOjVyVI.js → switch-DMT7qf_R.js} +24 -24
  25. package/dist/chunks/{update-policy-2MZ-Vf7v.js → update-policy-BCJc0oI5.js} +1 -1
  26. package/dist/chunks/{update-policy-qpyAkOyO.js → update-policy-C1pmhLz9.js} +1 -1
  27. package/dist/chunks/{use-create-flow-overlay-state-BzcJWNzh.js → use-create-flow-overlay-state-5MDbZcs1.js} +515 -544
  28. package/dist/chunks/use-create-flow-overlay-state-BNczg9Gj.js +11 -0
  29. package/dist/chunks/{validators-Dj1Y-46V.js → validators-DMlVbd1p.js} +1 -1
  30. package/dist/chunks/{validators-D0pfj3jJ.js → validators-PXkij33j.js} +1 -1
  31. package/dist/dashboard/index.cjs +1 -1
  32. package/dist/dashboard/index.js +1 -1
  33. package/dist/dashboard-authoring/index.cjs +1 -1
  34. package/dist/dashboard-authoring/index.js +2 -2
  35. package/dist/data-app-builder/index.cjs +1 -1
  36. package/dist/data-app-builder/index.js +108 -108
  37. package/dist/data-app-codegen/index.cjs +1 -1
  38. package/dist/data-app-codegen/index.js +2 -2
  39. package/dist/data-app-codegen-node/index.cjs +165 -340
  40. package/dist/data-app-codegen-node/index.js +761 -952
  41. package/dist/data-app-sdk/index.cjs +2 -2
  42. package/dist/data-app-sdk/index.js +91 -95
  43. package/dist/data-app-sdk-adapters/index.cjs +1 -1
  44. package/dist/data-app-sdk-adapters/index.js +1 -1
  45. package/dist/data-app-sdk-validation/index.cjs +1 -1
  46. package/dist/data-app-sdk-validation/index.js +2 -2
  47. package/dist/index.cjs +1 -1
  48. package/dist/index.js +168 -164
  49. package/dist/style.css +1 -1
  50. package/dist/surfboard/index.cjs +1 -1
  51. package/dist/surfboard/index.js +2 -2
  52. package/dist/types/analytics-protocol.d.ts +0 -4
  53. package/dist/types/briefings.d.ts +2388 -7
  54. package/dist/types/dashboard-assistant.d.ts +0 -1
  55. package/dist/types/data-app-sdk-validation.d.ts +0 -1
  56. package/dist/types/data-app-sdk.d.ts +0 -2
  57. package/dist/types/main.d.ts +70 -10
  58. package/dist/types/types.d.ts +4 -8
  59. package/package.json +1 -1
  60. package/dist/chunks/dashboard-briefing-launcher-BYTBNetR.js +0 -9077
  61. package/dist/chunks/dashboard-briefing-launcher-DmZkzIC3.js +0 -80
  62. package/dist/chunks/dashboard-controls-9DFeKIP4.js +0 -52
  63. package/dist/chunks/dashboard-controls-PhzuaTBj.js +0 -2280
  64. package/dist/chunks/dashboard-json-DyRHI3mL.js +0 -1
  65. package/dist/chunks/edit-dashboard-visual-3_jiBXsu.js +0 -178
  66. package/dist/chunks/index-BKDQw0aK.js +0 -1346
  67. package/dist/chunks/use-create-flow-overlay-state-DUQmgb9H.js +0 -21
@@ -0,0 +1,3401 @@
1
+ import { jsx as e, jsxs as r, Fragment as G } from "react/jsx-runtime";
2
+ import jt, { useState as A, useEffect as Z, useMemo as J, useContext as Wt, useRef as me, useCallback as q } from "react";
3
+ import { b as Se, c as De, e as ke, b9 as Ct, b$ as Ht, cm as Gt, cn as qt, aX as ge, ca as wt, bq as Ve, J as Kt, A as Xt, co as Qt, aN as Ye, aQ as Ze, aR as Je, aS as et, aT as tt, aU as rt, aV as at, aW as Nt, bp as nt, p as z, cp as Yt, cq as Zt, cr as qe, cb as Oe, cc as ze, cs as St, cd as _e, bZ as H, a$ as Jt, bE as Re, ct as er, bY as tr, d as st, f as ot, cu as rr, o as ar, b8 as nr, bn as Dt, cv as sr, bo as Xe, y as or, aK as ir, b1 as lr, u as $e, a0 as he, aH as it, aD as kt, aE as lt, a1 as At, aC as cr, aJ as dr, ch as ur, cw as hr, bA as mr, aF as mt, x as pr, a3 as fr, cx as gr, cy as br, cz as xr, cA as vr, cB as yr, cC as Cr, cD as wr, cE as Nr, cF as Et, cG as Sr, cH as Dr, cI as kr, cJ as Ar, cK as Er, b2 as Fr, cL as Ir, ce as Ft, cM as Lr, cN as Br, cO as Be, cP as Tr, cQ as Vr, cR as Rr, ay as Ur, aA as Pr, ae as Mr, ad as Or, ac as zr, ab as _r, a8 as $r, a6 as jr, cS as Wr, cT as Hr, cU as Gr, cV as qr, cW as Kr, aw as Xr, cX as Qr, cY as Yr, ak as Zr, cZ as Jr, c_ as ea, c$ as ta } from "./index-yHe0SeLO.js";
4
+ import { B, L as Ne, Z as Qe, e as ee, N as It, d as Lt, c as K, M as ra, E as be, u as M, A as xe, aF as pt, a6 as Bt, F as Tt, S as ct, P as Ue, a as Pe, b as Me, aG as aa, aH as na, aD as sa } from "./switch-2bh3Hka1.js";
5
+ import { L as dt } from "./layout-grid-CiubineE.js";
6
+ import { c as Ae, X as je, C as Vt } from "./x-CXDkqdur.js";
7
+ import { u as ut, V as oa, E as ft, a as gt, b as ia, c as la, L as ca, d as da, e as Rt, C as Ut, f as ua } from "./use-create-flow-overlay-state-5MDbZcs1.js";
8
+ import "./analyze-result-contract-D7pjjYPy.js";
9
+ import { S as ha } from "./search-BHsQIWBV.js";
10
+ import { l as bt } from "./date-formatter-BlhBftA9.js";
11
+ import "./index-CJdxSyQq.js";
12
+ import "react-dom";
13
+ import { getBriefingPresentation as oe, describeBriefingSchedule as ma, getBriefingCreationIntents as pa } from "../briefings/index.js";
14
+ /**
15
+ * @license lucide-react v0.453.0 - ISC
16
+ *
17
+ * This source code is licensed under the ISC license.
18
+ * See the LICENSE file in the root directory of this source tree.
19
+ */
20
+ const fa = Ae("ArrowUpRight", [
21
+ ["path", { d: "M7 7h10v10", key: "1tivn9" }],
22
+ ["path", { d: "M7 17 17 7", key: "1vkiza" }]
23
+ ]);
24
+ /**
25
+ * @license lucide-react v0.453.0 - ISC
26
+ *
27
+ * This source code is licensed under the ISC license.
28
+ * See the LICENSE file in the root directory of this source tree.
29
+ */
30
+ const ga = Ae("CircleX", [
31
+ ["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }],
32
+ ["path", { d: "m15 9-6 6", key: "1uzhvr" }],
33
+ ["path", { d: "m9 9 6 6", key: "z0biqf" }]
34
+ ]);
35
+ /**
36
+ * @license lucide-react v0.453.0 - ISC
37
+ *
38
+ * This source code is licensed under the ISC license.
39
+ * See the LICENSE file in the root directory of this source tree.
40
+ */
41
+ const xt = Ae("FileDown", [
42
+ ["path", { d: "M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z", key: "1rqfz7" }],
43
+ ["path", { d: "M14 2v4a2 2 0 0 0 2 2h4", key: "tnqrlb" }],
44
+ ["path", { d: "M12 18v-6", key: "17g6i2" }],
45
+ ["path", { d: "m9 15 3 3 3-3", key: "1npd3o" }]
46
+ ]);
47
+ /**
48
+ * @license lucide-react v0.453.0 - ISC
49
+ *
50
+ * This source code is licensed under the ISC license.
51
+ * See the LICENSE file in the root directory of this source tree.
52
+ */
53
+ const ba = Ae("FilterX", [
54
+ ["path", { d: "M13.013 3H2l8 9.46V19l4 2v-8.54l.9-1.055", key: "1fi1da" }],
55
+ ["path", { d: "m22 3-5 5", key: "12jva0" }],
56
+ ["path", { d: "m17 3 5 5", key: "k36vhe" }]
57
+ ]);
58
+ /**
59
+ * @license lucide-react v0.453.0 - ISC
60
+ *
61
+ * This source code is licensed under the ISC license.
62
+ * See the LICENSE file in the root directory of this source tree.
63
+ */
64
+ const xa = Ae("Newspaper", [
65
+ [
66
+ "path",
67
+ {
68
+ 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",
69
+ key: "7pis2x"
70
+ }
71
+ ],
72
+ ["path", { d: "M18 14h-8", key: "sponae" }],
73
+ ["path", { d: "M15 18h-5", key: "95g1m2" }],
74
+ ["path", { d: "M10 6h8v4h-8V6Z", key: "smlsk5" }]
75
+ ]);
76
+ function va() {
77
+ return /* @__PURE__ */ e("div", { className: "space-y-1.5 py-1", children: [...Array(5)].map((t, a) => /* @__PURE__ */ r(
78
+ "div",
79
+ {
80
+ className: "flex animate-pulse items-start gap-3 rounded-xl border border-transparent px-2.5 py-2.5",
81
+ children: [
82
+ /* @__PURE__ */ e("div", { className: "mt-0.5 h-4 w-4 flex-shrink-0 rounded bg-muted/60" }),
83
+ /* @__PURE__ */ r("div", { className: "flex-1 space-y-1.5", children: [
84
+ /* @__PURE__ */ e("div", { className: "h-4 w-3/5 rounded bg-muted/60" }),
85
+ /* @__PURE__ */ e("div", { className: "h-3 w-4/5 rounded bg-muted/40" })
86
+ ] })
87
+ ]
88
+ },
89
+ a
90
+ )) });
91
+ }
92
+ function ya({
93
+ open: t,
94
+ onOpenChange: a,
95
+ onSubmit: i,
96
+ isCreating: s
97
+ }) {
98
+ const [n, c] = A(""), [u, m] = A("");
99
+ Z(() => {
100
+ t || (c(""), m(""));
101
+ }, [t]);
102
+ const l = () => {
103
+ n.trim() && i({ title: n, description: u });
104
+ }, d = (o) => {
105
+ a(o);
106
+ };
107
+ return /* @__PURE__ */ e(Se, { open: t, onOpenChange: d, children: /* @__PURE__ */ r(
108
+ De,
109
+ {
110
+ showCloseButton: !1,
111
+ className: "flex max-w-lg grid-cols-none flex-col gap-0 overflow-hidden rounded-[6px] border-border/60 p-0 shadow-lg",
112
+ children: [
113
+ /* @__PURE__ */ r("div", { className: "flex h-10 shrink-0 items-center justify-between gap-2 border-b border-border/60 px-3", children: [
114
+ /* @__PURE__ */ r("div", { className: "flex min-w-0 items-center gap-2", children: [
115
+ /* @__PURE__ */ e(dt, { className: "h-3.5 w-3.5 shrink-0 text-muted-foreground" }),
116
+ /* @__PURE__ */ r("div", { className: "flex min-w-0 items-baseline gap-2", children: [
117
+ /* @__PURE__ */ e(ke, { className: "truncate text-[13px] font-medium leading-none tracking-normal", children: "New library visual" }),
118
+ /* @__PURE__ */ e("span", { className: "shrink-0 text-[10px] font-medium uppercase leading-none tracking-[0.08em] text-muted-foreground", children: "Visual" })
119
+ ] })
120
+ ] }),
121
+ /* @__PURE__ */ e(
122
+ B,
123
+ {
124
+ size: "xs",
125
+ variant: "ghost",
126
+ className: "w-7 px-0 text-muted-foreground hover:text-foreground",
127
+ onClick: () => d(!1),
128
+ "aria-label": "Close",
129
+ disabled: s,
130
+ children: /* @__PURE__ */ e(je, { className: "h-3.5 w-3.5" })
131
+ }
132
+ )
133
+ ] }),
134
+ /* @__PURE__ */ r("div", { className: "space-y-3 px-4 py-3", children: [
135
+ /* @__PURE__ */ e("p", { className: "text-[12px] text-muted-foreground", children: "Create a saved visual that can be reused across dashboards." }),
136
+ /* @__PURE__ */ r("div", { className: "space-y-1.5", children: [
137
+ /* @__PURE__ */ e(Ne, { htmlFor: "visual-title", className: "text-[12px]", children: "Name" }),
138
+ /* @__PURE__ */ e(
139
+ Qe,
140
+ {
141
+ id: "visual-title",
142
+ size: "sm",
143
+ placeholder: "Untitled visual",
144
+ value: n,
145
+ onChange: (o) => c(o.target.value),
146
+ disabled: s,
147
+ onKeyDown: (o) => {
148
+ o.key === "Enter" && !o.shiftKey && (o.preventDefault(), l());
149
+ }
150
+ }
151
+ )
152
+ ] }),
153
+ /* @__PURE__ */ r("div", { className: "space-y-1.5", children: [
154
+ /* @__PURE__ */ e(Ne, { htmlFor: "visual-description", className: "text-[12px]", children: "Description" }),
155
+ /* @__PURE__ */ e(
156
+ Qe,
157
+ {
158
+ id: "visual-description",
159
+ size: "sm",
160
+ placeholder: "Optional",
161
+ value: u,
162
+ onChange: (o) => m(o.target.value),
163
+ disabled: s
164
+ }
165
+ )
166
+ ] })
167
+ ] }),
168
+ /* @__PURE__ */ r("div", { className: "flex shrink-0 justify-end gap-2 border-t border-border/60 px-4 py-2.5", children: [
169
+ /* @__PURE__ */ e(
170
+ B,
171
+ {
172
+ size: "xs",
173
+ variant: "outline",
174
+ onClick: () => d(!1),
175
+ disabled: s,
176
+ children: "Cancel"
177
+ }
178
+ ),
179
+ /* @__PURE__ */ e(
180
+ B,
181
+ {
182
+ size: "xs",
183
+ onClick: l,
184
+ disabled: !n.trim() || s,
185
+ children: s ? /* @__PURE__ */ r(G, { children: [
186
+ /* @__PURE__ */ e(ee, { className: "h-3.5 w-3.5 animate-spin" }),
187
+ "Creating..."
188
+ ] }) : "Create library visual"
189
+ }
190
+ )
191
+ ] })
192
+ ]
193
+ }
194
+ ) });
195
+ }
196
+ function Pt(t) {
197
+ return t ? new Date(t).toLocaleDateString("en-US", {
198
+ month: "short",
199
+ day: "numeric",
200
+ year: "numeric"
201
+ }) : "Unknown";
202
+ }
203
+ function Mt(t, a) {
204
+ var s;
205
+ const i = (s = t.ownership.createdBy) == null ? void 0 : s.type;
206
+ return i === "tenant" || i === "organization" && a;
207
+ }
208
+ function ht(t, a) {
209
+ var i, s;
210
+ return Mt(t, a) ? ((i = t.ownership.createdBy) == null ? void 0 : i.name) || ((s = t.createdByTenantUserRel) == null ? void 0 : s.name) || t.lastModifiedBy || "Unknown" : "Organization";
211
+ }
212
+ function Ca(t, a) {
213
+ return ht(t, a).split(/\s+/).filter(Boolean).slice(0, 2).map((s) => s.charAt(0).toUpperCase()).join("") || "?";
214
+ }
215
+ function wa(t) {
216
+ const a = (t || "").toLowerCase();
217
+ return a.includes("table") ? It : a.includes("pie") || a.includes("donut") ? Yt : a.includes("line") ? Zt : a.includes("bar") ? ra : dt;
218
+ }
219
+ function Na({ visual: t }) {
220
+ const a = t.ownership.status === "public" ? "Public" : t.ownership.status === "shared" || t.ownership.sharedCount > 0 ? "Shared" : "Private";
221
+ return /* @__PURE__ */ e("span", { className: "inline-flex items-center rounded-[4px] border border-border/60 px-1.5 py-px text-[11px] text-muted-foreground", children: a });
222
+ }
223
+ function Tn({
224
+ open: t,
225
+ onOpenChange: a
226
+ }) {
227
+ const [i, s] = A(""), [n, c] = A(/* @__PURE__ */ new Set()), [u, m] = A(!1), [l, d] = A(
228
+ null
229
+ ), [o, g] = A(
230
+ null
231
+ ), [h, p] = A(!1), [y, x] = A(null), [D, E] = A(null), N = () => {
232
+ c(/* @__PURE__ */ new Set()), d(null), g(null), p(!1), x(null);
233
+ }, b = () => {
234
+ a(!1), N();
235
+ }, { selectVisual: S } = Ct(), { handleAddLibraryVisual: k, handleEditLibraryVisual: P } = ut(), { isConsoleMode: f } = Ht(), {
236
+ resources: C,
237
+ isLoading: T,
238
+ isError: F,
239
+ createResource: I,
240
+ updateResource: R,
241
+ deleteResourceAsync: V,
242
+ duplicateResource: W,
243
+ isCreating: ae,
244
+ isDeleting: ne
245
+ } = Gt(
246
+ void 0,
247
+ (v) => {
248
+ m(!1), v && (S(v), P(v), b());
249
+ }
250
+ ), {
251
+ startUpdating: We,
252
+ stopUpdating: ve,
253
+ isUpdating: He
254
+ } = qt(), Q = C, _ = J(() => {
255
+ const v = i.trim().toLowerCase();
256
+ return v ? Q.filter(
257
+ (L) => {
258
+ var O, re, ie;
259
+ return ((O = L.title) == null ? void 0 : O.toLowerCase().includes(v)) || ((re = L.description) == null ? void 0 : re.toLowerCase().includes(v)) || ((ie = L.kind) == null ? void 0 : ie.toLowerCase().includes(v));
260
+ }
261
+ ) : Q;
262
+ }, [i, Q]), te = J(
263
+ () => Q.filter(
264
+ (v) => n.has(v.id)
265
+ ),
266
+ [n, Q]
267
+ ), le = te.filter(
268
+ (v) => v.permissions.canDelete
269
+ ), ce = te.filter(
270
+ (v) => v.permissions.canShare
271
+ ), ye = _.length > 0 && _.every(
272
+ (v) => n.has(v.id)
273
+ ), Ee = _.some(
274
+ (v) => n.has(v.id)
275
+ ), de = (v) => {
276
+ const L = new Set(n);
277
+ v(L), c(L);
278
+ }, pe = (v) => {
279
+ de((L) => {
280
+ L.has(v) ? L.delete(v) : L.add(v);
281
+ });
282
+ }, Y = () => {
283
+ c((v) => {
284
+ const L = new Set(v);
285
+ return ye ? _.forEach(
286
+ (O) => L.delete(O.id)
287
+ ) : _.forEach(
288
+ (O) => L.add(O.id)
289
+ ), L;
290
+ });
291
+ }, Ce = async (v) => {
292
+ (await k(v)).success && b();
293
+ }, $ = async () => {
294
+ const v = te;
295
+ if (v.length === 0) return;
296
+ let L = !1;
297
+ for (const O of v)
298
+ if (!(await k(O)).success) {
299
+ L = !0;
300
+ break;
301
+ }
302
+ L || b();
303
+ }, j = (v) => {
304
+ P(v), b();
305
+ }, se = (v) => {
306
+ E(v), W(v, {
307
+ onSettled: () => E(null)
308
+ });
309
+ }, fe = () => {
310
+ if (le.length === 0) {
311
+ z.error("Select a visual you can delete");
312
+ return;
313
+ }
314
+ x(null), p(!0);
315
+ }, Fe = async () => {
316
+ const v = y ? [y] : le;
317
+ try {
318
+ for (const L of v)
319
+ await V(L.id);
320
+ c((L) => {
321
+ const O = new Set(L);
322
+ return v.forEach(
323
+ (re) => O.delete(re.id)
324
+ ), O;
325
+ }), p(!1), x(null);
326
+ } catch {
327
+ }
328
+ }, Ge = () => {
329
+ if (te.length !== 1) {
330
+ z.error("Select one visual to share");
331
+ return;
332
+ }
333
+ const [v] = te;
334
+ if (!v.permissions.canShare) {
335
+ z.error("You do not have permission to share this visual");
336
+ return;
337
+ }
338
+ d(v);
339
+ }, we = ({
340
+ title: v,
341
+ description: L
342
+ }) => {
343
+ if (!o) return;
344
+ const O = {};
345
+ if (v !== o.title && (O.title = v), (o.description || "") !== L && (O.description = L), Object.keys(O).length === 0) {
346
+ g(null);
347
+ return;
348
+ }
349
+ const re = Object.keys(O), ie = re.length === 1 ? re[0] : void 0;
350
+ We(o.id, ie), R(
351
+ {
352
+ resourceId: o.id,
353
+ data: O
354
+ },
355
+ {
356
+ onSuccess: () => {
357
+ ve(o.id, ie), g(null);
358
+ },
359
+ onError: () => {
360
+ ve(o.id, ie);
361
+ }
362
+ }
363
+ );
364
+ }, ue = (v) => {
365
+ a(v), v || N();
366
+ }, X = y ? 1 : le.length;
367
+ return /* @__PURE__ */ r(G, { children: [
368
+ /* @__PURE__ */ e(Se, { open: t, onOpenChange: ue, children: /* @__PURE__ */ r(
369
+ De,
370
+ {
371
+ showCloseButton: !1,
372
+ className: "flex max-h-[80vh] w-[min(72rem,calc(100vw-2rem))] max-w-none grid-cols-none flex-col gap-0 overflow-hidden rounded-[6px] border-border/60 p-0 shadow-lg",
373
+ children: [
374
+ /* @__PURE__ */ r("div", { className: "flex h-10 shrink-0 items-center justify-between gap-2 border-b border-border/60 px-3", children: [
375
+ /* @__PURE__ */ r("div", { className: "flex min-w-0 items-center gap-2", children: [
376
+ /* @__PURE__ */ e(It, { className: "h-3.5 w-3.5 shrink-0 text-muted-foreground" }),
377
+ /* @__PURE__ */ r("div", { className: "flex min-w-0 items-baseline gap-2", children: [
378
+ /* @__PURE__ */ e(ke, { className: "truncate text-[13px] font-medium leading-none tracking-normal", children: "Visuals library" }),
379
+ /* @__PURE__ */ e("span", { className: "shrink-0 text-[10px] font-medium uppercase leading-none tracking-[0.08em] text-muted-foreground", children: "Add to dashboard" })
380
+ ] })
381
+ ] }),
382
+ /* @__PURE__ */ e(
383
+ B,
384
+ {
385
+ size: "xs",
386
+ variant: "ghost",
387
+ className: "w-7 px-0 text-muted-foreground hover:text-foreground",
388
+ onClick: () => ue(!1),
389
+ "aria-label": "Close visuals library",
390
+ children: "×"
391
+ }
392
+ )
393
+ ] }),
394
+ /* @__PURE__ */ r("div", { className: "flex shrink-0 items-center gap-2 border-b border-border/60 px-3 py-2", children: [
395
+ /* @__PURE__ */ r("div", { className: "relative min-w-[12rem] flex-1 md:max-w-md", children: [
396
+ /* @__PURE__ */ e(ha, { className: "pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground" }),
397
+ /* @__PURE__ */ e(
398
+ "input",
399
+ {
400
+ autoFocus: !0,
401
+ value: i,
402
+ onChange: (v) => s(v.target.value),
403
+ placeholder: "Search visuals...",
404
+ 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",
405
+ "aria-label": "Search visuals"
406
+ }
407
+ )
408
+ ] }),
409
+ /* @__PURE__ */ r(
410
+ B,
411
+ {
412
+ size: "xs",
413
+ variant: "outline",
414
+ className: "ml-auto",
415
+ onClick: () => m(!0),
416
+ children: [
417
+ /* @__PURE__ */ e(ge, { className: "h-3.5 w-3.5" }),
418
+ "New library visual"
419
+ ]
420
+ }
421
+ )
422
+ ] }),
423
+ /* @__PURE__ */ e("div", { className: "min-h-0 flex-1 overflow-auto", children: T ? /* @__PURE__ */ e("div", { className: "p-3", children: /* @__PURE__ */ e(va, {}) }) : F ? /* @__PURE__ */ e("div", { className: "flex flex-col items-center gap-2 px-4 py-12 text-center", children: /* @__PURE__ */ e("p", { className: "text-[13px] text-destructive", children: "Failed to load visuals" }) }) : _.length === 0 ? /* @__PURE__ */ r("div", { className: "flex flex-col items-center gap-2 px-4 py-12 text-center", children: [
424
+ /* @__PURE__ */ e(dt, { className: "h-5 w-5 text-muted-foreground/60" }),
425
+ /* @__PURE__ */ e("p", { className: "text-[13px] font-medium", children: i ? "No visuals found" : "No visuals yet" }),
426
+ /* @__PURE__ */ e("p", { className: "text-[12px] text-muted-foreground", children: i ? "Try a different search." : "Create a saved visual to add it here." })
427
+ ] }) : /* @__PURE__ */ e(
428
+ Sa,
429
+ {
430
+ visuals: _,
431
+ selectedIds: n,
432
+ allFilteredSelected: ye,
433
+ someFilteredSelected: Ee,
434
+ onSelectAll: Y,
435
+ onToggleSelection: pe,
436
+ onAddVisual: Ce,
437
+ onOpenVisual: j,
438
+ onEditDetails: g,
439
+ onShareVisual: d,
440
+ onDeleteVisual: (v) => {
441
+ x(v), p(!0);
442
+ },
443
+ onDuplicateVisual: se,
444
+ duplicatingId: D,
445
+ isDeleting: ne,
446
+ isConsoleMode: f
447
+ }
448
+ ) }),
449
+ /* @__PURE__ */ r("div", { className: "flex shrink-0 items-center justify-between gap-2 border-t border-border/60 px-3 py-2", children: [
450
+ /* @__PURE__ */ e("div", { className: "flex min-w-0 items-center gap-1.5", children: n.size > 0 && /* @__PURE__ */ r(G, { children: [
451
+ /* @__PURE__ */ r("span", { className: "text-[12px] text-muted-foreground", children: [
452
+ /* @__PURE__ */ e("span", { className: "font-medium tabular-nums text-foreground", children: n.size }),
453
+ " ",
454
+ "selected"
455
+ ] }),
456
+ /* @__PURE__ */ e(
457
+ B,
458
+ {
459
+ size: "xs",
460
+ variant: "ghost",
461
+ onClick: () => c(/* @__PURE__ */ new Set()),
462
+ children: "Clear"
463
+ }
464
+ ),
465
+ /* @__PURE__ */ r(
466
+ B,
467
+ {
468
+ size: "xs",
469
+ variant: "outline",
470
+ onClick: Ge,
471
+ disabled: te.length !== 1 || ce.length !== 1,
472
+ children: [
473
+ /* @__PURE__ */ e(wt, { className: "h-3.5 w-3.5" }),
474
+ "Share"
475
+ ]
476
+ }
477
+ ),
478
+ /* @__PURE__ */ r(
479
+ B,
480
+ {
481
+ size: "xs",
482
+ variant: "outline",
483
+ className: "text-destructive hover:text-destructive",
484
+ onClick: fe,
485
+ disabled: le.length === 0,
486
+ children: [
487
+ /* @__PURE__ */ e(Ve, { className: "h-3.5 w-3.5" }),
488
+ "Delete ",
489
+ le.length || n.size
490
+ ]
491
+ }
492
+ )
493
+ ] }) }),
494
+ /* @__PURE__ */ r("div", { className: "flex items-center gap-2", children: [
495
+ /* @__PURE__ */ e(
496
+ B,
497
+ {
498
+ size: "xs",
499
+ variant: "outline",
500
+ onClick: () => ue(!1),
501
+ children: "Close"
502
+ }
503
+ ),
504
+ /* @__PURE__ */ r(
505
+ B,
506
+ {
507
+ size: "xs",
508
+ onClick: $,
509
+ disabled: n.size === 0,
510
+ children: [
511
+ /* @__PURE__ */ e(Lt, { className: "h-3.5 w-3.5" }),
512
+ n.size === 0 ? "Add to dashboard" : `Add ${n.size} visual${n.size === 1 ? "" : "s"}`
513
+ ]
514
+ }
515
+ )
516
+ ] })
517
+ ] })
518
+ ]
519
+ }
520
+ ) }),
521
+ /* @__PURE__ */ e(
522
+ ya,
523
+ {
524
+ open: u,
525
+ onOpenChange: m,
526
+ onSubmit: I,
527
+ isCreating: ae
528
+ }
529
+ ),
530
+ l && /* @__PURE__ */ e(
531
+ Kt,
532
+ {
533
+ resource: l,
534
+ resourceType: Xt.VISUAL,
535
+ onClose: () => d(null)
536
+ }
537
+ ),
538
+ o && /* @__PURE__ */ e(
539
+ Qt,
540
+ {
541
+ open: !!o,
542
+ resourceLabel: "Visual",
543
+ initialTitle: o.title || "",
544
+ initialDescription: o.description || "",
545
+ onClose: () => g(null),
546
+ onSave: we,
547
+ isSaving: He(o.id)
548
+ }
549
+ ),
550
+ /* @__PURE__ */ e(
551
+ Ye,
552
+ {
553
+ open: h,
554
+ onOpenChange: (v) => {
555
+ !v && ne || (p(v), v || x(null));
556
+ },
557
+ children: /* @__PURE__ */ r(Ze, { children: [
558
+ /* @__PURE__ */ r(Je, { children: [
559
+ /* @__PURE__ */ r(et, { children: [
560
+ "Delete ",
561
+ X,
562
+ " visual",
563
+ X === 1 ? "" : "s",
564
+ "?"
565
+ ] }),
566
+ /* @__PURE__ */ e(tt, { children: "This cannot be undone. Visuals already added to dashboards may need to be removed from those dashboards separately." })
567
+ ] }),
568
+ /* @__PURE__ */ r(rt, { children: [
569
+ /* @__PURE__ */ e(at, { disabled: ne, children: "Cancel" }),
570
+ /* @__PURE__ */ r(
571
+ Nt,
572
+ {
573
+ onClick: (v) => {
574
+ v.preventDefault(), Fe();
575
+ },
576
+ disabled: ne || X === 0,
577
+ children: [
578
+ ne ? /* @__PURE__ */ e(ee, { className: "h-3.5 w-3.5 animate-spin" }) : /* @__PURE__ */ e(Ve, { className: "h-3.5 w-3.5" }),
579
+ ne ? "Deleting..." : "Delete"
580
+ ]
581
+ }
582
+ )
583
+ ] })
584
+ ] })
585
+ }
586
+ )
587
+ ] });
588
+ }
589
+ function Sa({
590
+ visuals: t,
591
+ selectedIds: a,
592
+ allFilteredSelected: i,
593
+ someFilteredSelected: s,
594
+ onSelectAll: n,
595
+ onToggleSelection: c,
596
+ onAddVisual: u,
597
+ onOpenVisual: m,
598
+ onEditDetails: l,
599
+ onShareVisual: d,
600
+ onDeleteVisual: o,
601
+ onDuplicateVisual: g,
602
+ duplicatingId: h,
603
+ isDeleting: p,
604
+ isConsoleMode: y
605
+ }) {
606
+ return /* @__PURE__ */ r("div", { className: "min-w-[48rem]", children: [
607
+ /* @__PURE__ */ r("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: [
608
+ /* @__PURE__ */ e(
609
+ nt,
610
+ {
611
+ checked: i ? !0 : s ? "indeterminate" : !1,
612
+ onCheckedChange: n,
613
+ "aria-label": "Select all visuals"
614
+ }
615
+ ),
616
+ /* @__PURE__ */ e("span", { children: "Name" }),
617
+ /* @__PURE__ */ e("span", { children: "Created by" }),
618
+ /* @__PURE__ */ e("span", { children: "Updated" }),
619
+ /* @__PURE__ */ e("span", { children: "Visibility" }),
620
+ /* @__PURE__ */ e("span", { className: "text-right", children: "Shared" }),
621
+ /* @__PURE__ */ e("span", { className: "text-right", children: "Actions" })
622
+ ] }),
623
+ t.map((x) => /* @__PURE__ */ e(
624
+ Da,
625
+ {
626
+ visual: x,
627
+ selected: a.has(x.id),
628
+ onToggleSelection: c,
629
+ onAddVisual: u,
630
+ onOpenVisual: m,
631
+ onEditDetails: l,
632
+ onShareVisual: d,
633
+ onDeleteVisual: o,
634
+ onDuplicateVisual: g,
635
+ duplicatingId: h,
636
+ isDeleting: p,
637
+ isConsoleMode: y
638
+ },
639
+ x.id
640
+ ))
641
+ ] });
642
+ }
643
+ function Da({
644
+ visual: t,
645
+ selected: a,
646
+ onToggleSelection: i,
647
+ onAddVisual: s,
648
+ onOpenVisual: n,
649
+ onEditDetails: c,
650
+ onShareVisual: u,
651
+ onDeleteVisual: m,
652
+ onDuplicateVisual: l,
653
+ duplicatingId: d,
654
+ isDeleting: o,
655
+ isConsoleMode: g
656
+ }) {
657
+ var y;
658
+ const h = wa(t.kind), p = () => {
659
+ s(t);
660
+ };
661
+ return /* @__PURE__ */ r(
662
+ "div",
663
+ {
664
+ className: K(
665
+ "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",
666
+ a && "bg-muted/70"
667
+ ),
668
+ children: [
669
+ /* @__PURE__ */ e("div", { children: /* @__PURE__ */ e(
670
+ nt,
671
+ {
672
+ checked: a,
673
+ onCheckedChange: () => i(t.id),
674
+ "aria-label": `Select ${t.title || "visual"}`
675
+ }
676
+ ) }),
677
+ /* @__PURE__ */ r(
678
+ "button",
679
+ {
680
+ type: "button",
681
+ className: "flex min-w-0 items-center gap-2 rounded-[4px] text-left outline-none focus-visible:ring-1 focus-visible:ring-ring",
682
+ onClick: p,
683
+ "aria-label": `Add ${t.title || "visual"} to dashboard`,
684
+ children: [
685
+ /* @__PURE__ */ e(h, { className: "h-3.5 w-3.5 shrink-0 text-muted-foreground" }),
686
+ /* @__PURE__ */ r("div", { className: "min-w-0", children: [
687
+ /* @__PURE__ */ e(
688
+ "div",
689
+ {
690
+ className: "truncate font-medium text-foreground",
691
+ title: t.title || "Untitled Visual",
692
+ children: t.title || "Untitled Visual"
693
+ }
694
+ ),
695
+ ((y = t.description) == null ? void 0 : y.trim()) && /* @__PURE__ */ e(
696
+ "div",
697
+ {
698
+ className: "truncate text-[11px] text-muted-foreground",
699
+ title: t.description,
700
+ children: t.description
701
+ }
702
+ )
703
+ ] })
704
+ ]
705
+ }
706
+ ),
707
+ /* @__PURE__ */ r("div", { className: "flex min-w-0 items-center gap-2", children: [
708
+ /* @__PURE__ */ e("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: Ca(t, g) }),
709
+ /* @__PURE__ */ e("span", { className: "truncate text-muted-foreground", children: ht(t, g) })
710
+ ] }),
711
+ /* @__PURE__ */ e("span", { className: "text-muted-foreground", children: Pt(t.updatedAt) }),
712
+ /* @__PURE__ */ e(Na, { visual: t }),
713
+ /* @__PURE__ */ e("span", { className: "text-right tabular-nums text-muted-foreground", children: t.ownership.sharedCount > 0 ? t.ownership.sharedCount : "—" }),
714
+ /* @__PURE__ */ e(
715
+ ka,
716
+ {
717
+ visual: t,
718
+ onOpenVisual: n,
719
+ onEditDetails: c,
720
+ onShareVisual: u,
721
+ onDeleteVisual: m,
722
+ onDuplicateVisual: l,
723
+ duplicatingId: d,
724
+ isDeleting: o,
725
+ isConsoleMode: g
726
+ }
727
+ )
728
+ ]
729
+ }
730
+ );
731
+ }
732
+ function ka({
733
+ visual: t,
734
+ onOpenVisual: a,
735
+ onEditDetails: i,
736
+ onShareVisual: s,
737
+ onDeleteVisual: n,
738
+ onDuplicateVisual: c,
739
+ duplicatingId: u,
740
+ isDeleting: m,
741
+ isConsoleMode: l
742
+ }) {
743
+ return /* @__PURE__ */ r(
744
+ "div",
745
+ {
746
+ className: "flex items-center justify-end gap-0.5 opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100",
747
+ onClick: (d) => d.stopPropagation(),
748
+ children: [
749
+ /* @__PURE__ */ e(
750
+ B,
751
+ {
752
+ size: "xs",
753
+ variant: "ghost",
754
+ className: "w-7 px-0",
755
+ onClick: () => a(t),
756
+ "aria-label": "Edit visual",
757
+ children: /* @__PURE__ */ e(qe, { className: "h-3.5 w-3.5" })
758
+ }
759
+ ),
760
+ /* @__PURE__ */ r(Oe, { modal: !1, children: [
761
+ /* @__PURE__ */ e(ze, { asChild: !0, children: /* @__PURE__ */ e(
762
+ B,
763
+ {
764
+ size: "xs",
765
+ variant: "ghost",
766
+ className: "w-7 px-0",
767
+ "aria-label": "More actions",
768
+ children: /* @__PURE__ */ e(St, { className: "h-3.5 w-3.5" })
769
+ }
770
+ ) }),
771
+ /* @__PURE__ */ r(
772
+ _e,
773
+ {
774
+ align: "end",
775
+ className: "z-[60] w-44 rounded-[6px] border-border/60 p-1 shadow-sm",
776
+ children: [
777
+ /* @__PURE__ */ r(H, { onClick: () => a(t), children: [
778
+ /* @__PURE__ */ e(qe, { className: "h-3.5 w-3.5" }),
779
+ "Edit visual"
780
+ ] }),
781
+ /* @__PURE__ */ r(
782
+ H,
783
+ {
784
+ onClick: () => c(t.id),
785
+ disabled: u === t.id,
786
+ children: [
787
+ u === t.id ? /* @__PURE__ */ e(ee, { className: "h-3.5 w-3.5 animate-spin" }) : /* @__PURE__ */ e(Jt, { className: "h-3.5 w-3.5" }),
788
+ u === t.id ? "Duplicating..." : "Duplicate"
789
+ ]
790
+ }
791
+ ),
792
+ t.permissions.canEdit && /* @__PURE__ */ r(H, { onClick: () => i(t), children: [
793
+ /* @__PURE__ */ e(qe, { className: "h-3.5 w-3.5" }),
794
+ "Edit details"
795
+ ] }),
796
+ t.permissions.canShare && /* @__PURE__ */ r(H, { onClick: () => s(t), children: [
797
+ /* @__PURE__ */ e(wt, { className: "h-3.5 w-3.5" }),
798
+ "Share"
799
+ ] }),
800
+ t.permissions.canDelete && /* @__PURE__ */ r(G, { children: [
801
+ /* @__PURE__ */ e(Re, {}),
802
+ /* @__PURE__ */ r(
803
+ H,
804
+ {
805
+ className: "text-destructive focus:bg-destructive/10 focus:text-destructive",
806
+ onClick: () => n(t),
807
+ disabled: m,
808
+ children: [
809
+ /* @__PURE__ */ e(Ve, { className: "h-3.5 w-3.5" }),
810
+ m ? "Deleting..." : "Delete"
811
+ ]
812
+ }
813
+ )
814
+ ] }),
815
+ /* @__PURE__ */ e(Re, {}),
816
+ /* @__PURE__ */ r("div", { className: "space-y-1 px-2 py-1.5 text-[11px] text-muted-foreground", children: [
817
+ Mt(t, l) && /* @__PURE__ */ r("div", { className: "flex items-center gap-1.5", children: [
818
+ /* @__PURE__ */ e(er, { className: "h-3 w-3" }),
819
+ /* @__PURE__ */ e("span", { className: "truncate", children: ht(t, l) })
820
+ ] }),
821
+ /* @__PURE__ */ r("div", { className: "flex items-center gap-1.5", children: [
822
+ /* @__PURE__ */ e(tr, { className: "h-3 w-3" }),
823
+ /* @__PURE__ */ e("span", { children: Pt(t.updatedAt) })
824
+ ] })
825
+ ] })
826
+ ]
827
+ }
828
+ )
829
+ ] })
830
+ ]
831
+ }
832
+ );
833
+ }
834
+ function Aa({
835
+ open: t,
836
+ onOpenChange: a,
837
+ isLibraryVisual: i,
838
+ currentVisualName: s,
839
+ isSaving: n = !1,
840
+ destinationMode: c = "both",
841
+ onConfirm: u
842
+ }) {
843
+ const [m, l] = A(
844
+ i && s ? `Copy of ${s}` : s || ""
845
+ ), [d, o] = A("");
846
+ jt.useEffect(() => {
847
+ t && (l(
848
+ i && s ? `Copy of ${s}` : s || ""
849
+ ), o(""));
850
+ }, [t, i, s]);
851
+ const g = !!m.trim(), h = c === "local" ? {
852
+ saveToLibrary: !1,
853
+ saveToCurrentDashboard: !0,
854
+ badgeType: "local",
855
+ description: "Creates a local copy on the current dashboard.",
856
+ actionLabel: "Add to Dashboard (Local)"
857
+ } : c === "library" ? {
858
+ saveToLibrary: !0,
859
+ saveToCurrentDashboard: !1,
860
+ badgeType: "library",
861
+ description: "Creates a reusable visual in Visual Library.",
862
+ actionLabel: "Save as Library Visual"
863
+ } : {
864
+ saveToLibrary: !0,
865
+ saveToCurrentDashboard: !0,
866
+ badgeType: "linked",
867
+ description: "Creates a new library visual and adds a linked copy to this dashboard.",
868
+ actionLabel: "Save Copy as Linked Visual"
869
+ }, p = () => {
870
+ !g || n || u({
871
+ name: m.trim(),
872
+ description: d.trim() || void 0,
873
+ saveToLibrary: h.saveToLibrary,
874
+ saveToCurrentDashboard: h.saveToCurrentDashboard
875
+ });
876
+ };
877
+ return /* @__PURE__ */ e(Se, { open: t, onOpenChange: a, children: /* @__PURE__ */ r(De, { className: "sm:max-w-[500px]", children: [
878
+ /* @__PURE__ */ r(st, { children: [
879
+ /* @__PURE__ */ r(ke, { className: "flex items-center gap-2", children: [
880
+ /* @__PURE__ */ e("span", { children: "Save Visual As" }),
881
+ h.badgeType !== "local" && /* @__PURE__ */ e(
882
+ oa,
883
+ {
884
+ type: h.badgeType,
885
+ showLabel: !0,
886
+ className: "px-2 py-0.5"
887
+ }
888
+ )
889
+ ] }),
890
+ /* @__PURE__ */ e(ot, { children: h.description })
891
+ ] }),
892
+ /* @__PURE__ */ r("div", { className: "grid gap-4 py-4", children: [
893
+ /* @__PURE__ */ r("div", { className: "grid gap-2", children: [
894
+ /* @__PURE__ */ e(Ne, { htmlFor: "name", children: "Name" }),
895
+ /* @__PURE__ */ e(
896
+ Qe,
897
+ {
898
+ id: "name",
899
+ value: m,
900
+ onChange: (y) => l(y.target.value),
901
+ placeholder: "Enter visual name",
902
+ disabled: n
903
+ }
904
+ )
905
+ ] }),
906
+ /* @__PURE__ */ r("div", { className: "grid gap-2", children: [
907
+ /* @__PURE__ */ e(Ne, { htmlFor: "description", children: "Description (optional)" }),
908
+ /* @__PURE__ */ e(
909
+ rr,
910
+ {
911
+ id: "description",
912
+ value: d,
913
+ onChange: (y) => o(y.target.value),
914
+ placeholder: "Enter visual description",
915
+ rows: 3,
916
+ disabled: n
917
+ }
918
+ )
919
+ ] })
920
+ ] }),
921
+ /* @__PURE__ */ r(ar, { children: [
922
+ /* @__PURE__ */ e(
923
+ B,
924
+ {
925
+ variant: "outline",
926
+ onClick: () => a(!1),
927
+ disabled: n,
928
+ children: "Cancel"
929
+ }
930
+ ),
931
+ /* @__PURE__ */ r(B, { onClick: p, disabled: !g || n, children: [
932
+ n && /* @__PURE__ */ e(ee, { className: "mr-2 h-4 w-4 animate-spin" }),
933
+ h.actionLabel
934
+ ] })
935
+ ] })
936
+ ] }) });
937
+ }
938
+ function Ea() {
939
+ const [t, a] = A(!1), [i, s] = A(!1), [n, c] = A(null), [u, m] = A(null), l = be((f) => f.frame), d = be((f) => f.card), o = nr(), g = M((f) => f.selectedSheetId), h = M((f) => f.dashboard), { getUpdatedFrame: p } = ut(), { selectVisual: y } = Ct(), { addFrame: x, setSelectedFrameId: D, setIsVisualEditing: E } = xe(), N = Dt(), b = !!(l != null && l.visualId), S = (() => {
940
+ var f, C;
941
+ return ((f = l == null ? void 0 : l.cards) == null ? void 0 : f.length) === 1 && ((C = l.cards[0]) != null && C.title) ? l.cards[0].title : o != null && o.title ? o.title : (d == null ? void 0 : d.title) || "Untitled Visual";
942
+ })(), k = sr((f) => {
943
+ f != null && f.id && (y(f), i && n && u && g && (async () => {
944
+ try {
945
+ const C = {
946
+ ...n,
947
+ id: pt(),
948
+ visualId: f.id
949
+ // Link to the newly created library visual
950
+ };
951
+ x(g, C, {
952
+ position: "end",
953
+ semanticExecutionPayload: u
954
+ }), D(C.id), s(!1), c(null), m(null), E(!1);
955
+ } catch (C) {
956
+ console.error(
957
+ "Failed to promote semantic metadata for saved visual:",
958
+ C
959
+ ), z.error(
960
+ C instanceof Error ? C.message : "Failed to prepare semantic metadata for the saved visual"
961
+ );
962
+ }
963
+ })(), a(!1));
964
+ });
965
+ return {
966
+ saveAsDialogOpen: t,
967
+ setSaveAsDialogOpen: a,
968
+ handleSaveAs: async (f) => {
969
+ if (!g) {
970
+ z.error("No sheet selected");
971
+ return;
972
+ }
973
+ const C = p(), T = Bt(C);
974
+ if (T) {
975
+ z.error(T);
976
+ return;
977
+ }
978
+ const I = C.cards.length === 1 ? {
979
+ ...C,
980
+ cards: C.cards.map((R) => ({
981
+ ...R,
982
+ title: f.name
983
+ // Use visual name as card title
984
+ }))
985
+ } : C;
986
+ if (f.saveToLibrary) {
987
+ let R = null;
988
+ if (f.saveToCurrentDashboard)
989
+ try {
990
+ R = await N(I, {
991
+ previousFrame: Xe(h, I.id)
992
+ });
993
+ } catch (W) {
994
+ console.error(
995
+ "Failed to prepare semantic metadata before saving visual:",
996
+ W
997
+ ), z.error(
998
+ W instanceof Error ? W.message : "Failed to prepare semantic metadata for the saved visual"
999
+ );
1000
+ return;
1001
+ }
1002
+ s(f.saveToCurrentDashboard), c(I), m(R);
1003
+ const V = {
1004
+ title: f.name,
1005
+ description: f.description,
1006
+ frameObject: I,
1007
+ // Card title synced for single-card frames
1008
+ isPrivate: !1
1009
+ };
1010
+ k.mutate(V);
1011
+ } else if (f.saveToCurrentDashboard) {
1012
+ const R = {
1013
+ ...I,
1014
+ // Card title already synced
1015
+ id: pt(),
1016
+ visualId: void 0
1017
+ // Explicitly no visualId for local visuals
1018
+ };
1019
+ try {
1020
+ const V = await N(I, {
1021
+ previousFrame: Xe(h, I.id)
1022
+ });
1023
+ x(g, R, {
1024
+ position: "end",
1025
+ semanticExecutionPayload: V
1026
+ }), D(R.id), z.success("Visual saved to dashboard"), a(!1), E(!1);
1027
+ } catch (V) {
1028
+ console.error("Failed to save visual to dashboard:", V), z.error(
1029
+ V instanceof Error ? V.message : "Failed to prepare semantic metadata for the visual"
1030
+ );
1031
+ }
1032
+ }
1033
+ },
1034
+ isLibraryVisual: b,
1035
+ currentVisualName: S,
1036
+ isSaving: k.isPending
1037
+ };
1038
+ }
1039
+ function Vn(t = {}) {
1040
+ const a = be((I) => I.frame), i = be((I) => I.editorContext), s = or((I) => I.selectedVisual), n = M((I) => I.selectedFrameId), c = M((I) => I.selectedSheetId), u = M((I) => I.dashboard), { setIsVisualEditing: m, updateFrame: l } = xe(), [d, o] = A(!1), [g, h] = A("both"), p = Dt(), y = (i == null ? void 0 : i.type) === "documentSection", x = !!(a != null && a.visualId || s != null && s.id), D = !!(a != null && a.visualId && n), E = x && !D, {
1041
+ saveAsDialogOpen: N,
1042
+ setSaveAsDialogOpen: b,
1043
+ handleSaveAs: S,
1044
+ isLibraryVisual: k,
1045
+ currentVisualName: P,
1046
+ isSaving: f
1047
+ } = Ea(), { getUpdatedFrame: C } = ut();
1048
+ if (y)
1049
+ return /* @__PURE__ */ r(G, { children: [
1050
+ /* @__PURE__ */ e(ft, { className: "rounded-control", variant: "default" }),
1051
+ /* @__PURE__ */ e(gt, {})
1052
+ ] });
1053
+ const T = async () => {
1054
+ if (!c) {
1055
+ z.error("No sheet selected");
1056
+ return;
1057
+ }
1058
+ if (d) return;
1059
+ o(!0);
1060
+ const I = C(), R = Bt(I);
1061
+ if (R) {
1062
+ o(!1), z.error(R);
1063
+ return;
1064
+ }
1065
+ const V = {
1066
+ ...I,
1067
+ visualId: void 0
1068
+ }, W = Xe(u, V.id);
1069
+ try {
1070
+ const ae = await p(V, {
1071
+ previousFrame: W
1072
+ });
1073
+ l(c, V, {
1074
+ semanticExecutionPayload: ae
1075
+ });
1076
+ } catch (ae) {
1077
+ console.error("Failed to apply local semantic metadata:", ae), o(!1), z.error(
1078
+ ae instanceof Error ? ae.message : "Failed to prepare semantic metadata for this visual"
1079
+ );
1080
+ return;
1081
+ }
1082
+ setTimeout(() => {
1083
+ o(!1), z.success("Changes applied. Visual is now local to this dashboard"), m(!1);
1084
+ }, 300);
1085
+ }, F = (I) => {
1086
+ h(I), b(!0);
1087
+ };
1088
+ return /* @__PURE__ */ r(G, { children: [
1089
+ /* @__PURE__ */ r("div", { className: "inline-flex items-center overflow-hidden rounded-control", children: [
1090
+ !x && /* @__PURE__ */ e(ft, { className: "!rounded-none", variant: "default" }),
1091
+ x && E && /* @__PURE__ */ e(ia, { className: "!rounded-none", variant: "default" }),
1092
+ x && D && /* @__PURE__ */ e(la, { className: "!rounded-none" }),
1093
+ /* @__PURE__ */ r(Oe, { modal: !1, children: [
1094
+ /* @__PURE__ */ e(ze, { asChild: !0, children: /* @__PURE__ */ e(
1095
+ B,
1096
+ {
1097
+ variant: "default",
1098
+ size: "xs",
1099
+ className: "w-7 !rounded-none border-l border-primary-foreground/20 px-0",
1100
+ "aria-label": "Open visual save options",
1101
+ disabled: f || d,
1102
+ children: /* @__PURE__ */ e(Vt, { className: "h-3.5 w-3.5" })
1103
+ }
1104
+ ) }),
1105
+ /* @__PURE__ */ r(
1106
+ _e,
1107
+ {
1108
+ align: "end",
1109
+ className: "min-w-[220px] rounded-control border border-border/60 p-1 shadow-sm",
1110
+ children: [
1111
+ D && /* @__PURE__ */ r(G, { children: [
1112
+ /* @__PURE__ */ r(
1113
+ H,
1114
+ {
1115
+ onClick: T,
1116
+ disabled: d,
1117
+ children: [
1118
+ /* @__PURE__ */ e(Lt, { className: "h-3.5 w-3.5" }),
1119
+ d ? "Applying..." : "Apply Locally"
1120
+ ]
1121
+ }
1122
+ ),
1123
+ /* @__PURE__ */ e(Re, {})
1124
+ ] }),
1125
+ /* @__PURE__ */ r(
1126
+ H,
1127
+ {
1128
+ onClick: () => F("local"),
1129
+ disabled: f,
1130
+ children: [
1131
+ /* @__PURE__ */ e(ge, { className: "h-3.5 w-3.5" }),
1132
+ "Add to Dashboard (Local)"
1133
+ ]
1134
+ }
1135
+ ),
1136
+ /* @__PURE__ */ r(
1137
+ H,
1138
+ {
1139
+ onClick: () => F("library"),
1140
+ disabled: f,
1141
+ children: [
1142
+ /* @__PURE__ */ e(ca, { className: "h-3.5 w-3.5" }),
1143
+ "Save as Library Visual"
1144
+ ]
1145
+ }
1146
+ ),
1147
+ /* @__PURE__ */ r(
1148
+ H,
1149
+ {
1150
+ onClick: () => F("both"),
1151
+ disabled: f,
1152
+ children: [
1153
+ /* @__PURE__ */ e(da, { className: "h-3.5 w-3.5" }),
1154
+ "Save Copy as Linked Visual"
1155
+ ]
1156
+ }
1157
+ )
1158
+ ]
1159
+ }
1160
+ )
1161
+ ] })
1162
+ ] }),
1163
+ /* @__PURE__ */ e(gt, {}),
1164
+ /* @__PURE__ */ e(
1165
+ Aa,
1166
+ {
1167
+ open: N,
1168
+ onOpenChange: (I) => {
1169
+ f || b(I);
1170
+ },
1171
+ isLibraryVisual: k,
1172
+ currentVisualName: P,
1173
+ isSaving: f,
1174
+ destinationMode: g,
1175
+ onConfirm: S
1176
+ }
1177
+ )
1178
+ ] });
1179
+ }
1180
+ function Rn({ className: t }) {
1181
+ const a = be((d) => d.isDevMode), i = M((d) => d.isVisualEditing), { setIsDevMode: s } = Tt(), { config: n } = Wt(ir).tokenProps, c = (n == null ? void 0 : n.showAdvancedMode) !== !1;
1182
+ if (!i || !c)
1183
+ return null;
1184
+ const u = a ? ct : lr, m = a ? "Drag & drop" : "SQL", l = a ? "Switch to drag-and-drop mode" : "Switch to SQL mode";
1185
+ return /* @__PURE__ */ r(
1186
+ "button",
1187
+ {
1188
+ type: "button",
1189
+ "aria-label": l,
1190
+ title: l,
1191
+ onClick: () => s(!a),
1192
+ className: K(
1193
+ "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",
1194
+ t
1195
+ ),
1196
+ children: [
1197
+ /* @__PURE__ */ e(u, { className: "h-3 w-3 text-muted-foreground" }),
1198
+ m
1199
+ ]
1200
+ }
1201
+ );
1202
+ }
1203
+ function Un({
1204
+ open: t,
1205
+ onOpenChange: a,
1206
+ onSave: i,
1207
+ onDiscard: s,
1208
+ isSaving: n,
1209
+ title: c = "Unsaved changes",
1210
+ description: u = "You have unsaved changes to this dashboard. What would you like to do?",
1211
+ cancelLabel: m = "Cancel",
1212
+ discardLabel: l = "Discard",
1213
+ saveLabel: d = "Save"
1214
+ }) {
1215
+ return /* @__PURE__ */ e(Ye, { open: t, onOpenChange: (g) => {
1216
+ !g && n || a(g);
1217
+ }, children: /* @__PURE__ */ r(Ze, { children: [
1218
+ /* @__PURE__ */ r(Je, { children: [
1219
+ /* @__PURE__ */ e(et, { children: c }),
1220
+ /* @__PURE__ */ e(tt, { children: u })
1221
+ ] }),
1222
+ /* @__PURE__ */ r(rt, { children: [
1223
+ /* @__PURE__ */ e(
1224
+ B,
1225
+ {
1226
+ type: "button",
1227
+ size: "xs",
1228
+ onClick: s,
1229
+ disabled: n,
1230
+ variant: "ghost",
1231
+ className: "mr-auto text-muted-foreground hover:bg-destructive/10 hover:text-destructive focus-visible:bg-destructive/10 focus-visible:text-destructive",
1232
+ children: l
1233
+ }
1234
+ ),
1235
+ /* @__PURE__ */ e(at, { disabled: n, children: m }),
1236
+ /* @__PURE__ */ e(B, { type: "button", size: "xs", onClick: i, disabled: n, children: n ? /* @__PURE__ */ r(G, { children: [
1237
+ /* @__PURE__ */ e(ee, { className: "mr-2 h-3.5 w-3.5 animate-spin" }),
1238
+ "Saving..."
1239
+ ] }) : d })
1240
+ ] })
1241
+ ] }) });
1242
+ }
1243
+ const Fa = 1e4, Ia = 15e3, La = 3e4, Ba = 3e4, Ta = 12e4, vt = 2 * 60 * 60 * 1e3;
1244
+ function Va(t) {
1245
+ const a = Date.now() - t.getTime();
1246
+ return a < Ba ? Fa : a < Ta ? Ia : La;
1247
+ }
1248
+ function Pn() {
1249
+ const { authToken: t, tokenProps: a } = $e(), i = he((h) => h.activeExports), [s, n] = A(
1250
+ typeof document < "u" ? !document.hidden : !0
1251
+ ), c = me(null), u = me(!1), m = me(void 0), l = a == null ? void 0 : a.apiServiceUrl, d = t == null ? void 0 : t.accessToken, o = q(() => {
1252
+ const h = he.getState().activeExports;
1253
+ return Array.from(h.values()).filter(
1254
+ (p) => it(p.status)
1255
+ );
1256
+ }, []);
1257
+ Z(() => {
1258
+ if (typeof document > "u") return;
1259
+ const h = () => {
1260
+ n(!document.hidden);
1261
+ };
1262
+ return document.addEventListener("visibilitychange", h), () => {
1263
+ document.removeEventListener("visibilitychange", h);
1264
+ };
1265
+ }, []);
1266
+ const g = q(async () => {
1267
+ if (!l || !d) {
1268
+ u.current = !1;
1269
+ return;
1270
+ }
1271
+ const h = o();
1272
+ if (h.length === 0) {
1273
+ u.current = !1;
1274
+ return;
1275
+ }
1276
+ const p = Date.now(), y = h.filter(
1277
+ (b) => p - b.startedAt.getTime() > vt
1278
+ );
1279
+ if (y.length > 0) {
1280
+ const { updateExport: b } = he.getState().actions;
1281
+ for (const S of y)
1282
+ b(S.id, {
1283
+ status: "failed",
1284
+ error: "Export timed out. Please try again or contact support.",
1285
+ lastUpdatedAt: /* @__PURE__ */ new Date()
1286
+ });
1287
+ }
1288
+ const x = h.filter(
1289
+ (b) => p - b.startedAt.getTime() <= vt
1290
+ );
1291
+ if (x.length === 0) {
1292
+ u.current = !1;
1293
+ return;
1294
+ }
1295
+ const D = await Promise.allSettled(
1296
+ x.map(async (b) => {
1297
+ try {
1298
+ const S = await kt(l, d, b.id);
1299
+ let k;
1300
+ if (S.status === "completed")
1301
+ try {
1302
+ k = await lt(l, d, b.id);
1303
+ } catch (P) {
1304
+ console.error(
1305
+ `[useExportPolling] Failed to get download URL for ${b.id}:`,
1306
+ P
1307
+ );
1308
+ }
1309
+ return {
1310
+ id: b.id,
1311
+ status: S.status,
1312
+ progress: S.progress,
1313
+ completedChunks: S.completedChunks,
1314
+ completedAt: S.completedAt ? new Date(S.completedAt) : void 0,
1315
+ lastUpdatedAt: /* @__PURE__ */ new Date(),
1316
+ fileSize: S.fileSize,
1317
+ error: S.error,
1318
+ downloadUrl: k
1319
+ };
1320
+ } catch (S) {
1321
+ return console.error(
1322
+ `[useExportPolling] Failed to poll export ${b.id}:`,
1323
+ S
1324
+ ), null;
1325
+ }
1326
+ })
1327
+ ), { updateExport: E } = he.getState().actions;
1328
+ for (const b of D)
1329
+ b.status === "fulfilled" && b.value && E(b.value.id, b.value);
1330
+ const N = o();
1331
+ if (N.length > 0 && !document.hidden) {
1332
+ const b = N.reduce(
1333
+ (k, P) => P.startedAt < k ? P.startedAt : k,
1334
+ N[0].startedAt
1335
+ ), S = Va(b);
1336
+ c.current && clearTimeout(c.current), c.current = setTimeout(() => {
1337
+ var k;
1338
+ (k = m.current) == null || k.call(m);
1339
+ }, S);
1340
+ } else
1341
+ u.current = !1;
1342
+ }, [l, d, o]);
1343
+ return Z(() => {
1344
+ m.current = g;
1345
+ }, [g]), Z(() => {
1346
+ var p;
1347
+ o().length > 0 && s && !u.current && (u.current = !0, (p = m.current) == null || p.call(m));
1348
+ }, [i, s, o]), Z(() => {
1349
+ var p;
1350
+ const h = o();
1351
+ s && h.length > 0 && !u.current && (u.current = !0, (p = m.current) == null || p.call(m));
1352
+ }, [s, o]), Z(() => {
1353
+ !s && c.current && (clearTimeout(c.current), c.current = null, u.current = !1);
1354
+ }, [s]), Z(() => () => {
1355
+ c.current && (clearTimeout(c.current), c.current = null);
1356
+ }, []), {
1357
+ isPolling: u.current,
1358
+ isTabVisible: s,
1359
+ inProgressCount: o().length
1360
+ };
1361
+ }
1362
+ function Mn() {
1363
+ const { authToken: t, tokenProps: a } = $e(), i = he((m) => m.activeExports), { addExport: s } = At(), n = me(!1), c = a == null ? void 0 : a.apiServiceUrl, u = t == null ? void 0 : t.accessToken;
1364
+ Z(() => {
1365
+ if (n.current || !c || !u) return;
1366
+ (async () => {
1367
+ try {
1368
+ const { exports: l } = await cr(c, u, {
1369
+ status: ["pending", "processing", "chunking", "compacting", "completed", "failed"],
1370
+ limit: 20
1371
+ // Limit to recent exports
1372
+ });
1373
+ for (const d of l) {
1374
+ if (i.has(d.id)) continue;
1375
+ const o = d.totalChunks ? Math.round(d.completedChunks / d.totalChunks * 100) : 0;
1376
+ let g;
1377
+ if (d.status === "completed")
1378
+ try {
1379
+ g = await lt(c, u, d.id);
1380
+ } catch (p) {
1381
+ console.error(
1382
+ `[useExportRecovery] Failed to get download URL for ${d.id}:`,
1383
+ p
1384
+ );
1385
+ }
1386
+ const h = {
1387
+ id: d.id,
1388
+ status: d.status,
1389
+ progress: o,
1390
+ title: Ra(d),
1391
+ totalRows: d.totalRows,
1392
+ totalChunks: d.totalChunks,
1393
+ completedChunks: d.completedChunks,
1394
+ startedAt: new Date(d.createdAt),
1395
+ lastUpdatedAt: /* @__PURE__ */ new Date(),
1396
+ completedAt: d.completedAt ? new Date(d.completedAt) : void 0,
1397
+ fileSize: d.fileSize,
1398
+ error: d.error,
1399
+ expiresAt: new Date(d.expiresAt),
1400
+ downloadUrl: g
1401
+ };
1402
+ s(h);
1403
+ }
1404
+ n.current = !0;
1405
+ } catch (l) {
1406
+ console.error("[useExportRecovery] Failed to recover exports:", l), n.current = !0;
1407
+ }
1408
+ })();
1409
+ }, [c, u, s, i]);
1410
+ }
1411
+ function Ra(t) {
1412
+ return t.title ? t.title : it(
1413
+ t.status
1414
+ ) ? "Export in progress..." : t.status === "completed" ? "Export completed" : t.status === "failed" ? "Export failed" : "Export";
1415
+ }
1416
+ function Ua({
1417
+ export: t,
1418
+ onRemove: a
1419
+ }) {
1420
+ const i = () => {
1421
+ t.downloadUrl && window.open(t.downloadUrl, "_blank");
1422
+ }, s = (m) => {
1423
+ m.stopPropagation(), a == null || a(t.id);
1424
+ }, n = () => {
1425
+ switch (t.status) {
1426
+ case "completed":
1427
+ return /* @__PURE__ */ e(mr, { className: "mt-0.5 h-5 w-5 shrink-0 text-green-600" });
1428
+ case "failed":
1429
+ return /* @__PURE__ */ e(ga, { className: "mt-0.5 h-5 w-5 shrink-0 text-destructive" });
1430
+ default:
1431
+ return /* @__PURE__ */ e(ee, { className: "text-foreground-muted mt-0.5 h-5 w-5 shrink-0 animate-spin" });
1432
+ }
1433
+ }, c = it(t.status), u = (() => {
1434
+ switch (t.status) {
1435
+ case "pending":
1436
+ return "Queued...";
1437
+ case "processing":
1438
+ return "Processing...";
1439
+ case "chunking":
1440
+ return "Processing...";
1441
+ case "compacting":
1442
+ return "Finalizing...";
1443
+ default:
1444
+ return "Processing...";
1445
+ }
1446
+ })();
1447
+ return /* @__PURE__ */ r("div", { className: "group p-4 transition-colors hover:bg-muted/50", children: [
1448
+ /* @__PURE__ */ r("div", { className: "mb-2 flex items-start justify-between gap-3", children: [
1449
+ /* @__PURE__ */ r("div", { className: "flex min-w-0 flex-1 items-start gap-3", children: [
1450
+ n(),
1451
+ /* @__PURE__ */ r("div", { className: "min-w-0 flex-1", children: [
1452
+ /* @__PURE__ */ e("h4", { className: "mb-1 truncate text-sm font-medium", children: t.title }),
1453
+ t.status === "completed" && /* @__PURE__ */ r("div", { className: "flex items-center gap-2 text-xs text-muted-foreground", children: [
1454
+ /* @__PURE__ */ r("span", { children: [
1455
+ t.totalRows.toLocaleString(),
1456
+ " rows"
1457
+ ] }),
1458
+ t.fileSize && /* @__PURE__ */ r(G, { children: [
1459
+ /* @__PURE__ */ e("span", { children: "•" }),
1460
+ /* @__PURE__ */ e("span", { children: dr(t.fileSize) })
1461
+ ] })
1462
+ ] }),
1463
+ c && /* @__PURE__ */ e("div", { className: "text-xs text-muted-foreground", children: u }),
1464
+ t.status === "failed" && /* @__PURE__ */ e("div", { className: "line-clamp-2 text-xs text-destructive", children: t.error || "Export failed" })
1465
+ ] })
1466
+ ] }),
1467
+ /* @__PURE__ */ e(
1468
+ B,
1469
+ {
1470
+ variant: "ghost",
1471
+ size: "icon",
1472
+ className: "h-6 w-6 shrink-0 opacity-0 transition-opacity group-hover:opacity-100",
1473
+ onClick: s,
1474
+ "aria-label": "Remove notification",
1475
+ children: /* @__PURE__ */ e(je, { className: "h-4 w-4" })
1476
+ }
1477
+ )
1478
+ ] }),
1479
+ /* @__PURE__ */ r("div", { className: "ml-8", children: [
1480
+ t.status === "completed" && /* @__PURE__ */ r("div", { className: "flex items-center justify-between", children: [
1481
+ /* @__PURE__ */ e("span", { className: "text-xs text-muted-foreground", children: bt(t.startedAt, { addSuffix: !0 }) }),
1482
+ t.downloadUrl && /* @__PURE__ */ r(
1483
+ B,
1484
+ {
1485
+ size: "sm",
1486
+ variant: "outline",
1487
+ className: "h-8 bg-transparent",
1488
+ onClick: i,
1489
+ children: [
1490
+ /* @__PURE__ */ e(ur, { className: "mr-1.5 h-3.5 w-3.5" }),
1491
+ "Download"
1492
+ ]
1493
+ }
1494
+ )
1495
+ ] }),
1496
+ c && /* @__PURE__ */ r("div", { children: [
1497
+ /* @__PURE__ */ e(hr, { value: t.progress, className: "h-1.5" }),
1498
+ /* @__PURE__ */ r("span", { className: "mt-1 block text-xs text-muted-foreground", children: [
1499
+ t.progress,
1500
+ "% complete"
1501
+ ] })
1502
+ ] }),
1503
+ t.status === "failed" && /* @__PURE__ */ e("span", { className: "text-xs text-muted-foreground", children: bt(t.startedAt, { addSuffix: !0 }) })
1504
+ ] })
1505
+ ] });
1506
+ }
1507
+ function Pa() {
1508
+ const { authToken: t, tokenProps: a } = $e(), i = he((x) => x.activeExports), { clearCompleted: s, removeExport: n, updateExport: c } = At(), [u, m] = A(!1), [l, d] = A(!1), o = Array.from(i.values()).sort(
1509
+ (x, D) => D.startedAt.getTime() - x.startedAt.getTime()
1510
+ ), g = o.some(
1511
+ (x) => x.status === "completed" || x.status === "failed"
1512
+ ), h = q(async () => {
1513
+ const x = a == null ? void 0 : a.apiServiceUrl, D = t == null ? void 0 : t.accessToken;
1514
+ if (!(!x || !D)) {
1515
+ m(!0);
1516
+ try {
1517
+ const E = Array.from(i.values());
1518
+ await Promise.all(
1519
+ E.map(async (N) => {
1520
+ try {
1521
+ const b = await kt(x, D, N.id);
1522
+ let S;
1523
+ if (b.status === "completed")
1524
+ try {
1525
+ S = await lt(
1526
+ x,
1527
+ D,
1528
+ N.id
1529
+ );
1530
+ } catch (k) {
1531
+ console.error(`Failed to get download URL for ${N.id}:`, k);
1532
+ }
1533
+ c(N.id, {
1534
+ status: b.status,
1535
+ progress: b.progress,
1536
+ completedChunks: b.completedChunks,
1537
+ completedAt: b.completedAt ? new Date(b.completedAt) : void 0,
1538
+ lastUpdatedAt: /* @__PURE__ */ new Date(),
1539
+ fileSize: b.fileSize,
1540
+ error: b.error,
1541
+ downloadUrl: S
1542
+ });
1543
+ } catch (b) {
1544
+ console.error(`Failed to refresh export ${N.id}:`, b);
1545
+ }
1546
+ })
1547
+ );
1548
+ } finally {
1549
+ m(!1);
1550
+ }
1551
+ }
1552
+ }, [
1553
+ i,
1554
+ t == null ? void 0 : t.accessToken,
1555
+ a == null ? void 0 : a.apiServiceUrl,
1556
+ c
1557
+ ]), p = q(async () => {
1558
+ const x = a == null ? void 0 : a.apiServiceUrl, D = t == null ? void 0 : t.accessToken;
1559
+ if (!x || !D) {
1560
+ s();
1561
+ return;
1562
+ }
1563
+ d(!0);
1564
+ try {
1565
+ const E = o.filter(
1566
+ (b) => b.status === "completed" || b.status === "failed"
1567
+ ), N = await Promise.allSettled(
1568
+ E.map(async (b) => (await mt(x, D, b.id), b.id))
1569
+ );
1570
+ for (const b of N)
1571
+ b.status === "fulfilled" ? n(b.value) : console.error("Failed to delete export:", b.reason);
1572
+ } finally {
1573
+ d(!1);
1574
+ }
1575
+ }, [
1576
+ o,
1577
+ a == null ? void 0 : a.apiServiceUrl,
1578
+ t == null ? void 0 : t.accessToken,
1579
+ s,
1580
+ n
1581
+ ]), y = q(
1582
+ async (x) => {
1583
+ const D = a == null ? void 0 : a.apiServiceUrl, E = t == null ? void 0 : t.accessToken;
1584
+ if (D && E)
1585
+ try {
1586
+ await mt(D, E, x), n(x);
1587
+ return;
1588
+ } catch (N) {
1589
+ console.error(`Failed to cancel export ${x}:`, N);
1590
+ }
1591
+ n(x);
1592
+ },
1593
+ [a == null ? void 0 : a.apiServiceUrl, t == null ? void 0 : t.accessToken, n]
1594
+ );
1595
+ return o.length === 0 ? /* @__PURE__ */ r("div", { className: "p-6 text-center", children: [
1596
+ /* @__PURE__ */ e(xt, { className: "mx-auto mb-2 h-8 w-8 text-muted-foreground" }),
1597
+ /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: "No active exports" }),
1598
+ /* @__PURE__ */ e("p", { className: "mt-1 text-xs text-muted-foreground", children: "Large exports will appear here" })
1599
+ ] }) : /* @__PURE__ */ r("div", { className: "flex flex-col", children: [
1600
+ /* @__PURE__ */ r("div", { className: "flex items-center justify-between border-b px-4 py-3", children: [
1601
+ /* @__PURE__ */ r("div", { className: "flex items-center gap-2", children: [
1602
+ /* @__PURE__ */ e(xt, { className: "h-5 w-5 text-muted-foreground" }),
1603
+ /* @__PURE__ */ e("h4", { className: "font-semibold", children: "Exports" })
1604
+ ] }),
1605
+ /* @__PURE__ */ r("div", { className: "flex items-center gap-1", children: [
1606
+ /* @__PURE__ */ e(
1607
+ B,
1608
+ {
1609
+ variant: "ghost",
1610
+ size: "sm",
1611
+ className: "h-7 w-7 p-0",
1612
+ onClick: h,
1613
+ disabled: u,
1614
+ title: "Refresh status",
1615
+ children: /* @__PURE__ */ e(
1616
+ pr,
1617
+ {
1618
+ className: `h-4 w-4 ${u ? "animate-spin" : ""}`
1619
+ }
1620
+ )
1621
+ }
1622
+ ),
1623
+ g && /* @__PURE__ */ e(
1624
+ B,
1625
+ {
1626
+ variant: "ghost",
1627
+ size: "sm",
1628
+ className: "h-7 px-2 text-sm",
1629
+ onClick: p,
1630
+ disabled: l,
1631
+ children: l ? "Clearing..." : "Clear all"
1632
+ }
1633
+ )
1634
+ ] })
1635
+ ] }),
1636
+ /* @__PURE__ */ e("div", { className: "max-h-[350px] overflow-y-auto", children: /* @__PURE__ */ e("div", { className: "divide-y", children: o.map((x) => /* @__PURE__ */ e(
1637
+ Ua,
1638
+ {
1639
+ export: x,
1640
+ onRemove: y
1641
+ },
1642
+ x.id
1643
+ )) }) })
1644
+ ] });
1645
+ }
1646
+ function On({
1647
+ variant: t
1648
+ }) {
1649
+ const a = he((l) => l.activeExports), i = fr(), s = a.size > 0, n = Array.from(a.values()).some(
1650
+ (l) => l.status === "completed" || l.status === "failed"
1651
+ ), u = i > 0 ? i > 9 ? "9+" : String(i) : null;
1652
+ return /* @__PURE__ */ r(Ue, { children: [
1653
+ /* @__PURE__ */ e(Pe, { asChild: !0, children: /* @__PURE__ */ r(
1654
+ B,
1655
+ {
1656
+ variant: t ?? "ghost",
1657
+ size: "xs",
1658
+ className: "relative w-7 px-0 text-muted-foreground hover:text-foreground",
1659
+ "aria-label": "Export notifications",
1660
+ children: [
1661
+ /* @__PURE__ */ e(gr, { className: "h-3.5 w-3.5" }),
1662
+ s && /* @__PURE__ */ e(
1663
+ "span",
1664
+ {
1665
+ className: `absolute flex items-center justify-center rounded-full bg-primary text-primary-foreground ${u ? "-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"}`,
1666
+ children: u
1667
+ }
1668
+ )
1669
+ ]
1670
+ }
1671
+ ) }),
1672
+ /* @__PURE__ */ e(Me, { className: "w-80 p-0", align: "end", sideOffset: 8, children: /* @__PURE__ */ e(Pa, {}) })
1673
+ ] });
1674
+ }
1675
+ function Ma(t) {
1676
+ if (t)
1677
+ return {
1678
+ renamed: t.type === "rename" ? { oldId: t.oldId, newId: t.newId } : void 0,
1679
+ removedControlId: t.type === "remove" ? t.controlId : void 0,
1680
+ cardBindingsById: t.type === "add" || t.type === "update" ? t.cardBindingsById : void 0,
1681
+ affectedBindingControlIds: t.type === "add" || t.type === "update" ? t.affectedBindingControlIds : void 0
1682
+ };
1683
+ }
1684
+ function Oa({
1685
+ open: t,
1686
+ onOpenChange: a,
1687
+ trigger: i,
1688
+ showTrigger: s = !0,
1689
+ initialMode: n = "manage"
1690
+ }) {
1691
+ const c = n === "create", {
1692
+ forceClose: u,
1693
+ handleOpenChange: m,
1694
+ isCreateFlowActive: l,
1695
+ preventPassiveDismissDuringCreate: d,
1696
+ resolvedOpen: o,
1697
+ setIsCreateFlowActive: g
1698
+ } = Rt({
1699
+ open: t,
1700
+ onOpenChange: a,
1701
+ initialCreateFlowActive: n === "create",
1702
+ // Dialog mode renders a built-in X close button — allow explicit
1703
+ // closes through `handleOpenChange`. Popover mode has no X; its
1704
+ // only close-via-trigger path is a re-click that would silently
1705
+ // wipe the in-progress create flow, so block everything during
1706
+ // create and make consumers use `forceClose()` from a dedicated
1707
+ // button.
1708
+ dismissMode: s ? "passive" : "explicit-only"
1709
+ }), h = M((C) => C.dashboard), { setDashboardControlsModel: p } = xe(), { participants: y } = br(aa(h)), x = Array.from(
1710
+ new Map(
1711
+ y.flatMap(
1712
+ (C) => C.fieldChoices.map((T) => {
1713
+ var F;
1714
+ return [
1715
+ T.value,
1716
+ {
1717
+ option: T,
1718
+ target: (F = C.fieldTargetMap) == null ? void 0 : F[T.value]
1719
+ }
1720
+ ];
1721
+ })
1722
+ )
1723
+ ).values()
1724
+ ), D = Array.from(
1725
+ new Map(
1726
+ y.flatMap(
1727
+ (C) => C.metricChoices.map((T) => {
1728
+ var F;
1729
+ return [
1730
+ T.value,
1731
+ {
1732
+ option: T,
1733
+ target: (F = C.metricTargetMap) == null ? void 0 : F[T.value]
1734
+ }
1735
+ ];
1736
+ })
1737
+ )
1738
+ ).values()
1739
+ ), E = na({
1740
+ ...h || {},
1741
+ controls: []
1742
+ }), N = xr(h), b = (C, T, F) => {
1743
+ p(
1744
+ C,
1745
+ T,
1746
+ Ma(F)
1747
+ );
1748
+ }, S = q(() => {
1749
+ if (c) {
1750
+ u();
1751
+ return;
1752
+ }
1753
+ g(!1);
1754
+ }, [c, u, g]), k = /* @__PURE__ */ e(
1755
+ Ut,
1756
+ {
1757
+ scope: "dashboard",
1758
+ controls: h.controls || [],
1759
+ reservedControlIds: E,
1760
+ defaultValues: h.defaultControlValues || {},
1761
+ usageByControlId: vr(h),
1762
+ availableFieldChoices: x,
1763
+ availableMetricChoices: D,
1764
+ structuralParticipants: y,
1765
+ structuralParticipantIdsByControlId: N,
1766
+ initialCreateFlow: n === "create",
1767
+ onCreateFlowActiveChange: g,
1768
+ onCreateFlowComplete: S,
1769
+ onChange: b,
1770
+ emptyMessage: "No dashboard controls yet."
1771
+ }
1772
+ ), P = l ? "Add dashboard control" : "Dashboard Controls", f = /* @__PURE__ */ r(G, { children: [
1773
+ /* @__PURE__ */ r("div", { className: "space-y-1", children: [
1774
+ /* @__PURE__ */ e("h4", { className: "text-sm font-medium", children: "Dashboard Controls" }),
1775
+ /* @__PURE__ */ e("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." })
1776
+ ] }),
1777
+ k
1778
+ ] });
1779
+ return s ? /* @__PURE__ */ r(Ue, { open: o, onOpenChange: m, children: [
1780
+ /* @__PURE__ */ e(Pe, { asChild: !0, children: i || /* @__PURE__ */ r(B, { variant: "outline", className: "h-7 px-2", size: "sm", children: [
1781
+ /* @__PURE__ */ e(ct, { className: "mr-2 h-4 w-4" }),
1782
+ "Controls"
1783
+ ] }) }),
1784
+ /* @__PURE__ */ e(
1785
+ Me,
1786
+ {
1787
+ className: "w-[620px] max-w-[95vw] space-y-4",
1788
+ align: "end",
1789
+ onEscapeKeyDown: d,
1790
+ onPointerDownOutside: d,
1791
+ children: f
1792
+ }
1793
+ )
1794
+ ] }) : /* @__PURE__ */ e(Se, { open: o, onOpenChange: m, children: /* @__PURE__ */ r(
1795
+ De,
1796
+ {
1797
+ className: "flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",
1798
+ onEscapeKeyDown: d,
1799
+ onPointerDownOutside: d,
1800
+ children: [
1801
+ /* @__PURE__ */ r(
1802
+ st,
1803
+ {
1804
+ className: l ? "space-y-0" : void 0,
1805
+ children: [
1806
+ /* @__PURE__ */ e(ke, { className: "text-[15px]", children: P }),
1807
+ /* @__PURE__ */ e(
1808
+ ot,
1809
+ {
1810
+ className: l ? "sr-only" : "text-[13px]",
1811
+ 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."
1812
+ }
1813
+ )
1814
+ ]
1815
+ }
1816
+ ),
1817
+ /* @__PURE__ */ e("div", { className: "min-h-0 overflow-y-auto pr-1", children: k })
1818
+ ]
1819
+ }
1820
+ ) });
1821
+ }
1822
+ const za = [
1823
+ "enum",
1824
+ "multi_enum",
1825
+ "text",
1826
+ "number",
1827
+ "boolean",
1828
+ "date"
1829
+ ];
1830
+ function _a({
1831
+ open: t,
1832
+ onOpenChange: a,
1833
+ initialMode: i = "manage"
1834
+ }) {
1835
+ var f;
1836
+ const s = i === "create", {
1837
+ forceClose: n,
1838
+ handleOpenChange: c,
1839
+ isCreateFlowActive: u,
1840
+ preventPassiveDismissDuringCreate: m,
1841
+ resolvedOpen: l,
1842
+ setIsCreateFlowActive: d
1843
+ } = Rt({
1844
+ open: t,
1845
+ onOpenChange: a,
1846
+ initialCreateFlowActive: i === "create",
1847
+ dismissMode: "explicit-only"
1848
+ }), o = M((C) => C.dashboard), g = M((C) => C.selectedSheetId), { setDashboardInputs: h } = xe(), p = (f = o.sheets) == null ? void 0 : f.find(
1849
+ (C) => C.id === g
1850
+ ), y = (p == null ? void 0 : p.kind) === "document" && !!p.document, x = J(
1851
+ () => y && (p != null && p.document) ? yr(o, p.id) : [],
1852
+ [o, y, p == null ? void 0 : p.document, p == null ? void 0 : p.id]
1853
+ ), D = J(
1854
+ () => x.filter(
1855
+ (C) => C.kind === "control"
1856
+ ),
1857
+ [x]
1858
+ ), E = J(
1859
+ () => D.map((C) => C.control),
1860
+ [D]
1861
+ ), N = J(
1862
+ () => ja(E),
1863
+ [E]
1864
+ ), b = J(
1865
+ () => $a(o),
1866
+ [o]
1867
+ ), S = q(() => {
1868
+ if (s) {
1869
+ n();
1870
+ return;
1871
+ }
1872
+ d(!1);
1873
+ }, [s, n, d]), k = q(
1874
+ (C, T, F) => {
1875
+ !y || !(p != null && p.document) || h(
1876
+ Ha({
1877
+ allInputs: o.inputs || [],
1878
+ documentSheetId: p.id,
1879
+ currentDocumentInputs: x,
1880
+ nextControls: C,
1881
+ nextDefaultValues: T,
1882
+ change: F
1883
+ })
1884
+ );
1885
+ },
1886
+ [
1887
+ o.inputs,
1888
+ x,
1889
+ y,
1890
+ p,
1891
+ h
1892
+ ]
1893
+ );
1894
+ return !y || !(p != null && p.document) ? null : /* @__PURE__ */ e(Se, { open: l, onOpenChange: c, children: /* @__PURE__ */ r(
1895
+ De,
1896
+ {
1897
+ className: "flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",
1898
+ onEscapeKeyDown: m,
1899
+ onPointerDownOutside: m,
1900
+ children: [
1901
+ /* @__PURE__ */ r(st, { className: u ? "space-y-0" : void 0, children: [
1902
+ /* @__PURE__ */ e(ke, { className: "text-[15px]", children: u ? "Add document control" : "Document Controls" }),
1903
+ /* @__PURE__ */ e(
1904
+ ot,
1905
+ {
1906
+ className: u ? "sr-only" : "text-[13px]",
1907
+ children: u ? "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."
1908
+ }
1909
+ )
1910
+ ] }),
1911
+ /* @__PURE__ */ e("div", { className: "min-h-0 overflow-y-auto pr-1", children: /* @__PURE__ */ e(
1912
+ Ut,
1913
+ {
1914
+ scope: "dashboard",
1915
+ controls: E,
1916
+ reservedControlIds: b,
1917
+ defaultValues: N,
1918
+ usageByControlId: {},
1919
+ availableFieldChoices: [],
1920
+ availableMetricChoices: [],
1921
+ structuralParticipants: [],
1922
+ structuralParticipantIdsByControlId: {},
1923
+ allowedControlTypes: za,
1924
+ initialCreateFlow: i === "create",
1925
+ onCreateFlowActiveChange: d,
1926
+ onCreateFlowComplete: S,
1927
+ onChange: k,
1928
+ emptyMessage: "No document controls yet."
1929
+ }
1930
+ ) })
1931
+ ]
1932
+ }
1933
+ ) });
1934
+ }
1935
+ function $a(t) {
1936
+ return (t.controls || []).map((a) => a.id);
1937
+ }
1938
+ function ja(t) {
1939
+ const a = {};
1940
+ for (const i of t)
1941
+ i.defaultValue !== void 0 && (a[i.id] = i.defaultValue);
1942
+ return a;
1943
+ }
1944
+ function Wa(t, a) {
1945
+ return a ? Object.prototype.hasOwnProperty.call(a, t.id) ? {
1946
+ ...t,
1947
+ defaultValue: a[t.id]
1948
+ } : t.defaultValue === void 0 ? t : { ...t, defaultValue: void 0 } : t.defaultValue === void 0 ? t : { ...t, defaultValue: void 0 };
1949
+ }
1950
+ function Ha({
1951
+ allInputs: t,
1952
+ documentSheetId: a,
1953
+ currentDocumentInputs: i,
1954
+ nextControls: s,
1955
+ nextDefaultValues: n,
1956
+ change: c
1957
+ }) {
1958
+ const u = new Map(
1959
+ s.map((h) => [
1960
+ h.id,
1961
+ Wa(h, n)
1962
+ ])
1963
+ ), m = (c == null ? void 0 : c.type) === "rename" ? { oldId: c.oldId, newId: c.newId } : null, l = /* @__PURE__ */ new Set(), d = [];
1964
+ for (const h of i) {
1965
+ if (h.kind !== "control") {
1966
+ d.push(h);
1967
+ continue;
1968
+ }
1969
+ const p = u.get(h.control.id) || ((m == null ? void 0 : m.oldId) === h.control.id ? u.get(m.newId) : void 0);
1970
+ if (!p)
1971
+ continue;
1972
+ l.add(p.id);
1973
+ const y = Cr(
1974
+ p.id,
1975
+ [...t, ...d].filter(
1976
+ (D) => D.id !== h.id
1977
+ )
1978
+ ), x = p.id === y ? p : { ...p, id: y };
1979
+ d.push({
1980
+ ...h,
1981
+ label: x.label,
1982
+ variableName: y,
1983
+ requiredAtExecution: x.requiredAtExecution,
1984
+ control: x
1985
+ });
1986
+ }
1987
+ for (const h of u.values())
1988
+ l.has(h.id) || d.push(
1989
+ wr({
1990
+ control: h,
1991
+ existingInputs: [...t, ...d],
1992
+ sheetId: a
1993
+ })
1994
+ );
1995
+ const o = new Set(
1996
+ i.map((h) => h.id)
1997
+ );
1998
+ return [...t.filter(
1999
+ (h) => !o.has(h.id)
2000
+ ), ...d];
2001
+ }
2002
+ function Ga({
2003
+ showFilters: t,
2004
+ onShowFiltersChange: a,
2005
+ pickerContent: i,
2006
+ settingsContent: s,
2007
+ size: n = "default",
2008
+ className: c,
2009
+ primaryButtonClassName: u,
2010
+ secondaryButtonClassName: m,
2011
+ pickerContentClassName: l,
2012
+ settingsContentClassName: d
2013
+ }) {
2014
+ const o = n === "toolbar", [g, h] = A(!1), p = Nr("interactive");
2015
+ return /* @__PURE__ */ r(
2016
+ "div",
2017
+ {
2018
+ className: K(
2019
+ // Height lives on the shell so the outer border is part of the
2020
+ // h-7 box (matches regular `size="xs"` buttons). Inner triggers
2021
+ // stretch to fill via `h-full`.
2022
+ "relative inline-flex items-stretch overflow-hidden rounded-control border border-input bg-background",
2023
+ o ? "h-8" : "h-7",
2024
+ c
2025
+ ),
2026
+ children: [
2027
+ /* @__PURE__ */ r(Ue, { open: t, onOpenChange: a, children: [
2028
+ /* @__PURE__ */ e(Pe, { asChild: !0, children: /* @__PURE__ */ r(
2029
+ B,
2030
+ {
2031
+ variant: "ghost",
2032
+ size: "xs",
2033
+ className: K(
2034
+ "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",
2035
+ u
2036
+ ),
2037
+ children: [
2038
+ t ? /* @__PURE__ */ e(ba, { className: "h-3.5 w-3.5" }) : /* @__PURE__ */ e(Et, { className: "h-3.5 w-3.5" }),
2039
+ "Filter"
2040
+ ]
2041
+ }
2042
+ ) }),
2043
+ /* @__PURE__ */ e(
2044
+ Me,
2045
+ {
2046
+ align: "end",
2047
+ sideOffset: 6,
2048
+ className: K(
2049
+ "w-auto rounded-card border border-border/60 p-0 shadow-sm",
2050
+ l
2051
+ ),
2052
+ style: p.contentStyle,
2053
+ children: i
2054
+ }
2055
+ )
2056
+ ] }),
2057
+ /* @__PURE__ */ r(Ue, { open: g, onOpenChange: h, children: [
2058
+ /* @__PURE__ */ e(Pe, { asChild: !0, children: /* @__PURE__ */ e(
2059
+ B,
2060
+ {
2061
+ variant: "ghost",
2062
+ size: "xs",
2063
+ className: K(
2064
+ "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",
2065
+ m
2066
+ ),
2067
+ "aria-label": "Filter and control actions",
2068
+ children: /* @__PURE__ */ e(Vt, { className: "h-3.5 w-3.5" })
2069
+ }
2070
+ ) }),
2071
+ /* @__PURE__ */ e(
2072
+ Me,
2073
+ {
2074
+ align: "end",
2075
+ sideOffset: 6,
2076
+ className: K(
2077
+ "w-auto rounded-card border border-border/60 p-0 shadow-sm",
2078
+ d
2079
+ ),
2080
+ style: p.contentStyle,
2081
+ children: s(() => h(!1))
2082
+ }
2083
+ )
2084
+ ] })
2085
+ ]
2086
+ }
2087
+ );
2088
+ }
2089
+ function qa() {
2090
+ ua();
2091
+ const t = M((l) => l.selectedSheetId), a = M((l) => l.selectedFrameId), i = M((l) => l.dashboard), s = M((l) => l.actions.getSelectedFrame), { setSelectedFrameId: n } = xe(), { setCard: c } = Tt(), u = be((l) => l.card.dataSource);
2092
+ return Z(() => {
2093
+ var d, o;
2094
+ let l = s();
2095
+ if (!l) {
2096
+ const g = (d = i == null ? void 0 : i.sheets) == null ? void 0 : d.find((p) => p.id === t), h = (o = g == null ? void 0 : g.frames) == null ? void 0 : o[0];
2097
+ h && (n(h.id), l = h);
2098
+ }
2099
+ if (l) {
2100
+ const g = l.cards.find((h) => h.id === l.activeCardId);
2101
+ g && c(g);
2102
+ }
2103
+ }, [s, t, a, i, n, c]), {
2104
+ hasEntities: !!(u != null && u.selectedEntities && u.selectedEntities.length > 0)
2105
+ };
2106
+ }
2107
+ function Ka() {
2108
+ const t = M((l) => l.dashboard), a = M(
2109
+ (l) => l.semanticExecutionPayload
2110
+ ), i = M((l) => l.actions.addFilter), { hasEntities: s } = qa(), { isLoading: n } = Sr(), c = J(
2111
+ () => Dr(t, a),
2112
+ [t, a]
2113
+ ), m = !kr(t.filters) && c.hasEligibleCards && !n;
2114
+ return /* @__PURE__ */ r("div", { className: "flex h-[520px] w-[400px] flex-col", children: [
2115
+ m && /* @__PURE__ */ e("div", { className: "border-b border-border/60 p-2", children: /* @__PURE__ */ r(
2116
+ "button",
2117
+ {
2118
+ type: "button",
2119
+ onClick: () => i(Er()),
2120
+ title: `Applies to ${c.eligibleCardCount} of ${c.totalCardCount} date-aware cards`,
2121
+ className: "flex w-full items-start gap-2 rounded-[4px] 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",
2122
+ children: [
2123
+ /* @__PURE__ */ e(Ar, { className: "mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground" }),
2124
+ /* @__PURE__ */ r("span", { className: "flex min-w-0 flex-col", children: [
2125
+ /* @__PURE__ */ e("span", { className: "text-[12px] font-medium text-foreground", children: "Add global date filter" }),
2126
+ /* @__PURE__ */ e("span", { className: "text-[11px] leading-[1.4] text-muted-foreground", children: "One date range across all date-aware cards." })
2127
+ ] })
2128
+ ]
2129
+ }
2130
+ ) }),
2131
+ !s && /* @__PURE__ */ r("div", { className: "flex flex-1 flex-col items-center justify-center px-6 py-8 text-center", children: [
2132
+ /* @__PURE__ */ e(Fr, { className: "mb-3 h-10 w-10 text-muted-foreground/50" }),
2133
+ /* @__PURE__ */ e("h3", { className: "mb-1 text-[13px] font-medium text-foreground", children: "No fields configured" }),
2134
+ /* @__PURE__ */ e("p", { className: "text-[11px] text-muted-foreground", children: "Configure a data source for this card to enable filtering." })
2135
+ ] }),
2136
+ s && /* @__PURE__ */ e("div", { className: "flex flex-1 overflow-hidden", children: /* @__PURE__ */ e(Ir, { context: "filter" }) })
2137
+ ] });
2138
+ }
2139
+ const yt = !1;
2140
+ function Xa({
2141
+ onAddFilter: t,
2142
+ onAddControl: a,
2143
+ onManageControls: i,
2144
+ onDismiss: s
2145
+ }) {
2146
+ const n = M(
2147
+ (m) => m.dashboard.filterLayout
2148
+ ), { setFilterLayout: c } = xe();
2149
+ n != null && n.displayMode;
2150
+ const u = (n == null ? void 0 : n.toolbarWrap) ?? !1;
2151
+ return n == null || n.showDownloadButton, /* @__PURE__ */ r("div", { className: "w-[300px]", children: [
2152
+ /* @__PURE__ */ r("div", { className: "p-1", children: [
2153
+ /* @__PURE__ */ e(
2154
+ Ke,
2155
+ {
2156
+ icon: Et,
2157
+ label: "Add filter",
2158
+ onClick: () => {
2159
+ t(), s();
2160
+ }
2161
+ }
2162
+ ),
2163
+ /* @__PURE__ */ e(
2164
+ Ke,
2165
+ {
2166
+ icon: ct,
2167
+ label: "Add control",
2168
+ onClick: () => {
2169
+ a(), s();
2170
+ }
2171
+ }
2172
+ ),
2173
+ /* @__PURE__ */ e(
2174
+ Ke,
2175
+ {
2176
+ icon: Ft,
2177
+ label: "Manage controls",
2178
+ onClick: () => {
2179
+ i(), s();
2180
+ }
2181
+ }
2182
+ )
2183
+ ] }),
2184
+ /* @__PURE__ */ e("div", { className: "border-t border-border/60" }),
2185
+ /* @__PURE__ */ r("div", { className: "space-y-1 p-2", children: [
2186
+ /* @__PURE__ */ e("p", { className: "px-1 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: "Display" }),
2187
+ yt,
2188
+ /* @__PURE__ */ e(
2189
+ Qa,
2190
+ {
2191
+ id: "filter-display-wrap",
2192
+ label: "Wrap to multiple lines",
2193
+ checked: u,
2194
+ onCheckedChange: (m) => c({ toolbarWrap: m === !0 })
2195
+ }
2196
+ ),
2197
+ yt
2198
+ ] })
2199
+ ] });
2200
+ }
2201
+ function Ke({
2202
+ icon: t,
2203
+ label: a,
2204
+ onClick: i
2205
+ }) {
2206
+ return /* @__PURE__ */ r(
2207
+ "button",
2208
+ {
2209
+ type: "button",
2210
+ onClick: i,
2211
+ className: "flex w-full items-center gap-2 rounded-[4px] px-2 py-1.5 text-left text-[13px] text-foreground transition-colors hover:bg-muted/40",
2212
+ children: [
2213
+ /* @__PURE__ */ e(t, { className: "h-3.5 w-3.5 text-muted-foreground" }),
2214
+ a
2215
+ ]
2216
+ }
2217
+ );
2218
+ }
2219
+ function Qa({
2220
+ id: t,
2221
+ label: a,
2222
+ checked: i,
2223
+ onCheckedChange: s
2224
+ }) {
2225
+ return /* @__PURE__ */ r("div", { className: "flex items-center gap-2 rounded-[4px] px-1 py-1 transition-colors hover:bg-muted/40", children: [
2226
+ /* @__PURE__ */ e(nt, { id: t, checked: i, onCheckedChange: s }),
2227
+ /* @__PURE__ */ e(
2228
+ Ne,
2229
+ {
2230
+ htmlFor: t,
2231
+ className: "cursor-pointer text-[12px] font-normal leading-[1.3]",
2232
+ children: a
2233
+ }
2234
+ )
2235
+ ] });
2236
+ }
2237
+ function zn({
2238
+ size: t,
2239
+ className: a,
2240
+ primaryButtonClassName: i,
2241
+ secondaryButtonClassName: s,
2242
+ pickerContentClassName: n,
2243
+ settingsContentClassName: c
2244
+ }) {
2245
+ var P;
2246
+ const [u, m] = A(null), l = M((f) => f.dashboard), d = M((f) => f.selectedSheetId), o = M((f) => f.showFilters), g = Lr((f) => f.setPanelOpen), h = M((f) => f.actions), { setDocumentInspectorTab: p, setShowFilters: y } = h, x = (P = l.sheets) == null ? void 0 : P.find(
2247
+ (f) => f.id === d
2248
+ ), D = sa(x), E = q((f) => {
2249
+ window.setTimeout(() => {
2250
+ m(f);
2251
+ }, 0);
2252
+ }, []), N = q(
2253
+ (f) => {
2254
+ if (D && d) {
2255
+ f && p(d, "inputs");
2256
+ return;
2257
+ }
2258
+ f && g("dashboard", !1), y(f);
2259
+ },
2260
+ [
2261
+ D,
2262
+ d,
2263
+ p,
2264
+ g,
2265
+ y
2266
+ ]
2267
+ ), b = q(() => {
2268
+ N(!0);
2269
+ }, [N]), S = q(() => {
2270
+ E("create");
2271
+ }, [E]), k = q(() => {
2272
+ E("manage");
2273
+ }, [E]);
2274
+ return /* @__PURE__ */ r(G, { children: [
2275
+ /* @__PURE__ */ e(
2276
+ Ga,
2277
+ {
2278
+ showFilters: D ? !1 : o,
2279
+ onShowFiltersChange: N,
2280
+ pickerContent: /* @__PURE__ */ e(Ka, {}),
2281
+ settingsContent: (f) => /* @__PURE__ */ e(
2282
+ Xa,
2283
+ {
2284
+ onAddFilter: b,
2285
+ onAddControl: S,
2286
+ onManageControls: k,
2287
+ onDismiss: f
2288
+ }
2289
+ ),
2290
+ size: t,
2291
+ className: a,
2292
+ primaryButtonClassName: i,
2293
+ secondaryButtonClassName: s,
2294
+ pickerContentClassName: n,
2295
+ settingsContentClassName: c
2296
+ }
2297
+ ),
2298
+ u ? D ? /* @__PURE__ */ e(
2299
+ _a,
2300
+ {
2301
+ open: !0,
2302
+ onOpenChange: (f) => {
2303
+ f || m(null);
2304
+ },
2305
+ initialMode: u
2306
+ }
2307
+ ) : /* @__PURE__ */ e(
2308
+ Oa,
2309
+ {
2310
+ open: !0,
2311
+ onOpenChange: (f) => {
2312
+ f || m(null);
2313
+ },
2314
+ showTrigger: !1,
2315
+ initialMode: u
2316
+ }
2317
+ ) : null
2318
+ ] });
2319
+ }
2320
+ function Ya({
2321
+ disabled: t,
2322
+ briefingCount: a,
2323
+ className: i,
2324
+ onClick: s
2325
+ }) {
2326
+ const n = typeof a == "number" && a > 0;
2327
+ return /* @__PURE__ */ r(
2328
+ B,
2329
+ {
2330
+ type: "button",
2331
+ size: "xs",
2332
+ variant: "outline",
2333
+ disabled: t,
2334
+ className: K("gap-1.5", i),
2335
+ onClick: s,
2336
+ "aria-label": "Reports & briefings",
2337
+ children: [
2338
+ /* @__PURE__ */ e(xa, { className: "h-3.5 w-3.5" }),
2339
+ "Reports & briefings",
2340
+ n ? /* @__PURE__ */ e("span", { className: "ml-0.5 rounded-control bg-muted px-1 text-[10px] tabular-nums text-foreground/70", children: a }) : null
2341
+ ]
2342
+ }
2343
+ );
2344
+ }
2345
+ const Za = "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", Ot = "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", Te = "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";
2346
+ function Ja(t) {
2347
+ return t === "dashboard" ? "This dashboard" : "Project";
2348
+ }
2349
+ function en(t) {
2350
+ if (!t) return "Never";
2351
+ const a = new Date(t);
2352
+ if (Number.isNaN(a.getTime())) return "Unknown";
2353
+ const i = Date.now() - a.getTime(), s = Math.round(i / 6e4);
2354
+ if (s < 1) return "now";
2355
+ if (s < 60) return `${s}m ago`;
2356
+ const n = Math.round(s / 60);
2357
+ if (n < 24) return `${n}h ago`;
2358
+ const c = Math.round(n / 24);
2359
+ if (c < 7) return `${c}d ago`;
2360
+ const u = Math.round(c / 7);
2361
+ return u < 5 ? `${u}w ago` : `${Math.round(c / 30)}mo ago`;
2362
+ }
2363
+ function tn(t) {
2364
+ return t.scheduleExpr ? ma(
2365
+ t.scheduleExpr,
2366
+ t.timezone || "UTC"
2367
+ ) ?? "Invalid schedule" : "On demand";
2368
+ }
2369
+ function rn(t) {
2370
+ if (t.lastRunStatus) {
2371
+ const a = t.lastRunStatus.toString().toUpperCase();
2372
+ return a === "SUCCESS" ? "Last run completed." : a === "FAILED" ? "Last run failed." : `Last run ${t.lastRunStatus.toString().toLowerCase()}`;
2373
+ }
2374
+ return null;
2375
+ }
2376
+ function zt(t) {
2377
+ return t.hasActiveRun ? "Running" : t.lastRunStatus ? `Last run ${t.lastRunStatus.toString().toLowerCase()}` : "Idle";
2378
+ }
2379
+ function an(t) {
2380
+ return t.source.type === "dashboard" ? "This dashboard" : "Project";
2381
+ }
2382
+ function nn({
2383
+ activeView: t,
2384
+ onChange: a
2385
+ }) {
2386
+ return /* @__PURE__ */ e(
2387
+ "div",
2388
+ {
2389
+ className: "flex shrink-0 items-center gap-1 rounded-control bg-muted p-0.5",
2390
+ role: "tablist",
2391
+ "aria-label": "Briefing source view",
2392
+ children: ["dashboard", "project"].map((i) => {
2393
+ const s = t === i;
2394
+ return /* @__PURE__ */ e(
2395
+ "button",
2396
+ {
2397
+ type: "button",
2398
+ role: "tab",
2399
+ "aria-selected": s,
2400
+ onClick: () => a(i),
2401
+ className: K(
2402
+ "h-6 rounded-[3px] px-2 text-[11px] transition-colors",
2403
+ s ? "bg-background font-medium text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"
2404
+ ),
2405
+ children: Ja(i)
2406
+ },
2407
+ i
2408
+ );
2409
+ })
2410
+ }
2411
+ );
2412
+ }
2413
+ function sn({
2414
+ briefings: t,
2415
+ dashboardLabel: a,
2416
+ sourceView: i,
2417
+ error: s,
2418
+ loading: n,
2419
+ onSourceViewChange: c,
2420
+ onClose: u,
2421
+ onEdit: m,
2422
+ onNew: l,
2423
+ canCreate: d,
2424
+ canCreateScheduledReport: o,
2425
+ analyticalBriefingsEnabled: g,
2426
+ onRunNow: h,
2427
+ onTogglePause: p,
2428
+ onDelete: y,
2429
+ selectingId: x,
2430
+ busyId: D,
2431
+ manageBriefingsHref: E,
2432
+ contentKind: N,
2433
+ hideHeader: b = !1
2434
+ }) {
2435
+ const S = t.length, k = t.filter((F) => F.status === "ACTIVE").length, P = N === "reports" ? S === 1 ? "report" : "reports" : N === "briefings" ? S === 1 ? "briefing" : "briefings" : S === 1 ? "item" : "items", f = t.find((F) => F.hasActiveRun) ?? null, C = N ?? "reports & briefings", T = i === "dashboard" ? a : `Project ${C}`;
2436
+ return /* @__PURE__ */ r(
2437
+ "section",
2438
+ {
2439
+ "aria-label": `Dashboard ${C.replace("&", "and")}`,
2440
+ className: "flex h-full min-h-0 flex-col bg-background text-foreground",
2441
+ children: [
2442
+ b ? null : /* @__PURE__ */ r("header", { className: "flex items-start justify-between gap-3 border-b border-border px-4 py-3", children: [
2443
+ /* @__PURE__ */ r("div", { className: "min-w-0", children: [
2444
+ /* @__PURE__ */ e("div", { className: Za, children: C }),
2445
+ /* @__PURE__ */ e("h2", { className: "mt-0.5 truncate text-[14px] font-semibold leading-5", children: T })
2446
+ ] }),
2447
+ /* @__PURE__ */ e(
2448
+ "button",
2449
+ {
2450
+ type: "button",
2451
+ onClick: u,
2452
+ className: "rounded-control p-1 text-muted-foreground hover:bg-muted hover:text-foreground",
2453
+ "aria-label": `Close ${C.replace("&", "and")} panel`,
2454
+ children: /* @__PURE__ */ e(je, { className: "h-3.5 w-3.5" })
2455
+ }
2456
+ )
2457
+ ] }),
2458
+ /* @__PURE__ */ r("div", { className: "flex items-center justify-between gap-3 border-b border-border px-4 py-2", children: [
2459
+ /* @__PURE__ */ r("div", { className: "flex min-w-0 items-center gap-3", children: [
2460
+ /* @__PURE__ */ e(
2461
+ nn,
2462
+ {
2463
+ activeView: i,
2464
+ onChange: c
2465
+ }
2466
+ ),
2467
+ /* @__PURE__ */ e("div", { className: "flex min-w-0 items-center gap-1.5 text-[11px] text-muted-foreground", children: n && S === 0 ? /* @__PURE__ */ r("span", { children: [
2468
+ "Loading ",
2469
+ C,
2470
+ "…"
2471
+ ] }) : S === 0 ? /* @__PURE__ */ r("span", { children: [
2472
+ "No ",
2473
+ C,
2474
+ " yet"
2475
+ ] }) : /* @__PURE__ */ r(G, { children: [
2476
+ /* @__PURE__ */ r("span", { className: "font-medium text-foreground/80", children: [
2477
+ S,
2478
+ " ",
2479
+ P
2480
+ ] }),
2481
+ /* @__PURE__ */ e("span", { className: "text-border", children: "·" }),
2482
+ /* @__PURE__ */ r("span", { children: [
2483
+ k,
2484
+ " active"
2485
+ ] })
2486
+ ] }) })
2487
+ ] }),
2488
+ /* @__PURE__ */ r("div", { className: "flex items-center gap-1.5", children: [
2489
+ n ? (
2490
+ // Auto-refresh on open; surface a quiet spinner near the count
2491
+ // when a manual reload is in flight, but don't show a separate
2492
+ // refresh button — close+reopen handles the rare "stale list"
2493
+ // case without crowding the toolbar.
2494
+ /* @__PURE__ */ e(ee, { className: "h-3.5 w-3.5 animate-spin text-muted-foreground" })
2495
+ ) : null,
2496
+ S > 0 && d ? g && o ? /* @__PURE__ */ r(Oe, { children: [
2497
+ /* @__PURE__ */ e(ze, { asChild: !0, children: /* @__PURE__ */ r("button", { className: Te, children: [
2498
+ /* @__PURE__ */ e(ge, { className: "h-3 w-3" }),
2499
+ " New"
2500
+ ] }) }),
2501
+ /* @__PURE__ */ r(_e, { align: "end", children: [
2502
+ /* @__PURE__ */ e(H, { onClick: () => l("scheduled_report"), children: "Schedule a report" }),
2503
+ /* @__PURE__ */ e(
2504
+ H,
2505
+ {
2506
+ onClick: () => l("analytical_briefing"),
2507
+ children: "Create analytical briefing"
2508
+ }
2509
+ )
2510
+ ] })
2511
+ ] }) : o ? /* @__PURE__ */ r(
2512
+ "button",
2513
+ {
2514
+ onClick: () => l("scheduled_report"),
2515
+ className: Te,
2516
+ children: [
2517
+ /* @__PURE__ */ e(ge, { className: "h-3 w-3" }),
2518
+ " Schedule report"
2519
+ ]
2520
+ }
2521
+ ) : g ? /* @__PURE__ */ r(
2522
+ "button",
2523
+ {
2524
+ onClick: () => l("analytical_briefing"),
2525
+ className: Te,
2526
+ children: [
2527
+ /* @__PURE__ */ e(ge, { className: "h-3 w-3" }),
2528
+ " New briefing"
2529
+ ]
2530
+ }
2531
+ ) : null : null
2532
+ ] })
2533
+ ] }),
2534
+ f ? /* @__PURE__ */ r("div", { className: "flex items-center gap-2 border-b border-border bg-muted/60 px-4 py-2 text-[12px]", children: [
2535
+ /* @__PURE__ */ e(ee, { className: "h-3 w-3 shrink-0 animate-spin text-muted-foreground" }),
2536
+ /* @__PURE__ */ e("span", { className: "font-medium text-foreground", children: f.name }),
2537
+ /* @__PURE__ */ e("span", { className: "text-border", children: "·" }),
2538
+ /* @__PURE__ */ e("span", { className: "truncate text-muted-foreground", children: zt(f) })
2539
+ ] }) : null,
2540
+ /* @__PURE__ */ r("div", { className: "flex-1 overflow-y-auto", children: [
2541
+ s ? /* @__PURE__ */ e("div", { className: "m-4 rounded-card border border-destructive/30 bg-destructive/10 px-3 py-2 text-[12px] text-destructive", children: s }) : null,
2542
+ !n && t.length === 0 && !s ? /* @__PURE__ */ e(
2543
+ on,
2544
+ {
2545
+ onNew: l,
2546
+ canCreate: d,
2547
+ canCreateScheduledReport: o,
2548
+ analyticalBriefingsEnabled: g,
2549
+ contentKind: N
2550
+ }
2551
+ ) : null,
2552
+ t.map((F) => /* @__PURE__ */ e(
2553
+ cn,
2554
+ {
2555
+ briefing: F,
2556
+ isOpening: x === F.id,
2557
+ isBusy: D === F.id,
2558
+ onOpen: () => m(F.id),
2559
+ onRunNow: () => h(F),
2560
+ onTogglePause: () => p(F),
2561
+ onDelete: () => y(F)
2562
+ },
2563
+ F.id
2564
+ ))
2565
+ ] }),
2566
+ E ? /* @__PURE__ */ e("div", { className: "border-t border-border px-4 py-2.5", children: /* @__PURE__ */ r(
2567
+ "a",
2568
+ {
2569
+ href: E,
2570
+ className: K(Ot, "h-6 px-1 text-[11px]"),
2571
+ children: [
2572
+ "Manage all reports & briefings",
2573
+ /* @__PURE__ */ e(fa, { className: "h-3 w-3" })
2574
+ ]
2575
+ }
2576
+ ) }) : null
2577
+ ]
2578
+ }
2579
+ );
2580
+ }
2581
+ function on({
2582
+ onNew: t,
2583
+ canCreate: a,
2584
+ canCreateScheduledReport: i,
2585
+ analyticalBriefingsEnabled: s,
2586
+ contentKind: n
2587
+ }) {
2588
+ const c = n === "reports" ? {
2589
+ title: "No reports yet",
2590
+ description: "Schedule an emailed dashboard or visual report to see it here."
2591
+ } : n === "briefings" ? {
2592
+ title: "No briefings yet",
2593
+ description: "Create an analytical briefing to monitor this dashboard and brief your team."
2594
+ } : null;
2595
+ return /* @__PURE__ */ r("div", { className: "flex h-full flex-col items-center justify-center px-8 py-12 text-center", children: [
2596
+ /* @__PURE__ */ e(ln, { className: "mb-5 h-[88px] w-[112px] text-border" }),
2597
+ /* @__PURE__ */ e("div", { className: "text-[13px] font-medium text-foreground", children: (c == null ? void 0 : c.title) ?? "Have an analyst brief your team" }),
2598
+ /* @__PURE__ */ e("p", { className: "mt-1.5 max-w-[320px] text-[12px] leading-5 text-muted-foreground", children: (c == null ? void 0 : c.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." }),
2599
+ a ? /* @__PURE__ */ r("div", { className: "mt-4 flex flex-wrap justify-center gap-2", children: [
2600
+ i ? /* @__PURE__ */ r(
2601
+ "button",
2602
+ {
2603
+ onClick: () => t("scheduled_report"),
2604
+ className: Te,
2605
+ children: [
2606
+ /* @__PURE__ */ e(ge, { className: "h-3 w-3" }),
2607
+ " Schedule a report"
2608
+ ]
2609
+ }
2610
+ ) : null,
2611
+ s ? /* @__PURE__ */ e(
2612
+ "button",
2613
+ {
2614
+ onClick: () => t("analytical_briefing"),
2615
+ className: Ot,
2616
+ children: "Create analytical briefing"
2617
+ }
2618
+ ) : null
2619
+ ] }) : null
2620
+ ] });
2621
+ }
2622
+ function ln({ className: t }) {
2623
+ return /* @__PURE__ */ r(
2624
+ "svg",
2625
+ {
2626
+ viewBox: "0 0 112 88",
2627
+ fill: "none",
2628
+ xmlns: "http://www.w3.org/2000/svg",
2629
+ role: "presentation",
2630
+ "aria-hidden": "true",
2631
+ className: t,
2632
+ children: [
2633
+ /* @__PURE__ */ e(
2634
+ "rect",
2635
+ {
2636
+ x: "22",
2637
+ y: "6",
2638
+ width: "60",
2639
+ height: "72",
2640
+ rx: "3",
2641
+ stroke: "currentColor",
2642
+ strokeWidth: "1.25"
2643
+ }
2644
+ ),
2645
+ /* @__PURE__ */ e(
2646
+ "line",
2647
+ {
2648
+ x1: "30",
2649
+ y1: "16",
2650
+ x2: "64",
2651
+ y2: "16",
2652
+ stroke: "currentColor",
2653
+ strokeWidth: "1.5",
2654
+ strokeLinecap: "round"
2655
+ }
2656
+ ),
2657
+ /* @__PURE__ */ e(
2658
+ "line",
2659
+ {
2660
+ x1: "30",
2661
+ y1: "21",
2662
+ x2: "52",
2663
+ y2: "21",
2664
+ stroke: "currentColor",
2665
+ strokeWidth: "1",
2666
+ strokeLinecap: "round",
2667
+ opacity: "0.5"
2668
+ }
2669
+ ),
2670
+ /* @__PURE__ */ e("circle", { cx: "31", cy: "32", r: "1", fill: "currentColor", opacity: "0.6" }),
2671
+ /* @__PURE__ */ e(
2672
+ "line",
2673
+ {
2674
+ x1: "35",
2675
+ y1: "32",
2676
+ x2: "72",
2677
+ y2: "32",
2678
+ stroke: "currentColor",
2679
+ strokeWidth: "1",
2680
+ opacity: "0.4",
2681
+ strokeLinecap: "round"
2682
+ }
2683
+ ),
2684
+ /* @__PURE__ */ e("circle", { cx: "31", cy: "38", r: "1", fill: "currentColor", opacity: "0.6" }),
2685
+ /* @__PURE__ */ e(
2686
+ "line",
2687
+ {
2688
+ x1: "35",
2689
+ y1: "38",
2690
+ x2: "68",
2691
+ y2: "38",
2692
+ stroke: "currentColor",
2693
+ strokeWidth: "1",
2694
+ opacity: "0.4",
2695
+ strokeLinecap: "round"
2696
+ }
2697
+ ),
2698
+ /* @__PURE__ */ e("circle", { cx: "31", cy: "44", r: "1", fill: "currentColor", opacity: "0.6" }),
2699
+ /* @__PURE__ */ e(
2700
+ "line",
2701
+ {
2702
+ x1: "35",
2703
+ y1: "44",
2704
+ x2: "74",
2705
+ y2: "44",
2706
+ stroke: "currentColor",
2707
+ strokeWidth: "1",
2708
+ opacity: "0.4",
2709
+ strokeLinecap: "round"
2710
+ }
2711
+ ),
2712
+ /* @__PURE__ */ e(
2713
+ "rect",
2714
+ {
2715
+ x: "30",
2716
+ y: "64",
2717
+ width: "5",
2718
+ height: "8",
2719
+ rx: "0.5",
2720
+ fill: "currentColor",
2721
+ opacity: "0.55"
2722
+ }
2723
+ ),
2724
+ /* @__PURE__ */ e(
2725
+ "rect",
2726
+ {
2727
+ x: "38",
2728
+ y: "60",
2729
+ width: "5",
2730
+ height: "12",
2731
+ rx: "0.5",
2732
+ fill: "currentColor",
2733
+ opacity: "0.7"
2734
+ }
2735
+ ),
2736
+ /* @__PURE__ */ e(
2737
+ "rect",
2738
+ {
2739
+ x: "46",
2740
+ y: "56",
2741
+ width: "5",
2742
+ height: "16",
2743
+ rx: "0.5",
2744
+ fill: "currentColor",
2745
+ opacity: "0.85"
2746
+ }
2747
+ ),
2748
+ /* @__PURE__ */ e(
2749
+ "rect",
2750
+ {
2751
+ x: "54",
2752
+ y: "62",
2753
+ width: "5",
2754
+ height: "10",
2755
+ rx: "0.5",
2756
+ fill: "currentColor",
2757
+ opacity: "0.6"
2758
+ }
2759
+ ),
2760
+ /* @__PURE__ */ e(
2761
+ "rect",
2762
+ {
2763
+ x: "62",
2764
+ y: "58",
2765
+ width: "5",
2766
+ height: "14",
2767
+ rx: "0.5",
2768
+ fill: "currentColor",
2769
+ opacity: "0.75"
2770
+ }
2771
+ ),
2772
+ /* @__PURE__ */ e(
2773
+ "circle",
2774
+ {
2775
+ cx: "86",
2776
+ cy: "62",
2777
+ r: "10",
2778
+ fill: "var(--background, white)",
2779
+ stroke: "currentColor",
2780
+ strokeWidth: "1.25"
2781
+ }
2782
+ ),
2783
+ /* @__PURE__ */ e(
2784
+ "line",
2785
+ {
2786
+ x1: "93.5",
2787
+ y1: "69.5",
2788
+ x2: "100",
2789
+ y2: "76",
2790
+ stroke: "currentColor",
2791
+ strokeWidth: "1.5",
2792
+ strokeLinecap: "round"
2793
+ }
2794
+ )
2795
+ ]
2796
+ }
2797
+ );
2798
+ }
2799
+ function cn({
2800
+ briefing: t,
2801
+ isOpening: a,
2802
+ isBusy: i,
2803
+ onOpen: s,
2804
+ onRunNow: n,
2805
+ onTogglePause: c,
2806
+ onDelete: u
2807
+ }) {
2808
+ const m = t.status === "PAUSED", l = t.hasActiveRun, d = rn(t), o = en(t.lastRunAt), g = t.lastRunStatus, h = oe(t), p = g === "SUCCESS" ? Be.success.dot : g === "FAILED" ? Be.danger.dot : g ? Be.warning.dot : Be.neutral.dot;
2809
+ return /* @__PURE__ */ r(
2810
+ "div",
2811
+ {
2812
+ className: K(
2813
+ "group relative border-b border-border/60 px-4 py-3 transition-colors hover:bg-muted/60",
2814
+ m && "opacity-70"
2815
+ ),
2816
+ children: [
2817
+ /* @__PURE__ */ r(
2818
+ "div",
2819
+ {
2820
+ role: "button",
2821
+ tabIndex: 0,
2822
+ onClick: s,
2823
+ onKeyDown: (y) => {
2824
+ (y.key === "Enter" || y.key === " ") && (y.preventDefault(), s());
2825
+ },
2826
+ className: "cursor-pointer pr-8",
2827
+ children: [
2828
+ /* @__PURE__ */ r("div", { className: "flex min-w-0 items-center gap-2", children: [
2829
+ /* @__PURE__ */ e("span", { className: "truncate text-[13px] font-medium text-foreground", children: t.name }),
2830
+ m ? /* @__PURE__ */ e("span", { className: "shrink-0 text-[11px] text-muted-foreground", children: "· Paused" }) : null
2831
+ ] }),
2832
+ /* @__PURE__ */ r("div", { className: "mt-1 flex flex-wrap items-center gap-x-1.5 text-[11px] text-muted-foreground", children: [
2833
+ /* @__PURE__ */ e("span", { children: h.typeLabel }),
2834
+ /* @__PURE__ */ e("span", { className: "text-border", children: "·" }),
2835
+ /* @__PURE__ */ e("span", { children: an(t) }),
2836
+ /* @__PURE__ */ e("span", { className: "text-border", children: "·" }),
2837
+ /* @__PURE__ */ e(Br, { className: "h-3 w-3" }),
2838
+ /* @__PURE__ */ e("span", { className: "truncate", children: tn(t) }),
2839
+ t.lastRunAt ? /* @__PURE__ */ r(G, { children: [
2840
+ /* @__PURE__ */ e("span", { className: "text-border", children: "·" }),
2841
+ /* @__PURE__ */ r("span", { children: [
2842
+ "Last run ",
2843
+ o
2844
+ ] })
2845
+ ] }) : null
2846
+ ] }),
2847
+ d || l ? /* @__PURE__ */ r("div", { className: "mt-1.5 flex items-center gap-1.5 text-[12px] leading-[1.5] text-foreground/80", children: [
2848
+ l ? /* @__PURE__ */ e(ee, { className: "h-3 w-3 shrink-0 animate-spin text-muted-foreground/70" }) : /* @__PURE__ */ e(
2849
+ "span",
2850
+ {
2851
+ className: K(
2852
+ "inline-block h-1.5 w-1.5 shrink-0 rounded-full",
2853
+ p
2854
+ )
2855
+ }
2856
+ ),
2857
+ /* @__PURE__ */ e("span", { className: "truncate", children: l ? zt(t) : d })
2858
+ ] }) : null
2859
+ ]
2860
+ }
2861
+ ),
2862
+ /* @__PURE__ */ e("div", { className: "absolute right-3 top-3", children: i ? /* @__PURE__ */ e(ee, { className: "h-3.5 w-3.5 animate-spin text-muted-foreground/70" }) : a ? /* @__PURE__ */ e(ee, { className: "h-3.5 w-3.5 animate-spin text-muted-foreground/70" }) : /* @__PURE__ */ r(Oe, { children: [
2863
+ /* @__PURE__ */ e(ze, { asChild: !0, children: /* @__PURE__ */ e(
2864
+ "button",
2865
+ {
2866
+ type: "button",
2867
+ onClick: (y) => y.stopPropagation(),
2868
+ 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",
2869
+ "aria-label": `${h.noun === "report" ? "Report" : "Briefing"} actions`,
2870
+ children: /* @__PURE__ */ e(St, { className: "h-3.5 w-3.5" })
2871
+ }
2872
+ ) }),
2873
+ /* @__PURE__ */ r(_e, { align: "end", className: "w-44", children: [
2874
+ /* @__PURE__ */ r(H, { onClick: s, children: [
2875
+ /* @__PURE__ */ e(Ft, { className: "h-3.5 w-3.5" }),
2876
+ "Edit ",
2877
+ h.noun
2878
+ ] }),
2879
+ /* @__PURE__ */ r(
2880
+ H,
2881
+ {
2882
+ onClick: (y) => {
2883
+ y.preventDefault(), n();
2884
+ },
2885
+ children: [
2886
+ /* @__PURE__ */ e(Tr, { className: "h-3.5 w-3.5" }),
2887
+ "Run now"
2888
+ ]
2889
+ }
2890
+ ),
2891
+ t.scheduleExpr ? /* @__PURE__ */ e(
2892
+ H,
2893
+ {
2894
+ onClick: (y) => {
2895
+ y.preventDefault(), c();
2896
+ },
2897
+ children: m ? /* @__PURE__ */ r(G, { children: [
2898
+ /* @__PURE__ */ e(Vr, { className: "h-3.5 w-3.5" }),
2899
+ "Resume"
2900
+ ] }) : /* @__PURE__ */ r(G, { children: [
2901
+ /* @__PURE__ */ e(Rr, { className: "h-3.5 w-3.5" }),
2902
+ "Pause"
2903
+ ] })
2904
+ }
2905
+ ) : null,
2906
+ /* @__PURE__ */ e(Re, {}),
2907
+ /* @__PURE__ */ r(
2908
+ H,
2909
+ {
2910
+ onClick: (y) => {
2911
+ y.preventDefault(), u();
2912
+ },
2913
+ className: "text-destructive focus:bg-destructive/10 focus:text-destructive",
2914
+ children: [
2915
+ /* @__PURE__ */ e(Ve, { className: "h-3.5 w-3.5" }),
2916
+ "Delete ",
2917
+ h.noun
2918
+ ]
2919
+ }
2920
+ )
2921
+ ] })
2922
+ ] }) })
2923
+ ]
2924
+ }
2925
+ );
2926
+ }
2927
+ const dn = 2e3, un = 20 * 6e4;
2928
+ function hn(t) {
2929
+ return (t == null ? void 0 : t.trim()) || "This dashboard";
2930
+ }
2931
+ function mn(t) {
2932
+ return t === "This dashboard" ? "Watch this dashboard" : `Watch ${t}`;
2933
+ }
2934
+ function pn(t, a, i) {
2935
+ return a !== "dashboard" ? t : t.filter(
2936
+ (s) => s.source.type === "dashboard" && s.source.dashboardId === i
2937
+ );
2938
+ }
2939
+ async function fn(t) {
2940
+ const i = [];
2941
+ let s = 1, n = 0, c = Number.POSITIVE_INFINITY;
2942
+ for (; n < c; ) {
2943
+ const u = await t.apiClient.listBriefings(
2944
+ t.apiServiceUrl,
2945
+ t.token,
2946
+ { scope: "organization", page: s, pageSize: 100 }
2947
+ );
2948
+ if (i.push(...u.briefings), n += u.briefings.length, c = u.total, u.briefings.length === 0 || n >= c) break;
2949
+ s += 1;
2950
+ }
2951
+ return i;
2952
+ }
2953
+ const gn = {
2954
+ listBriefings: jr,
2955
+ getBriefing: $r,
2956
+ pauseBriefing: _r,
2957
+ resumeBriefing: zr,
2958
+ deleteBriefing: Or,
2959
+ runBriefingNow: Mr
2960
+ };
2961
+ function bn({
2962
+ briefingId: t,
2963
+ initialRun: a,
2964
+ apiServiceUrl: i,
2965
+ token: s,
2966
+ onTerminal: n,
2967
+ onTimeout: c,
2968
+ onExpand: u
2969
+ }) {
2970
+ const [m, l] = A(a), { startRun: d } = Yr({
2971
+ apiServiceUrl: i,
2972
+ token: s,
2973
+ intervalMs: dn,
2974
+ timeoutMs: un,
2975
+ fetchRun: ({
2976
+ apiServiceUrl: g,
2977
+ token: h,
2978
+ runId: p
2979
+ }) => Zr(g, h, t, p),
2980
+ onRun: (g) => {
2981
+ l(g);
2982
+ },
2983
+ onTerminalRun: (g) => {
2984
+ n(g);
2985
+ },
2986
+ onTimeout: () => {
2987
+ c();
2988
+ }
2989
+ }), o = me(!1);
2990
+ return Z(() => {
2991
+ o.current || (o.current = !0, Jr(a.status) ? d(a) : ea(a.status) && n(a));
2992
+ }, [a, n, d]), /* @__PURE__ */ e(ta, { run: m, onExpand: u });
2993
+ }
2994
+ function _n(t) {
2995
+ return /* @__PURE__ */ e(Ur, { children: /* @__PURE__ */ e(xn, { ...t }) });
2996
+ }
2997
+ function xn({
2998
+ dashboardId: t,
2999
+ dashboardTitle: a,
3000
+ apiServiceUrl: i,
3001
+ token: s,
3002
+ disabled: n,
3003
+ className: c,
3004
+ manageBriefingsHref: u,
3005
+ open: m,
3006
+ onOpenChange: l,
3007
+ hideTrigger: d = !1,
3008
+ workflowIntent: o,
3009
+ client: g
3010
+ }) {
3011
+ const { authToken: h, tokenProps: p } = $e(), y = Pr(), x = !o || y.canCreate && (o === "scheduled_report" || y.analyticalBriefingsEnabled), [D, E] = A(!1), N = m ?? D, b = (w) => {
3012
+ m === void 0 && E(w), l == null || l(w);
3013
+ }, [S, k] = A(
3014
+ o ? "author" : "list"
3015
+ ), [P, f] = A(
3016
+ o ?? "analytical_briefing"
3017
+ ), [C, T] = A("dashboard"), [F, I] = A(
3018
+ []
3019
+ ), [R, V] = A(null), W = o && !x && !R ? "list" : S, [ae, ne] = A(!1), [We, ve] = A(null), [He, Q] = A(null), [_, te] = A(
3020
+ null
3021
+ ), [le, ce] = A(null), ye = me(null), Ee = me(N);
3022
+ Z(() => {
3023
+ const w = N && !Ee.current;
3024
+ Ee.current = N, !(!w || !o) && (V(null), T("dashboard"), f(o), k("author"), ce(null));
3025
+ }, [N, o]);
3026
+ const [de, pe] = A(
3027
+ null
3028
+ ), [Y, Ce] = A(null), $ = i ?? (p == null ? void 0 : p.apiServiceUrl), j = s ?? (h == null ? void 0 : h.accessToken), se = J(() => ({ ...gn, ...g }), [g]), fe = hn(a), Fe = J(() => {
3029
+ const w = pn(
3030
+ F,
3031
+ C,
3032
+ t
3033
+ );
3034
+ if (!o)
3035
+ return w;
3036
+ const U = o === "scheduled_report" ? "report" : "briefing";
3037
+ return w.filter(
3038
+ (Ie) => oe(Ie).noun === U
3039
+ );
3040
+ }, [t, F, C, o]), Ge = J(() => C === "dashboard" ? {
3041
+ source: { type: "dashboard", dashboardId: t },
3042
+ label: fe,
3043
+ detail: mn(fe)
3044
+ } : {
3045
+ source: { type: "project" },
3046
+ label: "This project",
3047
+ detail: "Use any data in this project."
3048
+ }, [t, fe, C]), we = !!($ && j), ue = pa({
3049
+ canCreate: y.canCreate,
3050
+ analyticalBriefingsEnabled: y.analyticalBriefingsEnabled,
3051
+ scheduledReportAvailable: C === "dashboard"
3052
+ }), X = q(async () => {
3053
+ if (!(!$ || !j)) {
3054
+ ne(!0), ce(null);
3055
+ try {
3056
+ I(
3057
+ await fn({
3058
+ apiClient: se,
3059
+ apiServiceUrl: $,
3060
+ token: j
3061
+ })
3062
+ );
3063
+ } catch (w) {
3064
+ ce(
3065
+ w instanceof Error ? w.message : "Could not load briefings."
3066
+ );
3067
+ } finally {
3068
+ ne(!1);
3069
+ }
3070
+ }
3071
+ }, [se, $, j]);
3072
+ Z(() => {
3073
+ !N || W !== "list" || !we || X();
3074
+ }, [we, W, X, N]);
3075
+ const v = () => {
3076
+ V(null), T("dashboard"), k("list"), b(!0);
3077
+ }, L = (w) => {
3078
+ V(null), f(w), k("author");
3079
+ }, O = async (w) => {
3080
+ if (!(!$ || !j)) {
3081
+ ve(w), ce(null);
3082
+ try {
3083
+ const U = await se.getBriefing(
3084
+ $,
3085
+ j,
3086
+ w
3087
+ );
3088
+ V(U.briefing), k("author");
3089
+ } catch (U) {
3090
+ ce(
3091
+ U instanceof Error ? U.message : "Could not open briefing."
3092
+ );
3093
+ } finally {
3094
+ ve(null);
3095
+ }
3096
+ }
3097
+ }, re = async (w) => {
3098
+ if (!(!$ || !j)) {
3099
+ Q(w.id);
3100
+ try {
3101
+ await se.runBriefingNow(
3102
+ $,
3103
+ j,
3104
+ w.id,
3105
+ { requestId: vn() }
3106
+ ), X();
3107
+ } catch (U) {
3108
+ z.error(
3109
+ U instanceof Error ? U.message : "Could not start the run."
3110
+ );
3111
+ } finally {
3112
+ Q(null);
3113
+ }
3114
+ }
3115
+ }, ie = async (w) => {
3116
+ if (!$ || !j) return;
3117
+ const { noun: U } = oe(w), Ie = U === "report" ? "Report" : "Briefing";
3118
+ Q(w.id);
3119
+ try {
3120
+ const Le = w.status === "PAUSED" ? await se.resumeBriefing(
3121
+ $,
3122
+ j,
3123
+ w.id
3124
+ ) : await se.pauseBriefing(
3125
+ $,
3126
+ j,
3127
+ w.id
3128
+ );
3129
+ z.success(
3130
+ Le.briefing.status === "PAUSED" ? `${Ie} paused` : `${Ie} resumed`
3131
+ ), X();
3132
+ } catch (Le) {
3133
+ z.error(
3134
+ Le instanceof Error ? Le.message : `Could not update the ${U} status.`
3135
+ );
3136
+ } finally {
3137
+ Q(null);
3138
+ }
3139
+ }, _t = async () => {
3140
+ if (!_ || !$ || !j) return;
3141
+ const w = _;
3142
+ Q(w.id);
3143
+ try {
3144
+ await se.deleteBriefing(
3145
+ $,
3146
+ j,
3147
+ w.id
3148
+ );
3149
+ const { noun: U } = oe(w);
3150
+ z.success(`${U === "report" ? "Report" : "Briefing"} deleted`), te(null), X();
3151
+ } catch (U) {
3152
+ z.error(
3153
+ U instanceof Error ? U.message : "Could not delete the briefing."
3154
+ );
3155
+ } finally {
3156
+ Q(null);
3157
+ }
3158
+ }, $t = Fe.length;
3159
+ return y.surfaceVisible ? /* @__PURE__ */ r(Wr, { open: N, onOpenChange: b, children: [
3160
+ d ? null : /* @__PURE__ */ e(
3161
+ Ya,
3162
+ {
3163
+ disabled: n || !we,
3164
+ briefingCount: $t,
3165
+ className: c,
3166
+ onClick: v
3167
+ }
3168
+ ),
3169
+ /* @__PURE__ */ r(
3170
+ Hr,
3171
+ {
3172
+ ref: ye,
3173
+ side: "right",
3174
+ hideClose: !0,
3175
+ className: "flex h-full w-full flex-col overflow-hidden p-0 outline-none sm:max-w-[560px]",
3176
+ onOpenAutoFocus: (w) => {
3177
+ var U;
3178
+ w.preventDefault(), (U = ye.current) == null || U.focus({ preventScroll: !0 });
3179
+ },
3180
+ children: [
3181
+ /* @__PURE__ */ r(Gr, { className: "sr-only", children: [
3182
+ /* @__PURE__ */ e(qr, { children: "Reports & briefings" }),
3183
+ /* @__PURE__ */ e(Kr, { children: "Manage reports and briefings for this dashboard." })
3184
+ ] }),
3185
+ o ? /* @__PURE__ */ r("div", { className: "flex shrink-0 items-start justify-between gap-3 border-b border-border pl-4 pr-3 pt-2", children: [
3186
+ /* @__PURE__ */ r(
3187
+ "div",
3188
+ {
3189
+ className: "flex items-center gap-5",
3190
+ role: "tablist",
3191
+ "aria-label": o === "scheduled_report" ? "Email report workflow" : "Analytical briefing workflow",
3192
+ children: [
3193
+ /* @__PURE__ */ e(
3194
+ "button",
3195
+ {
3196
+ type: "button",
3197
+ role: "tab",
3198
+ "aria-selected": W === "author",
3199
+ disabled: !x,
3200
+ className: K(
3201
+ "-mb-px border-b-2 px-0.5 pb-2 text-[12px] transition-colors",
3202
+ W === "author" ? "border-foreground font-medium text-foreground" : "border-transparent text-muted-foreground hover:text-foreground",
3203
+ !x && "cursor-not-allowed opacity-50"
3204
+ ),
3205
+ onClick: () => {
3206
+ x && (V(null), f(o), T("dashboard"), k("author"));
3207
+ },
3208
+ children: R ? `Edit ${oe(R).noun}` : o === "scheduled_report" ? "Schedule report" : "Create briefing"
3209
+ }
3210
+ ),
3211
+ /* @__PURE__ */ e(
3212
+ "button",
3213
+ {
3214
+ type: "button",
3215
+ role: "tab",
3216
+ "aria-selected": W === "list",
3217
+ className: K(
3218
+ "-mb-px border-b-2 px-0.5 pb-2 text-[12px] transition-colors",
3219
+ W === "list" ? "border-foreground font-medium text-foreground" : "border-transparent text-muted-foreground hover:text-foreground"
3220
+ ),
3221
+ onClick: () => k("list"),
3222
+ children: o === "scheduled_report" ? "Manage reports" : "Manage briefings"
3223
+ }
3224
+ )
3225
+ ]
3226
+ }
3227
+ ),
3228
+ /* @__PURE__ */ e(
3229
+ "button",
3230
+ {
3231
+ type: "button",
3232
+ onClick: () => b(!1),
3233
+ className: "rounded-control p-1 text-muted-foreground hover:bg-muted hover:text-foreground",
3234
+ "aria-label": o === "scheduled_report" ? "Close email report workflow" : "Close analytical briefing workflow",
3235
+ children: /* @__PURE__ */ e(je, { className: "h-3.5 w-3.5" })
3236
+ }
3237
+ )
3238
+ ] }) : null,
3239
+ W === "list" ? /* @__PURE__ */ e(
3240
+ sn,
3241
+ {
3242
+ briefings: Fe,
3243
+ dashboardLabel: fe,
3244
+ sourceView: C,
3245
+ error: le,
3246
+ loading: ae,
3247
+ onSourceViewChange: T,
3248
+ onClose: () => b(!1),
3249
+ onEdit: (w) => {
3250
+ O(w);
3251
+ },
3252
+ onNew: L,
3253
+ canCreate: !o && ue.length > 0,
3254
+ canCreateScheduledReport: ue.includes(
3255
+ "scheduled_report"
3256
+ ),
3257
+ analyticalBriefingsEnabled: ue.includes(
3258
+ "analytical_briefing"
3259
+ ),
3260
+ onRunNow: (w) => {
3261
+ re(w);
3262
+ },
3263
+ onTogglePause: (w) => {
3264
+ ie(w);
3265
+ },
3266
+ onDelete: (w) => te(w),
3267
+ selectingId: We,
3268
+ busyId: He,
3269
+ manageBriefingsHref: u,
3270
+ contentKind: o === "scheduled_report" ? "reports" : o === "analytical_briefing" ? "briefings" : void 0,
3271
+ hideHeader: !!o
3272
+ }
3273
+ ) : /* @__PURE__ */ e(
3274
+ Xr,
3275
+ {
3276
+ apiServiceUrl: $,
3277
+ token: j,
3278
+ briefing: R,
3279
+ intent: P,
3280
+ sourceContext: R ? void 0 : Ge,
3281
+ title: R ? `Edit ${oe(R).noun}` : P === "scheduled_report" ? "Schedule report" : "Create analytical briefing",
3282
+ hideHeader: !!o,
3283
+ className: "h-full min-h-0 max-w-none border-0 shadow-none",
3284
+ onBack: o ? void 0 : () => k("list"),
3285
+ onCancel: () => b(!1),
3286
+ onDeleted: () => {
3287
+ const w = R ? oe(R).noun : "briefing";
3288
+ z.success(`${w === "report" ? "Report" : "Briefing"} deleted`), V(null), k("list"), X();
3289
+ },
3290
+ onRunStarted: () => {
3291
+ },
3292
+ onSaved: (w) => {
3293
+ V(w), X();
3294
+ },
3295
+ onMinimizeRun: ({ briefing: w, run: U }) => {
3296
+ pe({ briefing: w, run: U }), b(!1);
3297
+ }
3298
+ }
3299
+ )
3300
+ ]
3301
+ }
3302
+ ),
3303
+ de && $ && j ? /* @__PURE__ */ e(
3304
+ bn,
3305
+ {
3306
+ briefingId: de.briefing.id,
3307
+ initialRun: de.run,
3308
+ apiServiceUrl: $,
3309
+ token: j,
3310
+ onTerminal: (w) => {
3311
+ Ce({
3312
+ briefing: de.briefing,
3313
+ run: w
3314
+ }), pe(null), X();
3315
+ },
3316
+ onTimeout: () => {
3317
+ pe(null), X();
3318
+ },
3319
+ onExpand: () => {
3320
+ V(de.briefing), k("author"), pe(null), b(!0);
3321
+ }
3322
+ }
3323
+ ) : null,
3324
+ Y ? /* @__PURE__ */ e("div", { className: "fixed bottom-4 right-4 z-50 w-[360px]", children: /* @__PURE__ */ e(
3325
+ Qr,
3326
+ {
3327
+ title: Y.run.status === "SUCCESS" ? `${Y.briefing.name} is ready` : `${Y.briefing.name} run failed`,
3328
+ durationSeconds: Y.run.startedAt && Y.run.completedAt ? Math.max(
3329
+ 0,
3330
+ Math.floor(
3331
+ (new Date(Y.run.completedAt).getTime() - new Date(Y.run.startedAt).getTime()) / 1e3
3332
+ )
3333
+ ) : null,
3334
+ status: Y.run.status === "SUCCESS" ? "success" : "failed",
3335
+ onView: () => {
3336
+ V(Y.briefing), k("author"), Ce(null), b(!0);
3337
+ },
3338
+ onDismiss: () => Ce(null)
3339
+ }
3340
+ ) }) : null,
3341
+ /* @__PURE__ */ e(
3342
+ Ye,
3343
+ {
3344
+ open: !!_,
3345
+ onOpenChange: (w) => {
3346
+ w || te(null);
3347
+ },
3348
+ children: /* @__PURE__ */ r(Ze, { children: [
3349
+ /* @__PURE__ */ r(Je, { children: [
3350
+ /* @__PURE__ */ r(et, { children: [
3351
+ "Delete",
3352
+ " ",
3353
+ _ ? oe(_).noun : "briefing",
3354
+ "?"
3355
+ ] }),
3356
+ /* @__PURE__ */ r(tt, { children: [
3357
+ "This permanently deletes ",
3358
+ /* @__PURE__ */ e("strong", { children: _ == null ? void 0 : _.name }),
3359
+ ". Recipients will stop receiving it."
3360
+ ] })
3361
+ ] }),
3362
+ /* @__PURE__ */ r(rt, { children: [
3363
+ /* @__PURE__ */ e(at, { children: "Cancel" }),
3364
+ /* @__PURE__ */ r(
3365
+ Nt,
3366
+ {
3367
+ className: "bg-destructive/90 hover:bg-destructive",
3368
+ onClick: _t,
3369
+ children: [
3370
+ "Delete",
3371
+ " ",
3372
+ _ ? oe(_).noun : "briefing"
3373
+ ]
3374
+ }
3375
+ )
3376
+ ] })
3377
+ ] })
3378
+ }
3379
+ )
3380
+ ] }) : null;
3381
+ }
3382
+ function vn() {
3383
+ return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `briefing-run-now-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
3384
+ }
3385
+ export {
3386
+ Rn as A,
3387
+ Oa as D,
3388
+ Pa as E,
3389
+ On as N,
3390
+ Un as U,
3391
+ Tn as V,
3392
+ Ya as W,
3393
+ Vn as a,
3394
+ Ua as b,
3395
+ Mn as c,
3396
+ _a as d,
3397
+ Ga as e,
3398
+ zn as f,
3399
+ _n as g,
3400
+ Pn as u
3401
+ };