react-semaphor 0.1.59 → 0.1.61

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 (53) hide show
  1. package/dist/chunks/axis-mapping-8ZVwlkl6.js +315 -0
  2. package/dist/chunks/axis-mapping-Cwa3KrDR.js +16 -0
  3. package/dist/chunks/bar-chart-settings-B_WyC-7g.js +52 -0
  4. package/dist/chunks/bar-chart-settings-CvorW7RD.js +1 -0
  5. package/dist/chunks/bubble-chart-settings-BPtESqYK.js +1 -0
  6. package/dist/chunks/bubble-chart-settings-CxFAlErV.js +50 -0
  7. package/dist/chunks/common-chart-settings-CvRrQf-H.js +1 -0
  8. package/dist/chunks/common-chart-settings-D3ww0Xtx.js +147 -0
  9. package/dist/chunks/custom-visual-settings-DXWyN2Dr.js +11 -0
  10. package/dist/chunks/custom-visual-settings-m5o8R5tL.js +243 -0
  11. package/dist/chunks/dashboard-plus-B8-ocT_Z.js +41 -0
  12. package/dist/chunks/dashboard-plus-DSUKhvcv.js +2941 -0
  13. package/dist/chunks/display-labels-BYsRReye.js +1 -0
  14. package/dist/chunks/display-labels-C_jsL0Jo.js +74 -0
  15. package/dist/chunks/editor-C7xQi9Ab.js +105 -0
  16. package/dist/chunks/editor-DqvyBUrl.js +8321 -0
  17. package/dist/chunks/filter-on-click-columns-6dRYhvgz.js +1 -0
  18. package/dist/chunks/filter-on-click-columns-BJUGTE6W.js +120 -0
  19. package/dist/chunks/frame-filters-D9sDN4Vm.js +1 -0
  20. package/dist/chunks/frame-filters-DFgqSoV2.js +75 -0
  21. package/dist/chunks/{index-D4y2uVa5.js → index--MUeDITx.js} +28329 -25746
  22. package/dist/chunks/index-Bvtpj-_R.js +1080 -0
  23. package/dist/chunks/kpi-settings-BONvmfNr.js +1 -0
  24. package/dist/chunks/kpi-settings-CI-9fp4Z.js +286 -0
  25. package/dist/chunks/map-chart-settings-CSxZdu_g.js +1 -0
  26. package/dist/chunks/map-chart-settings-DQIN7Pn8.js +334 -0
  27. package/dist/chunks/pie-chart-settings-CN3JCLdP.js +86 -0
  28. package/dist/chunks/pie-chart-settings-CsErfZOL.js +1 -0
  29. package/dist/chunks/reusable-select-CQbD03nT.js +40 -0
  30. package/dist/chunks/reusable-select-CVRzPWkg.js +1 -0
  31. package/dist/chunks/stacked-chart-settings-BfqHFFqA.js +1 -0
  32. package/dist/chunks/stacked-chart-settings-poYotO6Q.js +90 -0
  33. package/dist/chunks/table-visual-settings-B46pdUra.js +46 -0
  34. package/dist/chunks/table-visual-settings-ZKWuNokZ.js +1 -0
  35. package/dist/chunks/tag-BrxBSbSe.js +20 -0
  36. package/dist/chunks/tag-D9G2kz2B.js +6 -0
  37. package/dist/chunks/use-assign-filter-5gplfsO1.js +83 -0
  38. package/dist/chunks/use-assign-filter-DzmBSsyO.js +1 -0
  39. package/dist/chunks/use-local-storage-state-CBh2HHB9.js +16 -0
  40. package/dist/chunks/use-local-storage-state-CL0JsTZM.js +1745 -0
  41. package/dist/chunks/use-plugin-query-DA6Yrp7P.js +12 -0
  42. package/dist/chunks/use-plugin-query-JdHNPYZS.js +1 -0
  43. package/dist/dashboard/index.cjs +1 -1
  44. package/dist/dashboard/index.js +1 -1
  45. package/dist/index.cjs +1 -1
  46. package/dist/index.js +103 -103
  47. package/dist/style.css +1 -1
  48. package/dist/surfboard/index.cjs +1 -1
  49. package/dist/surfboard/index.js +1 -1
  50. package/package.json +1 -1
  51. package/dist/chunks/dashboard-plus-B-lXkbRY.js +0 -225
  52. package/dist/chunks/dashboard-plus-CHqCwJFO.js +0 -17362
  53. package/dist/chunks/index-CLxl35mK.js +0 -1045
@@ -0,0 +1,2941 @@
1
+ import { jsxs as s, jsx as e, Fragment as R } from "react/jsx-runtime";
2
+ import { E as he, bG as _s, e as N, bH as ye, bI as we, B as I, bJ as De, bK as Q, bL as ns, G as Re, Q as re, bM as Ee, bN as Bs, _ as le, bO as ke, bP as Fe, bQ as Le, bR as Ge, L as X, I as Ce, bS as Qe, ag as de, bT as qs, bU as Ze, bV as Qs, bW as ys, bX as Ms, q as G, bY as rs, bZ as Hs, b_ as $s, b$ as Ks, c0 as Ws, c1 as Js, aZ as A, aq as ws, c2 as Xs, c3 as Zs, c4 as ae, u as ne, aV as He, c5 as $e, c6 as Es, c7 as ks, c8 as Ys, a$ as Z, c9 as te, ca as ea, cb as sa, a4 as is, a5 as ls, a6 as Se, cc as Pe, by as Ye, bx as Ie, cd as es, ce as je, cf as ss, C as Be, cg as Fs, ch as Ls, ci as Ae, cj as aa, bl as os, bm as cs, bn as ds, bo as hs, bp as us, bq as ms, br as ps, bs as fs, ck as ta, bz as ze, aW as na, aX as Ke, cl as ra, M as Ds, a1 as ia, bc as Cs, d as As, cm as la, cn as oa, co as ca, cp as Ts, cq as gs, cr as da, cs as ha, ct as ua, ai as Ue, cu as ma, cv as pa, cw as fa, cx as ga, ap as ba, cy as va, cz as Na, r as xa, cA as ya, am as bs, bw as wa, cB as Da, cC as Ca, cD as Sa, cE as Pa, F as Ia, cF as Ma, cG as Ea, cH as ka, bi as Os, bk as Vs, cI as Ss, cJ as Fa, cK as La, cL as Aa, cM as Ta, cN as Us, cO as Oa, cP as zs, cQ as Rs, cR as Va, cS as Ua, cT as za, cU as Ra, cV as Ga, bB as ja, cW as _a, cX as Ba, aO as qa, aP as Qa, aQ as Ha, aR as $a, b9 as Ka, a7 as Wa, a8 as Ja, a9 as Xa, cY as Za, aa as Ya, cZ as et, c_ as st, c$ as at, d0 as Ps, d1 as tt, ac as nt, d2 as rt } from "./index--MUeDITx.js";
3
+ import Gs, { useState as x, useMemo as _e, useContext as it, useEffect as Me, useRef as Is } from "react";
4
+ import "react-dom";
5
+ import { u as vs, E as lt, V as ot, a as ct, b as dt, S as qe, c as ht, d as ut, F as mt, e as pt, f as ft } from "./use-local-storage-state-CL0JsTZM.js";
6
+ /**
7
+ * @license lucide-react v0.453.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */
12
+ const gt = he("CirclePlus", [
13
+ ["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }],
14
+ ["path", { d: "M8 12h8", key: "1wcyev" }],
15
+ ["path", { d: "M12 8v8", key: "napkw2" }]
16
+ ]);
17
+ /**
18
+ * @license lucide-react v0.453.0 - ISC
19
+ *
20
+ * This source code is licensed under the ISC license.
21
+ * See the LICENSE file in the root directory of this source tree.
22
+ */
23
+ const bt = he("FolderOpen", [
24
+ [
25
+ "path",
26
+ {
27
+ d: "m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",
28
+ key: "usdka0"
29
+ }
30
+ ]
31
+ ]);
32
+ /**
33
+ * @license lucide-react v0.453.0 - ISC
34
+ *
35
+ * This source code is licensed under the ISC license.
36
+ * See the LICENSE file in the root directory of this source tree.
37
+ */
38
+ const vt = he("Glasses", [
39
+ ["circle", { cx: "6", cy: "15", r: "4", key: "vux9w4" }],
40
+ ["circle", { cx: "18", cy: "15", r: "4", key: "18o8ve" }],
41
+ ["path", { d: "M14 15a2 2 0 0 0-2-2 2 2 0 0 0-2 2", key: "1ag4bs" }],
42
+ ["path", { d: "M2.5 13 5 7c.7-1.3 1.4-2 3-2", key: "1hm1gs" }],
43
+ ["path", { d: "M21.5 13 19 7c-.7-1.3-1.5-2-3-2", key: "1r31ai" }]
44
+ ]);
45
+ /**
46
+ * @license lucide-react v0.453.0 - ISC
47
+ *
48
+ * This source code is licensed under the ISC license.
49
+ * See the LICENSE file in the root directory of this source tree.
50
+ */
51
+ const Nt = he("Menu", [
52
+ ["line", { x1: "4", x2: "20", y1: "12", y2: "12", key: "1e0a9i" }],
53
+ ["line", { x1: "4", x2: "20", y1: "6", y2: "6", key: "1owob3" }],
54
+ ["line", { x1: "4", x2: "20", y1: "18", y2: "18", key: "yk5zj1" }]
55
+ ]);
56
+ /**
57
+ * @license lucide-react v0.453.0 - ISC
58
+ *
59
+ * This source code is licensed under the ISC license.
60
+ * See the LICENSE file in the root directory of this source tree.
61
+ */
62
+ const xt = he("Moon", [
63
+ ["path", { d: "M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z", key: "a7tn18" }]
64
+ ]);
65
+ /**
66
+ * @license lucide-react v0.453.0 - ISC
67
+ *
68
+ * This source code is licensed under the ISC license.
69
+ * See the LICENSE file in the root directory of this source tree.
70
+ */
71
+ const yt = he("PanelLeft", [
72
+ ["rect", { width: "18", height: "18", x: "3", y: "3", rx: "2", key: "afitv7" }],
73
+ ["path", { d: "M9 3v18", key: "fh3hqa" }]
74
+ ]);
75
+ /**
76
+ * @license lucide-react v0.453.0 - ISC
77
+ *
78
+ * This source code is licensed under the ISC license.
79
+ * See the LICENSE file in the root directory of this source tree.
80
+ */
81
+ const wt = he("ShieldX", [
82
+ [
83
+ "path",
84
+ {
85
+ d: "M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",
86
+ key: "oel41y"
87
+ }
88
+ ],
89
+ ["path", { d: "m14.5 9.5-5 5", key: "17q4r4" }],
90
+ ["path", { d: "m9.5 9.5 5 5", key: "18nt4w" }]
91
+ ]);
92
+ /**
93
+ * @license lucide-react v0.453.0 - ISC
94
+ *
95
+ * This source code is licensed under the ISC license.
96
+ * See the LICENSE file in the root directory of this source tree.
97
+ */
98
+ const Dt = he("Sun", [
99
+ ["circle", { cx: "12", cy: "12", r: "4", key: "4exip2" }],
100
+ ["path", { d: "M12 2v2", key: "tus03m" }],
101
+ ["path", { d: "M12 20v2", key: "1lh1kg" }],
102
+ ["path", { d: "m4.93 4.93 1.41 1.41", key: "149t6j" }],
103
+ ["path", { d: "m17.66 17.66 1.41 1.41", key: "ptbguv" }],
104
+ ["path", { d: "M2 12h2", key: "1t8f8n" }],
105
+ ["path", { d: "M20 12h2", key: "1q8mjw" }],
106
+ ["path", { d: "m6.34 17.66-1.41 1.41", key: "1m8zz5" }],
107
+ ["path", { d: "m19.07 4.93-1.41 1.41", key: "1shlcs" }]
108
+ ]);
109
+ function Ct() {
110
+ const { setTheme: a } = _s(), i = N(
111
+ (n) => n.actions.setDashboardTheme
112
+ );
113
+ return /* @__PURE__ */ s(ye, { children: [
114
+ /* @__PURE__ */ e(we, { asChild: !0, children: /* @__PURE__ */ s(I, { className: "h-7 p-2", variant: "ghost", size: "sm", children: [
115
+ /* @__PURE__ */ e(
116
+ Dt,
117
+ {
118
+ strokeWidth: 1.5,
119
+ className: "h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0"
120
+ }
121
+ ),
122
+ /* @__PURE__ */ e(
123
+ xt,
124
+ {
125
+ strokeWidth: 1.5,
126
+ className: "absolute h-4 w-4 rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100"
127
+ }
128
+ ),
129
+ /* @__PURE__ */ e("span", { className: "sr-only", children: "Toggle theme" })
130
+ ] }) }),
131
+ /* @__PURE__ */ s(De, { align: "end", children: [
132
+ /* @__PURE__ */ e(
133
+ Q,
134
+ {
135
+ onClick: () => {
136
+ a("light"), i("light");
137
+ },
138
+ children: "Light"
139
+ }
140
+ ),
141
+ /* @__PURE__ */ e(
142
+ Q,
143
+ {
144
+ onClick: () => {
145
+ a("dark"), i("dark");
146
+ },
147
+ children: "Dark"
148
+ }
149
+ ),
150
+ /* @__PURE__ */ e(
151
+ Q,
152
+ {
153
+ onClick: () => {
154
+ a("system"), i("system");
155
+ },
156
+ children: "System"
157
+ }
158
+ )
159
+ ] })
160
+ ] });
161
+ }
162
+ function as(a) {
163
+ var i;
164
+ return {
165
+ ...a,
166
+ sheets: (i = a == null ? void 0 : a.sheets) == null ? void 0 : i.map((n) => {
167
+ var t;
168
+ return {
169
+ ...n,
170
+ frames: (t = n.frames) == null ? void 0 : t.map((r) => {
171
+ var c;
172
+ return {
173
+ ...r,
174
+ cards: (c = r.cards) == null ? void 0 : c.map((o) => St(o))
175
+ };
176
+ })
177
+ };
178
+ })
179
+ };
180
+ }
181
+ function St(a) {
182
+ return {
183
+ ...a,
184
+ // cfg: {
185
+ // ...card.cfg,
186
+ // data: {
187
+ // ...card.cfg?.data,
188
+ // labels: [],
189
+ // datasets: card.cfg?.data?.datasets?.map((dataset: any) => {
190
+ // return {
191
+ // ...dataset,
192
+ // data: [],
193
+ // };
194
+ // }),
195
+ // },
196
+ // },
197
+ customCfg: Pt(a.customCfg),
198
+ // if customCfg is present, clean it, otherwise return null{
199
+ data: []
200
+ };
201
+ }
202
+ function Pt(a) {
203
+ var i, n;
204
+ return a ? {
205
+ ...a,
206
+ data: {
207
+ ...a == null ? void 0 : a.data,
208
+ labels: [],
209
+ datasets: (n = (i = a == null ? void 0 : a.data) == null ? void 0 : i.datasets) == null ? void 0 : n.map((t) => ({
210
+ ...t,
211
+ data: []
212
+ }))
213
+ }
214
+ } : null;
215
+ }
216
+ async function It(a, i, n, t, r) {
217
+ if (!r)
218
+ return null;
219
+ const c = JSON.stringify(n), o = `${a}/v1/lens`;
220
+ return await ns(o, r, {
221
+ name: i,
222
+ template: c,
223
+ filterValues: t,
224
+ operation: "create"
225
+ });
226
+ }
227
+ async function ts(a, i, n) {
228
+ if (!n)
229
+ return null;
230
+ const { id: t, template: r, filterValues: c, isDefault: o, shared: m } = i, d = `${a}/v1/lens`;
231
+ return await ns(d, n, {
232
+ lensId: t,
233
+ template: r,
234
+ filterValues: c,
235
+ isDefault: o,
236
+ shared: m,
237
+ operation: "update"
238
+ });
239
+ }
240
+ async function Mt(a, i, n) {
241
+ if (!n)
242
+ return null;
243
+ const t = `${a}/v1/lens`;
244
+ return await ns(t, n, {
245
+ operation: "delete",
246
+ lensId: i
247
+ });
248
+ }
249
+ function Et() {
250
+ const [a, i] = x(""), [n, t] = x(!1), r = N((P) => P.lenses), { setLenses: c, setSelectedLensId: o } = Re(), [m, d] = x(!1), [f, p] = x(!1), l = N((P) => P.dashboard), u = N((P) => P.filterValues), { authToken: y, tokenProps: v } = re();
251
+ async function S() {
252
+ d(!0);
253
+ const P = as(
254
+ l
255
+ ), L = await It(
256
+ v.apiServiceUrl,
257
+ a,
258
+ P,
259
+ u,
260
+ y == null ? void 0 : y.accessToken
261
+ );
262
+ L && (c([...r || [], L]), o(L.id), p(!1)), d(!1);
263
+ }
264
+ return /* @__PURE__ */ s(Ee, { open: f, onOpenChange: p, children: [
265
+ /* @__PURE__ */ e(Bs, { asChild: !0, children: /* @__PURE__ */ s(
266
+ I,
267
+ {
268
+ variant: "secondary",
269
+ className: "h-7 p-2",
270
+ size: "sm",
271
+ children: [
272
+ /* @__PURE__ */ e(le, { className: "mr-2 h-4 w-4" }),
273
+ "Lens"
274
+ ]
275
+ }
276
+ ) }),
277
+ /* @__PURE__ */ s(ke, { className: "sm:max-w-[425px]", children: [
278
+ /* @__PURE__ */ s(Fe, { children: [
279
+ /* @__PURE__ */ e(Le, { children: "Create Lens" }),
280
+ /* @__PURE__ */ e(Ge, { children: "Lenses are private by default and are only visible to you." })
281
+ ] }),
282
+ /* @__PURE__ */ e("div", { className: "grid gap-4 py-4", children: /* @__PURE__ */ s("div", { className: "grid grid-cols-8 items-center gap-4", children: [
283
+ /* @__PURE__ */ e(X, { className: "text-right", children: "Name" }),
284
+ /* @__PURE__ */ e(
285
+ Ce,
286
+ {
287
+ value: a,
288
+ onChange: (P) => {
289
+ i(P.target.value);
290
+ },
291
+ id: "name",
292
+ className: "col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"
293
+ }
294
+ )
295
+ ] }) }),
296
+ n && /* @__PURE__ */ e("p", { className: "text-sm", children: "The lens name already exists. Use a differnet name." }),
297
+ /* @__PURE__ */ e(Qe, { children: /* @__PURE__ */ e(
298
+ I,
299
+ {
300
+ size: "sm",
301
+ variant: "outline",
302
+ type: "submit",
303
+ onClick: S,
304
+ disabled: m,
305
+ children: m ? "Creating..." : "Add"
306
+ }
307
+ ) })
308
+ ] })
309
+ ] });
310
+ }
311
+ function kt() {
312
+ const [a, i] = x(!1), n = N((l) => l.lenses), t = N((l) => l.selectedLensId), { setLenses: r, setSelectedLensId: c } = Re(), { authToken: o, tokenProps: m } = re();
313
+ async function d(l) {
314
+ c(l);
315
+ }
316
+ async function f(l) {
317
+ if (await Mt(m.apiServiceUrl, l, o == null ? void 0 : o.accessToken)) {
318
+ const y = n == null ? void 0 : n.filter((v) => v.id !== l);
319
+ r(y || []), c("original");
320
+ }
321
+ }
322
+ async function p(l) {
323
+ const u = n == null ? void 0 : n.map((S) => S.id === l.id ? {
324
+ ...S,
325
+ isDefault: !l.isDefault
326
+ } : {
327
+ ...S,
328
+ isDefault: !1
329
+ });
330
+ r(u || []);
331
+ const y = {
332
+ ...l,
333
+ isDefault: !l.isDefault
334
+ };
335
+ await ts(m.apiServiceUrl, y, o == null ? void 0 : o.accessToken);
336
+ const v = n == null ? void 0 : n.find((S) => S.isDefault);
337
+ if (v && v.id !== l.id) {
338
+ const S = {
339
+ ...v,
340
+ isDefault: !1
341
+ };
342
+ await ts(m.apiServiceUrl, S, o == null ? void 0 : o.accessToken);
343
+ }
344
+ }
345
+ return /* @__PURE__ */ s(ye, { open: a, onOpenChange: i, children: [
346
+ /* @__PURE__ */ e(we, { asChild: !0, children: /* @__PURE__ */ e(de, { tooltip: "Lenses", className: "h-7 p-2", children: /* @__PURE__ */ e(vt, { className: "h-4 w-4" }) }) }),
347
+ /* @__PURE__ */ s(De, { align: "end", className: "w-60", children: [
348
+ /* @__PURE__ */ e(qs, { className: "px-3", children: "Lenses" }),
349
+ /* @__PURE__ */ e(Ze, {}),
350
+ /* @__PURE__ */ s(
351
+ Qs,
352
+ {
353
+ value: t,
354
+ onValueChange: d,
355
+ children: [
356
+ /* @__PURE__ */ e(ys, { value: "original", children: "Original" }),
357
+ n == null ? void 0 : n.map((l) => /* @__PURE__ */ s(
358
+ ys,
359
+ {
360
+ className: "group flex justify-between gap-2",
361
+ value: l.id,
362
+ children: [
363
+ /* @__PURE__ */ e("p", { children: l.name }),
364
+ /* @__PURE__ */ s("span", { className: "flex items-center gap-3", children: [
365
+ /* @__PURE__ */ e(
366
+ Ms,
367
+ {
368
+ onClick: (u) => {
369
+ u.preventDefault(), p(l);
370
+ },
371
+ className: G(
372
+ "size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",
373
+ {
374
+ invisible: !l.isDefault,
375
+ "text-green-500": l.isDefault
376
+ }
377
+ ),
378
+ strokeWidth: 1.5
379
+ }
380
+ ),
381
+ /* @__PURE__ */ e(
382
+ rs,
383
+ {
384
+ onClick: (u) => {
385
+ u.preventDefault(), f(l.id);
386
+ },
387
+ className: "invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",
388
+ strokeWidth: 1.5
389
+ }
390
+ )
391
+ ] })
392
+ ]
393
+ },
394
+ l.id
395
+ ))
396
+ ]
397
+ }
398
+ )
399
+ ] })
400
+ ] });
401
+ }
402
+ function Ft({
403
+ iconClassName: a
404
+ }) {
405
+ const [i, n] = x(!1), [t, r] = x(""), [c, o] = x(!1), m = N((l) => l.isDownloadingPdf), { tokenProps: d } = re();
406
+ async function f() {
407
+ const l = A.loading(
408
+ "Generating PDF... may take up to 60 seconds"
409
+ );
410
+ try {
411
+ await ws(d.apiServiceUrl), A.dismiss(l), A.success("PDF downloaded successfully!", {
412
+ duration: 2e3
413
+ });
414
+ } catch (u) {
415
+ A.dismiss(l), A.error("Failed to download PDF", {
416
+ description: "Please try again or contact support.",
417
+ richColors: !0
418
+ }), console.error("PDF download error:", u);
419
+ }
420
+ }
421
+ async function p() {
422
+ if (!t) return;
423
+ n(!1), r(""), o(!1);
424
+ const l = A.loading(
425
+ "Generating protected PDF... may take up to 60 seconds"
426
+ );
427
+ try {
428
+ await ws(d.apiServiceUrl, t), A.dismiss(l), A.success("Protected PDF downloaded successfully!", {
429
+ duration: 2e3,
430
+ position: "top-right"
431
+ });
432
+ } catch (u) {
433
+ A.dismiss(l), A.error("Failed to download protected PDF. Please try again."), console.error("Protected PDF download error:", u);
434
+ }
435
+ }
436
+ return /* @__PURE__ */ s(R, { children: [
437
+ /* @__PURE__ */ s(ye, { modal: !1, children: [
438
+ /* @__PURE__ */ e(we, { asChild: !0, children: /* @__PURE__ */ e(
439
+ I,
440
+ {
441
+ variant: "ghost",
442
+ size: "sm",
443
+ className: "h-7 p-2",
444
+ disabled: m,
445
+ children: /* @__PURE__ */ e(Hs, { className: G("size-4", a) })
446
+ }
447
+ ) }),
448
+ /* @__PURE__ */ s(De, { align: "end", children: [
449
+ /* @__PURE__ */ s(Q, { onClick: f, children: [
450
+ /* @__PURE__ */ e($s, { className: "mr-2 h-4 w-4" }),
451
+ "Download PDF"
452
+ ] }),
453
+ /* @__PURE__ */ s(Q, { onClick: () => n(!0), children: [
454
+ /* @__PURE__ */ e(Ks, { className: "mr-2 h-4 w-4" }),
455
+ "Download Protected PDF"
456
+ ] })
457
+ ] })
458
+ ] }),
459
+ /* @__PURE__ */ e(
460
+ Ee,
461
+ {
462
+ open: i,
463
+ onOpenChange: n,
464
+ children: /* @__PURE__ */ s(ke, { className: "sm:max-w-[425px]", children: [
465
+ /* @__PURE__ */ s(Fe, { children: [
466
+ /* @__PURE__ */ e(Le, { children: "Download Protected PDF" }),
467
+ /* @__PURE__ */ e(Ge, { children: "Enter a password to protect your PDF. The PDF will be encrypted and require this password to open." })
468
+ ] }),
469
+ /* @__PURE__ */ e("div", { className: "grid gap-4 py-4", children: /* @__PURE__ */ s("div", { className: "grid gap-2", children: [
470
+ /* @__PURE__ */ e(X, { htmlFor: "password", children: "Password" }),
471
+ /* @__PURE__ */ s("div", { className: "relative", children: [
472
+ /* @__PURE__ */ e(
473
+ Ce,
474
+ {
475
+ id: "password",
476
+ type: c ? "text" : "password",
477
+ value: t,
478
+ onChange: (l) => r(l.target.value),
479
+ placeholder: "Enter password",
480
+ className: "pr-10",
481
+ onKeyDown: (l) => {
482
+ l.key === "Enter" && t && p();
483
+ }
484
+ }
485
+ ),
486
+ /* @__PURE__ */ e(
487
+ I,
488
+ {
489
+ type: "button",
490
+ variant: "ghost",
491
+ size: "sm",
492
+ className: "absolute right-0 top-0 h-full px-3 py-2 hover:bg-transparent",
493
+ onClick: () => o(!c),
494
+ children: c ? /* @__PURE__ */ e(Ws, { className: "h-4 w-4 text-muted-foreground" }) : /* @__PURE__ */ e(Js, { className: "h-4 w-4 text-muted-foreground" })
495
+ }
496
+ )
497
+ ] })
498
+ ] }) }),
499
+ /* @__PURE__ */ s(Qe, { children: [
500
+ /* @__PURE__ */ e(
501
+ I,
502
+ {
503
+ variant: "outline",
504
+ onClick: () => n(!1),
505
+ children: "Cancel"
506
+ }
507
+ ),
508
+ /* @__PURE__ */ e(I, { onClick: p, disabled: !t, children: "Download" })
509
+ ] })
510
+ ] })
511
+ }
512
+ )
513
+ ] });
514
+ }
515
+ function Lt({
516
+ triggerButtonClassName: a
517
+ }) {
518
+ const [i, n] = x(!1), t = N((m) => {
519
+ var d;
520
+ return (d = m.dashboard) == null ? void 0 : d.id;
521
+ }), r = N((m) => {
522
+ var d;
523
+ return (d = m.dashboard) == null ? void 0 : d.title;
524
+ }), c = N((m) => {
525
+ var d;
526
+ return (d = m.dashboard) == null ? void 0 : d.sheets;
527
+ }), o = N((m) => m.selectedSheetId);
528
+ return c == null || c.find((m) => m.id === o), t ? /* @__PURE__ */ s(R, { children: [
529
+ /* @__PURE__ */ e(
530
+ de,
531
+ {
532
+ tooltip: "Schedule Dashboard",
533
+ className: G("h-7 p-2", a),
534
+ onClick: () => n(!0),
535
+ children: /* @__PURE__ */ e(Xs, { className: "size-4" })
536
+ }
537
+ ),
538
+ /* @__PURE__ */ e(
539
+ Zs,
540
+ {
541
+ open: i,
542
+ onOpenChange: n,
543
+ dashboardId: t,
544
+ dashboardName: r
545
+ }
546
+ )
547
+ ] }) : null;
548
+ }
549
+ function At({
550
+ type: a,
551
+ isLinked: i,
552
+ className: n
553
+ }) {
554
+ const t = N((f) => f.selectedFrameId), r = ae((f) => f.selectedVisual), c = ne((f) => f.frame);
555
+ let o;
556
+ if (a)
557
+ o = a;
558
+ else if (i !== void 0)
559
+ o = i ? "linked" : "library";
560
+ else if (!!!(c != null && c.visualId || r != null && r.id) && t)
561
+ o = "local";
562
+ else if (r && !t)
563
+ o = "library";
564
+ else if (c != null && c.visualId && t)
565
+ o = "linked";
566
+ else if (r != null && r.id && t)
567
+ o = "library";
568
+ else
569
+ return null;
570
+ const m = {
571
+ local: "bg-gray-100 text-gray-700",
572
+ linked: "bg-purple-100 text-purple-700",
573
+ library: "bg-blue-100 text-blue-700"
574
+ }, d = {
575
+ local: "Local Visual",
576
+ linked: "Linked Visual",
577
+ library: "Library Visual"
578
+ };
579
+ return /* @__PURE__ */ e(
580
+ "span",
581
+ {
582
+ className: G(
583
+ "rounded-full px-2.5 py-0.5 text-xs font-medium",
584
+ m[o],
585
+ n
586
+ ),
587
+ children: d[o]
588
+ }
589
+ );
590
+ }
591
+ const Tt = async (a, i, n) => {
592
+ const t = `${a}/management/v1/groups`;
593
+ return await Es(t, i, n);
594
+ }, Ot = async (a, i, n) => {
595
+ const t = `${a}/management/v1/groups/${n}`, r = await fetch(t, {
596
+ method: "DELETE",
597
+ headers: {
598
+ Authorization: `Bearer ${i}`
599
+ }
600
+ });
601
+ if (!r.ok) {
602
+ const c = await r.text();
603
+ throw new Error(c || "Failed to delete group");
604
+ }
605
+ }, Vt = async (a, i, n, t) => {
606
+ const r = `${a}/management/v1/groups/${n}/members`;
607
+ return await Es(r, i, t);
608
+ }, Ut = async (a, i, n, t) => {
609
+ const r = `${a}/management/v1/groups/${n}/members`, c = await fetch(r, {
610
+ method: "DELETE",
611
+ headers: {
612
+ "Content-Type": "application/json",
613
+ Authorization: `Bearer ${i}`
614
+ },
615
+ body: JSON.stringify(t)
616
+ });
617
+ if (!c.ok) {
618
+ const o = await c.text();
619
+ throw new Error(o || "Failed to remove group members");
620
+ }
621
+ };
622
+ function zt() {
623
+ const { authToken: a, tokenProps: i } = re(), n = He();
624
+ return $e({
625
+ mutationFn: (t) => Tt(i.apiServiceUrl, (a == null ? void 0 : a.accessToken) || "", t),
626
+ onSuccess: () => {
627
+ n.invalidateQueries({ queryKey: ["groups"] }), A.success("Group created successfully");
628
+ },
629
+ onError: (t) => {
630
+ console.error("Failed to create group:", t), A.error("Failed to create group", {
631
+ description: t.message
632
+ });
633
+ }
634
+ });
635
+ }
636
+ function Rt() {
637
+ const { authToken: a, tokenProps: i } = re(), n = He();
638
+ return $e({
639
+ mutationFn: (t) => Ot(i.apiServiceUrl, (a == null ? void 0 : a.accessToken) || "", t),
640
+ onSuccess: (t, r) => {
641
+ n.invalidateQueries({ queryKey: ["groups"] }), n.removeQueries({ queryKey: ["group", r] }), A.success("Group deleted successfully");
642
+ },
643
+ onError: (t) => {
644
+ console.error("Failed to delete group:", t), A.error("Failed to delete group", {
645
+ description: t.message
646
+ });
647
+ }
648
+ });
649
+ }
650
+ function Gt() {
651
+ const { authToken: a, tokenProps: i } = re(), n = He();
652
+ return $e({
653
+ mutationFn: ({
654
+ groupId: t,
655
+ data: r
656
+ }) => Vt(i.apiServiceUrl, (a == null ? void 0 : a.accessToken) || "", t, r),
657
+ onSuccess: (t, r) => {
658
+ n.invalidateQueries({ queryKey: ["group", r.groupId] }), n.invalidateQueries({
659
+ queryKey: ["group-members", r.groupId]
660
+ }), n.invalidateQueries({ queryKey: ["groups"] }), A.success("Members added successfully");
661
+ },
662
+ onError: (t) => {
663
+ console.error("Failed to add group members:", t), A.error("Failed to add members", {
664
+ description: t.message
665
+ });
666
+ }
667
+ });
668
+ }
669
+ function jt() {
670
+ const { authToken: a, tokenProps: i } = re(), n = He();
671
+ return $e({
672
+ mutationFn: ({
673
+ groupId: t,
674
+ data: r
675
+ }) => Ut(i.apiServiceUrl, (a == null ? void 0 : a.accessToken) || "", t, r),
676
+ onSuccess: (t, r) => {
677
+ n.invalidateQueries({ queryKey: ["group", r.groupId] }), n.invalidateQueries({
678
+ queryKey: ["group-members", r.groupId]
679
+ }), n.invalidateQueries({ queryKey: ["groups"] }), A.success("Members removed successfully");
680
+ },
681
+ onError: (t) => {
682
+ console.error("Failed to remove group members:", t), A.error("Failed to remove members", {
683
+ description: t.message
684
+ });
685
+ }
686
+ });
687
+ }
688
+ function _t({
689
+ onSuccess: a,
690
+ tenantId: i,
691
+ isTenantUser: n
692
+ }) {
693
+ const [t, r] = x(""), [c, o] = x(""), [m, d] = x({}), f = zt(), p = () => {
694
+ const u = {};
695
+ return t.trim() ? t.length < 3 ? u.name = "Group name must be at least 3 characters" : t.length > 50 && (u.name = "Group name must be less than 50 characters") : u.name = "Group name is required", c && c.length > 200 && (u.description = "Description must be less than 200 characters"), d(u), Object.keys(u).length === 0;
696
+ };
697
+ return /* @__PURE__ */ s("form", { onSubmit: async (u) => {
698
+ if (u.preventDefault(), !p()) return;
699
+ const y = {
700
+ name: t.trim(),
701
+ description: c.trim() || void 0,
702
+ type: n ? "TENANT_GROUP" : "ORG_GROUP",
703
+ ...n && i ? { tenantId: i } : {}
704
+ };
705
+ try {
706
+ await f.mutateAsync(y), r(""), o(""), d({}), a();
707
+ } catch (v) {
708
+ console.error("Failed to create group:", v);
709
+ }
710
+ }, className: "space-y-6", children: [
711
+ /* @__PURE__ */ s("div", { className: "space-y-4", children: [
712
+ /* @__PURE__ */ s("div", { className: "space-y-2", children: [
713
+ /* @__PURE__ */ s(X, { htmlFor: "group-name", children: [
714
+ "Group Name ",
715
+ /* @__PURE__ */ e("span", { className: "text-destructive", children: "*" })
716
+ ] }),
717
+ /* @__PURE__ */ e(
718
+ Ce,
719
+ {
720
+ id: "group-name",
721
+ placeholder: "e.g., Marketing Team, Engineering Squad",
722
+ value: t,
723
+ onChange: (u) => {
724
+ r(u.target.value), m.name && d((y) => ({ ...y, name: "" }));
725
+ },
726
+ className: m.name ? "border-destructive" : "",
727
+ disabled: f.isPending
728
+ }
729
+ ),
730
+ m.name && /* @__PURE__ */ e("p", { className: "text-sm text-destructive", children: m.name })
731
+ ] }),
732
+ /* @__PURE__ */ s("div", { className: "space-y-2", children: [
733
+ /* @__PURE__ */ s(X, { htmlFor: "group-description", children: [
734
+ "Description",
735
+ /* @__PURE__ */ e("span", { className: "ml-2 text-xs text-muted-foreground", children: "(optional)" })
736
+ ] }),
737
+ /* @__PURE__ */ e(
738
+ ks,
739
+ {
740
+ id: "group-description",
741
+ placeholder: "Describe the purpose of this group...",
742
+ value: c,
743
+ onChange: (u) => {
744
+ o(u.target.value), m.description && d((y) => ({ ...y, description: "" }));
745
+ },
746
+ className: m.description ? "border-destructive" : "",
747
+ disabled: f.isPending,
748
+ rows: 3
749
+ }
750
+ ),
751
+ m.description && /* @__PURE__ */ e("p", { className: "text-sm text-destructive", children: m.description }),
752
+ /* @__PURE__ */ s("p", { className: "text-xs text-muted-foreground", children: [
753
+ c.length,
754
+ "/200 characters"
755
+ ] })
756
+ ] }),
757
+ /* @__PURE__ */ e("div", { className: "rounded-lg border bg-muted/50 p-4", children: /* @__PURE__ */ s("div", { className: "flex gap-3", children: [
758
+ /* @__PURE__ */ e(Ys, { className: "h-4 w-4 mt-0.5 text-muted-foreground" }),
759
+ /* @__PURE__ */ e("div", { className: "text-sm text-muted-foreground", children: "This group will be accessible to users in your workspace. You can add members after creating the group." })
760
+ ] }) })
761
+ ] }),
762
+ /* @__PURE__ */ s("div", { className: "flex justify-end gap-3", children: [
763
+ /* @__PURE__ */ e(
764
+ I,
765
+ {
766
+ type: "button",
767
+ variant: "outline",
768
+ onClick: () => {
769
+ r(""), o(""), d({});
770
+ },
771
+ disabled: f.isPending,
772
+ children: "Clear"
773
+ }
774
+ ),
775
+ /* @__PURE__ */ e(
776
+ I,
777
+ {
778
+ type: "submit",
779
+ disabled: f.isPending || !t.trim(),
780
+ children: f.isPending ? /* @__PURE__ */ s(R, { children: [
781
+ /* @__PURE__ */ e(Z, { className: "mr-2 h-4 w-4 animate-spin" }),
782
+ "Creating..."
783
+ ] }) : /* @__PURE__ */ s(R, { children: [
784
+ /* @__PURE__ */ e(te, { className: "mr-2 h-4 w-4" }),
785
+ "Create Group"
786
+ ] })
787
+ }
788
+ )
789
+ ] })
790
+ ] });
791
+ }
792
+ function Bt({
793
+ open: a,
794
+ onOpenChange: i,
795
+ group: n,
796
+ onUpdate: t
797
+ }) {
798
+ const [r, c] = x("members"), [o, m] = x(""), [d, f] = x([]), [p, l] = x([]), { data: u, isLoading: y, refetch: v } = ea(n.id), S = n.type === "TENANT_GROUP" ? "tenant" : "organization", { users: P, isLoading: L } = sa({
799
+ type: S,
800
+ tenantId: n.tenantId || void 0,
801
+ active: !0,
802
+ limit: 100
803
+ }), w = Gt(), O = jt(), C = (u == null ? void 0 : u.members) || [], V = _e(() => new Set(C.map((D) => D.userId)), [C]), T = _e(() => P.filter((D) => !V.has(D.id)), [P, V]), M = _e(() => {
804
+ if (!o) return T;
805
+ const D = o.toLowerCase();
806
+ return T.filter(
807
+ (U) => {
808
+ var z, K;
809
+ return ((z = U.name) == null ? void 0 : z.toLowerCase().includes(D)) || ((K = U.email) == null ? void 0 : K.toLowerCase().includes(D));
810
+ }
811
+ );
812
+ }, [T, o]), k = _e(() => {
813
+ if (!o) return C;
814
+ const D = o.toLowerCase();
815
+ return C.filter(
816
+ (U) => {
817
+ var z, K, ie, se;
818
+ return ((K = (z = U.user) == null ? void 0 : z.name) == null ? void 0 : K.toLowerCase().includes(D)) || ((se = (ie = U.user) == null ? void 0 : ie.email) == null ? void 0 : se.toLowerCase().includes(D));
819
+ }
820
+ );
821
+ }, [C, o]), E = async () => {
822
+ if (d.length !== 0)
823
+ try {
824
+ await w.mutateAsync({
825
+ groupId: n.id,
826
+ data: {
827
+ userIds: d,
828
+ userType: S === "tenant" ? "tenant" : "org"
829
+ }
830
+ }), f([]), c("members"), v(), t == null || t();
831
+ } catch (D) {
832
+ console.error("Failed to add members:", D);
833
+ }
834
+ }, Y = async () => {
835
+ if (p.length !== 0)
836
+ try {
837
+ await O.mutateAsync({
838
+ groupId: n.id,
839
+ data: {
840
+ userIds: p
841
+ }
842
+ }), l([]), v(), t == null || t();
843
+ } catch (D) {
844
+ console.error("Failed to remove members:", D);
845
+ }
846
+ }, j = (D) => {
847
+ f(
848
+ (U) => U.includes(D) ? U.filter((z) => z !== D) : [...U, D]
849
+ );
850
+ }, ee = (D) => {
851
+ l(
852
+ (U) => U.includes(D) ? U.filter((z) => z !== D) : [...U, D]
853
+ );
854
+ };
855
+ return /* @__PURE__ */ e(R, { children: /* @__PURE__ */ e(Ee, { open: a, onOpenChange: i, children: /* @__PURE__ */ s(ke, { className: "max-w-3xl max-h-[80vh]", "aria-describedby": "group-members-description", children: [
856
+ /* @__PURE__ */ s(Fe, { children: [
857
+ /* @__PURE__ */ e(Le, { children: n.name }),
858
+ /* @__PURE__ */ e("div", { className: "flex items-center gap-2 mt-1", children: /* @__PURE__ */ s("p", { className: "text-sm text-muted-foreground", children: [
859
+ C.length,
860
+ " ",
861
+ C.length === 1 ? "member" : "members"
862
+ ] }) }),
863
+ /* @__PURE__ */ s("p", { id: "group-members-description", className: "sr-only", children: [
864
+ "Add or remove members from the ",
865
+ n.name,
866
+ " group"
867
+ ] })
868
+ ] }),
869
+ /* @__PURE__ */ s(is, { value: r, onValueChange: (D) => {
870
+ c(D), m(""), l([]);
871
+ }, className: "mt-4", children: [
872
+ /* @__PURE__ */ s(ls, { className: "grid w-full grid-cols-2", children: [
873
+ /* @__PURE__ */ e(Se, { value: "members", children: "Current Members" }),
874
+ /* @__PURE__ */ e(Se, { value: "add", children: "Add Members" })
875
+ ] }),
876
+ /* @__PURE__ */ s(Pe, { value: "members", className: "mt-4 space-y-4", children: [
877
+ /* @__PURE__ */ s("div", { className: "relative", children: [
878
+ /* @__PURE__ */ e(Ye, { className: "absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" }),
879
+ /* @__PURE__ */ e(
880
+ Ce,
881
+ {
882
+ placeholder: "Search members...",
883
+ value: o,
884
+ onChange: (D) => m(D.target.value),
885
+ className: "pl-10"
886
+ }
887
+ )
888
+ ] }),
889
+ /* @__PURE__ */ e(Ie, { className: p.length > 0 ? "h-[300px]" : "h-[350px]", children: y ? /* @__PURE__ */ e("div", { className: "space-y-2", children: [1, 2, 3].map((D) => /* @__PURE__ */ e(es, { className: "h-16 w-full" }, D)) }) : k.length === 0 ? /* @__PURE__ */ s("div", { className: "flex flex-col items-center justify-center py-12 text-muted-foreground", children: [
890
+ /* @__PURE__ */ e(te, { className: "h-12 w-12 mb-3 opacity-50" }),
891
+ /* @__PURE__ */ e("p", { className: "text-sm font-medium", children: o ? "No members found" : "No members yet" }),
892
+ /* @__PURE__ */ e("p", { className: "text-xs mt-1", children: o ? "Try a different search" : 'Switch to the "Add Members" tab to add people to this group' })
893
+ ] }) : /* @__PURE__ */ e("div", { className: "space-y-2", children: k.map((D) => /* @__PURE__ */ e(
894
+ qt,
895
+ {
896
+ member: D,
897
+ selected: p.includes(D.userId),
898
+ onToggle: () => ee(D.userId)
899
+ },
900
+ D.id
901
+ )) }) }),
902
+ p.length > 0 && /* @__PURE__ */ s("div", { className: "flex items-center justify-between pt-4 border-t", children: [
903
+ /* @__PURE__ */ s("span", { className: "text-sm text-muted-foreground", children: [
904
+ p.length,
905
+ " member",
906
+ p.length !== 1 ? "s" : "",
907
+ " selected"
908
+ ] }),
909
+ /* @__PURE__ */ e(
910
+ I,
911
+ {
912
+ variant: "destructive",
913
+ size: "sm",
914
+ onClick: Y,
915
+ disabled: O.isPending,
916
+ children: O.isPending ? /* @__PURE__ */ s(R, { children: [
917
+ /* @__PURE__ */ e(Z, { className: "mr-2 h-4 w-4 animate-spin" }),
918
+ "Removing..."
919
+ ] }) : /* @__PURE__ */ s(R, { children: [
920
+ /* @__PURE__ */ e(je, { className: "mr-2 h-4 w-4" }),
921
+ "Remove Selected"
922
+ ] })
923
+ }
924
+ )
925
+ ] })
926
+ ] }),
927
+ /* @__PURE__ */ s(Pe, { value: "add", className: "mt-4 space-y-4", children: [
928
+ /* @__PURE__ */ s("div", { className: "relative", children: [
929
+ /* @__PURE__ */ e(Ye, { className: "absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" }),
930
+ /* @__PURE__ */ e(
931
+ Ce,
932
+ {
933
+ placeholder: "Search users to add...",
934
+ value: o,
935
+ onChange: (D) => m(D.target.value),
936
+ className: "pl-10"
937
+ }
938
+ )
939
+ ] }),
940
+ /* @__PURE__ */ e(Ie, { className: "h-[300px]", children: L ? /* @__PURE__ */ e("div", { className: "space-y-2", children: [1, 2, 3].map((D) => /* @__PURE__ */ e(es, { className: "h-16 w-full" }, D)) }) : M.length === 0 ? /* @__PURE__ */ s("div", { className: "flex flex-col items-center justify-center py-12 text-muted-foreground", children: [
941
+ /* @__PURE__ */ e(ss, { className: "h-12 w-12 mb-3 opacity-50" }),
942
+ /* @__PURE__ */ e("p", { className: "text-sm font-medium", children: "No available users" }),
943
+ /* @__PURE__ */ e("p", { className: "text-xs mt-1", children: o ? "Try a different search" : "All eligible users are already members" })
944
+ ] }) : /* @__PURE__ */ e("div", { className: "space-y-2", children: M.map((D) => /* @__PURE__ */ e(
945
+ Qt,
946
+ {
947
+ user: D,
948
+ selected: d.includes(D.id),
949
+ onToggle: () => j(D.id)
950
+ },
951
+ D.id
952
+ )) }) }),
953
+ d.length > 0 && /* @__PURE__ */ s("div", { className: "flex items-center justify-between pt-4 border-t", children: [
954
+ /* @__PURE__ */ s("span", { className: "text-sm text-muted-foreground", children: [
955
+ d.length,
956
+ " user",
957
+ d.length !== 1 ? "s" : "",
958
+ " selected"
959
+ ] }),
960
+ /* @__PURE__ */ e(
961
+ I,
962
+ {
963
+ onClick: E,
964
+ disabled: w.isPending,
965
+ children: w.isPending ? /* @__PURE__ */ s(R, { children: [
966
+ /* @__PURE__ */ e(Z, { className: "mr-2 h-4 w-4 animate-spin" }),
967
+ "Adding..."
968
+ ] }) : /* @__PURE__ */ s(R, { children: [
969
+ /* @__PURE__ */ e(ss, { className: "mr-2 h-4 w-4" }),
970
+ "Add Members"
971
+ ] })
972
+ }
973
+ )
974
+ ] })
975
+ ] })
976
+ ] })
977
+ ] }) }) });
978
+ }
979
+ function qt({
980
+ member: a,
981
+ selected: i,
982
+ onToggle: n
983
+ }) {
984
+ var r, c, o, m;
985
+ const t = ((c = (r = a.user) == null ? void 0 : r.name) == null ? void 0 : c.split(" ").map((d) => d[0]).join("").toUpperCase()) || "?";
986
+ return /* @__PURE__ */ s(
987
+ "div",
988
+ {
989
+ className: "flex items-center gap-3 p-3 rounded-lg border bg-card hover:bg-muted/50 cursor-pointer",
990
+ onClick: n,
991
+ children: [
992
+ /* @__PURE__ */ e(Be, { checked: i }),
993
+ /* @__PURE__ */ e(Fs, { className: "h-8 w-8", children: /* @__PURE__ */ e(Ls, { className: "text-xs", children: t }) }),
994
+ /* @__PURE__ */ s("div", { className: "flex-1", children: [
995
+ /* @__PURE__ */ e("p", { className: "text-sm font-medium", children: ((o = a.user) == null ? void 0 : o.name) || "Unknown User" }),
996
+ /* @__PURE__ */ e("p", { className: "text-xs text-muted-foreground", children: (m = a.user) == null ? void 0 : m.email })
997
+ ] })
998
+ ]
999
+ }
1000
+ );
1001
+ }
1002
+ function Qt({
1003
+ user: a,
1004
+ selected: i,
1005
+ onToggle: n
1006
+ }) {
1007
+ var r;
1008
+ const t = ((r = a.name) == null ? void 0 : r.split(" ").map((c) => c[0]).join("").toUpperCase()) || "?";
1009
+ return /* @__PURE__ */ s(
1010
+ "div",
1011
+ {
1012
+ className: "flex items-center gap-3 p-3 rounded-lg border bg-card hover:bg-muted/50 cursor-pointer",
1013
+ onClick: n,
1014
+ children: [
1015
+ /* @__PURE__ */ e(Be, { checked: i }),
1016
+ /* @__PURE__ */ e(Fs, { className: "h-8 w-8", children: /* @__PURE__ */ e(Ls, { className: "text-xs", children: t }) }),
1017
+ /* @__PURE__ */ s("div", { className: "flex-1", children: [
1018
+ /* @__PURE__ */ e("p", { className: "text-sm font-medium", children: a.name }),
1019
+ /* @__PURE__ */ e("p", { className: "text-xs text-muted-foreground", children: a.email })
1020
+ ] })
1021
+ ]
1022
+ }
1023
+ );
1024
+ }
1025
+ function Ht({
1026
+ open: a,
1027
+ onOpenChange: i
1028
+ }) {
1029
+ const [n, t] = x("groups"), [r, c] = x(""), [o, m] = x(null), [d, f] = x(!1), [p, l] = x(null), { tokenProps: u } = re(), { currentUser: y } = Ae(), v = Rt(), S = (y == null ? void 0 : y.type) === "tenant", P = u == null ? void 0 : u.tenantId, { groups: L, isLoading: w, refetch: O } = aa({
1030
+ type: S ? "TENANT_GROUP" : "all",
1031
+ tenantId: S ? P : void 0,
1032
+ includeMembers: !1
1033
+ }), C = L.filter(
1034
+ (k) => {
1035
+ var E;
1036
+ return k.name.toLowerCase().includes(r.toLowerCase()) || ((E = k.description) == null ? void 0 : E.toLowerCase().includes(r.toLowerCase()));
1037
+ }
1038
+ ), V = async () => {
1039
+ if (p)
1040
+ try {
1041
+ await v.mutateAsync(p.id), l(null), O();
1042
+ } catch (k) {
1043
+ console.error("Failed to delete group:", k);
1044
+ }
1045
+ }, T = (k) => {
1046
+ m(k), f(!0);
1047
+ }, M = () => {
1048
+ t("groups"), O();
1049
+ };
1050
+ return /* @__PURE__ */ s(R, { children: [
1051
+ /* @__PURE__ */ e(Ee, { open: a, onOpenChange: i, children: /* @__PURE__ */ s(ke, { className: "max-w-4xl max-h-[80vh]", children: [
1052
+ /* @__PURE__ */ s(Fe, { children: [
1053
+ /* @__PURE__ */ s(Le, { className: "flex items-center gap-2", children: [
1054
+ /* @__PURE__ */ e(te, { className: "h-5 w-5" }),
1055
+ "Group Management"
1056
+ ] }),
1057
+ /* @__PURE__ */ e(Ge, { children: "Manage your groups, create new groups, and control group membership" })
1058
+ ] }),
1059
+ /* @__PURE__ */ s(is, { value: n, onValueChange: t, className: "mt-4", children: [
1060
+ /* @__PURE__ */ s(ls, { className: "grid w-full grid-cols-2", children: [
1061
+ /* @__PURE__ */ s(Se, { value: "groups", className: "flex items-center gap-2", children: [
1062
+ /* @__PURE__ */ e(te, { className: "h-4 w-4" }),
1063
+ "Groups"
1064
+ ] }),
1065
+ /* @__PURE__ */ s(Se, { value: "create", className: "flex items-center gap-2", children: [
1066
+ /* @__PURE__ */ e(le, { className: "h-4 w-4" }),
1067
+ "Create Group"
1068
+ ] })
1069
+ ] }),
1070
+ /* @__PURE__ */ e(Pe, { value: "groups", className: "mt-4", children: /* @__PURE__ */ s("div", { className: "space-y-4", children: [
1071
+ /* @__PURE__ */ s("div", { className: "relative", children: [
1072
+ /* @__PURE__ */ e(Ye, { className: "absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" }),
1073
+ /* @__PURE__ */ e(
1074
+ Ce,
1075
+ {
1076
+ placeholder: "Search groups...",
1077
+ value: r,
1078
+ onChange: (k) => c(k.target.value),
1079
+ className: "pl-10"
1080
+ }
1081
+ )
1082
+ ] }),
1083
+ /* @__PURE__ */ e(Ie, { className: "h-[400px]", children: w ? /* @__PURE__ */ e("div", { className: "space-y-3", children: [1, 2, 3].map((k) => /* @__PURE__ */ e(es, { className: "h-24 w-full" }, k)) }) : C.length === 0 ? /* @__PURE__ */ s("div", { className: "flex flex-col items-center justify-center py-12 text-muted-foreground", children: [
1084
+ /* @__PURE__ */ e(te, { className: "h-12 w-12 mb-3 opacity-50" }),
1085
+ /* @__PURE__ */ e("p", { className: "text-sm font-medium", children: "No groups found" }),
1086
+ /* @__PURE__ */ e("p", { className: "text-xs mt-1", children: r ? "Try a different search" : "Create your first group to get started" })
1087
+ ] }) : /* @__PURE__ */ e("div", { className: "space-y-3", children: C.map((k) => /* @__PURE__ */ e(
1088
+ $t,
1089
+ {
1090
+ group: k,
1091
+ onManageMembers: () => T(k),
1092
+ onDelete: () => l(k),
1093
+ currentUserId: y == null ? void 0 : y.id
1094
+ },
1095
+ k.id
1096
+ )) }) })
1097
+ ] }) }),
1098
+ /* @__PURE__ */ e(Pe, { value: "create", className: "mt-4", children: /* @__PURE__ */ e(
1099
+ _t,
1100
+ {
1101
+ onSuccess: M,
1102
+ tenantId: P,
1103
+ isTenantUser: S
1104
+ }
1105
+ ) })
1106
+ ] })
1107
+ ] }) }),
1108
+ o && /* @__PURE__ */ e(
1109
+ Bt,
1110
+ {
1111
+ open: d,
1112
+ onOpenChange: f,
1113
+ group: o,
1114
+ onUpdate: () => O()
1115
+ }
1116
+ ),
1117
+ /* @__PURE__ */ e(
1118
+ os,
1119
+ {
1120
+ open: !!p,
1121
+ onOpenChange: () => l(null),
1122
+ children: /* @__PURE__ */ s(cs, { children: [
1123
+ /* @__PURE__ */ s(ds, { children: [
1124
+ /* @__PURE__ */ e(hs, { children: "Delete Group" }),
1125
+ /* @__PURE__ */ s(us, { children: [
1126
+ 'Are you sure you want to delete "',
1127
+ p == null ? void 0 : p.name,
1128
+ '"? This action cannot be undone and will remove all members from the group.'
1129
+ ] })
1130
+ ] }),
1131
+ /* @__PURE__ */ s(ms, { children: [
1132
+ /* @__PURE__ */ e(ps, { children: "Cancel" }),
1133
+ /* @__PURE__ */ e(
1134
+ fs,
1135
+ {
1136
+ onClick: V,
1137
+ disabled: v.isPending,
1138
+ className: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
1139
+ children: v.isPending ? /* @__PURE__ */ s(R, { children: [
1140
+ /* @__PURE__ */ e(Z, { className: "mr-2 h-4 w-4 animate-spin" }),
1141
+ "Deleting..."
1142
+ ] }) : "Delete Group"
1143
+ }
1144
+ )
1145
+ ] })
1146
+ ] })
1147
+ }
1148
+ )
1149
+ ] });
1150
+ }
1151
+ function $t({
1152
+ group: a,
1153
+ onManageMembers: i,
1154
+ onDelete: n,
1155
+ currentUserId: t
1156
+ }) {
1157
+ const r = a.createdBy === t;
1158
+ return /* @__PURE__ */ e("div", { className: "rounded-lg border bg-card p-4 transition-colors hover:bg-muted/50", children: /* @__PURE__ */ s("div", { className: "flex items-start justify-between gap-3", children: [
1159
+ /* @__PURE__ */ s("div", { className: "flex-1 space-y-2", children: [
1160
+ /* @__PURE__ */ s("div", { children: [
1161
+ /* @__PURE__ */ e("h4", { className: "font-medium", children: a.name }),
1162
+ a.description && /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground mt-1", children: a.description })
1163
+ ] }),
1164
+ /* @__PURE__ */ s("div", { className: "flex flex-wrap items-center gap-3 text-xs text-muted-foreground", children: [
1165
+ /* @__PURE__ */ s("span", { className: "flex items-center gap-1", children: [
1166
+ /* @__PURE__ */ e(te, { className: "h-3 w-3" }),
1167
+ a.memberCount,
1168
+ " ",
1169
+ a.memberCount === 1 ? "member" : "members"
1170
+ ] }),
1171
+ /* @__PURE__ */ s("span", { children: [
1172
+ "Created ",
1173
+ ta(new Date(a.createdAt), "MMM d, yyyy")
1174
+ ] })
1175
+ ] })
1176
+ ] }),
1177
+ /* @__PURE__ */ s("div", { className: "flex items-center gap-1", children: [
1178
+ /* @__PURE__ */ e(
1179
+ I,
1180
+ {
1181
+ variant: "ghost",
1182
+ size: "sm",
1183
+ onClick: i,
1184
+ title: "Manage members",
1185
+ children: /* @__PURE__ */ e(ss, { className: "h-4 w-4" })
1186
+ }
1187
+ ),
1188
+ r && /* @__PURE__ */ e(
1189
+ I,
1190
+ {
1191
+ variant: "ghost",
1192
+ size: "sm",
1193
+ onClick: n,
1194
+ title: "Delete group",
1195
+ className: "text-destructive hover:text-destructive",
1196
+ children: /* @__PURE__ */ e(je, { className: "h-4 w-4" })
1197
+ }
1198
+ )
1199
+ ] })
1200
+ ] }) });
1201
+ }
1202
+ function Kt({
1203
+ open: a,
1204
+ onOpenChange: i,
1205
+ isLibraryVisual: n,
1206
+ currentVisualName: t,
1207
+ isSaving: r = !1,
1208
+ onConfirm: c
1209
+ }) {
1210
+ const [o, m] = x(
1211
+ n && t ? `Copy of ${t}` : t || ""
1212
+ ), [d, f] = x(""), [p, l] = x(!n), [u, y] = x(!0);
1213
+ Gs.useEffect(() => {
1214
+ a && (m(
1215
+ n && t ? `Copy of ${t}` : t || ""
1216
+ ), f(""), l(!n), y(!0));
1217
+ }, [a, n, t]);
1218
+ const v = () => {
1219
+ o.trim() && (!p && !u || c({
1220
+ name: o.trim(),
1221
+ description: d.trim() || void 0,
1222
+ saveToLibrary: p,
1223
+ saveToCurrentDashboard: u
1224
+ }));
1225
+ }, S = o.trim() && (p || u);
1226
+ return /* @__PURE__ */ e(Ee, { open: a, onOpenChange: i, children: /* @__PURE__ */ s(ke, { className: "sm:max-w-[425px]", children: [
1227
+ /* @__PURE__ */ s(Fe, { children: [
1228
+ /* @__PURE__ */ e(Le, { children: "Save Visual As" }),
1229
+ /* @__PURE__ */ e(Ge, { children: n ? "Create a copy of this visual with a new name" : "Save this visual to make it reusable" })
1230
+ ] }),
1231
+ /* @__PURE__ */ s("div", { className: "grid gap-4 py-4", children: [
1232
+ /* @__PURE__ */ s("div", { className: "grid gap-2", children: [
1233
+ /* @__PURE__ */ e(X, { htmlFor: "name", children: "Name" }),
1234
+ /* @__PURE__ */ e(
1235
+ ze,
1236
+ {
1237
+ id: "name",
1238
+ value: o,
1239
+ onChange: (P) => m(P.target.value),
1240
+ placeholder: "Enter visual name",
1241
+ disabled: r
1242
+ }
1243
+ )
1244
+ ] }),
1245
+ /* @__PURE__ */ s("div", { className: "grid gap-2", children: [
1246
+ /* @__PURE__ */ e(X, { htmlFor: "description", children: "Description (optional)" }),
1247
+ /* @__PURE__ */ e(
1248
+ ks,
1249
+ {
1250
+ id: "description",
1251
+ value: d,
1252
+ onChange: (P) => f(P.target.value),
1253
+ placeholder: "Enter visual description",
1254
+ rows: 3,
1255
+ disabled: r
1256
+ }
1257
+ )
1258
+ ] }),
1259
+ /* @__PURE__ */ s("div", { className: "space-y-4", children: [
1260
+ /* @__PURE__ */ e(X, { children: "Save to:" }),
1261
+ /* @__PURE__ */ s("div", { className: "space-y-2", children: [
1262
+ /* @__PURE__ */ s("div", { className: "flex items-center space-x-2", children: [
1263
+ /* @__PURE__ */ e(
1264
+ Be,
1265
+ {
1266
+ id: "save-to-dashboard",
1267
+ checked: u,
1268
+ onCheckedChange: (P) => y(!!P),
1269
+ disabled: r
1270
+ }
1271
+ ),
1272
+ /* @__PURE__ */ s(
1273
+ "label",
1274
+ {
1275
+ htmlFor: "save-to-dashboard",
1276
+ className: "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",
1277
+ children: [
1278
+ "Current Dashboard",
1279
+ /* @__PURE__ */ e("span", { className: "ml-2 text-xs text-muted-foreground", children: n ? "(add copy to this dashboard)" : "(keep as local visual)" })
1280
+ ]
1281
+ }
1282
+ )
1283
+ ] }),
1284
+ /* @__PURE__ */ s("div", { className: "flex items-center space-x-2", children: [
1285
+ /* @__PURE__ */ e(
1286
+ Be,
1287
+ {
1288
+ id: "save-to-library",
1289
+ checked: p,
1290
+ onCheckedChange: (P) => l(!!P),
1291
+ disabled: r
1292
+ }
1293
+ ),
1294
+ /* @__PURE__ */ s(
1295
+ "label",
1296
+ {
1297
+ htmlFor: "save-to-library",
1298
+ className: "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",
1299
+ children: [
1300
+ "Visual Library",
1301
+ /* @__PURE__ */ e("span", { className: "ml-2 text-xs text-muted-foreground", children: n ? "(save as new reusable visual)" : "(make available to all dashboards)" })
1302
+ ]
1303
+ }
1304
+ )
1305
+ ] })
1306
+ ] }),
1307
+ !p && !u && /* @__PURE__ */ e("p", { className: "text-sm text-destructive", children: "Please select at least one destination" })
1308
+ ] })
1309
+ ] }),
1310
+ /* @__PURE__ */ s(Qe, { children: [
1311
+ /* @__PURE__ */ e(
1312
+ I,
1313
+ {
1314
+ variant: "outline",
1315
+ onClick: () => i(!1),
1316
+ disabled: r,
1317
+ children: "Cancel"
1318
+ }
1319
+ ),
1320
+ /* @__PURE__ */ s(I, { onClick: v, disabled: !S || r, children: [
1321
+ r && /* @__PURE__ */ e(Z, { className: "mr-2 h-4 w-4 animate-spin" }),
1322
+ r ? "Saving..." : "Save"
1323
+ ] })
1324
+ ] })
1325
+ ] }) });
1326
+ }
1327
+ function Wt() {
1328
+ const [a, i] = x(!1), [n, t] = x(!1), [r, c] = x(null), o = ne((C) => C.frame), m = ne((C) => C.card), d = na(), f = N((C) => C.selectedSheetId), p = N(
1329
+ (C) => C.actions.setIsDashboardPanelOpen
1330
+ ), { getUpdatedFrame: l } = vs(), { selectVisual: u } = Ke(), { addFrame: y, setSelectedFrameId: v, setIsVisualEditing: S } = Re(), P = !!(o != null && o.visualId), L = (d == null ? void 0 : d.title) || (m == null ? void 0 : m.title) || "Untitled Visual", w = ra((C) => {
1331
+ if (C != null && C.id) {
1332
+ if (u(C), n && r && f) {
1333
+ const V = {
1334
+ ...r,
1335
+ id: Ds(),
1336
+ visualId: C.id
1337
+ // Link to the newly created library visual
1338
+ };
1339
+ y(f, V, "end"), v(V.id), t(!1), c(null), S(!1);
1340
+ }
1341
+ p(!0), i(!1);
1342
+ }
1343
+ });
1344
+ return {
1345
+ saveAsDialogOpen: a,
1346
+ setSaveAsDialogOpen: i,
1347
+ handleSaveAs: async (C) => {
1348
+ if (!f) {
1349
+ A.error("No sheet selected");
1350
+ return;
1351
+ }
1352
+ const V = l();
1353
+ if (C.saveToLibrary) {
1354
+ t(C.saveToCurrentDashboard), c(V);
1355
+ const T = {
1356
+ title: C.name,
1357
+ description: C.description,
1358
+ frameObject: V,
1359
+ isPrivate: !1
1360
+ };
1361
+ w.mutate(T);
1362
+ } else if (C.saveToCurrentDashboard) {
1363
+ const T = {
1364
+ ...V,
1365
+ id: Ds(),
1366
+ visualId: void 0,
1367
+ // Explicitly no visualId for local visuals
1368
+ cards: V.cards.map((M) => ({
1369
+ ...M,
1370
+ title: M.id === m.id ? C.name : M.title
1371
+ }))
1372
+ };
1373
+ y(f, T, "end"), v(T.id), A.success("Visual saved to dashboard"), i(!1), S(!1);
1374
+ }
1375
+ },
1376
+ isLibraryVisual: P,
1377
+ currentVisualName: L,
1378
+ isSaving: w.isPending
1379
+ };
1380
+ }
1381
+ function Jt({
1382
+ className: a
1383
+ }) {
1384
+ const i = ne((w) => w.frame), n = ne((w) => w.card), t = ae((w) => w.selectedVisual), r = N((w) => w.selectedFrameId), c = N((w) => w.selectedSheetId), { setIsVisualEditing: o } = Re(), m = !!(i != null && i.visualId || t != null && t.id), d = !!(i != null && i.visualId && r), f = m && !d, {
1385
+ saveAsDialogOpen: p,
1386
+ setSaveAsDialogOpen: l,
1387
+ handleSaveAs: u,
1388
+ isLibraryVisual: y,
1389
+ currentVisualName: v,
1390
+ isSaving: S
1391
+ } = Wt(), { handleAddLibraryVisual: P } = vs(), L = async () => {
1392
+ if (!c) {
1393
+ A.error("No dashboard sheet selected");
1394
+ return;
1395
+ }
1396
+ if (!t) {
1397
+ A.error("No visual selected");
1398
+ return;
1399
+ }
1400
+ const w = await P(t);
1401
+ w.success ? (A.success("Visual added to dashboard"), o(!1)) : A.error(w.error || "Failed to add visual to dashboard");
1402
+ };
1403
+ return /* @__PURE__ */ s(R, { children: [
1404
+ !m && /* @__PURE__ */ e(lt, { className: a, variant: "default" }),
1405
+ m && /* @__PURE__ */ s(R, { children: [
1406
+ d && /* @__PURE__ */ e(ot, { className: a }),
1407
+ f && c && n && (n.sql || ia(n.config)) && /* @__PURE__ */ s(
1408
+ I,
1409
+ {
1410
+ onClick: L,
1411
+ className: G(a),
1412
+ size: "sm",
1413
+ variant: "outline",
1414
+ children: [
1415
+ /* @__PURE__ */ e(gt, { className: "mr-2 size-4 font-bold" }),
1416
+ "Add to Dashboard"
1417
+ ]
1418
+ }
1419
+ ),
1420
+ f && /* @__PURE__ */ e(ct, { className: a, variant: "default" }),
1421
+ d && /* @__PURE__ */ e(dt, { className: a }),
1422
+ /* @__PURE__ */ s(ye, { modal: !1, children: [
1423
+ /* @__PURE__ */ e(we, { asChild: !0, children: /* @__PURE__ */ e(
1424
+ I,
1425
+ {
1426
+ variant: "outline",
1427
+ size: "sm",
1428
+ className: G(a, "w-8 p-0"),
1429
+ children: /* @__PURE__ */ e(Cs, { className: "h-4 w-4" })
1430
+ }
1431
+ ) }),
1432
+ /* @__PURE__ */ e(De, { align: "end", children: /* @__PURE__ */ s(
1433
+ Q,
1434
+ {
1435
+ onClick: (w) => {
1436
+ w.stopPropagation(), l(!0);
1437
+ },
1438
+ children: [
1439
+ /* @__PURE__ */ e(qe, { className: "mr-2 h-4 w-4" }),
1440
+ "Save As..."
1441
+ ]
1442
+ }
1443
+ ) })
1444
+ ] })
1445
+ ] }),
1446
+ !m && /* @__PURE__ */ s(ye, { modal: !1, children: [
1447
+ /* @__PURE__ */ e(we, { asChild: !0, children: /* @__PURE__ */ e(
1448
+ I,
1449
+ {
1450
+ variant: "outline",
1451
+ size: "sm",
1452
+ className: G(a, "w-8 p-0"),
1453
+ children: /* @__PURE__ */ e(Cs, { className: "h-4 w-4" })
1454
+ }
1455
+ ) }),
1456
+ /* @__PURE__ */ e(De, { align: "end", children: /* @__PURE__ */ s(Q, { onClick: () => l(!0), children: [
1457
+ /* @__PURE__ */ e(qe, { className: "mr-2 h-4 w-4" }),
1458
+ "Save As..."
1459
+ ] }) })
1460
+ ] }),
1461
+ /* @__PURE__ */ e(ht, { className: a }),
1462
+ /* @__PURE__ */ e(
1463
+ Kt,
1464
+ {
1465
+ open: p,
1466
+ onOpenChange: (w) => {
1467
+ S || l(w);
1468
+ },
1469
+ isLibraryVisual: y,
1470
+ currentVisualName: v,
1471
+ isSaving: S,
1472
+ onConfirm: u
1473
+ }
1474
+ )
1475
+ ] });
1476
+ }
1477
+ function Xt({
1478
+ className: a,
1479
+ //labelClassName,
1480
+ switchClassName: i
1481
+ }) {
1482
+ const n = ne((m) => m.isDevMode), t = N((m) => m.isVisualEditing), { setIsDevMode: r } = As(), { config: c } = it(la).tokenProps, o = (c == null ? void 0 : c.showAdvancedMode) !== !1;
1483
+ return !t || !o ? null : /* @__PURE__ */ s("div", { className: G("flex items-center space-x-2", a), children: [
1484
+ /* @__PURE__ */ e(
1485
+ oa,
1486
+ {
1487
+ className: G("", i),
1488
+ checked: n,
1489
+ onCheckedChange: () => r(!n),
1490
+ id: "advanced-mode",
1491
+ icon: /* @__PURE__ */ e(ca, { className: "h-4 w-4" }),
1492
+ tooltip: "Advanced Mode"
1493
+ }
1494
+ ),
1495
+ /* @__PURE__ */ e("label", { htmlFor: "advanced-mode", className: "sr-only", children: "Advanced Mode" })
1496
+ ] });
1497
+ }
1498
+ function Zt() {
1499
+ var Ve, g, q;
1500
+ const {
1501
+ authToken: a,
1502
+ tokenProps: i,
1503
+ id: n
1504
+ } = re(), { isLocalDev: t, isConsoleMode: r } = Ts(), { permissions: c } = gs(), o = da(), { isLoading: m } = ha();
1505
+ N((h) => h.theme);
1506
+ const d = N((h) => h.lenses), f = N((h) => h.selectedLensId), p = d == null ? void 0 : d.find((h) => h.id === f), l = N((h) => h.dashboard);
1507
+ N((h) => h.selectedSheetId);
1508
+ const u = N(
1509
+ (h) => h.isDashboardEditing
1510
+ ), { setDashboardTitle: y } = N((h) => h.actions), [v, S] = x(!1), [P, L] = x(!1), [w, O] = x(!1), C = N((h) => h.isDashboardPanelOpen), V = N(
1511
+ (h) => h.actions.setIsDashboardPanelOpen
1512
+ ), T = N((h) => h.filterValues), M = N((h) => h.isVisualEditing), k = ne((h) => h.card), E = ae(
1513
+ (h) => h.selectedDashboard
1514
+ ), Y = ae(
1515
+ (h) => h.initialDashboard
1516
+ ), j = ae((h) => h.selectedVisual);
1517
+ N((h) => h.selectedFrameId), ne((h) => h.frame);
1518
+ const ee = E ? (g = E == null ? void 0 : E.permissions) == null ? void 0 : g.canEdit : (Ve = Y == null ? void 0 : Y.permissions) == null ? void 0 : Ve.canEdit, D = N((h) => h.showFilters), U = N(
1519
+ (h) => h.showDashboardJSON
1520
+ ), z = N((h) => h.onSaveFunction), K = N(
1521
+ (h) => h.actions.setShowFilters
1522
+ ), { setIsDashboardEditing: ie, setShowDashboardJSON: se } = N(
1523
+ (h) => h.actions
1524
+ ), { setInitialDashboard: W, clearSelectedDashboard: Te } = ae(
1525
+ (h) => h.actions
1526
+ ), { resources: H } = ua(Ue.DASHBOARD), { currentUser: ue } = Ae(), me = ma(ue), J = E || Y, ve = J ? {
1527
+ id: J.id,
1528
+ title: (l == null ? void 0 : l.title) || J.title || "Dashboard"
1529
+ } : null, { handleAddNewFrame: Oe } = pa(), [pe, fe] = x(!1), b = fa(Ue.DASHBOARD), B = async (h, _) => {
1530
+ if (!(l != null && l.id)) {
1531
+ console.log("No dashboard ID found");
1532
+ return;
1533
+ }
1534
+ console.log("Updating dashboard title:", {
1535
+ dashboardId: l.id,
1536
+ newTitle: h,
1537
+ previousTitle: _
1538
+ }), b.mutate(
1539
+ {
1540
+ resourceId: l.id,
1541
+ data: { title: h }
1542
+ },
1543
+ {
1544
+ onSuccess: () => {
1545
+ console.log("Dashboard title updated successfully"), A.success("Dashboard title updated");
1546
+ },
1547
+ onError: (ce) => {
1548
+ console.error("Failed to update dashboard title:", ce), A.error("Failed to update dashboard title"), y(_);
1549
+ }
1550
+ }
1551
+ );
1552
+ };
1553
+ Me(() => {
1554
+ if (H && H.length > 0) {
1555
+ const h = l == null ? void 0 : l.id;
1556
+ if (h) {
1557
+ const _ = H.find(
1558
+ (ce) => ce.id === h
1559
+ );
1560
+ _ && W(_);
1561
+ }
1562
+ }
1563
+ }, [H, l == null ? void 0 : l.id, W]);
1564
+ const F = i.orgUserId || i.tenantId, oe = u && !M && F && ee, Ne = () => {
1565
+ ie(!0);
1566
+ };
1567
+ async function ge() {
1568
+ const h = as(
1569
+ l
1570
+ );
1571
+ fe(!0);
1572
+ const _ = {
1573
+ template: h
1574
+ };
1575
+ b.mutate(
1576
+ {
1577
+ resourceId: h.id,
1578
+ data: _
1579
+ },
1580
+ {
1581
+ onSuccess: () => {
1582
+ fe(!1), A.success("Dashboard saved!");
1583
+ },
1584
+ onError: () => {
1585
+ fe(!1), A.error("Failed to save dashboard");
1586
+ }
1587
+ }
1588
+ );
1589
+ }
1590
+ async function xe() {
1591
+ if (S(!0), !f || !p) return;
1592
+ const h = as(
1593
+ l
1594
+ ), _ = JSON.stringify(h), ce = {
1595
+ ...p,
1596
+ template: _,
1597
+ filterValues: T
1598
+ };
1599
+ await ts(
1600
+ i.apiServiceUrl,
1601
+ ce,
1602
+ a == null ? void 0 : a.accessToken
1603
+ ), A.success("Lens saved"), z == null || z(h), S(!1);
1604
+ }
1605
+ const $ = (p == null ? void 0 : p.name) || l.title;
1606
+ b.isPending && console.log("Title during update:", {
1607
+ title: $,
1608
+ dashboardStateTitle: l.title,
1609
+ dashboardId: l == null ? void 0 : l.id,
1610
+ currentLensName: p == null ? void 0 : p.name
1611
+ });
1612
+ const We = H && H.length > 0 && (i.orgUserId || i.tenantId && i.endUserId && i.endUserEmail), Je = E && !(i != null && i.dashboard_id) && !n;
1613
+ return /* @__PURE__ */ s(
1614
+ "div",
1615
+ {
1616
+ className: "flex h-11 items-center justify-between gap-2 border-b px-4 py-2",
1617
+ role: "dashboard-controls",
1618
+ children: [
1619
+ /* @__PURE__ */ s("div", { className: "flex items-center gap-2", children: [
1620
+ We && /* @__PURE__ */ s(R, { children: [
1621
+ /* @__PURE__ */ e(
1622
+ de,
1623
+ {
1624
+ "aria-label": "Manage Dashboards",
1625
+ tooltip: "Manage Dashboards",
1626
+ onClick: () => {
1627
+ V(!C);
1628
+ },
1629
+ className: "h-7 p-2",
1630
+ children: /* @__PURE__ */ e(Nt, { className: "h-4 w-4" })
1631
+ }
1632
+ ),
1633
+ Je && !M && /* @__PURE__ */ e(
1634
+ de,
1635
+ {
1636
+ "aria-label": "Dashboard Hub",
1637
+ tooltip: "Dashboard Hub",
1638
+ onClick: () => Te(),
1639
+ className: "h-7 p-2",
1640
+ children: /* @__PURE__ */ e(Ms, { className: "h-4 w-4" })
1641
+ }
1642
+ )
1643
+ ] }),
1644
+ !M && o && (m ? /* @__PURE__ */ s("div", { className: "flex items-center gap-2", children: [
1645
+ /* @__PURE__ */ e(Z, { className: "h-3 w-3 animate-spin text-muted-foreground" }),
1646
+ /* @__PURE__ */ e("span", { className: "text-sm text-muted-foreground", children: "Loading..." })
1647
+ ] }) : /* @__PURE__ */ e(
1648
+ ga,
1649
+ {
1650
+ value: $ || "Untitled Dashboard",
1651
+ onSave: (h) => {
1652
+ console.log("EditableText onSave called:", {
1653
+ newTitle: h,
1654
+ canEditDashboard: ee,
1655
+ dashboardId: l == null ? void 0 : l.id
1656
+ });
1657
+ const _ = (l == null ? void 0 : l.title) || "";
1658
+ y(h), B(h, _);
1659
+ },
1660
+ isEditable: ee && !p,
1661
+ displayClassName: "text-sm font-medium",
1662
+ inputClassName: "text-sm font-medium",
1663
+ placeholder: "Dashboard Title",
1664
+ isPending: b.isPending
1665
+ }
1666
+ )),
1667
+ M && /* @__PURE__ */ s("div", { className: "flex items-center gap-2", children: [
1668
+ /* @__PURE__ */ e(X, { className: "text-sm font-medium", children: (j == null ? void 0 : j.title) || (k == null ? void 0 : k.title) || "Untitled Visual" }),
1669
+ /* @__PURE__ */ e(At, {})
1670
+ ] })
1671
+ ] }),
1672
+ /* @__PURE__ */ s("div", { className: "flex items-center gap-2", children: [
1673
+ M && /* @__PURE__ */ s(R, { children: [
1674
+ /* @__PURE__ */ e(Xt, { className: "mr-2" }),
1675
+ /* @__PURE__ */ e(Jt, { className: "h-7" })
1676
+ ] }),
1677
+ t && !M && /* @__PURE__ */ e(
1678
+ de,
1679
+ {
1680
+ tooltip: "Invalidate Token",
1681
+ onClick: () => ba(i.apiServiceUrl),
1682
+ className: "h-7 p-2",
1683
+ children: /* @__PURE__ */ e(wt, { className: "h-4 w-4" })
1684
+ }
1685
+ ),
1686
+ !M && o && /* @__PURE__ */ e(Ft, {}),
1687
+ !M && o && /* @__PURE__ */ e(Lt, {}),
1688
+ !M && o && me && /* @__PURE__ */ e(
1689
+ de,
1690
+ {
1691
+ tooltip: "Manage Groups",
1692
+ onClick: () => O(!0),
1693
+ className: "h-7 p-2",
1694
+ children: /* @__PURE__ */ e(te, { className: "h-4 w-4" })
1695
+ }
1696
+ ),
1697
+ !M && o && ((q = J == null ? void 0 : J.permissions) == null ? void 0 : q.canShare) && /* @__PURE__ */ e(
1698
+ de,
1699
+ {
1700
+ tooltip: "Share Dashboard",
1701
+ onClick: () => L(!0),
1702
+ className: "h-7 p-2",
1703
+ children: /* @__PURE__ */ e(va, { className: "h-4 w-4" })
1704
+ }
1705
+ ),
1706
+ !D && !M && u && c.canUseFilters && o && /* @__PURE__ */ e(
1707
+ I,
1708
+ {
1709
+ className: "h-7 p-2",
1710
+ variant: "outline",
1711
+ onClick: () => K(!0),
1712
+ size: "sm",
1713
+ children: /* @__PURE__ */ e(Na, { className: "h-4 w-4" })
1714
+ }
1715
+ ),
1716
+ u && !M && F && t && o && /* @__PURE__ */ e(Et, {}),
1717
+ !M && F && t && o && /* @__PURE__ */ e(kt, {}),
1718
+ u && !M && F && p && t && o && /* @__PURE__ */ s(
1719
+ I,
1720
+ {
1721
+ className: "h-7 p-2",
1722
+ variant: "secondary",
1723
+ disabled: v,
1724
+ onClick: xe,
1725
+ size: "sm",
1726
+ children: [
1727
+ /* @__PURE__ */ e(qe, { className: "mr-2 h-4 w-4" }),
1728
+ "Save Lens"
1729
+ ]
1730
+ }
1731
+ ),
1732
+ u && !M && o && /* @__PURE__ */ s(
1733
+ I,
1734
+ {
1735
+ variant: "outline",
1736
+ className: "h-7 p-2",
1737
+ size: "sm",
1738
+ disabled: !u,
1739
+ onClick: () => Oe(),
1740
+ children: [
1741
+ /* @__PURE__ */ e(le, { className: "mr-2 h-4 w-4" }),
1742
+ "Visual"
1743
+ ]
1744
+ }
1745
+ ),
1746
+ !M && !u && c.canEdit && o && /* @__PURE__ */ s(
1747
+ I,
1748
+ {
1749
+ variant: "outline",
1750
+ className: "h-7 p-2",
1751
+ onClick: Ne,
1752
+ size: "sm",
1753
+ children: [
1754
+ /* @__PURE__ */ e(xa, { className: "mr-2 h-4 w-4" }),
1755
+ "Edit"
1756
+ ]
1757
+ }
1758
+ ),
1759
+ oe && o && /* @__PURE__ */ s(
1760
+ I,
1761
+ {
1762
+ className: "h-7 p-2",
1763
+ disabled: pe,
1764
+ onClick: ge,
1765
+ size: "sm",
1766
+ children: [
1767
+ pe ? /* @__PURE__ */ e(Z, { className: "mr-2 h-4 w-4 animate-spin" }) : /* @__PURE__ */ e(qe, { className: "mr-2 h-4 w-4" }),
1768
+ pe ? "Saving..." : "Save"
1769
+ ]
1770
+ }
1771
+ ),
1772
+ !M && u && t && o && /* @__PURE__ */ e("div", { className: "flex items-center space-x-2", children: /* @__PURE__ */ e(
1773
+ I,
1774
+ {
1775
+ className: "h-7 p-2",
1776
+ onClick: () => se(!U),
1777
+ size: "sm",
1778
+ variant: "ghost",
1779
+ children: /* @__PURE__ */ e(ya, { className: "h-4 w-4" })
1780
+ }
1781
+ ) }),
1782
+ !M && t && /* @__PURE__ */ e(Ct, {}),
1783
+ u && !M && o && /* @__PURE__ */ s(
1784
+ I,
1785
+ {
1786
+ variant: "outline",
1787
+ className: "h-7 p-2",
1788
+ onClick: () => {
1789
+ ie(!1), se(!1);
1790
+ },
1791
+ children: [
1792
+ /* @__PURE__ */ e(rs, { className: "mr-2 h-4 w-4" }),
1793
+ "Close"
1794
+ ]
1795
+ }
1796
+ ),
1797
+ P && ve && /* @__PURE__ */ e(
1798
+ bs,
1799
+ {
1800
+ resource: ve,
1801
+ resourceType: Ue.DASHBOARD,
1802
+ onClose: () => L(!1)
1803
+ }
1804
+ ),
1805
+ /* @__PURE__ */ e(
1806
+ Ht,
1807
+ {
1808
+ open: w,
1809
+ onOpenChange: O
1810
+ }
1811
+ )
1812
+ ] })
1813
+ ]
1814
+ }
1815
+ );
1816
+ }
1817
+ function Yt() {
1818
+ ut();
1819
+ const a = N((d) => d.selectedSheetId), i = N((d) => d.selectedFrameId), n = N((d) => d.dashboard), t = N((d) => d.actions.getSelectedFrame), { setSelectedFrameId: r } = Re(), { setCard: c } = As(), o = ne((d) => d.card.dataSource);
1820
+ return Me(() => {
1821
+ var f, p;
1822
+ let d = t();
1823
+ if (!d) {
1824
+ const l = (f = n == null ? void 0 : n.sheets) == null ? void 0 : f.find((y) => y.id === a), u = (p = l == null ? void 0 : l.frames) == null ? void 0 : p[0];
1825
+ u && (r(u.id), d = u);
1826
+ }
1827
+ if (d) {
1828
+ const l = d.cards.find((u) => u.id === d.activeCardId);
1829
+ l && c(l);
1830
+ }
1831
+ }, [t, a, i, n, r, c]), {
1832
+ hasEntities: !!(o != null && o.selectedEntities && o.selectedEntities.length > 0)
1833
+ };
1834
+ }
1835
+ function en() {
1836
+ const a = N(
1837
+ (n) => n.actions.setShowFilters
1838
+ ), { hasEntities: i } = Yt();
1839
+ return /* @__PURE__ */ s("section", { className: "relative flex min-w-[320px] grow flex-col border-l", children: [
1840
+ /* @__PURE__ */ s("div", { className: "mt-4 flex items-center justify-between gap-2 px-4", children: [
1841
+ /* @__PURE__ */ e(X, { className: "px-2 text-base", children: "Dashboard Filters" }),
1842
+ /* @__PURE__ */ e(
1843
+ I,
1844
+ {
1845
+ onClick: () => a(!1),
1846
+ className: "h-7 w-7 p-0",
1847
+ variant: "ghost",
1848
+ children: /* @__PURE__ */ e(rs, {})
1849
+ }
1850
+ )
1851
+ ] }),
1852
+ !i && /* @__PURE__ */ s("div", { className: "flex h-full flex-col items-center justify-center px-6 py-12 text-center", children: [
1853
+ /* @__PURE__ */ e(wa, { className: "mb-4 h-12 w-12 text-muted-foreground/50" }),
1854
+ /* @__PURE__ */ e("h3", { className: "mb-2 text-sm font-medium text-foreground", children: "No fields configured" }),
1855
+ /* @__PURE__ */ e("p", { className: "text-xs text-muted-foreground", children: "Please configure a data source for this card to enable filtering" })
1856
+ ] }),
1857
+ i && /* @__PURE__ */ e("div", { className: "flex grow", children: /* @__PURE__ */ e(Da, { collisionDetection: Ca, children: /* @__PURE__ */ e(Sa, { items: [], strategy: Pa, children: /* @__PURE__ */ e(mt, { context: "filter" }) }) }) })
1858
+ ] });
1859
+ }
1860
+ function sn() {
1861
+ const a = N((t) => t.dashboard.filters), i = N((t) => t.theme), n = a == null ? void 0 : a.filter((t) => t.hide);
1862
+ return n != null && n.length ? /* @__PURE__ */ e(
1863
+ "div",
1864
+ {
1865
+ className: G("mb-1 flex items-center gap-2 border-y px-0.5 pb-0.5", {
1866
+ "bg-[repeating-linear-gradient(45deg,_#ffffff_0_3px,_#f3f3f3_3px_6px)]": i === "light",
1867
+ "bg-[repeating-linear-gradient(45deg,_#18171d_0_3px,_#272729_3px_6px)]": i === "dark"
1868
+ }),
1869
+ children: n == null ? void 0 : n.map((t) => /* @__PURE__ */ s(
1870
+ "div",
1871
+ {
1872
+ className: "flex min-w-[250px] max-w-fit flex-col gap-1 p-2",
1873
+ children: [
1874
+ /* @__PURE__ */ e(Ia, { filter: t }),
1875
+ /* @__PURE__ */ e(Ma, { filter: t })
1876
+ ]
1877
+ },
1878
+ t.id
1879
+ ))
1880
+ }
1881
+ ) : null;
1882
+ }
1883
+ function an() {
1884
+ const a = N((t) => t.showFilters), i = N((t) => t.isVisualEditing), n = N(
1885
+ (t) => t.isDashboardEditing
1886
+ );
1887
+ return /* @__PURE__ */ s(
1888
+ "div",
1889
+ {
1890
+ role: "dashboard-plus-main",
1891
+ className: G("", {
1892
+ "max-h-0 overflow-hidden": i,
1893
+ "flex grow overflow-auto": !i
1894
+ // can't do h-full because parent container has dashboard controls (10px height)
1895
+ //**overflow-auto** is needed to prevent the tabs from overflowing the container - important for chatbox
1896
+ }),
1897
+ children: [
1898
+ /* @__PURE__ */ s("section", { className: "flex grow flex-col", children: [
1899
+ n && /* @__PURE__ */ e(sn, {}),
1900
+ /* @__PURE__ */ e(Ea, {})
1901
+ ] }),
1902
+ a && /* @__PURE__ */ e("div", { role: "filter-aside-container", className: "flex", children: /* @__PURE__ */ e(en, {}) })
1903
+ ]
1904
+ }
1905
+ );
1906
+ }
1907
+ function js() {
1908
+ return /* @__PURE__ */ e(Ie, { className: "w-full flex-1", children: /* @__PURE__ */ s("div", { className: "space-y-4 px-4 py-2", children: [
1909
+ /* @__PURE__ */ e("div", { className: "h-9 w-full rounded bg-muted animate-pulse" }),
1910
+ /* @__PURE__ */ e("div", { className: "h-9 w-full rounded bg-muted animate-pulse" }),
1911
+ /* @__PURE__ */ e("div", { className: "space-y-3 pt-2", children: [...Array(3)].map((a, i) => /* @__PURE__ */ s("div", { className: "flex gap-3 animate-pulse", children: [
1912
+ /* @__PURE__ */ e("div", { className: "h-8 w-8 rounded bg-muted flex-shrink-0" }),
1913
+ /* @__PURE__ */ s("div", { className: "flex-1 space-y-1.5", children: [
1914
+ /* @__PURE__ */ e("div", { className: "h-4 w-2/3 rounded bg-muted" }),
1915
+ /* @__PURE__ */ e("div", { className: "h-3 w-4/5 rounded bg-muted" })
1916
+ ] })
1917
+ ] }, i)) })
1918
+ ] }) });
1919
+ }
1920
+ const tn = (a) => {
1921
+ const i = N((r) => r.isVisualEditing), n = N((r) => r.selectedFrameId), t = ne((r) => r.frame);
1922
+ return !!(i && n && (t == null ? void 0 : t.visualId) === a);
1923
+ };
1924
+ function nn({
1925
+ visual: a,
1926
+ isDeleting: i,
1927
+ isDuplicating: n,
1928
+ onAddVisual: t,
1929
+ onOpenVisual: r,
1930
+ onEditDetails: c,
1931
+ onDeleteClick: o,
1932
+ onDuplicateVisual: m,
1933
+ // onTogglePrivacy,
1934
+ onShareVisual: d,
1935
+ formatDate: f
1936
+ }) {
1937
+ var V, T, M, k;
1938
+ const { selectVisual: p } = Ke(), l = ka(a.id), u = tn(a.id), { isConsoleMode: y } = Ts(), v = Gs.useRef(null), [S, P] = x(!1), [L, w] = x(!1);
1939
+ Me(() => {
1940
+ n ? (P(!0), w(!0)) : L && (P(!1), w(!1));
1941
+ }, [n, L]), Me(() => {
1942
+ u && v.current && v.current.scrollIntoView({
1943
+ behavior: "smooth",
1944
+ block: "center"
1945
+ });
1946
+ }, [u]);
1947
+ const O = () => /* @__PURE__ */ e(Us, { className: "h-4 w-4" }), C = () => {
1948
+ p(a), r == null || r(a);
1949
+ };
1950
+ return /* @__PURE__ */ e(
1951
+ Os,
1952
+ {
1953
+ ref: v,
1954
+ className: G(
1955
+ "group cursor-pointer border border-border/50 p-3 transition-colors hover:bg-accent/50",
1956
+ u ? "border-purple-500" : l && "border-primary"
1957
+ ),
1958
+ onClick: C,
1959
+ children: /* @__PURE__ */ s("div", { className: "flex items-start gap-3", children: [
1960
+ /* @__PURE__ */ e("div", { className: "mt-0.5 rounded bg-muted p-1.5", children: O() }),
1961
+ /* @__PURE__ */ s("div", { className: "min-w-0 flex-1 flex flex-col", children: [
1962
+ /* @__PURE__ */ s("div", { className: "flex items-center gap-2", children: [
1963
+ /* @__PURE__ */ e(
1964
+ "p",
1965
+ {
1966
+ className: "text-sm font-medium text-foreground truncate",
1967
+ title: a.title || "Untitled Visual",
1968
+ children: a.title || "Untitled Visual"
1969
+ }
1970
+ ),
1971
+ a.ownership.status === "shared" && /* @__PURE__ */ s(Vs, { variant: "outline", className: "text-xs", children: [
1972
+ /* @__PURE__ */ e(te, { className: "mr-1 h-2.5 w-2.5" }),
1973
+ "Shared"
1974
+ ] })
1975
+ ] }),
1976
+ /* @__PURE__ */ s("div", { className: "flex items-center justify-between gap-2", children: [
1977
+ /* @__PURE__ */ e(
1978
+ "p",
1979
+ {
1980
+ className: "text-xs text-muted-foreground line-clamp-2 flex-1",
1981
+ title: a.description || "No description",
1982
+ children: (V = a.description) != null && V.trim() ? a.description : "No description"
1983
+ }
1984
+ ),
1985
+ /* @__PURE__ */ s(
1986
+ "div",
1987
+ {
1988
+ className: G(
1989
+ "invisible flex flex-shrink-0 items-center gap-1 transition-opacity duration-150 group-hover:visible",
1990
+ l && "visible"
1991
+ ),
1992
+ onClick: (E) => E.stopPropagation(),
1993
+ children: [
1994
+ /* @__PURE__ */ e(
1995
+ I,
1996
+ {
1997
+ size: "sm",
1998
+ variant: "ghost",
1999
+ className: "h-6 w-6 p-0",
2000
+ onClick: (E) => {
2001
+ E.stopPropagation(), t(a);
2002
+ },
2003
+ title: "Add to dashboard",
2004
+ children: /* @__PURE__ */ e(le, { className: "h-3.5 w-3.5" })
2005
+ }
2006
+ ),
2007
+ a.ownership.isOwner && /* @__PURE__ */ e(
2008
+ I,
2009
+ {
2010
+ size: "sm",
2011
+ variant: "ghost",
2012
+ className: "h-6 w-6 p-0",
2013
+ onClick: (E) => {
2014
+ E.stopPropagation(), c == null || c(a);
2015
+ },
2016
+ title: "Edit details",
2017
+ children: /* @__PURE__ */ e(Ss, { className: "h-3 w-3" })
2018
+ }
2019
+ ),
2020
+ /* @__PURE__ */ s(
2021
+ ye,
2022
+ {
2023
+ modal: !1,
2024
+ open: S,
2025
+ onOpenChange: P,
2026
+ children: [
2027
+ /* @__PURE__ */ e(we, { asChild: !0, children: /* @__PURE__ */ e(I, { size: "sm", variant: "ghost", className: "h-6 w-6 p-0", children: /* @__PURE__ */ e(Fa, { className: "h-3 w-3" }) }) }),
2028
+ /* @__PURE__ */ s(De, { align: "end", className: "z-[51] w-40", children: [
2029
+ /* @__PURE__ */ s(
2030
+ Q,
2031
+ {
2032
+ onClick: (E) => {
2033
+ E.stopPropagation(), t(a);
2034
+ },
2035
+ children: [
2036
+ /* @__PURE__ */ e(le, { className: "mr-2 h-3 w-3" }),
2037
+ "Add"
2038
+ ]
2039
+ }
2040
+ ),
2041
+ /* @__PURE__ */ s(
2042
+ Q,
2043
+ {
2044
+ onClick: (E) => {
2045
+ E.stopPropagation(), r == null || r(a);
2046
+ },
2047
+ children: [
2048
+ /* @__PURE__ */ e(bt, { className: "mr-2 h-3 w-3" }),
2049
+ "Open"
2050
+ ]
2051
+ }
2052
+ ),
2053
+ /* @__PURE__ */ s(
2054
+ Q,
2055
+ {
2056
+ onClick: (E) => {
2057
+ E.preventDefault(), E.stopPropagation(), m(a.id);
2058
+ },
2059
+ disabled: n,
2060
+ children: [
2061
+ n ? /* @__PURE__ */ e(Z, { className: "mr-2 h-3 w-3 animate-spin" }) : /* @__PURE__ */ e(La, { className: "mr-2 h-3 w-3" }),
2062
+ n ? "Duplicating..." : "Duplicate"
2063
+ ]
2064
+ }
2065
+ ),
2066
+ a.ownership.isOwner && /* @__PURE__ */ s(R, { children: [
2067
+ /* @__PURE__ */ s(
2068
+ Q,
2069
+ {
2070
+ onClick: (E) => {
2071
+ E.stopPropagation(), c == null || c(a);
2072
+ },
2073
+ children: [
2074
+ /* @__PURE__ */ e(Ss, { className: "mr-2 h-3 w-3" }),
2075
+ "Edit details"
2076
+ ]
2077
+ }
2078
+ ),
2079
+ /* @__PURE__ */ s(
2080
+ Q,
2081
+ {
2082
+ onClick: (E) => {
2083
+ E.stopPropagation(), d(a);
2084
+ },
2085
+ children: [
2086
+ /* @__PURE__ */ e(te, { className: "mr-2 h-3 w-3" }),
2087
+ "Share"
2088
+ ]
2089
+ }
2090
+ ),
2091
+ /* @__PURE__ */ e(Ze, {}),
2092
+ /* @__PURE__ */ s(
2093
+ Q,
2094
+ {
2095
+ onClick: (E) => {
2096
+ E.stopPropagation(), o(a);
2097
+ },
2098
+ className: "text-destructive",
2099
+ disabled: i,
2100
+ children: [
2101
+ /* @__PURE__ */ e(je, { className: "mr-2 h-3 w-3" }),
2102
+ i ? "Deleting..." : "Delete"
2103
+ ]
2104
+ }
2105
+ )
2106
+ ] }),
2107
+ /* @__PURE__ */ e(Ze, {}),
2108
+ /* @__PURE__ */ s("div", { className: "space-y-1 px-2 py-2 text-xs text-slate-500 dark:text-slate-400", children: [
2109
+ (((T = a.ownership.createdBy) == null ? void 0 : T.type) === "tenant" || ((M = a.ownership.createdBy) == null ? void 0 : M.type) === "organization" && y) && /* @__PURE__ */ s("div", { className: "flex items-center gap-1", children: [
2110
+ /* @__PURE__ */ e(Aa, { className: "h-3 w-3" }),
2111
+ /* @__PURE__ */ e("span", { children: ((k = a.ownership.createdBy) == null ? void 0 : k.name) || "Unknown" })
2112
+ ] }),
2113
+ /* @__PURE__ */ s("div", { className: "flex items-center gap-1", children: [
2114
+ /* @__PURE__ */ e(Ta, { className: "h-3 w-3" }),
2115
+ /* @__PURE__ */ e("span", { children: f(a.lastModified) })
2116
+ ] })
2117
+ ] })
2118
+ ] })
2119
+ ]
2120
+ }
2121
+ )
2122
+ ]
2123
+ }
2124
+ )
2125
+ ] })
2126
+ ] })
2127
+ ] })
2128
+ },
2129
+ a.id
2130
+ );
2131
+ }
2132
+ function rn({
2133
+ open: a,
2134
+ onOpenChange: i,
2135
+ onSubmit: n,
2136
+ isCreating: t
2137
+ }) {
2138
+ const [r, c] = x(""), [o, m] = x("");
2139
+ Me(() => {
2140
+ a || (c(""), m(""));
2141
+ }, [a]);
2142
+ const d = () => {
2143
+ r.trim() && n({ title: r, description: o });
2144
+ }, f = (p) => {
2145
+ i(p);
2146
+ };
2147
+ return /* @__PURE__ */ e(Ee, { open: a, onOpenChange: f, children: /* @__PURE__ */ s(ke, { children: [
2148
+ /* @__PURE__ */ s(Fe, { children: [
2149
+ /* @__PURE__ */ e(Le, { children: "Create New Visual" }),
2150
+ /* @__PURE__ */ e(Ge, { children: "Add a new visual to your library. You can configure it after creation." })
2151
+ ] }),
2152
+ /* @__PURE__ */ s("div", { className: "space-y-4 py-4", children: [
2153
+ /* @__PURE__ */ s("div", { className: "space-y-2", children: [
2154
+ /* @__PURE__ */ e(X, { htmlFor: "title", children: "Visual Title" }),
2155
+ /* @__PURE__ */ e(
2156
+ ze,
2157
+ {
2158
+ id: "title",
2159
+ placeholder: "Enter visual title...",
2160
+ value: r,
2161
+ onChange: (p) => c(p.target.value),
2162
+ disabled: t,
2163
+ onKeyDown: (p) => {
2164
+ p.key === "Enter" && !p.shiftKey && (p.preventDefault(), d());
2165
+ }
2166
+ }
2167
+ )
2168
+ ] }),
2169
+ /* @__PURE__ */ s("div", { className: "space-y-2", children: [
2170
+ /* @__PURE__ */ e(X, { htmlFor: "description", children: "Description (optional)" }),
2171
+ /* @__PURE__ */ e(
2172
+ ze,
2173
+ {
2174
+ id: "description",
2175
+ placeholder: "Enter visual description...",
2176
+ value: o,
2177
+ onChange: (p) => m(p.target.value),
2178
+ disabled: t
2179
+ }
2180
+ )
2181
+ ] })
2182
+ ] }),
2183
+ /* @__PURE__ */ s(Qe, { children: [
2184
+ /* @__PURE__ */ e(
2185
+ I,
2186
+ {
2187
+ variant: "outline",
2188
+ onClick: () => f(!1),
2189
+ disabled: t,
2190
+ children: "Cancel"
2191
+ }
2192
+ ),
2193
+ /* @__PURE__ */ e(
2194
+ I,
2195
+ {
2196
+ onClick: d,
2197
+ disabled: !r.trim() || t,
2198
+ children: t ? /* @__PURE__ */ s(R, { children: [
2199
+ /* @__PURE__ */ e(Z, { className: "mr-2 h-4 w-4 animate-spin" }),
2200
+ "Creating..."
2201
+ ] }) : "Create Visual"
2202
+ }
2203
+ )
2204
+ ] })
2205
+ ] }) });
2206
+ }
2207
+ function ln() {
2208
+ const [a, i] = x(""), [n, t] = x(!1), [r, c] = x(!1), [o, m] = x(
2209
+ null
2210
+ ), [d, f] = x(!1), [p, l] = x(null), [u, y] = x(null), [v, S] = x(
2211
+ null
2212
+ ), { selectVisual: P } = Ke(), { handleEditLibraryVisual: L, handleAddLibraryVisual: w } = vs(), {
2213
+ resources: O,
2214
+ isLoading: C,
2215
+ isError: V,
2216
+ createResource: T,
2217
+ updateResource: M,
2218
+ deleteResource: k,
2219
+ duplicateResource: E,
2220
+ isCreating: Y,
2221
+ isDeleting: j
2222
+ } = Oa(
2223
+ () => {
2224
+ f(!1), l(null);
2225
+ },
2226
+ (b) => {
2227
+ t(!1), b && (P(b), L(b));
2228
+ }
2229
+ );
2230
+ Ae();
2231
+ const ee = O.filter(
2232
+ (b) => {
2233
+ var B, F;
2234
+ return ((B = b == null ? void 0 : b.title) == null ? void 0 : B.toLowerCase().includes(a.toLowerCase())) || ((F = b == null ? void 0 : b.description) == null ? void 0 : F.toLowerCase().includes(a.toLowerCase()));
2235
+ }
2236
+ ), D = (b) => new Date(b).toLocaleDateString("en-US", {
2237
+ month: "short",
2238
+ day: "numeric",
2239
+ year: "numeric"
2240
+ }), U = (b) => {
2241
+ T({
2242
+ title: b.title,
2243
+ description: b.description,
2244
+ isPrivate: !1
2245
+ });
2246
+ }, z = (b) => {
2247
+ l(b), f(!0);
2248
+ }, K = () => {
2249
+ p && k(p.id);
2250
+ }, {
2251
+ startUpdating: ie,
2252
+ stopUpdating: se,
2253
+ isUpdating: W
2254
+ } = zs(), Te = (b, B, F) => {
2255
+ var xe;
2256
+ const oe = Object.fromEntries(
2257
+ Object.entries(B).filter(([, $]) => $ !== void 0)
2258
+ );
2259
+ if (Object.keys(oe).length === 0) {
2260
+ (xe = F == null ? void 0 : F.onSuccess) == null || xe.call(F);
2261
+ return;
2262
+ }
2263
+ const Ne = Object.keys(oe), ge = Ne.length === 1 ? Ne[0] : void 0;
2264
+ ie(b, ge), M(
2265
+ {
2266
+ resourceId: b,
2267
+ data: oe
2268
+ },
2269
+ {
2270
+ onSuccess: () => {
2271
+ var $;
2272
+ se(b, ge), ($ = F == null ? void 0 : F.onSuccess) == null || $.call(F);
2273
+ },
2274
+ onError: () => {
2275
+ var $;
2276
+ se(b, ge), ($ = F == null ? void 0 : F.onError) == null || $.call(F);
2277
+ }
2278
+ }
2279
+ );
2280
+ }, H = (b) => {
2281
+ y(b), E(b, {
2282
+ onSettled: () => y(null)
2283
+ });
2284
+ }, ue = (b) => {
2285
+ L(b);
2286
+ }, me = (b) => {
2287
+ w(b);
2288
+ }, J = (b) => {
2289
+ const B = O.find((F) => F.id === b);
2290
+ B && M({
2291
+ resourceId: b,
2292
+ data: {
2293
+ isPrivate: !B.isPrivate
2294
+ }
2295
+ });
2296
+ }, ve = (b) => {
2297
+ m(b), c(!0);
2298
+ }, Oe = (b) => {
2299
+ S(b);
2300
+ }, pe = () => {
2301
+ S(null);
2302
+ }, fe = ({
2303
+ title: b,
2304
+ description: B
2305
+ }) => {
2306
+ if (!v)
2307
+ return;
2308
+ const F = {};
2309
+ b !== v.title && (F.title = b), (v.description || "") !== B && (F.description = B), Te(v.id, F, {
2310
+ onSuccess: () => {
2311
+ S(null);
2312
+ }
2313
+ });
2314
+ };
2315
+ return C ? /* @__PURE__ */ e(js, {}) : V ? /* @__PURE__ */ e(Ie, { className: "w-full flex-1 pr-2", children: /* @__PURE__ */ s("div", { className: "py-8 text-center text-muted-foreground", children: [
2316
+ /* @__PURE__ */ e("p", { className: "text-sm text-destructive", children: "Failed to load visuals" }),
2317
+ /* @__PURE__ */ e(
2318
+ I,
2319
+ {
2320
+ variant: "outline",
2321
+ size: "sm",
2322
+ className: "mt-2",
2323
+ onClick: () => window.location.reload(),
2324
+ children: "Retry"
2325
+ }
2326
+ )
2327
+ ] }) }) : /* @__PURE__ */ s("div", { className: "relative flex h-full flex-1 flex-col gap-4", children: [
2328
+ O && O.length > 5 && /* @__PURE__ */ e("div", { className: "space-y-2", children: /* @__PURE__ */ e(
2329
+ ze,
2330
+ {
2331
+ id: "search",
2332
+ placeholder: "Search by title or description...",
2333
+ value: a,
2334
+ onChange: (b) => i(b.target.value),
2335
+ className: "h-9"
2336
+ }
2337
+ ) }),
2338
+ /* @__PURE__ */ e("div", { className: "flex flex-1 flex-col", children: /* @__PURE__ */ e("div", { className: "flex flex-1 basis-0 flex-col gap-3 overflow-y-auto", children: ee.length === 0 ? /* @__PURE__ */ s("div", { className: "py-8 text-center", children: [
2339
+ /* @__PURE__ */ e("div", { className: "mb-3", children: /* @__PURE__ */ e(Us, { className: "mx-auto h-12 w-12 text-muted-foreground/50" }) }),
2340
+ /* @__PURE__ */ e("h3", { className: "mb-1 font-medium text-foreground", children: a ? "No visuals found" : "No visuals yet" }),
2341
+ /* @__PURE__ */ e("p", { className: "mb-4 text-sm text-muted-foreground", children: a ? "Try adjusting your search" : "Create your first visual component to get started" }),
2342
+ !a && /* @__PURE__ */ s(
2343
+ I,
2344
+ {
2345
+ size: "sm",
2346
+ className: "bg-primary hover:bg-primary/90",
2347
+ onClick: () => t(!0),
2348
+ children: [
2349
+ /* @__PURE__ */ e(le, { className: "mr-2 h-4 w-4" }),
2350
+ "Create Visual"
2351
+ ]
2352
+ }
2353
+ )
2354
+ ] }) : ee.map((b) => /* @__PURE__ */ e(
2355
+ nn,
2356
+ {
2357
+ visual: b,
2358
+ onAddVisual: me,
2359
+ onOpenVisual: ue,
2360
+ onEditDetails: Oe,
2361
+ onDeleteClick: z,
2362
+ onDuplicateVisual: H,
2363
+ onTogglePrivacy: J,
2364
+ onShareVisual: ve,
2365
+ isDeleting: j,
2366
+ isDuplicating: u === b.id,
2367
+ formatDate: D
2368
+ },
2369
+ b.id
2370
+ )) }) }),
2371
+ r && o && /* @__PURE__ */ e(
2372
+ bs,
2373
+ {
2374
+ resource: o,
2375
+ resourceType: Ue.VISUAL,
2376
+ onClose: () => {
2377
+ c(!1), m(null);
2378
+ }
2379
+ }
2380
+ ),
2381
+ v && /* @__PURE__ */ e(
2382
+ Rs,
2383
+ {
2384
+ open: !!v,
2385
+ resourceLabel: "Visual",
2386
+ initialTitle: v.title || "",
2387
+ initialDescription: v.description || "",
2388
+ onClose: pe,
2389
+ onSave: fe,
2390
+ isSaving: W(v.id)
2391
+ }
2392
+ ),
2393
+ /* @__PURE__ */ e(
2394
+ os,
2395
+ {
2396
+ open: d,
2397
+ onOpenChange: (b) => {
2398
+ !b && j || (f(b), b || l(null));
2399
+ },
2400
+ children: /* @__PURE__ */ s(cs, { children: [
2401
+ /* @__PURE__ */ s(ds, { children: [
2402
+ /* @__PURE__ */ e(hs, { children: "Delete Visual" }),
2403
+ /* @__PURE__ */ s(us, { children: [
2404
+ 'Are you sure you want to delete "',
2405
+ p == null ? void 0 : p.title,
2406
+ '"? This action cannot be undone.'
2407
+ ] })
2408
+ ] }),
2409
+ /* @__PURE__ */ s(ms, { children: [
2410
+ /* @__PURE__ */ e(ps, { disabled: j, children: "Cancel" }),
2411
+ /* @__PURE__ */ s(
2412
+ fs,
2413
+ {
2414
+ onClick: (b) => {
2415
+ b.preventDefault(), b.stopPropagation(), K();
2416
+ },
2417
+ className: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
2418
+ disabled: j,
2419
+ children: [
2420
+ j ? /* @__PURE__ */ e(Z, { className: "mr-2 h-3.5 w-3.5 animate-spin" }) : /* @__PURE__ */ e(je, { className: "mr-2 h-3.5 w-3.5" }),
2421
+ j ? "Deleting..." : "Delete"
2422
+ ]
2423
+ }
2424
+ )
2425
+ ] })
2426
+ ] })
2427
+ }
2428
+ ),
2429
+ /* @__PURE__ */ e(
2430
+ rn,
2431
+ {
2432
+ open: n,
2433
+ onOpenChange: t,
2434
+ onSubmit: U,
2435
+ isCreating: Y
2436
+ }
2437
+ ),
2438
+ /* @__PURE__ */ e(
2439
+ I,
2440
+ {
2441
+ size: "icon",
2442
+ className: "absolute bottom-2 left-2 h-11 w-11 rounded-full shadow-lg shadow-black/15",
2443
+ onClick: () => t(!0),
2444
+ "aria-label": "Create visual",
2445
+ children: /* @__PURE__ */ e(le, { className: "h-5 w-5" })
2446
+ }
2447
+ )
2448
+ ] });
2449
+ }
2450
+ function on({
2451
+ dashboard: a,
2452
+ isDeleting: i,
2453
+ isDuplicating: n,
2454
+ onLoadDashboard: t,
2455
+ onEditDetails: r,
2456
+ onDeleteClick: c,
2457
+ onDuplicateDashboard: o,
2458
+ onShareDashboard: m,
2459
+ formatDate: d,
2460
+ onDashboardItemClick: f
2461
+ }) {
2462
+ var w, O;
2463
+ const { selectDashboard: p } = Ke(), l = Va(a.id), { userContext: u, isLoading: y } = Ae(), v = ((w = u == null ? void 0 : u.permissions) == null ? void 0 : w.canEdit) ?? !1, S = y || !v, P = () => /* @__PURE__ */ e(za, { className: "h-4 w-4" }), L = () => {
2464
+ p(a), t(a.id), f == null || f(a.id);
2465
+ };
2466
+ return /* @__PURE__ */ e(
2467
+ Os,
2468
+ {
2469
+ className: G(
2470
+ "group cursor-pointer border border-border/50 p-3 transition-colors hover:bg-accent/50",
2471
+ l && "border-primary"
2472
+ ),
2473
+ onClick: L,
2474
+ children: /* @__PURE__ */ s("div", { className: "flex items-start gap-3", children: [
2475
+ /* @__PURE__ */ e("div", { className: "mt-0.5 rounded bg-muted p-1.5", children: P() }),
2476
+ /* @__PURE__ */ s("div", { className: "min-w-0 flex-1 flex flex-col", children: [
2477
+ /* @__PURE__ */ s("div", { className: "flex items-center gap-2", children: [
2478
+ /* @__PURE__ */ e(
2479
+ "p",
2480
+ {
2481
+ className: "text-sm font-medium text-foreground truncate",
2482
+ title: a.title || "Untitled Dashboard",
2483
+ children: a.title || "Untitled Dashboard"
2484
+ }
2485
+ ),
2486
+ a.ownership.status === "shared" && /* @__PURE__ */ s(Vs, { variant: "outline", className: "text-xs", children: [
2487
+ /* @__PURE__ */ e(te, { className: "mr-1 h-2.5 w-2.5" }),
2488
+ "Shared"
2489
+ ] })
2490
+ ] }),
2491
+ /* @__PURE__ */ s("div", { className: "flex items-center justify-between gap-2", children: [
2492
+ /* @__PURE__ */ e(
2493
+ "p",
2494
+ {
2495
+ className: "text-xs text-muted-foreground line-clamp-2 flex-1",
2496
+ title: a.description || "No description",
2497
+ children: (O = a.description) != null && O.trim() ? a.description : "No description"
2498
+ }
2499
+ ),
2500
+ /* @__PURE__ */ e(
2501
+ Ua,
2502
+ {
2503
+ dashboard: a,
2504
+ isDeleting: i,
2505
+ isDuplicating: n,
2506
+ shouldHideActions: S,
2507
+ onEditDetails: r,
2508
+ onDeleteClick: c,
2509
+ onDuplicateDashboard: o,
2510
+ onShareDashboard: m,
2511
+ formatDate: d
2512
+ }
2513
+ )
2514
+ ] })
2515
+ ] })
2516
+ ] })
2517
+ },
2518
+ a.id
2519
+ );
2520
+ }
2521
+ function cn({ onRetry: a }) {
2522
+ return /* @__PURE__ */ e(Ie, { className: "w-full flex-1 pr-2", children: /* @__PURE__ */ s("div", { className: "py-8 text-center text-muted-foreground", children: [
2523
+ /* @__PURE__ */ e("p", { className: "text-sm text-destructive", children: "Failed to load dashboards" }),
2524
+ /* @__PURE__ */ e(I, { variant: "outline", size: "sm", className: "mt-2", onClick: a, children: "Retry" })
2525
+ ] }) });
2526
+ }
2527
+ function dn(a) {
2528
+ var Ve;
2529
+ const { onLoadDashboard: i, onEditDashboard: n, onDashboardItemClick: t } = a, [r, c] = x(""), [o, m] = x(!1), [d, f] = x(!1), [p, l] = x(
2530
+ null
2531
+ ), [u, y] = x(!1), [v, S] = x(null), [P, L] = x(null), [w, O] = x(null), C = ae(
2532
+ (g) => g.lastSelectedDashboard
2533
+ ), V = ae(
2534
+ (g) => g.selectedDashboard
2535
+ ), T = ae(
2536
+ (g) => g.actions.selectDashboard
2537
+ ), M = ae(
2538
+ (g) => g.actions.clearSelectedDashboard
2539
+ ), { tokenProps: k, id: E } = re();
2540
+ gs();
2541
+ const { onCreateSuccess: Y } = Ra({
2542
+ onDashboardSelect: t
2543
+ }), {
2544
+ resources: j,
2545
+ isLoading: ee,
2546
+ isError: D,
2547
+ createResource: U,
2548
+ updateResource: z,
2549
+ deleteResource: K,
2550
+ duplicateResource: ie,
2551
+ isCreating: se,
2552
+ isDeleting: W,
2553
+ refetch: Te
2554
+ } = Ga(
2555
+ () => {
2556
+ y(!1);
2557
+ const g = v == null ? void 0 : v.id;
2558
+ S(null), (V == null ? void 0 : V.id) === g && (!(k != null && k.dashboard_id) && !E ? M() : C && C.id !== g && T(C));
2559
+ },
2560
+ (g) => {
2561
+ m(!1), Y(g, Te);
2562
+ }
2563
+ ), { currentUser: H, userContext: ue } = Ae(), me = ((Ve = ue == null ? void 0 : ue.permissions) == null ? void 0 : Ve.canCreateDashboard) ?? !1, J = j.filter(
2564
+ (g) => {
2565
+ var q, h;
2566
+ return ((q = g == null ? void 0 : g.title) == null ? void 0 : q.toLowerCase().includes(r.toLowerCase())) || ((h = g == null ? void 0 : g.description) == null ? void 0 : h.toLowerCase().includes(r.toLowerCase()));
2567
+ }
2568
+ ), ve = (g) => new Date(g).toLocaleDateString("en-US", {
2569
+ month: "short",
2570
+ day: "numeric",
2571
+ year: "numeric"
2572
+ }), Oe = (g) => {
2573
+ U({
2574
+ title: g.title,
2575
+ description: g.description,
2576
+ isPrivate: !1
2577
+ });
2578
+ }, pe = (g) => {
2579
+ i == null || i(g);
2580
+ }, fe = (g) => {
2581
+ S(g), y(!0);
2582
+ }, b = () => {
2583
+ v && K(v.id);
2584
+ }, B = (g) => {
2585
+ L(g), ie(g, {
2586
+ onSettled: () => L(null)
2587
+ });
2588
+ }, {
2589
+ startUpdating: F,
2590
+ stopUpdating: oe,
2591
+ isUpdating: Ne
2592
+ } = zs(), ge = (g, q, h) => {
2593
+ var xs;
2594
+ const _ = Object.fromEntries(
2595
+ Object.entries(q).filter(([, be]) => be !== void 0)
2596
+ );
2597
+ if (Object.keys(_).length === 0) {
2598
+ (xs = h == null ? void 0 : h.onSuccess) == null || xs.call(h);
2599
+ return;
2600
+ }
2601
+ const ce = Object.keys(_), Xe = ce.length === 1 ? ce[0] : void 0;
2602
+ F(g, Xe), z(
2603
+ {
2604
+ resourceId: g,
2605
+ data: _
2606
+ },
2607
+ {
2608
+ onSuccess: () => {
2609
+ var be;
2610
+ oe(g, Xe), (be = h == null ? void 0 : h.onSuccess) == null || be.call(h);
2611
+ },
2612
+ onError: () => {
2613
+ var be;
2614
+ oe(g, Xe), (be = h == null ? void 0 : h.onError) == null || be.call(h);
2615
+ }
2616
+ }
2617
+ );
2618
+ }, xe = (g) => {
2619
+ const q = j.find(
2620
+ (h) => h.id === g
2621
+ );
2622
+ q && z({
2623
+ resourceId: g,
2624
+ data: {
2625
+ isPrivate: !q.isPrivate
2626
+ }
2627
+ });
2628
+ }, $ = (g) => {
2629
+ l(g), H == null || H.type, f(!0);
2630
+ }, Ns = (g) => {
2631
+ n == null || n(g.id), O(g);
2632
+ }, We = () => {
2633
+ O(null);
2634
+ }, Je = ({
2635
+ title: g,
2636
+ description: q
2637
+ }) => {
2638
+ if (!w)
2639
+ return;
2640
+ const h = {};
2641
+ g !== w.title && (h.title = g), (w.description || "") !== q && (h.description = q), ge(w.id, h, {
2642
+ onSuccess: () => {
2643
+ O(null);
2644
+ }
2645
+ });
2646
+ };
2647
+ return ee ? /* @__PURE__ */ e(js, {}) : D ? /* @__PURE__ */ e(cn, { onRetry: () => window.location.reload() }) : /* @__PURE__ */ s("div", { className: "relative flex h-full flex-1 flex-col gap-4", children: [
2648
+ j && j.length > 5 && /* @__PURE__ */ e("div", { className: "space-y-2", children: /* @__PURE__ */ e(
2649
+ ze,
2650
+ {
2651
+ id: "search",
2652
+ placeholder: "Search by title or description...",
2653
+ value: r,
2654
+ onChange: (g) => c(g.target.value),
2655
+ className: "h-9"
2656
+ }
2657
+ ) }),
2658
+ /* @__PURE__ */ e("div", { className: "flex flex-1 flex-col", children: /* @__PURE__ */ e("div", { className: "flex flex-1 basis-0 flex-col gap-3 overflow-y-auto", children: J.length === 0 ? /* @__PURE__ */ s("div", { className: "py-8 text-center", children: [
2659
+ /* @__PURE__ */ e("div", { className: "mb-3", children: /* @__PURE__ */ e(ja, { className: "mx-auto h-12 w-12 text-muted-foreground/50" }) }),
2660
+ /* @__PURE__ */ e("h3", { className: "mb-1 font-medium text-foreground", children: r ? "No dashboards found" : "No dashboards yet" }),
2661
+ /* @__PURE__ */ e("p", { className: "mb-4 text-sm text-muted-foreground", children: r ? "Try adjusting your search" : me ? "Create your first dashboard to get started" : "No dashboards have been shared with you yet" }),
2662
+ me && !r && /* @__PURE__ */ s(
2663
+ I,
2664
+ {
2665
+ size: "sm",
2666
+ className: "bg-primary hover:bg-primary/90",
2667
+ onClick: () => m(!0),
2668
+ children: [
2669
+ /* @__PURE__ */ e(le, { className: "mr-2 h-4 w-4" }),
2670
+ "Create Dashboard"
2671
+ ]
2672
+ }
2673
+ )
2674
+ ] }) : J.map((g) => /* @__PURE__ */ e(
2675
+ on,
2676
+ {
2677
+ dashboard: g,
2678
+ isDeleting: W,
2679
+ isDuplicating: P === g.id,
2680
+ onLoadDashboard: pe,
2681
+ onEditDetails: Ns,
2682
+ onDeleteClick: fe,
2683
+ onDuplicateDashboard: B,
2684
+ onTogglePrivacy: xe,
2685
+ onShareDashboard: $,
2686
+ formatDate: ve,
2687
+ onDashboardItemClick: t
2688
+ },
2689
+ g.id
2690
+ )) }) }),
2691
+ d && p && /* @__PURE__ */ e(
2692
+ bs,
2693
+ {
2694
+ resource: p,
2695
+ resourceType: Ue.DASHBOARD,
2696
+ onClose: () => {
2697
+ f(!1), l(null);
2698
+ }
2699
+ }
2700
+ ),
2701
+ /* @__PURE__ */ e(
2702
+ os,
2703
+ {
2704
+ open: u,
2705
+ onOpenChange: (g) => {
2706
+ !g && W || (y(g), g || S(null));
2707
+ },
2708
+ children: /* @__PURE__ */ s(cs, { children: [
2709
+ /* @__PURE__ */ s(ds, { children: [
2710
+ /* @__PURE__ */ e(hs, { children: "Delete Dashboard" }),
2711
+ /* @__PURE__ */ s(us, { children: [
2712
+ 'Are you sure you want to delete "',
2713
+ v == null ? void 0 : v.title,
2714
+ '"? This action cannot be undone.'
2715
+ ] })
2716
+ ] }),
2717
+ /* @__PURE__ */ s(ms, { children: [
2718
+ /* @__PURE__ */ e(ps, { disabled: W, children: "Cancel" }),
2719
+ /* @__PURE__ */ s(
2720
+ fs,
2721
+ {
2722
+ onClick: (g) => {
2723
+ g.preventDefault(), g.stopPropagation(), b();
2724
+ },
2725
+ className: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
2726
+ disabled: W,
2727
+ children: [
2728
+ W ? /* @__PURE__ */ e(Z, { className: "mr-2 h-3.5 w-3.5 animate-spin" }) : /* @__PURE__ */ e(je, { className: "mr-2 h-3.5 w-3.5" }),
2729
+ W ? "Deleting..." : "Delete"
2730
+ ]
2731
+ }
2732
+ )
2733
+ ] })
2734
+ ] })
2735
+ }
2736
+ ),
2737
+ w && /* @__PURE__ */ e(
2738
+ Rs,
2739
+ {
2740
+ open: !!w,
2741
+ resourceLabel: "Dashboard",
2742
+ initialTitle: w.title || "",
2743
+ initialDescription: w.description || "",
2744
+ onClose: We,
2745
+ onSave: Je,
2746
+ isSaving: Ne(w.id)
2747
+ }
2748
+ ),
2749
+ /* @__PURE__ */ e(
2750
+ _a,
2751
+ {
2752
+ open: o,
2753
+ onOpenChange: m,
2754
+ onSubmit: Oe,
2755
+ isCreating: se
2756
+ }
2757
+ ),
2758
+ me && /* @__PURE__ */ e(
2759
+ I,
2760
+ {
2761
+ size: "icon",
2762
+ className: "absolute bottom-2 left-2 h-11 w-11 rounded-full shadow-lg shadow-black/15",
2763
+ onClick: () => m(!0),
2764
+ "aria-label": "Create dashboard",
2765
+ children: /* @__PURE__ */ e(le, { className: "h-5 w-5" })
2766
+ }
2767
+ )
2768
+ ] });
2769
+ }
2770
+ function hn({
2771
+ isOpen: a,
2772
+ onClose: i,
2773
+ className: n,
2774
+ onDashboardItemClick: t,
2775
+ variant: r = "inline"
2776
+ }) {
2777
+ N((T) => T.dashboard);
2778
+ const c = N((T) => T.isDashboardEditing), { setDashboard: o, addSheet: m } = N(
2779
+ (T) => T.actions
2780
+ ), {
2781
+ currentUser: d
2782
+ } = Ae(), f = d, { permissions: p } = gs(), u = Ba() && p.canAccessVisuals && c, y = "dashboards", [v, S] = pt(
2783
+ "resource-management-active-tab",
2784
+ y
2785
+ ), P = u ? v : "dashboards", L = r === "overlay", w = ft(i, {
2786
+ enabled: a && L
2787
+ }), O = G(
2788
+ "flex h-full flex-col border-r bg-background",
2789
+ L ? G(
2790
+ "absolute inset-y-0 left-0 z-[51] w-96 shadow-lg transition-transform duration-300 ease-in-out",
2791
+ a ? "translate-x-0" : "pointer-events-none -translate-x-full"
2792
+ ) : "w-full max-w-[28rem] min-w-[18rem] overflow-hidden shadow-sm",
2793
+ n
2794
+ ), C = (T) => {
2795
+ }, V = (T) => {
2796
+ console.log("Editing dashboard:", T);
2797
+ };
2798
+ return /* @__PURE__ */ e(qa, { children: (!L || a) && /* @__PURE__ */ s("div", { ref: w, className: O, children: [
2799
+ /* @__PURE__ */ s("div", { className: "flex items-center justify-between border-b border-border p-4", children: [
2800
+ /* @__PURE__ */ e("div", { className: "flex items-center gap-2", children: f && /* @__PURE__ */ s(R, { children: [
2801
+ /* @__PURE__ */ s(Qa, { children: [
2802
+ /* @__PURE__ */ e(Ha, { asChild: !0, children: /* @__PURE__ */ e("div", { className: "flex h-8 w-8 cursor-default items-center justify-center rounded-full bg-primary/10", children: /* @__PURE__ */ e("span", { className: "text-sm font-medium text-primary", children: f.name.charAt(0).toUpperCase() }) }) }),
2803
+ /* @__PURE__ */ e($a, { side: "bottom", className: "ml-2 max-w-xs", children: /* @__PURE__ */ s("div", { className: "space-y-1", children: [
2804
+ /* @__PURE__ */ e("div", { className: "font-medium", children: f.name }),
2805
+ /* @__PURE__ */ e("div", { className: "text-xs text-muted-foreground", children: f.email }),
2806
+ f.role && /* @__PURE__ */ s("div", { className: "text-xs text-muted-foreground", children: [
2807
+ "Role:",
2808
+ " ",
2809
+ Ka(
2810
+ f.role.replace(/_/g, " ")
2811
+ )
2812
+ ] }),
2813
+ /* @__PURE__ */ s("div", { className: "text-xs text-muted-foreground", children: [
2814
+ "ID: ",
2815
+ f.id
2816
+ ] })
2817
+ ] }) })
2818
+ ] }),
2819
+ /* @__PURE__ */ e("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ e("span", { className: "text-sm font-medium text-foreground", children: f.name }) })
2820
+ ] }) }),
2821
+ /* @__PURE__ */ e(
2822
+ de,
2823
+ {
2824
+ className: "h-8 w-8 p-0 text-muted-foreground hover:text-foreground",
2825
+ onClick: i,
2826
+ tooltip: "Close Sidebar",
2827
+ children: /* @__PURE__ */ e(yt, { className: "h-4 w-4" })
2828
+ }
2829
+ )
2830
+ ] }),
2831
+ /* @__PURE__ */ e("div", { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ s(
2832
+ is,
2833
+ {
2834
+ value: P,
2835
+ onValueChange: u ? S : void 0,
2836
+ className: "flex h-9 grow flex-col",
2837
+ children: [
2838
+ u && /* @__PURE__ */ e("div", { className: "px-4 pt-4", children: /* @__PURE__ */ s(ls, { className: "grid w-full grid-cols-2", children: [
2839
+ /* @__PURE__ */ e(Se, { value: "dashboards", className: "text-sm", children: "Dashboards" }),
2840
+ /* @__PURE__ */ e(Se, { value: "visuals", className: "text-sm", children: "Visuals" })
2841
+ ] }) }),
2842
+ /* @__PURE__ */ e(Pe, { value: "dashboards", className: "flex-1 px-4 py-4", children: /* @__PURE__ */ e(
2843
+ dn,
2844
+ {
2845
+ onLoadDashboard: C,
2846
+ onEditDashboard: V,
2847
+ onDashboardItemClick: t
2848
+ }
2849
+ ) }),
2850
+ u && /* @__PURE__ */ e(Pe, { value: "visuals", className: "flex-1 px-4 py-4", children: /* @__PURE__ */ e(ln, {}) })
2851
+ ]
2852
+ }
2853
+ ) })
2854
+ ] }) });
2855
+ }
2856
+ function bn({
2857
+ showControls: a = !1,
2858
+ showFooter: i = !0,
2859
+ ...n
2860
+ }) {
2861
+ const t = N(
2862
+ (u) => u.isDashboardPanelOpen
2863
+ );
2864
+ N((u) => u.isVisualEditing);
2865
+ const r = N(
2866
+ (u) => u.actions.setIsDashboardPanelOpen
2867
+ ), c = 20, o = 20, m = 30, d = t, f = Is(null), p = Is(null);
2868
+ Me(() => {
2869
+ f.current && p.current && (t ? (f.current.resize(c), p.current.resize(100 - c)) : (f.current.resize(0), p.current.resize(100)));
2870
+ }, [t]);
2871
+ const { preferences: l } = n;
2872
+ return /* @__PURE__ */ e(Wa, { FallbackComponent: Ja, children: /* @__PURE__ */ s(Xa, { dashboardProps: n, children: [
2873
+ /* @__PURE__ */ e(Za, {}),
2874
+ /* @__PURE__ */ e(Ya, { children: /* @__PURE__ */ s(et, { preferences: l, children: [
2875
+ /* @__PURE__ */ e(st, {}),
2876
+ /* @__PURE__ */ s("main", { className: "relative flex h-full w-full flex-col", children: [
2877
+ a && /* @__PURE__ */ e(Zt, {}),
2878
+ /* @__PURE__ */ s(
2879
+ at,
2880
+ {
2881
+ direction: "horizontal",
2882
+ className: "flex grow overflow-hidden",
2883
+ children: [
2884
+ /* @__PURE__ */ e(
2885
+ Ps,
2886
+ {
2887
+ ref: f,
2888
+ className: G("flex h-full max-w-[26rem] overflow-hidden", {
2889
+ "min-w-[20rem]": d
2890
+ }),
2891
+ defaultSize: d ? c : 0,
2892
+ minSize: d ? o : 0,
2893
+ maxSize: d ? m : 0,
2894
+ children: /* @__PURE__ */ e(
2895
+ hn,
2896
+ {
2897
+ isOpen: t,
2898
+ onClose: () => r(!1),
2899
+ variant: "inline"
2900
+ }
2901
+ )
2902
+ }
2903
+ ),
2904
+ /* @__PURE__ */ e(
2905
+ tt,
2906
+ {
2907
+ className: G("", {
2908
+ "w-0": !d
2909
+ })
2910
+ }
2911
+ ),
2912
+ /* @__PURE__ */ e(
2913
+ Ps,
2914
+ {
2915
+ ref: p,
2916
+ className: "flex min-w-0 flex-1",
2917
+ defaultSize: d ? 100 - c : 100,
2918
+ minSize: d ? 40 : 100,
2919
+ children: /* @__PURE__ */ s(nt, { ...n, type: "dashboard", children: [
2920
+ /* @__PURE__ */ e(rt, {}),
2921
+ /* @__PURE__ */ e(an, {})
2922
+ ] })
2923
+ }
2924
+ )
2925
+ ]
2926
+ }
2927
+ )
2928
+ ] })
2929
+ ] }) })
2930
+ ] }) });
2931
+ }
2932
+ export {
2933
+ Xt as A,
2934
+ bn as D,
2935
+ hn as R,
2936
+ Lt as S,
2937
+ Jt as V,
2938
+ At as a,
2939
+ St as c,
2940
+ as as g
2941
+ };