react-semaphor 0.1.229 → 0.1.230

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 (32) hide show
  1. package/dist/chunks/dashboard-controls-CIGGC81u.js +47 -0
  2. package/dist/chunks/dashboard-controls-uZZf2_Ms.js +1837 -0
  3. package/dist/chunks/{dashboard-json-Bb4sPs1-.js → dashboard-json-BPOoq2o2.js} +1 -1
  4. package/dist/chunks/{dashboard-json-C6i1R8Wf.js → dashboard-json-BSpSg-pF.js} +1 -1
  5. package/dist/chunks/{dashboard-summary-settings-dialog-B-EIaEfz.js → dashboard-summary-settings-dialog-BBOnX1vh.js} +1 -1
  6. package/dist/chunks/{dashboard-summary-settings-dialog-B5oZC5Et.js → dashboard-summary-settings-dialog-Dd-wAZsI.js} +23 -23
  7. package/dist/chunks/{edit-dashboard-visual-BhqnGTNb.js → edit-dashboard-visual-CmKLavr8.js} +459 -459
  8. package/dist/chunks/{edit-dashboard-visual-BrR2eN_x.js → edit-dashboard-visual-D0myN7lC.js} +1 -1
  9. package/dist/chunks/{editor-action-buttons-DZHYde-x.js → editor-action-buttons-DicV0M4e.js} +1 -1
  10. package/dist/chunks/{editor-action-buttons-BuGSShg4.js → editor-action-buttons-ujerALSP.js} +42 -42
  11. package/dist/chunks/{index--t-xJkFo.js → index-BKtY-D8Y.js} +161 -161
  12. package/dist/chunks/{index-C_FfPMsT.js → index-SLQXKi01.js} +5658 -5645
  13. package/dist/chunks/{notification-bell-BUK6qo6E.js → notification-bell-BlKABlIE.js} +1 -1
  14. package/dist/chunks/{notification-bell-BJx5GZ0K.js → notification-bell-D83sUTTI.js} +60 -60
  15. package/dist/chunks/resource-management-panel-CJXZMjqO.js +920 -0
  16. package/dist/chunks/resource-management-panel-TqjX5FH0.js +6 -0
  17. package/dist/chunks/{use-visual-utils-CckIJVB_.js → use-visual-utils-CjUf9Xns.js} +1 -1
  18. package/dist/chunks/{use-visual-utils-C-1MadD0.js → use-visual-utils-DNfxkGiH.js} +33 -33
  19. package/dist/dashboard/index.cjs +1 -1
  20. package/dist/dashboard/index.js +1 -1
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.js +44 -44
  23. package/dist/style.css +1 -1
  24. package/dist/surfboard/index.cjs +1 -1
  25. package/dist/surfboard/index.js +2 -2
  26. package/package.json +1 -1
  27. package/dist/chunks/dashboard-controls-C4Yq0TiH.js +0 -1764
  28. package/dist/chunks/dashboard-controls-DUVPeEnP.js +0 -47
  29. package/dist/chunks/resource-management-panel-C--Zp8ix.js +0 -6
  30. package/dist/chunks/resource-management-panel-CliUOxsc.js +0 -913
  31. package/dist/chunks/use-role-aware-display-preferences-Dza-JBu0.js +0 -29
  32. package/dist/chunks/use-role-aware-display-preferences-YdbXXiO7.js +0 -1
@@ -0,0 +1,47 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-BKtY-D8Y.js"),b=require("react");require("react-dom");const _=require("./notification-bell-BlKABlIE.js"),Ss=require("./date-formatter-Sz6QDaM8.js"),Pe=require("./dashboard-summary-settings-dialog-BBOnX1vh.js"),ys=require("./use-debounced-dirty-check-XHSwAefL.js"),xe=require("./normalize-dashboard-for-dirty-check-B7NQDI1H.js"),Fe=require("./editor-action-buttons-DicV0M4e.js");function Ds(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=Ds(b);/**
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 Ns=s.createLucideIcon("FilterX",[["path",{d:"M13.013 3H2l8 9.46V19l4 2v-8.54l.9-1.055",key:"1fi1da"}],["path",{d:"m22 3-5 5",key:"12jva0"}],["path",{d:"m17 3 5 5",key:"k36vhe"}]]);/**
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 ws=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"}]]);/**
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 Cs=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"}]]);/**
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 Ms=s.createLucideIcon("Moon",[["path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z",key:"a7tn18"}]]);/**
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 Ls=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"}]]);/**
27
+ * @license lucide-react v0.453.0 - ISC
28
+ *
29
+ * This source code is licensed under the ISC license.
30
+ * See the LICENSE file in the root directory of this source tree.
31
+ */const As=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 ve={exports:{}},ge={};/**
32
+ * @license React
33
+ * use-sync-external-store-shim.production.js
34
+ *
35
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
36
+ *
37
+ * This source code is licensed under the MIT license found in the
38
+ * LICENSE file in the root directory of this source tree.
39
+ */var Re;function Es(){if(Re)return ge;Re=1;var t=b;function n(d,h){return d===h&&(d!==0||1/d===1/h)||d!==d&&h!==h}var a=typeof Object.is=="function"?Object.is:n,r=t.useState,o=t.useEffect,l=t.useLayoutEffect,u=t.useDebugValue;function m(d,h){var x=h(),f=r({inst:{value:x,getSnapshot:h}}),j=f[0].inst,S=f[1];return l(function(){j.value=x,j.getSnapshot=h,p(j)&&S({inst:j})},[d,x,h]),o(function(){return p(j)&&S({inst:j}),d(function(){p(j)&&S({inst:j})})},[d]),u(x),x}function p(d){var h=d.getSnapshot;d=d.value;try{var x=h();return!a(d,x)}catch{return!0}}function g(d,h){return h()}var c=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?g:m;return ge.useSyncExternalStore=t.useSyncExternalStore!==void 0?t.useSyncExternalStore:c,ge}var fe={};/**
40
+ * @license React
41
+ * use-sync-external-store-shim.development.js
42
+ *
43
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
44
+ *
45
+ * This source code is licensed under the MIT license found in the
46
+ * LICENSE file in the root directory of this source tree.
47
+ */var Ge;function ks(){return Ge||(Ge=1,process.env.NODE_ENV!=="production"&&function(){function t(x,f){return x===f&&(x!==0||1/x===1/f)||x!==x&&f!==f}function n(x,f){c||o.startTransition===void 0||(c=!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(!d){var S=f();l(j,S)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),d=!0)}S=u({inst:{value:j,getSnapshot:f}});var C=S[0].inst,A=S[1];return p(function(){C.value=j,C.getSnapshot=f,a(C)&&A({inst:C})},[x,j,f]),m(function(){return a(C)&&A({inst:C}),x(function(){a(C)&&A({inst:C})})},[x]),g(j),j}function a(x){var f=x.getSnapshot;x=x.value;try{var j=f();return!l(x,j)}catch{return!0}}function r(x,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,l=typeof Object.is=="function"?Object.is:t,u=o.useState,m=o.useEffect,p=o.useLayoutEffect,g=o.useDebugValue,c=!1,d=!1,h=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?r:n;fe.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())}()),fe}process.env.NODE_ENV==="production"?ve.exports=Es():ve.exports=ks();var Is=ve.exports;function Ts(){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(As,{strokeWidth:1.5,className:"h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0"}),e.jsx(Ms,{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 l=JSON.stringify(a),u=`${t}/v1/lens`;return await s.postRequest(u,o,{name:n,template:l,filterValues:r,operation:"create"})}async function be(t,n,a){if(!a)return null;const{id:r,template:o,filterValues:l,isDefault:u,shared:m}=n,p=`${t}/v1/lens`;return await s.postRequest(p,a,{lensId:r,template:o,filterValues:l,isDefault:u,shared:m,operation:"update"})}async function _s(t,n,a){if(!a)return null;const r=`${t}/v1/lens`;return await s.postRequest(r,a,{operation:"delete",lensId:n})}function Us(){const[t,n]=b.useState(""),[a,r]=b.useState(!1),o=s.useDashboardStore(S=>S.lenses),{setLenses:l,setSelectedLensId:u}=s.useDashboardActions(),[m,p]=b.useState(!1),[g,c]=b.useState(!1),d=s.useDashboardStore(S=>S.dashboard),h=s.useDashboardStore(S=>S.filterValues),{authToken:x,tokenProps:f}=s.useSemaphorContext();async function j(){p(!0);const S=await Os(f.apiServiceUrl,t,d,h,x==null?void 0:x.accessToken);S&&(l([...o||[],S]),u(S.id),c(!1)),p(!1)}return e.jsxs(s.Dialog,{open:g,onOpenChange:c,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,{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 Ps(){const[t,n]=b.useState(!1),a=s.useDashboardStore(d=>d.lenses),r=s.useDashboardStore(d=>d.selectedLensId),{setLenses:o,setSelectedLensId:l}=s.useDashboardActions(),{authToken:u,tokenProps:m}=s.useSemaphorContext();async function p(d){l(d)}async function g(d){if(await _s(m.apiServiceUrl,d,u==null?void 0:u.accessToken)){const x=a==null?void 0:a.filter(f=>f.id!==d);o(x||[]),l("original")}}async function c(d){const h=a==null?void 0:a.map(j=>j.id===d.id?{...j,isDefault:!d.isDefault}:{...j,isDefault:!1});o(h||[]);const x={...d,isDefault:!d.isDefault};await be(m.apiServiceUrl,x,u==null?void 0:u.accessToken);const f=a==null?void 0:a.find(j=>j.isDefault);if(f&&f.id!==d.id){const j={...f,isDefault:!1};await be(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(ws,{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:p,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),a==null?void 0:a.map(d=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:d.id,children:[e.jsx("p",{children:d.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(s.House,{onClick:h=>{h.preventDefault(),c(d)},className:s.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!d.isDefault,"text-green-500":d.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:h=>{h.preventDefault(),g(d.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},d.id))]})]})]})}function Fs(){const{displayPreferences:t,shouldShowElement:n}=s.useDisplayPreferences(),{currentUser:a,userContext:r}=s.useCurrentUserInfo(),o=b.useMemo(()=>s.getRoleBasedDisplayOverrides(a),[a]),l=b.useMemo(()=>m=>o&&o[m]!==void 0&&o[m]===!1?!1:n(m),[o,n,t]),u=b.useMemo(()=>{var m,p,g,c,d;return{canEdit:((m=r==null?void 0:r.permissions)==null?void 0:m.canEdit)??s.canUserEdit(a),canUseFilters:((p=r==null?void 0:r.permissions)==null?void 0:p.canEdit)??s.canUserUseFilters(a),canManageDashboards:((g=r==null?void 0:r.permissions)==null?void 0:g.canCreateDashboard)??s.canUserManageDashboards(a),canCreateDashboards:((c=r==null?void 0:r.permissions)==null?void 0:c.canCreateDashboard)??s.canUserCreateDashboards(a),canAccessVisuals:((d=r==null?void 0:r.permissions)==null?void 0:d.canEdit)??s.canUserAccessVisuals(a)}},[a,r]);return{displayPreferences:t,shouldShowElement:l,permissions:u,currentUser:a}}const Rs=async(t,n,a)=>{const r=`${t}/management/v1/groups`;return await s.postRequestRegular(r,n,a)},Gs=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 l=await o.text();throw new Error(l||"Failed to delete group")}},Bs=async(t,n,a,r)=>{const o=`${t}/management/v1/groups/${a}/members`;return await s.postRequestRegular(o,n,r)},qs=async(t,n,a,r)=>{const o=`${t}/management/v1/groups/${a}/members`,l=await fetch(o,{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify(r)});if(!l.ok){const u=await l.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=>Rs(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 zs(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:r=>Gs(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 Vs(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:o})=>Bs(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 $s(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:o})=>qs(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 Qs({onSuccess:t,tenantId:n,isTenantUser:a}){const[r,o]=b.useState(""),[l,u]=b.useState(""),[m,p]=b.useState({}),g=Hs(),c=()=>{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",l&&l.length>200&&(h.description="Description must be less than 200 characters"),p(h),Object.keys(h).length===0},d=async h=>{if(h.preventDefault(),!c())return;const x={name:r.trim(),description:l.trim()||void 0,type:a?"TENANT_GROUP":"ORG_GROUP",...a&&n?{tenantId:n}:{}};try{await g.mutateAsync(x),o(""),u(""),p({}),t()}catch(f){console.error("Failed to create group:",f)}};return e.jsxs("form",{onSubmit:d,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,{id:"group-name",placeholder:"e.g., Marketing Team, Engineering Squad",value:r,onChange:h=>{o(h.target.value),m.name&&p(x=>({...x,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:l,onChange:h=>{u(h.target.value),m.description&&p(x=>({...x,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:[l.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(""),p({})},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 Ks(t,n=[]){let a=[];function r(l,u){const m=w.createContext(u);m.displayName=l+"Context";const p=a.length;a=[...a,u];const g=d=>{var C;const{scope:h,children:x,...f}=d,j=((C=h==null?void 0:h[t])==null?void 0:C[p])||m,S=w.useMemo(()=>f,Object.values(f));return e.jsx(j.Provider,{value:S,children:x})};g.displayName=l+"Provider";function c(d,h){var j;const x=((j=h==null?void 0:h[t])==null?void 0:j[p])||m,f=w.useContext(x);if(f)return f;if(u!==void 0)return u;throw new Error(`\`${d}\` must be used within \`${l}\``)}return[g,c]}const o=()=>{const l=a.map(u=>w.createContext(u));return function(m){const p=(m==null?void 0:m[t])||l;return w.useMemo(()=>({[`__scope${t}`]:{...m,[t]:p}}),[m,p])}};return o.scopeName=t,[r,Ws(o,...n)]}function Ws(...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(l){const u=r.reduce((m,{useScope:p,scopeName:g})=>{const d=p(l)[`__scope${g}`];return{...m,...d}},{});return w.useMemo(()=>({[`__scope${n.scopeName}`]:u}),[u])}};return a.scopeName=n.scopeName,a}var Js=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],je=Js.reduce((t,n)=>{const a=s.createSlot(`Primitive.${n}`),r=w.forwardRef((o,l)=>{const{asChild:u,...m}=o,p=u?a:n;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(p,{...m,ref:l})});return r.displayName=`Primitive.${n}`,{...t,[n]:r}},{});function Xs(){return Is.useSyncExternalStore(Ys,()=>!0,()=>!1)}function Ys(){return()=>{}}var Se="Avatar",[Zs]=Ks(Se),[et,qe]=Zs(Se),He=w.forwardRef((t,n)=>{const{__scopeAvatar:a,...r}=t,[o,l]=w.useState("idle");return e.jsx(et,{scope:a,imageLoadingStatus:o,onImageLoadingStatusChange:l,children:e.jsx(je.span,{...r,ref:n})})});He.displayName=Se;var ze="AvatarImage",Ve=w.forwardRef((t,n)=>{const{__scopeAvatar:a,src:r,onLoadingStatusChange:o=()=>{},...l}=t,u=qe(ze,a),m=st(r,l),p=s.useCallbackRef(g=>{o(g),u.onImageLoadingStatusChange(g)});return s.useLayoutEffect2(()=>{m!=="idle"&&p(m)},[m,p]),m==="loaded"?e.jsx(je.img,{...l,ref:n,src:r}):null});Ve.displayName=ze;var $e="AvatarFallback",Qe=w.forwardRef((t,n)=>{const{__scopeAvatar:a,delayMs:r,...o}=t,l=qe($e,a),[u,m]=w.useState(r===void 0);return w.useEffect(()=>{if(r!==void 0){const p=window.setTimeout(()=>m(!0),r);return()=>window.clearTimeout(p)}},[r]),u&&l.imageLoadingStatus!=="loaded"?e.jsx(je.span,{...o,ref:n}):null});Qe.displayName=$e;function Be(t,n){return t?n?(t.src!==n&&(t.src=n),t.complete&&t.naturalWidth>0?"loaded":"loading"):"error":"idle"}function st(t,{referrerPolicy:n,crossOrigin:a}){const r=Xs(),o=w.useRef(null),l=r?(o.current||(o.current=new window.Image),o.current):null,[u,m]=w.useState(()=>Be(l,t));return s.useLayoutEffect2(()=>{m(Be(l,t))},[l,t]),s.useLayoutEffect2(()=>{const p=d=>()=>{m(d)};if(!l)return;const g=p("loaded"),c=p("error");return l.addEventListener("load",g),l.addEventListener("error",c),n&&(l.referrerPolicy=n),typeof a=="string"&&(l.crossOrigin=a),()=>{l.removeEventListener("load",g),l.removeEventListener("error",c)}},[l,a,n]),u}var Ke=He,We=Ve,Je=Qe;const ye=w.forwardRef(({className:t,...n},a)=>e.jsx(Ke,{ref:a,className:s.cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",t),...n}));ye.displayName=Ke.displayName;const tt=w.forwardRef(({className:t,...n},a)=>e.jsx(We,{ref:a,className:s.cn("aspect-square h-full w-full",t),...n}));tt.displayName=We.displayName;const De=w.forwardRef(({className:t,...n},a)=>e.jsx(Je,{ref:a,className:s.cn("flex h-full w-full items-center justify-center rounded-full bg-muted",t),...n}));De.displayName=Je.displayName;function at({open:t,onOpenChange:n,group:a,onUpdate:r}){const[o,l]=b.useState("members"),[u,m]=b.useState(""),[p,g]=b.useState([]),[c,d]=b.useState([]),{data:h,isLoading:x,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}),A=Vs(),k=$s(),M=(h==null?void 0:h.members)||[],U=b.useMemo(()=>new Set(M.map(v=>v.userId)),[M]),T=b.useMemo(()=>S.filter(v=>!U.has(v.id)),[S,U]),P=b.useMemo(()=>{if(!u)return T;const v=u.toLowerCase();return T.filter(N=>{var E,O;return((E=N.name)==null?void 0:E.toLowerCase().includes(v))||((O=N.email)==null?void 0:O.toLowerCase().includes(v))})},[T,u]),y=b.useMemo(()=>{if(!u)return M;const v=u.toLowerCase();return M.filter(N=>{var E,O,W,D;return((O=(E=N.user)==null?void 0:E.name)==null?void 0:O.toLowerCase().includes(v))||((D=(W=N.user)==null?void 0:W.email)==null?void 0:D.toLowerCase().includes(v))})},[M,u]),F=async()=>{if(p.length!==0)try{await A.mutateAsync({groupId:a.id,data:{userIds:p,userType:j==="tenant"?"tenant":"org"}}),g([]),l("members"),f(),r==null||r()}catch(v){console.error("Failed to add members:",v)}},R=async()=>{if(c.length!==0)try{await k.mutateAsync({groupId:a.id,data:{userIds:c}}),d([]),f(),r==null||r()}catch(v){console.error("Failed to remove members:",v)}},G=v=>{g(N=>N.includes(v)?N.filter(E=>E!==v):[...N,v])},B=v=>{d(N=>N.includes(v)?N.filter(E=>E!==v):[...N,v])};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:o,onValueChange:v=>{l(v),m(""),d([])},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,{placeholder:"Search members...",value:u,onChange:v=>m(v.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:c.length>0?"h-[300px]":"h-[350px]",children:x?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(v=>e.jsx(s.Skeleton,{className:"h-16 w-full"},v))}):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(v=>e.jsx(rt,{member:v,selected:c.includes(v.userId),onToggle:()=>B(v.userId)},v.id))})}),c.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:[c.length," member",c.length!==1?"s":""," selected"]}),e.jsx(s.Button,{variant:"destructive",size:"sm",onClick:R,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,{placeholder:"Search users to add...",value:u,onChange:v=>m(v.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(v=>e.jsx(s.Skeleton,{className:"h-16 w-full"},v))}):P.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:P.map(v=>e.jsx(nt,{user:v,selected:p.includes(v.id),onToggle:()=>G(v.id)},v.id))})}),p.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:[p.length," user",p.length!==1?"s":""," selected"]}),e.jsx(s.Button,{onClick:F,disabled:A.isPending,children:A.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 rt({member:t,selected:n,onToggle:a}){var o,l,u,m;const r=((l=(o=t.user)==null?void 0:o.name)==null?void 0:l.split(" ").map(p=>p[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(ye,{className:"h-8 w-8",children:e.jsx(De,{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 nt({user:t,selected:n,onToggle:a}){var o;const r=((o=t.name)==null?void 0:o.split(" ").map(l=>l[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(ye,{className:"h-8 w-8",children:e.jsx(De,{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 ot({open:t,onOpenChange:n}){const[a,r]=b.useState("groups"),[o,l]=b.useState(""),[u,m]=b.useState(null),[p,g]=b.useState(!1),[c,d]=b.useState(null),{tokenProps:h}=s.useSemaphorContext(),{currentUser:x}=s.useCurrentUserInfo(),f=zs(),j=(x==null?void 0:x.type)==="tenant",S=h==null?void 0:h.tenantId,{groups:C,isLoading:A,refetch:k}=s.useGroups({type:j?"TENANT_GROUP":"all",tenantId:j?S:void 0,includeMembers:!1}),M=C.filter(y=>{var F;return y.name.toLowerCase().includes(o.toLowerCase())||((F=y.description)==null?void 0:F.toLowerCase().includes(o.toLowerCase()))}),U=async()=>{if(c)try{await f.mutateAsync(c.id),d(null),k()}catch(y){console.error("Failed to delete group:",y)}},T=y=>{m(y),g(!0)},P=()=>{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,{placeholder:"Search groups...",value:o,onChange:y=>l(y.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:"h-[400px]",children:A?e.jsx("div",{className:"space-y-3",children:[1,2,3].map(y=>e.jsx(s.Skeleton,{className:"h-24 w-full"},y))}):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:o?"Try a different search":"Create your first group to get started"})]}):e.jsx("div",{className:"space-y-3",children:M.map(y=>e.jsx(it,{group:y,onManageMembers:()=>T(y),onDelete:()=>d(y),currentUserId:x==null?void 0:x.id},y.id))})})]})}),e.jsx(s.TabsContent,{value:"create",className:"mt-4",children:e.jsx(Qs,{onSuccess:P,tenantId:S,isTenantUser:j})})]})]})}),u&&e.jsx(at,{open:p,onOpenChange:g,group:u,onUpdate:()=>k()}),e.jsx(s.AlertDialog,{open:!!c,onOpenChange:()=>d(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 "',c==null?void 0:c.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:U,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 it({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 ",Ss.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 lt(){var Te,Oe,_e,Ue;_.useExportRecovery(),_.useExportPolling();const{authToken:t,tokenProps:n,id:a}=s.useSemaphorContext(),{isLocalDev:r}=s.useDashboardPreferences(),{permissions:o}=Fs(),l=s.useHasDashboardId(),{isLoading:u}=s.useDashboardQuery();s.useDashboardStore(i=>i.theme);const m=s.useDashboardStore(i=>i.lenses),p=s.useDashboardStore(i=>i.selectedLensId),g=m==null?void 0:m.find(i=>i.id===p),c=s.useDashboardStore(i=>i.dashboard);s.useDashboardStore(i=>i.selectedSheetId);const d=s.useDashboardStore(i=>i.isDashboardEditing),{setDashboardTitle:h}=s.useDashboardStore(i=>i.actions),[x,f]=b.useState(!1),[j,S]=b.useState(!1),[C,A]=b.useState(!1),[k,M]=b.useState(!1),[U,T]=b.useState(!1),[P,y]=b.useState(!1),[F,R]=b.useState(!1),[G,B]=b.useState(null),[v,N]=b.useState(!1),E=s.useDashboardStore(i=>i.isDashboardPanelOpen),O=s.useDashboardStore(i=>i.actions.setIsDashboardPanelOpen),W=s.useDashboardStore(i=>i.filterValues),D=s.useDashboardStore(i=>i.isVisualEditing);s.useEditorStore(i=>i.card);const H=s.useManagementStore(i=>i.selectedDashboard),J=s.useManagementStore(i=>i.initialDashboard);s.useManagementStore(i=>i.selectedVisual),s.useDashboardStore(i=>i.selectedFrameId),s.useEditorStore(i=>i.frame);const X=H?(Oe=H==null?void 0:H.permissions)==null?void 0:Oe.canEdit:(Te=J==null?void 0:J.permissions)==null?void 0:Te.canEdit,te=s.useDashboardStore(i=>i.showFilters),Xe=s.useAssistantLayoutStore(i=>i.setPanelOpen),Ye=s.useDashboardStore(i=>i.showDashboardJSON),ae=s.useDashboardStore(i=>i.onSaveFunction),Ze=s.useDashboardStore(i=>i.actions.setShowFilters),{setIsDashboardEditing:Ne,setShowDashboardJSON:we}=s.useDashboardStore(i=>i.actions),{setInitialDashboard:Ce,clearSelectedDashboard:re}=s.useManagementStore(i=>i.actions),{resources:Y}=s.useResourceManagement(s.ResourceType.DASHBOARD),{data:ne}=s.useUserPreferences(),es=((_e=ne==null?void 0:ne.preference)==null?void 0:_e.defaultDashboardId)||null,{mutate:ss,isPending:ts}=s.useDefaultDashboardMutation(),{currentUser:as}=s.useCurrentUserInfo(),rs=s.canUserManageGroups(as),q=H||J,Me=q?{id:q.id,title:(c==null?void 0:c.title)||q.title||"Dashboard"}:null,{handleAddNewFrame:ns}=s.useAddNewFrame(),[oe,ie]=b.useState(!1),[os,z]=b.useState(!1),[le,Z]=b.useState("close"),V=s.useUpdateResource(s.ResourceType.DASHBOARD),[I,ce]=b.useState(null),is=async(i,L)=>{if(!(c!=null&&c.id)){console.log("No dashboard ID found");return}console.log("Updating dashboard title:",{dashboardId:c.id,newTitle:i,previousTitle:L}),V.mutate({resourceId:c.id,data:{title:i}},{onSuccess:()=>{console.log("Dashboard title updated successfully"),s.ue.success("Dashboard title updated")},onError:K=>{console.error("Failed to update dashboard title:",K),s.ue.error("Failed to update dashboard title"),h(L)}})};b.useEffect(()=>{if(Y&&Y.length>0){const i=c==null?void 0:c.id;if(i){const L=Y.find(K=>K.id===i);L&&Ce(L)}}},[Y,c==null?void 0:c.id,Ce]);const ee=n.orgUserId||n.tenantId,Le=d&&!D&&ee&&X,{setDashboard:de}=s.useDashboardStore(i=>i.actions),ls=()=>{Ne(!0)},ue=()=>{Ne(!1),we(!1),ce(null)};_.usePristineSnapshotInitializer(d,c,I,i=>ce(i));const{isDirty:Ae,isDirtyPending:cs,resetDirty:se}=ys.useDebouncedDirtyCheck(c,I,300,1e3,xe.serializeDashboardForDirtyCheck),Ee=b.useCallback(()=>I?xe.serializeDashboardForDirtyCheck(c)!==xe.serializeDashboardForDirtyCheck(I):!1,[c,I]),me=Ae||cs,$=oe||V.isPending,ds=()=>{Ee()?(Z("close"),z(!0)):(ue(),se())},us=async()=>{await he({closeAfterSave:!0,navigateHomeAfterSave:le==="home"})},ms=()=>{I&&de(I),ue(),le==="home"&&re(),Z("close"),z(!1),se()},hs=()=>{I&&(de(I),se())},ps=()=>{if(d&&Ee()){Z("home"),z(!0);return}re()};async function he(i){const L=(i==null?void 0:i.closeAfterSave)??v,K=(i==null?void 0:i.navigateHomeAfterSave)??!1;N(L),L&&z(!1);const bs=s.cloneDeep(c);R(!0),B(null),ie(!0);const js={template:c};V.mutate({resourceId:c.id,data:js},{onSuccess:()=>{ie(!1),s.ue.success("Dashboard saved!"),ce(bs),R(!1),N(!1),L&&(ue(),se(),K&&re()),Z("close")},onError:()=>{ie(!1),B("Failed to save dashboard. Please try again."),s.ue.error("Failed to save dashboard")}})}async function xs(){if(f(!0),!p||!g)return;const i=JSON.stringify(c),L={...g,template:i,filterValues:W};await be(n.apiServiceUrl,L,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),ae==null||ae(c),f(!1)}const ke=(g==null?void 0:g.name)||c.title;V.isPending&&console.log("Title during update:",{title:ke,dashboardStateTitle:c.title,dashboardId:c==null?void 0:c.id,currentLensName:g==null?void 0:g.name});const Ie=n.orgUserId||n.tenantId&&n.endUserId&&n.endUserEmail,gs=!!Ie&&!!(t!=null&&t.accessToken)&&!!(n!=null&&n.apiServiceUrl),fs=l,Q=(c==null?void 0:c.id)||null,pe=!!Q&&es===Q,vs=()=>{Q&&ss({dashboardId:pe?null:Q})};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:[Ie&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{"aria-label":"Manage Dashboards",tooltip:"Manage Dashboards",onClick:()=>{O(!E)},className:"h-7 p-2",children:e.jsx(Cs,{className:"h-4 w-4"})}),fs&&!D&&e.jsx(s.IconButton,{"aria-label":"Dashboard Hub",tooltip:"Dashboard Hub",onClick:ps,className:"h-7 p-2",children:e.jsx(s.House,{className:"h-4 w-4"})})]}),!D&&l&&(u?e.jsx("div",{className:"h-4 w-28 rounded-md bg-muted/70 animate-pulse","aria-label":"Loading dashboard title",role:"status",children:e.jsx("span",{className:"sr-only",children:"Loading dashboard title"})}):e.jsxs(e.Fragment,{children:[e.jsx(s.EditableText,{value:ke||"Untitled Dashboard",onSave:i=>{console.log("EditableText onSave called:",{newTitle:i,canEditDashboard:X,dashboardId:c==null?void 0:c.id});const L=(c==null?void 0:c.title)||"";h(i),is(i,L)},isEditable:X&&!g,displayClassName:"text-sm font-medium",inputClassName:"text-sm font-medium",placeholder:"Dashboard Title",isPending:V.isPending}),gs&&Q&&e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"ghost",size:"icon",onClick:vs,disabled:ts||!(t!=null&&t.accessToken)||!(n!=null&&n.apiServiceUrl),className:"h-7 w-7",children:e.jsx(s.Star,{className:s.cn("h-4 w-4 transition-colors",pe?"fill-yellow-400 text-yellow-400":"text-muted-foreground hover:text-yellow-400")})})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{children:pe?"Remove as default dashboard":"Make this a default dashboard"})})]})})]}))]}),e.jsxs("div",{className:"flex items-center gap-2",children:[D&&e.jsxs(e.Fragment,{children:[e.jsx(_.AdvancedModeToggle,{className:"mr-2"}),e.jsx(_.VisualEditingControls,{className:"h-7"})]}),r&&!D&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{tooltip:"Copy Token",onClick:()=>{var i;t!=null&&t.accessToken&&((i=navigator==null?void 0:navigator.clipboard)!=null&&i.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(Ls,{className:"h-4 w-4"})})]}),!D&&l&&e.jsx(s.DownloadPdf,{}),!D&&l&&e.jsx(_.NotificationBell,{}),!D&&l&&((Ue=q==null?void 0:q.permissions)==null?void 0:Ue.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"})}),!D&&d&&o.canUseFilters&&l&&e.jsxs(s.Button,{className:"h-7 px-2",variant:"outline",onClick:()=>{te||Xe("dashboard",!1),Ze(!te)},size:"sm",children:[te?e.jsx(Ns,{className:"mr-2 h-4 w-4"}):e.jsx(s.Filter,{className:"mr-2 h-4 w-4"}),"Filter"]}),d&&!D&&ee&&r&&l&&e.jsx(Us,{}),!D&&ee&&r&&l&&e.jsx(Ps,{}),d&&!D&&ee&&g&&r&&l&&e.jsxs(s.Button,{className:"h-7 p-2",variant:"secondary",disabled:x,onClick:xs,size:"sm",children:[e.jsx(Fe.Save,{className:"mr-2 h-4 w-4"}),"Save Lens"]}),d&&!D&&l&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",size:"sm",disabled:!d,onClick:()=>ns(),children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Visual"]}),!D&&!d&&X&&l&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",onClick:ls,size:"sm",children:[e.jsx(s.Pencil,{className:"mr-2 h-4 w-4"}),"Edit"]}),Le&&l&&Ae&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",onClick:hs,size:"sm",disabled:$,children:[e.jsx(s.Undo2,{className:"mr-2 h-4 w-4"}),"Undo"]}),Le&&l&&e.jsxs("div",{className:"relative inline-flex",children:[e.jsxs(s.Button,{className:s.cn("h-7 p-2",!me&&"opacity-60"),disabled:$||!me,onClick:()=>he(),size:"sm",children:[$?e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(Fe.Save,{className:"mr-2 h-4 w-4"}),$?"Saving...":"Save"]}),me&&!$&&e.jsx("span",{"aria-hidden":"true",className:"pointer-events-none absolute -right-1 -top-1 h-2.5 w-2.5 rounded-full bg-orange-500 ring-2 ring-background"})]}),!D&&d&&r&&l&&e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(s.Button,{className:"h-7 p-2",onClick:()=>we(!Ye),size:"sm",variant:"ghost",children:e.jsx(s.Code,{className:"h-4 w-4"})})}),!D&&r&&e.jsx(Ts,{}),d&&!D&&l&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",onClick:ds,children:[e.jsx(s.Cross2Icon,{className:"mr-2 h-4 w-4"}),"Close"]}),!D&&l&&e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"More Options",className:"h-8 w-8 rounded-md border border-transparent p-0 text-muted-foreground hover:bg-muted/50 hover:text-foreground",buttonProps:{"aria-label":"More dashboard options"},children:e.jsx(s.EllipsisVertical,{className:"h-4 w-4"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-56 rounded-xl border border-border/60 p-1 shadow-sm",children:[e.jsx(s.DropdownMenuLabel,{className:"px-2.5 text-xs font-medium text-muted-foreground",children:"Automation"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>M(!0),className:"flex items-center gap-2",children:[e.jsx(s.Clock,{className:"mr-2 h-4 w-4"}),"Schedule Dashboard"]}),e.jsx(s.DropdownMenuSeparator,{}),rs&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuLabel,{className:"px-2.5 text-xs font-medium text-muted-foreground",children:"Access"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>A(!0),className:"flex items-center gap-2",children:[e.jsx(s.Users,{className:"mr-2 h-4 w-4"}),"Manage Groups"]}),e.jsx(s.DropdownMenuSeparator,{})]}),e.jsx(s.DropdownMenuLabel,{className:"px-2.5 text-xs font-medium text-muted-foreground",children:"Preferences"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>T(!0),className:"flex items-center gap-2",children:[e.jsx(s.Calendar,{className:"mr-2 h-4 w-4"}),"Calendar Preferences"]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>y(!0),className:"flex items-center gap-2",children:[e.jsx(s.FileText,{className:"mr-2 h-4 w-4"}),"Summary Settings"]})]})]}),j&&Me&&e.jsx(s.ShareDialog,{resource:Me,resourceType:s.ResourceType.DASHBOARD,onClose:()=>S(!1)}),e.jsx(ot,{open:C,onOpenChange:A}),(c==null?void 0:c.id)&&e.jsx(s.EmailScheduleDialog,{open:k,onOpenChange:M,dashboardId:c.id,dashboardName:c==null?void 0:c.title}),e.jsx(Pe.CalendarPreferencesDialog,{open:U,onOpenChange:T}),e.jsx(Pe.DashboardSummarySettingsDialog,{open:P,onOpenChange:y,dashboard:c,disabled:!d,onApply:i=>de({...c,summary:i})}),e.jsx(s.AlertDialog,{open:F,onOpenChange:i=>{!i&&oe&&!G||(R(i),i||(B(null),N(!1)))},children:e.jsxs(s.AlertDialogContent,{className:"max-w-sm",children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:G?"Save failed":"Saving dashboard"}),e.jsx(s.AlertDialogDescription,{className:"pt-2",children:G?"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:G?e.jsxs(e.Fragment,{children:[e.jsx(s.AlertDialogCancel,{onClick:()=>{R(!1),B(null),N(!1)},className:"m-0",children:"Close"}),e.jsx(s.AlertDialogAction,{onClick:()=>he({closeAfterSave:v,navigateHomeAfterSave:le==="home"}),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(_.UnsavedChangesAlert,{open:os,onOpenChange:i=>{z(i)},onSave:us,onDiscard:ms,isSaving:oe,saveLabel:"Save",discardLabel:"Discard"})]})]})}exports.default=lt;