react-semaphor 0.1.292 → 0.1.293

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