react-semaphor 0.1.177 → 0.1.179

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 (30) hide show
  1. package/dist/chunks/{dashboard-controls-00cjSeD7.js → dashboard-controls-CeT5saB7.js} +8 -8
  2. package/dist/chunks/{dashboard-controls-C9IWIFfW.js → dashboard-controls-O2Vl2SaH.js} +204 -203
  3. package/dist/chunks/{dashboard-json--ke9XK9p.js → dashboard-json--jGkpREU.js} +1 -1
  4. package/dist/chunks/{dashboard-json-BDjl-3ej.js → dashboard-json-d1qZ8OYo.js} +1 -1
  5. package/dist/chunks/{edit-dashboard-visual-BBsC9feJ.js → edit-dashboard-visual-BsP87bZV.js} +2 -2
  6. package/dist/chunks/{edit-dashboard-visual-BroCdmtP.js → edit-dashboard-visual-ViDNkE8Q.js} +1 -1
  7. package/dist/chunks/{editor-action-buttons-JE9t84-4.js → editor-action-buttons-DseT424l.js} +1 -1
  8. package/dist/chunks/{editor-action-buttons-CHoiNw7F.js → editor-action-buttons-F4_UU-Mk.js} +2 -2
  9. package/dist/chunks/index-8Crk3ROJ.js +1 -0
  10. package/dist/chunks/index-B4EhQdS9.js +1857 -0
  11. package/dist/chunks/{index-CdfFCbJb.js → index-CFWw2cJ5.js} +228 -228
  12. package/dist/chunks/{index-DZjcALSv.js → index-v6ayK5K2.js} +19466 -21309
  13. package/dist/chunks/{resource-management-panel-DE8DnPSl.js → resource-management-panel-CApVr9Vd.js} +3 -3
  14. package/dist/chunks/{resource-management-panel-C96ElLa5.js → resource-management-panel-Cn1aOr6L.js} +1 -1
  15. package/dist/chunks/{schedule-dashboard-BFa0Uljc.js → schedule-dashboard-B4KUKLfW.js} +3 -3
  16. package/dist/chunks/{schedule-dashboard-CzU0ziLB.js → schedule-dashboard-vvFw8B1E.js} +1 -1
  17. package/dist/chunks/{use-role-aware-display-preferences-Rd1BhDG4.js → use-role-aware-display-preferences-Bxp6i8c7.js} +1 -1
  18. package/dist/chunks/{use-role-aware-display-preferences-Dovp_VmV.js → use-role-aware-display-preferences-C-N0-Iik.js} +1 -1
  19. package/dist/chunks/{use-visual-utils-Cnju2tnE.js → use-visual-utils-D19qzwzI.js} +1 -1
  20. package/dist/chunks/{use-visual-utils-BkRr5LoD.js → use-visual-utils-D9lMGeVv.js} +1 -1
  21. package/dist/dashboard/index.cjs +1 -1
  22. package/dist/dashboard/index.js +1 -1
  23. package/dist/format-utils/index.cjs +5 -0
  24. package/dist/format-utils/index.js +451 -0
  25. package/dist/index.cjs +1 -1
  26. package/dist/index.js +4 -4
  27. package/dist/surfboard/index.cjs +1 -1
  28. package/dist/surfboard/index.js +1 -1
  29. package/dist/types/format-utils.d.ts +375 -0
  30. package/package.json +14 -1
@@ -1,29 +1,29 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-CdfFCbJb.js"),b=require("react");require("react-dom");const B=require("./schedule-dashboard-CzU0ziLB.js"),Ke=require("./use-role-aware-display-preferences-Rd1BhDG4.js"),fe=require("./editor-action-buttons-JE9t84-4.js");function We(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 w=We(b);/**
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-CFWw2cJ5.js"),b=require("react");require("react-dom");const B=require("./schedule-dashboard-vvFw8B1E.js"),Ke=require("./use-role-aware-display-preferences-Bxp6i8c7.js"),We=require("./index-8Crk3ROJ.js"),fe=require("./editor-action-buttons-DseT424l.js");function Je(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 w=Je(b);/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
5
5
  * See the LICENSE file in the root directory of this source tree.
6
- */const Je=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"}]]);/**
6
+ */const Xe=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
7
  * @license lucide-react v0.453.0 - ISC
8
8
  *
9
9
  * This source code is licensed under the ISC license.
10
10
  * See the LICENSE file in the root directory of this source tree.
11
- */const Xe=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"}]]);/**
11
+ */const Ye=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
12
  * @license lucide-react v0.453.0 - ISC
13
13
  *
14
14
  * This source code is licensed under the ISC license.
15
15
  * See the LICENSE file in the root directory of this source tree.
16
- */const Ye=s.createLucideIcon("Moon",[["path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z",key:"a7tn18"}]]);/**
16
+ */const Ze=s.createLucideIcon("Moon",[["path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z",key:"a7tn18"}]]);/**
17
17
  * @license lucide-react v0.453.0 - ISC
18
18
  *
19
19
  * This source code is licensed under the ISC license.
20
20
  * See the LICENSE file in the root directory of this source tree.
21
- */const Ze=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"}]]);/**
21
+ */const es=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
22
  * @license lucide-react v0.453.0 - ISC
23
23
  *
24
24
  * This source code is licensed under the ISC license.
25
25
  * See the LICENSE file in the root directory of this source tree.
26
- */const es=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 ae={exports:{}},se={};/**
26
+ */const ss=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 ae={exports:{}},se={};/**
27
27
  * @license React
28
28
  * use-sync-external-store-shim.production.js
29
29
  *
@@ -31,7 +31,7 @@
31
31
  *
32
32
  * This source code is licensed under the MIT license found in the
33
33
  * LICENSE file in the root directory of this source tree.
34
- */var ve;function ss(){if(ve)return se;ve=1;var t=b;function n(c,h){return c===h&&(c!==0||1/c===1/h)||c!==c&&h!==h}var a=typeof Object.is=="function"?Object.is:n,r=t.useState,o=t.useEffect,i=t.useLayoutEffect,u=t.useDebugValue;function m(c,h){var p=h(),f=r({inst:{value:p,getSnapshot:h}}),j=f[0].inst,S=f[1];return i(function(){j.value=p,j.getSnapshot=h,x(j)&&S({inst:j})},[c,p,h]),o(function(){return x(j)&&S({inst:j}),c(function(){x(j)&&S({inst:j})})},[c]),u(p),p}function x(c){var h=c.getSnapshot;c=c.value;try{var p=h();return!a(c,p)}catch{return!0}}function v(c,h){return h()}var d=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?v:m;return se.useSyncExternalStore=t.useSyncExternalStore!==void 0?t.useSyncExternalStore:d,se}var te={};/**
34
+ */var ve;function ts(){if(ve)return se;ve=1;var t=b;function n(c,h){return c===h&&(c!==0||1/c===1/h)||c!==c&&h!==h}var a=typeof Object.is=="function"?Object.is:n,r=t.useState,o=t.useEffect,i=t.useLayoutEffect,u=t.useDebugValue;function m(c,h){var p=h(),f=r({inst:{value:p,getSnapshot:h}}),j=f[0].inst,S=f[1];return i(function(){j.value=p,j.getSnapshot=h,x(j)&&S({inst:j})},[c,p,h]),o(function(){return x(j)&&S({inst:j}),c(function(){x(j)&&S({inst:j})})},[c]),u(p),p}function x(c){var h=c.getSnapshot;c=c.value;try{var p=h();return!a(c,p)}catch{return!0}}function v(c,h){return h()}var d=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?v:m;return se.useSyncExternalStore=t.useSyncExternalStore!==void 0?t.useSyncExternalStore:d,se}var te={};/**
35
35
  * @license React
36
36
  * use-sync-external-store-shim.development.js
37
37
  *
@@ -39,4 +39,4 @@
39
39
  *
40
40
  * This source code is licensed under the MIT license found in the
41
41
  * LICENSE file in the root directory of this source tree.
42
- */var je;function ts(){return je||(je=1,process.env.NODE_ENV!=="production"&&function(){function t(p,f){return p===f&&(p!==0||1/p===1/f)||p!==p&&f!==f}function n(p,f){d||o.startTransition===void 0||(d=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var j=f();if(!c){var S=f();i(j,S)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),c=!0)}S=u({inst:{value:j,getSnapshot:f}});var C=S[0].inst,E=S[1];return x(function(){C.value=j,C.getSnapshot=f,a(C)&&E({inst:C})},[p,j,f]),m(function(){return a(C)&&E({inst:C}),p(function(){a(C)&&E({inst:C})})},[p]),v(j),j}function a(p){var f=p.getSnapshot;p=p.value;try{var j=f();return!i(p,j)}catch{return!0}}function r(p,f){return f()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var o=b,i=typeof Object.is=="function"?Object.is:t,u=o.useState,m=o.useEffect,x=o.useLayoutEffect,v=o.useDebugValue,d=!1,c=!1,h=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?r:n;te.useSyncExternalStore=o.useSyncExternalStore!==void 0?o.useSyncExternalStore:h,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()),te}process.env.NODE_ENV==="production"?ae.exports=ss():ae.exports=ts();var as=ae.exports;function rs(){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(es,{strokeWidth:1.5,className:"h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0"}),e.jsx(Ye,{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 ns(t,n,a,r,o){if(!o)return null;const i=JSON.stringify(a),u=`${t}/v1/lens`;return await s.postRequest(u,o,{name:n,template:i,filterValues:r,operation:"create"})}async function re(t,n,a){if(!a)return null;const{id:r,template:o,filterValues:i,isDefault:u,shared:m}=n,x=`${t}/v1/lens`;return await s.postRequest(x,a,{lensId:r,template:o,filterValues:i,isDefault:u,shared:m,operation:"update"})}async function os(t,n,a){if(!a)return null;const r=`${t}/v1/lens`;return await s.postRequest(r,a,{operation:"delete",lensId:n})}function is(){const[t,n]=b.useState(""),[a,r]=b.useState(!1),o=s.useDashboardStore(S=>S.lenses),{setLenses:i,setSelectedLensId:u}=s.useDashboardActions(),[m,x]=b.useState(!1),[v,d]=b.useState(!1),c=s.useDashboardStore(S=>S.dashboard),h=s.useDashboardStore(S=>S.filterValues),{authToken:p,tokenProps:f}=s.useSemaphorContext();async function j(){x(!0);const S=await ns(f.apiServiceUrl,t,c,h,p==null?void 0:p.accessToken);S&&(i([...o||[],S]),u(S.id),d(!1)),x(!1)}return e.jsxs(s.Dialog,{open:v,onOpenChange:d,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:S=>{n(S.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:j,disabled:m,children:m?"Creating...":"Add"})})]})]})}function ls(){const[t,n]=b.useState(!1),a=s.useDashboardStore(c=>c.lenses),r=s.useDashboardStore(c=>c.selectedLensId),{setLenses:o,setSelectedLensId:i}=s.useDashboardActions(),{authToken:u,tokenProps:m}=s.useSemaphorContext();async function x(c){i(c)}async function v(c){if(await os(m.apiServiceUrl,c,u==null?void 0:u.accessToken)){const p=a==null?void 0:a.filter(f=>f.id!==c);o(p||[]),i("original")}}async function d(c){const h=a==null?void 0:a.map(j=>j.id===c.id?{...j,isDefault:!c.isDefault}:{...j,isDefault:!1});o(h||[]);const p={...c,isDefault:!c.isDefault};await re(m.apiServiceUrl,p,u==null?void 0:u.accessToken);const f=a==null?void 0:a.find(j=>j.isDefault);if(f&&f.id!==c.id){const j={...f,isDefault:!1};await re(m.apiServiceUrl,j,u==null?void 0:u.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(Je,{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:x,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),a==null?void 0:a.map(c=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:c.id,children:[e.jsx("p",{children:c.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(s.House,{onClick:h=>{h.preventDefault(),d(c)},className:s.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!c.isDefault,"text-green-500":c.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:h=>{h.preventDefault(),v(c.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},c.id))]})]})]})}const cs=async(t,n,a)=>{const r=`${t}/management/v1/groups`;return await s.postRequestRegular(r,n,a)},ds=async(t,n,a)=>{const r=`${t}/management/v1/groups/${a}`,o=await fetch(r,{method:"DELETE",headers:{Authorization:`Bearer ${n}`}});if(!o.ok){const i=await o.text();throw new Error(i||"Failed to delete group")}},us=async(t,n,a,r)=>{const o=`${t}/management/v1/groups/${a}/members`;return await s.postRequestRegular(o,n,r)},ms=async(t,n,a,r)=>{const o=`${t}/management/v1/groups/${a}/members`,i=await fetch(o,{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify(r)});if(!i.ok){const u=await i.text();throw new Error(u||"Failed to remove group members")}};function hs(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:r=>cs(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 ps(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:r=>ds(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r),onSuccess:(r,o)=>{a.invalidateQueries({queryKey:["groups"]}),a.removeQueries({queryKey:["group",o]}),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 xs(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:o})=>us(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r,o),onSuccess:(r,o)=>{a.invalidateQueries({queryKey:["group",o.groupId]}),a.invalidateQueries({queryKey:["group-members",o.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 gs(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:o})=>ms(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r,o),onSuccess:(r,o)=>{a.invalidateQueries({queryKey:["group",o.groupId]}),a.invalidateQueries({queryKey:["group-members",o.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 fs({onSuccess:t,tenantId:n,isTenantUser:a}){const[r,o]=b.useState(""),[i,u]=b.useState(""),[m,x]=b.useState({}),v=hs(),d=()=>{const h={};return r.trim()?r.length<3?h.name="Group name must be at least 3 characters":r.length>50&&(h.name="Group name must be less than 50 characters"):h.name="Group name is required",i&&i.length>200&&(h.description="Description must be less than 200 characters"),x(h),Object.keys(h).length===0},c=async h=>{if(h.preventDefault(),!d())return;const p={name:r.trim(),description:i.trim()||void 0,type:a?"TENANT_GROUP":"ORG_GROUP",...a&&n?{tenantId:n}:{}};try{await v.mutateAsync(p),o(""),u(""),x({}),t()}catch(f){console.error("Failed to create group:",f)}};return e.jsxs("form",{onSubmit:c,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:h=>{o(h.target.value),m.name&&x(p=>({...p,name:""}))},className:m.name?"border-destructive":"",disabled:v.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:i,onChange:h=>{u(h.target.value),m.description&&x(p=>({...p,description:""}))},className:m.description?"border-destructive":"",disabled:v.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:[i.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:()=>{o(""),u(""),x({})},disabled:v.isPending,children:"Clear"}),e.jsx(s.Button,{type:"submit",disabled:v.isPending||!r.trim(),children:v.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 vs(t,n=[]){let a=[];function r(i,u){const m=w.createContext(u);m.displayName=i+"Context";const x=a.length;a=[...a,u];const v=c=>{var C;const{scope:h,children:p,...f}=c,j=((C=h==null?void 0:h[t])==null?void 0:C[x])||m,S=w.useMemo(()=>f,Object.values(f));return e.jsx(j.Provider,{value:S,children:p})};v.displayName=i+"Provider";function d(c,h){var j;const p=((j=h==null?void 0:h[t])==null?void 0:j[x])||m,f=w.useContext(p);if(f)return f;if(u!==void 0)return u;throw new Error(`\`${c}\` must be used within \`${i}\``)}return[v,d]}const o=()=>{const i=a.map(u=>w.createContext(u));return function(m){const x=(m==null?void 0:m[t])||i;return w.useMemo(()=>({[`__scope${t}`]:{...m,[t]:x}}),[m,x])}};return o.scopeName=t,[r,js(o,...n)]}function js(...t){const n=t[0];if(t.length===1)return n;const a=()=>{const r=t.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(i){const u=r.reduce((m,{useScope:x,scopeName:v})=>{const c=x(i)[`__scope${v}`];return{...m,...c}},{});return w.useMemo(()=>({[`__scope${n.scopeName}`]:u}),[u])}};return a.scopeName=n.scopeName,a}var bs=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],ne=bs.reduce((t,n)=>{const a=s.createSlot(`Primitive.${n}`),r=w.forwardRef((o,i)=>{const{asChild:u,...m}=o,x=u?a:n;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(x,{...m,ref:i})});return r.displayName=`Primitive.${n}`,{...t,[n]:r}},{});function Ss(){return as.useSyncExternalStore(ys,()=>!0,()=>!1)}function ys(){return()=>{}}var oe="Avatar",[Ns]=vs(oe),[Ds,Se]=Ns(oe),ye=w.forwardRef((t,n)=>{const{__scopeAvatar:a,...r}=t,[o,i]=w.useState("idle");return e.jsx(Ds,{scope:a,imageLoadingStatus:o,onImageLoadingStatusChange:i,children:e.jsx(ne.span,{...r,ref:n})})});ye.displayName=oe;var Ne="AvatarImage",De=w.forwardRef((t,n)=>{const{__scopeAvatar:a,src:r,onLoadingStatusChange:o=()=>{},...i}=t,u=Se(Ne,a),m=ws(r,i),x=s.useCallbackRef(v=>{o(v),u.onImageLoadingStatusChange(v)});return s.useLayoutEffect2(()=>{m!=="idle"&&x(m)},[m,x]),m==="loaded"?e.jsx(ne.img,{...i,ref:n,src:r}):null});De.displayName=Ne;var we="AvatarFallback",Ce=w.forwardRef((t,n)=>{const{__scopeAvatar:a,delayMs:r,...o}=t,i=Se(we,a),[u,m]=w.useState(r===void 0);return w.useEffect(()=>{if(r!==void 0){const x=window.setTimeout(()=>m(!0),r);return()=>window.clearTimeout(x)}},[r]),u&&i.imageLoadingStatus!=="loaded"?e.jsx(ne.span,{...o,ref:n}):null});Ce.displayName=we;function be(t,n){return t?n?(t.src!==n&&(t.src=n),t.complete&&t.naturalWidth>0?"loaded":"loading"):"error":"idle"}function ws(t,{referrerPolicy:n,crossOrigin:a}){const r=Ss(),o=w.useRef(null),i=r?(o.current||(o.current=new window.Image),o.current):null,[u,m]=w.useState(()=>be(i,t));return s.useLayoutEffect2(()=>{m(be(i,t))},[i,t]),s.useLayoutEffect2(()=>{const x=c=>()=>{m(c)};if(!i)return;const v=x("loaded"),d=x("error");return i.addEventListener("load",v),i.addEventListener("error",d),n&&(i.referrerPolicy=n),typeof a=="string"&&(i.crossOrigin=a),()=>{i.removeEventListener("load",v),i.removeEventListener("error",d)}},[i,a,n]),u}var Le=ye,Ae=De,Me=Ce;const ie=w.forwardRef(({className:t,...n},a)=>e.jsx(Le,{ref:a,className:s.cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",t),...n}));ie.displayName=Le.displayName;const Cs=w.forwardRef(({className:t,...n},a)=>e.jsx(Ae,{ref:a,className:s.cn("aspect-square h-full w-full",t),...n}));Cs.displayName=Ae.displayName;const le=w.forwardRef(({className:t,...n},a)=>e.jsx(Me,{ref:a,className:s.cn("flex h-full w-full items-center justify-center rounded-full bg-muted",t),...n}));le.displayName=Me.displayName;function Ls({open:t,onOpenChange:n,group:a,onUpdate:r}){const[o,i]=b.useState("members"),[u,m]=b.useState(""),[x,v]=b.useState([]),[d,c]=b.useState([]),{data:h,isLoading:p,refetch:f}=s.useGroupMembers(a.id),j=a.type==="TENANT_GROUP"?"tenant":"organization",{users:S,isLoading:C}=s.useUnifiedUsers({type:j,tenantId:a.tenantId||void 0,active:!0,limit:100}),E=xs(),k=gs(),L=(h==null?void 0:h.members)||[],T=b.useMemo(()=>new Set(L.map(g=>g.userId)),[L]),I=b.useMemo(()=>S.filter(g=>!T.has(g.id)),[S,T]),_=b.useMemo(()=>{if(!u)return I;const g=u.toLowerCase();return I.filter(D=>{var A,O;return((A=D.name)==null?void 0:A.toLowerCase().includes(g))||((O=D.email)==null?void 0:O.toLowerCase().includes(g))})},[I,u]),y=b.useMemo(()=>{if(!u)return L;const g=u.toLowerCase();return L.filter(D=>{var A,O,q,$;return((O=(A=D.user)==null?void 0:A.name)==null?void 0:O.toLowerCase().includes(g))||(($=(q=D.user)==null?void 0:q.email)==null?void 0:$.toLowerCase().includes(g))})},[L,u]),R=async()=>{if(x.length!==0)try{await E.mutateAsync({groupId:a.id,data:{userIds:x,userType:j==="tenant"?"tenant":"org"}}),v([]),i("members"),f(),r==null||r()}catch(g){console.error("Failed to add members:",g)}},K=async()=>{if(d.length!==0)try{await k.mutateAsync({groupId:a.id,data:{userIds:d}}),c([]),f(),r==null||r()}catch(g){console.error("Failed to remove members:",g)}},W=g=>{v(D=>D.includes(g)?D.filter(A=>A!==g):[...D,g])},N=g=>{c(D=>D.includes(g)?D.filter(A=>A!==g):[...D,g])};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:[L.length," ",L.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:o,onValueChange:g=>{i(g),m(""),c([])},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:u,onChange:g=>m(g.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:d.length>0?"h-[300px]":"h-[350px]",children:p?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(g=>e.jsx(s.Skeleton,{className:"h-16 w-full"},g))}):y.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:u?"No members found":"No members yet"}),e.jsx("p",{className:"text-xs mt-1",children:u?"Try a different search":'Switch to the "Add Members" tab to add people to this group'})]}):e.jsx("div",{className:"space-y-2",children:y.map(g=>e.jsx(As,{member:g,selected:d.includes(g.userId),onToggle:()=>N(g.userId)},g.id))})}),d.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:[d.length," member",d.length!==1?"s":""," selected"]}),e.jsx(s.Button,{variant:"destructive",size:"sm",onClick:K,disabled:k.isPending,children:k.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:u,onChange:g=>m(g.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(g=>e.jsx(s.Skeleton,{className:"h-16 w-full"},g))}):_.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:u?"Try a different search":"All eligible users are already members"})]}):e.jsx("div",{className:"space-y-2",children:_.map(g=>e.jsx(Ms,{user:g,selected:x.includes(g.id),onToggle:()=>W(g.id)},g.id))})}),x.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:[x.length," user",x.length!==1?"s":""," selected"]}),e.jsx(s.Button,{onClick:R,disabled:E.isPending,children:E.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 As({member:t,selected:n,onToggle:a}){var o,i,u,m;const r=((i=(o=t.user)==null?void 0:o.name)==null?void 0:i.split(" ").map(x=>x[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(ie,{className:"h-8 w-8",children:e.jsx(le,{className:"text-xs",children:r})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:((u=t.user)==null?void 0:u.name)||"Unknown User"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(m=t.user)==null?void 0:m.email})]})]})}function Ms({user:t,selected:n,onToggle:a}){var o;const r=((o=t.name)==null?void 0:o.split(" ").map(i=>i[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(ie,{className:"h-8 w-8",children:e.jsx(le,{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 Es({open:t,onOpenChange:n}){const[a,r]=b.useState("groups"),[o,i]=b.useState(""),[u,m]=b.useState(null),[x,v]=b.useState(!1),[d,c]=b.useState(null),{tokenProps:h}=s.useSemaphorContext(),{currentUser:p}=s.useCurrentUserInfo(),f=ps(),j=(p==null?void 0:p.type)==="tenant",S=h==null?void 0:h.tenantId,{groups:C,isLoading:E,refetch:k}=s.useGroups({type:j?"TENANT_GROUP":"all",tenantId:j?S:void 0,includeMembers:!1}),L=C.filter(y=>{var R;return y.name.toLowerCase().includes(o.toLowerCase())||((R=y.description)==null?void 0:R.toLowerCase().includes(o.toLowerCase()))}),T=async()=>{if(d)try{await f.mutateAsync(d.id),c(null),k()}catch(y){console.error("Failed to delete group:",y)}},I=y=>{m(y),v(!0)},_=()=>{r("groups"),k()};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:o,onChange:y=>i(y.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:"h-[400px]",children:E?e.jsx("div",{className:"space-y-3",children:[1,2,3].map(y=>e.jsx(s.Skeleton,{className:"h-24 w-full"},y))}):L.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:o?"Try a different search":"Create your first group to get started"})]}):e.jsx("div",{className:"space-y-3",children:L.map(y=>e.jsx(Is,{group:y,onManageMembers:()=>I(y),onDelete:()=>c(y),currentUserId:p==null?void 0:p.id},y.id))})})]})}),e.jsx(s.TabsContent,{value:"create",className:"mt-4",children:e.jsx(fs,{onSuccess:_,tenantId:S,isTenantUser:j})})]})]})}),u&&e.jsx(Ls,{open:x,onOpenChange:v,group:u,onUpdate:()=>k()}),e.jsx(s.AlertDialog,{open:!!d,onOpenChange:()=>c(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 "',d==null?void 0:d.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:T,disabled:f.isPending,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:f.isPending?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Deleting..."]}):"Delete Group"})]})]})})]})}function Is({group:t,onManageMembers:n,onDelete:a,currentUserId:r}){const o=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"})}),o&&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 ks(){var pe,xe,ge;const{authToken:t,tokenProps:n,id:a}=s.useSemaphorContext(),{isLocalDev:r}=s.useDashboardPreferences(),{permissions:o}=Ke.useRoleAwareDisplayPreferences(),i=s.useHasDashboardId(),{isLoading:u}=s.useDashboardQuery();s.useDashboardStore(l=>l.theme);const m=s.useDashboardStore(l=>l.lenses),x=s.useDashboardStore(l=>l.selectedLensId),v=m==null?void 0:m.find(l=>l.id===x),d=s.useDashboardStore(l=>l.dashboard);s.useDashboardStore(l=>l.selectedSheetId);const c=s.useDashboardStore(l=>l.isDashboardEditing),{setDashboardTitle:h}=s.useDashboardStore(l=>l.actions),[p,f]=b.useState(!1),[j,S]=b.useState(!1),[C,E]=b.useState(!1),[k,L]=b.useState(!1),[T,I]=b.useState(null),[_,y]=b.useState(!1),R=s.useDashboardStore(l=>l.isDashboardPanelOpen),K=s.useDashboardStore(l=>l.actions.setIsDashboardPanelOpen),W=s.useDashboardStore(l=>l.filterValues),N=s.useDashboardStore(l=>l.isVisualEditing);s.useEditorStore(l=>l.card);const g=s.useManagementStore(l=>l.selectedDashboard),D=s.useManagementStore(l=>l.initialDashboard);s.useManagementStore(l=>l.selectedVisual),s.useDashboardStore(l=>l.selectedFrameId),s.useEditorStore(l=>l.frame);const A=g?(xe=g==null?void 0:g.permissions)==null?void 0:xe.canEdit:(pe=D==null?void 0:D.permissions)==null?void 0:pe.canEdit,O=s.useDashboardStore(l=>l.showFilters),q=s.useAssistantLayoutStore(l=>l.setPanelOpen),$=s.useDashboardStore(l=>l.showDashboardJSON),J=s.useDashboardStore(l=>l.onSaveFunction),Ee=s.useDashboardStore(l=>l.actions.setShowFilters),{setIsDashboardEditing:ce,setShowDashboardJSON:de}=s.useDashboardStore(l=>l.actions),{setInitialDashboard:ue,clearSelectedDashboard:Ie}=s.useManagementStore(l=>l.actions),{resources:V}=s.useResourceManagement(s.ResourceType.DASHBOARD),{currentUser:ke}=s.useCurrentUserInfo(),Te=s.canUserManageGroups(ke),P=g||D,me=P?{id:P.id,title:(d==null?void 0:d.title)||P.title||"Dashboard"}:null,{handleAddNewFrame:Oe}=s.useAddNewFrame(),[F,X]=b.useState(!1),[_e,z]=b.useState(!1),H=s.useUpdateResource(s.ResourceType.DASHBOARD),[G,Y]=b.useState(null),Re=async(l,M)=>{if(!(d!=null&&d.id)){console.log("No dashboard ID found");return}console.log("Updating dashboard title:",{dashboardId:d.id,newTitle:l,previousTitle:M}),H.mutate({resourceId:d.id,data:{title:l}},{onSuccess:()=>{console.log("Dashboard title updated successfully"),s.ue.success("Dashboard title updated")},onError:U=>{console.error("Failed to update dashboard title:",U),s.ue.error("Failed to update dashboard title"),h(M)}})};b.useEffect(()=>{if(V&&V.length>0){const l=d==null?void 0:d.id;if(l){const M=V.find(U=>U.id===l);M&&ue(M)}}},[V,d==null?void 0:d.id,ue]);const Q=n.orgUserId||n.tenantId,Pe=c&&!N&&Q&&A,{setDashboard:Fe}=s.useDashboardStore(l=>l.actions),Ge=()=>{ce(!0)},Z=()=>{ce(!1),de(!1),Y(null)};B.usePristineSnapshotInitializer(c,d,G,l=>Y(l));const Ue=()=>G?JSON.stringify(d)!==JSON.stringify(G):!1,Be=()=>{Ue()?z(!0):Z()},qe=async()=>{await ee({closeAfterSave:!0})},$e=()=>{G&&Fe(G),Z(),z(!1)};async function ee(l){const M=(l==null?void 0:l.closeAfterSave)??_;y(M),M&&z(!1);const U=s.cloneDeep(d);L(!0),I(null),X(!0);const Qe={template:d};H.mutate({resourceId:d.id,data:Qe},{onSuccess:()=>{X(!1),s.ue.success("Dashboard saved!"),Y(U),L(!1),y(!1),M&&Z()},onError:()=>{X(!1),I("Failed to save dashboard. Please try again."),s.ue.error("Failed to save dashboard")}})}async function Ve(){if(f(!0),!x||!v)return;const l=JSON.stringify(d),M={...v,template:l,filterValues:W};await re(n.apiServiceUrl,M,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),J==null||J(d),f(!1)}const he=(v==null?void 0:v.name)||d.title;H.isPending&&console.log("Title during update:",{title:he,dashboardStateTitle:d.title,dashboardId:d==null?void 0:d.id,currentLensName:v==null?void 0:v.name});const ze=n.orgUserId||n.tenantId&&n.endUserId&&n.endUserEmail,He=i;return e.jsxs("div",{className:"flex h-11 shrink-0 items-center justify-between gap-2 overflow-x-auto border-b px-4 py-2",role:"dashboard-controls",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[ze&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{"aria-label":"Manage Dashboards",tooltip:"Manage Dashboards",onClick:()=>{K(!R)},className:"h-7 p-2",children:e.jsx(Xe,{className:"h-4 w-4"})}),He&&!N&&e.jsx(s.IconButton,{"aria-label":"Dashboard Hub",tooltip:"Dashboard Hub",onClick:()=>Ie(),className:"h-7 p-2",children:e.jsx(s.House,{className:"h-4 w-4"})})]}),!N&&i&&(u?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:he||"Untitled Dashboard",onSave:l=>{console.log("EditableText onSave called:",{newTitle:l,canEditDashboard:A,dashboardId:d==null?void 0:d.id});const M=(d==null?void 0:d.title)||"";h(l),Re(l,M)},isEditable:A&&!v,displayClassName:"text-sm font-medium",inputClassName:"text-sm font-medium",placeholder:"Dashboard Title",isPending:H.isPending}))]}),e.jsxs("div",{className:"flex items-center gap-2",children:[N&&e.jsxs(e.Fragment,{children:[e.jsx(B.AdvancedModeToggle,{className:"mr-2"}),e.jsx(B.VisualEditingControls,{className:"h-7"})]}),r&&!N&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{tooltip:"Copy Token",onClick:()=>{var l;t!=null&&t.accessToken&&((l=navigator==null?void 0:navigator.clipboard)!=null&&l.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(Ze,{className:"h-4 w-4"})})]}),!N&&i&&e.jsx(s.DownloadPdf,{}),!N&&i&&e.jsx(B.ScheduleDashboard,{}),!N&&i&&Te&&e.jsx(s.IconButton,{tooltip:"Manage Groups",onClick:()=>E(!0),className:"h-7 p-2",children:e.jsx(s.Users,{className:"h-4 w-4"})}),!N&&i&&((ge=P==null?void 0:P.permissions)==null?void 0:ge.canShare)&&e.jsx(s.IconButton,{tooltip:"Share Dashboard",onClick:()=>S(!0),className:"h-7 p-2",children:e.jsx(s.Share2,{className:"h-4 w-4"})}),!O&&!N&&c&&o.canUseFilters&&i&&e.jsx(s.Button,{className:"h-7 p-2",variant:"outline",onClick:()=>{q("dashboard",!1),Ee(!0)},size:"sm",children:e.jsx(s.Filter,{className:"h-4 w-4"})}),c&&!N&&Q&&r&&i&&e.jsx(is,{}),!N&&Q&&r&&i&&e.jsx(ls,{}),c&&!N&&Q&&v&&r&&i&&e.jsxs(s.Button,{className:"h-7 p-2",variant:"secondary",disabled:p,onClick:Ve,size:"sm",children:[e.jsx(fe.Save,{className:"mr-2 h-4 w-4"}),"Save Lens"]}),c&&!N&&i&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",size:"sm",disabled:!c,onClick:()=>Oe(),children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Visual"]}),!N&&!c&&A&&i&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",onClick:Ge,size:"sm",children:[e.jsx(s.Pencil,{className:"mr-2 h-4 w-4"}),"Edit"]}),Pe&&i&&e.jsxs(s.Button,{className:"h-7 p-2",disabled:F,onClick:()=>ee(),size:"sm",children:[F?e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(fe.Save,{className:"mr-2 h-4 w-4"}),F?"Saving...":"Save"]}),!N&&c&&r&&i&&e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(s.Button,{className:"h-7 p-2",onClick:()=>de(!$),size:"sm",variant:"ghost",children:e.jsx(s.Code,{className:"h-4 w-4"})})}),!N&&r&&e.jsx(rs,{}),c&&!N&&i&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",onClick:Be,children:[e.jsx(s.Cross2Icon,{className:"mr-2 h-4 w-4"}),"Close"]}),j&&me&&e.jsx(s.ShareDialog,{resource:me,resourceType:s.ResourceType.DASHBOARD,onClose:()=>S(!1)}),e.jsx(Es,{open:C,onOpenChange:E}),e.jsx(s.AlertDialog,{open:k,onOpenChange:l=>{!l&&F&&!T||(L(l),l||(I(null),y(!1)))},children:e.jsxs(s.AlertDialogContent,{className:"max-w-sm",children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:T?"Save failed":"Saving dashboard"}),e.jsx(s.AlertDialogDescription,{className:"pt-2",children:T?"We could not save the dashboard. Please try again.":"Please wait while we save your changes."})]}),e.jsx(s.AlertDialogFooter,{className:"flex-col gap-2 sm:flex-row sm:justify-end",children:T?e.jsxs(e.Fragment,{children:[e.jsx(s.AlertDialogCancel,{onClick:()=>{L(!1),I(null),y(!1)},className:"m-0",children:"Close"}),e.jsx(s.AlertDialogAction,{onClick:()=>ee(),className:"m-0",children:"Retry"})]}):e.jsxs(s.AlertDialogAction,{disabled:!0,className:"m-0 cursor-default",children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]})})]})}),e.jsx(B.UnsavedChangesAlert,{open:_e,onOpenChange:z,onSave:qe,onDiscard:$e,isSaving:F})]})]})}exports.default=ks;
42
+ */var je;function as(){return je||(je=1,process.env.NODE_ENV!=="production"&&function(){function t(p,f){return p===f&&(p!==0||1/p===1/f)||p!==p&&f!==f}function n(p,f){d||o.startTransition===void 0||(d=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var j=f();if(!c){var S=f();i(j,S)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),c=!0)}S=u({inst:{value:j,getSnapshot:f}});var C=S[0].inst,E=S[1];return x(function(){C.value=j,C.getSnapshot=f,a(C)&&E({inst:C})},[p,j,f]),m(function(){return a(C)&&E({inst:C}),p(function(){a(C)&&E({inst:C})})},[p]),v(j),j}function a(p){var f=p.getSnapshot;p=p.value;try{var j=f();return!i(p,j)}catch{return!0}}function r(p,f){return f()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var o=b,i=typeof Object.is=="function"?Object.is:t,u=o.useState,m=o.useEffect,x=o.useLayoutEffect,v=o.useDebugValue,d=!1,c=!1,h=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?r:n;te.useSyncExternalStore=o.useSyncExternalStore!==void 0?o.useSyncExternalStore:h,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()),te}process.env.NODE_ENV==="production"?ae.exports=ts():ae.exports=as();var rs=ae.exports;function ns(){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(ss,{strokeWidth:1.5,className:"h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0"}),e.jsx(Ze,{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 os(t,n,a,r,o){if(!o)return null;const i=JSON.stringify(a),u=`${t}/v1/lens`;return await s.postRequest(u,o,{name:n,template:i,filterValues:r,operation:"create"})}async function re(t,n,a){if(!a)return null;const{id:r,template:o,filterValues:i,isDefault:u,shared:m}=n,x=`${t}/v1/lens`;return await s.postRequest(x,a,{lensId:r,template:o,filterValues:i,isDefault:u,shared:m,operation:"update"})}async function is(t,n,a){if(!a)return null;const r=`${t}/v1/lens`;return await s.postRequest(r,a,{operation:"delete",lensId:n})}function ls(){const[t,n]=b.useState(""),[a,r]=b.useState(!1),o=s.useDashboardStore(S=>S.lenses),{setLenses:i,setSelectedLensId:u}=s.useDashboardActions(),[m,x]=b.useState(!1),[v,d]=b.useState(!1),c=s.useDashboardStore(S=>S.dashboard),h=s.useDashboardStore(S=>S.filterValues),{authToken:p,tokenProps:f}=s.useSemaphorContext();async function j(){x(!0);const S=await os(f.apiServiceUrl,t,c,h,p==null?void 0:p.accessToken);S&&(i([...o||[],S]),u(S.id),d(!1)),x(!1)}return e.jsxs(s.Dialog,{open:v,onOpenChange:d,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:S=>{n(S.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:j,disabled:m,children:m?"Creating...":"Add"})})]})]})}function cs(){const[t,n]=b.useState(!1),a=s.useDashboardStore(c=>c.lenses),r=s.useDashboardStore(c=>c.selectedLensId),{setLenses:o,setSelectedLensId:i}=s.useDashboardActions(),{authToken:u,tokenProps:m}=s.useSemaphorContext();async function x(c){i(c)}async function v(c){if(await is(m.apiServiceUrl,c,u==null?void 0:u.accessToken)){const p=a==null?void 0:a.filter(f=>f.id!==c);o(p||[]),i("original")}}async function d(c){const h=a==null?void 0:a.map(j=>j.id===c.id?{...j,isDefault:!c.isDefault}:{...j,isDefault:!1});o(h||[]);const p={...c,isDefault:!c.isDefault};await re(m.apiServiceUrl,p,u==null?void 0:u.accessToken);const f=a==null?void 0:a.find(j=>j.isDefault);if(f&&f.id!==c.id){const j={...f,isDefault:!1};await re(m.apiServiceUrl,j,u==null?void 0:u.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(Xe,{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:x,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),a==null?void 0:a.map(c=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:c.id,children:[e.jsx("p",{children:c.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(s.House,{onClick:h=>{h.preventDefault(),d(c)},className:s.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!c.isDefault,"text-green-500":c.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:h=>{h.preventDefault(),v(c.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},c.id))]})]})]})}const ds=async(t,n,a)=>{const r=`${t}/management/v1/groups`;return await s.postRequestRegular(r,n,a)},us=async(t,n,a)=>{const r=`${t}/management/v1/groups/${a}`,o=await fetch(r,{method:"DELETE",headers:{Authorization:`Bearer ${n}`}});if(!o.ok){const i=await o.text();throw new Error(i||"Failed to delete group")}},ms=async(t,n,a,r)=>{const o=`${t}/management/v1/groups/${a}/members`;return await s.postRequestRegular(o,n,r)},hs=async(t,n,a,r)=>{const o=`${t}/management/v1/groups/${a}/members`,i=await fetch(o,{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify(r)});if(!i.ok){const u=await i.text();throw new Error(u||"Failed to remove group members")}};function ps(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:r=>ds(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 xs(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:r=>us(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r),onSuccess:(r,o)=>{a.invalidateQueries({queryKey:["groups"]}),a.removeQueries({queryKey:["group",o]}),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 gs(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:o})=>ms(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r,o),onSuccess:(r,o)=>{a.invalidateQueries({queryKey:["group",o.groupId]}),a.invalidateQueries({queryKey:["group-members",o.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 fs(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:o})=>hs(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r,o),onSuccess:(r,o)=>{a.invalidateQueries({queryKey:["group",o.groupId]}),a.invalidateQueries({queryKey:["group-members",o.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 vs({onSuccess:t,tenantId:n,isTenantUser:a}){const[r,o]=b.useState(""),[i,u]=b.useState(""),[m,x]=b.useState({}),v=ps(),d=()=>{const h={};return r.trim()?r.length<3?h.name="Group name must be at least 3 characters":r.length>50&&(h.name="Group name must be less than 50 characters"):h.name="Group name is required",i&&i.length>200&&(h.description="Description must be less than 200 characters"),x(h),Object.keys(h).length===0},c=async h=>{if(h.preventDefault(),!d())return;const p={name:r.trim(),description:i.trim()||void 0,type:a?"TENANT_GROUP":"ORG_GROUP",...a&&n?{tenantId:n}:{}};try{await v.mutateAsync(p),o(""),u(""),x({}),t()}catch(f){console.error("Failed to create group:",f)}};return e.jsxs("form",{onSubmit:c,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:h=>{o(h.target.value),m.name&&x(p=>({...p,name:""}))},className:m.name?"border-destructive":"",disabled:v.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:i,onChange:h=>{u(h.target.value),m.description&&x(p=>({...p,description:""}))},className:m.description?"border-destructive":"",disabled:v.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:[i.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:()=>{o(""),u(""),x({})},disabled:v.isPending,children:"Clear"}),e.jsx(s.Button,{type:"submit",disabled:v.isPending||!r.trim(),children:v.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 js(t,n=[]){let a=[];function r(i,u){const m=w.createContext(u);m.displayName=i+"Context";const x=a.length;a=[...a,u];const v=c=>{var C;const{scope:h,children:p,...f}=c,j=((C=h==null?void 0:h[t])==null?void 0:C[x])||m,S=w.useMemo(()=>f,Object.values(f));return e.jsx(j.Provider,{value:S,children:p})};v.displayName=i+"Provider";function d(c,h){var j;const p=((j=h==null?void 0:h[t])==null?void 0:j[x])||m,f=w.useContext(p);if(f)return f;if(u!==void 0)return u;throw new Error(`\`${c}\` must be used within \`${i}\``)}return[v,d]}const o=()=>{const i=a.map(u=>w.createContext(u));return function(m){const x=(m==null?void 0:m[t])||i;return w.useMemo(()=>({[`__scope${t}`]:{...m,[t]:x}}),[m,x])}};return o.scopeName=t,[r,bs(o,...n)]}function bs(...t){const n=t[0];if(t.length===1)return n;const a=()=>{const r=t.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(i){const u=r.reduce((m,{useScope:x,scopeName:v})=>{const c=x(i)[`__scope${v}`];return{...m,...c}},{});return w.useMemo(()=>({[`__scope${n.scopeName}`]:u}),[u])}};return a.scopeName=n.scopeName,a}var Ss=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],ne=Ss.reduce((t,n)=>{const a=s.createSlot(`Primitive.${n}`),r=w.forwardRef((o,i)=>{const{asChild:u,...m}=o,x=u?a:n;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(x,{...m,ref:i})});return r.displayName=`Primitive.${n}`,{...t,[n]:r}},{});function ys(){return rs.useSyncExternalStore(Ns,()=>!0,()=>!1)}function Ns(){return()=>{}}var oe="Avatar",[Ds]=js(oe),[ws,Se]=Ds(oe),ye=w.forwardRef((t,n)=>{const{__scopeAvatar:a,...r}=t,[o,i]=w.useState("idle");return e.jsx(ws,{scope:a,imageLoadingStatus:o,onImageLoadingStatusChange:i,children:e.jsx(ne.span,{...r,ref:n})})});ye.displayName=oe;var Ne="AvatarImage",De=w.forwardRef((t,n)=>{const{__scopeAvatar:a,src:r,onLoadingStatusChange:o=()=>{},...i}=t,u=Se(Ne,a),m=Cs(r,i),x=s.useCallbackRef(v=>{o(v),u.onImageLoadingStatusChange(v)});return s.useLayoutEffect2(()=>{m!=="idle"&&x(m)},[m,x]),m==="loaded"?e.jsx(ne.img,{...i,ref:n,src:r}):null});De.displayName=Ne;var we="AvatarFallback",Ce=w.forwardRef((t,n)=>{const{__scopeAvatar:a,delayMs:r,...o}=t,i=Se(we,a),[u,m]=w.useState(r===void 0);return w.useEffect(()=>{if(r!==void 0){const x=window.setTimeout(()=>m(!0),r);return()=>window.clearTimeout(x)}},[r]),u&&i.imageLoadingStatus!=="loaded"?e.jsx(ne.span,{...o,ref:n}):null});Ce.displayName=we;function be(t,n){return t?n?(t.src!==n&&(t.src=n),t.complete&&t.naturalWidth>0?"loaded":"loading"):"error":"idle"}function Cs(t,{referrerPolicy:n,crossOrigin:a}){const r=ys(),o=w.useRef(null),i=r?(o.current||(o.current=new window.Image),o.current):null,[u,m]=w.useState(()=>be(i,t));return s.useLayoutEffect2(()=>{m(be(i,t))},[i,t]),s.useLayoutEffect2(()=>{const x=c=>()=>{m(c)};if(!i)return;const v=x("loaded"),d=x("error");return i.addEventListener("load",v),i.addEventListener("error",d),n&&(i.referrerPolicy=n),typeof a=="string"&&(i.crossOrigin=a),()=>{i.removeEventListener("load",v),i.removeEventListener("error",d)}},[i,a,n]),u}var Le=ye,Ae=De,Me=Ce;const ie=w.forwardRef(({className:t,...n},a)=>e.jsx(Le,{ref:a,className:s.cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",t),...n}));ie.displayName=Le.displayName;const Ls=w.forwardRef(({className:t,...n},a)=>e.jsx(Ae,{ref:a,className:s.cn("aspect-square h-full w-full",t),...n}));Ls.displayName=Ae.displayName;const le=w.forwardRef(({className:t,...n},a)=>e.jsx(Me,{ref:a,className:s.cn("flex h-full w-full items-center justify-center rounded-full bg-muted",t),...n}));le.displayName=Me.displayName;function As({open:t,onOpenChange:n,group:a,onUpdate:r}){const[o,i]=b.useState("members"),[u,m]=b.useState(""),[x,v]=b.useState([]),[d,c]=b.useState([]),{data:h,isLoading:p,refetch:f}=s.useGroupMembers(a.id),j=a.type==="TENANT_GROUP"?"tenant":"organization",{users:S,isLoading:C}=s.useUnifiedUsers({type:j,tenantId:a.tenantId||void 0,active:!0,limit:100}),E=gs(),k=fs(),L=(h==null?void 0:h.members)||[],T=b.useMemo(()=>new Set(L.map(g=>g.userId)),[L]),I=b.useMemo(()=>S.filter(g=>!T.has(g.id)),[S,T]),_=b.useMemo(()=>{if(!u)return I;const g=u.toLowerCase();return I.filter(D=>{var A,O;return((A=D.name)==null?void 0:A.toLowerCase().includes(g))||((O=D.email)==null?void 0:O.toLowerCase().includes(g))})},[I,u]),y=b.useMemo(()=>{if(!u)return L;const g=u.toLowerCase();return L.filter(D=>{var A,O,q,$;return((O=(A=D.user)==null?void 0:A.name)==null?void 0:O.toLowerCase().includes(g))||(($=(q=D.user)==null?void 0:q.email)==null?void 0:$.toLowerCase().includes(g))})},[L,u]),R=async()=>{if(x.length!==0)try{await E.mutateAsync({groupId:a.id,data:{userIds:x,userType:j==="tenant"?"tenant":"org"}}),v([]),i("members"),f(),r==null||r()}catch(g){console.error("Failed to add members:",g)}},K=async()=>{if(d.length!==0)try{await k.mutateAsync({groupId:a.id,data:{userIds:d}}),c([]),f(),r==null||r()}catch(g){console.error("Failed to remove members:",g)}},W=g=>{v(D=>D.includes(g)?D.filter(A=>A!==g):[...D,g])},N=g=>{c(D=>D.includes(g)?D.filter(A=>A!==g):[...D,g])};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:[L.length," ",L.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:o,onValueChange:g=>{i(g),m(""),c([])},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:u,onChange:g=>m(g.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:d.length>0?"h-[300px]":"h-[350px]",children:p?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(g=>e.jsx(s.Skeleton,{className:"h-16 w-full"},g))}):y.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:u?"No members found":"No members yet"}),e.jsx("p",{className:"text-xs mt-1",children:u?"Try a different search":'Switch to the "Add Members" tab to add people to this group'})]}):e.jsx("div",{className:"space-y-2",children:y.map(g=>e.jsx(Ms,{member:g,selected:d.includes(g.userId),onToggle:()=>N(g.userId)},g.id))})}),d.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:[d.length," member",d.length!==1?"s":""," selected"]}),e.jsx(s.Button,{variant:"destructive",size:"sm",onClick:K,disabled:k.isPending,children:k.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:u,onChange:g=>m(g.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(g=>e.jsx(s.Skeleton,{className:"h-16 w-full"},g))}):_.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:u?"Try a different search":"All eligible users are already members"})]}):e.jsx("div",{className:"space-y-2",children:_.map(g=>e.jsx(Es,{user:g,selected:x.includes(g.id),onToggle:()=>W(g.id)},g.id))})}),x.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:[x.length," user",x.length!==1?"s":""," selected"]}),e.jsx(s.Button,{onClick:R,disabled:E.isPending,children:E.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 Ms({member:t,selected:n,onToggle:a}){var o,i,u,m;const r=((i=(o=t.user)==null?void 0:o.name)==null?void 0:i.split(" ").map(x=>x[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(ie,{className:"h-8 w-8",children:e.jsx(le,{className:"text-xs",children:r})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:((u=t.user)==null?void 0:u.name)||"Unknown User"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(m=t.user)==null?void 0:m.email})]})]})}function Es({user:t,selected:n,onToggle:a}){var o;const r=((o=t.name)==null?void 0:o.split(" ").map(i=>i[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(ie,{className:"h-8 w-8",children:e.jsx(le,{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]=b.useState("groups"),[o,i]=b.useState(""),[u,m]=b.useState(null),[x,v]=b.useState(!1),[d,c]=b.useState(null),{tokenProps:h}=s.useSemaphorContext(),{currentUser:p}=s.useCurrentUserInfo(),f=xs(),j=(p==null?void 0:p.type)==="tenant",S=h==null?void 0:h.tenantId,{groups:C,isLoading:E,refetch:k}=s.useGroups({type:j?"TENANT_GROUP":"all",tenantId:j?S:void 0,includeMembers:!1}),L=C.filter(y=>{var R;return y.name.toLowerCase().includes(o.toLowerCase())||((R=y.description)==null?void 0:R.toLowerCase().includes(o.toLowerCase()))}),T=async()=>{if(d)try{await f.mutateAsync(d.id),c(null),k()}catch(y){console.error("Failed to delete group:",y)}},I=y=>{m(y),v(!0)},_=()=>{r("groups"),k()};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:o,onChange:y=>i(y.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:"h-[400px]",children:E?e.jsx("div",{className:"space-y-3",children:[1,2,3].map(y=>e.jsx(s.Skeleton,{className:"h-24 w-full"},y))}):L.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:o?"Try a different search":"Create your first group to get started"})]}):e.jsx("div",{className:"space-y-3",children:L.map(y=>e.jsx(ks,{group:y,onManageMembers:()=>I(y),onDelete:()=>c(y),currentUserId:p==null?void 0:p.id},y.id))})})]})}),e.jsx(s.TabsContent,{value:"create",className:"mt-4",children:e.jsx(vs,{onSuccess:_,tenantId:S,isTenantUser:j})})]})]})}),u&&e.jsx(As,{open:x,onOpenChange:v,group:u,onUpdate:()=>k()}),e.jsx(s.AlertDialog,{open:!!d,onOpenChange:()=>c(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 "',d==null?void 0:d.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:T,disabled:f.isPending,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:f.isPending?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Deleting..."]}):"Delete Group"})]})]})})]})}function ks({group:t,onManageMembers:n,onDelete:a,currentUserId:r}){const o=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 ",We.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"})}),o&&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 Ts(){var pe,xe,ge;const{authToken:t,tokenProps:n,id:a}=s.useSemaphorContext(),{isLocalDev:r}=s.useDashboardPreferences(),{permissions:o}=Ke.useRoleAwareDisplayPreferences(),i=s.useHasDashboardId(),{isLoading:u}=s.useDashboardQuery();s.useDashboardStore(l=>l.theme);const m=s.useDashboardStore(l=>l.lenses),x=s.useDashboardStore(l=>l.selectedLensId),v=m==null?void 0:m.find(l=>l.id===x),d=s.useDashboardStore(l=>l.dashboard);s.useDashboardStore(l=>l.selectedSheetId);const c=s.useDashboardStore(l=>l.isDashboardEditing),{setDashboardTitle:h}=s.useDashboardStore(l=>l.actions),[p,f]=b.useState(!1),[j,S]=b.useState(!1),[C,E]=b.useState(!1),[k,L]=b.useState(!1),[T,I]=b.useState(null),[_,y]=b.useState(!1),R=s.useDashboardStore(l=>l.isDashboardPanelOpen),K=s.useDashboardStore(l=>l.actions.setIsDashboardPanelOpen),W=s.useDashboardStore(l=>l.filterValues),N=s.useDashboardStore(l=>l.isVisualEditing);s.useEditorStore(l=>l.card);const g=s.useManagementStore(l=>l.selectedDashboard),D=s.useManagementStore(l=>l.initialDashboard);s.useManagementStore(l=>l.selectedVisual),s.useDashboardStore(l=>l.selectedFrameId),s.useEditorStore(l=>l.frame);const A=g?(xe=g==null?void 0:g.permissions)==null?void 0:xe.canEdit:(pe=D==null?void 0:D.permissions)==null?void 0:pe.canEdit,O=s.useDashboardStore(l=>l.showFilters),q=s.useAssistantLayoutStore(l=>l.setPanelOpen),$=s.useDashboardStore(l=>l.showDashboardJSON),J=s.useDashboardStore(l=>l.onSaveFunction),Ee=s.useDashboardStore(l=>l.actions.setShowFilters),{setIsDashboardEditing:ce,setShowDashboardJSON:de}=s.useDashboardStore(l=>l.actions),{setInitialDashboard:ue,clearSelectedDashboard:Ie}=s.useManagementStore(l=>l.actions),{resources:V}=s.useResourceManagement(s.ResourceType.DASHBOARD),{currentUser:ke}=s.useCurrentUserInfo(),Te=s.canUserManageGroups(ke),P=g||D,me=P?{id:P.id,title:(d==null?void 0:d.title)||P.title||"Dashboard"}:null,{handleAddNewFrame:Oe}=s.useAddNewFrame(),[F,X]=b.useState(!1),[_e,z]=b.useState(!1),H=s.useUpdateResource(s.ResourceType.DASHBOARD),[G,Y]=b.useState(null),Re=async(l,M)=>{if(!(d!=null&&d.id)){console.log("No dashboard ID found");return}console.log("Updating dashboard title:",{dashboardId:d.id,newTitle:l,previousTitle:M}),H.mutate({resourceId:d.id,data:{title:l}},{onSuccess:()=>{console.log("Dashboard title updated successfully"),s.ue.success("Dashboard title updated")},onError:U=>{console.error("Failed to update dashboard title:",U),s.ue.error("Failed to update dashboard title"),h(M)}})};b.useEffect(()=>{if(V&&V.length>0){const l=d==null?void 0:d.id;if(l){const M=V.find(U=>U.id===l);M&&ue(M)}}},[V,d==null?void 0:d.id,ue]);const Q=n.orgUserId||n.tenantId,Pe=c&&!N&&Q&&A,{setDashboard:Fe}=s.useDashboardStore(l=>l.actions),Ge=()=>{ce(!0)},Z=()=>{ce(!1),de(!1),Y(null)};B.usePristineSnapshotInitializer(c,d,G,l=>Y(l));const Ue=()=>G?JSON.stringify(d)!==JSON.stringify(G):!1,Be=()=>{Ue()?z(!0):Z()},qe=async()=>{await ee({closeAfterSave:!0})},$e=()=>{G&&Fe(G),Z(),z(!1)};async function ee(l){const M=(l==null?void 0:l.closeAfterSave)??_;y(M),M&&z(!1);const U=s.cloneDeep(d);L(!0),I(null),X(!0);const Qe={template:d};H.mutate({resourceId:d.id,data:Qe},{onSuccess:()=>{X(!1),s.ue.success("Dashboard saved!"),Y(U),L(!1),y(!1),M&&Z()},onError:()=>{X(!1),I("Failed to save dashboard. Please try again."),s.ue.error("Failed to save dashboard")}})}async function Ve(){if(f(!0),!x||!v)return;const l=JSON.stringify(d),M={...v,template:l,filterValues:W};await re(n.apiServiceUrl,M,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),J==null||J(d),f(!1)}const he=(v==null?void 0:v.name)||d.title;H.isPending&&console.log("Title during update:",{title:he,dashboardStateTitle:d.title,dashboardId:d==null?void 0:d.id,currentLensName:v==null?void 0:v.name});const ze=n.orgUserId||n.tenantId&&n.endUserId&&n.endUserEmail,He=i;return e.jsxs("div",{className:"flex h-11 shrink-0 items-center justify-between gap-2 overflow-x-auto border-b px-4 py-2",role:"dashboard-controls",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[ze&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{"aria-label":"Manage Dashboards",tooltip:"Manage Dashboards",onClick:()=>{K(!R)},className:"h-7 p-2",children:e.jsx(Ye,{className:"h-4 w-4"})}),He&&!N&&e.jsx(s.IconButton,{"aria-label":"Dashboard Hub",tooltip:"Dashboard Hub",onClick:()=>Ie(),className:"h-7 p-2",children:e.jsx(s.House,{className:"h-4 w-4"})})]}),!N&&i&&(u?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:he||"Untitled Dashboard",onSave:l=>{console.log("EditableText onSave called:",{newTitle:l,canEditDashboard:A,dashboardId:d==null?void 0:d.id});const M=(d==null?void 0:d.title)||"";h(l),Re(l,M)},isEditable:A&&!v,displayClassName:"text-sm font-medium",inputClassName:"text-sm font-medium",placeholder:"Dashboard Title",isPending:H.isPending}))]}),e.jsxs("div",{className:"flex items-center gap-2",children:[N&&e.jsxs(e.Fragment,{children:[e.jsx(B.AdvancedModeToggle,{className:"mr-2"}),e.jsx(B.VisualEditingControls,{className:"h-7"})]}),r&&!N&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{tooltip:"Copy Token",onClick:()=>{var l;t!=null&&t.accessToken&&((l=navigator==null?void 0:navigator.clipboard)!=null&&l.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(es,{className:"h-4 w-4"})})]}),!N&&i&&e.jsx(s.DownloadPdf,{}),!N&&i&&e.jsx(B.ScheduleDashboard,{}),!N&&i&&Te&&e.jsx(s.IconButton,{tooltip:"Manage Groups",onClick:()=>E(!0),className:"h-7 p-2",children:e.jsx(s.Users,{className:"h-4 w-4"})}),!N&&i&&((ge=P==null?void 0:P.permissions)==null?void 0:ge.canShare)&&e.jsx(s.IconButton,{tooltip:"Share Dashboard",onClick:()=>S(!0),className:"h-7 p-2",children:e.jsx(s.Share2,{className:"h-4 w-4"})}),!O&&!N&&c&&o.canUseFilters&&i&&e.jsx(s.Button,{className:"h-7 p-2",variant:"outline",onClick:()=>{q("dashboard",!1),Ee(!0)},size:"sm",children:e.jsx(s.Filter,{className:"h-4 w-4"})}),c&&!N&&Q&&r&&i&&e.jsx(ls,{}),!N&&Q&&r&&i&&e.jsx(cs,{}),c&&!N&&Q&&v&&r&&i&&e.jsxs(s.Button,{className:"h-7 p-2",variant:"secondary",disabled:p,onClick:Ve,size:"sm",children:[e.jsx(fe.Save,{className:"mr-2 h-4 w-4"}),"Save Lens"]}),c&&!N&&i&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",size:"sm",disabled:!c,onClick:()=>Oe(),children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Visual"]}),!N&&!c&&A&&i&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",onClick:Ge,size:"sm",children:[e.jsx(s.Pencil,{className:"mr-2 h-4 w-4"}),"Edit"]}),Pe&&i&&e.jsxs(s.Button,{className:"h-7 p-2",disabled:F,onClick:()=>ee(),size:"sm",children:[F?e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(fe.Save,{className:"mr-2 h-4 w-4"}),F?"Saving...":"Save"]}),!N&&c&&r&&i&&e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(s.Button,{className:"h-7 p-2",onClick:()=>de(!$),size:"sm",variant:"ghost",children:e.jsx(s.Code,{className:"h-4 w-4"})})}),!N&&r&&e.jsx(ns,{}),c&&!N&&i&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",onClick:Be,children:[e.jsx(s.Cross2Icon,{className:"mr-2 h-4 w-4"}),"Close"]}),j&&me&&e.jsx(s.ShareDialog,{resource:me,resourceType:s.ResourceType.DASHBOARD,onClose:()=>S(!1)}),e.jsx(Is,{open:C,onOpenChange:E}),e.jsx(s.AlertDialog,{open:k,onOpenChange:l=>{!l&&F&&!T||(L(l),l||(I(null),y(!1)))},children:e.jsxs(s.AlertDialogContent,{className:"max-w-sm",children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:T?"Save failed":"Saving dashboard"}),e.jsx(s.AlertDialogDescription,{className:"pt-2",children:T?"We could not save the dashboard. Please try again.":"Please wait while we save your changes."})]}),e.jsx(s.AlertDialogFooter,{className:"flex-col gap-2 sm:flex-row sm:justify-end",children:T?e.jsxs(e.Fragment,{children:[e.jsx(s.AlertDialogCancel,{onClick:()=>{L(!1),I(null),y(!1)},className:"m-0",children:"Close"}),e.jsx(s.AlertDialogAction,{onClick:()=>ee(),className:"m-0",children:"Retry"})]}):e.jsxs(s.AlertDialogAction,{disabled:!0,className:"m-0 cursor-default",children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]})})]})}),e.jsx(B.UnsavedChangesAlert,{open:_e,onOpenChange:z,onSave:qe,onDiscard:$e,isSaving:F})]})]})}exports.default=Ts;