react-semaphor 0.1.126 → 0.1.128

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/dashboard-controls-Dd27T34x.js +26 -0
  2. package/dist/chunks/dashboard-controls-I6kqudDF.js +1539 -0
  3. package/dist/chunks/dashboard-export-dialog-CiZbDQ5t.js +6 -0
  4. package/dist/chunks/dashboard-export-dialog-DEOlAtvs.js +601 -0
  5. package/dist/chunks/{dashboard-json-DpgglXTM.js → dashboard-json-A6ShtMJP.js} +1 -1
  6. package/dist/chunks/{dashboard-json-B7_R2nwz.js → dashboard-json-D_muUlA0.js} +1 -1
  7. package/dist/chunks/edit-dashboard-visual-BgRPk31F.js +195 -0
  8. package/dist/chunks/{edit-dashboard-visual-Dfdl-K74.js → edit-dashboard-visual-KhJjpeit.js} +5966 -4980
  9. package/dist/chunks/{editor-action-buttons-CsV8nUOI.js → editor-action-buttons-cJ_lq4jv.js} +1 -1
  10. package/dist/chunks/{editor-action-buttons-CMKMrnww.js → editor-action-buttons-umPHWm3K.js} +2 -2
  11. package/dist/chunks/{index-BdiWSBWd.js → index-Bko2LZ3Y.js} +5816 -5795
  12. package/dist/chunks/{index-GG6fcfuj.js → index-CM_yfKlN.js} +192 -187
  13. package/dist/chunks/{resource-management-panel-CdC7mFhx.js → resource-management-panel-DAdIhRme.js} +88 -88
  14. package/dist/chunks/{resource-management-panel-3Q8phtkW.js → resource-management-panel-DvgyBS2t.js} +1 -1
  15. package/dist/chunks/{use-visual-utils-BE_5Rl3X.js → use-visual-utils-80E0OR0x.js} +1 -1
  16. package/dist/chunks/{use-visual-utils-CxVLCLOf.js → use-visual-utils-C7QMpNLz.js} +8 -8
  17. package/dist/dashboard/index.cjs +1 -1
  18. package/dist/dashboard/index.js +1 -1
  19. package/dist/index.cjs +2 -2
  20. package/dist/index.js +88 -87
  21. package/dist/style.css +1 -1
  22. package/dist/surfboard/index.cjs +1 -1
  23. package/dist/surfboard/index.js +1 -1
  24. package/dist/types/dashboard.d.ts +1 -1
  25. package/dist/types/main.d.ts +19 -43
  26. package/dist/types/surfboard.d.ts +1 -1
  27. package/dist/types/types.d.ts +1 -1
  28. package/package.json +1 -1
  29. package/dist/chunks/dashboard-controls-BktHa763.js +0 -1473
  30. package/dist/chunks/dashboard-controls-DucLNOji.js +0 -26
  31. package/dist/chunks/dashboard-export-dialog-BNjL5KSw.js +0 -600
  32. package/dist/chunks/dashboard-export-dialog-M318NGd7.js +0 -6
  33. package/dist/chunks/edit-dashboard-visual-BaNXGTU-.js +0 -170
@@ -0,0 +1,1539 @@
1
+ import { jsxs as n, jsx as e, Fragment as I } from "react/jsx-runtime";
2
+ import { b as X, bB as qs, bC as _s, u as y, aF as Je, aG as Ke, B as k, aI as We, aJ as fe, bD as Me, g as Xe, am as U, ar as ke, bE as $s, b7 as Le, as as Ae, at as Ie, au as Ee, av as Ye, aw as be, b0 as W, aA as js, I as q, bF as Vs, bb as Qs, bG as Hs, bH as Ve, bI as Ze, c as Y, bJ as es, b3 as Bs, h as le, bK as ce, l as L, bL as ss, ay as Js, bM as Ks, L as _, ba as $, bN as Ws, bO as Xs, bP as Ys, bQ as as, bR as ts, bS as oe, bT as ie, by as Ne, bi as ye, bU as we, bc as rs, bV as xe, az as ns, bg as os, bW as Zs, aN as is, aO as ls, aP as cs, aR as ds, aS as us, aT as ms, aU as hs, aV as Ce, bX as ea, b5 as sa, bt as aa, bY as ta, bZ as ra, f as Qe, aD as re, b_ as na, R as ve, b$ as oa, c0 as ia, c1 as la, c2 as ca, b8 as da, T as ua, c3 as ma, c4 as ha, c5 as pa, c6 as ga, J as fa, Q as va } from "./index-Bko2LZ3Y.js";
3
+ import * as D from "react";
4
+ import { useState as b, useMemo as ne, useEffect as ba } from "react";
5
+ import "react-dom";
6
+ import { D as Na, u as ya, A as wa, V as xa, S as Ca, U as Da } from "./dashboard-export-dialog-DEOlAtvs.js";
7
+ import { S as He } from "./editor-action-buttons-umPHWm3K.js";
8
+ /**
9
+ * @license lucide-react v0.453.0 - ISC
10
+ *
11
+ * This source code is licensed under the ISC license.
12
+ * See the LICENSE file in the root directory of this source tree.
13
+ */
14
+ const Sa = X("Glasses", [
15
+ ["circle", { cx: "6", cy: "15", r: "4", key: "vux9w4" }],
16
+ ["circle", { cx: "18", cy: "15", r: "4", key: "18o8ve" }],
17
+ ["path", { d: "M14 15a2 2 0 0 0-2-2 2 2 0 0 0-2 2", key: "1ag4bs" }],
18
+ ["path", { d: "M2.5 13 5 7c.7-1.3 1.4-2 3-2", key: "1hm1gs" }],
19
+ ["path", { d: "M21.5 13 19 7c-.7-1.3-1.5-2-3-2", key: "1r31ai" }]
20
+ ]);
21
+ /**
22
+ * @license lucide-react v0.453.0 - ISC
23
+ *
24
+ * This source code is licensed under the ISC license.
25
+ * See the LICENSE file in the root directory of this source tree.
26
+ */
27
+ const Ma = X("Menu", [
28
+ ["line", { x1: "4", x2: "20", y1: "12", y2: "12", key: "1e0a9i" }],
29
+ ["line", { x1: "4", x2: "20", y1: "6", y2: "6", key: "1owob3" }],
30
+ ["line", { x1: "4", x2: "20", y1: "18", y2: "18", key: "yk5zj1" }]
31
+ ]);
32
+ /**
33
+ * @license lucide-react v0.453.0 - ISC
34
+ *
35
+ * This source code is licensed under the ISC license.
36
+ * See the LICENSE file in the root directory of this source tree.
37
+ */
38
+ const ka = X("Moon", [
39
+ ["path", { d: "M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z", key: "a7tn18" }]
40
+ ]);
41
+ /**
42
+ * @license lucide-react v0.453.0 - ISC
43
+ *
44
+ * This source code is licensed under the ISC license.
45
+ * See the LICENSE file in the root directory of this source tree.
46
+ */
47
+ const La = X("ShieldX", [
48
+ [
49
+ "path",
50
+ {
51
+ 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",
52
+ key: "oel41y"
53
+ }
54
+ ],
55
+ ["path", { d: "m14.5 9.5-5 5", key: "17q4r4" }],
56
+ ["path", { d: "m9.5 9.5 5 5", key: "18nt4w" }]
57
+ ]);
58
+ /**
59
+ * @license lucide-react v0.453.0 - ISC
60
+ *
61
+ * This source code is licensed under the ISC license.
62
+ * See the LICENSE file in the root directory of this source tree.
63
+ */
64
+ const Aa = X("Sun", [
65
+ ["circle", { cx: "12", cy: "12", r: "4", key: "4exip2" }],
66
+ ["path", { d: "M12 2v2", key: "tus03m" }],
67
+ ["path", { d: "M12 20v2", key: "1lh1kg" }],
68
+ ["path", { d: "m4.93 4.93 1.41 1.41", key: "149t6j" }],
69
+ ["path", { d: "m17.66 17.66 1.41 1.41", key: "ptbguv" }],
70
+ ["path", { d: "M2 12h2", key: "1t8f8n" }],
71
+ ["path", { d: "M20 12h2", key: "1q8mjw" }],
72
+ ["path", { d: "m6.34 17.66-1.41 1.41", key: "1m8zz5" }],
73
+ ["path", { d: "m19.07 4.93-1.41 1.41", key: "1shlcs" }]
74
+ ]);
75
+ var Ia = qs();
76
+ function Ea() {
77
+ const { setTheme: s } = _s(), r = y(
78
+ (a) => a.actions.setDashboardTheme
79
+ );
80
+ return /* @__PURE__ */ n(Je, { children: [
81
+ /* @__PURE__ */ e(Ke, { asChild: !0, children: /* @__PURE__ */ n(k, { className: "h-7 p-2", variant: "ghost", size: "sm", children: [
82
+ /* @__PURE__ */ e(
83
+ Aa,
84
+ {
85
+ strokeWidth: 1.5,
86
+ className: "h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0"
87
+ }
88
+ ),
89
+ /* @__PURE__ */ e(
90
+ ka,
91
+ {
92
+ strokeWidth: 1.5,
93
+ className: "absolute h-4 w-4 rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100"
94
+ }
95
+ ),
96
+ /* @__PURE__ */ e("span", { className: "sr-only", children: "Toggle theme" })
97
+ ] }) }),
98
+ /* @__PURE__ */ n(We, { align: "end", children: [
99
+ /* @__PURE__ */ e(
100
+ fe,
101
+ {
102
+ onClick: () => {
103
+ s("light"), r("light");
104
+ },
105
+ children: "Light"
106
+ }
107
+ ),
108
+ /* @__PURE__ */ e(
109
+ fe,
110
+ {
111
+ onClick: () => {
112
+ s("dark"), r("dark");
113
+ },
114
+ children: "Dark"
115
+ }
116
+ ),
117
+ /* @__PURE__ */ e(
118
+ fe,
119
+ {
120
+ onClick: () => {
121
+ s("system"), r("system");
122
+ },
123
+ children: "System"
124
+ }
125
+ )
126
+ ] })
127
+ ] });
128
+ }
129
+ async function Ta(s, r, a, t, l) {
130
+ if (!l)
131
+ return null;
132
+ const o = JSON.stringify(a), c = `${s}/v1/lens`;
133
+ return await Me(c, l, {
134
+ name: r,
135
+ template: o,
136
+ filterValues: t,
137
+ operation: "create"
138
+ });
139
+ }
140
+ async function De(s, r, a) {
141
+ if (!a)
142
+ return null;
143
+ const { id: t, template: l, filterValues: o, isDefault: c, shared: u } = r, p = `${s}/v1/lens`;
144
+ return await Me(p, a, {
145
+ lensId: t,
146
+ template: l,
147
+ filterValues: o,
148
+ isDefault: c,
149
+ shared: u,
150
+ operation: "update"
151
+ });
152
+ }
153
+ async function Pa(s, r, a) {
154
+ if (!a)
155
+ return null;
156
+ const t = `${s}/v1/lens`;
157
+ return await Me(t, a, {
158
+ operation: "delete",
159
+ lensId: r
160
+ });
161
+ }
162
+ function Ga() {
163
+ const [s, r] = b(""), [a, t] = b(!1), l = y((C) => C.lenses), { setLenses: o, setSelectedLensId: c } = Xe(), [u, p] = b(!1), [f, d] = b(!1), m = y((C) => C.dashboard), g = y((C) => C.filterValues), { authToken: v, tokenProps: N } = U();
164
+ async function w() {
165
+ p(!0);
166
+ const C = await Ta(
167
+ N.apiServiceUrl,
168
+ s,
169
+ m,
170
+ g,
171
+ v == null ? void 0 : v.accessToken
172
+ );
173
+ C && (o([...l || [], C]), c(C.id), d(!1)), p(!1);
174
+ }
175
+ return /* @__PURE__ */ n(ke, { open: f, onOpenChange: d, children: [
176
+ /* @__PURE__ */ e($s, { asChild: !0, children: /* @__PURE__ */ n(
177
+ k,
178
+ {
179
+ variant: "secondary",
180
+ className: "h-7 p-2",
181
+ size: "sm",
182
+ children: [
183
+ /* @__PURE__ */ e(Le, { className: "mr-2 h-4 w-4" }),
184
+ "Lens"
185
+ ]
186
+ }
187
+ ) }),
188
+ /* @__PURE__ */ n(Ae, { className: "sm:max-w-[425px]", children: [
189
+ /* @__PURE__ */ n(Ie, { children: [
190
+ /* @__PURE__ */ e(Ee, { children: "Create Lens" }),
191
+ /* @__PURE__ */ e(Ye, { children: "Lenses are private by default and are only visible to you." })
192
+ ] }),
193
+ /* @__PURE__ */ e("div", { className: "grid gap-4 py-4", children: /* @__PURE__ */ n("div", { className: "grid grid-cols-8 items-center gap-4", children: [
194
+ /* @__PURE__ */ e(be, { className: "text-right", children: "Name" }),
195
+ /* @__PURE__ */ e(
196
+ W,
197
+ {
198
+ value: s,
199
+ onChange: (C) => {
200
+ r(C.target.value);
201
+ },
202
+ id: "name",
203
+ className: "col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"
204
+ }
205
+ )
206
+ ] }) }),
207
+ a && /* @__PURE__ */ e("p", { className: "text-sm", children: "The lens name already exists. Use a differnet name." }),
208
+ /* @__PURE__ */ e(js, { children: /* @__PURE__ */ e(
209
+ k,
210
+ {
211
+ size: "sm",
212
+ variant: "outline",
213
+ type: "submit",
214
+ onClick: w,
215
+ disabled: u,
216
+ children: u ? "Creating..." : "Add"
217
+ }
218
+ ) })
219
+ ] })
220
+ ] });
221
+ }
222
+ function Fa() {
223
+ const [s, r] = b(!1), a = y((m) => m.lenses), t = y((m) => m.selectedLensId), { setLenses: l, setSelectedLensId: o } = Xe(), { authToken: c, tokenProps: u } = U();
224
+ async function p(m) {
225
+ o(m);
226
+ }
227
+ async function f(m) {
228
+ if (await Pa(u.apiServiceUrl, m, c == null ? void 0 : c.accessToken)) {
229
+ const v = a == null ? void 0 : a.filter((N) => N.id !== m);
230
+ l(v || []), o("original");
231
+ }
232
+ }
233
+ async function d(m) {
234
+ const g = a == null ? void 0 : a.map((w) => w.id === m.id ? {
235
+ ...w,
236
+ isDefault: !m.isDefault
237
+ } : {
238
+ ...w,
239
+ isDefault: !1
240
+ });
241
+ l(g || []);
242
+ const v = {
243
+ ...m,
244
+ isDefault: !m.isDefault
245
+ };
246
+ await De(u.apiServiceUrl, v, c == null ? void 0 : c.accessToken);
247
+ const N = a == null ? void 0 : a.find((w) => w.isDefault);
248
+ if (N && N.id !== m.id) {
249
+ const w = {
250
+ ...N,
251
+ isDefault: !1
252
+ };
253
+ await De(u.apiServiceUrl, w, c == null ? void 0 : c.accessToken);
254
+ }
255
+ }
256
+ return /* @__PURE__ */ n(Je, { open: s, onOpenChange: r, children: [
257
+ /* @__PURE__ */ e(Ke, { asChild: !0, children: /* @__PURE__ */ e(q, { tooltip: "Lenses", className: "h-7 p-2", children: /* @__PURE__ */ e(Sa, { className: "h-4 w-4" }) }) }),
258
+ /* @__PURE__ */ n(We, { align: "end", className: "w-60", children: [
259
+ /* @__PURE__ */ e(Vs, { className: "px-3", children: "Lenses" }),
260
+ /* @__PURE__ */ e(Qs, {}),
261
+ /* @__PURE__ */ n(
262
+ Hs,
263
+ {
264
+ value: t,
265
+ onValueChange: p,
266
+ children: [
267
+ /* @__PURE__ */ e(Ve, { value: "original", children: "Original" }),
268
+ a == null ? void 0 : a.map((m) => /* @__PURE__ */ n(
269
+ Ve,
270
+ {
271
+ className: "group flex justify-between gap-2",
272
+ value: m.id,
273
+ children: [
274
+ /* @__PURE__ */ e("p", { children: m.name }),
275
+ /* @__PURE__ */ n("span", { className: "flex items-center gap-3", children: [
276
+ /* @__PURE__ */ e(
277
+ Ze,
278
+ {
279
+ onClick: (g) => {
280
+ g.preventDefault(), d(m);
281
+ },
282
+ className: Y(
283
+ "size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",
284
+ {
285
+ invisible: !m.isDefault,
286
+ "text-green-500": m.isDefault
287
+ }
288
+ ),
289
+ strokeWidth: 1.5
290
+ }
291
+ ),
292
+ /* @__PURE__ */ e(
293
+ es,
294
+ {
295
+ onClick: (g) => {
296
+ g.preventDefault(), f(m.id);
297
+ },
298
+ className: "invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",
299
+ strokeWidth: 1.5
300
+ }
301
+ )
302
+ ] })
303
+ ]
304
+ },
305
+ m.id
306
+ ))
307
+ ]
308
+ }
309
+ )
310
+ ] })
311
+ ] });
312
+ }
313
+ function Oa({
314
+ iconClassName: s
315
+ }) {
316
+ const [r, a] = b(!1), t = y((l) => l.isDownloadingPdf);
317
+ return /* @__PURE__ */ n(I, { children: [
318
+ /* @__PURE__ */ e(
319
+ k,
320
+ {
321
+ variant: "ghost",
322
+ size: "sm",
323
+ className: "h-7 p-2",
324
+ disabled: t,
325
+ onClick: () => a(!0),
326
+ children: /* @__PURE__ */ e(Bs, { className: Y("size-4", s) })
327
+ }
328
+ ),
329
+ /* @__PURE__ */ e(
330
+ Na,
331
+ {
332
+ open: r,
333
+ onOpenChange: a
334
+ }
335
+ )
336
+ ] });
337
+ }
338
+ const Ra = async (s, r, a) => {
339
+ const t = `${s}/management/v1/groups`;
340
+ return await ss(t, r, a);
341
+ }, Ua = async (s, r, a) => {
342
+ const t = `${s}/management/v1/groups/${a}`, l = await fetch(t, {
343
+ method: "DELETE",
344
+ headers: {
345
+ Authorization: `Bearer ${r}`
346
+ }
347
+ });
348
+ if (!l.ok) {
349
+ const o = await l.text();
350
+ throw new Error(o || "Failed to delete group");
351
+ }
352
+ }, za = async (s, r, a, t) => {
353
+ const l = `${s}/management/v1/groups/${a}/members`;
354
+ return await ss(l, r, t);
355
+ }, qa = async (s, r, a, t) => {
356
+ const l = `${s}/management/v1/groups/${a}/members`, o = await fetch(l, {
357
+ method: "DELETE",
358
+ headers: {
359
+ "Content-Type": "application/json",
360
+ Authorization: `Bearer ${r}`
361
+ },
362
+ body: JSON.stringify(t)
363
+ });
364
+ if (!o.ok) {
365
+ const c = await o.text();
366
+ throw new Error(c || "Failed to remove group members");
367
+ }
368
+ };
369
+ function _a() {
370
+ const { authToken: s, tokenProps: r } = U(), a = le();
371
+ return ce({
372
+ mutationFn: (t) => Ra(r.apiServiceUrl, (s == null ? void 0 : s.accessToken) || "", t),
373
+ onSuccess: () => {
374
+ a.invalidateQueries({ queryKey: ["groups"] }), L.success("Group created successfully");
375
+ },
376
+ onError: (t) => {
377
+ console.error("Failed to create group:", t), L.error("Failed to create group", {
378
+ description: t.message
379
+ });
380
+ }
381
+ });
382
+ }
383
+ function $a() {
384
+ const { authToken: s, tokenProps: r } = U(), a = le();
385
+ return ce({
386
+ mutationFn: (t) => Ua(r.apiServiceUrl, (s == null ? void 0 : s.accessToken) || "", t),
387
+ onSuccess: (t, l) => {
388
+ a.invalidateQueries({ queryKey: ["groups"] }), a.removeQueries({ queryKey: ["group", l] }), L.success("Group deleted successfully");
389
+ },
390
+ onError: (t) => {
391
+ console.error("Failed to delete group:", t), L.error("Failed to delete group", {
392
+ description: t.message
393
+ });
394
+ }
395
+ });
396
+ }
397
+ function ja() {
398
+ const { authToken: s, tokenProps: r } = U(), a = le();
399
+ return ce({
400
+ mutationFn: ({
401
+ groupId: t,
402
+ data: l
403
+ }) => za(r.apiServiceUrl, (s == null ? void 0 : s.accessToken) || "", t, l),
404
+ onSuccess: (t, l) => {
405
+ a.invalidateQueries({ queryKey: ["group", l.groupId] }), a.invalidateQueries({
406
+ queryKey: ["group-members", l.groupId]
407
+ }), a.invalidateQueries({ queryKey: ["groups"] }), L.success("Members added successfully");
408
+ },
409
+ onError: (t) => {
410
+ console.error("Failed to add group members:", t), L.error("Failed to add members", {
411
+ description: t.message
412
+ });
413
+ }
414
+ });
415
+ }
416
+ function Va() {
417
+ const { authToken: s, tokenProps: r } = U(), a = le();
418
+ return ce({
419
+ mutationFn: ({
420
+ groupId: t,
421
+ data: l
422
+ }) => qa(r.apiServiceUrl, (s == null ? void 0 : s.accessToken) || "", t, l),
423
+ onSuccess: (t, l) => {
424
+ a.invalidateQueries({ queryKey: ["group", l.groupId] }), a.invalidateQueries({
425
+ queryKey: ["group-members", l.groupId]
426
+ }), a.invalidateQueries({ queryKey: ["groups"] }), L.success("Members removed successfully");
427
+ },
428
+ onError: (t) => {
429
+ console.error("Failed to remove group members:", t), L.error("Failed to remove members", {
430
+ description: t.message
431
+ });
432
+ }
433
+ });
434
+ }
435
+ function Qa({
436
+ onSuccess: s,
437
+ tenantId: r,
438
+ isTenantUser: a
439
+ }) {
440
+ const [t, l] = b(""), [o, c] = b(""), [u, p] = b({}), f = _a(), d = () => {
441
+ const g = {};
442
+ return t.trim() ? t.length < 3 ? g.name = "Group name must be at least 3 characters" : t.length > 50 && (g.name = "Group name must be less than 50 characters") : g.name = "Group name is required", o && o.length > 200 && (g.description = "Description must be less than 200 characters"), p(g), Object.keys(g).length === 0;
443
+ };
444
+ return /* @__PURE__ */ n("form", { onSubmit: async (g) => {
445
+ if (g.preventDefault(), !d()) return;
446
+ const v = {
447
+ name: t.trim(),
448
+ description: o.trim() || void 0,
449
+ type: a ? "TENANT_GROUP" : "ORG_GROUP",
450
+ ...a && r ? { tenantId: r } : {}
451
+ };
452
+ try {
453
+ await f.mutateAsync(v), l(""), c(""), p({}), s();
454
+ } catch (N) {
455
+ console.error("Failed to create group:", N);
456
+ }
457
+ }, className: "space-y-6", children: [
458
+ /* @__PURE__ */ n("div", { className: "space-y-4", children: [
459
+ /* @__PURE__ */ n("div", { className: "space-y-2", children: [
460
+ /* @__PURE__ */ n(be, { htmlFor: "group-name", children: [
461
+ "Group Name ",
462
+ /* @__PURE__ */ e("span", { className: "text-destructive", children: "*" })
463
+ ] }),
464
+ /* @__PURE__ */ e(
465
+ W,
466
+ {
467
+ id: "group-name",
468
+ placeholder: "e.g., Marketing Team, Engineering Squad",
469
+ value: t,
470
+ onChange: (g) => {
471
+ l(g.target.value), u.name && p((v) => ({ ...v, name: "" }));
472
+ },
473
+ className: u.name ? "border-destructive" : "",
474
+ disabled: f.isPending
475
+ }
476
+ ),
477
+ u.name && /* @__PURE__ */ e("p", { className: "text-sm text-destructive", children: u.name })
478
+ ] }),
479
+ /* @__PURE__ */ n("div", { className: "space-y-2", children: [
480
+ /* @__PURE__ */ n(be, { htmlFor: "group-description", children: [
481
+ "Description",
482
+ /* @__PURE__ */ e("span", { className: "ml-2 text-xs text-muted-foreground", children: "(optional)" })
483
+ ] }),
484
+ /* @__PURE__ */ e(
485
+ Js,
486
+ {
487
+ id: "group-description",
488
+ placeholder: "Describe the purpose of this group...",
489
+ value: o,
490
+ onChange: (g) => {
491
+ c(g.target.value), u.description && p((v) => ({ ...v, description: "" }));
492
+ },
493
+ className: u.description ? "border-destructive" : "",
494
+ disabled: f.isPending,
495
+ rows: 3
496
+ }
497
+ ),
498
+ u.description && /* @__PURE__ */ e("p", { className: "text-sm text-destructive", children: u.description }),
499
+ /* @__PURE__ */ n("p", { className: "text-xs text-muted-foreground", children: [
500
+ o.length,
501
+ "/200 characters"
502
+ ] })
503
+ ] }),
504
+ /* @__PURE__ */ e("div", { className: "rounded-lg border bg-muted/50 p-4", children: /* @__PURE__ */ n("div", { className: "flex gap-3", children: [
505
+ /* @__PURE__ */ e(Ks, { className: "h-4 w-4 mt-0.5 text-muted-foreground" }),
506
+ /* @__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." })
507
+ ] }) })
508
+ ] }),
509
+ /* @__PURE__ */ n("div", { className: "flex justify-end gap-3", children: [
510
+ /* @__PURE__ */ e(
511
+ k,
512
+ {
513
+ type: "button",
514
+ variant: "outline",
515
+ onClick: () => {
516
+ l(""), c(""), p({});
517
+ },
518
+ disabled: f.isPending,
519
+ children: "Clear"
520
+ }
521
+ ),
522
+ /* @__PURE__ */ e(
523
+ k,
524
+ {
525
+ type: "submit",
526
+ disabled: f.isPending || !t.trim(),
527
+ children: f.isPending ? /* @__PURE__ */ n(I, { children: [
528
+ /* @__PURE__ */ e(_, { className: "mr-2 h-4 w-4 animate-spin" }),
529
+ "Creating..."
530
+ ] }) : /* @__PURE__ */ n(I, { children: [
531
+ /* @__PURE__ */ e($, { className: "mr-2 h-4 w-4" }),
532
+ "Create Group"
533
+ ] })
534
+ }
535
+ )
536
+ ] })
537
+ ] });
538
+ }
539
+ function Ha(s, r = []) {
540
+ let a = [];
541
+ function t(o, c) {
542
+ const u = D.createContext(c), p = a.length;
543
+ a = [...a, c];
544
+ const f = (m) => {
545
+ var O;
546
+ const { scope: g, children: v, ...N } = m, w = ((O = g == null ? void 0 : g[s]) == null ? void 0 : O[p]) || u, C = D.useMemo(() => N, Object.values(N));
547
+ return /* @__PURE__ */ e(w.Provider, { value: C, children: v });
548
+ };
549
+ f.displayName = o + "Provider";
550
+ function d(m, g) {
551
+ var w;
552
+ const v = ((w = g == null ? void 0 : g[s]) == null ? void 0 : w[p]) || u, N = D.useContext(v);
553
+ if (N) return N;
554
+ if (c !== void 0) return c;
555
+ throw new Error(`\`${m}\` must be used within \`${o}\``);
556
+ }
557
+ return [f, d];
558
+ }
559
+ const l = () => {
560
+ const o = a.map((c) => D.createContext(c));
561
+ return function(u) {
562
+ const p = (u == null ? void 0 : u[s]) || o;
563
+ return D.useMemo(
564
+ () => ({ [`__scope${s}`]: { ...u, [s]: p } }),
565
+ [u, p]
566
+ );
567
+ };
568
+ };
569
+ return l.scopeName = s, [t, Ba(l, ...r)];
570
+ }
571
+ function Ba(...s) {
572
+ const r = s[0];
573
+ if (s.length === 1) return r;
574
+ const a = () => {
575
+ const t = s.map((l) => ({
576
+ useScope: l(),
577
+ scopeName: l.scopeName
578
+ }));
579
+ return function(o) {
580
+ const c = t.reduce((u, { useScope: p, scopeName: f }) => {
581
+ const m = p(o)[`__scope${f}`];
582
+ return { ...u, ...m };
583
+ }, {});
584
+ return D.useMemo(() => ({ [`__scope${r.scopeName}`]: c }), [c]);
585
+ };
586
+ };
587
+ return a.scopeName = r.scopeName, a;
588
+ }
589
+ function Ja(s) {
590
+ const r = D.useRef(s);
591
+ return D.useEffect(() => {
592
+ r.current = s;
593
+ }), D.useMemo(() => (...a) => {
594
+ var t;
595
+ return (t = r.current) == null ? void 0 : t.call(r, ...a);
596
+ }, []);
597
+ }
598
+ var Se = globalThis != null && globalThis.document ? D.useLayoutEffect : () => {
599
+ }, Ka = [
600
+ "a",
601
+ "button",
602
+ "div",
603
+ "form",
604
+ "h2",
605
+ "h3",
606
+ "img",
607
+ "input",
608
+ "label",
609
+ "li",
610
+ "nav",
611
+ "ol",
612
+ "p",
613
+ "select",
614
+ "span",
615
+ "svg",
616
+ "ul"
617
+ ], Te = Ka.reduce((s, r) => {
618
+ const a = Ws(`Primitive.${r}`), t = D.forwardRef((l, o) => {
619
+ const { asChild: c, ...u } = l, p = c ? a : r;
620
+ return typeof window < "u" && (window[Symbol.for("radix-ui")] = !0), /* @__PURE__ */ e(p, { ...u, ref: o });
621
+ });
622
+ return t.displayName = `Primitive.${r}`, { ...s, [r]: t };
623
+ }, {});
624
+ function Wa() {
625
+ return Ia.useSyncExternalStore(
626
+ Xa,
627
+ () => !0,
628
+ () => !1
629
+ );
630
+ }
631
+ function Xa() {
632
+ return () => {
633
+ };
634
+ }
635
+ var Pe = "Avatar", [Ya] = Ha(Pe), [Za, ps] = Ya(Pe), gs = D.forwardRef(
636
+ (s, r) => {
637
+ const { __scopeAvatar: a, ...t } = s, [l, o] = D.useState("idle");
638
+ return /* @__PURE__ */ e(
639
+ Za,
640
+ {
641
+ scope: a,
642
+ imageLoadingStatus: l,
643
+ onImageLoadingStatusChange: o,
644
+ children: /* @__PURE__ */ e(Te.span, { ...t, ref: r })
645
+ }
646
+ );
647
+ }
648
+ );
649
+ gs.displayName = Pe;
650
+ var fs = "AvatarImage", vs = D.forwardRef(
651
+ (s, r) => {
652
+ const { __scopeAvatar: a, src: t, onLoadingStatusChange: l = () => {
653
+ }, ...o } = s, c = ps(fs, a), u = et(t, o), p = Ja((f) => {
654
+ l(f), c.onImageLoadingStatusChange(f);
655
+ });
656
+ return Se(() => {
657
+ u !== "idle" && p(u);
658
+ }, [u, p]), u === "loaded" ? /* @__PURE__ */ e(Te.img, { ...o, ref: r, src: t }) : null;
659
+ }
660
+ );
661
+ vs.displayName = fs;
662
+ var bs = "AvatarFallback", Ns = D.forwardRef(
663
+ (s, r) => {
664
+ const { __scopeAvatar: a, delayMs: t, ...l } = s, o = ps(bs, a), [c, u] = D.useState(t === void 0);
665
+ return D.useEffect(() => {
666
+ if (t !== void 0) {
667
+ const p = window.setTimeout(() => u(!0), t);
668
+ return () => window.clearTimeout(p);
669
+ }
670
+ }, [t]), c && o.imageLoadingStatus !== "loaded" ? /* @__PURE__ */ e(Te.span, { ...l, ref: r }) : null;
671
+ }
672
+ );
673
+ Ns.displayName = bs;
674
+ function Be(s, r) {
675
+ return s ? r ? (s.src !== r && (s.src = r), s.complete && s.naturalWidth > 0 ? "loaded" : "loading") : "error" : "idle";
676
+ }
677
+ function et(s, { referrerPolicy: r, crossOrigin: a }) {
678
+ const t = Wa(), l = D.useRef(null), o = t ? (l.current || (l.current = new window.Image()), l.current) : null, [c, u] = D.useState(
679
+ () => Be(o, s)
680
+ );
681
+ return Se(() => {
682
+ u(Be(o, s));
683
+ }, [o, s]), Se(() => {
684
+ const p = (m) => () => {
685
+ u(m);
686
+ };
687
+ if (!o) return;
688
+ const f = p("loaded"), d = p("error");
689
+ return o.addEventListener("load", f), o.addEventListener("error", d), r && (o.referrerPolicy = r), typeof a == "string" && (o.crossOrigin = a), () => {
690
+ o.removeEventListener("load", f), o.removeEventListener("error", d);
691
+ };
692
+ }, [o, a, r]), c;
693
+ }
694
+ var ys = gs, ws = vs, xs = Ns;
695
+ const Ge = D.forwardRef(({ className: s, ...r }, a) => /* @__PURE__ */ e(
696
+ ys,
697
+ {
698
+ ref: a,
699
+ className: Y(
700
+ "relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",
701
+ s
702
+ ),
703
+ ...r
704
+ }
705
+ ));
706
+ Ge.displayName = ys.displayName;
707
+ const st = D.forwardRef(({ className: s, ...r }, a) => /* @__PURE__ */ e(
708
+ ws,
709
+ {
710
+ ref: a,
711
+ className: Y("aspect-square h-full w-full", s),
712
+ ...r
713
+ }
714
+ ));
715
+ st.displayName = ws.displayName;
716
+ const Fe = D.forwardRef(({ className: s, ...r }, a) => /* @__PURE__ */ e(
717
+ xs,
718
+ {
719
+ ref: a,
720
+ className: Y(
721
+ "flex h-full w-full items-center justify-center rounded-full bg-muted",
722
+ s
723
+ ),
724
+ ...r
725
+ }
726
+ ));
727
+ Fe.displayName = xs.displayName;
728
+ function at({
729
+ open: s,
730
+ onOpenChange: r,
731
+ group: a,
732
+ onUpdate: t
733
+ }) {
734
+ const [l, o] = b("members"), [c, u] = b(""), [p, f] = b([]), [d, m] = b([]), { data: g, isLoading: v, refetch: N } = Xs(a.id), w = a.type === "TENANT_GROUP" ? "tenant" : "organization", { users: C, isLoading: O } = Ys({
735
+ type: w,
736
+ tenantId: a.tenantId || void 0,
737
+ active: !0,
738
+ limit: 100
739
+ }), R = ja(), G = Va(), A = (g == null ? void 0 : g.members) || [], F = ne(() => new Set(A.map((h) => h.userId)), [A]), P = ne(() => C.filter((h) => !F.has(h.id)), [C, F]), j = ne(() => {
740
+ if (!c) return P;
741
+ const h = c.toLowerCase();
742
+ return P.filter(
743
+ (M) => {
744
+ var E, z;
745
+ return ((E = M.name) == null ? void 0 : E.toLowerCase().includes(h)) || ((z = M.email) == null ? void 0 : z.toLowerCase().includes(h));
746
+ }
747
+ );
748
+ }, [P, c]), x = ne(() => {
749
+ if (!c) return A;
750
+ const h = c.toLowerCase();
751
+ return A.filter(
752
+ (M) => {
753
+ var E, z, Z, Q;
754
+ return ((z = (E = M.user) == null ? void 0 : E.name) == null ? void 0 : z.toLowerCase().includes(h)) || ((Q = (Z = M.user) == null ? void 0 : Z.email) == null ? void 0 : Q.toLowerCase().includes(h));
755
+ }
756
+ );
757
+ }, [A, c]), V = async () => {
758
+ if (p.length !== 0)
759
+ try {
760
+ await R.mutateAsync({
761
+ groupId: a.id,
762
+ data: {
763
+ userIds: p,
764
+ userType: w === "tenant" ? "tenant" : "org"
765
+ }
766
+ }), f([]), o("members"), N(), t == null || t();
767
+ } catch (h) {
768
+ console.error("Failed to add members:", h);
769
+ }
770
+ }, de = async () => {
771
+ if (d.length !== 0)
772
+ try {
773
+ await G.mutateAsync({
774
+ groupId: a.id,
775
+ data: {
776
+ userIds: d
777
+ }
778
+ }), m([]), N(), t == null || t();
779
+ } catch (h) {
780
+ console.error("Failed to remove members:", h);
781
+ }
782
+ }, ue = (h) => {
783
+ f(
784
+ (M) => M.includes(h) ? M.filter((E) => E !== h) : [...M, h]
785
+ );
786
+ }, S = (h) => {
787
+ m(
788
+ (M) => M.includes(h) ? M.filter((E) => E !== h) : [...M, h]
789
+ );
790
+ };
791
+ return /* @__PURE__ */ e(I, { children: /* @__PURE__ */ e(ke, { open: s, onOpenChange: r, children: /* @__PURE__ */ n(Ae, { className: "max-w-3xl max-h-[80vh]", "aria-describedby": "group-members-description", children: [
792
+ /* @__PURE__ */ n(Ie, { children: [
793
+ /* @__PURE__ */ e(Ee, { children: a.name }),
794
+ /* @__PURE__ */ e("div", { className: "flex items-center gap-2 mt-1", children: /* @__PURE__ */ n("p", { className: "text-sm text-muted-foreground", children: [
795
+ A.length,
796
+ " ",
797
+ A.length === 1 ? "member" : "members"
798
+ ] }) }),
799
+ /* @__PURE__ */ n("p", { id: "group-members-description", className: "sr-only", children: [
800
+ "Add or remove members from the ",
801
+ a.name,
802
+ " group"
803
+ ] })
804
+ ] }),
805
+ /* @__PURE__ */ n(as, { value: l, onValueChange: (h) => {
806
+ o(h), u(""), m([]);
807
+ }, className: "mt-4", children: [
808
+ /* @__PURE__ */ n(ts, { className: "grid w-full grid-cols-2", children: [
809
+ /* @__PURE__ */ e(oe, { value: "members", children: "Current Members" }),
810
+ /* @__PURE__ */ e(oe, { value: "add", children: "Add Members" })
811
+ ] }),
812
+ /* @__PURE__ */ n(ie, { value: "members", className: "mt-4 space-y-4", children: [
813
+ /* @__PURE__ */ n("div", { className: "relative", children: [
814
+ /* @__PURE__ */ e(Ne, { className: "absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" }),
815
+ /* @__PURE__ */ e(
816
+ W,
817
+ {
818
+ placeholder: "Search members...",
819
+ value: c,
820
+ onChange: (h) => u(h.target.value),
821
+ className: "pl-10"
822
+ }
823
+ )
824
+ ] }),
825
+ /* @__PURE__ */ e(ye, { className: d.length > 0 ? "h-[300px]" : "h-[350px]", children: v ? /* @__PURE__ */ e("div", { className: "space-y-2", children: [1, 2, 3].map((h) => /* @__PURE__ */ e(we, { className: "h-16 w-full" }, h)) }) : x.length === 0 ? /* @__PURE__ */ n("div", { className: "flex flex-col items-center justify-center py-12 text-muted-foreground", children: [
826
+ /* @__PURE__ */ e($, { className: "h-12 w-12 mb-3 opacity-50" }),
827
+ /* @__PURE__ */ e("p", { className: "text-sm font-medium", children: c ? "No members found" : "No members yet" }),
828
+ /* @__PURE__ */ e("p", { className: "text-xs mt-1", children: c ? "Try a different search" : 'Switch to the "Add Members" tab to add people to this group' })
829
+ ] }) : /* @__PURE__ */ e("div", { className: "space-y-2", children: x.map((h) => /* @__PURE__ */ e(
830
+ tt,
831
+ {
832
+ member: h,
833
+ selected: d.includes(h.userId),
834
+ onToggle: () => S(h.userId)
835
+ },
836
+ h.id
837
+ )) }) }),
838
+ d.length > 0 && /* @__PURE__ */ n("div", { className: "flex items-center justify-between pt-4 border-t", children: [
839
+ /* @__PURE__ */ n("span", { className: "text-sm text-muted-foreground", children: [
840
+ d.length,
841
+ " member",
842
+ d.length !== 1 ? "s" : "",
843
+ " selected"
844
+ ] }),
845
+ /* @__PURE__ */ e(
846
+ k,
847
+ {
848
+ variant: "destructive",
849
+ size: "sm",
850
+ onClick: de,
851
+ disabled: G.isPending,
852
+ children: G.isPending ? /* @__PURE__ */ n(I, { children: [
853
+ /* @__PURE__ */ e(_, { className: "mr-2 h-4 w-4 animate-spin" }),
854
+ "Removing..."
855
+ ] }) : /* @__PURE__ */ n(I, { children: [
856
+ /* @__PURE__ */ e(rs, { className: "mr-2 h-4 w-4" }),
857
+ "Remove Selected"
858
+ ] })
859
+ }
860
+ )
861
+ ] })
862
+ ] }),
863
+ /* @__PURE__ */ n(ie, { value: "add", className: "mt-4 space-y-4", children: [
864
+ /* @__PURE__ */ n("div", { className: "relative", children: [
865
+ /* @__PURE__ */ e(Ne, { className: "absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" }),
866
+ /* @__PURE__ */ e(
867
+ W,
868
+ {
869
+ placeholder: "Search users to add...",
870
+ value: c,
871
+ onChange: (h) => u(h.target.value),
872
+ className: "pl-10"
873
+ }
874
+ )
875
+ ] }),
876
+ /* @__PURE__ */ e(ye, { className: "h-[300px]", children: O ? /* @__PURE__ */ e("div", { className: "space-y-2", children: [1, 2, 3].map((h) => /* @__PURE__ */ e(we, { className: "h-16 w-full" }, h)) }) : j.length === 0 ? /* @__PURE__ */ n("div", { className: "flex flex-col items-center justify-center py-12 text-muted-foreground", children: [
877
+ /* @__PURE__ */ e(xe, { className: "h-12 w-12 mb-3 opacity-50" }),
878
+ /* @__PURE__ */ e("p", { className: "text-sm font-medium", children: "No available users" }),
879
+ /* @__PURE__ */ e("p", { className: "text-xs mt-1", children: c ? "Try a different search" : "All eligible users are already members" })
880
+ ] }) : /* @__PURE__ */ e("div", { className: "space-y-2", children: j.map((h) => /* @__PURE__ */ e(
881
+ rt,
882
+ {
883
+ user: h,
884
+ selected: p.includes(h.id),
885
+ onToggle: () => ue(h.id)
886
+ },
887
+ h.id
888
+ )) }) }),
889
+ p.length > 0 && /* @__PURE__ */ n("div", { className: "flex items-center justify-between pt-4 border-t", children: [
890
+ /* @__PURE__ */ n("span", { className: "text-sm text-muted-foreground", children: [
891
+ p.length,
892
+ " user",
893
+ p.length !== 1 ? "s" : "",
894
+ " selected"
895
+ ] }),
896
+ /* @__PURE__ */ e(
897
+ k,
898
+ {
899
+ onClick: V,
900
+ disabled: R.isPending,
901
+ children: R.isPending ? /* @__PURE__ */ n(I, { children: [
902
+ /* @__PURE__ */ e(_, { className: "mr-2 h-4 w-4 animate-spin" }),
903
+ "Adding..."
904
+ ] }) : /* @__PURE__ */ n(I, { children: [
905
+ /* @__PURE__ */ e(xe, { className: "mr-2 h-4 w-4" }),
906
+ "Add Members"
907
+ ] })
908
+ }
909
+ )
910
+ ] })
911
+ ] })
912
+ ] })
913
+ ] }) }) });
914
+ }
915
+ function tt({
916
+ member: s,
917
+ selected: r,
918
+ onToggle: a
919
+ }) {
920
+ var l, o, c, u;
921
+ const t = ((o = (l = s.user) == null ? void 0 : l.name) == null ? void 0 : o.split(" ").map((p) => p[0]).join("").toUpperCase()) || "?";
922
+ return /* @__PURE__ */ n(
923
+ "div",
924
+ {
925
+ className: "flex items-center gap-3 p-3 rounded-lg border bg-card hover:bg-muted/50 cursor-pointer",
926
+ onClick: a,
927
+ children: [
928
+ /* @__PURE__ */ e(ns, { checked: r }),
929
+ /* @__PURE__ */ e(Ge, { className: "h-8 w-8", children: /* @__PURE__ */ e(Fe, { className: "text-xs", children: t }) }),
930
+ /* @__PURE__ */ n("div", { className: "flex-1", children: [
931
+ /* @__PURE__ */ e("p", { className: "text-sm font-medium", children: ((c = s.user) == null ? void 0 : c.name) || "Unknown User" }),
932
+ /* @__PURE__ */ e("p", { className: "text-xs text-muted-foreground", children: (u = s.user) == null ? void 0 : u.email })
933
+ ] })
934
+ ]
935
+ }
936
+ );
937
+ }
938
+ function rt({
939
+ user: s,
940
+ selected: r,
941
+ onToggle: a
942
+ }) {
943
+ var l;
944
+ const t = ((l = s.name) == null ? void 0 : l.split(" ").map((o) => o[0]).join("").toUpperCase()) || "?";
945
+ return /* @__PURE__ */ n(
946
+ "div",
947
+ {
948
+ className: "flex items-center gap-3 p-3 rounded-lg border bg-card hover:bg-muted/50 cursor-pointer",
949
+ onClick: a,
950
+ children: [
951
+ /* @__PURE__ */ e(ns, { checked: r }),
952
+ /* @__PURE__ */ e(Ge, { className: "h-8 w-8", children: /* @__PURE__ */ e(Fe, { className: "text-xs", children: t }) }),
953
+ /* @__PURE__ */ n("div", { className: "flex-1", children: [
954
+ /* @__PURE__ */ e("p", { className: "text-sm font-medium", children: s.name }),
955
+ /* @__PURE__ */ e("p", { className: "text-xs text-muted-foreground", children: s.email })
956
+ ] })
957
+ ]
958
+ }
959
+ );
960
+ }
961
+ function nt({
962
+ open: s,
963
+ onOpenChange: r
964
+ }) {
965
+ const [a, t] = b("groups"), [l, o] = b(""), [c, u] = b(null), [p, f] = b(!1), [d, m] = b(null), { tokenProps: g } = U(), { currentUser: v } = os(), N = $a(), w = (v == null ? void 0 : v.type) === "tenant", C = g == null ? void 0 : g.tenantId, { groups: O, isLoading: R, refetch: G } = Zs({
966
+ type: w ? "TENANT_GROUP" : "all",
967
+ tenantId: w ? C : void 0,
968
+ includeMembers: !1
969
+ }), A = O.filter(
970
+ (x) => {
971
+ var V;
972
+ return x.name.toLowerCase().includes(l.toLowerCase()) || ((V = x.description) == null ? void 0 : V.toLowerCase().includes(l.toLowerCase()));
973
+ }
974
+ ), F = async () => {
975
+ if (d)
976
+ try {
977
+ await N.mutateAsync(d.id), m(null), G();
978
+ } catch (x) {
979
+ console.error("Failed to delete group:", x);
980
+ }
981
+ }, P = (x) => {
982
+ u(x), f(!0);
983
+ }, j = () => {
984
+ t("groups"), G();
985
+ };
986
+ return /* @__PURE__ */ n(I, { children: [
987
+ /* @__PURE__ */ e(ke, { open: s, onOpenChange: r, children: /* @__PURE__ */ n(Ae, { className: "max-w-4xl max-h-[80vh]", children: [
988
+ /* @__PURE__ */ n(Ie, { children: [
989
+ /* @__PURE__ */ n(Ee, { className: "flex items-center gap-2", children: [
990
+ /* @__PURE__ */ e($, { className: "h-5 w-5" }),
991
+ "Group Management"
992
+ ] }),
993
+ /* @__PURE__ */ e(Ye, { children: "Manage your groups, create new groups, and control group membership" })
994
+ ] }),
995
+ /* @__PURE__ */ n(as, { value: a, onValueChange: t, className: "mt-4", children: [
996
+ /* @__PURE__ */ n(ts, { className: "grid w-full grid-cols-2", children: [
997
+ /* @__PURE__ */ n(oe, { value: "groups", className: "flex items-center gap-2", children: [
998
+ /* @__PURE__ */ e($, { className: "h-4 w-4" }),
999
+ "Groups"
1000
+ ] }),
1001
+ /* @__PURE__ */ n(oe, { value: "create", className: "flex items-center gap-2", children: [
1002
+ /* @__PURE__ */ e(Le, { className: "h-4 w-4" }),
1003
+ "Create Group"
1004
+ ] })
1005
+ ] }),
1006
+ /* @__PURE__ */ e(ie, { value: "groups", className: "mt-4", children: /* @__PURE__ */ n("div", { className: "space-y-4", children: [
1007
+ /* @__PURE__ */ n("div", { className: "relative", children: [
1008
+ /* @__PURE__ */ e(Ne, { className: "absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" }),
1009
+ /* @__PURE__ */ e(
1010
+ W,
1011
+ {
1012
+ placeholder: "Search groups...",
1013
+ value: l,
1014
+ onChange: (x) => o(x.target.value),
1015
+ className: "pl-10"
1016
+ }
1017
+ )
1018
+ ] }),
1019
+ /* @__PURE__ */ e(ye, { className: "h-[400px]", children: R ? /* @__PURE__ */ e("div", { className: "space-y-3", children: [1, 2, 3].map((x) => /* @__PURE__ */ e(we, { className: "h-24 w-full" }, x)) }) : A.length === 0 ? /* @__PURE__ */ n("div", { className: "flex flex-col items-center justify-center py-12 text-muted-foreground", children: [
1020
+ /* @__PURE__ */ e($, { className: "h-12 w-12 mb-3 opacity-50" }),
1021
+ /* @__PURE__ */ e("p", { className: "text-sm font-medium", children: "No groups found" }),
1022
+ /* @__PURE__ */ e("p", { className: "text-xs mt-1", children: l ? "Try a different search" : "Create your first group to get started" })
1023
+ ] }) : /* @__PURE__ */ e("div", { className: "space-y-3", children: A.map((x) => /* @__PURE__ */ e(
1024
+ ot,
1025
+ {
1026
+ group: x,
1027
+ onManageMembers: () => P(x),
1028
+ onDelete: () => m(x),
1029
+ currentUserId: v == null ? void 0 : v.id
1030
+ },
1031
+ x.id
1032
+ )) }) })
1033
+ ] }) }),
1034
+ /* @__PURE__ */ e(ie, { value: "create", className: "mt-4", children: /* @__PURE__ */ e(
1035
+ Qa,
1036
+ {
1037
+ onSuccess: j,
1038
+ tenantId: C,
1039
+ isTenantUser: w
1040
+ }
1041
+ ) })
1042
+ ] })
1043
+ ] }) }),
1044
+ c && /* @__PURE__ */ e(
1045
+ at,
1046
+ {
1047
+ open: p,
1048
+ onOpenChange: f,
1049
+ group: c,
1050
+ onUpdate: () => G()
1051
+ }
1052
+ ),
1053
+ /* @__PURE__ */ e(
1054
+ is,
1055
+ {
1056
+ open: !!d,
1057
+ onOpenChange: () => m(null),
1058
+ children: /* @__PURE__ */ n(ls, { children: [
1059
+ /* @__PURE__ */ n(cs, { children: [
1060
+ /* @__PURE__ */ e(ds, { children: "Delete Group" }),
1061
+ /* @__PURE__ */ n(us, { children: [
1062
+ 'Are you sure you want to delete "',
1063
+ d == null ? void 0 : d.name,
1064
+ '"? This action cannot be undone and will remove all members from the group.'
1065
+ ] })
1066
+ ] }),
1067
+ /* @__PURE__ */ n(ms, { children: [
1068
+ /* @__PURE__ */ e(hs, { children: "Cancel" }),
1069
+ /* @__PURE__ */ e(
1070
+ Ce,
1071
+ {
1072
+ onClick: F,
1073
+ disabled: N.isPending,
1074
+ className: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
1075
+ children: N.isPending ? /* @__PURE__ */ n(I, { children: [
1076
+ /* @__PURE__ */ e(_, { className: "mr-2 h-4 w-4 animate-spin" }),
1077
+ "Deleting..."
1078
+ ] }) : "Delete Group"
1079
+ }
1080
+ )
1081
+ ] })
1082
+ ] })
1083
+ }
1084
+ )
1085
+ ] });
1086
+ }
1087
+ function ot({
1088
+ group: s,
1089
+ onManageMembers: r,
1090
+ onDelete: a,
1091
+ currentUserId: t
1092
+ }) {
1093
+ const l = s.createdBy === t;
1094
+ return /* @__PURE__ */ e("div", { className: "rounded-lg border bg-card p-4 transition-colors hover:bg-muted/50", children: /* @__PURE__ */ n("div", { className: "flex items-start justify-between gap-3", children: [
1095
+ /* @__PURE__ */ n("div", { className: "flex-1 space-y-2", children: [
1096
+ /* @__PURE__ */ n("div", { children: [
1097
+ /* @__PURE__ */ e("h4", { className: "font-medium", children: s.name }),
1098
+ s.description && /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground mt-1", children: s.description })
1099
+ ] }),
1100
+ /* @__PURE__ */ n("div", { className: "flex flex-wrap items-center gap-3 text-xs text-muted-foreground", children: [
1101
+ /* @__PURE__ */ n("span", { className: "flex items-center gap-1", children: [
1102
+ /* @__PURE__ */ e($, { className: "h-3 w-3" }),
1103
+ s.memberCount,
1104
+ " ",
1105
+ s.memberCount === 1 ? "member" : "members"
1106
+ ] }),
1107
+ /* @__PURE__ */ n("span", { children: [
1108
+ "Created ",
1109
+ ea(new Date(s.createdAt), "MMM d, yyyy")
1110
+ ] })
1111
+ ] })
1112
+ ] }),
1113
+ /* @__PURE__ */ n("div", { className: "flex items-center gap-1", children: [
1114
+ /* @__PURE__ */ e(
1115
+ k,
1116
+ {
1117
+ variant: "ghost",
1118
+ size: "sm",
1119
+ onClick: r,
1120
+ title: "Manage members",
1121
+ children: /* @__PURE__ */ e(xe, { className: "h-4 w-4" })
1122
+ }
1123
+ ),
1124
+ l && /* @__PURE__ */ e(
1125
+ k,
1126
+ {
1127
+ variant: "ghost",
1128
+ size: "sm",
1129
+ onClick: a,
1130
+ title: "Delete group",
1131
+ className: "text-destructive hover:text-destructive",
1132
+ children: /* @__PURE__ */ e(rs, { className: "h-4 w-4" })
1133
+ }
1134
+ )
1135
+ ] })
1136
+ ] }) });
1137
+ }
1138
+ function pt() {
1139
+ var _e, $e, je;
1140
+ const {
1141
+ authToken: s,
1142
+ tokenProps: r,
1143
+ id: a
1144
+ } = U(), { isLocalDev: t } = sa(), { permissions: l } = aa(), o = ta(), { isLoading: c } = ra();
1145
+ y((i) => i.theme);
1146
+ const u = y((i) => i.lenses), p = y((i) => i.selectedLensId), f = u == null ? void 0 : u.find((i) => i.id === p), d = y((i) => i.dashboard);
1147
+ y((i) => i.selectedSheetId);
1148
+ const m = y(
1149
+ (i) => i.isDashboardEditing
1150
+ ), { setDashboardTitle: g } = y((i) => i.actions), [v, N] = b(!1), [w, C] = b(!1), [O, R] = b(!1), [G, A] = b(!1), [F, P] = b(null), [j, x] = b(!1), V = y((i) => i.isDashboardPanelOpen), de = y(
1151
+ (i) => i.actions.setIsDashboardPanelOpen
1152
+ ), ue = y((i) => i.filterValues), S = y((i) => i.isVisualEditing);
1153
+ Qe((i) => i.card);
1154
+ const h = re(
1155
+ (i) => i.selectedDashboard
1156
+ ), M = re(
1157
+ (i) => i.initialDashboard
1158
+ );
1159
+ re((i) => i.selectedVisual), y((i) => i.selectedFrameId), Qe((i) => i.frame);
1160
+ const E = h ? ($e = h == null ? void 0 : h.permissions) == null ? void 0 : $e.canEdit : (_e = M == null ? void 0 : M.permissions) == null ? void 0 : _e.canEdit, z = y((i) => i.showFilters), Z = y(
1161
+ (i) => i.showDashboardJSON
1162
+ ), Q = y((i) => i.onSaveFunction), Cs = y(
1163
+ (i) => i.actions.setShowFilters
1164
+ ), { setIsDashboardEditing: Oe, setShowDashboardJSON: Re } = y(
1165
+ (i) => i.actions
1166
+ ), { setInitialDashboard: Ue, clearSelectedDashboard: Ds } = re(
1167
+ (i) => i.actions
1168
+ ), { resources: ee } = na(ve.DASHBOARD), { currentUser: Ss } = os(), Ms = oa(Ss), H = h || M, ze = H ? {
1169
+ id: H.id,
1170
+ title: (d == null ? void 0 : d.title) || H.title || "Dashboard"
1171
+ } : null, { handleAddNewFrame: ks } = ia(), [B, me] = b(!1), [Ls, se] = b(!1), ae = la(ve.DASHBOARD), [J, he] = b(
1172
+ null
1173
+ ), As = async (i, T) => {
1174
+ if (!(d != null && d.id)) {
1175
+ console.log("No dashboard ID found");
1176
+ return;
1177
+ }
1178
+ console.log("Updating dashboard title:", {
1179
+ dashboardId: d.id,
1180
+ newTitle: i,
1181
+ previousTitle: T
1182
+ }), ae.mutate(
1183
+ {
1184
+ resourceId: d.id,
1185
+ data: { title: i }
1186
+ },
1187
+ {
1188
+ onSuccess: () => {
1189
+ console.log("Dashboard title updated successfully"), L.success("Dashboard title updated");
1190
+ },
1191
+ onError: (K) => {
1192
+ console.error("Failed to update dashboard title:", K), L.error("Failed to update dashboard title"), g(T);
1193
+ }
1194
+ }
1195
+ );
1196
+ };
1197
+ ba(() => {
1198
+ if (ee && ee.length > 0) {
1199
+ const i = d == null ? void 0 : d.id;
1200
+ if (i) {
1201
+ const T = ee.find(
1202
+ (K) => K.id === i
1203
+ );
1204
+ T && Ue(T);
1205
+ }
1206
+ }
1207
+ }, [ee, d == null ? void 0 : d.id, Ue]);
1208
+ const te = r.orgUserId || r.tenantId, Is = m && !S && te && E, { setDashboard: Es } = y((i) => i.actions), Ts = () => {
1209
+ Oe(!0);
1210
+ }, pe = () => {
1211
+ Oe(!1), Re(!1), he(null);
1212
+ };
1213
+ ya(
1214
+ m,
1215
+ d,
1216
+ J,
1217
+ (i) => he(i)
1218
+ );
1219
+ const Ps = () => J ? JSON.stringify(d) !== JSON.stringify(J) : !1, Gs = () => {
1220
+ Ps() ? se(!0) : pe();
1221
+ }, Fs = async () => {
1222
+ await ge({ closeAfterSave: !0 });
1223
+ }, Os = () => {
1224
+ J && Es(J), pe(), se(!1);
1225
+ };
1226
+ async function ge(i) {
1227
+ const T = (i == null ? void 0 : i.closeAfterSave) ?? j;
1228
+ x(T), T && se(!1);
1229
+ const K = va(d);
1230
+ A(!0), P(null), me(!0);
1231
+ const zs = {
1232
+ template: d
1233
+ };
1234
+ ae.mutate(
1235
+ {
1236
+ resourceId: d.id,
1237
+ data: zs
1238
+ },
1239
+ {
1240
+ onSuccess: () => {
1241
+ me(!1), L.success("Dashboard saved!"), he(K), A(!1), x(!1), T && pe();
1242
+ },
1243
+ onError: () => {
1244
+ me(!1), P("Failed to save dashboard. Please try again."), L.error("Failed to save dashboard");
1245
+ }
1246
+ }
1247
+ );
1248
+ }
1249
+ async function Rs() {
1250
+ if (N(!0), !p || !f) return;
1251
+ const i = JSON.stringify(d), T = {
1252
+ ...f,
1253
+ template: i,
1254
+ filterValues: ue
1255
+ };
1256
+ await De(
1257
+ r.apiServiceUrl,
1258
+ T,
1259
+ s == null ? void 0 : s.accessToken
1260
+ ), L.success("Lens saved"), Q == null || Q(d), N(!1);
1261
+ }
1262
+ const qe = (f == null ? void 0 : f.name) || d.title;
1263
+ ae.isPending && console.log("Title during update:", {
1264
+ title: qe,
1265
+ dashboardStateTitle: d.title,
1266
+ dashboardId: d == null ? void 0 : d.id,
1267
+ currentLensName: f == null ? void 0 : f.name
1268
+ });
1269
+ const Us = r.orgUserId || r.tenantId && r.endUserId && r.endUserEmail;
1270
+ return /* @__PURE__ */ n(
1271
+ "div",
1272
+ {
1273
+ className: "flex h-11 items-center justify-between gap-2 border-b px-4 py-2",
1274
+ role: "dashboard-controls",
1275
+ children: [
1276
+ /* @__PURE__ */ n("div", { className: "flex items-center gap-2", children: [
1277
+ Us && /* @__PURE__ */ n(I, { children: [
1278
+ /* @__PURE__ */ e(
1279
+ q,
1280
+ {
1281
+ "aria-label": "Manage Dashboards",
1282
+ tooltip: "Manage Dashboards",
1283
+ onClick: () => {
1284
+ de(!V);
1285
+ },
1286
+ className: "h-7 p-2",
1287
+ children: /* @__PURE__ */ e(Ma, { className: "h-4 w-4" })
1288
+ }
1289
+ ),
1290
+ o && !S && /* @__PURE__ */ e(
1291
+ q,
1292
+ {
1293
+ "aria-label": "Dashboard Hub",
1294
+ tooltip: "Dashboard Hub",
1295
+ onClick: () => Ds(),
1296
+ className: "h-7 p-2",
1297
+ children: /* @__PURE__ */ e(Ze, { className: "h-4 w-4" })
1298
+ }
1299
+ )
1300
+ ] }),
1301
+ !S && o && (c ? /* @__PURE__ */ n("div", { className: "flex items-center gap-2", children: [
1302
+ /* @__PURE__ */ e(_, { className: "h-3 w-3 animate-spin text-muted-foreground" }),
1303
+ /* @__PURE__ */ e("span", { className: "text-sm text-muted-foreground", children: "Loading..." })
1304
+ ] }) : /* @__PURE__ */ e(
1305
+ ca,
1306
+ {
1307
+ value: qe || "Untitled Dashboard",
1308
+ onSave: (i) => {
1309
+ console.log("EditableText onSave called:", {
1310
+ newTitle: i,
1311
+ canEditDashboard: E,
1312
+ dashboardId: d == null ? void 0 : d.id
1313
+ });
1314
+ const T = (d == null ? void 0 : d.title) || "";
1315
+ g(i), As(i, T);
1316
+ },
1317
+ isEditable: E && !f,
1318
+ displayClassName: "text-sm font-medium",
1319
+ inputClassName: "text-sm font-medium",
1320
+ placeholder: "Dashboard Title",
1321
+ isPending: ae.isPending
1322
+ }
1323
+ ))
1324
+ ] }),
1325
+ /* @__PURE__ */ n("div", { className: "flex items-center gap-2", children: [
1326
+ S && /* @__PURE__ */ n(I, { children: [
1327
+ /* @__PURE__ */ e(wa, { className: "mr-2" }),
1328
+ /* @__PURE__ */ e(xa, { className: "h-7" })
1329
+ ] }),
1330
+ t && !S && /* @__PURE__ */ n(I, { children: [
1331
+ /* @__PURE__ */ e(
1332
+ q,
1333
+ {
1334
+ tooltip: "Copy Token",
1335
+ onClick: () => {
1336
+ var i;
1337
+ s != null && s.accessToken && ((i = navigator == null ? void 0 : navigator.clipboard) != null && i.writeText ? navigator.clipboard.writeText(s.accessToken).then(() => L.success("Token copied to clipboard")).catch(() => L.error("Unable to copy token")) : L.error("Clipboard not available"));
1338
+ },
1339
+ className: "h-7 p-2",
1340
+ children: /* @__PURE__ */ e(da, { className: "h-4 w-4" })
1341
+ }
1342
+ ),
1343
+ /* @__PURE__ */ e(
1344
+ q,
1345
+ {
1346
+ tooltip: "Invalidate Token",
1347
+ onClick: () => ua(r.apiServiceUrl),
1348
+ className: "h-7 p-2",
1349
+ children: /* @__PURE__ */ e(La, { className: "h-4 w-4" })
1350
+ }
1351
+ )
1352
+ ] }),
1353
+ !S && o && /* @__PURE__ */ e(Oa, {}),
1354
+ !S && o && /* @__PURE__ */ e(Ca, {}),
1355
+ !S && o && Ms && /* @__PURE__ */ e(
1356
+ q,
1357
+ {
1358
+ tooltip: "Manage Groups",
1359
+ onClick: () => R(!0),
1360
+ className: "h-7 p-2",
1361
+ children: /* @__PURE__ */ e($, { className: "h-4 w-4" })
1362
+ }
1363
+ ),
1364
+ !S && o && ((je = H == null ? void 0 : H.permissions) == null ? void 0 : je.canShare) && /* @__PURE__ */ e(
1365
+ q,
1366
+ {
1367
+ tooltip: "Share Dashboard",
1368
+ onClick: () => C(!0),
1369
+ className: "h-7 p-2",
1370
+ children: /* @__PURE__ */ e(ma, { className: "h-4 w-4" })
1371
+ }
1372
+ ),
1373
+ !z && !S && m && l.canUseFilters && o && /* @__PURE__ */ e(
1374
+ k,
1375
+ {
1376
+ className: "h-7 p-2",
1377
+ variant: "outline",
1378
+ onClick: () => Cs(!0),
1379
+ size: "sm",
1380
+ children: /* @__PURE__ */ e(ha, { className: "h-4 w-4" })
1381
+ }
1382
+ ),
1383
+ m && !S && te && t && o && /* @__PURE__ */ e(Ga, {}),
1384
+ !S && te && t && o && /* @__PURE__ */ e(Fa, {}),
1385
+ m && !S && te && f && t && o && /* @__PURE__ */ n(
1386
+ k,
1387
+ {
1388
+ className: "h-7 p-2",
1389
+ variant: "secondary",
1390
+ disabled: v,
1391
+ onClick: Rs,
1392
+ size: "sm",
1393
+ children: [
1394
+ /* @__PURE__ */ e(He, { className: "mr-2 h-4 w-4" }),
1395
+ "Save Lens"
1396
+ ]
1397
+ }
1398
+ ),
1399
+ m && !S && o && /* @__PURE__ */ n(
1400
+ k,
1401
+ {
1402
+ variant: "outline",
1403
+ className: "h-7 p-2",
1404
+ size: "sm",
1405
+ disabled: !m,
1406
+ onClick: () => ks(),
1407
+ children: [
1408
+ /* @__PURE__ */ e(Le, { className: "mr-2 h-4 w-4" }),
1409
+ "Visual"
1410
+ ]
1411
+ }
1412
+ ),
1413
+ !S && !m && l.canEdit && o && /* @__PURE__ */ n(
1414
+ k,
1415
+ {
1416
+ variant: "outline",
1417
+ className: "h-7 p-2",
1418
+ onClick: Ts,
1419
+ size: "sm",
1420
+ children: [
1421
+ /* @__PURE__ */ e(pa, { className: "mr-2 h-4 w-4" }),
1422
+ "Edit"
1423
+ ]
1424
+ }
1425
+ ),
1426
+ Is && o && /* @__PURE__ */ n(
1427
+ k,
1428
+ {
1429
+ className: "h-7 p-2",
1430
+ disabled: B,
1431
+ onClick: () => ge(),
1432
+ size: "sm",
1433
+ children: [
1434
+ B ? /* @__PURE__ */ e(_, { className: "mr-2 h-4 w-4 animate-spin" }) : /* @__PURE__ */ e(He, { className: "mr-2 h-4 w-4" }),
1435
+ B ? "Saving..." : "Save"
1436
+ ]
1437
+ }
1438
+ ),
1439
+ !S && m && t && o && /* @__PURE__ */ e("div", { className: "flex items-center space-x-2", children: /* @__PURE__ */ e(
1440
+ k,
1441
+ {
1442
+ className: "h-7 p-2",
1443
+ onClick: () => Re(!Z),
1444
+ size: "sm",
1445
+ variant: "ghost",
1446
+ children: /* @__PURE__ */ e(ga, { className: "h-4 w-4" })
1447
+ }
1448
+ ) }),
1449
+ !S && t && /* @__PURE__ */ e(Ea, {}),
1450
+ m && !S && o && /* @__PURE__ */ n(
1451
+ k,
1452
+ {
1453
+ variant: "outline",
1454
+ className: "h-7 p-2",
1455
+ onClick: Gs,
1456
+ children: [
1457
+ /* @__PURE__ */ e(es, { className: "mr-2 h-4 w-4" }),
1458
+ "Close"
1459
+ ]
1460
+ }
1461
+ ),
1462
+ w && ze && /* @__PURE__ */ e(
1463
+ fa,
1464
+ {
1465
+ resource: ze,
1466
+ resourceType: ve.DASHBOARD,
1467
+ onClose: () => C(!1)
1468
+ }
1469
+ ),
1470
+ /* @__PURE__ */ e(
1471
+ nt,
1472
+ {
1473
+ open: O,
1474
+ onOpenChange: R
1475
+ }
1476
+ ),
1477
+ /* @__PURE__ */ e(
1478
+ is,
1479
+ {
1480
+ open: G,
1481
+ onOpenChange: (i) => {
1482
+ !i && B && !F || (A(i), i || (P(null), x(!1)));
1483
+ },
1484
+ children: /* @__PURE__ */ n(ls, { className: "max-w-sm", children: [
1485
+ /* @__PURE__ */ n(cs, { children: [
1486
+ /* @__PURE__ */ e(ds, { children: F ? "Save failed" : "Saving dashboard" }),
1487
+ /* @__PURE__ */ e(us, { className: "pt-2", children: F ? "We could not save the dashboard. Please try again." : "Please wait while we save your changes." })
1488
+ ] }),
1489
+ /* @__PURE__ */ e(ms, { className: "flex-col gap-2 sm:flex-row sm:justify-end", children: F ? /* @__PURE__ */ n(I, { children: [
1490
+ /* @__PURE__ */ e(
1491
+ hs,
1492
+ {
1493
+ onClick: () => {
1494
+ A(!1), P(null), x(!1);
1495
+ },
1496
+ className: "m-0",
1497
+ children: "Close"
1498
+ }
1499
+ ),
1500
+ /* @__PURE__ */ e(
1501
+ Ce,
1502
+ {
1503
+ onClick: () => ge(),
1504
+ className: "m-0",
1505
+ children: "Retry"
1506
+ }
1507
+ )
1508
+ ] }) : /* @__PURE__ */ n(
1509
+ Ce,
1510
+ {
1511
+ disabled: !0,
1512
+ className: "m-0 cursor-default",
1513
+ children: [
1514
+ /* @__PURE__ */ e(_, { className: "mr-2 h-4 w-4 animate-spin" }),
1515
+ "Saving..."
1516
+ ]
1517
+ }
1518
+ ) })
1519
+ ] })
1520
+ }
1521
+ ),
1522
+ /* @__PURE__ */ e(
1523
+ Da,
1524
+ {
1525
+ open: Ls,
1526
+ onOpenChange: se,
1527
+ onSave: Fs,
1528
+ onDiscard: Os,
1529
+ isSaving: B
1530
+ }
1531
+ )
1532
+ ] })
1533
+ ]
1534
+ }
1535
+ );
1536
+ }
1537
+ export {
1538
+ pt as default
1539
+ };