react-semaphor 0.1.210 → 0.1.211

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-C08300Wi.js → dashboard-controls-7KpXzAWL.js} +592 -585
  2. package/dist/chunks/dashboard-controls-CnDq9Uh_.js +42 -0
  3. package/dist/chunks/{dashboard-json-GjDBGO26.js → dashboard-json-dqey5VK0.js} +1 -1
  4. package/dist/chunks/{dashboard-json-DlEE5-WA.js → dashboard-json-stWvjp2O.js} +1 -1
  5. package/dist/chunks/{dashboard-summary-settings-dialog-THx-gjnG.js → dashboard-summary-settings-dialog-DPEe6XBC.js} +1 -1
  6. package/dist/chunks/{dashboard-summary-settings-dialog-QUuhhXU9.js → dashboard-summary-settings-dialog-DuxhidK1.js} +1 -1
  7. package/dist/chunks/{edit-dashboard-visual-Bsmow1Pa.js → edit-dashboard-visual-CQAk_UsI.js} +483 -484
  8. package/dist/chunks/{edit-dashboard-visual-PfWJXb2-.js → edit-dashboard-visual-D_XPr8f8.js} +2 -2
  9. package/dist/chunks/{editor-action-buttons-FPyaC09X.js → editor-action-buttons-CH7W6KdH.js} +1 -1
  10. package/dist/chunks/{editor-action-buttons-DNbp_ZWy.js → editor-action-buttons-D34_GSZu.js} +27 -27
  11. package/dist/chunks/{index-CAVrkf9d.js → index-BDS2sWhv.js} +27718 -27508
  12. package/dist/chunks/index-BfiIPyeS.js +1109 -0
  13. package/dist/chunks/{notification-bell-C3a7wC1u.js → notification-bell-Cu3qDd9V.js} +251 -285
  14. package/dist/chunks/notification-bell-hijGST9g.js +6 -0
  15. package/dist/chunks/{resource-management-panel-BVTgbma8.js → resource-management-panel-BvHqslqC.js} +73 -73
  16. package/dist/chunks/{resource-management-panel-C5NjrVsA.js → resource-management-panel-gK3a6OEj.js} +1 -1
  17. package/dist/chunks/{use-role-aware-display-preferences-l7NFLYnn.js → use-role-aware-display-preferences-BlR29aKQ.js} +1 -1
  18. package/dist/chunks/{use-role-aware-display-preferences-DxCPoCgr.js → use-role-aware-display-preferences-a5FH9Y0k.js} +1 -1
  19. package/dist/chunks/{use-visual-utils-B82Q-Ytl.js → use-visual-utils-B11AA2fd.js} +1 -1
  20. package/dist/chunks/{use-visual-utils-D9IJz9R0.js → use-visual-utils-ptPsQ3nC.js} +23 -23
  21. package/dist/dashboard/index.cjs +1 -1
  22. package/dist/dashboard/index.js +1 -1
  23. package/dist/index.cjs +1 -1
  24. package/dist/index.js +251 -216
  25. package/dist/style.css +1 -1
  26. package/dist/surfboard/index.cjs +1 -1
  27. package/dist/surfboard/index.js +2 -2
  28. package/dist/types/main.d.ts +49 -0
  29. package/package.json +1 -1
  30. package/dist/chunks/dashboard-controls-BAOrAMV9.js +0 -42
  31. package/dist/chunks/index-CXKjmjfB.js +0 -1104
  32. package/dist/chunks/notification-bell-BqvKQSw9.js +0 -6
@@ -0,0 +1,42 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-BfiIPyeS.js"),f=require("react");require("react-dom");const _=require("./notification-bell-hijGST9g.js"),bs=require("./use-role-aware-display-preferences-BlR29aKQ.js"),Ss=require("./date-formatter-Sz6QDaM8.js"),_e=require("./dashboard-summary-settings-dialog-DuxhidK1.js"),ae=require("./normalize-dashboard-for-dirty-check-D9x96J2F.js"),Re=require("./editor-action-buttons-CH7W6KdH.js");function ys(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 E=ys(f);/**
2
+ * @license lucide-react v0.453.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const Ds=s.createLucideIcon("Glasses",[["circle",{cx:"6",cy:"15",r:"4",key:"vux9w4"}],["circle",{cx:"18",cy:"15",r:"4",key:"18o8ve"}],["path",{d:"M14 15a2 2 0 0 0-2-2 2 2 0 0 0-2 2",key:"1ag4bs"}],["path",{d:"M2.5 13 5 7c.7-1.3 1.4-2 3-2",key:"1hm1gs"}],["path",{d:"M21.5 13 19 7c-.7-1.3-1.5-2-3-2",key:"1r31ai"}]]);/**
7
+ * @license lucide-react v0.453.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */const Ns=s.createLucideIcon("Menu",[["line",{x1:"4",x2:"20",y1:"12",y2:"12",key:"1e0a9i"}],["line",{x1:"4",x2:"20",y1:"6",y2:"6",key:"1owob3"}],["line",{x1:"4",x2:"20",y1:"18",y2:"18",key:"yk5zj1"}]]);/**
12
+ * @license lucide-react v0.453.0 - ISC
13
+ *
14
+ * This source code is licensed under the ISC license.
15
+ * See the LICENSE file in the root directory of this source tree.
16
+ */const ws=s.createLucideIcon("Moon",[["path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z",key:"a7tn18"}]]);/**
17
+ * @license lucide-react v0.453.0 - ISC
18
+ *
19
+ * This source code is licensed under the ISC license.
20
+ * See the LICENSE file in the root directory of this source tree.
21
+ */const Cs=s.createLucideIcon("ShieldX",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m14.5 9.5-5 5",key:"17q4r4"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]]);/**
22
+ * @license lucide-react v0.453.0 - ISC
23
+ *
24
+ * This source code is licensed under the ISC license.
25
+ * See the LICENSE file in the root directory of this source tree.
26
+ */const Ls=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 fe={exports:{}},ge={};/**
27
+ * @license React
28
+ * use-sync-external-store-shim.production.js
29
+ *
30
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
31
+ *
32
+ * This source code is licensed under the MIT license found in the
33
+ * LICENSE file in the root directory of this source tree.
34
+ */var Ue;function As(){if(Ue)return ge;Ue=1;var t=f;function n(d,m){return d===m&&(d!==0||1/d===1/m)||d!==d&&m!==m}var a=typeof Object.is=="function"?Object.is:n,r=t.useState,l=t.useEffect,c=t.useLayoutEffect,u=t.useDebugValue;function p(d,m){var h=m(),j=r({inst:{value:h,getSnapshot:m}}),b=j[0].inst,S=j[1];return c(function(){b.value=h,b.getSnapshot=m,x(b)&&S({inst:b})},[d,h,m]),l(function(){return x(b)&&S({inst:b}),d(function(){x(b)&&S({inst:b})})},[d]),u(h),h}function x(d){var m=d.getSnapshot;d=d.value;try{var h=m();return!a(d,h)}catch{return!0}}function v(d,m){return m()}var i=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?v:p;return ge.useSyncExternalStore=t.useSyncExternalStore!==void 0?t.useSyncExternalStore:i,ge}var xe={};/**
35
+ * @license React
36
+ * use-sync-external-store-shim.development.js
37
+ *
38
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
39
+ *
40
+ * This source code is licensed under the MIT license found in the
41
+ * LICENSE file in the root directory of this source tree.
42
+ */var Fe;function Ms(){return Fe||(Fe=1,process.env.NODE_ENV!=="production"&&function(){function t(h,j){return h===j&&(h!==0||1/h===1/j)||h!==h&&j!==j}function n(h,j){i||l.startTransition===void 0||(i=!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 b=j();if(!d){var S=j();c(b,S)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),d=!0)}S=u({inst:{value:b,getSnapshot:j}});var w=S[0].inst,A=S[1];return x(function(){w.value=b,w.getSnapshot=j,a(w)&&A({inst:w})},[h,b,j]),p(function(){return a(w)&&A({inst:w}),h(function(){a(w)&&A({inst:w})})},[h]),v(b),b}function a(h){var j=h.getSnapshot;h=h.value;try{var b=j();return!c(h,b)}catch{return!0}}function r(h,j){return j()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var l=f,c=typeof Object.is=="function"?Object.is:t,u=l.useState,p=l.useEffect,x=l.useLayoutEffect,v=l.useDebugValue,i=!1,d=!1,m=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?r:n;xe.useSyncExternalStore=l.useSyncExternalStore!==void 0?l.useSyncExternalStore:m,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()),xe}process.env.NODE_ENV==="production"?fe.exports=As():fe.exports=Ms();var Es=fe.exports;function Is(){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(Ls,{strokeWidth:1.5,className:"h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0"}),e.jsx(ws,{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 ks(t,n,a,r,l){if(!l)return null;const c=JSON.stringify(a),u=`${t}/v1/lens`;return await s.postRequest(u,l,{name:n,template:c,filterValues:r,operation:"create"})}async function ve(t,n,a){if(!a)return null;const{id:r,template:l,filterValues:c,isDefault:u,shared:p}=n,x=`${t}/v1/lens`;return await s.postRequest(x,a,{lensId:r,template:l,filterValues:c,isDefault:u,shared:p,operation:"update"})}async function Ts(t,n,a){if(!a)return null;const r=`${t}/v1/lens`;return await s.postRequest(r,a,{operation:"delete",lensId:n})}function Os(){const[t,n]=f.useState(""),[a,r]=f.useState(!1),l=s.useDashboardStore(S=>S.lenses),{setLenses:c,setSelectedLensId:u}=s.useDashboardActions(),[p,x]=f.useState(!1),[v,i]=f.useState(!1),d=s.useDashboardStore(S=>S.dashboard),m=s.useDashboardStore(S=>S.filterValues),{authToken:h,tokenProps:j}=s.useSemaphorContext();async function b(){x(!0);const S=await ks(j.apiServiceUrl,t,d,m,h==null?void 0:h.accessToken);S&&(c([...l||[],S]),u(S.id),i(!1)),x(!1)}return e.jsxs(s.Dialog,{open:v,onOpenChange:i,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:b,disabled:p,children:p?"Creating...":"Add"})})]})]})}function _s(){const[t,n]=f.useState(!1),a=s.useDashboardStore(d=>d.lenses),r=s.useDashboardStore(d=>d.selectedLensId),{setLenses:l,setSelectedLensId:c}=s.useDashboardActions(),{authToken:u,tokenProps:p}=s.useSemaphorContext();async function x(d){c(d)}async function v(d){if(await Ts(p.apiServiceUrl,d,u==null?void 0:u.accessToken)){const h=a==null?void 0:a.filter(j=>j.id!==d);l(h||[]),c("original")}}async function i(d){const m=a==null?void 0:a.map(b=>b.id===d.id?{...b,isDefault:!d.isDefault}:{...b,isDefault:!1});l(m||[]);const h={...d,isDefault:!d.isDefault};await ve(p.apiServiceUrl,h,u==null?void 0:u.accessToken);const j=a==null?void 0:a.find(b=>b.isDefault);if(j&&j.id!==d.id){const b={...j,isDefault:!1};await ve(p.apiServiceUrl,b,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(Ds,{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(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:m=>{m.preventDefault(),i(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:m=>{m.preventDefault(),v(d.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},d.id))]})]})]})}const Rs=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}`,l=await fetch(r,{method:"DELETE",headers:{Authorization:`Bearer ${n}`}});if(!l.ok){const c=await l.text();throw new Error(c||"Failed to delete group")}},Fs=async(t,n,a,r)=>{const l=`${t}/management/v1/groups/${a}/members`;return await s.postRequestRegular(l,n,r)},Ps=async(t,n,a,r)=>{const l=`${t}/management/v1/groups/${a}/members`,c=await fetch(l,{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify(r)});if(!c.ok){const u=await c.text();throw new Error(u||"Failed to remove group members")}};function Gs(){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 Bs(){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,l)=>{a.invalidateQueries({queryKey:["groups"]}),a.removeQueries({queryKey:["group",l]}),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 qs(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:l})=>Fs(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r,l),onSuccess:(r,l)=>{a.invalidateQueries({queryKey:["group",l.groupId]}),a.invalidateQueries({queryKey:["group-members",l.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 Hs(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:l})=>Ps(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r,l),onSuccess:(r,l)=>{a.invalidateQueries({queryKey:["group",l.groupId]}),a.invalidateQueries({queryKey:["group-members",l.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 zs({onSuccess:t,tenantId:n,isTenantUser:a}){const[r,l]=f.useState(""),[c,u]=f.useState(""),[p,x]=f.useState({}),v=Gs(),i=()=>{const m={};return r.trim()?r.length<3?m.name="Group name must be at least 3 characters":r.length>50&&(m.name="Group name must be less than 50 characters"):m.name="Group name is required",c&&c.length>200&&(m.description="Description must be less than 200 characters"),x(m),Object.keys(m).length===0},d=async m=>{if(m.preventDefault(),!i())return;const h={name:r.trim(),description:c.trim()||void 0,type:a?"TENANT_GROUP":"ORG_GROUP",...a&&n?{tenantId:n}:{}};try{await v.mutateAsync(h),l(""),u(""),x({}),t()}catch(j){console.error("Failed to create group:",j)}};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:m=>{l(m.target.value),p.name&&x(h=>({...h,name:""}))},className:p.name?"border-destructive":"",disabled:v.isPending}),p.name&&e.jsx("p",{className:"text-sm text-destructive",children:p.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:c,onChange:m=>{u(m.target.value),p.description&&x(h=>({...h,description:""}))},className:p.description?"border-destructive":"",disabled:v.isPending,rows:3}),p.description&&e.jsx("p",{className:"text-sm text-destructive",children:p.description}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[c.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:()=>{l(""),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(){return Es.useSyncExternalStore($s,()=>!0,()=>!1)}function $s(){return()=>{}}var je="Avatar",[Qs]=s.createContextScope(je),[Ks,Ge]=Qs(je),Be=E.forwardRef((t,n)=>{const{__scopeAvatar:a,...r}=t,[l,c]=E.useState("idle");return e.jsx(Ks,{scope:a,imageLoadingStatus:l,onImageLoadingStatusChange:c,children:e.jsx(s.Primitive.span,{...r,ref:n})})});Be.displayName=je;var qe="AvatarImage",He=E.forwardRef((t,n)=>{const{__scopeAvatar:a,src:r,onLoadingStatusChange:l=()=>{},...c}=t,u=Ge(qe,a),p=Ws(r,c),x=s.useCallbackRef(v=>{l(v),u.onImageLoadingStatusChange(v)});return s.useLayoutEffect2(()=>{p!=="idle"&&x(p)},[p,x]),p==="loaded"?e.jsx(s.Primitive.img,{...c,ref:n,src:r}):null});He.displayName=qe;var ze="AvatarFallback",Ve=E.forwardRef((t,n)=>{const{__scopeAvatar:a,delayMs:r,...l}=t,c=Ge(ze,a),[u,p]=E.useState(r===void 0);return E.useEffect(()=>{if(r!==void 0){const x=window.setTimeout(()=>p(!0),r);return()=>window.clearTimeout(x)}},[r]),u&&c.imageLoadingStatus!=="loaded"?e.jsx(s.Primitive.span,{...l,ref:n}):null});Ve.displayName=ze;function Pe(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=Vs(),l=E.useRef(null),c=r?(l.current||(l.current=new window.Image),l.current):null,[u,p]=E.useState(()=>Pe(c,t));return s.useLayoutEffect2(()=>{p(Pe(c,t))},[c,t]),s.useLayoutEffect2(()=>{const x=d=>()=>{p(d)};if(!c)return;const v=x("loaded"),i=x("error");return c.addEventListener("load",v),c.addEventListener("error",i),n&&(c.referrerPolicy=n),typeof a=="string"&&(c.crossOrigin=a),()=>{c.removeEventListener("load",v),c.removeEventListener("error",i)}},[c,a,n]),u}var $e=Be,Qe=He,Ke=Ve;const be=E.forwardRef(({className:t,...n},a)=>e.jsx($e,{ref:a,className:s.cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",t),...n}));be.displayName=$e.displayName;const Js=E.forwardRef(({className:t,...n},a)=>e.jsx(Qe,{ref:a,className:s.cn("aspect-square h-full w-full",t),...n}));Js.displayName=Qe.displayName;const Se=E.forwardRef(({className:t,...n},a)=>e.jsx(Ke,{ref:a,className:s.cn("flex h-full w-full items-center justify-center rounded-full bg-muted",t),...n}));Se.displayName=Ke.displayName;function Xs({open:t,onOpenChange:n,group:a,onUpdate:r}){const[l,c]=f.useState("members"),[u,p]=f.useState(""),[x,v]=f.useState([]),[i,d]=f.useState([]),{data:m,isLoading:h,refetch:j}=s.useGroupMembers(a.id),b=a.type==="TENANT_GROUP"?"tenant":"organization",{users:S,isLoading:w}=s.useUnifiedUsers({type:b,tenantId:a.tenantId||void 0,active:!0,limit:100}),A=qs(),I=Hs(),C=(m==null?void 0:m.members)||[],R=f.useMemo(()=>new Set(C.map(g=>g.userId)),[C]),T=f.useMemo(()=>S.filter(g=>!R.has(g.id)),[S,R]),U=f.useMemo(()=>{if(!u)return T;const g=u.toLowerCase();return T.filter(N=>{var M,O;return((M=N.name)==null?void 0:M.toLowerCase().includes(g))||((O=N.email)==null?void 0:O.toLowerCase().includes(g))})},[T,u]),y=f.useMemo(()=>{if(!u)return C;const g=u.toLowerCase();return C.filter(N=>{var M,O,J,D;return((O=(M=N.user)==null?void 0:M.name)==null?void 0:O.toLowerCase().includes(g))||((D=(J=N.user)==null?void 0:J.email)==null?void 0:D.toLowerCase().includes(g))})},[C,u]),F=async()=>{if(x.length!==0)try{await A.mutateAsync({groupId:a.id,data:{userIds:x,userType:b==="tenant"?"tenant":"org"}}),v([]),c("members"),j(),r==null||r()}catch(g){console.error("Failed to add members:",g)}},P=async()=>{if(i.length!==0)try{await I.mutateAsync({groupId:a.id,data:{userIds:i}}),d([]),j(),r==null||r()}catch(g){console.error("Failed to remove members:",g)}},G=g=>{v(N=>N.includes(g)?N.filter(M=>M!==g):[...N,g])},B=g=>{d(N=>N.includes(g)?N.filter(M=>M!==g):[...N,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:[C.length," ",C.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:l,onValueChange:g=>{c(g),p(""),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:g=>p(g.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:i.length>0?"h-[300px]":"h-[350px]",children:h?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(Ys,{member:g,selected:i.includes(g.userId),onToggle:()=>B(g.userId)},g.id))})}),i.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:[i.length," member",i.length!==1?"s":""," selected"]}),e.jsx(s.Button,{variant:"destructive",size:"sm",onClick:P,disabled:I.isPending,children:I.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:g=>p(g.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:"h-[300px]",children:w?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(g=>e.jsx(s.Skeleton,{className:"h-16 w-full"},g))}):U.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:U.map(g=>e.jsx(Zs,{user:g,selected:x.includes(g.id),onToggle:()=>G(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: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 Ys({member:t,selected:n,onToggle:a}){var l,c,u,p;const r=((c=(l=t.user)==null?void 0:l.name)==null?void 0:c.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(be,{className:"h-8 w-8",children:e.jsx(Se,{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:(p=t.user)==null?void 0:p.email})]})]})}function Zs({user:t,selected:n,onToggle:a}){var l;const r=((l=t.name)==null?void 0:l.split(" ").map(c=>c[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(be,{className:"h-8 w-8",children:e.jsx(Se,{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 et({open:t,onOpenChange:n}){const[a,r]=f.useState("groups"),[l,c]=f.useState(""),[u,p]=f.useState(null),[x,v]=f.useState(!1),[i,d]=f.useState(null),{tokenProps:m}=s.useSemaphorContext(),{currentUser:h}=s.useCurrentUserInfo(),j=Bs(),b=(h==null?void 0:h.type)==="tenant",S=m==null?void 0:m.tenantId,{groups:w,isLoading:A,refetch:I}=s.useGroups({type:b?"TENANT_GROUP":"all",tenantId:b?S:void 0,includeMembers:!1}),C=w.filter(y=>{var F;return y.name.toLowerCase().includes(l.toLowerCase())||((F=y.description)==null?void 0:F.toLowerCase().includes(l.toLowerCase()))}),R=async()=>{if(i)try{await j.mutateAsync(i.id),d(null),I()}catch(y){console.error("Failed to delete group:",y)}},T=y=>{p(y),v(!0)},U=()=>{r("groups"),I()};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:l,onChange:y=>c(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))}):C.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:l?"Try a different search":"Create your first group to get started"})]}):e.jsx("div",{className:"space-y-3",children:C.map(y=>e.jsx(st,{group:y,onManageMembers:()=>T(y),onDelete:()=>d(y),currentUserId:h==null?void 0:h.id},y.id))})})]})}),e.jsx(s.TabsContent,{value:"create",className:"mt-4",children:e.jsx(zs,{onSuccess:U,tenantId:S,isTenantUser:b})})]})]})}),u&&e.jsx(Xs,{open:x,onOpenChange:v,group:u,onUpdate:()=>I()}),e.jsx(s.AlertDialog,{open:!!i,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 "',i==null?void 0:i.name,'"? This action cannot be undone and will remove all members from the group.']})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:R,disabled:j.isPending,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:j.isPending?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Deleting..."]}):"Delete Group"})]})]})})]})}function st({group:t,onManageMembers:n,onDelete:a,currentUserId:r}){const l=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"})}),l&&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 tt(){var Ie,ke,Te,Oe;_.useExportRecovery(),_.useExportPolling();const{authToken:t,tokenProps:n,id:a}=s.useSemaphorContext(),{isLocalDev:r}=s.useDashboardPreferences(),{permissions:l}=bs.useRoleAwareDisplayPreferences(),c=s.useHasDashboardId(),{isLoading:u}=s.useDashboardQuery();s.useDashboardStore(o=>o.theme);const p=s.useDashboardStore(o=>o.lenses),x=s.useDashboardStore(o=>o.selectedLensId),v=p==null?void 0:p.find(o=>o.id===x),i=s.useDashboardStore(o=>o.dashboard);s.useDashboardStore(o=>o.selectedSheetId);const d=s.useDashboardStore(o=>o.isDashboardEditing),{setDashboardTitle:m}=s.useDashboardStore(o=>o.actions),[h,j]=f.useState(!1),[b,S]=f.useState(!1),[w,A]=f.useState(!1),[I,C]=f.useState(!1),[R,T]=f.useState(!1),[U,y]=f.useState(!1),[F,P]=f.useState(!1),[G,B]=f.useState(null),[g,N]=f.useState(!1),M=s.useDashboardStore(o=>o.isDashboardPanelOpen),O=s.useDashboardStore(o=>o.actions.setIsDashboardPanelOpen),J=s.useDashboardStore(o=>o.filterValues),D=s.useDashboardStore(o=>o.isVisualEditing);s.useEditorStore(o=>o.card);const H=s.useManagementStore(o=>o.selectedDashboard),X=s.useManagementStore(o=>o.initialDashboard);s.useManagementStore(o=>o.selectedVisual),s.useDashboardStore(o=>o.selectedFrameId),s.useEditorStore(o=>o.frame);const Y=H?(ke=H==null?void 0:H.permissions)==null?void 0:ke.canEdit:(Ie=X==null?void 0:X.permissions)==null?void 0:Ie.canEdit,We=s.useDashboardStore(o=>o.showFilters),Je=s.useAssistantLayoutStore(o=>o.setPanelOpen),Xe=s.useDashboardStore(o=>o.showDashboardJSON),re=s.useDashboardStore(o=>o.onSaveFunction),Ye=s.useDashboardStore(o=>o.actions.setShowFilters),{setIsDashboardEditing:ye,setShowDashboardJSON:De}=s.useDashboardStore(o=>o.actions),{setInitialDashboard:Ne,clearSelectedDashboard:ne}=s.useManagementStore(o=>o.actions),{resources:Z}=s.useResourceManagement(s.ResourceType.DASHBOARD),{data:oe}=s.useUserPreferences(),Ze=((Te=oe==null?void 0:oe.preference)==null?void 0:Te.defaultDashboardId)||null,{mutate:es,isPending:ss}=s.useDefaultDashboardMutation(),{currentUser:ts}=s.useCurrentUserInfo(),as=s.canUserManageGroups(ts),q=H||X,we=q?{id:q.id,title:(i==null?void 0:i.title)||q.title||"Dashboard"}:null,{handleAddNewFrame:rs}=s.useAddNewFrame(),[ie,le]=f.useState(!1),[ns,z]=f.useState(!1),[V,ee]=f.useState("close"),$=s.useUpdateResource(s.ResourceType.DASHBOARD),[k,ce]=f.useState(null),os=async(o,L)=>{if(!(i!=null&&i.id)){console.log("No dashboard ID found");return}console.log("Updating dashboard title:",{dashboardId:i.id,newTitle:o,previousTitle:L}),$.mutate({resourceId:i.id,data:{title:o}},{onSuccess:()=>{console.log("Dashboard title updated successfully"),s.ue.success("Dashboard title updated")},onError:W=>{console.error("Failed to update dashboard title:",W),s.ue.error("Failed to update dashboard title"),m(L)}})};f.useEffect(()=>{if(Z&&Z.length>0){const o=i==null?void 0:i.id;if(o){const L=Z.find(W=>W.id===o);L&&Ne(L)}}},[Z,i==null?void 0:i.id,Ne]);const se=n.orgUserId||n.tenantId,Ce=d&&!D&&se&&Y,{setDashboard:de}=s.useDashboardStore(o=>o.actions),is=()=>{ye(!0)},ue=()=>{ye(!1),De(!1),ce(null)};_.usePristineSnapshotInitializer(d,i,k,o=>ce(o));const{isDirty:Le,isDirtyPending:ls,resetDirty:te}=ae.useDebouncedDirtyCheck(i,k,300,1e3,ae.serializeDashboardForDirtyCheck),Ae=f.useCallback(()=>k?ae.serializeDashboardForDirtyCheck(i)!==ae.serializeDashboardForDirtyCheck(k):!1,[i,k]),me=Le||ls,Q=ie||$.isPending,cs=()=>{Ae()?(ee("close"),z(!0)):(ue(),te())},ds=async()=>{await he({closeAfterSave:!0,navigateHomeAfterSave:V==="home"})},us=()=>{k&&de(k),ue(),V==="home"&&ne(),ee("close"),z(!1),te()},ms=()=>{k&&(de(k),te())},hs=()=>{if(d&&Ae()){ee("home"),z(!0);return}ne()};async function he(o){const L=(o==null?void 0:o.closeAfterSave)??g,W=(o==null?void 0:o.navigateHomeAfterSave)??!1;N(L),L&&z(!1);const vs=s.cloneDeep(i);P(!0),B(null),le(!0);const js={template:i};$.mutate({resourceId:i.id,data:js},{onSuccess:()=>{le(!1),s.ue.success("Dashboard saved!"),ce(vs),P(!1),N(!1),L&&(ue(),te(),W&&ne()),ee("close")},onError:()=>{le(!1),B("Failed to save dashboard. Please try again."),s.ue.error("Failed to save dashboard")}})}async function ps(){if(j(!0),!x||!v)return;const o=JSON.stringify(i),L={...v,template:o,filterValues:J};await ve(n.apiServiceUrl,L,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),re==null||re(i),j(!1)}const Me=(v==null?void 0:v.name)||i.title;$.isPending&&console.log("Title during update:",{title:Me,dashboardStateTitle:i.title,dashboardId:i==null?void 0:i.id,currentLensName:v==null?void 0:v.name});const Ee=n.orgUserId||n.tenantId&&n.endUserId&&n.endUserEmail,gs=!!Ee&&!!(t!=null&&t.accessToken)&&!!(n!=null&&n.apiServiceUrl),xs=c,K=(i==null?void 0:i.id)||null,pe=!!K&&Ze===K,fs=()=>{K&&es({dashboardId:pe?null:K})};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:[Ee&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{"aria-label":"Manage Dashboards",tooltip:"Manage Dashboards",onClick:()=>{O(!M)},className:"h-7 p-2",children:e.jsx(Ns,{className:"h-4 w-4"})}),xs&&!D&&e.jsx(s.IconButton,{"aria-label":"Dashboard Hub",tooltip:"Dashboard Hub",onClick:hs,className:"h-7 p-2",children:e.jsx(s.House,{className:"h-4 w-4"})})]}),!D&&c&&(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.jsxs(e.Fragment,{children:[e.jsx(s.EditableText,{value:Me||"Untitled Dashboard",onSave:o=>{console.log("EditableText onSave called:",{newTitle:o,canEditDashboard:Y,dashboardId:i==null?void 0:i.id});const L=(i==null?void 0:i.title)||"";m(o),os(o,L)},isEditable:Y&&!v,displayClassName:"text-sm font-medium",inputClassName:"text-sm font-medium",placeholder:"Dashboard Title",isPending:$.isPending}),gs&&K&&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:fs,disabled:ss||!(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 o;t!=null&&t.accessToken&&((o=navigator==null?void 0:navigator.clipboard)!=null&&o.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(Cs,{className:"h-4 w-4"})})]}),!D&&c&&e.jsx(s.DownloadPdf,{}),!D&&c&&e.jsx(_.NotificationBell,{}),!D&&c&&((Oe=q==null?void 0:q.permissions)==null?void 0:Oe.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"})}),!We&&!D&&d&&l.canUseFilters&&c&&e.jsx(s.Button,{className:"h-7 p-2",variant:"outline",onClick:()=>{Je("dashboard",!1),Ye(!0)},size:"sm",children:e.jsx(s.Filter,{className:"h-4 w-4"})}),d&&!D&&se&&r&&c&&e.jsx(Os,{}),!D&&se&&r&&c&&e.jsx(_s,{}),d&&!D&&se&&v&&r&&c&&e.jsxs(s.Button,{className:"h-7 p-2",variant:"secondary",disabled:h,onClick:ps,size:"sm",children:[e.jsx(Re.Save,{className:"mr-2 h-4 w-4"}),"Save Lens"]}),d&&!D&&c&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",size:"sm",disabled:!d,onClick:()=>rs(),children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Visual"]}),!D&&!d&&Y&&c&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",onClick:is,size:"sm",children:[e.jsx(s.Pencil,{className:"mr-2 h-4 w-4"}),"Edit"]}),Ce&&c&&Le&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",onClick:ms,size:"sm",disabled:Q,children:[e.jsx(s.Undo2,{className:"mr-2 h-4 w-4"}),"Undo"]}),Ce&&c&&e.jsxs("div",{className:"relative inline-flex",children:[e.jsxs(s.Button,{className:s.cn("h-7 p-2",!me&&"opacity-60"),disabled:Q||!me,onClick:()=>he(),size:"sm",children:[Q?e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(Re.Save,{className:"mr-2 h-4 w-4"}),Q?"Saving...":"Save"]}),me&&!Q&&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&&c&&e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(s.Button,{className:"h-7 p-2",onClick:()=>De(!Xe),size:"sm",variant:"ghost",children:e.jsx(s.Code,{className:"h-4 w-4"})})}),!D&&r&&e.jsx(Is,{}),d&&!D&&c&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",onClick:cs,children:[e.jsx(s.Cross2Icon,{className:"mr-2 h-4 w-4"}),"Close"]}),!D&&c&&e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"More Options",className:"h-7 p-2",children:e.jsx(s.EllipsisVertical,{className:"h-4 w-4"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",children:[e.jsxs(s.DropdownMenuItem,{onClick:()=>C(!0),children:[e.jsx(s.Clock,{className:"mr-2 h-4 w-4"}),"Schedule Dashboard"]}),as&&e.jsxs(s.DropdownMenuItem,{onClick:()=>A(!0),children:[e.jsx(s.Users,{className:"mr-2 h-4 w-4"}),"Manage Groups"]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>T(!0),children:[e.jsx(s.Calendar,{className:"mr-2 h-4 w-4"}),"Calendar Preferences"]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>y(!0),children:[e.jsx(s.FileText,{className:"mr-2 h-4 w-4"}),"Summary Settings"]})]})]}),b&&we&&e.jsx(s.ShareDialog,{resource:we,resourceType:s.ResourceType.DASHBOARD,onClose:()=>S(!1)}),e.jsx(et,{open:w,onOpenChange:A}),(i==null?void 0:i.id)&&e.jsx(s.EmailScheduleDialog,{open:I,onOpenChange:C,dashboardId:i.id,dashboardName:i==null?void 0:i.title}),e.jsx(_e.CalendarPreferencesDialog,{open:R,onOpenChange:T}),e.jsx(_e.DashboardSummarySettingsDialog,{open:U,onOpenChange:y,dashboard:i,disabled:!d,onApply:o=>de({...i,summary:o})}),e.jsx(s.AlertDialog,{open:F,onOpenChange:o=>{!o&&ie&&!G||(P(o),o||(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:()=>{P(!1),B(null),N(!1)},className:"m-0",children:"Close"}),e.jsx(s.AlertDialogAction,{onClick:()=>he({closeAfterSave:g,navigateHomeAfterSave:V==="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:ns,onOpenChange:o=>{z(o)},onSave:ds,onDiscard:us,isSaving:ie,saveLabel:V==="home"?"Save & Return to Hub":"Save & Close",discardLabel:V==="home"?"Discard & Return to Hub":"Discard"})]})]})}exports.default=tt;
@@ -1,5 +1,5 @@
1
1
  import { jsxs as o, jsx as r } from "react/jsx-runtime";
2
- import { u as s, B as l, X as h, d, c } from "./index-CAVrkf9d.js";
2
+ import { u as s, B as l, X as h, d, c } from "./index-BDS2sWhv.js";
3
3
  import "react";
4
4
  import "react-dom";
5
5
  function N() {
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),a=require("./index-CXKjmjfB.js");require("react");require("react-dom");function i(){const o=a.useDashboardStore(e=>e.dashboard),r=a.useDashboardStore(e=>e.actions.setDashboard),t=a.useDashboardStore(e=>e.showDashboardJSON),n=a.useDashboardStore(e=>e.actions.setShowDashboardJSON);return s.jsxs("div",{className:a.cn("relative p-2",{hidden:!t}),children:[s.jsxs(a.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>n(!1),children:[s.jsx(a.X,{className:"mr-2 h-4 w-4"}),"Close"]}),s.jsx(a.de,{onChange:e=>{if(e)try{JSON.parse(e),r(JSON.parse(e))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto",value:JSON.stringify(o,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}exports.default=i;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),a=require("./index-BfiIPyeS.js");require("react");require("react-dom");function i(){const o=a.useDashboardStore(e=>e.dashboard),r=a.useDashboardStore(e=>e.actions.setDashboard),t=a.useDashboardStore(e=>e.showDashboardJSON),n=a.useDashboardStore(e=>e.actions.setShowDashboardJSON);return s.jsxs("div",{className:a.cn("relative p-2",{hidden:!t}),children:[s.jsxs(a.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>n(!1),children:[s.jsx(a.X,{className:"mr-2 h-4 w-4"}),"Close"]}),s.jsx(a.de,{onChange:e=>{if(e)try{JSON.parse(e),r(JSON.parse(e))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto",value:JSON.stringify(o,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}exports.default=i;
@@ -1,6 +1,6 @@
1
1
  import { jsx as e, jsxs as s, Fragment as oe } from "react/jsx-runtime";
2
2
  import de, { useState as h, useCallback as L, useEffect as G, useMemo as z } from "react";
3
- import { l as ue, m as X, n as J, o as K, p as Z, q, R as j, r as F, L as b, c as C, P as me, s as he, B as P, C as fe, t as pe, v as ve, w as be, x as Se, y as ge, z as O, A as B, E as W, F as ye, G as Q, H as we, I as A, S as xe, J as Ne, K as Ce, M as Te, N as ke, O as R, Q as Ie } from "./index-CAVrkf9d.js";
3
+ import { l as ue, m as X, n as J, o as K, p as Z, q, R as j, r as F, L as b, c as C, P as me, s as he, B as P, C as fe, t as pe, v as ve, w as be, x as Se, y as ge, z as O, A as B, E as W, F as ye, G as Q, H as we, I as A, S as xe, J as Ne, K as Ce, M as Te, N as ke, O as R, Q as Ie } from "./index-BDS2sWhv.js";
4
4
  function Ee() {
5
5
  var k, I, E, N;
6
6
  const { authToken: a, tokenProps: r } = ue(), [l, S] = h(!1), [p, g] = h(!1), [x, y] = h(!1), [v, o] = h(null), [u, n] = h(null), w = u || {
@@ -1 +1 @@
1
- "use strict";const e=require("react/jsx-runtime"),l=require("react"),a=require("./index-CXKjmjfB.js");function W(){var N,C,T,y;const{authToken:s,tokenProps:r}=a.useSemaphorContext(),[i,S]=l.useState(!1),[x,v]=l.useState(!1),[j,b]=l.useState(!1),[p,u]=l.useState(null),[m,n]=l.useState(null),g=m||{tz:((C=(N=r==null?void 0:r.params)==null?void 0:N.calendarContext)==null?void 0:C.tz)||null,weekStart:((y=(T=r==null?void 0:r.params)==null?void 0:T.calendarContext)==null?void 0:y.weekStart)??null},d=l.useCallback(async()=>{if(!(!(s!=null&&s.accessToken)||!(r!=null&&r.apiServiceUrl))){S(!0),u(null);try{const c=await fetch(`${r.apiServiceUrl}/v1/user-preferences/calendar`,{method:"GET",headers:{Authorization:`Bearer ${s.accessToken}`}});if(!c.ok){const h=await c.json().catch(()=>({}));throw new Error(h.error||"Failed to fetch preferences")}const o=await c.json();n({tz:o.tz,weekStart:o.weekStart,source:o.source,isInherited:o.isInherited,userHasPrefs:o.userHasPrefs,inherited:o.inherited})}catch(c){const o=c instanceof Error?c.message:"Unknown error";u(o)}finally{S(!1)}}},[s,r]);l.useEffect(()=>{d()},[d]);const f=l.useCallback(async c=>{if(!(s!=null&&s.accessToken)||!(r!=null&&r.apiServiceUrl))return u("Not authenticated"),!1;v(!0),u(null);try{const o=await fetch(`${r.apiServiceUrl}/v1/user-preferences/calendar`,{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s.accessToken}`},body:JSON.stringify(c)});if(!o.ok){const h=await o.json().catch(()=>({}));throw new Error(h.error||"Failed to update preferences")}return await d(),!0}catch(o){const h=o instanceof Error?o.message:"Unknown error";return u(h),!1}finally{v(!1)}},[s,r,d]),w=l.useCallback(async()=>{if(!(s!=null&&s.accessToken)||!(r!=null&&r.apiServiceUrl))return u("Not authenticated"),!1;b(!0),u(null);try{const c=await fetch(`${r.apiServiceUrl}/v1/user-preferences/calendar`,{method:"DELETE",headers:{Authorization:`Bearer ${s.accessToken}`}});if(!c.ok){const h=await c.json().catch(()=>({}));throw new Error(h.error||"Failed to clear preferences")}const o=await c.text();if(o)try{const h=JSON.parse(o);return n({tz:h.tz,weekStart:h.weekStart,source:h.source,isInherited:h.isInherited??!0,userHasPrefs:!1,inherited:h.inherited}),!0}catch{}return await d(),!0}catch(c){const o=c instanceof Error?c.message:"Unknown error";return u(o),!1}finally{b(!1)}},[s,r,d]);return{preferences:g,isLoading:i,isSaving:x,isClearing:j,error:p,updatePreferences:f,clearPreferences:w,refetch:d}}const I=[{value:"America/New_York",label:"Eastern Time (US & Canada)"},{value:"America/Chicago",label:"Central Time (US & Canada)"},{value:"America/Denver",label:"Mountain Time (US & Canada)"},{value:"America/Los_Angeles",label:"Pacific Time (US & Canada)"},{value:"America/Phoenix",label:"Arizona"},{value:"America/Anchorage",label:"Alaska"},{value:"Pacific/Honolulu",label:"Hawaii"},{value:"Europe/London",label:"London"},{value:"Europe/Paris",label:"Paris, Berlin, Rome"},{value:"Asia/Tokyo",label:"Tokyo"},{value:"Asia/Shanghai",label:"Beijing, Shanghai"},{value:"Asia/Kolkata",label:"Mumbai, New Delhi"},{value:"Australia/Sydney",label:"Sydney"},{value:"UTC",label:"UTC"}],M=[{value:0,label:"Sunday"},{value:1,label:"Monday"},{value:6,label:"Saturday"}];function G(){try{const s=Intl;if(s.supportedValuesOf)return s.supportedValuesOf("timeZone")}catch{}return I.map(s=>s.value)}function V(s){switch(s){case"tenant":return"tenant";case"organization":return"organization";case"system":return"system";default:return"default"}}function L(s){const r=I.find(i=>i.value===s);return r?r.label:s}function X(s){const r=M.find(i=>i.value===s);return r?r.label:String(s)}function q({open:s,onOpenChange:r}){var E,P,A;const{preferences:i,isLoading:S,isSaving:x,isClearing:v,updatePreferences:j,clearPreferences:b}=W(),p=i.tz||((E=i.inherited)==null?void 0:E.tz)||Intl.DateTimeFormat().resolvedOptions().timeZone,u=i.weekStart??((P=i.inherited)==null?void 0:P.weekStart)??1,[m,n]=l.useState(!i.userHasPrefs),[g,d]=l.useState(!1),[f,w]=l.useState(p),[N,C]=l.useState(u),[T,y]=l.useState(!1),c=l.useMemo(()=>G(),[]),o=l.useMemo(()=>c.filter(t=>!I.some(R=>R.value===t)),[c]),h=l.useMemo(()=>L(f),[f]),F=i.inherited?L(i.inherited.tz):"UTC",H=i.inherited?X(i.inherited.weekStart):"Monday",B=V((A=i.inherited)==null?void 0:A.source);l.useEffect(()=>{if(!s){d(!1);return}g||(i.userHasPrefs!==void 0&&n(!i.userHasPrefs),w(p),C(u))},[s,g,i.userHasPrefs,p,u]);const _=async()=>{if(S){a.ue.error("Preferences are still loading. Please try again.");return}m?await b()?(a.ue.success("Now using default settings. Please refresh the page to apply changes.",{duration:5e3}),r(!1)):a.ue.error("Failed to save preferences. Please try again."):await j({tz:f,weekStart:N})?(a.ue.success("Preferences saved. Please refresh the page to apply changes.",{duration:5e3}),r(!1)):a.ue.error("Failed to save preferences. Please try again.")},$=()=>{r(!1)},D=x||v,O=D||S;return e.jsx(a.Dialog,{open:s,onOpenChange:r,children:e.jsxs(a.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Calendar Preferences"}),e.jsx(a.DialogDescription,{children:"Set your timezone and week start preferences for date calculations and displays."})]}),e.jsxs("div",{className:"space-y-6 py-4",children:[e.jsxs(a.RadioGroup,{value:m?"defaults":"custom",onValueChange:t=>{d(!0),n(t==="defaults")},className:"space-y-3",children:[e.jsxs("div",{className:a.cn("flex items-start space-x-3 rounded-lg border p-4 cursor-pointer transition-colors",m?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"),onClick:()=>{d(!0),n(!0)},children:[e.jsx(a.RadioGroupItem,{value:"defaults",id:"mode-defaults"}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsxs(a.Label,{htmlFor:"mode-defaults",className:"cursor-pointer font-medium",children:["Use ",B," defaults"]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[F,", Week starts ",H]})]})]}),e.jsxs("div",{className:a.cn("flex items-start space-x-3 rounded-lg border p-4 cursor-pointer transition-colors",m?"border-border hover:border-muted-foreground/50":"border-primary bg-primary/5"),onClick:()=>{d(!0),n(!1)},children:[e.jsx(a.RadioGroupItem,{value:"custom",id:"mode-custom"}),e.jsx(a.Label,{htmlFor:"mode-custom",className:"cursor-pointer font-medium",children:"Use custom settings"})]})]}),e.jsxs("div",{className:a.cn("space-y-6 transition-opacity",m&&"opacity-50 pointer-events-none"),children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{children:"Timezone"}),e.jsxs(a.Popover,{open:T,onOpenChange:y,modal:!0,children:[e.jsx(a.PopoverTrigger,{asChild:!0,children:e.jsxs(a.Button,{variant:"outline",role:"combobox","aria-expanded":T,className:"w-full justify-between",disabled:m,children:[h,e.jsx(a.ChevronsUpDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(a.PopoverContent,{className:"z-50 w-[--radix-popover-trigger-width] p-0",align:"start",children:e.jsxs(a.Command,{className:"overflow-visible",children:[e.jsx(a.CommandInput,{placeholder:"Search timezones..."}),e.jsxs(a.CommandList,{children:[e.jsx(a.CommandEmpty,{children:"No timezone found."}),e.jsx(a.CommandGroup,{heading:"Common",children:I.map(t=>e.jsxs(a.CommandItem,{value:`${t.value} ${t.label}`,onSelect:()=>{d(!0),w(t.value),y(!1)},children:[e.jsx(a.Check,{className:a.cn("mr-2 h-4 w-4",f===t.value?"opacity-100":"opacity-0")}),e.jsx("span",{className:"flex-1",children:t.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:t.value})]},t.value))}),e.jsx(a.CommandSeparator,{}),e.jsx(a.CommandGroup,{heading:"All Timezones",children:o.map(t=>e.jsxs(a.CommandItem,{value:t,onSelect:()=>{d(!0),w(t),y(!1)},children:[e.jsx(a.Check,{className:a.cn("mr-2 h-4 w-4",f===t?"opacity-100":"opacity-0")}),t]},t))})]})]})})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(a.Label,{children:"Week Starts On"}),e.jsx(a.RadioGroup,{value:String(N),onValueChange:t=>{d(!0),C(Number(t))},className:"flex gap-4",disabled:m,children:M.map(t=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(a.RadioGroupItem,{value:String(t.value),id:`week-start-${t.value}`,disabled:m}),e.jsx(a.Label,{htmlFor:`week-start-${t.value}`,className:a.cn("cursor-pointer font-normal",m&&"cursor-not-allowed"),children:t.label})]},t.value))})]})]})]}),e.jsxs(a.DialogFooter,{children:[e.jsx(a.Button,{variant:"outline",onClick:$,disabled:D,children:"Cancel"}),e.jsx(a.Button,{onClick:_,disabled:O,children:D?e.jsxs(e.Fragment,{children:[e.jsx(a.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):"Save"})]})]})})}const k=6,z=1,U=20;function Z(s){return Number.isNaN(s)?k:Math.min(U,Math.max(z,s))}function J({open:s,onOpenChange:r,dashboard:i,onApply:S,disabled:x=!1}){const[v,j]=l.useState(!1),[b,p]=l.useState("top"),[u,m]=l.useState(String(k)),n=i.summary;l.useEffect(()=>{s&&(j((n==null?void 0:n.enabled)===!0),p((n==null?void 0:n.position)==="bottom"?"bottom":"top"),m(String((n==null?void 0:n.maxItems)??k)))},[s,n==null?void 0:n.enabled,n==null?void 0:n.position,n==null?void 0:n.maxItems]);const g=l.useMemo(()=>Z(Number.parseInt(u||`${k}`,10)),[u]),d=()=>{S({enabled:v,position:b,maxItems:g}),r(!1)};return e.jsx(a.Dialog,{open:s,onOpenChange:r,children:e.jsxs(a.DialogContent,{className:"sm:max-w-[420px]",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Summary Settings"}),e.jsx(a.DialogDescription,{children:"Configure dashboard-level summary display. Card-level summary settings still control which cards contribute."})]}),e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{htmlFor:"dashboard-summary-enabled",children:"Enable Dashboard Summary"}),e.jsx(a.SmallSwitch,{id:"dashboard-summary-enabled",checked:v,disabled:x,onCheckedChange:j})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:"dashboard-summary-position",children:"Position"}),e.jsxs(a.Select,{value:b,disabled:x,onValueChange:f=>p(f),children:[e.jsx(a.SelectTrigger,{id:"dashboard-summary-position",children:e.jsx(a.SelectValue,{placeholder:"Select position"})}),e.jsxs(a.SelectContent,{children:[e.jsx(a.SelectItem,{value:"top",children:"Top"}),e.jsx(a.SelectItem,{value:"bottom",children:"Bottom"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:"dashboard-summary-max-items",children:"Max Items"}),e.jsx(a.Input,{id:"dashboard-summary-max-items",type:"number",min:z,max:U,disabled:x,value:u,onChange:f=>m(f.target.value),onBlur:()=>m(String(g))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Display limit only. Computation is unchanged."})]}),x&&e.jsx("p",{className:"text-xs text-amber-700",children:"Enter dashboard edit mode to modify summary settings."})]}),e.jsxs(a.DialogFooter,{children:[e.jsx(a.Button,{variant:"outline",onClick:()=>r(!1),children:"Cancel"}),e.jsx(a.Button,{onClick:d,disabled:x,children:"Apply"})]})]})})}exports.CalendarPreferencesDialog=q;exports.DashboardSummarySettingsDialog=J;
1
+ "use strict";const e=require("react/jsx-runtime"),l=require("react"),a=require("./index-BfiIPyeS.js");function W(){var N,C,T,y;const{authToken:s,tokenProps:r}=a.useSemaphorContext(),[i,S]=l.useState(!1),[x,v]=l.useState(!1),[j,b]=l.useState(!1),[p,u]=l.useState(null),[m,n]=l.useState(null),g=m||{tz:((C=(N=r==null?void 0:r.params)==null?void 0:N.calendarContext)==null?void 0:C.tz)||null,weekStart:((y=(T=r==null?void 0:r.params)==null?void 0:T.calendarContext)==null?void 0:y.weekStart)??null},d=l.useCallback(async()=>{if(!(!(s!=null&&s.accessToken)||!(r!=null&&r.apiServiceUrl))){S(!0),u(null);try{const c=await fetch(`${r.apiServiceUrl}/v1/user-preferences/calendar`,{method:"GET",headers:{Authorization:`Bearer ${s.accessToken}`}});if(!c.ok){const h=await c.json().catch(()=>({}));throw new Error(h.error||"Failed to fetch preferences")}const o=await c.json();n({tz:o.tz,weekStart:o.weekStart,source:o.source,isInherited:o.isInherited,userHasPrefs:o.userHasPrefs,inherited:o.inherited})}catch(c){const o=c instanceof Error?c.message:"Unknown error";u(o)}finally{S(!1)}}},[s,r]);l.useEffect(()=>{d()},[d]);const f=l.useCallback(async c=>{if(!(s!=null&&s.accessToken)||!(r!=null&&r.apiServiceUrl))return u("Not authenticated"),!1;v(!0),u(null);try{const o=await fetch(`${r.apiServiceUrl}/v1/user-preferences/calendar`,{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s.accessToken}`},body:JSON.stringify(c)});if(!o.ok){const h=await o.json().catch(()=>({}));throw new Error(h.error||"Failed to update preferences")}return await d(),!0}catch(o){const h=o instanceof Error?o.message:"Unknown error";return u(h),!1}finally{v(!1)}},[s,r,d]),w=l.useCallback(async()=>{if(!(s!=null&&s.accessToken)||!(r!=null&&r.apiServiceUrl))return u("Not authenticated"),!1;b(!0),u(null);try{const c=await fetch(`${r.apiServiceUrl}/v1/user-preferences/calendar`,{method:"DELETE",headers:{Authorization:`Bearer ${s.accessToken}`}});if(!c.ok){const h=await c.json().catch(()=>({}));throw new Error(h.error||"Failed to clear preferences")}const o=await c.text();if(o)try{const h=JSON.parse(o);return n({tz:h.tz,weekStart:h.weekStart,source:h.source,isInherited:h.isInherited??!0,userHasPrefs:!1,inherited:h.inherited}),!0}catch{}return await d(),!0}catch(c){const o=c instanceof Error?c.message:"Unknown error";return u(o),!1}finally{b(!1)}},[s,r,d]);return{preferences:g,isLoading:i,isSaving:x,isClearing:j,error:p,updatePreferences:f,clearPreferences:w,refetch:d}}const I=[{value:"America/New_York",label:"Eastern Time (US & Canada)"},{value:"America/Chicago",label:"Central Time (US & Canada)"},{value:"America/Denver",label:"Mountain Time (US & Canada)"},{value:"America/Los_Angeles",label:"Pacific Time (US & Canada)"},{value:"America/Phoenix",label:"Arizona"},{value:"America/Anchorage",label:"Alaska"},{value:"Pacific/Honolulu",label:"Hawaii"},{value:"Europe/London",label:"London"},{value:"Europe/Paris",label:"Paris, Berlin, Rome"},{value:"Asia/Tokyo",label:"Tokyo"},{value:"Asia/Shanghai",label:"Beijing, Shanghai"},{value:"Asia/Kolkata",label:"Mumbai, New Delhi"},{value:"Australia/Sydney",label:"Sydney"},{value:"UTC",label:"UTC"}],M=[{value:0,label:"Sunday"},{value:1,label:"Monday"},{value:6,label:"Saturday"}];function G(){try{const s=Intl;if(s.supportedValuesOf)return s.supportedValuesOf("timeZone")}catch{}return I.map(s=>s.value)}function V(s){switch(s){case"tenant":return"tenant";case"organization":return"organization";case"system":return"system";default:return"default"}}function L(s){const r=I.find(i=>i.value===s);return r?r.label:s}function X(s){const r=M.find(i=>i.value===s);return r?r.label:String(s)}function q({open:s,onOpenChange:r}){var E,P,A;const{preferences:i,isLoading:S,isSaving:x,isClearing:v,updatePreferences:j,clearPreferences:b}=W(),p=i.tz||((E=i.inherited)==null?void 0:E.tz)||Intl.DateTimeFormat().resolvedOptions().timeZone,u=i.weekStart??((P=i.inherited)==null?void 0:P.weekStart)??1,[m,n]=l.useState(!i.userHasPrefs),[g,d]=l.useState(!1),[f,w]=l.useState(p),[N,C]=l.useState(u),[T,y]=l.useState(!1),c=l.useMemo(()=>G(),[]),o=l.useMemo(()=>c.filter(t=>!I.some(R=>R.value===t)),[c]),h=l.useMemo(()=>L(f),[f]),F=i.inherited?L(i.inherited.tz):"UTC",H=i.inherited?X(i.inherited.weekStart):"Monday",B=V((A=i.inherited)==null?void 0:A.source);l.useEffect(()=>{if(!s){d(!1);return}g||(i.userHasPrefs!==void 0&&n(!i.userHasPrefs),w(p),C(u))},[s,g,i.userHasPrefs,p,u]);const _=async()=>{if(S){a.ue.error("Preferences are still loading. Please try again.");return}m?await b()?(a.ue.success("Now using default settings. Please refresh the page to apply changes.",{duration:5e3}),r(!1)):a.ue.error("Failed to save preferences. Please try again."):await j({tz:f,weekStart:N})?(a.ue.success("Preferences saved. Please refresh the page to apply changes.",{duration:5e3}),r(!1)):a.ue.error("Failed to save preferences. Please try again.")},$=()=>{r(!1)},D=x||v,O=D||S;return e.jsx(a.Dialog,{open:s,onOpenChange:r,children:e.jsxs(a.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Calendar Preferences"}),e.jsx(a.DialogDescription,{children:"Set your timezone and week start preferences for date calculations and displays."})]}),e.jsxs("div",{className:"space-y-6 py-4",children:[e.jsxs(a.RadioGroup,{value:m?"defaults":"custom",onValueChange:t=>{d(!0),n(t==="defaults")},className:"space-y-3",children:[e.jsxs("div",{className:a.cn("flex items-start space-x-3 rounded-lg border p-4 cursor-pointer transition-colors",m?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"),onClick:()=>{d(!0),n(!0)},children:[e.jsx(a.RadioGroupItem,{value:"defaults",id:"mode-defaults"}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsxs(a.Label,{htmlFor:"mode-defaults",className:"cursor-pointer font-medium",children:["Use ",B," defaults"]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[F,", Week starts ",H]})]})]}),e.jsxs("div",{className:a.cn("flex items-start space-x-3 rounded-lg border p-4 cursor-pointer transition-colors",m?"border-border hover:border-muted-foreground/50":"border-primary bg-primary/5"),onClick:()=>{d(!0),n(!1)},children:[e.jsx(a.RadioGroupItem,{value:"custom",id:"mode-custom"}),e.jsx(a.Label,{htmlFor:"mode-custom",className:"cursor-pointer font-medium",children:"Use custom settings"})]})]}),e.jsxs("div",{className:a.cn("space-y-6 transition-opacity",m&&"opacity-50 pointer-events-none"),children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{children:"Timezone"}),e.jsxs(a.Popover,{open:T,onOpenChange:y,modal:!0,children:[e.jsx(a.PopoverTrigger,{asChild:!0,children:e.jsxs(a.Button,{variant:"outline",role:"combobox","aria-expanded":T,className:"w-full justify-between",disabled:m,children:[h,e.jsx(a.ChevronsUpDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(a.PopoverContent,{className:"z-50 w-[--radix-popover-trigger-width] p-0",align:"start",children:e.jsxs(a.Command,{className:"overflow-visible",children:[e.jsx(a.CommandInput,{placeholder:"Search timezones..."}),e.jsxs(a.CommandList,{children:[e.jsx(a.CommandEmpty,{children:"No timezone found."}),e.jsx(a.CommandGroup,{heading:"Common",children:I.map(t=>e.jsxs(a.CommandItem,{value:`${t.value} ${t.label}`,onSelect:()=>{d(!0),w(t.value),y(!1)},children:[e.jsx(a.Check,{className:a.cn("mr-2 h-4 w-4",f===t.value?"opacity-100":"opacity-0")}),e.jsx("span",{className:"flex-1",children:t.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:t.value})]},t.value))}),e.jsx(a.CommandSeparator,{}),e.jsx(a.CommandGroup,{heading:"All Timezones",children:o.map(t=>e.jsxs(a.CommandItem,{value:t,onSelect:()=>{d(!0),w(t),y(!1)},children:[e.jsx(a.Check,{className:a.cn("mr-2 h-4 w-4",f===t?"opacity-100":"opacity-0")}),t]},t))})]})]})})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(a.Label,{children:"Week Starts On"}),e.jsx(a.RadioGroup,{value:String(N),onValueChange:t=>{d(!0),C(Number(t))},className:"flex gap-4",disabled:m,children:M.map(t=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(a.RadioGroupItem,{value:String(t.value),id:`week-start-${t.value}`,disabled:m}),e.jsx(a.Label,{htmlFor:`week-start-${t.value}`,className:a.cn("cursor-pointer font-normal",m&&"cursor-not-allowed"),children:t.label})]},t.value))})]})]})]}),e.jsxs(a.DialogFooter,{children:[e.jsx(a.Button,{variant:"outline",onClick:$,disabled:D,children:"Cancel"}),e.jsx(a.Button,{onClick:_,disabled:O,children:D?e.jsxs(e.Fragment,{children:[e.jsx(a.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):"Save"})]})]})})}const k=6,z=1,U=20;function Z(s){return Number.isNaN(s)?k:Math.min(U,Math.max(z,s))}function J({open:s,onOpenChange:r,dashboard:i,onApply:S,disabled:x=!1}){const[v,j]=l.useState(!1),[b,p]=l.useState("top"),[u,m]=l.useState(String(k)),n=i.summary;l.useEffect(()=>{s&&(j((n==null?void 0:n.enabled)===!0),p((n==null?void 0:n.position)==="bottom"?"bottom":"top"),m(String((n==null?void 0:n.maxItems)??k)))},[s,n==null?void 0:n.enabled,n==null?void 0:n.position,n==null?void 0:n.maxItems]);const g=l.useMemo(()=>Z(Number.parseInt(u||`${k}`,10)),[u]),d=()=>{S({enabled:v,position:b,maxItems:g}),r(!1)};return e.jsx(a.Dialog,{open:s,onOpenChange:r,children:e.jsxs(a.DialogContent,{className:"sm:max-w-[420px]",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Summary Settings"}),e.jsx(a.DialogDescription,{children:"Configure dashboard-level summary display. Card-level summary settings still control which cards contribute."})]}),e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{htmlFor:"dashboard-summary-enabled",children:"Enable Dashboard Summary"}),e.jsx(a.SmallSwitch,{id:"dashboard-summary-enabled",checked:v,disabled:x,onCheckedChange:j})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:"dashboard-summary-position",children:"Position"}),e.jsxs(a.Select,{value:b,disabled:x,onValueChange:f=>p(f),children:[e.jsx(a.SelectTrigger,{id:"dashboard-summary-position",children:e.jsx(a.SelectValue,{placeholder:"Select position"})}),e.jsxs(a.SelectContent,{children:[e.jsx(a.SelectItem,{value:"top",children:"Top"}),e.jsx(a.SelectItem,{value:"bottom",children:"Bottom"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:"dashboard-summary-max-items",children:"Max Items"}),e.jsx(a.Input,{id:"dashboard-summary-max-items",type:"number",min:z,max:U,disabled:x,value:u,onChange:f=>m(f.target.value),onBlur:()=>m(String(g))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Display limit only. Computation is unchanged."})]}),x&&e.jsx("p",{className:"text-xs text-amber-700",children:"Enter dashboard edit mode to modify summary settings."})]}),e.jsxs(a.DialogFooter,{children:[e.jsx(a.Button,{variant:"outline",onClick:()=>r(!1),children:"Cancel"}),e.jsx(a.Button,{onClick:d,disabled:x,children:"Apply"})]})]})})}exports.CalendarPreferencesDialog=q;exports.DashboardSummarySettingsDialog=J;