react-semaphor 0.1.125 → 0.1.127

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