react-semaphor 0.1.100 → 0.1.102

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-B69rp7Eg.js +26 -0
  2. package/dist/chunks/{dashboard-controls-DW1JJWP7.js → dashboard-controls-BcI9OPvx.js} +599 -599
  3. package/dist/chunks/{dashboard-json-C0CKQW3d.js → dashboard-json-BJ1c04y3.js} +1 -1
  4. package/dist/chunks/{dashboard-json-BDAEIUep.js → dashboard-json-DsxHtR1h.js} +1 -1
  5. package/dist/chunks/{edit-dashboard-visual-DQzy1fUR.js → edit-dashboard-visual-C2PPgPSf.js} +30 -21
  6. package/dist/chunks/{edit-dashboard-visual-BtV3RWgf.js → edit-dashboard-visual-CRvSRhC4.js} +31 -31
  7. package/dist/chunks/{editor-action-buttons-CReBF7FV.js → editor-action-buttons-18dPoIIF.js} +1 -1
  8. package/dist/chunks/{editor-action-buttons-BJRrkj_n.js → editor-action-buttons-D74G-fOO.js} +2 -2
  9. package/dist/chunks/{index-BDtdPUUE.js → index-BYjv54tY.js} +160 -160
  10. package/dist/chunks/{index-f2IZ7tlh.js → index-DLEb3N-R.js} +7985 -7967
  11. package/dist/chunks/resource-management-panel-DToljP14.js +11 -0
  12. package/dist/chunks/resource-management-panel-k_ZQIBfh.js +924 -0
  13. package/dist/chunks/{schedule-dashboard-CfeYnMXp.js → schedule-dashboard-fjtSpUVj.js} +4 -4
  14. package/dist/chunks/schedule-dashboard-vZXqGP-q.js +6 -0
  15. package/dist/chunks/use-click-outside-B9T3lmcw.js +1 -0
  16. package/dist/chunks/use-click-outside-CMeO_QFI.js +16 -0
  17. package/dist/chunks/{use-visual-utils-CRA2-3Z2.js → use-visual-utils-Btxew3Er.js} +1 -1
  18. package/dist/chunks/{use-visual-utils-BN4h1-xa.js → use-visual-utils-CMaqO2nT.js} +1 -1
  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 +4 -4
  23. package/dist/style.css +1 -1
  24. package/dist/surfboard/index.cjs +1 -1
  25. package/dist/surfboard/index.js +1 -1
  26. package/package.json +1 -1
  27. package/dist/chunks/dashboard-controls-DKci3my0.js +0 -26
  28. package/dist/chunks/resource-management-panel-BQVERuRi.js +0 -11
  29. package/dist/chunks/resource-management-panel-DNpbhYNu.js +0 -982
  30. package/dist/chunks/schedule-dashboard-D8ctQToc.js +0 -6
  31. package/dist/chunks/use-local-storage-state-CWjTT77L.js +0 -26
  32. package/dist/chunks/use-local-storage-state-DXYWw213.js +0 -1
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../chunks/index-BDtdPUUE.js"),r=require("../types/index.cjs");exports.Surfboard=e.DashboardPlus;exports.EMPTY_SELECTION=r.EMPTY_SELECTION;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../chunks/index-BYjv54tY.js"),r=require("../types/index.cjs");exports.Surfboard=e.DashboardPlus;exports.EMPTY_SELECTION=r.EMPTY_SELECTION;
@@ -1,4 +1,4 @@
1
- import { a } from "../chunks/index-f2IZ7tlh.js";
1
+ import { a } from "../chunks/index-DLEb3N-R.js";
2
2
  import { EMPTY_SELECTION as E } from "../types/index.js";
3
3
  export {
4
4
  E as EMPTY_SELECTION,
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "email": "support@semaphor.cloud"
6
6
  },
7
7
  "license": "MIT",
8
- "version": "0.1.100",
8
+ "version": "0.1.102",
9
9
  "description": "Fully interactive and customizable dashboards for your apps.",
10
10
  "keywords": [
11
11
  "react",
@@ -1,26 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-BDtdPUUE.js"),f=require("react");require("react-dom");const O=require("./schedule-dashboard-D8ctQToc.js"),oe=require("./editor-action-buttons-CReBF7FV.js");function Me(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const r=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(n,a,r.get?r:{enumerable:!0,get:()=>t[a]})}}return n.default=t,Object.freeze(n)}const D=Me(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 Le=s.createLucideIcon("Glasses",[["circle",{cx:"6",cy:"15",r:"4",key:"vux9w4"}],["circle",{cx:"18",cy:"15",r:"4",key:"18o8ve"}],["path",{d:"M14 15a2 2 0 0 0-2-2 2 2 0 0 0-2 2",key:"1ag4bs"}],["path",{d:"M2.5 13 5 7c.7-1.3 1.4-2 3-2",key:"1hm1gs"}],["path",{d:"M21.5 13 19 7c-.7-1.3-1.5-2-3-2",key:"1r31ai"}]]);/**
7
- * @license lucide-react v0.453.0 - ISC
8
- *
9
- * This source code is licensed under the ISC license.
10
- * See the LICENSE file in the root directory of this source tree.
11
- */const ke=s.createLucideIcon("Menu",[["line",{x1:"4",x2:"20",y1:"12",y2:"12",key:"1e0a9i"}],["line",{x1:"4",x2:"20",y1:"6",y2:"6",key:"1owob3"}],["line",{x1:"4",x2:"20",y1:"18",y2:"18",key:"yk5zj1"}]]);/**
12
- * @license lucide-react v0.453.0 - ISC
13
- *
14
- * This source code is licensed under the ISC license.
15
- * See the LICENSE file in the root directory of this source tree.
16
- */const Ie=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 Pe=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 Te=s.createLucideIcon("Sun",[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m4.93 4.93 1.41 1.41",key:"149t6j"}],["path",{d:"m17.66 17.66 1.41 1.41",key:"ptbguv"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"m6.34 17.66-1.41 1.41",key:"1m8zz5"}],["path",{d:"m19.07 4.93-1.41 1.41",key:"1shlcs"}]]);var Ae=s.requireShim();function Fe(){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(Te,{strokeWidth:1.5,className:"h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0"}),e.jsx(Ie,{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 Ee(t,n,a,r,l){if(!l)return null;const c=JSON.stringify(a),i=`${t}/v1/lens`;return await s.postRequest(i,l,{name:n,template:c,filterValues:r,operation:"create"})}async function W(t,n,a){if(!a)return null;const{id:r,template:l,filterValues:c,isDefault:i,shared:u}=n,h=`${t}/v1/lens`;return await s.postRequest(h,a,{lensId:r,template:l,filterValues:c,isDefault:i,shared:u,operation:"update"})}async function Re(t,n,a){if(!a)return null;const r=`${t}/v1/lens`;return await s.postRequest(r,a,{operation:"delete",lensId:n})}function Ge(){const[t,n]=f.useState(""),[a,r]=f.useState(!1),l=s.useDashboardStore(w=>w.lenses),{setLenses:c,setSelectedLensId:i}=s.useDashboardActions(),[u,h]=f.useState(!1),[g,x]=f.useState(!1),o=s.useDashboardStore(w=>w.dashboard),m=s.useDashboardStore(w=>w.filterValues),{authToken:j,tokenProps:v}=s.useSemaphorContext();async function y(){h(!0);const w=O.getDashbaordStateWithoutData(o),C=await Ee(v.apiServiceUrl,t,w,m,j==null?void 0:j.accessToken);C&&(c([...l||[],C]),i(C.id),x(!1)),h(!1)}return e.jsxs(s.Dialog,{open:g,onOpenChange:x,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Lens"]})}),e.jsxs(s.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Create Lens"}),e.jsx(s.DialogDescription,{children:"Lenses are private by default and are only visible to you."})]}),e.jsx("div",{className:"grid gap-4 py-4",children:e.jsxs("div",{className:"grid grid-cols-8 items-center gap-4",children:[e.jsx(s.Label,{className:"text-right",children:"Name"}),e.jsx(s.Input$1,{value:t,onChange:w=>{n(w.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),a&&e.jsx("p",{className:"text-sm",children:"The lens name already exists. Use a differnet name."}),e.jsx(s.DialogFooter,{children:e.jsx(s.Button,{size:"sm",variant:"outline",type:"submit",onClick:y,disabled:u,children:u?"Creating...":"Add"})})]})]})}function Oe(){const[t,n]=f.useState(!1),a=s.useDashboardStore(o=>o.lenses),r=s.useDashboardStore(o=>o.selectedLensId),{setLenses:l,setSelectedLensId:c}=s.useDashboardActions(),{authToken:i,tokenProps:u}=s.useSemaphorContext();async function h(o){c(o)}async function g(o){if(await Re(u.apiServiceUrl,o,i==null?void 0:i.accessToken)){const j=a==null?void 0:a.filter(v=>v.id!==o);l(j||[]),c("original")}}async function x(o){const m=a==null?void 0:a.map(y=>y.id===o.id?{...y,isDefault:!o.isDefault}:{...y,isDefault:!1});l(m||[]);const j={...o,isDefault:!o.isDefault};await W(u.apiServiceUrl,j,i==null?void 0:i.accessToken);const v=a==null?void 0:a.find(y=>y.isDefault);if(v&&v.id!==o.id){const y={...v,isDefault:!1};await W(u.apiServiceUrl,y,i==null?void 0:i.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(Le,{className:"h-4 w-4"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-60",children:[e.jsx(s.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuRadioGroup,{value:r,onValueChange:h,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),a==null?void 0:a.map(o=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:o.id,children:[e.jsx("p",{children:o.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(s.House,{onClick:m=>{m.preventDefault(),x(o)},className:s.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!o.isDefault,"text-green-500":o.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:m=>{m.preventDefault(),g(o.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},o.id))]})]})]})}function Ue({iconClassName:t}){const[n,a]=f.useState(!1),[r,l]=f.useState(""),[c,i]=f.useState(!1),u=s.useDashboardStore(o=>o.isDownloadingPdf),{tokenProps:h}=s.useSemaphorContext();async function g(){const o=s.ue.loading("Generating PDF... may take up to 60 seconds");try{await s.downloadPdf(h.apiServiceUrl),s.ue.dismiss(o),s.ue.success("PDF downloaded successfully!",{duration:2e3})}catch(m){s.ue.dismiss(o),s.ue.error("Failed to download PDF",{description:"Please try again or contact support.",richColors:!0}),console.error("PDF download error:",m)}}async function x(){if(!r)return;a(!1),l(""),i(!1);const o=s.ue.loading("Generating protected PDF... may take up to 60 seconds");try{await s.downloadPdf(h.apiServiceUrl,r),s.ue.dismiss(o),s.ue.success("Protected PDF downloaded successfully!",{duration:2e3,position:"top-right"})}catch(m){s.ue.dismiss(o),s.ue.error("Failed to download protected PDF. Please try again."),console.error("Protected PDF download error:",m)}}return e.jsxs(e.Fragment,{children:[e.jsxs(s.DropdownMenu,{modal:!1,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-7 p-2",disabled:u,children:e.jsx(s.Download,{className:s.cn("size-4",t)})})}),e.jsxs(s.DropdownMenuContent,{align:"end",children:[e.jsxs(s.DropdownMenuItem,{onClick:g,children:[e.jsx(s.File,{className:"mr-2 h-4 w-4"}),"Download PDF"]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>a(!0),children:[e.jsx(s.Lock,{className:"mr-2 h-4 w-4"}),"Download Protected PDF"]})]})]}),e.jsx(s.Dialog,{open:n,onOpenChange:a,children:e.jsxs(s.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Download Protected PDF"}),e.jsx(s.DialogDescription,{children:"Enter a password to protect your PDF. The PDF will be encrypted and require this password to open."})]}),e.jsx("div",{className:"grid gap-4 py-4",children:e.jsxs("div",{className:"grid gap-2",children:[e.jsx(s.Label,{htmlFor:"password",children:"Password"}),e.jsxs("div",{className:"relative",children:[e.jsx(s.Input$1,{id:"password",type:c?"text":"password",value:r,onChange:o=>l(o.target.value),placeholder:"Enter password",className:"pr-10",onKeyDown:o=>{o.key==="Enter"&&r&&x()}}),e.jsx(s.Button,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3 py-2 hover:bg-transparent",onClick:()=>i(!c),children:c?e.jsx(s.EyeOff,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(s.Eye,{className:"h-4 w-4 text-muted-foreground"})})]})]})}),e.jsxs(s.DialogFooter,{children:[e.jsx(s.Button,{variant:"outline",onClick:()=>a(!1),children:"Cancel"}),e.jsx(s.Button,{onClick:x,disabled:!r,children:"Download"})]})]})})]})}const Be=async(t,n,a)=>{const r=`${t}/management/v1/groups`;return await s.postRequestRegular(r,n,a)},qe=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")}},$e=async(t,n,a,r)=>{const l=`${t}/management/v1/groups/${a}/members`;return await s.postRequestRegular(l,n,r)},_e=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 i=await c.text();throw new Error(i||"Failed to remove group members")}};function ze(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:r=>Be(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r),onSuccess:()=>{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 Qe(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:r=>qe(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 He(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:l})=>$e(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 Ve(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:l})=>_e(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 Ke({onSuccess:t,tenantId:n,isTenantUser:a}){const[r,l]=f.useState(""),[c,i]=f.useState(""),[u,h]=f.useState({}),g=ze(),x=()=>{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"),h(m),Object.keys(m).length===0},o=async m=>{if(m.preventDefault(),!x())return;const j={name:r.trim(),description:c.trim()||void 0,type:a?"TENANT_GROUP":"ORG_GROUP",...a&&n?{tenantId:n}:{}};try{await g.mutateAsync(j),l(""),i(""),h({}),t()}catch(v){console.error("Failed to create group:",v)}};return e.jsxs("form",{onSubmit:o,className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(s.Label,{htmlFor:"group-name",children:["Group Name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(s.Input$1,{id:"group-name",placeholder:"e.g., Marketing Team, Engineering Squad",value:r,onChange:m=>{l(m.target.value),u.name&&h(j=>({...j,name:""}))},className:u.name?"border-destructive":"",disabled:g.isPending}),u.name&&e.jsx("p",{className:"text-sm text-destructive",children:u.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=>{i(m.target.value),u.description&&h(j=>({...j,description:""}))},className:u.description?"border-destructive":"",disabled:g.isPending,rows:3}),u.description&&e.jsx("p",{className:"text-sm text-destructive",children:u.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(""),i(""),h({})},disabled:g.isPending,children:"Clear"}),e.jsx(s.Button,{type:"submit",disabled:g.isPending||!r.trim(),children:g.isPending?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Creating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(s.Users,{className:"mr-2 h-4 w-4"}),"Create Group"]})})]})]})}function We(t,n=[]){let a=[];function r(c,i){const u=D.createContext(i),h=a.length;a=[...a,i];const g=o=>{var C;const{scope:m,children:j,...v}=o,y=((C=m==null?void 0:m[t])==null?void 0:C[h])||u,w=D.useMemo(()=>v,Object.values(v));return e.jsx(y.Provider,{value:w,children:j})};g.displayName=c+"Provider";function x(o,m){var y;const j=((y=m==null?void 0:m[t])==null?void 0:y[h])||u,v=D.useContext(j);if(v)return v;if(i!==void 0)return i;throw new Error(`\`${o}\` must be used within \`${c}\``)}return[g,x]}const l=()=>{const c=a.map(i=>D.createContext(i));return function(u){const h=(u==null?void 0:u[t])||c;return D.useMemo(()=>({[`__scope${t}`]:{...u,[t]:h}}),[u,h])}};return l.scopeName=t,[r,Je(l,...n)]}function Je(...t){const n=t[0];if(t.length===1)return n;const a=()=>{const r=t.map(l=>({useScope:l(),scopeName:l.scopeName}));return function(c){const i=r.reduce((u,{useScope:h,scopeName:g})=>{const o=h(c)[`__scope${g}`];return{...u,...o}},{});return D.useMemo(()=>({[`__scope${n.scopeName}`]:i}),[i])}};return a.scopeName=n.scopeName,a}function Xe(t){const n=D.useRef(t);return D.useEffect(()=>{n.current=t}),D.useMemo(()=>(...a)=>{var r;return(r=n.current)==null?void 0:r.call(n,...a)},[])}var J=globalThis!=null&&globalThis.document?D.useLayoutEffect:()=>{},Ye=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],X=Ye.reduce((t,n)=>{const a=s.createSlot(`Primitive.${n}`),r=D.forwardRef((l,c)=>{const{asChild:i,...u}=l,h=i?a:n;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(h,{...u,ref:c})});return r.displayName=`Primitive.${n}`,{...t,[n]:r}},{});function Ze(){return Ae.useSyncExternalStore(es,()=>!0,()=>!1)}function es(){return()=>{}}var Y="Avatar",[ss]=We(Y),[ts,le]=ss(Y),ce=D.forwardRef((t,n)=>{const{__scopeAvatar:a,...r}=t,[l,c]=D.useState("idle");return e.jsx(ts,{scope:a,imageLoadingStatus:l,onImageLoadingStatusChange:c,children:e.jsx(X.span,{...r,ref:n})})});ce.displayName=Y;var de="AvatarImage",ue=D.forwardRef((t,n)=>{const{__scopeAvatar:a,src:r,onLoadingStatusChange:l=()=>{},...c}=t,i=le(de,a),u=as(r,c),h=Xe(g=>{l(g),i.onImageLoadingStatusChange(g)});return J(()=>{u!=="idle"&&h(u)},[u,h]),u==="loaded"?e.jsx(X.img,{...c,ref:n,src:r}):null});ue.displayName=de;var me="AvatarFallback",he=D.forwardRef((t,n)=>{const{__scopeAvatar:a,delayMs:r,...l}=t,c=le(me,a),[i,u]=D.useState(r===void 0);return D.useEffect(()=>{if(r!==void 0){const h=window.setTimeout(()=>u(!0),r);return()=>window.clearTimeout(h)}},[r]),i&&c.imageLoadingStatus!=="loaded"?e.jsx(X.span,{...l,ref:n}):null});he.displayName=me;function ie(t,n){return t?n?(t.src!==n&&(t.src=n),t.complete&&t.naturalWidth>0?"loaded":"loading"):"error":"idle"}function as(t,{referrerPolicy:n,crossOrigin:a}){const r=Ze(),l=D.useRef(null),c=r?(l.current||(l.current=new window.Image),l.current):null,[i,u]=D.useState(()=>ie(c,t));return J(()=>{u(ie(c,t))},[c,t]),J(()=>{const h=o=>()=>{u(o)};if(!c)return;const g=h("loaded"),x=h("error");return c.addEventListener("load",g),c.addEventListener("error",x),n&&(c.referrerPolicy=n),typeof a=="string"&&(c.crossOrigin=a),()=>{c.removeEventListener("load",g),c.removeEventListener("error",x)}},[c,a,n]),i}var pe=ce,xe=ue,ge=he;const Z=D.forwardRef(({className:t,...n},a)=>e.jsx(pe,{ref:a,className:s.cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",t),...n}));Z.displayName=pe.displayName;const rs=D.forwardRef(({className:t,...n},a)=>e.jsx(xe,{ref:a,className:s.cn("aspect-square h-full w-full",t),...n}));rs.displayName=xe.displayName;const ee=D.forwardRef(({className:t,...n},a)=>e.jsx(ge,{ref:a,className:s.cn("flex h-full w-full items-center justify-center rounded-full bg-muted",t),...n}));ee.displayName=ge.displayName;function ns({open:t,onOpenChange:n,group:a,onUpdate:r}){const[l,c]=f.useState("members"),[i,u]=f.useState(""),[h,g]=f.useState([]),[x,o]=f.useState([]),{data:m,isLoading:j,refetch:v}=s.useGroupMembers(a.id),y=a.type==="TENANT_GROUP"?"tenant":"organization",{users:w,isLoading:C}=s.useUnifiedUsers({type:y,tenantId:a.tenantId||void 0,active:!0,limit:100}),A=He(),I=Ve(),M=(m==null?void 0:m.members)||[],E=f.useMemo(()=>new Set(M.map(p=>p.userId)),[M]),F=f.useMemo(()=>w.filter(p=>!E.has(p.id)),[w,E]),N=f.useMemo(()=>{if(!i)return F;const p=i.toLowerCase();return F.filter(S=>{var L,T;return((L=S.name)==null?void 0:L.toLowerCase().includes(p))||((T=S.email)==null?void 0:T.toLowerCase().includes(p))})},[F,i]),b=f.useMemo(()=>{if(!i)return M;const p=i.toLowerCase();return M.filter(S=>{var L,T,B,$;return((T=(L=S.user)==null?void 0:L.name)==null?void 0:T.toLowerCase().includes(p))||(($=(B=S.user)==null?void 0:B.email)==null?void 0:$.toLowerCase().includes(p))})},[M,i]),P=async()=>{if(h.length!==0)try{await A.mutateAsync({groupId:a.id,data:{userIds:h,userType:y==="tenant"?"tenant":"org"}}),g([]),c("members"),v(),r==null||r()}catch(p){console.error("Failed to add members:",p)}},U=async()=>{if(x.length!==0)try{await I.mutateAsync({groupId:a.id,data:{userIds:x}}),o([]),v(),r==null||r()}catch(p){console.error("Failed to remove members:",p)}},Q=p=>{g(S=>S.includes(p)?S.filter(L=>L!==p):[...S,p])},H=p=>{o(S=>S.includes(p)?S.filter(L=>L!==p):[...S,p])};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:l,onValueChange:p=>{c(p),u(""),o([])},className:"mt-4",children:[e.jsxs(s.TabsList,{className:"grid w-full grid-cols-2",children:[e.jsx(s.TabsTrigger,{value:"members",children:"Current Members"}),e.jsx(s.TabsTrigger,{value:"add",children:"Add Members"})]}),e.jsxs(s.TabsContent,{value:"members",className:"mt-4 space-y-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(s.Search,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(s.Input$1,{placeholder:"Search members...",value:i,onChange:p=>u(p.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:x.length>0?"h-[300px]":"h-[350px]",children:j?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(p=>e.jsx(s.Skeleton,{className:"h-16 w-full"},p))}):b.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:i?"No members found":"No members yet"}),e.jsx("p",{className:"text-xs mt-1",children:i?"Try a different search":'Switch to the "Add Members" tab to add people to this group'})]}):e.jsx("div",{className:"space-y-2",children:b.map(p=>e.jsx(os,{member:p,selected:x.includes(p.userId),onToggle:()=>H(p.userId)},p.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," member",x.length!==1?"s":""," selected"]}),e.jsx(s.Button,{variant:"destructive",size:"sm",onClick:U,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$1,{placeholder:"Search users to add...",value:i,onChange:p=>u(p.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(p=>e.jsx(s.Skeleton,{className:"h-16 w-full"},p))}):N.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:i?"Try a different search":"All eligible users are already members"})]}):e.jsx("div",{className:"space-y-2",children:N.map(p=>e.jsx(is,{user:p,selected:h.includes(p.id),onToggle:()=>Q(p.id)},p.id))})}),h.length>0&&e.jsxs("div",{className:"flex items-center justify-between pt-4 border-t",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[h.length," user",h.length!==1?"s":""," selected"]}),e.jsx(s.Button,{onClick:P,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 os({member:t,selected:n,onToggle:a}){var l,c,i,u;const r=((c=(l=t.user)==null?void 0:l.name)==null?void 0:c.split(" ").map(h=>h[0]).join("").toUpperCase())||"?";return e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg border bg-card hover:bg-muted/50 cursor-pointer",onClick:a,children:[e.jsx(s.Checkbox,{checked:n}),e.jsx(Z,{className:"h-8 w-8",children:e.jsx(ee,{className:"text-xs",children:r})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:((i=t.user)==null?void 0:i.name)||"Unknown User"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(u=t.user)==null?void 0:u.email})]})]})}function is({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(Z,{className:"h-8 w-8",children:e.jsx(ee,{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 ls({open:t,onOpenChange:n}){const[a,r]=f.useState("groups"),[l,c]=f.useState(""),[i,u]=f.useState(null),[h,g]=f.useState(!1),[x,o]=f.useState(null),{tokenProps:m}=s.useSemaphorContext(),{currentUser:j}=s.useCurrentUserInfo(),v=Qe(),y=(j==null?void 0:j.type)==="tenant",w=m==null?void 0:m.tenantId,{groups:C,isLoading:A,refetch:I}=s.useGroups({type:y?"TENANT_GROUP":"all",tenantId:y?w:void 0,includeMembers:!1}),M=C.filter(b=>{var P;return b.name.toLowerCase().includes(l.toLowerCase())||((P=b.description)==null?void 0:P.toLowerCase().includes(l.toLowerCase()))}),E=async()=>{if(x)try{await v.mutateAsync(x.id),o(null),I()}catch(b){console.error("Failed to delete group:",b)}},F=b=>{u(b),g(!0)},N=()=>{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$1,{placeholder:"Search groups...",value:l,onChange:b=>c(b.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(b=>e.jsx(s.Skeleton,{className:"h-24 w-full"},b))}):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:l?"Try a different search":"Create your first group to get started"})]}):e.jsx("div",{className:"space-y-3",children:M.map(b=>e.jsx(cs,{group:b,onManageMembers:()=>F(b),onDelete:()=>o(b),currentUserId:j==null?void 0:j.id},b.id))})})]})}),e.jsx(s.TabsContent,{value:"create",className:"mt-4",children:e.jsx(Ke,{onSuccess:N,tenantId:w,isTenantUser:y})})]})]})}),i&&e.jsx(ns,{open:h,onOpenChange:g,group:i,onUpdate:()=>I()}),e.jsx(s.AlertDialog,{open:!!x,onOpenChange:()=>o(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 "',x==null?void 0:x.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:E,disabled:v.isPending,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:v.isPending?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Deleting..."]}):"Delete Group"})]})]})})]})}function cs({group:t,onManageMembers:n,onDelete:a,currentUserId:r}){const 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 ",s.format(new Date(t.createdAt),"MMM d, yyyy")]})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:n,title:"Manage members",children:e.jsx(s.UserPlus,{className:"h-4 w-4"})}),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 ds(){var ae,re,ne;const{authToken:t,tokenProps:n,id:a}=s.useSemaphorContext(),{isLocalDev:r,isConsoleMode:l}=s.useDashboardPreferences(),{permissions:c}=s.useRoleAwareDisplayPreferences(),i=s.useHasDashboardId(),{isLoading:u}=s.useDashboardQuery();s.useDashboardStore(d=>d.theme);const h=s.useDashboardStore(d=>d.lenses),g=s.useDashboardStore(d=>d.selectedLensId),x=h==null?void 0:h.find(d=>d.id===g),o=s.useDashboardStore(d=>d.dashboard);s.useDashboardStore(d=>d.selectedSheetId);const m=s.useDashboardStore(d=>d.isDashboardEditing),{setDashboardTitle:j}=s.useDashboardStore(d=>d.actions),[v,y]=f.useState(!1),[w,C]=f.useState(!1),[A,I]=f.useState(!1),M=s.useDashboardStore(d=>d.isDashboardPanelOpen),E=s.useDashboardStore(d=>d.actions.setIsDashboardPanelOpen),F=s.useDashboardStore(d=>d.filterValues),N=s.useDashboardStore(d=>d.isVisualEditing);s.useEditorStore(d=>d.card);const b=s.useManagementStore(d=>d.selectedDashboard),P=s.useManagementStore(d=>d.initialDashboard);s.useManagementStore(d=>d.selectedVisual),s.useDashboardStore(d=>d.selectedFrameId),s.useEditorStore(d=>d.frame);const U=b?(re=b==null?void 0:b.permissions)==null?void 0:re.canEdit:(ae=P==null?void 0:P.permissions)==null?void 0:ae.canEdit,Q=s.useDashboardStore(d=>d.showFilters),H=s.useDashboardStore(d=>d.showDashboardJSON),p=s.useDashboardStore(d=>d.onSaveFunction),S=s.useDashboardStore(d=>d.actions.setShowFilters),{setIsDashboardEditing:L,setShowDashboardJSON:T}=s.useDashboardStore(d=>d.actions),{setInitialDashboard:B,clearSelectedDashboard:$}=s.useManagementStore(d=>d.actions),{resources:R}=s.useResourceManagement(s.ResourceType.DASHBOARD),{currentUser:fe}=s.useCurrentUserInfo(),je=s.canUserManageGroups(fe),G=b||P,se=G?{id:G.id,title:(o==null?void 0:o.title)||G.title||"Dashboard"}:null,{handleAddNewFrame:be}=s.useAddNewFrame(),[V,K]=f.useState(!1),_=s.useUpdateResource(s.ResourceType.DASHBOARD),ve=async(d,k)=>{if(!(o!=null&&o.id)){console.log("No dashboard ID found");return}console.log("Updating dashboard title:",{dashboardId:o.id,newTitle:d,previousTitle:k}),_.mutate({resourceId:o.id,data:{title:d}},{onSuccess:()=>{console.log("Dashboard title updated successfully"),s.ue.success("Dashboard title updated")},onError:q=>{console.error("Failed to update dashboard title:",q),s.ue.error("Failed to update dashboard title"),j(k)}})};f.useEffect(()=>{if(R&&R.length>0){const d=o==null?void 0:o.id;if(d){const k=R.find(q=>q.id===d);k&&B(k)}}},[R,o==null?void 0:o.id,B]);const z=n.orgUserId||n.tenantId,ye=m&&!N&&z&&U,Ne=()=>{L(!0)};async function De(){const d=O.getDashbaordStateWithoutData(o);K(!0);const k={template:d};_.mutate({resourceId:d.id,data:k},{onSuccess:()=>{K(!1),s.ue.success("Dashboard saved!")},onError:()=>{K(!1),s.ue.error("Failed to save dashboard")}})}async function we(){if(y(!0),!g||!x)return;const d=O.getDashbaordStateWithoutData(o),k=JSON.stringify(d),q={...x,template:k,filterValues:F};await W(n.apiServiceUrl,q,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),p==null||p(d),y(!1)}const te=(x==null?void 0:x.name)||o.title;_.isPending&&console.log("Title during update:",{title:te,dashboardStateTitle:o.title,dashboardId:o==null?void 0:o.id,currentLensName:x==null?void 0:x.name});const Se=R&&R.length>0&&(n.orgUserId||n.tenantId&&n.endUserId&&n.endUserEmail),Ce=b&&!(n!=null&&n.dashboard_id)&&!a;return e.jsxs("div",{className:"flex h-11 items-center justify-between gap-2 border-b px-4 py-2",role:"dashboard-controls",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[Se&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{"aria-label":"Manage Dashboards",tooltip:"Manage Dashboards",onClick:()=>{E(!M)},className:"h-7 p-2",children:e.jsx(ke,{className:"h-4 w-4"})}),Ce&&!N&&e.jsx(s.IconButton,{"aria-label":"Dashboard Hub",tooltip:"Dashboard Hub",onClick:()=>$(),className:"h-7 p-2",children:e.jsx(s.House,{className:"h-4 w-4"})})]}),!N&&i&&(u?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.LoaderCircle,{className:"h-3 w-3 animate-spin text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Loading..."})]}):e.jsx(s.EditableText,{value:te||"Untitled Dashboard",onSave:d=>{console.log("EditableText onSave called:",{newTitle:d,canEditDashboard:U,dashboardId:o==null?void 0:o.id});const k=(o==null?void 0:o.title)||"";j(d),ve(d,k)},isEditable:U&&!x,displayClassName:"text-sm font-medium",inputClassName:"text-sm font-medium",placeholder:"Dashboard Title",isPending:_.isPending}))]}),e.jsxs("div",{className:"flex items-center gap-2",children:[N&&e.jsxs(e.Fragment,{children:[e.jsx(O.AdvancedModeToggle,{className:"mr-2"}),e.jsx(O.VisualEditingControls,{className:"h-7"})]}),r&&!N&&e.jsx(s.IconButton,{tooltip:"Invalidate Token",onClick:()=>s.invalidateToken(n.apiServiceUrl),className:"h-7 p-2",children:e.jsx(Pe,{className:"h-4 w-4"})}),!N&&i&&e.jsx(Ue,{}),!N&&i&&e.jsx(O.ScheduleDashboard,{}),!N&&i&&je&&e.jsx(s.IconButton,{tooltip:"Manage Groups",onClick:()=>I(!0),className:"h-7 p-2",children:e.jsx(s.Users,{className:"h-4 w-4"})}),!N&&i&&((ne=G==null?void 0:G.permissions)==null?void 0:ne.canShare)&&e.jsx(s.IconButton,{tooltip:"Share Dashboard",onClick:()=>C(!0),className:"h-7 p-2",children:e.jsx(s.Share2,{className:"h-4 w-4"})}),!Q&&!N&&m&&c.canUseFilters&&i&&e.jsx(s.Button,{className:"h-7 p-2",variant:"outline",onClick:()=>S(!0),size:"sm",children:e.jsx(s.Filter,{className:"h-4 w-4"})}),m&&!N&&z&&r&&i&&e.jsx(Ge,{}),!N&&z&&r&&i&&e.jsx(Oe,{}),m&&!N&&z&&x&&r&&i&&e.jsxs(s.Button,{className:"h-7 p-2",variant:"secondary",disabled:v,onClick:we,size:"sm",children:[e.jsx(oe.Save,{className:"mr-2 h-4 w-4"}),"Save Lens"]}),m&&!N&&i&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",size:"sm",disabled:!m,onClick:()=>be(),children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Visual"]}),!N&&!m&&c.canEdit&&i&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",onClick:Ne,size:"sm",children:[e.jsx(s.Pencil,{className:"mr-2 h-4 w-4"}),"Edit"]}),ye&&i&&e.jsxs(s.Button,{className:"h-7 p-2",disabled:V,onClick:De,size:"sm",children:[V?e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(oe.Save,{className:"mr-2 h-4 w-4"}),V?"Saving...":"Save"]}),!N&&m&&r&&i&&e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(s.Button,{className:"h-7 p-2",onClick:()=>T(!H),size:"sm",variant:"ghost",children:e.jsx(s.Code,{className:"h-4 w-4"})})}),!N&&r&&e.jsx(Fe,{}),m&&!N&&i&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",onClick:()=>{L(!1),T(!1)},children:[e.jsx(s.Cross2Icon,{className:"mr-2 h-4 w-4"}),"Close"]}),w&&se&&e.jsx(s.ShareDialog,{resource:se,resourceType:s.ResourceType.DASHBOARD,onClose:()=>C(!1)}),e.jsx(ls,{open:A,onOpenChange:I})]})]})}exports.default=ds;
@@ -1,11 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-BDtdPUUE.js"),h=require("react"),ge=require("./use-visual-utils-BN4h1-xa.js"),ue=require("./use-local-storage-state-DXYWw213.js");/**
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 fe=s.createLucideIcon("FolderOpen",[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]]);/**
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 je=s.createLucideIcon("PanelLeft",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]]);function he(){return e.jsx(s.ScrollArea,{className:"w-full flex-1",children:e.jsxs("div",{className:"space-y-4 px-4 py-2",children:[e.jsx("div",{className:"h-9 w-full rounded bg-muted animate-pulse"}),e.jsx("div",{className:"h-9 w-full rounded bg-muted animate-pulse"}),e.jsx("div",{className:"space-y-3 pt-2",children:[...Array(3)].map((t,x)=>e.jsxs("div",{className:"flex gap-3 animate-pulse",children:[e.jsx("div",{className:"h-8 w-8 rounded bg-muted flex-shrink-0"}),e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("div",{className:"h-4 w-2/3 rounded bg-muted"}),e.jsx("div",{className:"h-3 w-4/5 rounded bg-muted"})]})]},x))})]})})}const De=t=>{const x=s.useDashboardStore(r=>r.isVisualEditing),p=s.useDashboardStore(r=>r.selectedFrameId),d=s.useEditorStore(r=>r.frame);return!!(x&&p&&(d==null?void 0:d.visualId)===t)};function Ne({visual:t,isDeleting:x,isDuplicating:p,onAddVisual:d,onOpenVisual:r,onEditDetails:f,onDeleteClick:b,onDuplicateVisual:D,onShareVisual:y,formatDate:l}){var P,w,R,M;const{selectVisual:c}=s.useManagementActions(),S=s.useIsVisualSelected(t.id),j=De(t.id),{isConsoleMode:T}=s.useDashboardPreferences(),i=h.useRef(null),[C,L]=h.useState(!1),[v,g]=h.useState(!1);h.useEffect(()=>{p?(L(!0),g(!0)):v&&(L(!1),g(!1))},[p,v]),h.useEffect(()=>{j&&i.current&&i.current.scrollIntoView({behavior:"smooth",block:"center"})},[j]);const N=()=>e.jsx(s.Grid3x3,{className:"h-4 w-4"}),I=()=>{c(t),r==null||r(t)};return e.jsx(s.Card,{ref:i,className:s.cn("group cursor-pointer border border-border/50 p-3 transition-colors hover:bg-accent/50",j?"border-purple-500":S&&"border-primary"),onClick:I,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5 rounded bg-muted p-1.5",children:N()}),e.jsxs("div",{className:"min-w-0 flex-1 flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground truncate",title:t.title||"Untitled Visual",children:t.title||"Untitled Visual"}),t.ownership.status==="shared"&&e.jsxs(s.Badge,{variant:"outline",className:"text-xs",children:[e.jsx(s.Users,{className:"mr-1 h-2.5 w-2.5"}),"Shared"]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2 flex-1",title:t.description||"No description",children:(P=t.description)!=null&&P.trim()?t.description:"No description"}),e.jsxs("div",{className:s.cn("invisible flex flex-shrink-0 items-center gap-1 transition-opacity duration-150 group-hover:visible",S&&"visible"),onClick:m=>m.stopPropagation(),children:[e.jsx(s.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:m=>{m.stopPropagation(),d(t)},title:"Add to dashboard",children:e.jsx(s.Plus,{className:"h-3.5 w-3.5"})}),t.ownership.isOwner&&e.jsx(s.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:m=>{m.stopPropagation(),f==null||f(t)},title:"Edit details",children:e.jsx(s.PenLine,{className:"h-3 w-3"})}),e.jsxs(s.DropdownMenu,{modal:!1,open:C,onOpenChange:L,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",children:e.jsx(s.Ellipsis,{className:"h-3 w-3"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"z-[51] w-40",children:[e.jsxs(s.DropdownMenuItem,{onClick:m=>{m.stopPropagation(),d(t)},children:[e.jsx(s.Plus,{className:"mr-2 h-3 w-3"}),"Add"]}),e.jsxs(s.DropdownMenuItem,{onClick:m=>{m.stopPropagation(),r==null||r(t)},children:[e.jsx(fe,{className:"mr-2 h-3 w-3"}),"Open"]}),e.jsxs(s.DropdownMenuItem,{onClick:m=>{m.preventDefault(),m.stopPropagation(),D(t.id)},disabled:p,children:[p?e.jsx(s.LoaderCircle,{className:"mr-2 h-3 w-3 animate-spin"}):e.jsx(s.Copy,{className:"mr-2 h-3 w-3"}),p?"Duplicating...":"Duplicate"]}),t.ownership.isOwner&&e.jsxs(e.Fragment,{children:[e.jsxs(s.DropdownMenuItem,{onClick:m=>{m.stopPropagation(),f==null||f(t)},children:[e.jsx(s.PenLine,{className:"mr-2 h-3 w-3"}),"Edit details"]}),e.jsxs(s.DropdownMenuItem,{onClick:m=>{m.stopPropagation(),y(t)},children:[e.jsx(s.Users,{className:"mr-2 h-3 w-3"}),"Share"]}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuItem,{onClick:m=>{m.stopPropagation(),b(t)},className:"text-destructive",disabled:x,children:[e.jsx(s.Trash2,{className:"mr-2 h-3 w-3"}),x?"Deleting...":"Delete"]})]}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs("div",{className:"space-y-1 px-2 py-2 text-xs text-slate-500 dark:text-slate-400",children:[(((w=t.ownership.createdBy)==null?void 0:w.type)==="tenant"||((R=t.ownership.createdBy)==null?void 0:R.type)==="organization"&&T)&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(s.User,{className:"h-3 w-3"}),e.jsx("span",{children:((M=t.ownership.createdBy)==null?void 0:M.name)||"Unknown"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(s.Calendar,{className:"h-3 w-3"}),e.jsx("span",{children:l(t.lastModified)})]})]})]})]})]})]})]})]})},t.id)}function we({open:t,onOpenChange:x,onSubmit:p,isCreating:d}){const[r,f]=h.useState(""),[b,D]=h.useState("");h.useEffect(()=>{t||(f(""),D(""))},[t]);const y=()=>{r.trim()&&p({title:r,description:b})},l=c=>{x(c)};return e.jsx(s.Dialog,{open:t,onOpenChange:l,children:e.jsxs(s.DialogContent,{children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Create New Visual"}),e.jsx(s.DialogDescription,{children:"Add a new visual to your library. You can configure it after creation."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"title",children:"Visual Title"}),e.jsx(s.Input,{id:"title",placeholder:"Enter visual title...",value:r,onChange:c=>f(c.target.value),disabled:d,onKeyDown:c=>{c.key==="Enter"&&!c.shiftKey&&(c.preventDefault(),y())}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"description",children:"Description (optional)"}),e.jsx(s.Input,{id:"description",placeholder:"Enter visual description...",value:b,onChange:c=>D(c.target.value),disabled:d})]})]}),e.jsxs(s.DialogFooter,{children:[e.jsx(s.Button,{variant:"outline",onClick:()=>l(!1),disabled:d,children:"Cancel"}),e.jsx(s.Button,{onClick:y,disabled:!r.trim()||d,children:d?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Creating..."]}):"Create Visual"})]})]})})}function ve(){const[t,x]=h.useState(""),[p,d]=h.useState(!1),[r,f]=h.useState(!1),[b,D]=h.useState(null),[y,l]=h.useState(!1),[c,S]=h.useState(null),[j,T]=h.useState(null),[i,C]=h.useState(null),{selectVisual:L}=s.useManagementActions(),{handleEditLibraryVisual:v,handleAddLibraryVisual:g}=ge.useVisualUtils(),{resources:N,isLoading:I,isError:P,createResource:w,updateResource:R,deleteResource:M,duplicateResource:m,isCreating:X,isDeleting:V}=s.useVisualManagement(()=>{l(!1),S(null)},n=>{d(!1),n&&(L(n),v(n))});s.useCurrentUserInfo();const _=N.filter(n=>{var A,o;return((A=n==null?void 0:n.title)==null?void 0:A.toLowerCase().includes(t.toLowerCase()))||((o=n==null?void 0:n.description)==null?void 0:o.toLowerCase().includes(t.toLowerCase()))}),Z=n=>new Date(n).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),$=n=>{w({title:n.title,description:n.description,isPrivate:!1})},G=n=>{S(n),l(!0)},k=()=>{c&&M(c.id)},{startUpdating:ee,stopUpdating:K,isUpdating:O}=s.useResourceUpdateState(),se=(n,A,o)=>{var J;const F=Object.fromEntries(Object.entries(A).filter(([,U])=>U!==void 0));if(Object.keys(F).length===0){(J=o==null?void 0:o.onSuccess)==null||J.call(o);return}const Y=Object.keys(F),Q=Y.length===1?Y[0]:void 0;ee(n,Q),R({resourceId:n,data:F},{onSuccess:()=>{var U;K(n,Q),(U=o==null?void 0:o.onSuccess)==null||U.call(o)},onError:()=>{var U;K(n,Q),(U=o==null?void 0:o.onError)==null||U.call(o)}})},z=n=>{T(n),m(n,{onSettled:()=>T(null)})},H=n=>{v(n)},q=n=>{g(n)},W=n=>{const A=N.find(o=>o.id===n);A&&R({resourceId:n,data:{isPrivate:!A.isPrivate}})},te=n=>{D(n),f(!0)},ae=n=>{C(n)},ne=()=>{C(null)},re=({title:n,description:A})=>{if(!i)return;const o={};n!==i.title&&(o.title=n),(i.description||"")!==A&&(o.description=A),se(i.id,o,{onSuccess:()=>{C(null)}})};return I?e.jsx(he,{}):P?e.jsx(s.ScrollArea,{className:"w-full flex-1 pr-2",children:e.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[e.jsx("p",{className:"text-sm text-destructive",children:"Failed to load visuals"}),e.jsx(s.Button,{variant:"outline",size:"sm",className:"mt-2",onClick:()=>window.location.reload(),children:"Retry"})]})}):e.jsxs("div",{className:"relative flex h-full flex-1 flex-col gap-4",children:[N&&N.length>5&&e.jsx("div",{className:"space-y-2",children:e.jsx(s.Input,{id:"search",placeholder:"Search by title or description...",value:t,onChange:n=>x(n.target.value),className:"h-9"})}),e.jsx("div",{className:"flex flex-1 flex-col",children:e.jsx("div",{className:"flex flex-1 basis-0 flex-col gap-3 overflow-y-auto",children:_.length===0?e.jsxs("div",{className:"py-8 text-center",children:[e.jsx("div",{className:"mb-3",children:e.jsx(s.Grid3x3,{className:"mx-auto h-12 w-12 text-muted-foreground/50"})}),e.jsx("h3",{className:"mb-1 font-medium text-foreground",children:t?"No visuals found":"No visuals yet"}),e.jsx("p",{className:"mb-4 text-sm text-muted-foreground",children:t?"Try adjusting your search":"Create your first visual component to get started"}),!t&&e.jsxs(s.Button,{size:"sm",className:"bg-primary hover:bg-primary/90",onClick:()=>d(!0),children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Create Visual"]})]}):_.map(n=>e.jsx(Ne,{visual:n,onAddVisual:q,onOpenVisual:H,onEditDetails:ae,onDeleteClick:G,onDuplicateVisual:z,onTogglePrivacy:W,onShareVisual:te,isDeleting:V,isDuplicating:j===n.id,formatDate:Z},n.id))})}),r&&b&&e.jsx(s.ShareDialog,{resource:b,resourceType:s.ResourceType.VISUAL,onClose:()=>{f(!1),D(null)}}),i&&e.jsx(s.ResourceEditDialog,{open:!!i,resourceLabel:"Visual",initialTitle:i.title||"",initialDescription:i.description||"",onClose:ne,onSave:re,isSaving:O(i.id)}),e.jsx(s.AlertDialog,{open:y,onOpenChange:n=>{!n&&V||(l(n),n||S(null))},children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Delete Visual"}),e.jsxs(s.AlertDialogDescription,{children:['Are you sure you want to delete "',c==null?void 0:c.title,'"? This action cannot be undone.']})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{disabled:V,children:"Cancel"}),e.jsxs(s.AlertDialogAction,{onClick:n=>{n.preventDefault(),n.stopPropagation(),k()},className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",disabled:V,children:[V?e.jsx(s.LoaderCircle,{className:"mr-2 h-3.5 w-3.5 animate-spin"}):e.jsx(s.Trash2,{className:"mr-2 h-3.5 w-3.5"}),V?"Deleting...":"Delete"]})]})]})}),e.jsx(we,{open:p,onOpenChange:d,onSubmit:$,isCreating:X}),e.jsx(s.Button,{size:"icon",className:"absolute bottom-2 left-2 h-11 w-11 rounded-full shadow-lg shadow-black/15",onClick:()=>d(!0),"aria-label":"Create visual",children:e.jsx(s.Plus,{className:"h-5 w-5"})})]})}function Ce({dashboard:t,isDeleting:x,isDuplicating:p,onLoadDashboard:d,onEditDetails:r,onDeleteClick:f,onDuplicateDashboard:b,onShareDashboard:D,formatDate:y,onDashboardItemClick:l}){var g,N;const{selectDashboard:c}=s.useManagementActions(),S=s.useIsDashboardSelected(t.id),{userContext:j,isLoading:T}=s.useCurrentUserInfo(),i=((g=j==null?void 0:j.permissions)==null?void 0:g.canEdit)??!1,C=T||!i,L=()=>e.jsx(s.LayoutDashboard,{className:"h-4 w-4"}),v=()=>{c(t),d(t.id),l==null||l(t.id)};return e.jsx(s.Card,{className:s.cn("group cursor-pointer border border-border/50 p-3 transition-colors hover:bg-accent/50",S&&"border-primary"),onClick:v,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5 rounded bg-muted p-1.5",children:L()}),e.jsxs("div",{className:"min-w-0 flex-1 flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground truncate",title:t.title||"Untitled Dashboard",children:t.title||"Untitled Dashboard"}),t.ownership.status==="shared"&&e.jsxs(s.Badge,{variant:"outline",className:"text-xs",children:[e.jsx(s.Users,{className:"mr-1 h-2.5 w-2.5"}),"Shared"]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2 flex-1",title:t.description||"No description",children:(N=t.description)!=null&&N.trim()?t.description:"No description"}),e.jsx(s.DashboardActionsMenu,{dashboard:t,isDeleting:x,isDuplicating:p,shouldHideActions:C,onEditDetails:r,onDeleteClick:f,onDuplicateDashboard:b,onShareDashboard:D,formatDate:y})]})]})]})},t.id)}function be({onRetry:t}){return e.jsx(s.ScrollArea,{className:"w-full flex-1 pr-2",children:e.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[e.jsx("p",{className:"text-sm text-destructive",children:"Failed to load dashboards"}),e.jsx(s.Button,{variant:"outline",size:"sm",className:"mt-2",onClick:t,children:"Retry"})]})})}function ye(t){var le;const{onLoadDashboard:x,onEditDashboard:p,onDashboardItemClick:d}=t,[r,f]=h.useState(""),[b,D]=h.useState(!1),[y,l]=h.useState(!1),[c,S]=h.useState(null),[j,T]=h.useState(!1),[i,C]=h.useState(null),[L,v]=h.useState(null),[g,N]=h.useState(null),I=s.useManagementStore(a=>a.lastSelectedDashboard),P=s.useManagementStore(a=>a.selectedDashboard),w=s.useManagementStore(a=>a.actions.selectDashboard),R=s.useManagementStore(a=>a.actions.clearSelectedDashboard),{tokenProps:M,id:m}=s.useSemaphorContext();s.useRoleAwareDisplayPreferences();const{onCreateSuccess:X}=s.useDashboardCreation({onDashboardSelect:d}),{resources:V,isLoading:_,isError:Z,createResource:$,updateResource:G,deleteResource:k,duplicateResource:ee,isCreating:K,isDeleting:O,refetch:se}=s.useDashboardManagement(()=>{T(!1);const a=i==null?void 0:i.id;C(null),(P==null?void 0:P.id)===a&&(!(M!=null&&M.dashboard_id)&&!m?R():I&&I.id!==a&&w(I))},a=>{D(!1),X(a,se)}),{currentUser:z,userContext:H}=s.useCurrentUserInfo(),q=((le=H==null?void 0:H.permissions)==null?void 0:le.canCreateDashboard)??!1,W=V.filter(a=>{var E,u;return((E=a==null?void 0:a.title)==null?void 0:E.toLowerCase().includes(r.toLowerCase()))||((u=a==null?void 0:a.description)==null?void 0:u.toLowerCase().includes(r.toLowerCase()))}),te=a=>new Date(a).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),ae=a=>{$({title:a.title,description:a.description,isPrivate:!1})},ne=a=>{x==null||x(a)},re=a=>{C(a),T(!0)},n=()=>{i&&k(i.id)},A=a=>{v(a),ee(a,{onSettled:()=>v(null)})},{startUpdating:o,stopUpdating:F,isUpdating:Y}=s.useResourceUpdateState(),Q=(a,E,u)=>{var ce;const ie=Object.fromEntries(Object.entries(E).filter(([,B])=>B!==void 0));if(Object.keys(ie).length===0){(ce=u==null?void 0:u.onSuccess)==null||ce.call(u);return}const de=Object.keys(ie),oe=de.length===1?de[0]:void 0;o(a,oe),G({resourceId:a,data:ie},{onSuccess:()=>{var B;F(a,oe),(B=u==null?void 0:u.onSuccess)==null||B.call(u)},onError:()=>{var B;F(a,oe),(B=u==null?void 0:u.onError)==null||B.call(u)}})},J=a=>{const E=V.find(u=>u.id===a);E&&G({resourceId:a,data:{isPrivate:!E.isPrivate}})},U=a=>{S(a),z==null||z.type,l(!0)},me=a=>{p==null||p(a.id),N(a)},xe=()=>{N(null)},pe=({title:a,description:E})=>{if(!g)return;const u={};a!==g.title&&(u.title=a),(g.description||"")!==E&&(u.description=E),Q(g.id,u,{onSuccess:()=>{N(null)}})};return _?e.jsx(he,{}):Z?e.jsx(be,{onRetry:()=>window.location.reload()}):e.jsxs("div",{className:"relative flex h-full flex-1 flex-col gap-4",children:[V&&V.length>5&&e.jsx("div",{className:"space-y-2",children:e.jsx(s.Input,{id:"search",placeholder:"Search by title or description...",value:r,onChange:a=>f(a.target.value),className:"h-9"})}),e.jsx("div",{className:"flex flex-1 flex-col",children:e.jsx("div",{className:"flex flex-1 basis-0 flex-col gap-3 overflow-y-auto",children:W.length===0?e.jsxs("div",{className:"py-8 text-center",children:[e.jsx("div",{className:"mb-3",children:e.jsx(s.ChartColumn,{className:"mx-auto h-12 w-12 text-muted-foreground/50"})}),e.jsx("h3",{className:"mb-1 font-medium text-foreground",children:r?"No dashboards found":"No dashboards yet"}),e.jsx("p",{className:"mb-4 text-sm text-muted-foreground",children:r?"Try adjusting your search":q?"Create your first dashboard to get started":"No dashboards have been shared with you yet"}),q&&!r&&e.jsxs(s.Button,{size:"sm",className:"bg-primary hover:bg-primary/90",onClick:()=>D(!0),children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Create Dashboard"]})]}):W.map(a=>e.jsx(Ce,{dashboard:a,isDeleting:O,isDuplicating:L===a.id,onLoadDashboard:ne,onEditDetails:me,onDeleteClick:re,onDuplicateDashboard:A,onTogglePrivacy:J,onShareDashboard:U,formatDate:te,onDashboardItemClick:d},a.id))})}),y&&c&&e.jsx(s.ShareDialog,{resource:c,resourceType:s.ResourceType.DASHBOARD,onClose:()=>{l(!1),S(null)}}),e.jsx(s.AlertDialog,{open:j,onOpenChange:a=>{!a&&O||(T(a),a||C(null))},children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Delete Dashboard"}),e.jsxs(s.AlertDialogDescription,{children:['Are you sure you want to delete "',i==null?void 0:i.title,'"? This action cannot be undone.']})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{disabled:O,children:"Cancel"}),e.jsxs(s.AlertDialogAction,{onClick:a=>{a.preventDefault(),a.stopPropagation(),n()},className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",disabled:O,children:[O?e.jsx(s.LoaderCircle,{className:"mr-2 h-3.5 w-3.5 animate-spin"}):e.jsx(s.Trash2,{className:"mr-2 h-3.5 w-3.5"}),O?"Deleting...":"Delete"]})]})]})}),g&&e.jsx(s.ResourceEditDialog,{open:!!g,resourceLabel:"Dashboard",initialTitle:g.title||"",initialDescription:g.description||"",onClose:xe,onSave:pe,isSaving:Y(g.id)}),e.jsx(s.CreateDashboardDialog,{open:b,onOpenChange:D,onSubmit:ae,isCreating:K}),q&&e.jsx(s.Button,{size:"icon",className:"absolute bottom-2 left-2 h-11 w-11 rounded-full shadow-lg shadow-black/15",onClick:()=>D(!0),"aria-label":"Create dashboard",children:e.jsx(s.Plus,{className:"h-5 w-5"})})]})}function Se({isOpen:t,onClose:x,className:p,onDashboardItemClick:d,variant:r="inline"}){s.useDashboardStore(w=>w.dashboard);const f=s.useDashboardStore(w=>w.isDashboardEditing),{setDashboard:b,addSheet:D}=s.useDashboardStore(w=>w.actions),{currentUser:y}=s.useCurrentUserInfo(),l=y,{permissions:c}=s.useRoleAwareDisplayPreferences(),j=s.useSelectedDashboard()&&c.canAccessVisuals&&f,T="dashboards",[i,C]=ue.useLocalStorageState("resource-management-active-tab",T),L=j?i:"dashboards",v=r==="overlay",g=ue.useClickOutside(x,{enabled:t&&v}),N=s.cn("flex h-full flex-col border-r bg-background",v?s.cn("absolute inset-y-0 left-0 z-[51] w-96 shadow-lg transition-transform duration-300 ease-in-out",t?"translate-x-0":"pointer-events-none -translate-x-full"):"w-full max-w-[28rem] min-w-[18rem] overflow-hidden shadow-sm",p),I=w=>{},P=w=>{console.log("Editing dashboard:",w)};return e.jsx(s.TooltipProvider,{children:(!v||t)&&e.jsxs("div",{ref:g,className:N,children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border p-4",children:[e.jsx("div",{className:"flex items-center gap-2",children:l&&e.jsxs(e.Fragment,{children:[e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("div",{className:"flex h-8 w-8 cursor-default items-center justify-center rounded-full bg-primary/10",children:e.jsx("span",{className:"text-sm font-medium text-primary",children:l.name.charAt(0).toUpperCase()})})}),e.jsx(s.TooltipContent,{side:"bottom",className:"ml-2 max-w-xs",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"font-medium",children:l.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:l.email}),l.role&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Role:"," ",s.toTitleCase(l.role.replace(/_/g," "))]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["ID: ",l.id]})]})})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"text-sm font-medium text-foreground",children:l.name})})]})}),e.jsx(s.IconButton,{className:"h-8 w-8 p-0 text-muted-foreground hover:text-foreground",onClick:x,tooltip:"Close Sidebar",children:e.jsx(je,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"flex flex-1 flex-col overflow-hidden",children:e.jsxs(s.Tabs,{value:L,onValueChange:j?C:void 0,className:"flex h-9 grow flex-col",children:[j&&e.jsx("div",{className:"px-4 pt-4",children:e.jsxs(s.TabsList,{className:"grid w-full grid-cols-2",children:[e.jsx(s.TabsTrigger,{value:"dashboards",className:"text-sm",children:"Dashboards"}),e.jsx(s.TabsTrigger,{value:"visuals",className:"text-sm",children:"Visuals"})]})}),e.jsx(s.TabsContent,{value:"dashboards",className:"flex-1 px-4 py-4",children:e.jsx(ye,{onLoadDashboard:I,onEditDashboard:P,onDashboardItemClick:d})}),j&&e.jsx(s.TabsContent,{value:"visuals",className:"flex-1 px-4 py-4",children:e.jsx(ve,{})})]})})]})})}exports.ResourceManagementPanel=Se;