react-semaphor 0.1.260 → 0.1.262

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 (48) hide show
  1. package/dist/chunks/dashboard-controls-AFlpiHtC.js +42 -0
  2. package/dist/chunks/dashboard-controls-Cq2fQ7bv.js +1979 -0
  3. package/dist/chunks/dashboard-filter-controls-button-Cedz-YZx.js +11 -0
  4. package/dist/chunks/dashboard-filter-controls-button-udrHABi3.js +1066 -0
  5. package/dist/chunks/{dashboard-json-BUrApiYl.js → dashboard-json-BU6cvmRP.js} +1 -1
  6. package/dist/chunks/{dashboard-json-U7VmojaR.js → dashboard-json-RKwWONKm.js} +1 -1
  7. package/dist/chunks/dashboard-summary-settings-dialog-Bl-XplTR.js +1 -0
  8. package/dist/chunks/dashboard-summary-settings-dialog-DDxHxKjp.js +535 -0
  9. package/dist/chunks/{edit-dashboard-visual-N2r5ObJ_.js → edit-dashboard-visual-B1r0Ho9B.js} +5970 -5492
  10. package/dist/chunks/edit-dashboard-visual-BwDFI3hI.js +188 -0
  11. package/dist/chunks/{index-BNdZjo5d.js → index-BtbNfaQD.js} +50751 -47206
  12. package/dist/chunks/index-DZ93VE76.js +1114 -0
  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-Cz7MYBC7.js} +1 -1
  16. package/dist/chunks/{resource-management-panel-zF23gLOJ.js → resource-management-panel-DxG6-naG.js} +70 -70
  17. package/dist/chunks/use-create-flow-overlay-state-BcMrPzMc.js +1445 -0
  18. package/dist/chunks/use-create-flow-overlay-state-D13D1vB_.js +21 -0
  19. package/dist/chunks/{use-visual-utils-BBTQGDdB.js → use-visual-utils-DScc5-p_.js} +1 -1
  20. package/dist/chunks/{use-visual-utils-K1k39w2U.js → use-visual-utils-DmxEKpor.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/dashboard-summary-settings-dialog-CaxmCNyy.js +0 -1
  41. package/dist/chunks/dashboard-summary-settings-dialog-DlVBUQmC.js +0 -544
  42. package/dist/chunks/edit-dashboard-visual-uA-0wLnR.js +0 -193
  43. package/dist/chunks/editor-action-buttons-B6lABkRB.js +0 -412
  44. package/dist/chunks/editor-action-buttons-Dh7Xndgk.js +0 -21
  45. package/dist/chunks/index-DOeggx0V.js +0 -1109
  46. package/dist/chunks/normalize-dashboard-for-dirty-check-B7NQDI1H.js +0 -1
  47. package/dist/chunks/notification-bell-BxyeaeRc.js +0 -839
  48. package/dist/chunks/notification-bell-tJRds5JJ.js +0 -6
@@ -0,0 +1,1979 @@
1
+ import { jsxs as o, jsx as e, Fragment as I } from "react/jsx-runtime";
2
+ import { bL as de, dn as $s, u as x, cy as ta, cz as ra, B as M, cB as na, cC as Q, dp as oa, N as Va, b as $, e as ia, dq as Vs, cp as la, f as ca, g as da, h as ua, i as qa, L as Ke, I as ce, v as qs, a6 as K, dr as De, cG as Qe, ds as Hs, dt as _a, du as Ha, c as Y, dv as ja, dw as js, cX as ma, dx as zs, dy as Bs, dz as Ks, dA as Qs, dB as Ws, dC as Js, H as Ae, V as Me, x as k, dD as za, d5 as Xs, dE as Ys, w as Z, cF as J, dF as Zs, dG as et, dH as We, dI as at, dJ as st, 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 tt, 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 rt, dS as nt, af as ot, U as Pa, ae as we, dT as it, al as lt, ag as He, dU as ct, dV as dt, dW as ut, aA as mt, dX as ht, dY as pt, bS as ft, bT as gt, bU as vt, dZ as bt, bV as yt, cD as Nt, as as St, d_ as xt, d$ as wt, dm as Dt, e0 as Ct, e1 as Et, cA as At, a8 as Mt, cI as Lt, e2 as kt, ak as It, a9 as Ot, ar as Tt, e3 as _t } from "./index-BtbNfaQD.js";
3
+ import * as A from "react";
4
+ import rs, { useState as N, useMemo as W, useCallback as Ua, useEffect as Pt } from "react";
5
+ import "react-dom";
6
+ import { b as Ut, u as Gt, d as Rt, A as Ft, V as $t, N as Vt, c as qt, D as Ht, U as jt } from "./dashboard-filter-controls-button-udrHABi3.js";
7
+ import { l as zt } from "./date-formatter-vkCj9Ct-.js";
8
+ import { C as Bt, D as Kt } from "./dashboard-summary-settings-dialog-DDxHxKjp.js";
9
+ import { u as Qt } 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-BcMrPzMc.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 Wt = 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 Jt = 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 Xt = 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 Yt = 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 Zt = 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 er() {
91
+ if (Ra) return ze;
92
+ Ra = 1;
93
+ var a = rs;
94
+ function n(r, d) {
95
+ return r === d && (r !== 0 || 1 / r === 1 / d) || r !== r && d !== d;
96
+ }
97
+ var s = typeof Object.is == "function" ? Object.is : n, t = a.useState, i = a.useEffect, c = a.useLayoutEffect, u = a.useDebugValue;
98
+ function m(r, d) {
99
+ var f = d(), v = t({ 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
+ [r, f, d]
105
+ ), i(
106
+ function() {
107
+ return p(b) && S({ inst: b }), r(function() {
108
+ p(b) && S({ inst: b });
109
+ });
110
+ },
111
+ [r]
112
+ ), u(f), f;
113
+ }
114
+ function p(r) {
115
+ var d = r.getSnapshot;
116
+ r = r.value;
117
+ try {
118
+ var f = d();
119
+ return !s(r, f);
120
+ } catch {
121
+ return !0;
122
+ }
123
+ }
124
+ function y(r, 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 ar() {
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 (!r) {
152
+ var S = v();
153
+ c(b, S) || (console.error(
154
+ "The result of getSnapshot should be cached to avoid an infinite loop"
155
+ ), r = !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, s(C) && P({ inst: C });
164
+ },
165
+ [f, b, v]
166
+ ), m(
167
+ function() {
168
+ return s(C) && P({ inst: C }), f(function() {
169
+ s(C) && P({ inst: C });
170
+ });
171
+ },
172
+ [f]
173
+ ), y(b), b;
174
+ }
175
+ function s(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 t(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, r = !1, d = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? t : 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 = er() : aa.exports = ar();
194
+ var sr = aa.exports;
195
+ function tr() {
196
+ const { setTheme: a } = $s(), n = x(
197
+ (s) => s.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
+ Zt,
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
+ Xt,
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
+ Q,
220
+ {
221
+ onClick: () => {
222
+ a("light"), n("light");
223
+ },
224
+ children: "Light"
225
+ }
226
+ ),
227
+ /* @__PURE__ */ e(
228
+ Q,
229
+ {
230
+ onClick: () => {
231
+ a("dark"), n("dark");
232
+ },
233
+ children: "Dark"
234
+ }
235
+ ),
236
+ /* @__PURE__ */ e(
237
+ Q,
238
+ {
239
+ onClick: () => {
240
+ a("system"), n("system");
241
+ },
242
+ children: "System"
243
+ }
244
+ )
245
+ ] })
246
+ ] });
247
+ }
248
+ async function rr(a, n, s, t, i) {
249
+ if (!i)
250
+ return null;
251
+ const c = JSON.stringify(s), u = `${a}/v1/lens`;
252
+ return await oa(u, i, {
253
+ name: n,
254
+ template: c,
255
+ filterValues: t,
256
+ operation: "create"
257
+ });
258
+ }
259
+ async function sa(a, n, s) {
260
+ if (!s)
261
+ return null;
262
+ const { id: t, template: i, filterValues: c, isDefault: u, shared: m } = n, p = `${a}/v1/lens`;
263
+ return await oa(p, s, {
264
+ lensId: t,
265
+ template: i,
266
+ filterValues: c,
267
+ isDefault: u,
268
+ shared: m,
269
+ operation: "update"
270
+ });
271
+ }
272
+ async function nr(a, n, s) {
273
+ if (!s)
274
+ return null;
275
+ const t = `${a}/v1/lens`;
276
+ return await oa(t, s, {
277
+ operation: "delete",
278
+ lensId: n
279
+ });
280
+ }
281
+ function or() {
282
+ const [a, n] = N(""), [s, t] = N(!1), i = x((S) => S.lenses), { setLenses: c, setSelectedLensId: u } = Va(), [m, p] = N(!1), [y, h] = N(!1), r = x((S) => S.dashboard), d = x((S) => S.filterValues), { authToken: f, tokenProps: v } = $();
283
+ async function b() {
284
+ p(!0);
285
+ const S = await rr(
286
+ v.apiServiceUrl,
287
+ a,
288
+ r,
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(Vs, { 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
+ s && /* @__PURE__ */ e("p", { className: "text-sm", children: "The lens name already exists. Use a differnet name." }),
327
+ /* @__PURE__ */ e(qs, { 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 ir() {
342
+ const [a, n] = N(!1), s = x((r) => r.lenses), t = x((r) => r.selectedLensId), { setLenses: i, setSelectedLensId: c } = Va(), { authToken: u, tokenProps: m } = $();
343
+ async function p(r) {
344
+ c(r);
345
+ }
346
+ async function y(r) {
347
+ if (await nr(m.apiServiceUrl, r, u == null ? void 0 : u.accessToken)) {
348
+ const f = s == null ? void 0 : s.filter((v) => v.id !== r);
349
+ i(f || []), c("original");
350
+ }
351
+ }
352
+ async function h(r) {
353
+ const d = s == null ? void 0 : s.map((b) => b.id === r.id ? {
354
+ ...b,
355
+ isDefault: !r.isDefault
356
+ } : {
357
+ ...b,
358
+ isDefault: !1
359
+ });
360
+ i(d || []);
361
+ const f = {
362
+ ...r,
363
+ isDefault: !r.isDefault
364
+ };
365
+ await sa(m.apiServiceUrl, f, u == null ? void 0 : u.accessToken);
366
+ const v = s == null ? void 0 : s.find((b) => b.isDefault);
367
+ if (v && v.id !== r.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(K, { tooltip: "Lenses", className: "h-7 p-2", children: /* @__PURE__ */ e(Wt, { 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
+ Hs,
382
+ {
383
+ value: t,
384
+ onValueChange: p,
385
+ children: [
386
+ /* @__PURE__ */ e(_a, { value: "original", children: "Original" }),
387
+ s == null ? void 0 : s.map((r) => /* @__PURE__ */ o(
388
+ _a,
389
+ {
390
+ className: "group flex justify-between gap-2",
391
+ value: r.id,
392
+ children: [
393
+ /* @__PURE__ */ e("p", { children: r.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(r);
400
+ },
401
+ className: Y(
402
+ "size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",
403
+ {
404
+ invisible: !r.isDefault,
405
+ "text-green-500": r.isDefault
406
+ }
407
+ ),
408
+ strokeWidth: 1.5
409
+ }
410
+ ),
411
+ /* @__PURE__ */ e(
412
+ ja,
413
+ {
414
+ onClick: (d) => {
415
+ d.preventDefault(), y(r.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
+ r.id
425
+ ))
426
+ ]
427
+ }
428
+ )
429
+ ] })
430
+ ] });
431
+ }
432
+ function lr() {
433
+ const { displayPreferences: a, shouldShowElement: n } = js(), { currentUser: s, userContext: t } = ma(), i = W(
434
+ () => zs(s),
435
+ [s]
436
+ ), c = W(() => (m) => i && i[m] !== void 0 && i[m] === !1 ? !1 : n(m), [i, n, a]), u = W(
437
+ () => {
438
+ var m, p, y, h, r;
439
+ return {
440
+ canEdit: ((m = t == null ? void 0 : t.permissions) == null ? void 0 : m.canEdit) ?? Js(s),
441
+ canUseFilters: ((p = t == null ? void 0 : t.permissions) == null ? void 0 : p.canEdit) ?? Ws(s),
442
+ canManageDashboards: ((y = t == null ? void 0 : t.permissions) == null ? void 0 : y.canCreateDashboard) ?? Qs(s),
443
+ canCreateDashboards: ((h = t == null ? void 0 : t.permissions) == null ? void 0 : h.canCreateDashboard) ?? Ks(s),
444
+ canAccessVisuals: ((r = t == null ? void 0 : t.permissions) == null ? void 0 : r.canEdit) ?? Bs(s)
445
+ };
446
+ },
447
+ [s, t]
448
+ );
449
+ return {
450
+ displayPreferences: a,
451
+ shouldShowElement: c,
452
+ permissions: u,
453
+ currentUser: s
454
+ };
455
+ }
456
+ const cr = async (a, n, s) => {
457
+ const t = `${a}/management/v1/groups`;
458
+ return await za(t, n, s);
459
+ }, dr = async (a, n, s) => {
460
+ const t = `${a}/management/v1/groups/${s}`, i = await fetch(t, {
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
+ }, ur = async (a, n, s, t) => {
471
+ const i = `${a}/management/v1/groups/${s}/members`;
472
+ return await za(i, n, t);
473
+ }, mr = async (a, n, s, t) => {
474
+ const i = `${a}/management/v1/groups/${s}/members`, c = await fetch(i, {
475
+ method: "DELETE",
476
+ headers: {
477
+ "Content-Type": "application/json",
478
+ Authorization: `Bearer ${n}`
479
+ },
480
+ body: JSON.stringify(t)
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 hr() {
488
+ const { authToken: a, tokenProps: n } = $(), s = Ae();
489
+ return Me({
490
+ mutationFn: (t) => cr(n.apiServiceUrl, (a == null ? void 0 : a.accessToken) || "", t),
491
+ onSuccess: () => {
492
+ s.invalidateQueries({ queryKey: ["groups"] }), k.success("Group created successfully");
493
+ },
494
+ onError: (t) => {
495
+ console.error("Failed to create group:", t), k.error("Failed to create group", {
496
+ description: t.message
497
+ });
498
+ }
499
+ });
500
+ }
501
+ function pr() {
502
+ const { authToken: a, tokenProps: n } = $(), s = Ae();
503
+ return Me({
504
+ mutationFn: (t) => dr(n.apiServiceUrl, (a == null ? void 0 : a.accessToken) || "", t),
505
+ onSuccess: (t, i) => {
506
+ s.invalidateQueries({ queryKey: ["groups"] }), s.removeQueries({ queryKey: ["group", i] }), k.success("Group deleted successfully");
507
+ },
508
+ onError: (t) => {
509
+ console.error("Failed to delete group:", t), k.error("Failed to delete group", {
510
+ description: t.message
511
+ });
512
+ }
513
+ });
514
+ }
515
+ function fr() {
516
+ const { authToken: a, tokenProps: n } = $(), s = Ae();
517
+ return Me({
518
+ mutationFn: ({
519
+ groupId: t,
520
+ data: i
521
+ }) => ur(n.apiServiceUrl, (a == null ? void 0 : a.accessToken) || "", t, i),
522
+ onSuccess: (t, i) => {
523
+ s.invalidateQueries({ queryKey: ["group", i.groupId] }), s.invalidateQueries({
524
+ queryKey: ["group-members", i.groupId]
525
+ }), s.invalidateQueries({ queryKey: ["groups"] }), k.success("Members added successfully");
526
+ },
527
+ onError: (t) => {
528
+ console.error("Failed to add group members:", t), k.error("Failed to add members", {
529
+ description: t.message
530
+ });
531
+ }
532
+ });
533
+ }
534
+ function gr() {
535
+ const { authToken: a, tokenProps: n } = $(), s = Ae();
536
+ return Me({
537
+ mutationFn: ({
538
+ groupId: t,
539
+ data: i
540
+ }) => mr(n.apiServiceUrl, (a == null ? void 0 : a.accessToken) || "", t, i),
541
+ onSuccess: (t, i) => {
542
+ s.invalidateQueries({ queryKey: ["group", i.groupId] }), s.invalidateQueries({
543
+ queryKey: ["group-members", i.groupId]
544
+ }), s.invalidateQueries({ queryKey: ["groups"] }), k.success("Members removed successfully");
545
+ },
546
+ onError: (t) => {
547
+ console.error("Failed to remove group members:", t), k.error("Failed to remove members", {
548
+ description: t.message
549
+ });
550
+ }
551
+ });
552
+ }
553
+ function vr({
554
+ onSuccess: a,
555
+ tenantId: n,
556
+ isTenantUser: s
557
+ }) {
558
+ const [t, i] = N(""), [c, u] = N(""), [m, p] = N({}), y = hr(), h = () => {
559
+ const d = {};
560
+ return t.trim() ? t.length < 3 ? d.name = "Group name must be at least 3 characters" : t.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: t.trim(),
566
+ description: c.trim() || void 0,
567
+ type: s ? "TENANT_GROUP" : "ORG_GROUP",
568
+ ...s && 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: t,
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
+ Xs,
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(Ys, { 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 || !t.trim(),
645
+ children: y.isPending ? /* @__PURE__ */ o(I, { children: [
646
+ /* @__PURE__ */ e(Z, { className: "mr-2 h-4 w-4 animate-spin" }),
647
+ "Creating..."
648
+ ] }) : /* @__PURE__ */ o(I, { children: [
649
+ /* @__PURE__ */ e(J, { className: "mr-2 h-4 w-4" }),
650
+ "Create Group"
651
+ ] })
652
+ }
653
+ )
654
+ ] })
655
+ ] });
656
+ }
657
+ function br(a, n = []) {
658
+ let s = [];
659
+ function t(c, u) {
660
+ const m = A.createContext(u);
661
+ m.displayName = c + "Context";
662
+ const p = s.length;
663
+ s = [...s, u];
664
+ const y = (r) => {
665
+ var C;
666
+ const { scope: d, children: f, ...v } = r, 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(r, 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(`\`${r}\` must be used within \`${c}\``);
676
+ }
677
+ return [y, h];
678
+ }
679
+ const i = () => {
680
+ const c = s.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, [t, yr(i, ...n)];
690
+ }
691
+ function yr(...a) {
692
+ const n = a[0];
693
+ if (a.length === 1) return n;
694
+ const s = () => {
695
+ const t = a.map((i) => ({
696
+ useScope: i(),
697
+ scopeName: i.scopeName
698
+ }));
699
+ return function(c) {
700
+ const u = t.reduce((m, { useScope: p, scopeName: y }) => {
701
+ const r = p(c)[`__scope${y}`];
702
+ return { ...m, ...r };
703
+ }, {});
704
+ return A.useMemo(() => ({ [`__scope${n.scopeName}`]: u }), [u]);
705
+ };
706
+ };
707
+ return s.scopeName = n.scopeName, s;
708
+ }
709
+ var Nr = [
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 = Nr.reduce((a, n) => {
728
+ const s = Zs(`Primitive.${n}`), t = A.forwardRef((i, c) => {
729
+ const { asChild: u, ...m } = i, p = u ? s : n;
730
+ return typeof window < "u" && (window[Symbol.for("radix-ui")] = !0), /* @__PURE__ */ e(p, { ...m, ref: c });
731
+ });
732
+ return t.displayName = `Primitive.${n}`, { ...a, [n]: t };
733
+ }, {});
734
+ function Sr() {
735
+ return sr.useSyncExternalStore(
736
+ xr,
737
+ () => !0,
738
+ () => !1
739
+ );
740
+ }
741
+ function xr() {
742
+ return () => {
743
+ };
744
+ }
745
+ var pa = "Avatar", [wr] = br(pa), [Dr, ns] = wr(pa), os = A.forwardRef(
746
+ (a, n) => {
747
+ const { __scopeAvatar: s, ...t } = a, [i, c] = A.useState("idle");
748
+ return /* @__PURE__ */ e(
749
+ Dr,
750
+ {
751
+ scope: s,
752
+ imageLoadingStatus: i,
753
+ onImageLoadingStatusChange: c,
754
+ children: /* @__PURE__ */ e(ha.span, { ...t, ref: n })
755
+ }
756
+ );
757
+ }
758
+ );
759
+ os.displayName = pa;
760
+ var is = "AvatarImage", ls = A.forwardRef(
761
+ (a, n) => {
762
+ const { __scopeAvatar: s, src: t, onLoadingStatusChange: i = () => {
763
+ }, ...c } = a, u = ns(is, s), m = Cr(t, c), p = et((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: t }) : null;
769
+ }
770
+ );
771
+ ls.displayName = is;
772
+ var cs = "AvatarFallback", ds = A.forwardRef(
773
+ (a, n) => {
774
+ const { __scopeAvatar: s, delayMs: t, ...i } = a, c = ns(cs, s), [u, m] = A.useState(t === void 0);
775
+ return A.useEffect(() => {
776
+ if (t !== void 0) {
777
+ const p = window.setTimeout(() => m(!0), t);
778
+ return () => window.clearTimeout(p);
779
+ }
780
+ }, [t]), 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 Cr(a, { referrerPolicy: n, crossOrigin: s }) {
788
+ const t = Sr(), i = A.useRef(null), c = t ? (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 = (r) => () => {
795
+ m(r);
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 s == "string" && (c.crossOrigin = s), () => {
800
+ c.removeEventListener("load", y), c.removeEventListener("error", h);
801
+ };
802
+ }, [c, s, n]), u;
803
+ }
804
+ var us = os, ms = ls, hs = ds;
805
+ const fa = A.forwardRef(({ className: a, ...n }, s) => /* @__PURE__ */ e(
806
+ us,
807
+ {
808
+ ref: s,
809
+ className: Y(
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 Er = A.forwardRef(({ className: a, ...n }, s) => /* @__PURE__ */ e(
818
+ ms,
819
+ {
820
+ ref: s,
821
+ className: Y("aspect-square h-full w-full", a),
822
+ ...n
823
+ }
824
+ ));
825
+ Er.displayName = ms.displayName;
826
+ const ga = A.forwardRef(({ className: a, ...n }, s) => /* @__PURE__ */ e(
827
+ hs,
828
+ {
829
+ ref: s,
830
+ className: Y(
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 Ar({
839
+ open: a,
840
+ onOpenChange: n,
841
+ group: s,
842
+ onUpdate: t
843
+ }) {
844
+ const [i, c] = N("members"), [u, m] = N(""), [p, y] = N([]), [h, r] = N([]), { data: d, isLoading: f, refetch: v } = at(s.id), b = s.type === "TENANT_GROUP" ? "tenant" : "organization", { users: S, isLoading: C } = st({
845
+ type: b,
846
+ tenantId: s.tenantId || void 0,
847
+ active: !0,
848
+ limit: 100
849
+ }), P = fr(), U = gr(), _ = (d == null ? void 0 : d.members) || [], V = W(() => new Set(_.map((g) => g.userId)), [_]), q = W(() => S.filter((g) => !V.has(g.id)), [S, V]), H = W(() => {
850
+ if (!u) return q;
851
+ const g = u.toLowerCase();
852
+ return q.filter(
853
+ (E) => {
854
+ var O, F;
855
+ return ((O = E.name) == null ? void 0 : O.toLowerCase().includes(g)) || ((F = E.email) == null ? void 0 : F.toLowerCase().includes(g));
856
+ }
857
+ );
858
+ }, [q, u]), w = W(() => {
859
+ if (!u) return _;
860
+ const g = u.toLowerCase();
861
+ return _.filter(
862
+ (E) => {
863
+ var O, F, z, ae;
864
+ return ((F = (O = E.user) == null ? void 0 : O.name) == null ? void 0 : F.toLowerCase().includes(g)) || ((ae = (z = E.user) == null ? void 0 : z.email) == null ? void 0 : ae.toLowerCase().includes(g));
865
+ }
866
+ );
867
+ }, [_, u]), j = async () => {
868
+ if (p.length !== 0)
869
+ try {
870
+ await P.mutateAsync({
871
+ groupId: s.id,
872
+ data: {
873
+ userIds: p,
874
+ userType: b === "tenant" ? "tenant" : "org"
875
+ }
876
+ }), y([]), c("members"), v(), t == null || t();
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: s.id,
885
+ data: {
886
+ userIds: h
887
+ }
888
+ }), r([]), v(), t == null || t();
889
+ } catch (g) {
890
+ console.error("Failed to remove members:", g);
891
+ }
892
+ }, ee = (g) => {
893
+ y(
894
+ (E) => E.includes(g) ? E.filter((O) => O !== g) : [...E, g]
895
+ );
896
+ }, Le = (g) => {
897
+ r(
898
+ (E) => E.includes(g) ? E.filter((O) => O !== g) : [...E, g]
899
+ );
900
+ };
901
+ return /* @__PURE__ */ e(I, { 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: s.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
+ s.name,
912
+ " group"
913
+ ] })
914
+ ] }),
915
+ /* @__PURE__ */ o(Ba, { value: i, onValueChange: (g) => {
916
+ c(g), m(""), r([]);
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(J, { 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
+ Mr,
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(I, { children: [
963
+ /* @__PURE__ */ e(Z, { className: "mr-2 h-4 w-4 animate-spin" }),
964
+ "Removing..."
965
+ ] }) : /* @__PURE__ */ o(I, { 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)) }) : H.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: H.map((g) => /* @__PURE__ */ e(
991
+ Lr,
992
+ {
993
+ user: g,
994
+ selected: p.includes(g.id),
995
+ onToggle: () => ee(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: j,
1010
+ disabled: P.isPending,
1011
+ children: P.isPending ? /* @__PURE__ */ o(I, { children: [
1012
+ /* @__PURE__ */ e(Z, { className: "mr-2 h-4 w-4 animate-spin" }),
1013
+ "Adding..."
1014
+ ] }) : /* @__PURE__ */ o(I, { 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 Mr({
1026
+ member: a,
1027
+ selected: n,
1028
+ onToggle: s
1029
+ }) {
1030
+ var i, c, u, m;
1031
+ const t = ((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: s,
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: t }) }),
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 Lr({
1049
+ user: a,
1050
+ selected: n,
1051
+ onToggle: s
1052
+ }) {
1053
+ var i;
1054
+ const t = ((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: s,
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: t }) }),
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 kr({
1072
+ open: a,
1073
+ onOpenChange: n
1074
+ }) {
1075
+ const [s, t] = N("groups"), [i, c] = N(""), [u, m] = N(null), [p, y] = N(!1), [h, r] = N(null), { tokenProps: d } = $(), { currentUser: f } = ma(), v = pr(), b = (f == null ? void 0 : f.type) === "tenant", S = d == null ? void 0 : d.tenantId, { groups: C, isLoading: P, refetch: U } = tt({
1076
+ type: b ? "TENANT_GROUP" : "all",
1077
+ tenantId: b ? S : void 0,
1078
+ includeMembers: !1
1079
+ }), _ = C.filter(
1080
+ (w) => {
1081
+ var j;
1082
+ return w.name.toLowerCase().includes(i.toLowerCase()) || ((j = w.description) == null ? void 0 : j.toLowerCase().includes(i.toLowerCase()));
1083
+ }
1084
+ ), V = async () => {
1085
+ if (h)
1086
+ try {
1087
+ await v.mutateAsync(h.id), r(null), U();
1088
+ } catch (w) {
1089
+ console.error("Failed to delete group:", w);
1090
+ }
1091
+ }, q = (w) => {
1092
+ m(w), y(!0);
1093
+ }, H = () => {
1094
+ t("groups"), U();
1095
+ };
1096
+ return /* @__PURE__ */ o(I, { 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(J, { 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: s, onValueChange: t, 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(J, { 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(J, { 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
+ Ir,
1135
+ {
1136
+ group: w,
1137
+ onManageMembers: () => q(w),
1138
+ onDelete: () => r(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
+ vr,
1146
+ {
1147
+ onSuccess: H,
1148
+ tenantId: S,
1149
+ isTenantUser: b
1150
+ }
1151
+ ) })
1152
+ ] })
1153
+ ] }) }),
1154
+ u && /* @__PURE__ */ e(
1155
+ Ar,
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: () => r(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: V,
1183
+ disabled: v.isPending,
1184
+ className: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
1185
+ children: v.isPending ? /* @__PURE__ */ o(I, { children: [
1186
+ /* @__PURE__ */ e(Z, { className: "mr-2 h-4 w-4 animate-spin" }),
1187
+ "Deleting..."
1188
+ ] }) : "Delete Group"
1189
+ }
1190
+ )
1191
+ ] })
1192
+ ] })
1193
+ }
1194
+ )
1195
+ ] });
1196
+ }
1197
+ function Ir({
1198
+ group: a,
1199
+ onManageMembers: n,
1200
+ onDelete: s,
1201
+ currentUserId: t
1202
+ }) {
1203
+ const i = a.createdBy === t;
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(J, { className: "h-3 w-3" }),
1213
+ a.memberCount,
1214
+ " ",
1215
+ a.memberCount === 1 ? "member" : "members"
1216
+ ] }),
1217
+ /* @__PURE__ */ o("span", { children: [
1218
+ "Created ",
1219
+ zt(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: s,
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, s) {
1249
+ var c, u;
1250
+ const t = (a.controls || []).find(
1251
+ (m) => m.id === s
1252
+ );
1253
+ if (t)
1254
+ return t.label;
1255
+ const i = (u = (c = ts(a, n)) == null ? void 0 : c.controls) == null ? void 0 : u.find(
1256
+ (m) => m.id === s
1257
+ );
1258
+ return (i == null ? void 0 : i.label) || s;
1259
+ }
1260
+ function le(a, n) {
1261
+ var s;
1262
+ return ((s = ts(a, n)) == null ? void 0 : s.title) || n;
1263
+ }
1264
+ function Or(a) {
1265
+ const { errors: n, dashboard: s } = a;
1266
+ if (!s)
1267
+ return n;
1268
+ const t = /* @__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, r] = c, d = `${h}:${r}:missing-metric`;
1275
+ t.has(d) || t.set(
1276
+ d,
1277
+ `"${le(s, h)}" has an outdated "${ie(
1278
+ s,
1279
+ h,
1280
+ r
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, r] = u, d = `${h}:${r}:missing-group-by`;
1290
+ t.has(d) || t.set(
1291
+ d,
1292
+ `"${le(s, h)}" has an outdated "${ie(
1293
+ s,
1294
+ h,
1295
+ r
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, r] = m, d = `${h}:${r}:invalid-metric`;
1305
+ t.has(d) || t.set(
1306
+ d,
1307
+ `"${le(s, h)}" has an invalid "${ie(
1308
+ s,
1309
+ h,
1310
+ r
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, r] = p, d = `${h}:${r}:invalid-group-by`;
1320
+ t.has(d) || t.set(
1321
+ d,
1322
+ `"${le(s, h)}" has an invalid "${ie(
1323
+ s,
1324
+ h,
1325
+ r
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, r] = y, d = `${h}:${r}:missing-temporal-group-by`;
1335
+ t.has(d) || t.set(
1336
+ d,
1337
+ `"${le(s, h)}" can no longer use "${ie(
1338
+ s,
1339
+ h,
1340
+ r
1341
+ )}" for time grain because the card does not currently group by a date field.`
1342
+ );
1343
+ continue;
1344
+ }
1345
+ t.set(i, i);
1346
+ }
1347
+ return Array.from(t.values());
1348
+ }
1349
+ function Hr() {
1350
+ var La, ka, Ia, Oa;
1351
+ Ut(), Gt();
1352
+ const {
1353
+ authToken: a,
1354
+ tokenProps: n,
1355
+ id: s
1356
+ } = $(), { isLocalDev: t } = rt(), { permissions: i } = lr(), c = nt(), { isLoading: u } = ot();
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), r = 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), [_, V] = N(!1), [q, H] = N(!1), [w, j] = N(!1), [ue, ee] = N(null), [Le, g] = N(!1), [E, O] = N(null), [F, z] = N([]), [ae, 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 se = 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 = se ? (ka = se == null ? void 0 : se.permissions) == null ? void 0 : ka.canEdit : (La = he == null ? void 0 : he.permissions) == null ? void 0 : La.canEdit, fe = x((l) => l.showFilters), va = it((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 } = lt(He.DASHBOARD), { data: Oe } = ct(), bs = ((Ia = Oe == null ? void 0 : Oe.preference) == null ? void 0 : Ia.defaultDashboardId) || null, { mutate: ys, isPending: Ns } = dt(), { currentUser: Ss } = ma(), xs = ut(Ss), X = se || he, xa = X ? {
1383
+ id: X.id,
1384
+ title: (r == null ? void 0 : r.title) || X.title || "Dashboard"
1385
+ } : null, { handleAddNewFrame: ws } = mt(), [Te, _e] = N(!1), [Ds, te] = N(!1), [Pe, ve] = N("close"), re = ht(He.DASHBOARD), [G, Ue] = N(
1386
+ null
1387
+ ), wa = Ua(
1388
+ (l) => {
1389
+ window.setTimeout(() => {
1390
+ ee(l);
1391
+ }, 0);
1392
+ },
1393
+ []
1394
+ ), Cs = async (l, L) => {
1395
+ if (!(r != null && r.id)) {
1396
+ console.log("No dashboard ID found");
1397
+ return;
1398
+ }
1399
+ console.log("Updating dashboard title:", {
1400
+ dashboardId: r.id,
1401
+ newTitle: l,
1402
+ previousTitle: L
1403
+ }), re.mutate(
1404
+ {
1405
+ resourceId: r.id,
1406
+ data: { title: l }
1407
+ },
1408
+ {
1409
+ onSuccess: () => {
1410
+ console.log("Dashboard title updated successfully"), k.success("Dashboard title updated");
1411
+ },
1412
+ onError: (R) => {
1413
+ console.error("Failed to update dashboard title:", R), k.error("Failed to update dashboard title"), f(L);
1414
+ }
1415
+ }
1416
+ );
1417
+ };
1418
+ Pt(() => {
1419
+ if (ge && ge.length > 0) {
1420
+ const l = r == null ? void 0 : r.id;
1421
+ if (l) {
1422
+ const L = ge.find(
1423
+ (R) => R.id === l
1424
+ );
1425
+ L && Sa(L);
1426
+ }
1427
+ }
1428
+ }, [ge, r == null ? void 0 : r.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), ee(null);
1433
+ };
1434
+ Rt(
1435
+ d,
1436
+ r,
1437
+ G,
1438
+ (l) => Ue(l)
1439
+ );
1440
+ const { isDirty: Ca, isDirtyPending: As, resetDirty: ye } = Qt(
1441
+ r,
1442
+ G,
1443
+ 300,
1444
+ 1e3,
1445
+ je
1446
+ ), Ea = Ua(() => G ? je(r) !== je(G) : !1, [r, G]), Fe = Ca || As, ne = Te || re.isPending, Ms = () => {
1447
+ Ea() ? (ve("close"), te(!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"), te(!1), ye();
1455
+ }, Is = () => {
1456
+ G && (Ge(G), ye());
1457
+ }, Os = () => {
1458
+ if (d && Ea()) {
1459
+ ve("home"), te(!0);
1460
+ return;
1461
+ }
1462
+ Ie();
1463
+ };
1464
+ async function $e(l) {
1465
+ const L = x.getState().dashboard;
1466
+ if (!L)
1467
+ return;
1468
+ const R = (l == null ? void 0 : l.closeAfterSave) ?? ae, Gs = (l == null ? void 0 : l.navigateHomeAfterSave) ?? !1;
1469
+ me(R), R && te(!1);
1470
+ const Rs = Tt(L);
1471
+ g(!0), O(null), z([]), _e(!0);
1472
+ const Fs = {
1473
+ template: L
1474
+ };
1475
+ re.mutate(
1476
+ {
1477
+ resourceId: L.id,
1478
+ data: Fs
1479
+ },
1480
+ {
1481
+ onSuccess: (T) => {
1482
+ var Ne, Se, Ta;
1483
+ const B = (T == null ? void 0 : T.id) || ((Ne = T == null ? void 0 : T.dashboard) == null ? void 0 : Ne.id) || ((Se = T == null ? void 0 : T.resource) == null ? void 0 : Se.id) || ((Ta = T == null ? void 0 : T.template) == null ? void 0 : Ta.id) || null;
1484
+ if (!L.id && B) {
1485
+ const qe = _t.getState(), xe = qe.pendingDashboardDraftMigration;
1486
+ (xe == null ? void 0 : xe.scopeKey) === m ? qe.actions.setPendingDashboardDraftMigrationExpectedDashboardId(
1487
+ B
1488
+ ) : xe && qe.actions.clearPendingDashboardDraftMigration();
1489
+ }
1490
+ _e(!1), k.success("Dashboard saved!"), Ue(Rs), g(!1), me(!1), R && (Re(), ye(), Gs && Ie()), ve("close");
1491
+ },
1492
+ onError: (T) => {
1493
+ _e(!1), O("Failed to save dashboard. Please try again.");
1494
+ const B = T.details, Ne = Array.isArray(
1495
+ B == null ? void 0 : B.errors
1496
+ ) ? (B.errors || []).filter(
1497
+ (Se) => typeof Se == "string"
1498
+ ) : [];
1499
+ z(
1500
+ Or({
1501
+ errors: Ne,
1502
+ dashboard: L || void 0
1503
+ })
1504
+ ), k.error("Failed to save dashboard");
1505
+ }
1506
+ }
1507
+ );
1508
+ }
1509
+ async function Ts() {
1510
+ if (b(!0), !y || !h) return;
1511
+ const l = x.getState().dashboard;
1512
+ if (!l) {
1513
+ b(!1);
1514
+ return;
1515
+ }
1516
+ const L = JSON.stringify(l), R = {
1517
+ ...h,
1518
+ template: L,
1519
+ filterValues: gs
1520
+ };
1521
+ await sa(
1522
+ n.apiServiceUrl,
1523
+ R,
1524
+ a == null ? void 0 : a.accessToken
1525
+ ), k.success("Lens saved"), ke == null || ke(l), b(!1);
1526
+ }
1527
+ const Aa = (h == null ? void 0 : h.name) || r.title;
1528
+ re.isPending && console.log("Title during update:", {
1529
+ title: Aa,
1530
+ dashboardStateTitle: r.title,
1531
+ dashboardId: r == null ? void 0 : r.id,
1532
+ currentLensName: h == null ? void 0 : h.name
1533
+ });
1534
+ const Ma = n.orgUserId || n.tenantId && n.endUserId && n.endUserEmail, _s = !!Ma && !!(a != null && a.accessToken) && !!(n != null && n.apiServiceUrl), Ps = c, oe = (r == null ? void 0 : r.id) || null, Ve = !!oe && bs === oe, Us = () => {
1535
+ oe && ys({
1536
+ dashboardId: Ve ? null : oe
1537
+ });
1538
+ };
1539
+ return /* @__PURE__ */ o(
1540
+ "div",
1541
+ {
1542
+ className: "flex h-11 shrink-0 items-center justify-between gap-2 overflow-x-auto border-b px-4 py-2",
1543
+ role: "dashboard-controls",
1544
+ children: [
1545
+ /* @__PURE__ */ o("div", { className: "flex items-center gap-2", children: [
1546
+ Ma && /* @__PURE__ */ o(I, { children: [
1547
+ /* @__PURE__ */ e(
1548
+ K,
1549
+ {
1550
+ "aria-label": "Manage Dashboards",
1551
+ tooltip: "Manage Dashboards",
1552
+ onClick: () => {
1553
+ fs(!ps);
1554
+ },
1555
+ className: "h-7 p-2",
1556
+ children: /* @__PURE__ */ e(Jt, { className: "h-4 w-4" })
1557
+ }
1558
+ ),
1559
+ Ps && !D && /* @__PURE__ */ e(
1560
+ K,
1561
+ {
1562
+ "aria-label": "Dashboard Hub",
1563
+ tooltip: "Dashboard Hub",
1564
+ onClick: Os,
1565
+ className: "h-7 p-2",
1566
+ children: /* @__PURE__ */ e(Ha, { className: "h-4 w-4" })
1567
+ }
1568
+ )
1569
+ ] }),
1570
+ !D && c && (u ? /* @__PURE__ */ e(
1571
+ "div",
1572
+ {
1573
+ className: "h-4 w-28 rounded-md bg-muted/70 animate-pulse",
1574
+ "aria-label": "Loading dashboard title",
1575
+ role: "status",
1576
+ children: /* @__PURE__ */ e("span", { className: "sr-only", children: "Loading dashboard title" })
1577
+ }
1578
+ ) : /* @__PURE__ */ o(I, { children: [
1579
+ /* @__PURE__ */ e(
1580
+ pt,
1581
+ {
1582
+ value: Aa || "Untitled Dashboard",
1583
+ onSave: (l) => {
1584
+ console.log("EditableText onSave called:", {
1585
+ newTitle: l,
1586
+ canEditDashboard: pe,
1587
+ dashboardId: r == null ? void 0 : r.id
1588
+ });
1589
+ const L = (r == null ? void 0 : r.title) || "";
1590
+ f(l), Cs(l, L);
1591
+ },
1592
+ isEditable: pe && !h,
1593
+ displayClassName: "text-sm font-medium",
1594
+ inputClassName: "text-sm font-medium",
1595
+ placeholder: "Dashboard Title",
1596
+ isPending: re.isPending
1597
+ }
1598
+ ),
1599
+ _s && oe && /* @__PURE__ */ e(ft, { children: /* @__PURE__ */ o(gt, { children: [
1600
+ /* @__PURE__ */ e(vt, { asChild: !0, children: /* @__PURE__ */ e(
1601
+ M,
1602
+ {
1603
+ variant: "ghost",
1604
+ size: "icon",
1605
+ onClick: Us,
1606
+ disabled: Ns || !(a != null && a.accessToken) || !(n != null && n.apiServiceUrl),
1607
+ className: "h-7 w-7",
1608
+ children: /* @__PURE__ */ e(
1609
+ bt,
1610
+ {
1611
+ className: Y(
1612
+ "h-4 w-4 transition-colors",
1613
+ Ve ? "fill-yellow-400 text-yellow-400" : "text-muted-foreground hover:text-yellow-400"
1614
+ )
1615
+ }
1616
+ )
1617
+ }
1618
+ ) }),
1619
+ /* @__PURE__ */ e(yt, { children: /* @__PURE__ */ e("p", { children: Ve ? "Remove as default dashboard" : "Make this a default dashboard" }) })
1620
+ ] }) })
1621
+ ] }))
1622
+ ] }),
1623
+ /* @__PURE__ */ o("div", { className: "flex items-center gap-2", children: [
1624
+ D && /* @__PURE__ */ o(I, { children: [
1625
+ /* @__PURE__ */ e(Ft, { className: "mr-2" }),
1626
+ /* @__PURE__ */ e($t, { className: "h-7" })
1627
+ ] }),
1628
+ t && !D && /* @__PURE__ */ o(I, { children: [
1629
+ /* @__PURE__ */ e(
1630
+ K,
1631
+ {
1632
+ tooltip: "Copy Token",
1633
+ onClick: () => {
1634
+ var l;
1635
+ a != null && a.accessToken && ((l = navigator == null ? void 0 : navigator.clipboard) != null && l.writeText ? navigator.clipboard.writeText(a.accessToken).then(() => k.success("Token copied to clipboard")).catch(() => k.error("Unable to copy token")) : k.error("Clipboard not available"));
1636
+ },
1637
+ className: "h-7 p-2",
1638
+ children: /* @__PURE__ */ e(Nt, { className: "h-4 w-4" })
1639
+ }
1640
+ ),
1641
+ /* @__PURE__ */ e(
1642
+ K,
1643
+ {
1644
+ tooltip: "Invalidate Token",
1645
+ onClick: () => St(n.apiServiceUrl),
1646
+ className: "h-7 p-2",
1647
+ children: /* @__PURE__ */ e(Yt, { className: "h-4 w-4" })
1648
+ }
1649
+ )
1650
+ ] }),
1651
+ !D && c && /* @__PURE__ */ e(xt, {}),
1652
+ !D && c && /* @__PURE__ */ e(Vt, {}),
1653
+ !D && c && ((Oa = X == null ? void 0 : X.permissions) == null ? void 0 : Oa.canShare) && /* @__PURE__ */ e(
1654
+ K,
1655
+ {
1656
+ tooltip: "Share Dashboard",
1657
+ onClick: () => C(!0),
1658
+ className: "h-7 p-2",
1659
+ children: /* @__PURE__ */ e(wt, { className: "h-4 w-4" })
1660
+ }
1661
+ ),
1662
+ !D && d && i.canUseFilters && c && /* @__PURE__ */ e(
1663
+ qt,
1664
+ {
1665
+ showFilters: fe,
1666
+ onToggleFilters: () => {
1667
+ fe || va("dashboard", !1), ba(!fe);
1668
+ },
1669
+ onAddFilter: () => {
1670
+ fe || (va("dashboard", !1), ba(!0));
1671
+ },
1672
+ onAddControl: () => {
1673
+ wa("create");
1674
+ },
1675
+ onManageControls: () => wa("manage")
1676
+ }
1677
+ ),
1678
+ d && !D && c && ue ? /* @__PURE__ */ e(
1679
+ Ht,
1680
+ {
1681
+ open: !0,
1682
+ onOpenChange: (l) => {
1683
+ l || ee(null);
1684
+ },
1685
+ showTrigger: !1,
1686
+ initialMode: ue
1687
+ }
1688
+ ) : null,
1689
+ d && !D && be && t && c && /* @__PURE__ */ e(or, {}),
1690
+ !D && be && t && c && /* @__PURE__ */ e(ir, {}),
1691
+ d && !D && be && h && t && c && /* @__PURE__ */ o(
1692
+ M,
1693
+ {
1694
+ className: "h-7 p-2",
1695
+ variant: "secondary",
1696
+ disabled: v,
1697
+ onClick: Ts,
1698
+ size: "sm",
1699
+ children: [
1700
+ /* @__PURE__ */ e(Ga, { className: "mr-2 h-4 w-4" }),
1701
+ "Save Lens"
1702
+ ]
1703
+ }
1704
+ ),
1705
+ d && !D && c && /* @__PURE__ */ o(
1706
+ M,
1707
+ {
1708
+ variant: "outline",
1709
+ className: "h-7 p-2",
1710
+ size: "sm",
1711
+ disabled: !d,
1712
+ onClick: () => ws(),
1713
+ children: [
1714
+ /* @__PURE__ */ e(la, { className: "mr-2 h-4 w-4" }),
1715
+ "Visual"
1716
+ ]
1717
+ }
1718
+ ),
1719
+ !D && !d && pe && c && /* @__PURE__ */ o(
1720
+ M,
1721
+ {
1722
+ variant: "outline",
1723
+ className: "h-7 p-2",
1724
+ onClick: Es,
1725
+ size: "sm",
1726
+ children: [
1727
+ /* @__PURE__ */ e(Dt, { className: "mr-2 h-4 w-4" }),
1728
+ "Edit"
1729
+ ]
1730
+ }
1731
+ ),
1732
+ Da && c && Ca && /* @__PURE__ */ o(
1733
+ M,
1734
+ {
1735
+ variant: "outline",
1736
+ className: "h-7 p-2",
1737
+ onClick: Is,
1738
+ size: "sm",
1739
+ disabled: ne,
1740
+ children: [
1741
+ /* @__PURE__ */ e(Ct, { className: "mr-2 h-4 w-4" }),
1742
+ "Undo"
1743
+ ]
1744
+ }
1745
+ ),
1746
+ Da && c && /* @__PURE__ */ o("div", { className: "relative inline-flex", children: [
1747
+ /* @__PURE__ */ o(
1748
+ M,
1749
+ {
1750
+ className: Y("h-7 p-2", !Fe && "opacity-60"),
1751
+ disabled: ne || !Fe,
1752
+ onClick: () => $e(),
1753
+ size: "sm",
1754
+ children: [
1755
+ ne ? /* @__PURE__ */ e(Z, { className: "mr-2 h-4 w-4 animate-spin" }) : /* @__PURE__ */ e(Ga, { className: "mr-2 h-4 w-4" }),
1756
+ ne ? "Saving..." : "Save"
1757
+ ]
1758
+ }
1759
+ ),
1760
+ Fe && !ne && /* @__PURE__ */ e(
1761
+ "span",
1762
+ {
1763
+ "aria-hidden": "true",
1764
+ className: "pointer-events-none absolute -right-1 -top-1 h-2.5 w-2.5 rounded-full bg-orange-500 ring-2 ring-background"
1765
+ }
1766
+ )
1767
+ ] }),
1768
+ !D && d && t && c && /* @__PURE__ */ e("div", { className: "flex items-center space-x-2", children: /* @__PURE__ */ e(
1769
+ M,
1770
+ {
1771
+ className: "h-7 p-2",
1772
+ onClick: () => Na(!vs),
1773
+ size: "sm",
1774
+ variant: "ghost",
1775
+ children: /* @__PURE__ */ e(Et, { className: "h-4 w-4" })
1776
+ }
1777
+ ) }),
1778
+ !D && t && /* @__PURE__ */ e(tr, {}),
1779
+ d && !D && c && /* @__PURE__ */ o(
1780
+ M,
1781
+ {
1782
+ variant: "outline",
1783
+ className: "h-7 p-2",
1784
+ onClick: Ms,
1785
+ children: [
1786
+ /* @__PURE__ */ e(ja, { className: "mr-2 h-4 w-4" }),
1787
+ "Close"
1788
+ ]
1789
+ }
1790
+ ),
1791
+ !D && c && /* @__PURE__ */ o(ta, { children: [
1792
+ /* @__PURE__ */ e(ra, { asChild: !0, children: /* @__PURE__ */ e(
1793
+ K,
1794
+ {
1795
+ tooltip: "More Options",
1796
+ className: "h-8 w-8 rounded-md border border-transparent p-0 text-muted-foreground hover:bg-muted/50 hover:text-foreground",
1797
+ buttonProps: { "aria-label": "More dashboard options" },
1798
+ children: /* @__PURE__ */ e(At, { className: "h-4 w-4" })
1799
+ }
1800
+ ) }),
1801
+ /* @__PURE__ */ o(
1802
+ na,
1803
+ {
1804
+ align: "end",
1805
+ className: "w-56 rounded-xl border border-border/60 p-1 shadow-sm",
1806
+ children: [
1807
+ /* @__PURE__ */ e(De, { className: "px-2.5 text-xs font-medium text-muted-foreground", children: "Automation" }),
1808
+ /* @__PURE__ */ o(
1809
+ Q,
1810
+ {
1811
+ onClick: () => V(!0),
1812
+ className: "flex items-center gap-2",
1813
+ children: [
1814
+ /* @__PURE__ */ e(Mt, { className: "mr-2 h-4 w-4" }),
1815
+ "Schedule Dashboard"
1816
+ ]
1817
+ }
1818
+ ),
1819
+ /* @__PURE__ */ e(Qe, {}),
1820
+ xs && /* @__PURE__ */ o(I, { children: [
1821
+ /* @__PURE__ */ e(De, { className: "px-2.5 text-xs font-medium text-muted-foreground", children: "Access" }),
1822
+ /* @__PURE__ */ o(
1823
+ Q,
1824
+ {
1825
+ onClick: () => U(!0),
1826
+ className: "flex items-center gap-2",
1827
+ children: [
1828
+ /* @__PURE__ */ e(J, { className: "mr-2 h-4 w-4" }),
1829
+ "Manage Groups"
1830
+ ]
1831
+ }
1832
+ ),
1833
+ /* @__PURE__ */ e(Qe, {})
1834
+ ] }),
1835
+ /* @__PURE__ */ e(De, { className: "px-2.5 text-xs font-medium text-muted-foreground", children: "Preferences" }),
1836
+ /* @__PURE__ */ o(
1837
+ Q,
1838
+ {
1839
+ onClick: () => H(!0),
1840
+ className: "flex items-center gap-2",
1841
+ children: [
1842
+ /* @__PURE__ */ e(Lt, { className: "mr-2 h-4 w-4" }),
1843
+ "Calendar Preferences"
1844
+ ]
1845
+ }
1846
+ ),
1847
+ /* @__PURE__ */ o(
1848
+ Q,
1849
+ {
1850
+ onClick: () => j(!0),
1851
+ className: "flex items-center gap-2",
1852
+ children: [
1853
+ /* @__PURE__ */ e(kt, { className: "mr-2 h-4 w-4" }),
1854
+ "Summary Settings"
1855
+ ]
1856
+ }
1857
+ )
1858
+ ]
1859
+ }
1860
+ )
1861
+ ] }),
1862
+ S && xa && /* @__PURE__ */ e(
1863
+ It,
1864
+ {
1865
+ resource: xa,
1866
+ resourceType: He.DASHBOARD,
1867
+ onClose: () => C(!1)
1868
+ }
1869
+ ),
1870
+ /* @__PURE__ */ e(
1871
+ kr,
1872
+ {
1873
+ open: P,
1874
+ onOpenChange: U
1875
+ }
1876
+ ),
1877
+ (r == null ? void 0 : r.id) && /* @__PURE__ */ e(
1878
+ Ot,
1879
+ {
1880
+ open: _,
1881
+ onOpenChange: V,
1882
+ dashboardId: r.id,
1883
+ dashboardName: r == null ? void 0 : r.title
1884
+ }
1885
+ ),
1886
+ /* @__PURE__ */ e(
1887
+ Bt,
1888
+ {
1889
+ open: q,
1890
+ onOpenChange: H
1891
+ }
1892
+ ),
1893
+ /* @__PURE__ */ e(
1894
+ Kt,
1895
+ {
1896
+ open: w,
1897
+ onOpenChange: j,
1898
+ dashboard: r,
1899
+ disabled: !d,
1900
+ onApply: (l) => Ge({
1901
+ ...r,
1902
+ summary: l
1903
+ })
1904
+ }
1905
+ ),
1906
+ /* @__PURE__ */ e(
1907
+ Ja,
1908
+ {
1909
+ open: Le,
1910
+ onOpenChange: (l) => {
1911
+ !l && Te && !E || (g(l), l || (O(null), z([]), me(!1)));
1912
+ },
1913
+ children: /* @__PURE__ */ o(Xa, { className: "max-w-sm", children: [
1914
+ /* @__PURE__ */ o(Ya, { children: [
1915
+ /* @__PURE__ */ e(Za, { children: E ? "Save failed" : "Saving dashboard" }),
1916
+ /* @__PURE__ */ e(es, { className: "pt-2", children: E ? "We could not save the dashboard. Please try again." : "Please wait while we save your changes." }),
1917
+ F.length > 0 && /* @__PURE__ */ o("div", { className: "space-y-1 rounded-md border border-destructive/20 bg-destructive/5 p-3 text-left", children: [
1918
+ /* @__PURE__ */ e("div", { className: "text-sm font-medium text-destructive", children: "What needs attention" }),
1919
+ /* @__PURE__ */ e("ul", { className: "list-disc space-y-1 pl-4 text-xs text-muted-foreground", children: F.slice(0, 5).map((l) => /* @__PURE__ */ e("li", { children: l }, l)) })
1920
+ ] })
1921
+ ] }),
1922
+ /* @__PURE__ */ e(as, { className: "flex-col gap-2 sm:flex-row sm:justify-end", children: E ? /* @__PURE__ */ o(I, { children: [
1923
+ /* @__PURE__ */ e(
1924
+ ss,
1925
+ {
1926
+ onClick: () => {
1927
+ g(!1), O(null), z([]), me(!1);
1928
+ },
1929
+ className: "m-0",
1930
+ children: "Close"
1931
+ }
1932
+ ),
1933
+ /* @__PURE__ */ e(
1934
+ ea,
1935
+ {
1936
+ onClick: () => $e({
1937
+ closeAfterSave: ae,
1938
+ navigateHomeAfterSave: Pe === "home"
1939
+ }),
1940
+ className: "m-0",
1941
+ children: "Retry"
1942
+ }
1943
+ )
1944
+ ] }) : /* @__PURE__ */ o(
1945
+ ea,
1946
+ {
1947
+ disabled: !0,
1948
+ className: "m-0 cursor-default",
1949
+ children: [
1950
+ /* @__PURE__ */ e(Z, { className: "mr-2 h-4 w-4 animate-spin" }),
1951
+ "Saving..."
1952
+ ]
1953
+ }
1954
+ ) })
1955
+ ] })
1956
+ }
1957
+ ),
1958
+ /* @__PURE__ */ e(
1959
+ jt,
1960
+ {
1961
+ open: Ds,
1962
+ onOpenChange: (l) => {
1963
+ te(l);
1964
+ },
1965
+ onSave: Ls,
1966
+ onDiscard: ks,
1967
+ isSaving: Te,
1968
+ saveLabel: "Save",
1969
+ discardLabel: "Discard"
1970
+ }
1971
+ )
1972
+ ] })
1973
+ ]
1974
+ }
1975
+ );
1976
+ }
1977
+ export {
1978
+ Hr as default
1979
+ };