react-semaphor 0.1.260 → 0.1.261

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 (46) hide show
  1. package/dist/chunks/dashboard-controls-0hbftZxY.js +42 -0
  2. package/dist/chunks/dashboard-controls-BYi_r2lH.js +1971 -0
  3. package/dist/chunks/dashboard-filter-controls-button-BPCw1GMh.js +1066 -0
  4. package/dist/chunks/dashboard-filter-controls-button-f4pDkDUL.js +11 -0
  5. package/dist/chunks/{dashboard-json-U7VmojaR.js → dashboard-json-2NJCXsDD.js} +1 -1
  6. package/dist/chunks/{dashboard-json-BUrApiYl.js → dashboard-json-Dpy-zKf2.js} +1 -1
  7. package/dist/chunks/{dashboard-summary-settings-dialog-DlVBUQmC.js → dashboard-summary-settings-dialog-B9zRCvc-.js} +1 -1
  8. package/dist/chunks/{dashboard-summary-settings-dialog-CaxmCNyy.js → dashboard-summary-settings-dialog-Be3JilRI.js} +1 -1
  9. package/dist/chunks/edit-dashboard-visual-Bon08erH.js +188 -0
  10. package/dist/chunks/{edit-dashboard-visual-N2r5ObJ_.js → edit-dashboard-visual-CqTlmuYL.js} +5970 -5492
  11. package/dist/chunks/index-BoJEr_9F.js +1114 -0
  12. package/dist/chunks/{index-BNdZjo5d.js → index-C2c-_lPE.js} +48333 -44824
  13. package/dist/chunks/{normalize-dashboard-for-dirty-check-Bn27S0PN.js → normalize-dashboard-for-dirty-check-5KpZN8xr.js} +20 -19
  14. package/dist/chunks/normalize-dashboard-for-dirty-check-BXRUMVb2.js +1 -0
  15. package/dist/chunks/{resource-management-panel-C_ZqsVMH.js → resource-management-panel-BtLPW2b4.js} +1 -1
  16. package/dist/chunks/{resource-management-panel-zF23gLOJ.js → resource-management-panel-Bva2_0OU.js} +70 -70
  17. package/dist/chunks/use-create-flow-overlay-state-9X7GyUzl.js +21 -0
  18. package/dist/chunks/use-create-flow-overlay-state-Vyd5mSnf.js +1445 -0
  19. package/dist/chunks/{use-visual-utils-BBTQGDdB.js → use-visual-utils-Jv4hWSLm.js} +1 -1
  20. package/dist/chunks/{use-visual-utils-K1k39w2U.js → use-visual-utils-OPk_1t4I.js} +1 -1
  21. package/dist/dashboard/index.cjs +1 -1
  22. package/dist/dashboard/index.js +5 -4
  23. package/dist/index.cjs +1 -1
  24. package/dist/index.js +102 -99
  25. package/dist/shared/index.cjs +1 -1
  26. package/dist/shared/index.js +1 -1
  27. package/dist/style.css +1 -1
  28. package/dist/surfboard/index.cjs +1 -1
  29. package/dist/surfboard/index.js +5 -4
  30. package/dist/types/dashboard.d.ts +105 -0
  31. package/dist/types/index.cjs +1 -1
  32. package/dist/types/index.js +4 -3
  33. package/dist/types/main.d.ts +175 -1
  34. package/dist/types/shared.d.ts +89 -0
  35. package/dist/types/surfboard.d.ts +105 -0
  36. package/dist/types/types.d.ts +113 -0
  37. package/package.json +1 -1
  38. package/dist/chunks/dashboard-controls-CIdYp98a.js +0 -47
  39. package/dist/chunks/dashboard-controls-DOqBYrkB.js +0 -1847
  40. package/dist/chunks/edit-dashboard-visual-uA-0wLnR.js +0 -193
  41. package/dist/chunks/editor-action-buttons-B6lABkRB.js +0 -412
  42. package/dist/chunks/editor-action-buttons-Dh7Xndgk.js +0 -21
  43. package/dist/chunks/index-DOeggx0V.js +0 -1109
  44. package/dist/chunks/normalize-dashboard-for-dirty-check-B7NQDI1H.js +0 -1
  45. package/dist/chunks/notification-bell-BxyeaeRc.js +0 -839
  46. package/dist/chunks/notification-bell-tJRds5JJ.js +0 -6
@@ -0,0 +1,1971 @@
1
+ import { jsxs as o, jsx as e, Fragment as k } from "react/jsx-runtime";
2
+ import { bL as de, dn as Fs, u as x, cy as ta, cz as ra, B as M, cB as na, cC as K, dp as oa, N as Va, b as F, e as ia, dq as $s, cp as la, f as ca, g as da, h as ua, i as qa, L as Ke, I as ce, v as Vs, a6 as B, dr as De, cG as Qe, ds as qs, dt as _a, du as Ha, c as X, dv as ja, dw as Hs, cX as ma, dx as js, dy as zs, dz as Bs, dA as Ks, dB as Qs, dC as Ws, H as Ae, V as Me, x as L, dD as za, d5 as Js, dE as Xs, w as Y, cF as W, dF as Ys, dG as Zs, dH as We, dI as et, dJ as at, dK as Ba, dL as Ka, dM as Ce, dN as Ee, d1 as Je, cL as Xe, dO as Ye, cc as Qa, dP as Ze, c7 as Wa, dQ as st, cO as Ja, cP as Xa, cQ as Ya, cR as Za, cS as es, cT as as, cU as ss, cV as ea, dR as ts, cx as tt, dS as rt, af as nt, U as Pa, ae as we, dT as ot, al as it, ag as He, dU as lt, dV as ct, dW as dt, aA as ut, dX as mt, dY as ht, bS as pt, bT as ft, bU as gt, dZ as vt, bV as bt, cD as yt, as as Nt, d_ as St, d$ as xt, dm as wt, e0 as Dt, e1 as Ct, cA as Et, a8 as At, cI as Mt, e2 as Lt, ak as kt, a9 as It, ar as Ot, e3 as Tt } from "./index-C2c-_lPE.js";
3
+ import * as A from "react";
4
+ import rs, { useState as N, useMemo as Q, useCallback as Ua, useEffect as _t } from "react";
5
+ import "react-dom";
6
+ import { b as Pt, u as Ut, d as Gt, A as Rt, V as Ft, N as $t, c as Vt, D as qt, U as Ht } from "./dashboard-filter-controls-button-BPCw1GMh.js";
7
+ import { l as jt } from "./date-formatter-vkCj9Ct-.js";
8
+ import { C as zt, D as Bt } from "./dashboard-summary-settings-dialog-B9zRCvc-.js";
9
+ import { u as Kt } from "./use-debounced-dirty-check-BwAbnX_5.js";
10
+ import { s as je } from "./normalize-dashboard-for-dirty-check-5KpZN8xr.js";
11
+ import { S as Ga } from "./use-create-flow-overlay-state-Vyd5mSnf.js";
12
+ /**
13
+ * @license lucide-react v0.453.0 - ISC
14
+ *
15
+ * This source code is licensed under the ISC license.
16
+ * See the LICENSE file in the root directory of this source tree.
17
+ */
18
+ const Qt = de("Glasses", [
19
+ ["circle", { cx: "6", cy: "15", r: "4", key: "vux9w4" }],
20
+ ["circle", { cx: "18", cy: "15", r: "4", key: "18o8ve" }],
21
+ ["path", { d: "M14 15a2 2 0 0 0-2-2 2 2 0 0 0-2 2", key: "1ag4bs" }],
22
+ ["path", { d: "M2.5 13 5 7c.7-1.3 1.4-2 3-2", key: "1hm1gs" }],
23
+ ["path", { d: "M21.5 13 19 7c-.7-1.3-1.5-2-3-2", key: "1r31ai" }]
24
+ ]);
25
+ /**
26
+ * @license lucide-react v0.453.0 - ISC
27
+ *
28
+ * This source code is licensed under the ISC license.
29
+ * See the LICENSE file in the root directory of this source tree.
30
+ */
31
+ const Wt = de("Menu", [
32
+ ["line", { x1: "4", x2: "20", y1: "12", y2: "12", key: "1e0a9i" }],
33
+ ["line", { x1: "4", x2: "20", y1: "6", y2: "6", key: "1owob3" }],
34
+ ["line", { x1: "4", x2: "20", y1: "18", y2: "18", key: "yk5zj1" }]
35
+ ]);
36
+ /**
37
+ * @license lucide-react v0.453.0 - ISC
38
+ *
39
+ * This source code is licensed under the ISC license.
40
+ * See the LICENSE file in the root directory of this source tree.
41
+ */
42
+ const Jt = de("Moon", [
43
+ ["path", { d: "M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z", key: "a7tn18" }]
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 Xt = de("ShieldX", [
52
+ [
53
+ "path",
54
+ {
55
+ 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",
56
+ key: "oel41y"
57
+ }
58
+ ],
59
+ ["path", { d: "m14.5 9.5-5 5", key: "17q4r4" }],
60
+ ["path", { d: "m9.5 9.5 5 5", key: "18nt4w" }]
61
+ ]);
62
+ /**
63
+ * @license lucide-react v0.453.0 - ISC
64
+ *
65
+ * This source code is licensed under the ISC license.
66
+ * See the LICENSE file in the root directory of this source tree.
67
+ */
68
+ const Yt = de("Sun", [
69
+ ["circle", { cx: "12", cy: "12", r: "4", key: "4exip2" }],
70
+ ["path", { d: "M12 2v2", key: "tus03m" }],
71
+ ["path", { d: "M12 20v2", key: "1lh1kg" }],
72
+ ["path", { d: "m4.93 4.93 1.41 1.41", key: "149t6j" }],
73
+ ["path", { d: "m17.66 17.66 1.41 1.41", key: "ptbguv" }],
74
+ ["path", { d: "M2 12h2", key: "1t8f8n" }],
75
+ ["path", { d: "M20 12h2", key: "1q8mjw" }],
76
+ ["path", { d: "m6.34 17.66-1.41 1.41", key: "1m8zz5" }],
77
+ ["path", { d: "m19.07 4.93-1.41 1.41", key: "1shlcs" }]
78
+ ]);
79
+ var aa = { exports: {} }, ze = {};
80
+ /**
81
+ * @license React
82
+ * use-sync-external-store-shim.production.js
83
+ *
84
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
85
+ *
86
+ * This source code is licensed under the MIT license found in the
87
+ * LICENSE file in the root directory of this source tree.
88
+ */
89
+ var Ra;
90
+ function Zt() {
91
+ if (Ra) return ze;
92
+ Ra = 1;
93
+ var a = rs;
94
+ function n(s, d) {
95
+ return s === d && (s !== 0 || 1 / s === 1 / d) || s !== s && d !== d;
96
+ }
97
+ var t = typeof Object.is == "function" ? Object.is : n, r = a.useState, i = a.useEffect, c = a.useLayoutEffect, u = a.useDebugValue;
98
+ function m(s, d) {
99
+ var f = d(), v = r({ inst: { value: f, getSnapshot: d } }), b = v[0].inst, S = v[1];
100
+ return c(
101
+ function() {
102
+ b.value = f, b.getSnapshot = d, p(b) && S({ inst: b });
103
+ },
104
+ [s, f, d]
105
+ ), i(
106
+ function() {
107
+ return p(b) && S({ inst: b }), s(function() {
108
+ p(b) && S({ inst: b });
109
+ });
110
+ },
111
+ [s]
112
+ ), u(f), f;
113
+ }
114
+ function p(s) {
115
+ var d = s.getSnapshot;
116
+ s = s.value;
117
+ try {
118
+ var f = d();
119
+ return !t(s, f);
120
+ } catch {
121
+ return !0;
122
+ }
123
+ }
124
+ function y(s, d) {
125
+ return d();
126
+ }
127
+ var h = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? y : m;
128
+ return ze.useSyncExternalStore = a.useSyncExternalStore !== void 0 ? a.useSyncExternalStore : h, ze;
129
+ }
130
+ var Be = {};
131
+ /**
132
+ * @license React
133
+ * use-sync-external-store-shim.development.js
134
+ *
135
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
136
+ *
137
+ * This source code is licensed under the MIT license found in the
138
+ * LICENSE file in the root directory of this source tree.
139
+ */
140
+ var Fa;
141
+ function er() {
142
+ return Fa || (Fa = 1, process.env.NODE_ENV !== "production" && function() {
143
+ function a(f, v) {
144
+ return f === v && (f !== 0 || 1 / f === 1 / v) || f !== f && v !== v;
145
+ }
146
+ function n(f, v) {
147
+ h || i.startTransition === void 0 || (h = !0, console.error(
148
+ "You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."
149
+ ));
150
+ var b = v();
151
+ if (!s) {
152
+ var S = v();
153
+ c(b, S) || (console.error(
154
+ "The result of getSnapshot should be cached to avoid an infinite loop"
155
+ ), s = !0);
156
+ }
157
+ S = u({
158
+ inst: { value: b, getSnapshot: v }
159
+ });
160
+ var C = S[0].inst, P = S[1];
161
+ return p(
162
+ function() {
163
+ C.value = b, C.getSnapshot = v, t(C) && P({ inst: C });
164
+ },
165
+ [f, b, v]
166
+ ), m(
167
+ function() {
168
+ return t(C) && P({ inst: C }), f(function() {
169
+ t(C) && P({ inst: C });
170
+ });
171
+ },
172
+ [f]
173
+ ), y(b), b;
174
+ }
175
+ function t(f) {
176
+ var v = f.getSnapshot;
177
+ f = f.value;
178
+ try {
179
+ var b = v();
180
+ return !c(f, b);
181
+ } catch {
182
+ return !0;
183
+ }
184
+ }
185
+ function r(f, v) {
186
+ return v();
187
+ }
188
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
189
+ var i = rs, c = typeof Object.is == "function" ? Object.is : a, u = i.useState, m = i.useEffect, p = i.useLayoutEffect, y = i.useDebugValue, h = !1, s = !1, d = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? r : n;
190
+ Be.useSyncExternalStore = i.useSyncExternalStore !== void 0 ? i.useSyncExternalStore : d, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
191
+ }()), Be;
192
+ }
193
+ process.env.NODE_ENV === "production" ? aa.exports = Zt() : aa.exports = er();
194
+ var ar = aa.exports;
195
+ function sr() {
196
+ const { setTheme: a } = Fs(), n = x(
197
+ (t) => t.actions.setDashboardTheme
198
+ );
199
+ return /* @__PURE__ */ o(ta, { children: [
200
+ /* @__PURE__ */ e(ra, { asChild: !0, children: /* @__PURE__ */ o(M, { className: "h-7 p-2", variant: "ghost", size: "sm", children: [
201
+ /* @__PURE__ */ e(
202
+ Yt,
203
+ {
204
+ strokeWidth: 1.5,
205
+ className: "h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0"
206
+ }
207
+ ),
208
+ /* @__PURE__ */ e(
209
+ Jt,
210
+ {
211
+ strokeWidth: 1.5,
212
+ className: "absolute h-4 w-4 rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100"
213
+ }
214
+ ),
215
+ /* @__PURE__ */ e("span", { className: "sr-only", children: "Toggle theme" })
216
+ ] }) }),
217
+ /* @__PURE__ */ o(na, { align: "end", children: [
218
+ /* @__PURE__ */ e(
219
+ K,
220
+ {
221
+ onClick: () => {
222
+ a("light"), n("light");
223
+ },
224
+ children: "Light"
225
+ }
226
+ ),
227
+ /* @__PURE__ */ e(
228
+ K,
229
+ {
230
+ onClick: () => {
231
+ a("dark"), n("dark");
232
+ },
233
+ children: "Dark"
234
+ }
235
+ ),
236
+ /* @__PURE__ */ e(
237
+ K,
238
+ {
239
+ onClick: () => {
240
+ a("system"), n("system");
241
+ },
242
+ children: "System"
243
+ }
244
+ )
245
+ ] })
246
+ ] });
247
+ }
248
+ async function tr(a, n, t, r, i) {
249
+ if (!i)
250
+ return null;
251
+ const c = JSON.stringify(t), u = `${a}/v1/lens`;
252
+ return await oa(u, i, {
253
+ name: n,
254
+ template: c,
255
+ filterValues: r,
256
+ operation: "create"
257
+ });
258
+ }
259
+ async function sa(a, n, t) {
260
+ if (!t)
261
+ return null;
262
+ const { id: r, template: i, filterValues: c, isDefault: u, shared: m } = n, p = `${a}/v1/lens`;
263
+ return await oa(p, t, {
264
+ lensId: r,
265
+ template: i,
266
+ filterValues: c,
267
+ isDefault: u,
268
+ shared: m,
269
+ operation: "update"
270
+ });
271
+ }
272
+ async function rr(a, n, t) {
273
+ if (!t)
274
+ return null;
275
+ const r = `${a}/v1/lens`;
276
+ return await oa(r, t, {
277
+ operation: "delete",
278
+ lensId: n
279
+ });
280
+ }
281
+ function nr() {
282
+ const [a, n] = N(""), [t, r] = N(!1), i = x((S) => S.lenses), { setLenses: c, setSelectedLensId: u } = Va(), [m, p] = N(!1), [y, h] = N(!1), s = x((S) => S.dashboard), d = x((S) => S.filterValues), { authToken: f, tokenProps: v } = F();
283
+ async function b() {
284
+ p(!0);
285
+ const S = await tr(
286
+ v.apiServiceUrl,
287
+ a,
288
+ s,
289
+ d,
290
+ f == null ? void 0 : f.accessToken
291
+ );
292
+ S && (c([...i || [], S]), u(S.id), h(!1)), p(!1);
293
+ }
294
+ return /* @__PURE__ */ o(ia, { open: y, onOpenChange: h, children: [
295
+ /* @__PURE__ */ e($s, { asChild: !0, children: /* @__PURE__ */ o(
296
+ M,
297
+ {
298
+ variant: "secondary",
299
+ className: "h-7 p-2",
300
+ size: "sm",
301
+ children: [
302
+ /* @__PURE__ */ e(la, { className: "mr-2 h-4 w-4" }),
303
+ "Lens"
304
+ ]
305
+ }
306
+ ) }),
307
+ /* @__PURE__ */ o(ca, { className: "sm:max-w-[425px]", children: [
308
+ /* @__PURE__ */ o(da, { children: [
309
+ /* @__PURE__ */ e(ua, { children: "Create Lens" }),
310
+ /* @__PURE__ */ e(qa, { children: "Lenses are private by default and are only visible to you." })
311
+ ] }),
312
+ /* @__PURE__ */ e("div", { className: "grid gap-4 py-4", children: /* @__PURE__ */ o("div", { className: "grid grid-cols-8 items-center gap-4", children: [
313
+ /* @__PURE__ */ e(Ke, { className: "text-right", children: "Name" }),
314
+ /* @__PURE__ */ e(
315
+ ce,
316
+ {
317
+ value: a,
318
+ onChange: (S) => {
319
+ n(S.target.value);
320
+ },
321
+ id: "name",
322
+ className: "col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"
323
+ }
324
+ )
325
+ ] }) }),
326
+ t && /* @__PURE__ */ e("p", { className: "text-sm", children: "The lens name already exists. Use a differnet name." }),
327
+ /* @__PURE__ */ e(Vs, { children: /* @__PURE__ */ e(
328
+ M,
329
+ {
330
+ size: "sm",
331
+ variant: "outline",
332
+ type: "submit",
333
+ onClick: b,
334
+ disabled: m,
335
+ children: m ? "Creating..." : "Add"
336
+ }
337
+ ) })
338
+ ] })
339
+ ] });
340
+ }
341
+ function or() {
342
+ const [a, n] = N(!1), t = x((s) => s.lenses), r = x((s) => s.selectedLensId), { setLenses: i, setSelectedLensId: c } = Va(), { authToken: u, tokenProps: m } = F();
343
+ async function p(s) {
344
+ c(s);
345
+ }
346
+ async function y(s) {
347
+ if (await rr(m.apiServiceUrl, s, u == null ? void 0 : u.accessToken)) {
348
+ const f = t == null ? void 0 : t.filter((v) => v.id !== s);
349
+ i(f || []), c("original");
350
+ }
351
+ }
352
+ async function h(s) {
353
+ const d = t == null ? void 0 : t.map((b) => b.id === s.id ? {
354
+ ...b,
355
+ isDefault: !s.isDefault
356
+ } : {
357
+ ...b,
358
+ isDefault: !1
359
+ });
360
+ i(d || []);
361
+ const f = {
362
+ ...s,
363
+ isDefault: !s.isDefault
364
+ };
365
+ await sa(m.apiServiceUrl, f, u == null ? void 0 : u.accessToken);
366
+ const v = t == null ? void 0 : t.find((b) => b.isDefault);
367
+ if (v && v.id !== s.id) {
368
+ const b = {
369
+ ...v,
370
+ isDefault: !1
371
+ };
372
+ await sa(m.apiServiceUrl, b, u == null ? void 0 : u.accessToken);
373
+ }
374
+ }
375
+ return /* @__PURE__ */ o(ta, { open: a, onOpenChange: n, children: [
376
+ /* @__PURE__ */ e(ra, { asChild: !0, children: /* @__PURE__ */ e(B, { tooltip: "Lenses", className: "h-7 p-2", children: /* @__PURE__ */ e(Qt, { className: "h-4 w-4" }) }) }),
377
+ /* @__PURE__ */ o(na, { align: "end", className: "w-60", children: [
378
+ /* @__PURE__ */ e(De, { className: "px-3", children: "Lenses" }),
379
+ /* @__PURE__ */ e(Qe, {}),
380
+ /* @__PURE__ */ o(
381
+ qs,
382
+ {
383
+ value: r,
384
+ onValueChange: p,
385
+ children: [
386
+ /* @__PURE__ */ e(_a, { value: "original", children: "Original" }),
387
+ t == null ? void 0 : t.map((s) => /* @__PURE__ */ o(
388
+ _a,
389
+ {
390
+ className: "group flex justify-between gap-2",
391
+ value: s.id,
392
+ children: [
393
+ /* @__PURE__ */ e("p", { children: s.name }),
394
+ /* @__PURE__ */ o("span", { className: "flex items-center gap-3", children: [
395
+ /* @__PURE__ */ e(
396
+ Ha,
397
+ {
398
+ onClick: (d) => {
399
+ d.preventDefault(), h(s);
400
+ },
401
+ className: X(
402
+ "size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",
403
+ {
404
+ invisible: !s.isDefault,
405
+ "text-green-500": s.isDefault
406
+ }
407
+ ),
408
+ strokeWidth: 1.5
409
+ }
410
+ ),
411
+ /* @__PURE__ */ e(
412
+ ja,
413
+ {
414
+ onClick: (d) => {
415
+ d.preventDefault(), y(s.id);
416
+ },
417
+ className: "invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",
418
+ strokeWidth: 1.5
419
+ }
420
+ )
421
+ ] })
422
+ ]
423
+ },
424
+ s.id
425
+ ))
426
+ ]
427
+ }
428
+ )
429
+ ] })
430
+ ] });
431
+ }
432
+ function ir() {
433
+ const { displayPreferences: a, shouldShowElement: n } = Hs(), { currentUser: t, userContext: r } = ma(), i = Q(
434
+ () => js(t),
435
+ [t]
436
+ ), c = Q(() => (m) => i && i[m] !== void 0 && i[m] === !1 ? !1 : n(m), [i, n, a]), u = Q(
437
+ () => {
438
+ var m, p, y, h, s;
439
+ return {
440
+ canEdit: ((m = r == null ? void 0 : r.permissions) == null ? void 0 : m.canEdit) ?? Ws(t),
441
+ canUseFilters: ((p = r == null ? void 0 : r.permissions) == null ? void 0 : p.canEdit) ?? Qs(t),
442
+ canManageDashboards: ((y = r == null ? void 0 : r.permissions) == null ? void 0 : y.canCreateDashboard) ?? Ks(t),
443
+ canCreateDashboards: ((h = r == null ? void 0 : r.permissions) == null ? void 0 : h.canCreateDashboard) ?? Bs(t),
444
+ canAccessVisuals: ((s = r == null ? void 0 : r.permissions) == null ? void 0 : s.canEdit) ?? zs(t)
445
+ };
446
+ },
447
+ [t, r]
448
+ );
449
+ return {
450
+ displayPreferences: a,
451
+ shouldShowElement: c,
452
+ permissions: u,
453
+ currentUser: t
454
+ };
455
+ }
456
+ const lr = async (a, n, t) => {
457
+ const r = `${a}/management/v1/groups`;
458
+ return await za(r, n, t);
459
+ }, cr = async (a, n, t) => {
460
+ const r = `${a}/management/v1/groups/${t}`, i = await fetch(r, {
461
+ method: "DELETE",
462
+ headers: {
463
+ Authorization: `Bearer ${n}`
464
+ }
465
+ });
466
+ if (!i.ok) {
467
+ const c = await i.text();
468
+ throw new Error(c || "Failed to delete group");
469
+ }
470
+ }, dr = async (a, n, t, r) => {
471
+ const i = `${a}/management/v1/groups/${t}/members`;
472
+ return await za(i, n, r);
473
+ }, ur = async (a, n, t, r) => {
474
+ const i = `${a}/management/v1/groups/${t}/members`, c = await fetch(i, {
475
+ method: "DELETE",
476
+ headers: {
477
+ "Content-Type": "application/json",
478
+ Authorization: `Bearer ${n}`
479
+ },
480
+ body: JSON.stringify(r)
481
+ });
482
+ if (!c.ok) {
483
+ const u = await c.text();
484
+ throw new Error(u || "Failed to remove group members");
485
+ }
486
+ };
487
+ function mr() {
488
+ const { authToken: a, tokenProps: n } = F(), t = Ae();
489
+ return Me({
490
+ mutationFn: (r) => lr(n.apiServiceUrl, (a == null ? void 0 : a.accessToken) || "", r),
491
+ onSuccess: () => {
492
+ t.invalidateQueries({ queryKey: ["groups"] }), L.success("Group created successfully");
493
+ },
494
+ onError: (r) => {
495
+ console.error("Failed to create group:", r), L.error("Failed to create group", {
496
+ description: r.message
497
+ });
498
+ }
499
+ });
500
+ }
501
+ function hr() {
502
+ const { authToken: a, tokenProps: n } = F(), t = Ae();
503
+ return Me({
504
+ mutationFn: (r) => cr(n.apiServiceUrl, (a == null ? void 0 : a.accessToken) || "", r),
505
+ onSuccess: (r, i) => {
506
+ t.invalidateQueries({ queryKey: ["groups"] }), t.removeQueries({ queryKey: ["group", i] }), L.success("Group deleted successfully");
507
+ },
508
+ onError: (r) => {
509
+ console.error("Failed to delete group:", r), L.error("Failed to delete group", {
510
+ description: r.message
511
+ });
512
+ }
513
+ });
514
+ }
515
+ function pr() {
516
+ const { authToken: a, tokenProps: n } = F(), t = Ae();
517
+ return Me({
518
+ mutationFn: ({
519
+ groupId: r,
520
+ data: i
521
+ }) => dr(n.apiServiceUrl, (a == null ? void 0 : a.accessToken) || "", r, i),
522
+ onSuccess: (r, i) => {
523
+ t.invalidateQueries({ queryKey: ["group", i.groupId] }), t.invalidateQueries({
524
+ queryKey: ["group-members", i.groupId]
525
+ }), t.invalidateQueries({ queryKey: ["groups"] }), L.success("Members added successfully");
526
+ },
527
+ onError: (r) => {
528
+ console.error("Failed to add group members:", r), L.error("Failed to add members", {
529
+ description: r.message
530
+ });
531
+ }
532
+ });
533
+ }
534
+ function fr() {
535
+ const { authToken: a, tokenProps: n } = F(), t = Ae();
536
+ return Me({
537
+ mutationFn: ({
538
+ groupId: r,
539
+ data: i
540
+ }) => ur(n.apiServiceUrl, (a == null ? void 0 : a.accessToken) || "", r, i),
541
+ onSuccess: (r, i) => {
542
+ t.invalidateQueries({ queryKey: ["group", i.groupId] }), t.invalidateQueries({
543
+ queryKey: ["group-members", i.groupId]
544
+ }), t.invalidateQueries({ queryKey: ["groups"] }), L.success("Members removed successfully");
545
+ },
546
+ onError: (r) => {
547
+ console.error("Failed to remove group members:", r), L.error("Failed to remove members", {
548
+ description: r.message
549
+ });
550
+ }
551
+ });
552
+ }
553
+ function gr({
554
+ onSuccess: a,
555
+ tenantId: n,
556
+ isTenantUser: t
557
+ }) {
558
+ const [r, i] = N(""), [c, u] = N(""), [m, p] = N({}), y = mr(), h = () => {
559
+ const d = {};
560
+ return r.trim() ? r.length < 3 ? d.name = "Group name must be at least 3 characters" : r.length > 50 && (d.name = "Group name must be less than 50 characters") : d.name = "Group name is required", c && c.length > 200 && (d.description = "Description must be less than 200 characters"), p(d), Object.keys(d).length === 0;
561
+ };
562
+ return /* @__PURE__ */ o("form", { onSubmit: async (d) => {
563
+ if (d.preventDefault(), !h()) return;
564
+ const f = {
565
+ name: r.trim(),
566
+ description: c.trim() || void 0,
567
+ type: t ? "TENANT_GROUP" : "ORG_GROUP",
568
+ ...t && n ? { tenantId: n } : {}
569
+ };
570
+ try {
571
+ await y.mutateAsync(f), i(""), u(""), p({}), a();
572
+ } catch (v) {
573
+ console.error("Failed to create group:", v);
574
+ }
575
+ }, className: "space-y-6", children: [
576
+ /* @__PURE__ */ o("div", { className: "space-y-4", children: [
577
+ /* @__PURE__ */ o("div", { className: "space-y-2", children: [
578
+ /* @__PURE__ */ o(Ke, { htmlFor: "group-name", children: [
579
+ "Group Name ",
580
+ /* @__PURE__ */ e("span", { className: "text-destructive", children: "*" })
581
+ ] }),
582
+ /* @__PURE__ */ e(
583
+ ce,
584
+ {
585
+ id: "group-name",
586
+ placeholder: "e.g., Marketing Team, Engineering Squad",
587
+ value: r,
588
+ onChange: (d) => {
589
+ i(d.target.value), m.name && p((f) => ({ ...f, name: "" }));
590
+ },
591
+ className: m.name ? "border-destructive" : "",
592
+ disabled: y.isPending
593
+ }
594
+ ),
595
+ m.name && /* @__PURE__ */ e("p", { className: "text-sm text-destructive", children: m.name })
596
+ ] }),
597
+ /* @__PURE__ */ o("div", { className: "space-y-2", children: [
598
+ /* @__PURE__ */ o(Ke, { htmlFor: "group-description", children: [
599
+ "Description",
600
+ /* @__PURE__ */ e("span", { className: "ml-2 text-xs text-muted-foreground", children: "(optional)" })
601
+ ] }),
602
+ /* @__PURE__ */ e(
603
+ Js,
604
+ {
605
+ id: "group-description",
606
+ placeholder: "Describe the purpose of this group...",
607
+ value: c,
608
+ onChange: (d) => {
609
+ u(d.target.value), m.description && p((f) => ({ ...f, description: "" }));
610
+ },
611
+ className: m.description ? "border-destructive" : "",
612
+ disabled: y.isPending,
613
+ rows: 3
614
+ }
615
+ ),
616
+ m.description && /* @__PURE__ */ e("p", { className: "text-sm text-destructive", children: m.description }),
617
+ /* @__PURE__ */ o("p", { className: "text-xs text-muted-foreground", children: [
618
+ c.length,
619
+ "/200 characters"
620
+ ] })
621
+ ] }),
622
+ /* @__PURE__ */ e("div", { className: "rounded-lg border bg-muted/50 p-4", children: /* @__PURE__ */ o("div", { className: "flex gap-3", children: [
623
+ /* @__PURE__ */ e(Xs, { className: "h-4 w-4 mt-0.5 text-muted-foreground" }),
624
+ /* @__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." })
625
+ ] }) })
626
+ ] }),
627
+ /* @__PURE__ */ o("div", { className: "flex justify-end gap-3", children: [
628
+ /* @__PURE__ */ e(
629
+ M,
630
+ {
631
+ type: "button",
632
+ variant: "outline",
633
+ onClick: () => {
634
+ i(""), u(""), p({});
635
+ },
636
+ disabled: y.isPending,
637
+ children: "Clear"
638
+ }
639
+ ),
640
+ /* @__PURE__ */ e(
641
+ M,
642
+ {
643
+ type: "submit",
644
+ disabled: y.isPending || !r.trim(),
645
+ children: y.isPending ? /* @__PURE__ */ o(k, { children: [
646
+ /* @__PURE__ */ e(Y, { className: "mr-2 h-4 w-4 animate-spin" }),
647
+ "Creating..."
648
+ ] }) : /* @__PURE__ */ o(k, { children: [
649
+ /* @__PURE__ */ e(W, { className: "mr-2 h-4 w-4" }),
650
+ "Create Group"
651
+ ] })
652
+ }
653
+ )
654
+ ] })
655
+ ] });
656
+ }
657
+ function vr(a, n = []) {
658
+ let t = [];
659
+ function r(c, u) {
660
+ const m = A.createContext(u);
661
+ m.displayName = c + "Context";
662
+ const p = t.length;
663
+ t = [...t, u];
664
+ const y = (s) => {
665
+ var C;
666
+ const { scope: d, children: f, ...v } = s, b = ((C = d == null ? void 0 : d[a]) == null ? void 0 : C[p]) || m, S = A.useMemo(() => v, Object.values(v));
667
+ return /* @__PURE__ */ e(b.Provider, { value: S, children: f });
668
+ };
669
+ y.displayName = c + "Provider";
670
+ function h(s, d) {
671
+ var b;
672
+ const f = ((b = d == null ? void 0 : d[a]) == null ? void 0 : b[p]) || m, v = A.useContext(f);
673
+ if (v) return v;
674
+ if (u !== void 0) return u;
675
+ throw new Error(`\`${s}\` must be used within \`${c}\``);
676
+ }
677
+ return [y, h];
678
+ }
679
+ const i = () => {
680
+ const c = t.map((u) => A.createContext(u));
681
+ return function(m) {
682
+ const p = (m == null ? void 0 : m[a]) || c;
683
+ return A.useMemo(
684
+ () => ({ [`__scope${a}`]: { ...m, [a]: p } }),
685
+ [m, p]
686
+ );
687
+ };
688
+ };
689
+ return i.scopeName = a, [r, br(i, ...n)];
690
+ }
691
+ function br(...a) {
692
+ const n = a[0];
693
+ if (a.length === 1) return n;
694
+ const t = () => {
695
+ const r = a.map((i) => ({
696
+ useScope: i(),
697
+ scopeName: i.scopeName
698
+ }));
699
+ return function(c) {
700
+ const u = r.reduce((m, { useScope: p, scopeName: y }) => {
701
+ const s = p(c)[`__scope${y}`];
702
+ return { ...m, ...s };
703
+ }, {});
704
+ return A.useMemo(() => ({ [`__scope${n.scopeName}`]: u }), [u]);
705
+ };
706
+ };
707
+ return t.scopeName = n.scopeName, t;
708
+ }
709
+ var yr = [
710
+ "a",
711
+ "button",
712
+ "div",
713
+ "form",
714
+ "h2",
715
+ "h3",
716
+ "img",
717
+ "input",
718
+ "label",
719
+ "li",
720
+ "nav",
721
+ "ol",
722
+ "p",
723
+ "select",
724
+ "span",
725
+ "svg",
726
+ "ul"
727
+ ], ha = yr.reduce((a, n) => {
728
+ const t = Ys(`Primitive.${n}`), r = A.forwardRef((i, c) => {
729
+ const { asChild: u, ...m } = i, p = u ? t : n;
730
+ return typeof window < "u" && (window[Symbol.for("radix-ui")] = !0), /* @__PURE__ */ e(p, { ...m, ref: c });
731
+ });
732
+ return r.displayName = `Primitive.${n}`, { ...a, [n]: r };
733
+ }, {});
734
+ function Nr() {
735
+ return ar.useSyncExternalStore(
736
+ Sr,
737
+ () => !0,
738
+ () => !1
739
+ );
740
+ }
741
+ function Sr() {
742
+ return () => {
743
+ };
744
+ }
745
+ var pa = "Avatar", [xr] = vr(pa), [wr, ns] = xr(pa), os = A.forwardRef(
746
+ (a, n) => {
747
+ const { __scopeAvatar: t, ...r } = a, [i, c] = A.useState("idle");
748
+ return /* @__PURE__ */ e(
749
+ wr,
750
+ {
751
+ scope: t,
752
+ imageLoadingStatus: i,
753
+ onImageLoadingStatusChange: c,
754
+ children: /* @__PURE__ */ e(ha.span, { ...r, ref: n })
755
+ }
756
+ );
757
+ }
758
+ );
759
+ os.displayName = pa;
760
+ var is = "AvatarImage", ls = A.forwardRef(
761
+ (a, n) => {
762
+ const { __scopeAvatar: t, src: r, onLoadingStatusChange: i = () => {
763
+ }, ...c } = a, u = ns(is, t), m = Dr(r, c), p = Zs((y) => {
764
+ i(y), u.onImageLoadingStatusChange(y);
765
+ });
766
+ return We(() => {
767
+ m !== "idle" && p(m);
768
+ }, [m, p]), m === "loaded" ? /* @__PURE__ */ e(ha.img, { ...c, ref: n, src: r }) : null;
769
+ }
770
+ );
771
+ ls.displayName = is;
772
+ var cs = "AvatarFallback", ds = A.forwardRef(
773
+ (a, n) => {
774
+ const { __scopeAvatar: t, delayMs: r, ...i } = a, c = ns(cs, t), [u, m] = A.useState(r === void 0);
775
+ return A.useEffect(() => {
776
+ if (r !== void 0) {
777
+ const p = window.setTimeout(() => m(!0), r);
778
+ return () => window.clearTimeout(p);
779
+ }
780
+ }, [r]), u && c.imageLoadingStatus !== "loaded" ? /* @__PURE__ */ e(ha.span, { ...i, ref: n }) : null;
781
+ }
782
+ );
783
+ ds.displayName = cs;
784
+ function $a(a, n) {
785
+ return a ? n ? (a.src !== n && (a.src = n), a.complete && a.naturalWidth > 0 ? "loaded" : "loading") : "error" : "idle";
786
+ }
787
+ function Dr(a, { referrerPolicy: n, crossOrigin: t }) {
788
+ const r = Nr(), i = A.useRef(null), c = r ? (i.current || (i.current = new window.Image()), i.current) : null, [u, m] = A.useState(
789
+ () => $a(c, a)
790
+ );
791
+ return We(() => {
792
+ m($a(c, a));
793
+ }, [c, a]), We(() => {
794
+ const p = (s) => () => {
795
+ m(s);
796
+ };
797
+ if (!c) return;
798
+ const y = p("loaded"), h = p("error");
799
+ return c.addEventListener("load", y), c.addEventListener("error", h), n && (c.referrerPolicy = n), typeof t == "string" && (c.crossOrigin = t), () => {
800
+ c.removeEventListener("load", y), c.removeEventListener("error", h);
801
+ };
802
+ }, [c, t, n]), u;
803
+ }
804
+ var us = os, ms = ls, hs = ds;
805
+ const fa = A.forwardRef(({ className: a, ...n }, t) => /* @__PURE__ */ e(
806
+ us,
807
+ {
808
+ ref: t,
809
+ className: X(
810
+ "relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",
811
+ a
812
+ ),
813
+ ...n
814
+ }
815
+ ));
816
+ fa.displayName = us.displayName;
817
+ const Cr = A.forwardRef(({ className: a, ...n }, t) => /* @__PURE__ */ e(
818
+ ms,
819
+ {
820
+ ref: t,
821
+ className: X("aspect-square h-full w-full", a),
822
+ ...n
823
+ }
824
+ ));
825
+ Cr.displayName = ms.displayName;
826
+ const ga = A.forwardRef(({ className: a, ...n }, t) => /* @__PURE__ */ e(
827
+ hs,
828
+ {
829
+ ref: t,
830
+ className: X(
831
+ "flex h-full w-full items-center justify-center rounded-full bg-muted",
832
+ a
833
+ ),
834
+ ...n
835
+ }
836
+ ));
837
+ ga.displayName = hs.displayName;
838
+ function Er({
839
+ open: a,
840
+ onOpenChange: n,
841
+ group: t,
842
+ onUpdate: r
843
+ }) {
844
+ const [i, c] = N("members"), [u, m] = N(""), [p, y] = N([]), [h, s] = N([]), { data: d, isLoading: f, refetch: v } = et(t.id), b = t.type === "TENANT_GROUP" ? "tenant" : "organization", { users: S, isLoading: C } = at({
845
+ type: b,
846
+ tenantId: t.tenantId || void 0,
847
+ active: !0,
848
+ limit: 100
849
+ }), P = pr(), U = fr(), _ = (d == null ? void 0 : d.members) || [], $ = Q(() => new Set(_.map((g) => g.userId)), [_]), V = Q(() => S.filter((g) => !$.has(g.id)), [S, $]), q = Q(() => {
850
+ if (!u) return V;
851
+ const g = u.toLowerCase();
852
+ return V.filter(
853
+ (E) => {
854
+ var I, R;
855
+ return ((I = E.name) == null ? void 0 : I.toLowerCase().includes(g)) || ((R = E.email) == null ? void 0 : R.toLowerCase().includes(g));
856
+ }
857
+ );
858
+ }, [V, u]), w = Q(() => {
859
+ if (!u) return _;
860
+ const g = u.toLowerCase();
861
+ return _.filter(
862
+ (E) => {
863
+ var I, R, j, ee;
864
+ return ((R = (I = E.user) == null ? void 0 : I.name) == null ? void 0 : R.toLowerCase().includes(g)) || ((ee = (j = E.user) == null ? void 0 : j.email) == null ? void 0 : ee.toLowerCase().includes(g));
865
+ }
866
+ );
867
+ }, [_, u]), H = async () => {
868
+ if (p.length !== 0)
869
+ try {
870
+ await P.mutateAsync({
871
+ groupId: t.id,
872
+ data: {
873
+ userIds: p,
874
+ userType: b === "tenant" ? "tenant" : "org"
875
+ }
876
+ }), y([]), c("members"), v(), r == null || r();
877
+ } catch (g) {
878
+ console.error("Failed to add members:", g);
879
+ }
880
+ }, ue = async () => {
881
+ if (h.length !== 0)
882
+ try {
883
+ await U.mutateAsync({
884
+ groupId: t.id,
885
+ data: {
886
+ userIds: h
887
+ }
888
+ }), s([]), v(), r == null || r();
889
+ } catch (g) {
890
+ console.error("Failed to remove members:", g);
891
+ }
892
+ }, Z = (g) => {
893
+ y(
894
+ (E) => E.includes(g) ? E.filter((I) => I !== g) : [...E, g]
895
+ );
896
+ }, Le = (g) => {
897
+ s(
898
+ (E) => E.includes(g) ? E.filter((I) => I !== g) : [...E, g]
899
+ );
900
+ };
901
+ return /* @__PURE__ */ e(k, { children: /* @__PURE__ */ e(ia, { open: a, onOpenChange: n, children: /* @__PURE__ */ o(ca, { className: "max-w-3xl max-h-[80vh]", "aria-describedby": "group-members-description", children: [
902
+ /* @__PURE__ */ o(da, { children: [
903
+ /* @__PURE__ */ e(ua, { children: t.name }),
904
+ /* @__PURE__ */ e("div", { className: "flex items-center gap-2 mt-1", children: /* @__PURE__ */ o("p", { className: "text-sm text-muted-foreground", children: [
905
+ _.length,
906
+ " ",
907
+ _.length === 1 ? "member" : "members"
908
+ ] }) }),
909
+ /* @__PURE__ */ o("p", { id: "group-members-description", className: "sr-only", children: [
910
+ "Add or remove members from the ",
911
+ t.name,
912
+ " group"
913
+ ] })
914
+ ] }),
915
+ /* @__PURE__ */ o(Ba, { value: i, onValueChange: (g) => {
916
+ c(g), m(""), s([]);
917
+ }, className: "mt-4", children: [
918
+ /* @__PURE__ */ o(Ka, { className: "grid w-full grid-cols-2", children: [
919
+ /* @__PURE__ */ e(Ce, { value: "members", children: "Current Members" }),
920
+ /* @__PURE__ */ e(Ce, { value: "add", children: "Add Members" })
921
+ ] }),
922
+ /* @__PURE__ */ o(Ee, { value: "members", className: "mt-4 space-y-4", children: [
923
+ /* @__PURE__ */ o("div", { className: "relative", children: [
924
+ /* @__PURE__ */ e(Je, { className: "absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" }),
925
+ /* @__PURE__ */ e(
926
+ ce,
927
+ {
928
+ placeholder: "Search members...",
929
+ value: u,
930
+ onChange: (g) => m(g.target.value),
931
+ className: "pl-10"
932
+ }
933
+ )
934
+ ] }),
935
+ /* @__PURE__ */ e(Xe, { className: h.length > 0 ? "h-[300px]" : "h-[350px]", children: f ? /* @__PURE__ */ e("div", { className: "space-y-2", children: [1, 2, 3].map((g) => /* @__PURE__ */ e(Ye, { className: "h-16 w-full" }, g)) }) : w.length === 0 ? /* @__PURE__ */ o("div", { className: "flex flex-col items-center justify-center py-12 text-muted-foreground", children: [
936
+ /* @__PURE__ */ e(W, { className: "h-12 w-12 mb-3 opacity-50" }),
937
+ /* @__PURE__ */ e("p", { className: "text-sm font-medium", children: u ? "No members found" : "No members yet" }),
938
+ /* @__PURE__ */ e("p", { className: "text-xs mt-1", children: u ? "Try a different search" : 'Switch to the "Add Members" tab to add people to this group' })
939
+ ] }) : /* @__PURE__ */ e("div", { className: "space-y-2", children: w.map((g) => /* @__PURE__ */ e(
940
+ Ar,
941
+ {
942
+ member: g,
943
+ selected: h.includes(g.userId),
944
+ onToggle: () => Le(g.userId)
945
+ },
946
+ g.id
947
+ )) }) }),
948
+ h.length > 0 && /* @__PURE__ */ o("div", { className: "flex items-center justify-between pt-4 border-t", children: [
949
+ /* @__PURE__ */ o("span", { className: "text-sm text-muted-foreground", children: [
950
+ h.length,
951
+ " member",
952
+ h.length !== 1 ? "s" : "",
953
+ " selected"
954
+ ] }),
955
+ /* @__PURE__ */ e(
956
+ M,
957
+ {
958
+ variant: "destructive",
959
+ size: "sm",
960
+ onClick: ue,
961
+ disabled: U.isPending,
962
+ children: U.isPending ? /* @__PURE__ */ o(k, { children: [
963
+ /* @__PURE__ */ e(Y, { className: "mr-2 h-4 w-4 animate-spin" }),
964
+ "Removing..."
965
+ ] }) : /* @__PURE__ */ o(k, { children: [
966
+ /* @__PURE__ */ e(Qa, { className: "mr-2 h-4 w-4" }),
967
+ "Remove Selected"
968
+ ] })
969
+ }
970
+ )
971
+ ] })
972
+ ] }),
973
+ /* @__PURE__ */ o(Ee, { value: "add", className: "mt-4 space-y-4", children: [
974
+ /* @__PURE__ */ o("div", { className: "relative", children: [
975
+ /* @__PURE__ */ e(Je, { className: "absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" }),
976
+ /* @__PURE__ */ e(
977
+ ce,
978
+ {
979
+ placeholder: "Search users to add...",
980
+ value: u,
981
+ onChange: (g) => m(g.target.value),
982
+ className: "pl-10"
983
+ }
984
+ )
985
+ ] }),
986
+ /* @__PURE__ */ e(Xe, { className: "h-[300px]", children: C ? /* @__PURE__ */ e("div", { className: "space-y-2", children: [1, 2, 3].map((g) => /* @__PURE__ */ e(Ye, { className: "h-16 w-full" }, g)) }) : q.length === 0 ? /* @__PURE__ */ o("div", { className: "flex flex-col items-center justify-center py-12 text-muted-foreground", children: [
987
+ /* @__PURE__ */ e(Ze, { className: "h-12 w-12 mb-3 opacity-50" }),
988
+ /* @__PURE__ */ e("p", { className: "text-sm font-medium", children: "No available users" }),
989
+ /* @__PURE__ */ e("p", { className: "text-xs mt-1", children: u ? "Try a different search" : "All eligible users are already members" })
990
+ ] }) : /* @__PURE__ */ e("div", { className: "space-y-2", children: q.map((g) => /* @__PURE__ */ e(
991
+ Mr,
992
+ {
993
+ user: g,
994
+ selected: p.includes(g.id),
995
+ onToggle: () => Z(g.id)
996
+ },
997
+ g.id
998
+ )) }) }),
999
+ p.length > 0 && /* @__PURE__ */ o("div", { className: "flex items-center justify-between pt-4 border-t", children: [
1000
+ /* @__PURE__ */ o("span", { className: "text-sm text-muted-foreground", children: [
1001
+ p.length,
1002
+ " user",
1003
+ p.length !== 1 ? "s" : "",
1004
+ " selected"
1005
+ ] }),
1006
+ /* @__PURE__ */ e(
1007
+ M,
1008
+ {
1009
+ onClick: H,
1010
+ disabled: P.isPending,
1011
+ children: P.isPending ? /* @__PURE__ */ o(k, { children: [
1012
+ /* @__PURE__ */ e(Y, { className: "mr-2 h-4 w-4 animate-spin" }),
1013
+ "Adding..."
1014
+ ] }) : /* @__PURE__ */ o(k, { children: [
1015
+ /* @__PURE__ */ e(Ze, { className: "mr-2 h-4 w-4" }),
1016
+ "Add Members"
1017
+ ] })
1018
+ }
1019
+ )
1020
+ ] })
1021
+ ] })
1022
+ ] })
1023
+ ] }) }) });
1024
+ }
1025
+ function Ar({
1026
+ member: a,
1027
+ selected: n,
1028
+ onToggle: t
1029
+ }) {
1030
+ var i, c, u, m;
1031
+ const r = ((c = (i = a.user) == null ? void 0 : i.name) == null ? void 0 : c.split(" ").map((p) => p[0]).join("").toUpperCase()) || "?";
1032
+ return /* @__PURE__ */ o(
1033
+ "div",
1034
+ {
1035
+ className: "flex items-center gap-3 p-3 rounded-lg border bg-card hover:bg-muted/50 cursor-pointer",
1036
+ onClick: t,
1037
+ children: [
1038
+ /* @__PURE__ */ e(Wa, { checked: n }),
1039
+ /* @__PURE__ */ e(fa, { className: "h-8 w-8", children: /* @__PURE__ */ e(ga, { className: "text-xs", children: r }) }),
1040
+ /* @__PURE__ */ o("div", { className: "flex-1", children: [
1041
+ /* @__PURE__ */ e("p", { className: "text-sm font-medium", children: ((u = a.user) == null ? void 0 : u.name) || "Unknown User" }),
1042
+ /* @__PURE__ */ e("p", { className: "text-xs text-muted-foreground", children: (m = a.user) == null ? void 0 : m.email })
1043
+ ] })
1044
+ ]
1045
+ }
1046
+ );
1047
+ }
1048
+ function Mr({
1049
+ user: a,
1050
+ selected: n,
1051
+ onToggle: t
1052
+ }) {
1053
+ var i;
1054
+ const r = ((i = a.name) == null ? void 0 : i.split(" ").map((c) => c[0]).join("").toUpperCase()) || "?";
1055
+ return /* @__PURE__ */ o(
1056
+ "div",
1057
+ {
1058
+ className: "flex items-center gap-3 p-3 rounded-lg border bg-card hover:bg-muted/50 cursor-pointer",
1059
+ onClick: t,
1060
+ children: [
1061
+ /* @__PURE__ */ e(Wa, { checked: n }),
1062
+ /* @__PURE__ */ e(fa, { className: "h-8 w-8", children: /* @__PURE__ */ e(ga, { className: "text-xs", children: r }) }),
1063
+ /* @__PURE__ */ o("div", { className: "flex-1", children: [
1064
+ /* @__PURE__ */ e("p", { className: "text-sm font-medium", children: a.name }),
1065
+ /* @__PURE__ */ e("p", { className: "text-xs text-muted-foreground", children: a.email })
1066
+ ] })
1067
+ ]
1068
+ }
1069
+ );
1070
+ }
1071
+ function Lr({
1072
+ open: a,
1073
+ onOpenChange: n
1074
+ }) {
1075
+ const [t, r] = N("groups"), [i, c] = N(""), [u, m] = N(null), [p, y] = N(!1), [h, s] = N(null), { tokenProps: d } = F(), { currentUser: f } = ma(), v = hr(), b = (f == null ? void 0 : f.type) === "tenant", S = d == null ? void 0 : d.tenantId, { groups: C, isLoading: P, refetch: U } = st({
1076
+ type: b ? "TENANT_GROUP" : "all",
1077
+ tenantId: b ? S : void 0,
1078
+ includeMembers: !1
1079
+ }), _ = C.filter(
1080
+ (w) => {
1081
+ var H;
1082
+ return w.name.toLowerCase().includes(i.toLowerCase()) || ((H = w.description) == null ? void 0 : H.toLowerCase().includes(i.toLowerCase()));
1083
+ }
1084
+ ), $ = async () => {
1085
+ if (h)
1086
+ try {
1087
+ await v.mutateAsync(h.id), s(null), U();
1088
+ } catch (w) {
1089
+ console.error("Failed to delete group:", w);
1090
+ }
1091
+ }, V = (w) => {
1092
+ m(w), y(!0);
1093
+ }, q = () => {
1094
+ r("groups"), U();
1095
+ };
1096
+ return /* @__PURE__ */ o(k, { children: [
1097
+ /* @__PURE__ */ e(ia, { open: a, onOpenChange: n, children: /* @__PURE__ */ o(ca, { className: "max-w-4xl max-h-[80vh]", children: [
1098
+ /* @__PURE__ */ o(da, { children: [
1099
+ /* @__PURE__ */ o(ua, { className: "flex items-center gap-2", children: [
1100
+ /* @__PURE__ */ e(W, { className: "h-5 w-5" }),
1101
+ "Group Management"
1102
+ ] }),
1103
+ /* @__PURE__ */ e(qa, { children: "Manage your groups, create new groups, and control group membership" })
1104
+ ] }),
1105
+ /* @__PURE__ */ o(Ba, { value: t, onValueChange: r, className: "mt-4", children: [
1106
+ /* @__PURE__ */ o(Ka, { className: "grid w-full grid-cols-2", children: [
1107
+ /* @__PURE__ */ o(Ce, { value: "groups", className: "flex items-center gap-2", children: [
1108
+ /* @__PURE__ */ e(W, { className: "h-4 w-4" }),
1109
+ "Groups"
1110
+ ] }),
1111
+ /* @__PURE__ */ o(Ce, { value: "create", className: "flex items-center gap-2", children: [
1112
+ /* @__PURE__ */ e(la, { className: "h-4 w-4" }),
1113
+ "Create Group"
1114
+ ] })
1115
+ ] }),
1116
+ /* @__PURE__ */ e(Ee, { value: "groups", className: "mt-4", children: /* @__PURE__ */ o("div", { className: "space-y-4", children: [
1117
+ /* @__PURE__ */ o("div", { className: "relative", children: [
1118
+ /* @__PURE__ */ e(Je, { className: "absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" }),
1119
+ /* @__PURE__ */ e(
1120
+ ce,
1121
+ {
1122
+ placeholder: "Search groups...",
1123
+ value: i,
1124
+ onChange: (w) => c(w.target.value),
1125
+ className: "pl-10"
1126
+ }
1127
+ )
1128
+ ] }),
1129
+ /* @__PURE__ */ e(Xe, { className: "h-[400px]", children: P ? /* @__PURE__ */ e("div", { className: "space-y-3", children: [1, 2, 3].map((w) => /* @__PURE__ */ e(Ye, { className: "h-24 w-full" }, w)) }) : _.length === 0 ? /* @__PURE__ */ o("div", { className: "flex flex-col items-center justify-center py-12 text-muted-foreground", children: [
1130
+ /* @__PURE__ */ e(W, { className: "h-12 w-12 mb-3 opacity-50" }),
1131
+ /* @__PURE__ */ e("p", { className: "text-sm font-medium", children: "No groups found" }),
1132
+ /* @__PURE__ */ e("p", { className: "text-xs mt-1", children: i ? "Try a different search" : "Create your first group to get started" })
1133
+ ] }) : /* @__PURE__ */ e("div", { className: "space-y-3", children: _.map((w) => /* @__PURE__ */ e(
1134
+ kr,
1135
+ {
1136
+ group: w,
1137
+ onManageMembers: () => V(w),
1138
+ onDelete: () => s(w),
1139
+ currentUserId: f == null ? void 0 : f.id
1140
+ },
1141
+ w.id
1142
+ )) }) })
1143
+ ] }) }),
1144
+ /* @__PURE__ */ e(Ee, { value: "create", className: "mt-4", children: /* @__PURE__ */ e(
1145
+ gr,
1146
+ {
1147
+ onSuccess: q,
1148
+ tenantId: S,
1149
+ isTenantUser: b
1150
+ }
1151
+ ) })
1152
+ ] })
1153
+ ] }) }),
1154
+ u && /* @__PURE__ */ e(
1155
+ Er,
1156
+ {
1157
+ open: p,
1158
+ onOpenChange: y,
1159
+ group: u,
1160
+ onUpdate: () => U()
1161
+ }
1162
+ ),
1163
+ /* @__PURE__ */ e(
1164
+ Ja,
1165
+ {
1166
+ open: !!h,
1167
+ onOpenChange: () => s(null),
1168
+ children: /* @__PURE__ */ o(Xa, { children: [
1169
+ /* @__PURE__ */ o(Ya, { children: [
1170
+ /* @__PURE__ */ e(Za, { children: "Delete Group" }),
1171
+ /* @__PURE__ */ o(es, { children: [
1172
+ 'Are you sure you want to delete "',
1173
+ h == null ? void 0 : h.name,
1174
+ '"? This action cannot be undone and will remove all members from the group.'
1175
+ ] })
1176
+ ] }),
1177
+ /* @__PURE__ */ o(as, { children: [
1178
+ /* @__PURE__ */ e(ss, { children: "Cancel" }),
1179
+ /* @__PURE__ */ e(
1180
+ ea,
1181
+ {
1182
+ onClick: $,
1183
+ disabled: v.isPending,
1184
+ className: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
1185
+ children: v.isPending ? /* @__PURE__ */ o(k, { children: [
1186
+ /* @__PURE__ */ e(Y, { className: "mr-2 h-4 w-4 animate-spin" }),
1187
+ "Deleting..."
1188
+ ] }) : "Delete Group"
1189
+ }
1190
+ )
1191
+ ] })
1192
+ ] })
1193
+ }
1194
+ )
1195
+ ] });
1196
+ }
1197
+ function kr({
1198
+ group: a,
1199
+ onManageMembers: n,
1200
+ onDelete: t,
1201
+ currentUserId: r
1202
+ }) {
1203
+ const i = a.createdBy === r;
1204
+ return /* @__PURE__ */ e("div", { className: "rounded-lg border bg-card p-4 transition-colors hover:bg-muted/50", children: /* @__PURE__ */ o("div", { className: "flex items-start justify-between gap-3", children: [
1205
+ /* @__PURE__ */ o("div", { className: "flex-1 space-y-2", children: [
1206
+ /* @__PURE__ */ o("div", { children: [
1207
+ /* @__PURE__ */ e("h4", { className: "font-medium", children: a.name }),
1208
+ a.description && /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground mt-1", children: a.description })
1209
+ ] }),
1210
+ /* @__PURE__ */ o("div", { className: "flex flex-wrap items-center gap-3 text-xs text-muted-foreground", children: [
1211
+ /* @__PURE__ */ o("span", { className: "flex items-center gap-1", children: [
1212
+ /* @__PURE__ */ e(W, { className: "h-3 w-3" }),
1213
+ a.memberCount,
1214
+ " ",
1215
+ a.memberCount === 1 ? "member" : "members"
1216
+ ] }),
1217
+ /* @__PURE__ */ o("span", { children: [
1218
+ "Created ",
1219
+ jt(new Date(a.createdAt), "MMM d, yyyy")
1220
+ ] })
1221
+ ] })
1222
+ ] }),
1223
+ /* @__PURE__ */ o("div", { className: "flex items-center gap-1", children: [
1224
+ /* @__PURE__ */ e(
1225
+ M,
1226
+ {
1227
+ variant: "ghost",
1228
+ size: "sm",
1229
+ onClick: n,
1230
+ title: "Manage members",
1231
+ children: /* @__PURE__ */ e(Ze, { className: "h-4 w-4" })
1232
+ }
1233
+ ),
1234
+ i && /* @__PURE__ */ e(
1235
+ M,
1236
+ {
1237
+ variant: "ghost",
1238
+ size: "sm",
1239
+ onClick: t,
1240
+ title: "Delete group",
1241
+ className: "text-destructive hover:text-destructive",
1242
+ children: /* @__PURE__ */ e(Qa, { className: "h-4 w-4" })
1243
+ }
1244
+ )
1245
+ ] })
1246
+ ] }) });
1247
+ }
1248
+ function ie(a, n, t) {
1249
+ var c, u;
1250
+ const r = (a.controls || []).find(
1251
+ (m) => m.id === t
1252
+ );
1253
+ if (r)
1254
+ return r.label;
1255
+ const i = (u = (c = ts(a, n)) == null ? void 0 : c.controls) == null ? void 0 : u.find(
1256
+ (m) => m.id === t
1257
+ );
1258
+ return (i == null ? void 0 : i.label) || t;
1259
+ }
1260
+ function le(a, n) {
1261
+ var t;
1262
+ return ((t = ts(a, n)) == null ? void 0 : t.title) || n;
1263
+ }
1264
+ function Ir(a) {
1265
+ const { errors: n, dashboard: t } = a;
1266
+ if (!t)
1267
+ return n;
1268
+ const r = /* @__PURE__ */ new Map();
1269
+ for (const i of n) {
1270
+ const c = i.match(
1271
+ /^Card '(.+)' binding for control '(.+)' maps to missing metric '(.+)'\.$/
1272
+ );
1273
+ if (c) {
1274
+ const [, h, s] = c, d = `${h}:${s}:missing-metric`;
1275
+ r.has(d) || r.set(
1276
+ d,
1277
+ `"${le(t, h)}" has an outdated "${ie(
1278
+ t,
1279
+ h,
1280
+ s
1281
+ )}" mapping. Some choices still point to metrics that are no longer available on this card. Open the card controls and choose replacements.`
1282
+ );
1283
+ continue;
1284
+ }
1285
+ const u = i.match(
1286
+ /^Card '(.+)' binding for control '(.+)' maps to missing group-by field '(.+)'\.$/
1287
+ );
1288
+ if (u) {
1289
+ const [, h, s] = u, d = `${h}:${s}:missing-group-by`;
1290
+ r.has(d) || r.set(
1291
+ d,
1292
+ `"${le(t, h)}" has an outdated "${ie(
1293
+ t,
1294
+ h,
1295
+ s
1296
+ )}" mapping. Some choices still point to fields that are no longer available on this card. Open the card controls and choose replacements.`
1297
+ );
1298
+ continue;
1299
+ }
1300
+ const m = i.match(
1301
+ /^Card '(.+)' binding for control '(.+)' maps to an invalid metric target\.$/
1302
+ );
1303
+ if (m) {
1304
+ const [, h, s] = m, d = `${h}:${s}:invalid-metric`;
1305
+ r.has(d) || r.set(
1306
+ d,
1307
+ `"${le(t, h)}" has an invalid "${ie(
1308
+ t,
1309
+ h,
1310
+ s
1311
+ )}" metric mapping. Open the card controls and choose a valid metric for each option.`
1312
+ );
1313
+ continue;
1314
+ }
1315
+ const p = i.match(
1316
+ /^Card '(.+)' binding for control '(.+)' maps to an invalid group-by target\.$/
1317
+ );
1318
+ if (p) {
1319
+ const [, h, s] = p, d = `${h}:${s}:invalid-group-by`;
1320
+ r.has(d) || r.set(
1321
+ d,
1322
+ `"${le(t, h)}" has an invalid "${ie(
1323
+ t,
1324
+ h,
1325
+ s
1326
+ )}" field mapping. Open the card controls and choose a valid field for each option.`
1327
+ );
1328
+ continue;
1329
+ }
1330
+ const y = i.match(
1331
+ /^Card '(.+)' binding for control '(.+)' requires at least one temporal group-by field\.$/
1332
+ );
1333
+ if (y) {
1334
+ const [, h, s] = y, d = `${h}:${s}:missing-temporal-group-by`;
1335
+ r.has(d) || r.set(
1336
+ d,
1337
+ `"${le(t, h)}" can no longer use "${ie(
1338
+ t,
1339
+ h,
1340
+ s
1341
+ )}" for time grain because the card does not currently group by a date field.`
1342
+ );
1343
+ continue;
1344
+ }
1345
+ r.set(i, i);
1346
+ }
1347
+ return Array.from(r.values());
1348
+ }
1349
+ function qr() {
1350
+ var La, ka, Ia, Oa;
1351
+ Pt(), Ut();
1352
+ const {
1353
+ authToken: a,
1354
+ tokenProps: n,
1355
+ id: t
1356
+ } = F(), { isLocalDev: r } = tt(), { permissions: i } = ir(), c = rt(), { isLoading: u } = nt();
1357
+ x((l) => l.theme);
1358
+ const m = x(
1359
+ (l) => l.dashboardAssistantDraftScopeKey
1360
+ ), p = x((l) => l.lenses), y = x((l) => l.selectedLensId), h = p == null ? void 0 : p.find((l) => l.id === y), s = x((l) => l.dashboard);
1361
+ x((l) => l.selectedSheetId);
1362
+ const d = x(
1363
+ (l) => l.isDashboardEditing
1364
+ ), { setDashboardTitle: f } = x((l) => l.actions), [v, b] = N(!1), [S, C] = N(!1), [P, U] = N(!1), [_, $] = N(!1), [V, q] = N(!1), [w, H] = N(!1), [ue, Z] = N(null), [Le, g] = N(!1), [E, I] = N(null), [R, j] = N([]), [ee, me] = N(!1), ps = x((l) => l.isDashboardPanelOpen), fs = x(
1365
+ (l) => l.actions.setIsDashboardPanelOpen
1366
+ ), gs = x((l) => l.filterValues), D = x((l) => l.isVisualEditing);
1367
+ Pa((l) => l.card);
1368
+ const ae = we(
1369
+ (l) => l.selectedDashboard
1370
+ ), he = we(
1371
+ (l) => l.initialDashboard
1372
+ );
1373
+ we((l) => l.selectedVisual), x((l) => l.selectedFrameId), Pa((l) => l.frame);
1374
+ const pe = ae ? (ka = ae == null ? void 0 : ae.permissions) == null ? void 0 : ka.canEdit : (La = he == null ? void 0 : he.permissions) == null ? void 0 : La.canEdit, fe = x((l) => l.showFilters), va = ot((l) => l.setPanelOpen), vs = x(
1375
+ (l) => l.showDashboardJSON
1376
+ ), ke = x((l) => l.onSaveFunction), ba = x(
1377
+ (l) => l.actions.setShowFilters
1378
+ ), { setIsDashboardEditing: ya, setShowDashboardJSON: Na } = x(
1379
+ (l) => l.actions
1380
+ ), { setInitialDashboard: Sa, clearSelectedDashboard: Ie } = we(
1381
+ (l) => l.actions
1382
+ ), { resources: ge } = it(He.DASHBOARD), { data: Oe } = lt(), bs = ((Ia = Oe == null ? void 0 : Oe.preference) == null ? void 0 : Ia.defaultDashboardId) || null, { mutate: ys, isPending: Ns } = ct(), { currentUser: Ss } = ma(), xs = dt(Ss), J = ae || he, xa = J ? {
1383
+ id: J.id,
1384
+ title: (s == null ? void 0 : s.title) || J.title || "Dashboard"
1385
+ } : null, { handleAddNewFrame: ws } = ut(), [Te, _e] = N(!1), [Ds, se] = N(!1), [Pe, ve] = N("close"), te = mt(He.DASHBOARD), [G, Ue] = N(
1386
+ null
1387
+ ), wa = Ua(
1388
+ (l) => {
1389
+ window.setTimeout(() => {
1390
+ Z(l);
1391
+ }, 0);
1392
+ },
1393
+ []
1394
+ ), Cs = async (l, T) => {
1395
+ if (!(s != null && s.id)) {
1396
+ console.log("No dashboard ID found");
1397
+ return;
1398
+ }
1399
+ console.log("Updating dashboard title:", {
1400
+ dashboardId: s.id,
1401
+ newTitle: l,
1402
+ previousTitle: T
1403
+ }), te.mutate(
1404
+ {
1405
+ resourceId: s.id,
1406
+ data: { title: l }
1407
+ },
1408
+ {
1409
+ onSuccess: () => {
1410
+ console.log("Dashboard title updated successfully"), L.success("Dashboard title updated");
1411
+ },
1412
+ onError: (oe) => {
1413
+ console.error("Failed to update dashboard title:", oe), L.error("Failed to update dashboard title"), f(T);
1414
+ }
1415
+ }
1416
+ );
1417
+ };
1418
+ _t(() => {
1419
+ if (ge && ge.length > 0) {
1420
+ const l = s == null ? void 0 : s.id;
1421
+ if (l) {
1422
+ const T = ge.find(
1423
+ (oe) => oe.id === l
1424
+ );
1425
+ T && Sa(T);
1426
+ }
1427
+ }
1428
+ }, [ge, s == null ? void 0 : s.id, Sa]);
1429
+ const be = n.orgUserId || n.tenantId, Da = d && !D && be && pe, { setDashboard: Ge } = x((l) => l.actions), Es = () => {
1430
+ ya(!0);
1431
+ }, Re = () => {
1432
+ ya(!1), Na(!1), Ue(null), Z(null);
1433
+ };
1434
+ Gt(
1435
+ d,
1436
+ s,
1437
+ G,
1438
+ (l) => Ue(l)
1439
+ );
1440
+ const { isDirty: Ca, isDirtyPending: As, resetDirty: ye } = Kt(
1441
+ s,
1442
+ G,
1443
+ 300,
1444
+ 1e3,
1445
+ je
1446
+ ), Ea = Ua(() => G ? je(s) !== je(G) : !1, [s, G]), Fe = Ca || As, re = Te || te.isPending, Ms = () => {
1447
+ Ea() ? (ve("close"), se(!0)) : (Re(), ye());
1448
+ }, Ls = async () => {
1449
+ await $e({
1450
+ closeAfterSave: !0,
1451
+ navigateHomeAfterSave: Pe === "home"
1452
+ });
1453
+ }, ks = () => {
1454
+ G && Ge(G), Re(), Pe === "home" && Ie(), ve("close"), se(!1), ye();
1455
+ }, Is = () => {
1456
+ G && (Ge(G), ye());
1457
+ }, Os = () => {
1458
+ if (d && Ea()) {
1459
+ ve("home"), se(!0);
1460
+ return;
1461
+ }
1462
+ Ie();
1463
+ };
1464
+ async function $e(l) {
1465
+ const T = (l == null ? void 0 : l.closeAfterSave) ?? ee, oe = (l == null ? void 0 : l.navigateHomeAfterSave) ?? !1;
1466
+ me(T), T && se(!1);
1467
+ const Gs = Ot(s);
1468
+ g(!0), I(null), j([]), _e(!0);
1469
+ const Rs = {
1470
+ template: s
1471
+ };
1472
+ te.mutate(
1473
+ {
1474
+ resourceId: s.id,
1475
+ data: Rs
1476
+ },
1477
+ {
1478
+ onSuccess: (O) => {
1479
+ var Ne, Se, Ta;
1480
+ const z = (O == null ? void 0 : O.id) || ((Ne = O == null ? void 0 : O.dashboard) == null ? void 0 : Ne.id) || ((Se = O == null ? void 0 : O.resource) == null ? void 0 : Se.id) || ((Ta = O == null ? void 0 : O.template) == null ? void 0 : Ta.id) || null;
1481
+ if (!s.id && z) {
1482
+ const qe = Tt.getState(), xe = qe.pendingDashboardDraftMigration;
1483
+ (xe == null ? void 0 : xe.scopeKey) === m ? qe.actions.setPendingDashboardDraftMigrationExpectedDashboardId(
1484
+ z
1485
+ ) : xe && qe.actions.clearPendingDashboardDraftMigration();
1486
+ }
1487
+ _e(!1), L.success("Dashboard saved!"), Ue(Gs), g(!1), me(!1), T && (Re(), ye(), oe && Ie()), ve("close");
1488
+ },
1489
+ onError: (O) => {
1490
+ _e(!1), I("Failed to save dashboard. Please try again.");
1491
+ const z = O.details, Ne = Array.isArray(
1492
+ z == null ? void 0 : z.errors
1493
+ ) ? (z.errors || []).filter(
1494
+ (Se) => typeof Se == "string"
1495
+ ) : [];
1496
+ j(
1497
+ Ir({
1498
+ errors: Ne,
1499
+ dashboard: s || void 0
1500
+ })
1501
+ ), L.error("Failed to save dashboard");
1502
+ }
1503
+ }
1504
+ );
1505
+ }
1506
+ async function Ts() {
1507
+ if (b(!0), !y || !h) return;
1508
+ const l = JSON.stringify(s), T = {
1509
+ ...h,
1510
+ template: l,
1511
+ filterValues: gs
1512
+ };
1513
+ await sa(
1514
+ n.apiServiceUrl,
1515
+ T,
1516
+ a == null ? void 0 : a.accessToken
1517
+ ), L.success("Lens saved"), ke == null || ke(s), b(!1);
1518
+ }
1519
+ const Aa = (h == null ? void 0 : h.name) || s.title;
1520
+ te.isPending && console.log("Title during update:", {
1521
+ title: Aa,
1522
+ dashboardStateTitle: s.title,
1523
+ dashboardId: s == null ? void 0 : s.id,
1524
+ currentLensName: h == null ? void 0 : h.name
1525
+ });
1526
+ const Ma = n.orgUserId || n.tenantId && n.endUserId && n.endUserEmail, _s = !!Ma && !!(a != null && a.accessToken) && !!(n != null && n.apiServiceUrl), Ps = c, ne = (s == null ? void 0 : s.id) || null, Ve = !!ne && bs === ne, Us = () => {
1527
+ ne && ys({
1528
+ dashboardId: Ve ? null : ne
1529
+ });
1530
+ };
1531
+ return /* @__PURE__ */ o(
1532
+ "div",
1533
+ {
1534
+ className: "flex h-11 shrink-0 items-center justify-between gap-2 overflow-x-auto border-b px-4 py-2",
1535
+ role: "dashboard-controls",
1536
+ children: [
1537
+ /* @__PURE__ */ o("div", { className: "flex items-center gap-2", children: [
1538
+ Ma && /* @__PURE__ */ o(k, { children: [
1539
+ /* @__PURE__ */ e(
1540
+ B,
1541
+ {
1542
+ "aria-label": "Manage Dashboards",
1543
+ tooltip: "Manage Dashboards",
1544
+ onClick: () => {
1545
+ fs(!ps);
1546
+ },
1547
+ className: "h-7 p-2",
1548
+ children: /* @__PURE__ */ e(Wt, { className: "h-4 w-4" })
1549
+ }
1550
+ ),
1551
+ Ps && !D && /* @__PURE__ */ e(
1552
+ B,
1553
+ {
1554
+ "aria-label": "Dashboard Hub",
1555
+ tooltip: "Dashboard Hub",
1556
+ onClick: Os,
1557
+ className: "h-7 p-2",
1558
+ children: /* @__PURE__ */ e(Ha, { className: "h-4 w-4" })
1559
+ }
1560
+ )
1561
+ ] }),
1562
+ !D && c && (u ? /* @__PURE__ */ e(
1563
+ "div",
1564
+ {
1565
+ className: "h-4 w-28 rounded-md bg-muted/70 animate-pulse",
1566
+ "aria-label": "Loading dashboard title",
1567
+ role: "status",
1568
+ children: /* @__PURE__ */ e("span", { className: "sr-only", children: "Loading dashboard title" })
1569
+ }
1570
+ ) : /* @__PURE__ */ o(k, { children: [
1571
+ /* @__PURE__ */ e(
1572
+ ht,
1573
+ {
1574
+ value: Aa || "Untitled Dashboard",
1575
+ onSave: (l) => {
1576
+ console.log("EditableText onSave called:", {
1577
+ newTitle: l,
1578
+ canEditDashboard: pe,
1579
+ dashboardId: s == null ? void 0 : s.id
1580
+ });
1581
+ const T = (s == null ? void 0 : s.title) || "";
1582
+ f(l), Cs(l, T);
1583
+ },
1584
+ isEditable: pe && !h,
1585
+ displayClassName: "text-sm font-medium",
1586
+ inputClassName: "text-sm font-medium",
1587
+ placeholder: "Dashboard Title",
1588
+ isPending: te.isPending
1589
+ }
1590
+ ),
1591
+ _s && ne && /* @__PURE__ */ e(pt, { children: /* @__PURE__ */ o(ft, { children: [
1592
+ /* @__PURE__ */ e(gt, { asChild: !0, children: /* @__PURE__ */ e(
1593
+ M,
1594
+ {
1595
+ variant: "ghost",
1596
+ size: "icon",
1597
+ onClick: Us,
1598
+ disabled: Ns || !(a != null && a.accessToken) || !(n != null && n.apiServiceUrl),
1599
+ className: "h-7 w-7",
1600
+ children: /* @__PURE__ */ e(
1601
+ vt,
1602
+ {
1603
+ className: X(
1604
+ "h-4 w-4 transition-colors",
1605
+ Ve ? "fill-yellow-400 text-yellow-400" : "text-muted-foreground hover:text-yellow-400"
1606
+ )
1607
+ }
1608
+ )
1609
+ }
1610
+ ) }),
1611
+ /* @__PURE__ */ e(bt, { children: /* @__PURE__ */ e("p", { children: Ve ? "Remove as default dashboard" : "Make this a default dashboard" }) })
1612
+ ] }) })
1613
+ ] }))
1614
+ ] }),
1615
+ /* @__PURE__ */ o("div", { className: "flex items-center gap-2", children: [
1616
+ D && /* @__PURE__ */ o(k, { children: [
1617
+ /* @__PURE__ */ e(Rt, { className: "mr-2" }),
1618
+ /* @__PURE__ */ e(Ft, { className: "h-7" })
1619
+ ] }),
1620
+ r && !D && /* @__PURE__ */ o(k, { children: [
1621
+ /* @__PURE__ */ e(
1622
+ B,
1623
+ {
1624
+ tooltip: "Copy Token",
1625
+ onClick: () => {
1626
+ var l;
1627
+ a != null && a.accessToken && ((l = navigator == null ? void 0 : navigator.clipboard) != null && l.writeText ? navigator.clipboard.writeText(a.accessToken).then(() => L.success("Token copied to clipboard")).catch(() => L.error("Unable to copy token")) : L.error("Clipboard not available"));
1628
+ },
1629
+ className: "h-7 p-2",
1630
+ children: /* @__PURE__ */ e(yt, { className: "h-4 w-4" })
1631
+ }
1632
+ ),
1633
+ /* @__PURE__ */ e(
1634
+ B,
1635
+ {
1636
+ tooltip: "Invalidate Token",
1637
+ onClick: () => Nt(n.apiServiceUrl),
1638
+ className: "h-7 p-2",
1639
+ children: /* @__PURE__ */ e(Xt, { className: "h-4 w-4" })
1640
+ }
1641
+ )
1642
+ ] }),
1643
+ !D && c && /* @__PURE__ */ e(St, {}),
1644
+ !D && c && /* @__PURE__ */ e($t, {}),
1645
+ !D && c && ((Oa = J == null ? void 0 : J.permissions) == null ? void 0 : Oa.canShare) && /* @__PURE__ */ e(
1646
+ B,
1647
+ {
1648
+ tooltip: "Share Dashboard",
1649
+ onClick: () => C(!0),
1650
+ className: "h-7 p-2",
1651
+ children: /* @__PURE__ */ e(xt, { className: "h-4 w-4" })
1652
+ }
1653
+ ),
1654
+ !D && d && i.canUseFilters && c && /* @__PURE__ */ e(
1655
+ Vt,
1656
+ {
1657
+ showFilters: fe,
1658
+ onToggleFilters: () => {
1659
+ fe || va("dashboard", !1), ba(!fe);
1660
+ },
1661
+ onAddFilter: () => {
1662
+ fe || (va("dashboard", !1), ba(!0));
1663
+ },
1664
+ onAddControl: () => {
1665
+ wa("create");
1666
+ },
1667
+ onManageControls: () => wa("manage")
1668
+ }
1669
+ ),
1670
+ d && !D && c && ue ? /* @__PURE__ */ e(
1671
+ qt,
1672
+ {
1673
+ open: !0,
1674
+ onOpenChange: (l) => {
1675
+ l || Z(null);
1676
+ },
1677
+ showTrigger: !1,
1678
+ initialMode: ue
1679
+ }
1680
+ ) : null,
1681
+ d && !D && be && r && c && /* @__PURE__ */ e(nr, {}),
1682
+ !D && be && r && c && /* @__PURE__ */ e(or, {}),
1683
+ d && !D && be && h && r && c && /* @__PURE__ */ o(
1684
+ M,
1685
+ {
1686
+ className: "h-7 p-2",
1687
+ variant: "secondary",
1688
+ disabled: v,
1689
+ onClick: Ts,
1690
+ size: "sm",
1691
+ children: [
1692
+ /* @__PURE__ */ e(Ga, { className: "mr-2 h-4 w-4" }),
1693
+ "Save Lens"
1694
+ ]
1695
+ }
1696
+ ),
1697
+ d && !D && c && /* @__PURE__ */ o(
1698
+ M,
1699
+ {
1700
+ variant: "outline",
1701
+ className: "h-7 p-2",
1702
+ size: "sm",
1703
+ disabled: !d,
1704
+ onClick: () => ws(),
1705
+ children: [
1706
+ /* @__PURE__ */ e(la, { className: "mr-2 h-4 w-4" }),
1707
+ "Visual"
1708
+ ]
1709
+ }
1710
+ ),
1711
+ !D && !d && pe && c && /* @__PURE__ */ o(
1712
+ M,
1713
+ {
1714
+ variant: "outline",
1715
+ className: "h-7 p-2",
1716
+ onClick: Es,
1717
+ size: "sm",
1718
+ children: [
1719
+ /* @__PURE__ */ e(wt, { className: "mr-2 h-4 w-4" }),
1720
+ "Edit"
1721
+ ]
1722
+ }
1723
+ ),
1724
+ Da && c && Ca && /* @__PURE__ */ o(
1725
+ M,
1726
+ {
1727
+ variant: "outline",
1728
+ className: "h-7 p-2",
1729
+ onClick: Is,
1730
+ size: "sm",
1731
+ disabled: re,
1732
+ children: [
1733
+ /* @__PURE__ */ e(Dt, { className: "mr-2 h-4 w-4" }),
1734
+ "Undo"
1735
+ ]
1736
+ }
1737
+ ),
1738
+ Da && c && /* @__PURE__ */ o("div", { className: "relative inline-flex", children: [
1739
+ /* @__PURE__ */ o(
1740
+ M,
1741
+ {
1742
+ className: X("h-7 p-2", !Fe && "opacity-60"),
1743
+ disabled: re || !Fe,
1744
+ onClick: () => $e(),
1745
+ size: "sm",
1746
+ children: [
1747
+ re ? /* @__PURE__ */ e(Y, { className: "mr-2 h-4 w-4 animate-spin" }) : /* @__PURE__ */ e(Ga, { className: "mr-2 h-4 w-4" }),
1748
+ re ? "Saving..." : "Save"
1749
+ ]
1750
+ }
1751
+ ),
1752
+ Fe && !re && /* @__PURE__ */ e(
1753
+ "span",
1754
+ {
1755
+ "aria-hidden": "true",
1756
+ className: "pointer-events-none absolute -right-1 -top-1 h-2.5 w-2.5 rounded-full bg-orange-500 ring-2 ring-background"
1757
+ }
1758
+ )
1759
+ ] }),
1760
+ !D && d && r && c && /* @__PURE__ */ e("div", { className: "flex items-center space-x-2", children: /* @__PURE__ */ e(
1761
+ M,
1762
+ {
1763
+ className: "h-7 p-2",
1764
+ onClick: () => Na(!vs),
1765
+ size: "sm",
1766
+ variant: "ghost",
1767
+ children: /* @__PURE__ */ e(Ct, { className: "h-4 w-4" })
1768
+ }
1769
+ ) }),
1770
+ !D && r && /* @__PURE__ */ e(sr, {}),
1771
+ d && !D && c && /* @__PURE__ */ o(
1772
+ M,
1773
+ {
1774
+ variant: "outline",
1775
+ className: "h-7 p-2",
1776
+ onClick: Ms,
1777
+ children: [
1778
+ /* @__PURE__ */ e(ja, { className: "mr-2 h-4 w-4" }),
1779
+ "Close"
1780
+ ]
1781
+ }
1782
+ ),
1783
+ !D && c && /* @__PURE__ */ o(ta, { children: [
1784
+ /* @__PURE__ */ e(ra, { asChild: !0, children: /* @__PURE__ */ e(
1785
+ B,
1786
+ {
1787
+ tooltip: "More Options",
1788
+ className: "h-8 w-8 rounded-md border border-transparent p-0 text-muted-foreground hover:bg-muted/50 hover:text-foreground",
1789
+ buttonProps: { "aria-label": "More dashboard options" },
1790
+ children: /* @__PURE__ */ e(Et, { className: "h-4 w-4" })
1791
+ }
1792
+ ) }),
1793
+ /* @__PURE__ */ o(
1794
+ na,
1795
+ {
1796
+ align: "end",
1797
+ className: "w-56 rounded-xl border border-border/60 p-1 shadow-sm",
1798
+ children: [
1799
+ /* @__PURE__ */ e(De, { className: "px-2.5 text-xs font-medium text-muted-foreground", children: "Automation" }),
1800
+ /* @__PURE__ */ o(
1801
+ K,
1802
+ {
1803
+ onClick: () => $(!0),
1804
+ className: "flex items-center gap-2",
1805
+ children: [
1806
+ /* @__PURE__ */ e(At, { className: "mr-2 h-4 w-4" }),
1807
+ "Schedule Dashboard"
1808
+ ]
1809
+ }
1810
+ ),
1811
+ /* @__PURE__ */ e(Qe, {}),
1812
+ xs && /* @__PURE__ */ o(k, { children: [
1813
+ /* @__PURE__ */ e(De, { className: "px-2.5 text-xs font-medium text-muted-foreground", children: "Access" }),
1814
+ /* @__PURE__ */ o(
1815
+ K,
1816
+ {
1817
+ onClick: () => U(!0),
1818
+ className: "flex items-center gap-2",
1819
+ children: [
1820
+ /* @__PURE__ */ e(W, { className: "mr-2 h-4 w-4" }),
1821
+ "Manage Groups"
1822
+ ]
1823
+ }
1824
+ ),
1825
+ /* @__PURE__ */ e(Qe, {})
1826
+ ] }),
1827
+ /* @__PURE__ */ e(De, { className: "px-2.5 text-xs font-medium text-muted-foreground", children: "Preferences" }),
1828
+ /* @__PURE__ */ o(
1829
+ K,
1830
+ {
1831
+ onClick: () => q(!0),
1832
+ className: "flex items-center gap-2",
1833
+ children: [
1834
+ /* @__PURE__ */ e(Mt, { className: "mr-2 h-4 w-4" }),
1835
+ "Calendar Preferences"
1836
+ ]
1837
+ }
1838
+ ),
1839
+ /* @__PURE__ */ o(
1840
+ K,
1841
+ {
1842
+ onClick: () => H(!0),
1843
+ className: "flex items-center gap-2",
1844
+ children: [
1845
+ /* @__PURE__ */ e(Lt, { className: "mr-2 h-4 w-4" }),
1846
+ "Summary Settings"
1847
+ ]
1848
+ }
1849
+ )
1850
+ ]
1851
+ }
1852
+ )
1853
+ ] }),
1854
+ S && xa && /* @__PURE__ */ e(
1855
+ kt,
1856
+ {
1857
+ resource: xa,
1858
+ resourceType: He.DASHBOARD,
1859
+ onClose: () => C(!1)
1860
+ }
1861
+ ),
1862
+ /* @__PURE__ */ e(
1863
+ Lr,
1864
+ {
1865
+ open: P,
1866
+ onOpenChange: U
1867
+ }
1868
+ ),
1869
+ (s == null ? void 0 : s.id) && /* @__PURE__ */ e(
1870
+ It,
1871
+ {
1872
+ open: _,
1873
+ onOpenChange: $,
1874
+ dashboardId: s.id,
1875
+ dashboardName: s == null ? void 0 : s.title
1876
+ }
1877
+ ),
1878
+ /* @__PURE__ */ e(
1879
+ zt,
1880
+ {
1881
+ open: V,
1882
+ onOpenChange: q
1883
+ }
1884
+ ),
1885
+ /* @__PURE__ */ e(
1886
+ Bt,
1887
+ {
1888
+ open: w,
1889
+ onOpenChange: H,
1890
+ dashboard: s,
1891
+ disabled: !d,
1892
+ onApply: (l) => Ge({
1893
+ ...s,
1894
+ summary: l
1895
+ })
1896
+ }
1897
+ ),
1898
+ /* @__PURE__ */ e(
1899
+ Ja,
1900
+ {
1901
+ open: Le,
1902
+ onOpenChange: (l) => {
1903
+ !l && Te && !E || (g(l), l || (I(null), j([]), me(!1)));
1904
+ },
1905
+ children: /* @__PURE__ */ o(Xa, { className: "max-w-sm", children: [
1906
+ /* @__PURE__ */ o(Ya, { children: [
1907
+ /* @__PURE__ */ e(Za, { children: E ? "Save failed" : "Saving dashboard" }),
1908
+ /* @__PURE__ */ e(es, { className: "pt-2", children: E ? "We could not save the dashboard. Please try again." : "Please wait while we save your changes." }),
1909
+ R.length > 0 && /* @__PURE__ */ o("div", { className: "space-y-1 rounded-md border border-destructive/20 bg-destructive/5 p-3 text-left", children: [
1910
+ /* @__PURE__ */ e("div", { className: "text-sm font-medium text-destructive", children: "What needs attention" }),
1911
+ /* @__PURE__ */ e("ul", { className: "list-disc space-y-1 pl-4 text-xs text-muted-foreground", children: R.slice(0, 5).map((l) => /* @__PURE__ */ e("li", { children: l }, l)) })
1912
+ ] })
1913
+ ] }),
1914
+ /* @__PURE__ */ e(as, { className: "flex-col gap-2 sm:flex-row sm:justify-end", children: E ? /* @__PURE__ */ o(k, { children: [
1915
+ /* @__PURE__ */ e(
1916
+ ss,
1917
+ {
1918
+ onClick: () => {
1919
+ g(!1), I(null), j([]), me(!1);
1920
+ },
1921
+ className: "m-0",
1922
+ children: "Close"
1923
+ }
1924
+ ),
1925
+ /* @__PURE__ */ e(
1926
+ ea,
1927
+ {
1928
+ onClick: () => $e({
1929
+ closeAfterSave: ee,
1930
+ navigateHomeAfterSave: Pe === "home"
1931
+ }),
1932
+ className: "m-0",
1933
+ children: "Retry"
1934
+ }
1935
+ )
1936
+ ] }) : /* @__PURE__ */ o(
1937
+ ea,
1938
+ {
1939
+ disabled: !0,
1940
+ className: "m-0 cursor-default",
1941
+ children: [
1942
+ /* @__PURE__ */ e(Y, { className: "mr-2 h-4 w-4 animate-spin" }),
1943
+ "Saving..."
1944
+ ]
1945
+ }
1946
+ ) })
1947
+ ] })
1948
+ }
1949
+ ),
1950
+ /* @__PURE__ */ e(
1951
+ Ht,
1952
+ {
1953
+ open: Ds,
1954
+ onOpenChange: (l) => {
1955
+ se(l);
1956
+ },
1957
+ onSave: Ls,
1958
+ onDiscard: ks,
1959
+ isSaving: Te,
1960
+ saveLabel: "Save",
1961
+ discardLabel: "Discard"
1962
+ }
1963
+ )
1964
+ ] })
1965
+ ]
1966
+ }
1967
+ );
1968
+ }
1969
+ export {
1970
+ qr as default
1971
+ };