react-semaphor 0.1.124 → 0.1.126

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 (28) hide show
  1. package/dist/chunks/dashboard-controls-BktHa763.js +1473 -0
  2. package/dist/chunks/dashboard-controls-DucLNOji.js +26 -0
  3. package/dist/chunks/dashboard-export-dialog-BNjL5KSw.js +600 -0
  4. package/dist/chunks/dashboard-export-dialog-M318NGd7.js +6 -0
  5. package/dist/chunks/{dashboard-json-QdBRgDPb.js → dashboard-json-B7_R2nwz.js} +1 -1
  6. package/dist/chunks/{dashboard-json-BCOS2K2w.js → dashboard-json-DpgglXTM.js} +1 -1
  7. package/dist/chunks/{edit-dashboard-visual-E4AXmvCQ.js → edit-dashboard-visual-BaNXGTU-.js} +1 -1
  8. package/dist/chunks/{edit-dashboard-visual-C-EPVOe8.js → edit-dashboard-visual-Dfdl-K74.js} +165 -165
  9. package/dist/chunks/{editor-action-buttons-Derg0Fka.js → editor-action-buttons-CMKMrnww.js} +2 -2
  10. package/dist/chunks/{editor-action-buttons-C_UBbFu6.js → editor-action-buttons-CsV8nUOI.js} +1 -1
  11. package/dist/chunks/{index-C_K3WRIV.js → index-BdiWSBWd.js} +322 -322
  12. package/dist/chunks/{index-3qBZw0dE.js → index-GG6fcfuj.js} +97 -97
  13. package/dist/chunks/{resource-management-panel-C4CDYpm_.js → resource-management-panel-3Q8phtkW.js} +1 -1
  14. package/dist/chunks/{resource-management-panel-y71osNXf.js → resource-management-panel-CdC7mFhx.js} +88 -88
  15. package/dist/chunks/{use-visual-utils-zPL0RdVw.js → use-visual-utils-BE_5Rl3X.js} +1 -1
  16. package/dist/chunks/{use-visual-utils-BBZxgwfD.js → use-visual-utils-CxVLCLOf.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/surfboard/index.cjs +1 -1
  22. package/dist/surfboard/index.js +1 -1
  23. package/dist/types/main.d.ts +8 -1
  24. package/package.json +1 -1
  25. package/dist/chunks/dashboard-controls-C_kxUkyD.js +0 -26
  26. package/dist/chunks/dashboard-controls-j6VncHyG.js +0 -1561
  27. package/dist/chunks/schedule-dashboard-B-z6gEwK.js +0 -6
  28. package/dist/chunks/schedule-dashboard-C79ka7qZ.js +0 -415
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
- import { b as S, E as D, F as w, S as P, U as M, m as k, n as A, u as F, o as y, p as L, P as R, q as I, B as V, c as v, r as _, s as W, t as B, v as j, I as q, w as H, x as O, y as U, z, C as G } from "./chunks/index-C_K3WRIV.js";
2
- import { W as oa, Y as ta, D as na, M as ia, a0 as da, R as la, H as ca, H as ua, J as ha, a as pa, aj as fa, a7 as ma, T as Ca, N as va, O as ba, a1 as ga, a9 as ya, a8 as Da, ac as xa, ad as Ea, a6 as Na, Q as Ta, a5 as Sa, _ as wa, $ as Pa, Z as Ma, aa as ka, a4 as Aa, a3 as Fa, a2 as La, ae as Ra, ab as Ia, K as Va, ag as _a, ai as Wa, ah as Ba, g as ja, V as qa, A as Ha, e as Oa, af as Ua, f as za, G as Ga } from "./chunks/index-C_K3WRIV.js";
1
+ import { b as S, E as y, F as w, S as P, U as M, m as k, n as A, u as F, o as g, p as L, P as R, q as I, B as V, c as b, r as _, s as W, t as B, v as j, I as q, w as H, x as O, y as U, z, C as G } from "./chunks/index-BdiWSBWd.js";
2
+ import { W as oa, Y as ta, D as na, M as ia, a0 as da, R as la, H as ca, H as ua, J as ha, a as pa, aj as fa, a7 as ma, T as Ca, N as ba, O as va, a1 as Da, a9 as ga, a8 as ya, ac as xa, ad as Ea, a6 as Na, Q as Ta, a5 as Sa, _ as wa, $ as Pa, Z as Ma, aa as ka, a4 as Aa, a3 as Fa, a2 as La, ae as Ra, ab as Ia, K as Va, ag as _a, ai as Wa, ah as Ba, g as ja, V as qa, A as Ha, e as Oa, af as Ua, f as za, G as Ga } from "./chunks/index-BdiWSBWd.js";
3
3
  import { EMPTY_SELECTION as Ka } from "./types/index.js";
4
4
  import { jsx as a, jsxs as d } from "react/jsx-runtime";
5
5
  import * as p from "react";
6
6
  import { useMemo as Q } from "react";
7
- import { ResourceManagementPanel as $a } from "./chunks/resource-management-panel-y71osNXf.js";
8
- import { A as Xa, S as Za, V as ae, c as ee, g as se } from "./chunks/schedule-dashboard-C79ka7qZ.js";
7
+ import { ResourceManagementPanel as $a } from "./chunks/resource-management-panel-CdC7mFhx.js";
8
+ import { A as Xa, D as Za, S as ae, V as ee, c as se, g as re } from "./chunks/dashboard-export-dialog-BNjL5KSw.js";
9
9
  import "react-dom";
10
10
  /**
11
11
  * @license lucide-react v0.453.0 - ISC
@@ -25,7 +25,7 @@ function aa(s) {
25
25
  id: s.dashboardId
26
26
  // override the id to the dashboard id so that the dashboard is not loaded
27
27
  };
28
- return /* @__PURE__ */ a(D, { FallbackComponent: w, children: /* @__PURE__ */ a(P, { dashboardProps: l, children: /* @__PURE__ */ a(M, { children: /* @__PURE__ */ a(k, { displayPreferences: o, children: /* @__PURE__ */ a(A, { type: "visual", ...l, children: /* @__PURE__ */ a(Y, { cardId: s.cardId }) }) }) }) }) });
28
+ return /* @__PURE__ */ a(y, { FallbackComponent: w, children: /* @__PURE__ */ a(P, { dashboardProps: l, children: /* @__PURE__ */ a(M, { children: /* @__PURE__ */ a(k, { displayPreferences: o, children: /* @__PURE__ */ a(A, { type: "visual", ...l, children: /* @__PURE__ */ a(Y, { cardId: s.cardId }) }) }) }) }) });
29
29
  }
30
30
  function Y({ cardId: s }) {
31
31
  const o = F((r) => {
@@ -41,7 +41,7 @@ function Y({ cardId: s }) {
41
41
  return { card: f, frame: m };
42
42
  }, [o, s]);
43
43
  return !i || !l ? /* @__PURE__ */ a(
44
- y,
44
+ g,
45
45
  {
46
46
  error: new Error("Card not found"),
47
47
  resetErrorBoundary: () => {
@@ -49,13 +49,13 @@ function Y({ cardId: s }) {
49
49
  customerFacingMessage: `Card not found with ID: ${s}`
50
50
  }
51
51
  ) : /* @__PURE__ */ a("main", { className: "flex h-full grow flex-col", children: /* @__PURE__ */ a(
52
- D,
52
+ y,
53
53
  {
54
54
  FallbackComponent: ({
55
55
  error: r,
56
56
  resetErrorBoundary: t
57
57
  }) => /* @__PURE__ */ a(
58
- y,
58
+ g,
59
59
  {
60
60
  error: r,
61
61
  resetErrorBoundary: t,
@@ -78,7 +78,7 @@ function ea({
78
78
  icon: e,
79
79
  showNone: h = !1
80
80
  }) {
81
- const c = p.useRef(null), [b, g] = p.useState(!1), [x, E] = p.useState("100%"), C = h ? [...o || [], { id: "none", name: "None" }] : o;
81
+ const c = p.useRef(null), [v, D] = p.useState(!1), [x, E] = p.useState("100%"), C = h ? [...o || [], { id: "none", name: "None" }] : o;
82
82
  p.useLayoutEffect(() => {
83
83
  c.current && E(c.current.offsetWidth);
84
84
  }, []);
@@ -87,17 +87,17 @@ function ea({
87
87
  return r ? "Loading..." : t ? "Error" : i ? (n = o == null ? void 0 : o.find((u) => u.id === i)) == null ? void 0 : n.name : `Select ${s}`;
88
88
  }
89
89
  function T(n, u) {
90
- l(u), g(!1);
90
+ l(u), D(!1);
91
91
  }
92
- return /* @__PURE__ */ d(R, { open: b, onOpenChange: g, children: [
92
+ return /* @__PURE__ */ d(R, { open: v, onOpenChange: D, children: [
93
93
  /* @__PURE__ */ a(I, { asChild: !0, children: /* @__PURE__ */ d(
94
94
  V,
95
95
  {
96
96
  ref: c,
97
97
  variant: "outline",
98
98
  role: "combobox",
99
- "aria-expanded": b,
100
- className: v("flex h-9 w-full justify-between", m),
99
+ "aria-expanded": v,
100
+ className: b("flex h-9 w-full justify-between", m),
101
101
  children: [
102
102
  /* @__PURE__ */ d("div", { className: "flex items-center gap-2", children: [
103
103
  e && /* @__PURE__ */ a("div", { className: "mr-2", children: e }),
@@ -118,7 +118,7 @@ function ea({
118
118
  /* @__PURE__ */ a(q, { className: "h-7", onClick: f, children: /* @__PURE__ */ a(
119
119
  K,
120
120
  {
121
- className: v(
121
+ className: b(
122
122
  "size-3.5 opacity-50",
123
123
  r && "animate-spin"
124
124
  )
@@ -141,7 +141,7 @@ function ea({
141
141
  /* @__PURE__ */ a(
142
142
  G,
143
143
  {
144
- className: v(
144
+ className: b(
145
145
  "size-4",
146
146
  i === n.id ? "opacity-100" : "opacity-0"
147
147
  )
@@ -164,29 +164,30 @@ export {
164
164
  ea as Combobox,
165
165
  ta as DATE_FORMAT_VALUES,
166
166
  na as Dashboard,
167
+ Za as DashboardExportDialog,
167
168
  ia as DashboardWC,
168
169
  Ka as EMPTY_SELECTION,
169
170
  da as PivotMarkerEnum,
170
171
  $a as ResourceManagementPanel,
171
172
  la as ResourceType,
172
- Za as ScheduleDashboard,
173
+ ae as ScheduleDashboard,
173
174
  P as SemaphorContextProvider,
174
175
  ca as SemaphorDataProvider,
175
176
  ua as SemaphorQueryClient,
176
177
  ha as ShareDialog,
177
178
  pa as Surfboard,
178
179
  aa as Visual,
179
- ae as VisualEditingControls,
180
- ee as cleanCard,
180
+ ee as VisualEditingControls,
181
+ se as cleanCard,
181
182
  fa as createEmptyKpiConfig,
182
183
  ma as createSqlGenConfig,
183
184
  Ca as downloadPdf,
184
- va as emitDashboardLoad,
185
- ba as emitDashboardUnload,
186
- ga as fmt,
187
- ya as getColumnDataType,
188
- se as getDashbaordStateWithoutData,
189
- Da as getFilterValueType,
185
+ ba as emitDashboardLoad,
186
+ va as emitDashboardUnload,
187
+ Da as fmt,
188
+ ga as getColumnDataType,
189
+ re as getDashbaordStateWithoutData,
190
+ ya as getFilterValueType,
190
191
  xa as getFormattedTableNameForQuery,
191
192
  Ea as getQualifiedTableName,
192
193
  Na as getSql,
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../chunks/index-3qBZw0dE.js"),r=require("../types/index.cjs");exports.Surfboard=e.DashboardPlus;exports.EMPTY_SELECTION=r.EMPTY_SELECTION;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../chunks/index-GG6fcfuj.js"),r=require("../types/index.cjs");exports.Surfboard=e.DashboardPlus;exports.EMPTY_SELECTION=r.EMPTY_SELECTION;
@@ -1,4 +1,4 @@
1
- import { a } from "../chunks/index-C_K3WRIV.js";
1
+ import { a } from "../chunks/index-BdiWSBWd.js";
2
2
  import { EMPTY_SELECTION as E } from "../types/index.js";
3
3
  export {
4
4
  E as EMPTY_SELECTION,
@@ -672,6 +672,13 @@ export declare type DashboardEventHandlers = {
672
672
  onExportData?: (payload: ExportDataPayload) => void;
673
673
  };
674
674
 
675
+ export declare function DashboardExportDialog({ open, onOpenChange, }: DashboardExportDialogProps): JSX_2.Element;
676
+
677
+ declare interface DashboardExportDialogProps {
678
+ open: boolean;
679
+ onOpenChange: (open: boolean) => void;
680
+ }
681
+
675
682
  declare type DashboardPlusProps = {
676
683
  showControls?: boolean;
677
684
  showFooter?: boolean;
@@ -861,7 +868,7 @@ export declare type Dialect = 'mysql' | 'postgres' | 'bigquery' | 'redshift' | '
861
868
 
862
869
  export declare type DisplayDataType = 'string' | 'date' | 'number' | 'html' | 'none';
863
870
 
864
- export declare function downloadPdf(apiServiceUrl: string, password?: string): Promise<void>;
871
+ export declare function downloadPdf(apiServiceUrl: string, password?: string, sheetSelection?: 'current' | 'all'): Promise<void>;
865
872
 
866
873
  declare interface DrillActions {
867
874
  updateDrillHierarchies: (h: DrillHierarchy[]) => void;
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "email": "support@semaphor.cloud"
6
6
  },
7
7
  "license": "MIT",
8
- "version": "0.1.124",
8
+ "version": "0.1.126",
9
9
  "description": "Fully interactive and customizable dashboards for your apps.",
10
10
  "keywords": [
11
11
  "react",
@@ -1,26 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-3qBZw0dE.js"),f=require("react");require("react-dom");const U=require("./schedule-dashboard-B-z6gEwK.js"),ne=require("./editor-action-buttons-C_UBbFu6.js");function Ce(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const r=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(n,a,r.get?r:{enumerable:!0,get:()=>t[a]})}}return n.default=t,Object.freeze(n)}const D=Ce(f);/**
2
- * @license lucide-react v0.453.0 - ISC
3
- *
4
- * This source code is licensed under the ISC license.
5
- * See the LICENSE file in the root directory of this source tree.
6
- */const Me=s.createLucideIcon("Glasses",[["circle",{cx:"6",cy:"15",r:"4",key:"vux9w4"}],["circle",{cx:"18",cy:"15",r:"4",key:"18o8ve"}],["path",{d:"M14 15a2 2 0 0 0-2-2 2 2 0 0 0-2 2",key:"1ag4bs"}],["path",{d:"M2.5 13 5 7c.7-1.3 1.4-2 3-2",key:"1hm1gs"}],["path",{d:"M21.5 13 19 7c-.7-1.3-1.5-2-3-2",key:"1r31ai"}]]);/**
7
- * @license lucide-react v0.453.0 - ISC
8
- *
9
- * This source code is licensed under the ISC license.
10
- * See the LICENSE file in the root directory of this source tree.
11
- */const ke=s.createLucideIcon("Menu",[["line",{x1:"4",x2:"20",y1:"12",y2:"12",key:"1e0a9i"}],["line",{x1:"4",x2:"20",y1:"6",y2:"6",key:"1owob3"}],["line",{x1:"4",x2:"20",y1:"18",y2:"18",key:"yk5zj1"}]]);/**
12
- * @license lucide-react v0.453.0 - ISC
13
- *
14
- * This source code is licensed under the ISC license.
15
- * See the LICENSE file in the root directory of this source tree.
16
- */const Le=s.createLucideIcon("Moon",[["path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z",key:"a7tn18"}]]);/**
17
- * @license lucide-react v0.453.0 - ISC
18
- *
19
- * This source code is licensed under the ISC license.
20
- * See the LICENSE file in the root directory of this source tree.
21
- */const Ie=s.createLucideIcon("ShieldX",[["path",{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",key:"oel41y"}],["path",{d:"m14.5 9.5-5 5",key:"17q4r4"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]]);/**
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
- */const Pe=s.createLucideIcon("Sun",[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m4.93 4.93 1.41 1.41",key:"149t6j"}],["path",{d:"m17.66 17.66 1.41 1.41",key:"ptbguv"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"m6.34 17.66-1.41 1.41",key:"1m8zz5"}],["path",{d:"m19.07 4.93-1.41 1.41",key:"1shlcs"}]]);var Te=s.requireShim();function Ae(){const{setTheme:t}=s.useTheme(),n=s.useDashboardStore(a=>a.actions.setDashboardTheme);return e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsxs(s.Button,{className:"h-7 p-2",variant:"ghost",size:"sm",children:[e.jsx(Pe,{strokeWidth:1.5,className:"h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0"}),e.jsx(Le,{strokeWidth:1.5,className:"absolute h-4 w-4 rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100"}),e.jsx("span",{className:"sr-only",children:"Toggle theme"})]})}),e.jsxs(s.DropdownMenuContent,{align:"end",children:[e.jsx(s.DropdownMenuItem,{onClick:()=>{t("light"),n("light")},children:"Light"}),e.jsx(s.DropdownMenuItem,{onClick:()=>{t("dark"),n("dark")},children:"Dark"}),e.jsx(s.DropdownMenuItem,{onClick:()=>{t("system"),n("system")},children:"System"})]})]})}async function Fe(t,n,a,r,i){if(!i)return null;const o=JSON.stringify(a),d=`${t}/v1/lens`;return await s.postRequest(d,i,{name:n,template:o,filterValues:r,operation:"create"})}async function K(t,n,a){if(!a)return null;const{id:r,template:i,filterValues:o,isDefault:d,shared:m}=n,h=`${t}/v1/lens`;return await s.postRequest(h,a,{lensId:r,template:i,filterValues:o,isDefault:d,shared:m,operation:"update"})}async function Ee(t,n,a){if(!a)return null;const r=`${t}/v1/lens`;return await s.postRequest(r,a,{operation:"delete",lensId:n})}function Re(){const[t,n]=f.useState(""),[a,r]=f.useState(!1),i=s.useDashboardStore(w=>w.lenses),{setLenses:o,setSelectedLensId:d}=s.useDashboardActions(),[m,h]=f.useState(!1),[g,u]=f.useState(!1),l=s.useDashboardStore(w=>w.dashboard),p=s.useDashboardStore(w=>w.filterValues),{authToken:j,tokenProps:b}=s.useSemaphorContext();async function y(){h(!0);const w=U.getDashbaordStateWithoutData(l),C=await Fe(b.apiServiceUrl,t,w,p,j==null?void 0:j.accessToken);C&&(o([...i||[],C]),d(C.id),u(!1)),h(!1)}return e.jsxs(s.Dialog,{open:g,onOpenChange:u,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Lens"]})}),e.jsxs(s.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Create Lens"}),e.jsx(s.DialogDescription,{children:"Lenses are private by default and are only visible to you."})]}),e.jsx("div",{className:"grid gap-4 py-4",children:e.jsxs("div",{className:"grid grid-cols-8 items-center gap-4",children:[e.jsx(s.Label,{className:"text-right",children:"Name"}),e.jsx(s.Input$1,{value:t,onChange:w=>{n(w.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),a&&e.jsx("p",{className:"text-sm",children:"The lens name already exists. Use a differnet name."}),e.jsx(s.DialogFooter,{children:e.jsx(s.Button,{size:"sm",variant:"outline",type:"submit",onClick:y,disabled:m,children:m?"Creating...":"Add"})})]})]})}function Ge(){const[t,n]=f.useState(!1),a=s.useDashboardStore(l=>l.lenses),r=s.useDashboardStore(l=>l.selectedLensId),{setLenses:i,setSelectedLensId:o}=s.useDashboardActions(),{authToken:d,tokenProps:m}=s.useSemaphorContext();async function h(l){o(l)}async function g(l){if(await Ee(m.apiServiceUrl,l,d==null?void 0:d.accessToken)){const j=a==null?void 0:a.filter(b=>b.id!==l);i(j||[]),o("original")}}async function u(l){const p=a==null?void 0:a.map(y=>y.id===l.id?{...y,isDefault:!l.isDefault}:{...y,isDefault:!1});i(p||[]);const j={...l,isDefault:!l.isDefault};await K(m.apiServiceUrl,j,d==null?void 0:d.accessToken);const b=a==null?void 0:a.find(y=>y.isDefault);if(b&&b.id!==l.id){const y={...b,isDefault:!1};await K(m.apiServiceUrl,y,d==null?void 0:d.accessToken)}}return e.jsxs(s.DropdownMenu,{open:t,onOpenChange:n,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Lenses",className:"h-7 p-2",children:e.jsx(Me,{className:"h-4 w-4"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-60",children:[e.jsx(s.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuRadioGroup,{value:r,onValueChange:h,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),a==null?void 0:a.map(l=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:l.id,children:[e.jsx("p",{children:l.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(s.House,{onClick:p=>{p.preventDefault(),u(l)},className:s.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!l.isDefault,"text-green-500":l.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:p=>{p.preventDefault(),g(l.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},l.id))]})]})]})}function Ue({iconClassName:t}){const[n,a]=f.useState(!1),[r,i]=f.useState(""),[o,d]=f.useState(!1),m=s.useDashboardStore(l=>l.isDownloadingPdf),{tokenProps:h}=s.useSemaphorContext();async function g(){const l=s.ue.loading("Generating PDF... may take up to 60 seconds");try{await s.downloadPdf(h.apiServiceUrl),s.ue.dismiss(l),s.ue.success("PDF downloaded successfully!",{duration:2e3})}catch(p){s.ue.dismiss(l),s.ue.error("Failed to download PDF",{description:"Please try again or contact support.",richColors:!0}),console.error("PDF download error:",p)}}async function u(){if(!r)return;a(!1),i(""),d(!1);const l=s.ue.loading("Generating protected PDF... may take up to 60 seconds");try{await s.downloadPdf(h.apiServiceUrl,r),s.ue.dismiss(l),s.ue.success("Protected PDF downloaded successfully!",{duration:2e3,position:"top-right"})}catch(p){s.ue.dismiss(l),s.ue.error("Failed to download protected PDF. Please try again."),console.error("Protected PDF download error:",p)}}return e.jsxs(e.Fragment,{children:[e.jsxs(s.DropdownMenu,{modal:!1,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-7 p-2",disabled:m,children:e.jsx(s.Download,{className:s.cn("size-4",t)})})}),e.jsxs(s.DropdownMenuContent,{align:"end",children:[e.jsxs(s.DropdownMenuItem,{onClick:g,children:[e.jsx(s.File,{className:"mr-2 h-4 w-4"}),"Download PDF"]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>a(!0),children:[e.jsx(s.Lock,{className:"mr-2 h-4 w-4"}),"Download Protected PDF"]})]})]}),e.jsx(s.Dialog,{open:n,onOpenChange:a,children:e.jsxs(s.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Download Protected PDF"}),e.jsx(s.DialogDescription,{children:"Enter a password to protect your PDF. The PDF will be encrypted and require this password to open."})]}),e.jsx("div",{className:"grid gap-4 py-4",children:e.jsxs("div",{className:"grid gap-2",children:[e.jsx(s.Label,{htmlFor:"password",children:"Password"}),e.jsxs("div",{className:"relative",children:[e.jsx(s.Input$1,{id:"password",type:o?"text":"password",value:r,onChange:l=>i(l.target.value),placeholder:"Enter password",className:"pr-10",onKeyDown:l=>{l.key==="Enter"&&r&&u()}}),e.jsx(s.Button,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3 py-2 hover:bg-transparent",onClick:()=>d(!o),children:o?e.jsx(s.EyeOff,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(s.Eye,{className:"h-4 w-4 text-muted-foreground"})})]})]})}),e.jsxs(s.DialogFooter,{children:[e.jsx(s.Button,{variant:"outline",onClick:()=>a(!1),children:"Cancel"}),e.jsx(s.Button,{onClick:u,disabled:!r,children:"Download"})]})]})})]})}const Oe=async(t,n,a)=>{const r=`${t}/management/v1/groups`;return await s.postRequestRegular(r,n,a)},Be=async(t,n,a)=>{const r=`${t}/management/v1/groups/${a}`,i=await fetch(r,{method:"DELETE",headers:{Authorization:`Bearer ${n}`}});if(!i.ok){const o=await i.text();throw new Error(o||"Failed to delete group")}},qe=async(t,n,a,r)=>{const i=`${t}/management/v1/groups/${a}/members`;return await s.postRequestRegular(i,n,r)},$e=async(t,n,a,r)=>{const i=`${t}/management/v1/groups/${a}/members`,o=await fetch(i,{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify(r)});if(!o.ok){const d=await o.text();throw new Error(d||"Failed to remove group members")}};function ze(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:r=>Oe(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r),onSuccess:()=>{a.invalidateQueries({queryKey:["groups"]}),s.ue.success("Group created successfully")},onError:r=>{console.error("Failed to create group:",r),s.ue.error("Failed to create group",{description:r.message})}})}function _e(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:r=>Be(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r),onSuccess:(r,i)=>{a.invalidateQueries({queryKey:["groups"]}),a.removeQueries({queryKey:["group",i]}),s.ue.success("Group deleted successfully")},onError:r=>{console.error("Failed to delete group:",r),s.ue.error("Failed to delete group",{description:r.message})}})}function Qe(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:i})=>qe(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r,i),onSuccess:(r,i)=>{a.invalidateQueries({queryKey:["group",i.groupId]}),a.invalidateQueries({queryKey:["group-members",i.groupId]}),a.invalidateQueries({queryKey:["groups"]}),s.ue.success("Members added successfully")},onError:r=>{console.error("Failed to add group members:",r),s.ue.error("Failed to add members",{description:r.message})}})}function He(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:i})=>$e(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r,i),onSuccess:(r,i)=>{a.invalidateQueries({queryKey:["group",i.groupId]}),a.invalidateQueries({queryKey:["group-members",i.groupId]}),a.invalidateQueries({queryKey:["groups"]}),s.ue.success("Members removed successfully")},onError:r=>{console.error("Failed to remove group members:",r),s.ue.error("Failed to remove members",{description:r.message})}})}function Ve({onSuccess:t,tenantId:n,isTenantUser:a}){const[r,i]=f.useState(""),[o,d]=f.useState(""),[m,h]=f.useState({}),g=ze(),u=()=>{const p={};return r.trim()?r.length<3?p.name="Group name must be at least 3 characters":r.length>50&&(p.name="Group name must be less than 50 characters"):p.name="Group name is required",o&&o.length>200&&(p.description="Description must be less than 200 characters"),h(p),Object.keys(p).length===0},l=async p=>{if(p.preventDefault(),!u())return;const j={name:r.trim(),description:o.trim()||void 0,type:a?"TENANT_GROUP":"ORG_GROUP",...a&&n?{tenantId:n}:{}};try{await g.mutateAsync(j),i(""),d(""),h({}),t()}catch(b){console.error("Failed to create group:",b)}};return e.jsxs("form",{onSubmit:l,className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(s.Label,{htmlFor:"group-name",children:["Group Name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(s.Input$1,{id:"group-name",placeholder:"e.g., Marketing Team, Engineering Squad",value:r,onChange:p=>{i(p.target.value),m.name&&h(j=>({...j,name:""}))},className:m.name?"border-destructive":"",disabled:g.isPending}),m.name&&e.jsx("p",{className:"text-sm text-destructive",children:m.name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(s.Label,{htmlFor:"group-description",children:["Description",e.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:"(optional)"})]}),e.jsx(s.Textarea,{id:"group-description",placeholder:"Describe the purpose of this group...",value:o,onChange:p=>{d(p.target.value),m.description&&h(j=>({...j,description:""}))},className:m.description?"border-destructive":"",disabled:g.isPending,rows:3}),m.description&&e.jsx("p",{className:"text-sm text-destructive",children:m.description}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[o.length,"/200 characters"]})]}),e.jsx("div",{className:"rounded-lg border bg-muted/50 p-4",children:e.jsxs("div",{className:"flex gap-3",children:[e.jsx(s.CircleAlert,{className:"h-4 w-4 mt-0.5 text-muted-foreground"}),e.jsx("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."})]})})]}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx(s.Button,{type:"button",variant:"outline",onClick:()=>{i(""),d(""),h({})},disabled:g.isPending,children:"Clear"}),e.jsx(s.Button,{type:"submit",disabled:g.isPending||!r.trim(),children:g.isPending?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Creating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(s.Users,{className:"mr-2 h-4 w-4"}),"Create Group"]})})]})]})}function Ke(t,n=[]){let a=[];function r(o,d){const m=D.createContext(d),h=a.length;a=[...a,d];const g=l=>{var C;const{scope:p,children:j,...b}=l,y=((C=p==null?void 0:p[t])==null?void 0:C[h])||m,w=D.useMemo(()=>b,Object.values(b));return e.jsx(y.Provider,{value:w,children:j})};g.displayName=o+"Provider";function u(l,p){var y;const j=((y=p==null?void 0:p[t])==null?void 0:y[h])||m,b=D.useContext(j);if(b)return b;if(d!==void 0)return d;throw new Error(`\`${l}\` must be used within \`${o}\``)}return[g,u]}const i=()=>{const o=a.map(d=>D.createContext(d));return function(m){const h=(m==null?void 0:m[t])||o;return D.useMemo(()=>({[`__scope${t}`]:{...m,[t]:h}}),[m,h])}};return i.scopeName=t,[r,We(i,...n)]}function We(...t){const n=t[0];if(t.length===1)return n;const a=()=>{const r=t.map(i=>({useScope:i(),scopeName:i.scopeName}));return function(o){const d=r.reduce((m,{useScope:h,scopeName:g})=>{const l=h(o)[`__scope${g}`];return{...m,...l}},{});return D.useMemo(()=>({[`__scope${n.scopeName}`]:d}),[d])}};return a.scopeName=n.scopeName,a}function Je(t){const n=D.useRef(t);return D.useEffect(()=>{n.current=t}),D.useMemo(()=>(...a)=>{var r;return(r=n.current)==null?void 0:r.call(n,...a)},[])}var W=globalThis!=null&&globalThis.document?D.useLayoutEffect:()=>{},Xe=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],J=Xe.reduce((t,n)=>{const a=s.createSlot(`Primitive.${n}`),r=D.forwardRef((i,o)=>{const{asChild:d,...m}=i,h=d?a:n;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(h,{...m,ref:o})});return r.displayName=`Primitive.${n}`,{...t,[n]:r}},{});function Ye(){return Te.useSyncExternalStore(Ze,()=>!0,()=>!1)}function Ze(){return()=>{}}var X="Avatar",[es]=Ke(X),[ss,ie]=es(X),ce=D.forwardRef((t,n)=>{const{__scopeAvatar:a,...r}=t,[i,o]=D.useState("idle");return e.jsx(ss,{scope:a,imageLoadingStatus:i,onImageLoadingStatusChange:o,children:e.jsx(J.span,{...r,ref:n})})});ce.displayName=X;var le="AvatarImage",de=D.forwardRef((t,n)=>{const{__scopeAvatar:a,src:r,onLoadingStatusChange:i=()=>{},...o}=t,d=ie(le,a),m=ts(r,o),h=Je(g=>{i(g),d.onImageLoadingStatusChange(g)});return W(()=>{m!=="idle"&&h(m)},[m,h]),m==="loaded"?e.jsx(J.img,{...o,ref:n,src:r}):null});de.displayName=le;var ue="AvatarFallback",me=D.forwardRef((t,n)=>{const{__scopeAvatar:a,delayMs:r,...i}=t,o=ie(ue,a),[d,m]=D.useState(r===void 0);return D.useEffect(()=>{if(r!==void 0){const h=window.setTimeout(()=>m(!0),r);return()=>window.clearTimeout(h)}},[r]),d&&o.imageLoadingStatus!=="loaded"?e.jsx(J.span,{...i,ref:n}):null});me.displayName=ue;function oe(t,n){return t?n?(t.src!==n&&(t.src=n),t.complete&&t.naturalWidth>0?"loaded":"loading"):"error":"idle"}function ts(t,{referrerPolicy:n,crossOrigin:a}){const r=Ye(),i=D.useRef(null),o=r?(i.current||(i.current=new window.Image),i.current):null,[d,m]=D.useState(()=>oe(o,t));return W(()=>{m(oe(o,t))},[o,t]),W(()=>{const h=l=>()=>{m(l)};if(!o)return;const g=h("loaded"),u=h("error");return o.addEventListener("load",g),o.addEventListener("error",u),n&&(o.referrerPolicy=n),typeof a=="string"&&(o.crossOrigin=a),()=>{o.removeEventListener("load",g),o.removeEventListener("error",u)}},[o,a,n]),d}var he=ce,pe=de,xe=me;const Y=D.forwardRef(({className:t,...n},a)=>e.jsx(he,{ref:a,className:s.cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",t),...n}));Y.displayName=he.displayName;const as=D.forwardRef(({className:t,...n},a)=>e.jsx(pe,{ref:a,className:s.cn("aspect-square h-full w-full",t),...n}));as.displayName=pe.displayName;const Z=D.forwardRef(({className:t,...n},a)=>e.jsx(xe,{ref:a,className:s.cn("flex h-full w-full items-center justify-center rounded-full bg-muted",t),...n}));Z.displayName=xe.displayName;function rs({open:t,onOpenChange:n,group:a,onUpdate:r}){const[i,o]=f.useState("members"),[d,m]=f.useState(""),[h,g]=f.useState([]),[u,l]=f.useState([]),{data:p,isLoading:j,refetch:b}=s.useGroupMembers(a.id),y=a.type==="TENANT_GROUP"?"tenant":"organization",{users:w,isLoading:C}=s.useUnifiedUsers({type:y,tenantId:a.tenantId||void 0,active:!0,limit:100}),T=Qe(),P=He(),M=(p==null?void 0:p.members)||[],R=f.useMemo(()=>new Set(M.map(x=>x.userId)),[M]),v=f.useMemo(()=>w.filter(x=>!R.has(x.id)),[w,R]),I=f.useMemo(()=>{if(!d)return v;const x=d.toLowerCase();return v.filter(S=>{var k,F;return((k=S.name)==null?void 0:k.toLowerCase().includes(x))||((F=S.email)==null?void 0:F.toLowerCase().includes(x))})},[v,d]),N=f.useMemo(()=>{if(!d)return M;const x=d.toLowerCase();return M.filter(S=>{var k,F,q,E;return((F=(k=S.user)==null?void 0:k.name)==null?void 0:F.toLowerCase().includes(x))||((E=(q=S.user)==null?void 0:q.email)==null?void 0:E.toLowerCase().includes(x))})},[M,d]),A=async()=>{if(h.length!==0)try{await T.mutateAsync({groupId:a.id,data:{userIds:h,userType:y==="tenant"?"tenant":"org"}}),g([]),o("members"),b(),r==null||r()}catch(x){console.error("Failed to add members:",x)}},_=async()=>{if(u.length!==0)try{await P.mutateAsync({groupId:a.id,data:{userIds:u}}),l([]),b(),r==null||r()}catch(x){console.error("Failed to remove members:",x)}},Q=x=>{g(S=>S.includes(x)?S.filter(k=>k!==x):[...S,x])},O=x=>{l(S=>S.includes(x)?S.filter(k=>k!==x):[...S,x])};return e.jsx(e.Fragment,{children:e.jsx(s.Dialog,{open:t,onOpenChange:n,children:e.jsxs(s.DialogContent,{className:"max-w-3xl max-h-[80vh]","aria-describedby":"group-members-description",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:a.name}),e.jsx("div",{className:"flex items-center gap-2 mt-1",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:[M.length," ",M.length===1?"member":"members"]})}),e.jsxs("p",{id:"group-members-description",className:"sr-only",children:["Add or remove members from the ",a.name," group"]})]}),e.jsxs(s.Tabs,{value:i,onValueChange:x=>{o(x),m(""),l([])},className:"mt-4",children:[e.jsxs(s.TabsList,{className:"grid w-full grid-cols-2",children:[e.jsx(s.TabsTrigger,{value:"members",children:"Current Members"}),e.jsx(s.TabsTrigger,{value:"add",children:"Add Members"})]}),e.jsxs(s.TabsContent,{value:"members",className:"mt-4 space-y-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(s.Search,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(s.Input$1,{placeholder:"Search members...",value:d,onChange:x=>m(x.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:u.length>0?"h-[300px]":"h-[350px]",children:j?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(x=>e.jsx(s.Skeleton,{className:"h-16 w-full"},x))}):N.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(s.Users,{className:"h-12 w-12 mb-3 opacity-50"}),e.jsx("p",{className:"text-sm font-medium",children:d?"No members found":"No members yet"}),e.jsx("p",{className:"text-xs mt-1",children:d?"Try a different search":'Switch to the "Add Members" tab to add people to this group'})]}):e.jsx("div",{className:"space-y-2",children:N.map(x=>e.jsx(ns,{member:x,selected:u.includes(x.userId),onToggle:()=>O(x.userId)},x.id))})}),u.length>0&&e.jsxs("div",{className:"flex items-center justify-between pt-4 border-t",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[u.length," member",u.length!==1?"s":""," selected"]}),e.jsx(s.Button,{variant:"destructive",size:"sm",onClick:_,disabled:P.isPending,children:P.isPending?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Removing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(s.Trash2,{className:"mr-2 h-4 w-4"}),"Remove Selected"]})})]})]}),e.jsxs(s.TabsContent,{value:"add",className:"mt-4 space-y-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(s.Search,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(s.Input$1,{placeholder:"Search users to add...",value:d,onChange:x=>m(x.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:"h-[300px]",children:C?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(x=>e.jsx(s.Skeleton,{className:"h-16 w-full"},x))}):I.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(s.UserPlus,{className:"h-12 w-12 mb-3 opacity-50"}),e.jsx("p",{className:"text-sm font-medium",children:"No available users"}),e.jsx("p",{className:"text-xs mt-1",children:d?"Try a different search":"All eligible users are already members"})]}):e.jsx("div",{className:"space-y-2",children:I.map(x=>e.jsx(os,{user:x,selected:h.includes(x.id),onToggle:()=>Q(x.id)},x.id))})}),h.length>0&&e.jsxs("div",{className:"flex items-center justify-between pt-4 border-t",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[h.length," user",h.length!==1?"s":""," selected"]}),e.jsx(s.Button,{onClick:A,disabled:T.isPending,children:T.isPending?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Adding..."]}):e.jsxs(e.Fragment,{children:[e.jsx(s.UserPlus,{className:"mr-2 h-4 w-4"}),"Add Members"]})})]})]})]})]})})})}function ns({member:t,selected:n,onToggle:a}){var i,o,d,m;const r=((o=(i=t.user)==null?void 0:i.name)==null?void 0:o.split(" ").map(h=>h[0]).join("").toUpperCase())||"?";return e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg border bg-card hover:bg-muted/50 cursor-pointer",onClick:a,children:[e.jsx(s.Checkbox,{checked:n}),e.jsx(Y,{className:"h-8 w-8",children:e.jsx(Z,{className:"text-xs",children:r})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:((d=t.user)==null?void 0:d.name)||"Unknown User"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(m=t.user)==null?void 0:m.email})]})]})}function os({user:t,selected:n,onToggle:a}){var i;const r=((i=t.name)==null?void 0:i.split(" ").map(o=>o[0]).join("").toUpperCase())||"?";return e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg border bg-card hover:bg-muted/50 cursor-pointer",onClick:a,children:[e.jsx(s.Checkbox,{checked:n}),e.jsx(Y,{className:"h-8 w-8",children:e.jsx(Z,{className:"text-xs",children:r})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:t.name}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t.email})]})]})}function is({open:t,onOpenChange:n}){const[a,r]=f.useState("groups"),[i,o]=f.useState(""),[d,m]=f.useState(null),[h,g]=f.useState(!1),[u,l]=f.useState(null),{tokenProps:p}=s.useSemaphorContext(),{currentUser:j}=s.useCurrentUserInfo(),b=_e(),y=(j==null?void 0:j.type)==="tenant",w=p==null?void 0:p.tenantId,{groups:C,isLoading:T,refetch:P}=s.useGroups({type:y?"TENANT_GROUP":"all",tenantId:y?w:void 0,includeMembers:!1}),M=C.filter(N=>{var A;return N.name.toLowerCase().includes(i.toLowerCase())||((A=N.description)==null?void 0:A.toLowerCase().includes(i.toLowerCase()))}),R=async()=>{if(u)try{await b.mutateAsync(u.id),l(null),P()}catch(N){console.error("Failed to delete group:",N)}},v=N=>{m(N),g(!0)},I=()=>{r("groups"),P()};return e.jsxs(e.Fragment,{children:[e.jsx(s.Dialog,{open:t,onOpenChange:n,children:e.jsxs(s.DialogContent,{className:"max-w-4xl max-h-[80vh]",children:[e.jsxs(s.DialogHeader,{children:[e.jsxs(s.DialogTitle,{className:"flex items-center gap-2",children:[e.jsx(s.Users,{className:"h-5 w-5"}),"Group Management"]}),e.jsx(s.DialogDescription,{children:"Manage your groups, create new groups, and control group membership"})]}),e.jsxs(s.Tabs,{value:a,onValueChange:r,className:"mt-4",children:[e.jsxs(s.TabsList,{className:"grid w-full grid-cols-2",children:[e.jsxs(s.TabsTrigger,{value:"groups",className:"flex items-center gap-2",children:[e.jsx(s.Users,{className:"h-4 w-4"}),"Groups"]}),e.jsxs(s.TabsTrigger,{value:"create",className:"flex items-center gap-2",children:[e.jsx(s.Plus,{className:"h-4 w-4"}),"Create Group"]})]}),e.jsx(s.TabsContent,{value:"groups",className:"mt-4",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(s.Search,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(s.Input$1,{placeholder:"Search groups...",value:i,onChange:N=>o(N.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:"h-[400px]",children:T?e.jsx("div",{className:"space-y-3",children:[1,2,3].map(N=>e.jsx(s.Skeleton,{className:"h-24 w-full"},N))}):M.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(s.Users,{className:"h-12 w-12 mb-3 opacity-50"}),e.jsx("p",{className:"text-sm font-medium",children:"No groups found"}),e.jsx("p",{className:"text-xs mt-1",children:i?"Try a different search":"Create your first group to get started"})]}):e.jsx("div",{className:"space-y-3",children:M.map(N=>e.jsx(cs,{group:N,onManageMembers:()=>v(N),onDelete:()=>l(N),currentUserId:j==null?void 0:j.id},N.id))})})]})}),e.jsx(s.TabsContent,{value:"create",className:"mt-4",children:e.jsx(Ve,{onSuccess:I,tenantId:w,isTenantUser:y})})]})]})}),d&&e.jsx(rs,{open:h,onOpenChange:g,group:d,onUpdate:()=>P()}),e.jsx(s.AlertDialog,{open:!!u,onOpenChange:()=>l(null),children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Delete Group"}),e.jsxs(s.AlertDialogDescription,{children:['Are you sure you want to delete "',u==null?void 0:u.name,'"? This action cannot be undone and will remove all members from the group.']})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:R,disabled:b.isPending,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:b.isPending?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Deleting..."]}):"Delete Group"})]})]})})]})}function cs({group:t,onManageMembers:n,onDelete:a,currentUserId:r}){const i=t.createdBy===r;return e.jsx("div",{className:"rounded-lg border bg-card p-4 transition-colors hover:bg-muted/50",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium",children:t.name}),t.description&&e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:t.description})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-xs text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(s.Users,{className:"h-3 w-3"}),t.memberCount," ",t.memberCount===1?"member":"members"]}),e.jsxs("span",{children:["Created ",s.format(new Date(t.createdAt),"MMM d, yyyy")]})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:n,title:"Manage members",children:e.jsx(s.UserPlus,{className:"h-4 w-4"})}),i&&e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:a,title:"Delete group",className:"text-destructive hover:text-destructive",children:e.jsx(s.Trash2,{className:"h-4 w-4"})})]})]})})}function ls(){var te,ae,re;const{authToken:t,tokenProps:n,id:a}=s.useSemaphorContext(),{isLocalDev:r}=s.useDashboardPreferences(),{permissions:i}=s.useRoleAwareDisplayPreferences(),o=s.useHasDashboardId(),{isLoading:d}=s.useDashboardQuery();s.useDashboardStore(c=>c.theme);const m=s.useDashboardStore(c=>c.lenses),h=s.useDashboardStore(c=>c.selectedLensId),g=m==null?void 0:m.find(c=>c.id===h),u=s.useDashboardStore(c=>c.dashboard);s.useDashboardStore(c=>c.selectedSheetId);const l=s.useDashboardStore(c=>c.isDashboardEditing),{setDashboardTitle:p}=s.useDashboardStore(c=>c.actions),[j,b]=f.useState(!1),[y,w]=f.useState(!1),[C,T]=f.useState(!1),P=s.useDashboardStore(c=>c.isDashboardPanelOpen),M=s.useDashboardStore(c=>c.actions.setIsDashboardPanelOpen),R=s.useDashboardStore(c=>c.filterValues),v=s.useDashboardStore(c=>c.isVisualEditing);s.useEditorStore(c=>c.card);const I=s.useManagementStore(c=>c.selectedDashboard),N=s.useManagementStore(c=>c.initialDashboard);s.useManagementStore(c=>c.selectedVisual),s.useDashboardStore(c=>c.selectedFrameId),s.useEditorStore(c=>c.frame);const A=I?(ae=I==null?void 0:I.permissions)==null?void 0:ae.canEdit:(te=N==null?void 0:N.permissions)==null?void 0:te.canEdit,_=s.useDashboardStore(c=>c.showFilters),Q=s.useDashboardStore(c=>c.showDashboardJSON),O=s.useDashboardStore(c=>c.onSaveFunction),x=s.useDashboardStore(c=>c.actions.setShowFilters),{setIsDashboardEditing:S,setShowDashboardJSON:k}=s.useDashboardStore(c=>c.actions),{setInitialDashboard:F,clearSelectedDashboard:q}=s.useManagementStore(c=>c.actions),{resources:E}=s.useResourceManagement(s.ResourceType.DASHBOARD),{currentUser:ge}=s.useCurrentUserInfo(),fe=s.canUserManageGroups(ge),G=I||N,ee=G?{id:G.id,title:(u==null?void 0:u.title)||G.title||"Dashboard"}:null,{handleAddNewFrame:je}=s.useAddNewFrame(),[H,V]=f.useState(!1),$=s.useUpdateResource(s.ResourceType.DASHBOARD),be=async(c,L)=>{if(!(u!=null&&u.id)){console.log("No dashboard ID found");return}console.log("Updating dashboard title:",{dashboardId:u.id,newTitle:c,previousTitle:L}),$.mutate({resourceId:u.id,data:{title:c}},{onSuccess:()=>{console.log("Dashboard title updated successfully"),s.ue.success("Dashboard title updated")},onError:B=>{console.error("Failed to update dashboard title:",B),s.ue.error("Failed to update dashboard title"),p(L)}})};f.useEffect(()=>{if(E&&E.length>0){const c=u==null?void 0:u.id;if(c){const L=E.find(B=>B.id===c);L&&F(L)}}},[E,u==null?void 0:u.id,F]);const z=n.orgUserId||n.tenantId,ve=l&&!v&&z&&A,ye=()=>{S(!0)};async function Ne(){const c=U.getDashbaordStateWithoutData(u);V(!0);const L={template:c};$.mutate({resourceId:c.id,data:L},{onSuccess:()=>{V(!1),s.ue.success("Dashboard saved!")},onError:()=>{V(!1),s.ue.error("Failed to save dashboard")}})}async function De(){if(b(!0),!h||!g)return;const c=U.getDashbaordStateWithoutData(u),L=JSON.stringify(c),B={...g,template:L,filterValues:R};await K(n.apiServiceUrl,B,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),O==null||O(c),b(!1)}const se=(g==null?void 0:g.name)||u.title;$.isPending&&console.log("Title during update:",{title:se,dashboardStateTitle:u.title,dashboardId:u==null?void 0:u.id,currentLensName:g==null?void 0:g.name});const we=n.orgUserId||n.tenantId&&n.endUserId&&n.endUserEmail,Se=o;return e.jsxs("div",{className:"flex h-11 items-center justify-between gap-2 border-b px-4 py-2",role:"dashboard-controls",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[we&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{"aria-label":"Manage Dashboards",tooltip:"Manage Dashboards",onClick:()=>{M(!P)},className:"h-7 p-2",children:e.jsx(ke,{className:"h-4 w-4"})}),Se&&!v&&e.jsx(s.IconButton,{"aria-label":"Dashboard Hub",tooltip:"Dashboard Hub",onClick:()=>q(),className:"h-7 p-2",children:e.jsx(s.House,{className:"h-4 w-4"})})]}),!v&&o&&(d?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.LoaderCircle,{className:"h-3 w-3 animate-spin text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Loading..."})]}):e.jsx(s.EditableText,{value:se||"Untitled Dashboard",onSave:c=>{console.log("EditableText onSave called:",{newTitle:c,canEditDashboard:A,dashboardId:u==null?void 0:u.id});const L=(u==null?void 0:u.title)||"";p(c),be(c,L)},isEditable:A&&!g,displayClassName:"text-sm font-medium",inputClassName:"text-sm font-medium",placeholder:"Dashboard Title",isPending:$.isPending}))]}),e.jsxs("div",{className:"flex items-center gap-2",children:[v&&e.jsxs(e.Fragment,{children:[e.jsx(U.AdvancedModeToggle,{className:"mr-2"}),e.jsx(U.VisualEditingControls,{className:"h-7"})]}),r&&!v&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{tooltip:"Copy Token",onClick:()=>{var c;t!=null&&t.accessToken&&((c=navigator==null?void 0:navigator.clipboard)!=null&&c.writeText?navigator.clipboard.writeText(t.accessToken).then(()=>s.ue.success("Token copied to clipboard")).catch(()=>s.ue.error("Unable to copy token")):s.ue.error("Clipboard not available"))},className:"h-7 p-2",children:e.jsx(s.Copy,{className:"h-4 w-4"})}),e.jsx(s.IconButton,{tooltip:"Invalidate Token",onClick:()=>s.invalidateToken(n.apiServiceUrl),className:"h-7 p-2",children:e.jsx(Ie,{className:"h-4 w-4"})})]}),!v&&o&&e.jsx(Ue,{}),!v&&o&&e.jsx(U.ScheduleDashboard,{}),!v&&o&&fe&&e.jsx(s.IconButton,{tooltip:"Manage Groups",onClick:()=>T(!0),className:"h-7 p-2",children:e.jsx(s.Users,{className:"h-4 w-4"})}),!v&&o&&((re=G==null?void 0:G.permissions)==null?void 0:re.canShare)&&e.jsx(s.IconButton,{tooltip:"Share Dashboard",onClick:()=>w(!0),className:"h-7 p-2",children:e.jsx(s.Share2,{className:"h-4 w-4"})}),!_&&!v&&l&&i.canUseFilters&&o&&e.jsx(s.Button,{className:"h-7 p-2",variant:"outline",onClick:()=>x(!0),size:"sm",children:e.jsx(s.Filter,{className:"h-4 w-4"})}),l&&!v&&z&&r&&o&&e.jsx(Re,{}),!v&&z&&r&&o&&e.jsx(Ge,{}),l&&!v&&z&&g&&r&&o&&e.jsxs(s.Button,{className:"h-7 p-2",variant:"secondary",disabled:j,onClick:De,size:"sm",children:[e.jsx(ne.Save,{className:"mr-2 h-4 w-4"}),"Save Lens"]}),l&&!v&&o&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",size:"sm",disabled:!l,onClick:()=>je(),children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Visual"]}),!v&&!l&&i.canEdit&&o&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",onClick:ye,size:"sm",children:[e.jsx(s.Pencil,{className:"mr-2 h-4 w-4"}),"Edit"]}),ve&&o&&e.jsxs(s.Button,{className:"h-7 p-2",disabled:H,onClick:Ne,size:"sm",children:[H?e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(ne.Save,{className:"mr-2 h-4 w-4"}),H?"Saving...":"Save"]}),!v&&l&&r&&o&&e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(s.Button,{className:"h-7 p-2",onClick:()=>k(!Q),size:"sm",variant:"ghost",children:e.jsx(s.Code,{className:"h-4 w-4"})})}),!v&&r&&e.jsx(Ae,{}),l&&!v&&o&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",onClick:()=>{S(!1),k(!1)},children:[e.jsx(s.Cross2Icon,{className:"mr-2 h-4 w-4"}),"Close"]}),y&&ee&&e.jsx(s.ShareDialog,{resource:ee,resourceType:s.ResourceType.DASHBOARD,onClose:()=>w(!1)}),e.jsx(is,{open:C,onOpenChange:T})]})]})}exports.default=ls;