react-semaphor 0.1.260 → 0.1.261

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 (46) hide show
  1. package/dist/chunks/dashboard-controls-0hbftZxY.js +42 -0
  2. package/dist/chunks/dashboard-controls-BYi_r2lH.js +1971 -0
  3. package/dist/chunks/dashboard-filter-controls-button-BPCw1GMh.js +1066 -0
  4. package/dist/chunks/dashboard-filter-controls-button-f4pDkDUL.js +11 -0
  5. package/dist/chunks/{dashboard-json-U7VmojaR.js → dashboard-json-2NJCXsDD.js} +1 -1
  6. package/dist/chunks/{dashboard-json-BUrApiYl.js → dashboard-json-Dpy-zKf2.js} +1 -1
  7. package/dist/chunks/{dashboard-summary-settings-dialog-DlVBUQmC.js → dashboard-summary-settings-dialog-B9zRCvc-.js} +1 -1
  8. package/dist/chunks/{dashboard-summary-settings-dialog-CaxmCNyy.js → dashboard-summary-settings-dialog-Be3JilRI.js} +1 -1
  9. package/dist/chunks/edit-dashboard-visual-Bon08erH.js +188 -0
  10. package/dist/chunks/{edit-dashboard-visual-N2r5ObJ_.js → edit-dashboard-visual-CqTlmuYL.js} +5970 -5492
  11. package/dist/chunks/index-BoJEr_9F.js +1114 -0
  12. package/dist/chunks/{index-BNdZjo5d.js → index-C2c-_lPE.js} +48333 -44824
  13. package/dist/chunks/{normalize-dashboard-for-dirty-check-Bn27S0PN.js → normalize-dashboard-for-dirty-check-5KpZN8xr.js} +20 -19
  14. package/dist/chunks/normalize-dashboard-for-dirty-check-BXRUMVb2.js +1 -0
  15. package/dist/chunks/{resource-management-panel-C_ZqsVMH.js → resource-management-panel-BtLPW2b4.js} +1 -1
  16. package/dist/chunks/{resource-management-panel-zF23gLOJ.js → resource-management-panel-Bva2_0OU.js} +70 -70
  17. package/dist/chunks/use-create-flow-overlay-state-9X7GyUzl.js +21 -0
  18. package/dist/chunks/use-create-flow-overlay-state-Vyd5mSnf.js +1445 -0
  19. package/dist/chunks/{use-visual-utils-BBTQGDdB.js → use-visual-utils-Jv4hWSLm.js} +1 -1
  20. package/dist/chunks/{use-visual-utils-K1k39w2U.js → use-visual-utils-OPk_1t4I.js} +1 -1
  21. package/dist/dashboard/index.cjs +1 -1
  22. package/dist/dashboard/index.js +5 -4
  23. package/dist/index.cjs +1 -1
  24. package/dist/index.js +102 -99
  25. package/dist/shared/index.cjs +1 -1
  26. package/dist/shared/index.js +1 -1
  27. package/dist/style.css +1 -1
  28. package/dist/surfboard/index.cjs +1 -1
  29. package/dist/surfboard/index.js +5 -4
  30. package/dist/types/dashboard.d.ts +105 -0
  31. package/dist/types/index.cjs +1 -1
  32. package/dist/types/index.js +4 -3
  33. package/dist/types/main.d.ts +175 -1
  34. package/dist/types/shared.d.ts +89 -0
  35. package/dist/types/surfboard.d.ts +105 -0
  36. package/dist/types/types.d.ts +113 -0
  37. package/package.json +1 -1
  38. package/dist/chunks/dashboard-controls-CIdYp98a.js +0 -47
  39. package/dist/chunks/dashboard-controls-DOqBYrkB.js +0 -1847
  40. package/dist/chunks/edit-dashboard-visual-uA-0wLnR.js +0 -193
  41. package/dist/chunks/editor-action-buttons-B6lABkRB.js +0 -412
  42. package/dist/chunks/editor-action-buttons-Dh7Xndgk.js +0 -21
  43. package/dist/chunks/index-DOeggx0V.js +0 -1109
  44. package/dist/chunks/normalize-dashboard-for-dirty-check-B7NQDI1H.js +0 -1
  45. package/dist/chunks/notification-bell-BxyeaeRc.js +0 -839
  46. package/dist/chunks/notification-bell-tJRds5JJ.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-BoJEr_9F.js"),x=require("react");require("react-dom");const O=require("./dashboard-filter-controls-button-f4pDkDUL.js"),_s=require("./date-formatter-CqXdM6JO.js"),Xe=require("./dashboard-summary-settings-dialog-Be3JilRI.js"),Us=require("./use-debounced-dirty-check-XHSwAefL.js"),we=require("./normalize-dashboard-for-dirty-check-BXRUMVb2.js"),Ye=require("./use-create-flow-overlay-state-9X7GyUzl.js");function Fs(t){const o=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(o,a,r.get?r:{enumerable:!0,get:()=>t[a]})}}return o.default=t,Object.freeze(o)}const C=Fs(x);/**
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 Rs=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 Gs=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 $s=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 Bs=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 qs=s.createLucideIcon("Sun",[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m4.93 4.93 1.41 1.41",key:"149t6j"}],["path",{d:"m17.66 17.66 1.41 1.41",key:"ptbguv"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"m6.34 17.66-1.41 1.41",key:"1m8zz5"}],["path",{d:"m19.07 4.93-1.41 1.41",key:"1shlcs"}]]);var Ae={exports:{}},Ce={};/**
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 Ze;function Hs(){if(Ze)return Ce;Ze=1;var t=x;function o(n,d){return n===d&&(n!==0||1/n===1/d)||n!==n&&d!==d}var a=typeof Object.is=="function"?Object.is:o,r=t.useState,i=t.useEffect,c=t.useLayoutEffect,u=t.useDebugValue;function m(n,d){var g=d(),v=r({inst:{value:g,getSnapshot:d}}),b=v[0].inst,y=v[1];return c(function(){b.value=g,b.getSnapshot=d,p(b)&&y({inst:b})},[n,g,d]),i(function(){return p(b)&&y({inst:b}),n(function(){p(b)&&y({inst:b})})},[n]),u(g),g}function p(n){var d=n.getSnapshot;n=n.value;try{var g=d();return!a(n,g)}catch{return!0}}function j(n,d){return d()}var h=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?j:m;return Ce.useSyncExternalStore=t.useSyncExternalStore!==void 0?t.useSyncExternalStore:h,Ce}var Me={};/**
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 es;function zs(){return es||(es=1,process.env.NODE_ENV!=="production"&&function(){function t(g,v){return g===v&&(g!==0||1/g===1/v)||g!==g&&v!==v}function o(g,v){h||i.startTransition===void 0||(h=!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=v();if(!n){var y=v();c(b,y)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),n=!0)}y=u({inst:{value:b,getSnapshot:v}});var N=y[0].inst,I=y[1];return p(function(){N.value=b,N.getSnapshot=v,a(N)&&I({inst:N})},[g,b,v]),m(function(){return a(N)&&I({inst:N}),g(function(){a(N)&&I({inst:N})})},[g]),j(b),b}function a(g){var v=g.getSnapshot;g=g.value;try{var b=v();return!c(g,b)}catch{return!0}}function r(g,v){return v()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var i=x,c=typeof Object.is=="function"?Object.is:t,u=i.useState,m=i.useEffect,p=i.useLayoutEffect,j=i.useDebugValue,h=!1,n=!1,d=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?r:o;Me.useSyncExternalStore=i.useSyncExternalStore!==void 0?i.useSyncExternalStore:d,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()),Me}process.env.NODE_ENV==="production"?Ae.exports=Hs():Ae.exports=zs();var Vs=Ae.exports;function Ks(){const{setTheme:t}=s.useTheme(),o=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(qs,{strokeWidth:1.5,className:"h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0"}),e.jsx($s,{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"),o("light")},children:"Light"}),e.jsx(s.DropdownMenuItem,{onClick:()=>{t("dark"),o("dark")},children:"Dark"}),e.jsx(s.DropdownMenuItem,{onClick:()=>{t("system"),o("system")},children:"System"})]})]})}async function Qs(t,o,a,r,i){if(!i)return null;const c=JSON.stringify(a),u=`${t}/v1/lens`;return await s.postRequest(u,i,{name:o,template:c,filterValues:r,operation:"create"})}async function Le(t,o,a){if(!a)return null;const{id:r,template:i,filterValues:c,isDefault:u,shared:m}=o,p=`${t}/v1/lens`;return await s.postRequest(p,a,{lensId:r,template:i,filterValues:c,isDefault:u,shared:m,operation:"update"})}async function Ws(t,o,a){if(!a)return null;const r=`${t}/v1/lens`;return await s.postRequest(r,a,{operation:"delete",lensId:o})}function Js(){const[t,o]=x.useState(""),[a,r]=x.useState(!1),i=s.useDashboardStore(y=>y.lenses),{setLenses:c,setSelectedLensId:u}=s.useDashboardActions(),[m,p]=x.useState(!1),[j,h]=x.useState(!1),n=s.useDashboardStore(y=>y.dashboard),d=s.useDashboardStore(y=>y.filterValues),{authToken:g,tokenProps:v}=s.useSemaphorContext();async function b(){p(!0);const y=await Qs(v.apiServiceUrl,t,n,d,g==null?void 0:g.accessToken);y&&(c([...i||[],y]),u(y.id),h(!1)),p(!1)}return e.jsxs(s.Dialog,{open:j,onOpenChange:h,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:y=>{o(y.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:m,children:m?"Creating...":"Add"})})]})]})}function Xs(){const[t,o]=x.useState(!1),a=s.useDashboardStore(n=>n.lenses),r=s.useDashboardStore(n=>n.selectedLensId),{setLenses:i,setSelectedLensId:c}=s.useDashboardActions(),{authToken:u,tokenProps:m}=s.useSemaphorContext();async function p(n){c(n)}async function j(n){if(await Ws(m.apiServiceUrl,n,u==null?void 0:u.accessToken)){const g=a==null?void 0:a.filter(v=>v.id!==n);i(g||[]),c("original")}}async function h(n){const d=a==null?void 0:a.map(b=>b.id===n.id?{...b,isDefault:!n.isDefault}:{...b,isDefault:!1});i(d||[]);const g={...n,isDefault:!n.isDefault};await Le(m.apiServiceUrl,g,u==null?void 0:u.accessToken);const v=a==null?void 0:a.find(b=>b.isDefault);if(v&&v.id!==n.id){const b={...v,isDefault:!1};await Le(m.apiServiceUrl,b,u==null?void 0:u.accessToken)}}return e.jsxs(s.DropdownMenu,{open:t,onOpenChange:o,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Lenses",className:"h-7 p-2",children:e.jsx(Rs,{className:"h-4 w-4"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-60",children:[e.jsx(s.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuRadioGroup,{value:r,onValueChange:p,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),a==null?void 0:a.map(n=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:n.id,children:[e.jsx("p",{children:n.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(s.House,{onClick:d=>{d.preventDefault(),h(n)},className:s.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!n.isDefault,"text-green-500":n.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:d=>{d.preventDefault(),j(n.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},n.id))]})]})]})}function Ys(){const{displayPreferences:t,shouldShowElement:o}=s.useDisplayPreferences(),{currentUser:a,userContext:r}=s.useCurrentUserInfo(),i=x.useMemo(()=>s.getRoleBasedDisplayOverrides(a),[a]),c=x.useMemo(()=>m=>i&&i[m]!==void 0&&i[m]===!1?!1:o(m),[i,o,t]),u=x.useMemo(()=>{var m,p,j,h,n;return{canEdit:((m=r==null?void 0:r.permissions)==null?void 0:m.canEdit)??s.canUserEdit(a),canUseFilters:((p=r==null?void 0:r.permissions)==null?void 0:p.canEdit)??s.canUserUseFilters(a),canManageDashboards:((j=r==null?void 0:r.permissions)==null?void 0:j.canCreateDashboard)??s.canUserManageDashboards(a),canCreateDashboards:((h=r==null?void 0:r.permissions)==null?void 0:h.canCreateDashboard)??s.canUserCreateDashboards(a),canAccessVisuals:((n=r==null?void 0:r.permissions)==null?void 0:n.canEdit)??s.canUserAccessVisuals(a)}},[a,r]);return{displayPreferences:t,shouldShowElement:c,permissions:u,currentUser:a}}const Zs=async(t,o,a)=>{const r=`${t}/management/v1/groups`;return await s.postRequestRegular(r,o,a)},et=async(t,o,a)=>{const r=`${t}/management/v1/groups/${a}`,i=await fetch(r,{method:"DELETE",headers:{Authorization:`Bearer ${o}`}});if(!i.ok){const c=await i.text();throw new Error(c||"Failed to delete group")}},st=async(t,o,a,r)=>{const i=`${t}/management/v1/groups/${a}/members`;return await s.postRequestRegular(i,o,r)},tt=async(t,o,a,r)=>{const i=`${t}/management/v1/groups/${a}/members`,c=await fetch(i,{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`},body:JSON.stringify(r)});if(!c.ok){const u=await c.text();throw new Error(u||"Failed to remove group members")}};function at(){const{authToken:t,tokenProps:o}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:r=>Zs(o.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 rt(){const{authToken:t,tokenProps:o}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:r=>et(o.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r),onSuccess:(r,i)=>{a.invalidateQueries({queryKey:["groups"]}),a.removeQueries({queryKey:["group",i]}),s.ue.success("Group deleted successfully")},onError:r=>{console.error("Failed to delete group:",r),s.ue.error("Failed to delete group",{description:r.message})}})}function nt(){const{authToken:t,tokenProps:o}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:i})=>st(o.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r,i),onSuccess:(r,i)=>{a.invalidateQueries({queryKey:["group",i.groupId]}),a.invalidateQueries({queryKey:["group-members",i.groupId]}),a.invalidateQueries({queryKey:["groups"]}),s.ue.success("Members added successfully")},onError:r=>{console.error("Failed to add group members:",r),s.ue.error("Failed to add members",{description:r.message})}})}function ot(){const{authToken:t,tokenProps:o}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:i})=>tt(o.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r,i),onSuccess:(r,i)=>{a.invalidateQueries({queryKey:["group",i.groupId]}),a.invalidateQueries({queryKey:["group-members",i.groupId]}),a.invalidateQueries({queryKey:["groups"]}),s.ue.success("Members removed successfully")},onError:r=>{console.error("Failed to remove group members:",r),s.ue.error("Failed to remove members",{description:r.message})}})}function it({onSuccess:t,tenantId:o,isTenantUser:a}){const[r,i]=x.useState(""),[c,u]=x.useState(""),[m,p]=x.useState({}),j=at(),h=()=>{const d={};return r.trim()?r.length<3?d.name="Group name must be at least 3 characters":r.length>50&&(d.name="Group name must be less than 50 characters"):d.name="Group name is required",c&&c.length>200&&(d.description="Description must be less than 200 characters"),p(d),Object.keys(d).length===0},n=async d=>{if(d.preventDefault(),!h())return;const g={name:r.trim(),description:c.trim()||void 0,type:a?"TENANT_GROUP":"ORG_GROUP",...a&&o?{tenantId:o}:{}};try{await j.mutateAsync(g),i(""),u(""),p({}),t()}catch(v){console.error("Failed to create group:",v)}};return e.jsxs("form",{onSubmit:n,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:d=>{i(d.target.value),m.name&&p(g=>({...g,name:""}))},className:m.name?"border-destructive":"",disabled:j.isPending}),m.name&&e.jsx("p",{className:"text-sm text-destructive",children:m.name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(s.Label,{htmlFor:"group-description",children:["Description",e.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:"(optional)"})]}),e.jsx(s.Textarea,{id:"group-description",placeholder:"Describe the purpose of this group...",value:c,onChange:d=>{u(d.target.value),m.description&&p(g=>({...g,description:""}))},className:m.description?"border-destructive":"",disabled:j.isPending,rows:3}),m.description&&e.jsx("p",{className:"text-sm text-destructive",children:m.description}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[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:()=>{i(""),u(""),p({})},disabled:j.isPending,children:"Clear"}),e.jsx(s.Button,{type:"submit",disabled:j.isPending||!r.trim(),children:j.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 lt(t,o=[]){let a=[];function r(c,u){const m=C.createContext(u);m.displayName=c+"Context";const p=a.length;a=[...a,u];const j=n=>{var N;const{scope:d,children:g,...v}=n,b=((N=d==null?void 0:d[t])==null?void 0:N[p])||m,y=C.useMemo(()=>v,Object.values(v));return e.jsx(b.Provider,{value:y,children:g})};j.displayName=c+"Provider";function h(n,d){var b;const g=((b=d==null?void 0:d[t])==null?void 0:b[p])||m,v=C.useContext(g);if(v)return v;if(u!==void 0)return u;throw new Error(`\`${n}\` must be used within \`${c}\``)}return[j,h]}const i=()=>{const c=a.map(u=>C.createContext(u));return function(m){const p=(m==null?void 0:m[t])||c;return C.useMemo(()=>({[`__scope${t}`]:{...m,[t]:p}}),[m,p])}};return i.scopeName=t,[r,ct(i,...o)]}function ct(...t){const o=t[0];if(t.length===1)return o;const a=()=>{const r=t.map(i=>({useScope:i(),scopeName:i.scopeName}));return function(c){const u=r.reduce((m,{useScope:p,scopeName:j})=>{const n=p(c)[`__scope${j}`];return{...m,...n}},{});return C.useMemo(()=>({[`__scope${o.scopeName}`]:u}),[u])}};return a.scopeName=o.scopeName,a}var dt=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ee=dt.reduce((t,o)=>{const a=s.createSlot(`Primitive.${o}`),r=C.forwardRef((i,c)=>{const{asChild:u,...m}=i,p=u?a:o;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(p,{...m,ref:c})});return r.displayName=`Primitive.${o}`,{...t,[o]:r}},{});function ut(){return Vs.useSyncExternalStore(mt,()=>!0,()=>!1)}function mt(){return()=>{}}var Ie="Avatar",[ht]=lt(Ie),[pt,ts]=ht(Ie),as=C.forwardRef((t,o)=>{const{__scopeAvatar:a,...r}=t,[i,c]=C.useState("idle");return e.jsx(pt,{scope:a,imageLoadingStatus:i,onImageLoadingStatusChange:c,children:e.jsx(Ee.span,{...r,ref:o})})});as.displayName=Ie;var rs="AvatarImage",ns=C.forwardRef((t,o)=>{const{__scopeAvatar:a,src:r,onLoadingStatusChange:i=()=>{},...c}=t,u=ts(rs,a),m=gt(r,c),p=s.useCallbackRef(j=>{i(j),u.onImageLoadingStatusChange(j)});return s.useLayoutEffect2(()=>{m!=="idle"&&p(m)},[m,p]),m==="loaded"?e.jsx(Ee.img,{...c,ref:o,src:r}):null});ns.displayName=rs;var os="AvatarFallback",is=C.forwardRef((t,o)=>{const{__scopeAvatar:a,delayMs:r,...i}=t,c=ts(os,a),[u,m]=C.useState(r===void 0);return C.useEffect(()=>{if(r!==void 0){const p=window.setTimeout(()=>m(!0),r);return()=>window.clearTimeout(p)}},[r]),u&&c.imageLoadingStatus!=="loaded"?e.jsx(Ee.span,{...i,ref:o}):null});is.displayName=os;function ss(t,o){return t?o?(t.src!==o&&(t.src=o),t.complete&&t.naturalWidth>0?"loaded":"loading"):"error":"idle"}function gt(t,{referrerPolicy:o,crossOrigin:a}){const r=ut(),i=C.useRef(null),c=r?(i.current||(i.current=new window.Image),i.current):null,[u,m]=C.useState(()=>ss(c,t));return s.useLayoutEffect2(()=>{m(ss(c,t))},[c,t]),s.useLayoutEffect2(()=>{const p=n=>()=>{m(n)};if(!c)return;const j=p("loaded"),h=p("error");return c.addEventListener("load",j),c.addEventListener("error",h),o&&(c.referrerPolicy=o),typeof a=="string"&&(c.crossOrigin=a),()=>{c.removeEventListener("load",j),c.removeEventListener("error",h)}},[c,a,o]),u}var ls=as,cs=ns,ds=is;const ke=C.forwardRef(({className:t,...o},a)=>e.jsx(ls,{ref:a,className:s.cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",t),...o}));ke.displayName=ls.displayName;const ft=C.forwardRef(({className:t,...o},a)=>e.jsx(cs,{ref:a,className:s.cn("aspect-square h-full w-full",t),...o}));ft.displayName=cs.displayName;const Te=C.forwardRef(({className:t,...o},a)=>e.jsx(ds,{ref:a,className:s.cn("flex h-full w-full items-center justify-center rounded-full bg-muted",t),...o}));Te.displayName=ds.displayName;function xt({open:t,onOpenChange:o,group:a,onUpdate:r}){const[i,c]=x.useState("members"),[u,m]=x.useState(""),[p,j]=x.useState([]),[h,n]=x.useState([]),{data:d,isLoading:g,refetch:v}=s.useGroupMembers(a.id),b=a.type==="TENANT_GROUP"?"tenant":"organization",{users:y,isLoading:N}=s.useUnifiedUsers({type:b,tenantId:a.tenantId||void 0,active:!0,limit:100}),I=nt(),k=ot(),E=(d==null?void 0:d.members)||[],_=x.useMemo(()=>new Set(E.map(f=>f.userId)),[E]),U=x.useMemo(()=>y.filter(f=>!_.has(f.id)),[y,_]),F=x.useMemo(()=>{if(!u)return U;const f=u.toLowerCase();return U.filter(w=>{var M,P;return((M=w.name)==null?void 0:M.toLowerCase().includes(f))||((P=w.email)==null?void 0:P.toLowerCase().includes(f))})},[U,u]),S=x.useMemo(()=>{if(!u)return E;const f=u.toLowerCase();return E.filter(w=>{var M,P,G,H;return((P=(M=w.user)==null?void 0:M.name)==null?void 0:P.toLowerCase().includes(f))||((H=(G=w.user)==null?void 0:G.email)==null?void 0:H.toLowerCase().includes(f))})},[E,u]),R=async()=>{if(p.length!==0)try{await I.mutateAsync({groupId:a.id,data:{userIds:p,userType:b==="tenant"?"tenant":"org"}}),j([]),c("members"),v(),r==null||r()}catch(f){console.error("Failed to add members:",f)}},Z=async()=>{if(h.length!==0)try{await k.mutateAsync({groupId:a.id,data:{userIds:h}}),n([]),v(),r==null||r()}catch(f){console.error("Failed to remove members:",f)}},q=f=>{j(w=>w.includes(f)?w.filter(M=>M!==f):[...w,f])},ue=f=>{n(w=>w.includes(f)?w.filter(M=>M!==f):[...w,f])};return e.jsx(e.Fragment,{children:e.jsx(s.Dialog,{open:t,onOpenChange:o,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:[E.length," ",E.length===1?"member":"members"]})}),e.jsxs("p",{id:"group-members-description",className:"sr-only",children:["Add or remove members from the ",a.name," group"]})]}),e.jsxs(s.Tabs,{value:i,onValueChange:f=>{c(f),m(""),n([])},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:f=>m(f.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:h.length>0?"h-[300px]":"h-[350px]",children:g?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(f=>e.jsx(s.Skeleton,{className:"h-16 w-full"},f))}):S.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:S.map(f=>e.jsx(vt,{member:f,selected:h.includes(f.userId),onToggle:()=>ue(f.userId)},f.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," member",h.length!==1?"s":""," selected"]}),e.jsx(s.Button,{variant:"destructive",size:"sm",onClick:Z,disabled:k.isPending,children:k.isPending?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Removing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(s.Trash2,{className:"mr-2 h-4 w-4"}),"Remove Selected"]})})]})]}),e.jsxs(s.TabsContent,{value:"add",className:"mt-4 space-y-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(s.Search,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(s.Input,{placeholder:"Search users to add...",value:u,onChange:f=>m(f.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:"h-[300px]",children:N?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(f=>e.jsx(s.Skeleton,{className:"h-16 w-full"},f))}):F.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:F.map(f=>e.jsx(bt,{user:f,selected:p.includes(f.id),onToggle:()=>q(f.id)},f.id))})}),p.length>0&&e.jsxs("div",{className:"flex items-center justify-between pt-4 border-t",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[p.length," user",p.length!==1?"s":""," selected"]}),e.jsx(s.Button,{onClick:R,disabled:I.isPending,children:I.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 vt({member:t,selected:o,onToggle:a}){var i,c,u,m;const r=((c=(i=t.user)==null?void 0:i.name)==null?void 0:c.split(" ").map(p=>p[0]).join("").toUpperCase())||"?";return e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg border bg-card hover:bg-muted/50 cursor-pointer",onClick:a,children:[e.jsx(s.Checkbox,{checked:o}),e.jsx(ke,{className:"h-8 w-8",children:e.jsx(Te,{className:"text-xs",children:r})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:((u=t.user)==null?void 0:u.name)||"Unknown User"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(m=t.user)==null?void 0:m.email})]})]})}function bt({user:t,selected:o,onToggle:a}){var i;const r=((i=t.name)==null?void 0:i.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:o}),e.jsx(ke,{className:"h-8 w-8",children:e.jsx(Te,{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 jt({open:t,onOpenChange:o}){const[a,r]=x.useState("groups"),[i,c]=x.useState(""),[u,m]=x.useState(null),[p,j]=x.useState(!1),[h,n]=x.useState(null),{tokenProps:d}=s.useSemaphorContext(),{currentUser:g}=s.useCurrentUserInfo(),v=rt(),b=(g==null?void 0:g.type)==="tenant",y=d==null?void 0:d.tenantId,{groups:N,isLoading:I,refetch:k}=s.useGroups({type:b?"TENANT_GROUP":"all",tenantId:b?y:void 0,includeMembers:!1}),E=N.filter(S=>{var R;return S.name.toLowerCase().includes(i.toLowerCase())||((R=S.description)==null?void 0:R.toLowerCase().includes(i.toLowerCase()))}),_=async()=>{if(h)try{await v.mutateAsync(h.id),n(null),k()}catch(S){console.error("Failed to delete group:",S)}},U=S=>{m(S),j(!0)},F=()=>{r("groups"),k()};return e.jsxs(e.Fragment,{children:[e.jsx(s.Dialog,{open:t,onOpenChange:o,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:i,onChange:S=>c(S.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:"h-[400px]",children:I?e.jsx("div",{className:"space-y-3",children:[1,2,3].map(S=>e.jsx(s.Skeleton,{className:"h-24 w-full"},S))}):E.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(s.Users,{className:"h-12 w-12 mb-3 opacity-50"}),e.jsx("p",{className:"text-sm font-medium",children:"No groups found"}),e.jsx("p",{className:"text-xs mt-1",children:i?"Try a different search":"Create your first group to get started"})]}):e.jsx("div",{className:"space-y-3",children:E.map(S=>e.jsx(yt,{group:S,onManageMembers:()=>U(S),onDelete:()=>n(S),currentUserId:g==null?void 0:g.id},S.id))})})]})}),e.jsx(s.TabsContent,{value:"create",className:"mt-4",children:e.jsx(it,{onSuccess:F,tenantId:y,isTenantUser:b})})]})]})}),u&&e.jsx(xt,{open:p,onOpenChange:j,group:u,onUpdate:()=>k()}),e.jsx(s.AlertDialog,{open:!!h,onOpenChange:()=>n(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 "',h==null?void 0:h.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:_,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 yt({group:t,onManageMembers:o,onDelete:a,currentUserId:r}){const i=t.createdBy===r;return e.jsx("div",{className:"rounded-lg border bg-card p-4 transition-colors hover:bg-muted/50",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium",children:t.name}),t.description&&e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:t.description})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-xs text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(s.Users,{className:"h-3 w-3"}),t.memberCount," ",t.memberCount===1?"member":"members"]}),e.jsxs("span",{children:["Created ",_s.format(new Date(t.createdAt),"MMM d, yyyy")]})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:o,title:"Manage members",children:e.jsx(s.UserPlus,{className:"h-4 w-4"})}),i&&e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:a,title:"Delete group",className:"text-destructive hover:text-destructive",children:e.jsx(s.Trash2,{className:"h-4 w-4"})})]})]})})}function X(t,o,a){var c,u;const r=(t.controls||[]).find(m=>m.id===a);if(r)return r.label;const i=(u=(c=s.findCardById(t,o))==null?void 0:c.controls)==null?void 0:u.find(m=>m.id===a);return(i==null?void 0:i.label)||a}function Y(t,o){var a;return((a=s.findCardById(t,o))==null?void 0:a.title)||o}function St(t){const{errors:o,dashboard:a}=t;if(!a)return o;const r=new Map;for(const i of o){const c=i.match(/^Card '(.+)' binding for control '(.+)' maps to missing metric '(.+)'\.$/);if(c){const[,h,n]=c,d=`${h}:${n}:missing-metric`;r.has(d)||r.set(d,`"${Y(a,h)}" has an outdated "${X(a,h,n)}" mapping. Some choices still point to metrics that are no longer available on this card. Open the card controls and choose replacements.`);continue}const u=i.match(/^Card '(.+)' binding for control '(.+)' maps to missing group-by field '(.+)'\.$/);if(u){const[,h,n]=u,d=`${h}:${n}:missing-group-by`;r.has(d)||r.set(d,`"${Y(a,h)}" has an outdated "${X(a,h,n)}" mapping. Some choices still point to fields that are no longer available on this card. Open the card controls and choose replacements.`);continue}const m=i.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid metric target\.$/);if(m){const[,h,n]=m,d=`${h}:${n}:invalid-metric`;r.has(d)||r.set(d,`"${Y(a,h)}" has an invalid "${X(a,h,n)}" metric mapping. Open the card controls and choose a valid metric for each option.`);continue}const p=i.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid group-by target\.$/);if(p){const[,h,n]=p,d=`${h}:${n}:invalid-group-by`;r.has(d)||r.set(d,`"${Y(a,h)}" has an invalid "${X(a,h,n)}" field mapping. Open the card controls and choose a valid field for each option.`);continue}const j=i.match(/^Card '(.+)' binding for control '(.+)' requires at least one temporal group-by field\.$/);if(j){const[,h,n]=j,d=`${h}:${n}:missing-temporal-group-by`;r.has(d)||r.set(d,`"${Y(a,h)}" can no longer use "${X(a,h,n)}" for time grain because the card does not currently group by a date field.`);continue}r.set(i,i)}return Array.from(r.values())}function Dt(){var Ve,Ke,Qe,We;O.useExportRecovery(),O.useExportPolling();const{authToken:t,tokenProps:o,id:a}=s.useSemaphorContext(),{isLocalDev:r}=s.useDashboardPreferences(),{permissions:i}=Ys(),c=s.useHasDashboardId(),{isLoading:u}=s.useDashboardQuery();s.useDashboardStore(l=>l.theme);const m=s.useDashboardStore(l=>l.dashboardAssistantDraftScopeKey),p=s.useDashboardStore(l=>l.lenses),j=s.useDashboardStore(l=>l.selectedLensId),h=p==null?void 0:p.find(l=>l.id===j),n=s.useDashboardStore(l=>l.dashboard);s.useDashboardStore(l=>l.selectedSheetId);const d=s.useDashboardStore(l=>l.isDashboardEditing),{setDashboardTitle:g}=s.useDashboardStore(l=>l.actions),[v,b]=x.useState(!1),[y,N]=x.useState(!1),[I,k]=x.useState(!1),[E,_]=x.useState(!1),[U,F]=x.useState(!1),[S,R]=x.useState(!1),[Z,q]=x.useState(null),[ue,f]=x.useState(!1),[w,M]=x.useState(null),[P,G]=x.useState([]),[H,ee]=x.useState(!1),us=s.useDashboardStore(l=>l.isDashboardPanelOpen),ms=s.useDashboardStore(l=>l.actions.setIsDashboardPanelOpen),hs=s.useDashboardStore(l=>l.filterValues),D=s.useDashboardStore(l=>l.isVisualEditing);s.useEditorStore(l=>l.card);const z=s.useManagementStore(l=>l.selectedDashboard),se=s.useManagementStore(l=>l.initialDashboard);s.useManagementStore(l=>l.selectedVisual),s.useDashboardStore(l=>l.selectedFrameId),s.useEditorStore(l=>l.frame);const te=z?(Ke=z==null?void 0:z.permissions)==null?void 0:Ke.canEdit:(Ve=se==null?void 0:se.permissions)==null?void 0:Ve.canEdit,ae=s.useDashboardStore(l=>l.showFilters),Oe=s.useAssistantLayoutStore(l=>l.setPanelOpen),ps=s.useDashboardStore(l=>l.showDashboardJSON),me=s.useDashboardStore(l=>l.onSaveFunction),Pe=s.useDashboardStore(l=>l.actions.setShowFilters),{setIsDashboardEditing:_e,setShowDashboardJSON:Ue}=s.useDashboardStore(l=>l.actions),{setInitialDashboard:Fe,clearSelectedDashboard:he}=s.useManagementStore(l=>l.actions),{resources:re}=s.useResourceManagement(s.ResourceType.DASHBOARD),{data:pe}=s.useUserPreferences(),gs=((Qe=pe==null?void 0:pe.preference)==null?void 0:Qe.defaultDashboardId)||null,{mutate:fs,isPending:xs}=s.useDefaultDashboardMutation(),{currentUser:vs}=s.useCurrentUserInfo(),bs=s.canUserManageGroups(vs),B=z||se,Re=B?{id:B.id,title:(n==null?void 0:n.title)||B.title||"Dashboard"}:null,{handleAddNewFrame:js}=s.useAddNewFrame(),[ge,fe]=x.useState(!1),[ys,V]=x.useState(!1),[xe,ne]=x.useState("close"),K=s.useUpdateResource(s.ResourceType.DASHBOARD),[T,ve]=x.useState(null),Ge=x.useCallback(l=>{window.setTimeout(()=>{q(l)},0)},[]),Ss=async(l,L)=>{if(!(n!=null&&n.id)){console.log("No dashboard ID found");return}console.log("Updating dashboard title:",{dashboardId:n.id,newTitle:l,previousTitle:L}),K.mutate({resourceId:n.id,data:{title:l}},{onSuccess:()=>{console.log("Dashboard title updated successfully"),s.ue.success("Dashboard title updated")},onError:J=>{console.error("Failed to update dashboard title:",J),s.ue.error("Failed to update dashboard title"),g(L)}})};x.useEffect(()=>{if(re&&re.length>0){const l=n==null?void 0:n.id;if(l){const L=re.find(J=>J.id===l);L&&Fe(L)}}},[re,n==null?void 0:n.id,Fe]);const oe=o.orgUserId||o.tenantId,$e=d&&!D&&oe&&te,{setDashboard:be}=s.useDashboardStore(l=>l.actions),Ds=()=>{_e(!0)},je=()=>{_e(!1),Ue(!1),ve(null),q(null)};O.usePristineSnapshotInitializer(d,n,T,l=>ve(l));const{isDirty:Be,isDirtyPending:Ns,resetDirty:ie}=Us.useDebouncedDirtyCheck(n,T,300,1e3,we.serializeDashboardForDirtyCheck),qe=x.useCallback(()=>T?we.serializeDashboardForDirtyCheck(n)!==we.serializeDashboardForDirtyCheck(T):!1,[n,T]),ye=Be||Ns,Q=ge||K.isPending,ws=()=>{qe()?(ne("close"),V(!0)):(je(),ie())},Cs=async()=>{await Se({closeAfterSave:!0,navigateHomeAfterSave:xe==="home"})},Ms=()=>{T&&be(T),je(),xe==="home"&&he(),ne("close"),V(!1),ie()},As=()=>{T&&(be(T),ie())},Ls=()=>{if(d&&qe()){ne("home"),V(!0);return}he()};async function Se(l){const L=(l==null?void 0:l.closeAfterSave)??H,J=(l==null?void 0:l.navigateHomeAfterSave)??!1;ee(L),L&&V(!1);const Os=s.cloneDeep(n);f(!0),M(null),G([]),fe(!0);const Ps={template:n};K.mutate({resourceId:n.id,data:Ps},{onSuccess:A=>{var le,ce,Je;const $=(A==null?void 0:A.id)||((le=A==null?void 0:A.dashboard)==null?void 0:le.id)||((ce=A==null?void 0:A.resource)==null?void 0:ce.id)||((Je=A==null?void 0:A.template)==null?void 0:Je.id)||null;if(!n.id&&$){const Ne=s.useAIInteractionStore.getState(),de=Ne.pendingDashboardDraftMigration;(de==null?void 0:de.scopeKey)===m?Ne.actions.setPendingDashboardDraftMigrationExpectedDashboardId($):de&&Ne.actions.clearPendingDashboardDraftMigration()}fe(!1),s.ue.success("Dashboard saved!"),ve(Os),f(!1),ee(!1),L&&(je(),ie(),J&&he()),ne("close")},onError:A=>{fe(!1),M("Failed to save dashboard. Please try again.");const $=A.details,le=Array.isArray($==null?void 0:$.errors)?($.errors||[]).filter(ce=>typeof ce=="string"):[];G(St({errors:le,dashboard:n||void 0})),s.ue.error("Failed to save dashboard")}})}async function Es(){if(b(!0),!j||!h)return;const l=JSON.stringify(n),L={...h,template:l,filterValues:hs};await Le(o.apiServiceUrl,L,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),me==null||me(n),b(!1)}const He=(h==null?void 0:h.name)||n.title;K.isPending&&console.log("Title during update:",{title:He,dashboardStateTitle:n.title,dashboardId:n==null?void 0:n.id,currentLensName:h==null?void 0:h.name});const ze=o.orgUserId||o.tenantId&&o.endUserId&&o.endUserEmail,Is=!!ze&&!!(t!=null&&t.accessToken)&&!!(o!=null&&o.apiServiceUrl),ks=c,W=(n==null?void 0:n.id)||null,De=!!W&&gs===W,Ts=()=>{W&&fs({dashboardId:De?null:W})};return e.jsxs("div",{className:"flex h-11 shrink-0 items-center justify-between gap-2 overflow-x-auto border-b px-4 py-2",role:"dashboard-controls",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[ze&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{"aria-label":"Manage Dashboards",tooltip:"Manage Dashboards",onClick:()=>{ms(!us)},className:"h-7 p-2",children:e.jsx(Gs,{className:"h-4 w-4"})}),ks&&!D&&e.jsx(s.IconButton,{"aria-label":"Dashboard Hub",tooltip:"Dashboard Hub",onClick:Ls,className:"h-7 p-2",children:e.jsx(s.House,{className:"h-4 w-4"})})]}),!D&&c&&(u?e.jsx("div",{className:"h-4 w-28 rounded-md bg-muted/70 animate-pulse","aria-label":"Loading dashboard title",role:"status",children:e.jsx("span",{className:"sr-only",children:"Loading dashboard title"})}):e.jsxs(e.Fragment,{children:[e.jsx(s.EditableText,{value:He||"Untitled Dashboard",onSave:l=>{console.log("EditableText onSave called:",{newTitle:l,canEditDashboard:te,dashboardId:n==null?void 0:n.id});const L=(n==null?void 0:n.title)||"";g(l),Ss(l,L)},isEditable:te&&!h,displayClassName:"text-sm font-medium",inputClassName:"text-sm font-medium",placeholder:"Dashboard Title",isPending:K.isPending}),Is&&W&&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:Ts,disabled:xs||!(t!=null&&t.accessToken)||!(o!=null&&o.apiServiceUrl),className:"h-7 w-7",children:e.jsx(s.Star,{className:s.cn("h-4 w-4 transition-colors",De?"fill-yellow-400 text-yellow-400":"text-muted-foreground hover:text-yellow-400")})})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{children:De?"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(O.AdvancedModeToggle,{className:"mr-2"}),e.jsx(O.VisualEditingControls,{className:"h-7"})]}),r&&!D&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{tooltip:"Copy Token",onClick:()=>{var l;t!=null&&t.accessToken&&((l=navigator==null?void 0:navigator.clipboard)!=null&&l.writeText?navigator.clipboard.writeText(t.accessToken).then(()=>s.ue.success("Token copied to clipboard")).catch(()=>s.ue.error("Unable to copy token")):s.ue.error("Clipboard not available"))},className:"h-7 p-2",children:e.jsx(s.Copy,{className:"h-4 w-4"})}),e.jsx(s.IconButton,{tooltip:"Invalidate Token",onClick:()=>s.invalidateToken(o.apiServiceUrl),className:"h-7 p-2",children:e.jsx(Bs,{className:"h-4 w-4"})})]}),!D&&c&&e.jsx(s.DownloadPdf,{}),!D&&c&&e.jsx(O.NotificationBell,{}),!D&&c&&((We=B==null?void 0:B.permissions)==null?void 0:We.canShare)&&e.jsx(s.IconButton,{tooltip:"Share Dashboard",onClick:()=>N(!0),className:"h-7 p-2",children:e.jsx(s.Share2,{className:"h-4 w-4"})}),!D&&d&&i.canUseFilters&&c&&e.jsx(O.DashboardFilterControlsButton,{showFilters:ae,onToggleFilters:()=>{ae||Oe("dashboard",!1),Pe(!ae)},onAddFilter:()=>{ae||(Oe("dashboard",!1),Pe(!0))},onAddControl:()=>{Ge("create")},onManageControls:()=>Ge("manage")}),d&&!D&&c&&Z?e.jsx(O.DashboardControlsSettings,{open:!0,onOpenChange:l=>{l||q(null)},showTrigger:!1,initialMode:Z}):null,d&&!D&&oe&&r&&c&&e.jsx(Js,{}),!D&&oe&&r&&c&&e.jsx(Xs,{}),d&&!D&&oe&&h&&r&&c&&e.jsxs(s.Button,{className:"h-7 p-2",variant:"secondary",disabled:v,onClick:Es,size:"sm",children:[e.jsx(Ye.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:()=>js(),children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Visual"]}),!D&&!d&&te&&c&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",onClick:Ds,size:"sm",children:[e.jsx(s.Pencil,{className:"mr-2 h-4 w-4"}),"Edit"]}),$e&&c&&Be&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",onClick:As,size:"sm",disabled:Q,children:[e.jsx(s.Undo2,{className:"mr-2 h-4 w-4"}),"Undo"]}),$e&&c&&e.jsxs("div",{className:"relative inline-flex",children:[e.jsxs(s.Button,{className:s.cn("h-7 p-2",!ye&&"opacity-60"),disabled:Q||!ye,onClick:()=>Se(),size:"sm",children:[Q?e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(Ye.Save,{className:"mr-2 h-4 w-4"}),Q?"Saving...":"Save"]}),ye&&!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:()=>Ue(!ps),size:"sm",variant:"ghost",children:e.jsx(s.Code,{className:"h-4 w-4"})})}),!D&&r&&e.jsx(Ks,{}),d&&!D&&c&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",onClick:ws,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-8 w-8 rounded-md border border-transparent p-0 text-muted-foreground hover:bg-muted/50 hover:text-foreground",buttonProps:{"aria-label":"More dashboard options"},children:e.jsx(s.EllipsisVertical,{className:"h-4 w-4"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-56 rounded-xl border border-border/60 p-1 shadow-sm",children:[e.jsx(s.DropdownMenuLabel,{className:"px-2.5 text-xs font-medium text-muted-foreground",children:"Automation"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>_(!0),className:"flex items-center gap-2",children:[e.jsx(s.Clock,{className:"mr-2 h-4 w-4"}),"Schedule Dashboard"]}),e.jsx(s.DropdownMenuSeparator,{}),bs&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuLabel,{className:"px-2.5 text-xs font-medium text-muted-foreground",children:"Access"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>k(!0),className:"flex items-center gap-2",children:[e.jsx(s.Users,{className:"mr-2 h-4 w-4"}),"Manage Groups"]}),e.jsx(s.DropdownMenuSeparator,{})]}),e.jsx(s.DropdownMenuLabel,{className:"px-2.5 text-xs font-medium text-muted-foreground",children:"Preferences"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>F(!0),className:"flex items-center gap-2",children:[e.jsx(s.Calendar,{className:"mr-2 h-4 w-4"}),"Calendar Preferences"]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>R(!0),className:"flex items-center gap-2",children:[e.jsx(s.FileText,{className:"mr-2 h-4 w-4"}),"Summary Settings"]})]})]}),y&&Re&&e.jsx(s.ShareDialog,{resource:Re,resourceType:s.ResourceType.DASHBOARD,onClose:()=>N(!1)}),e.jsx(jt,{open:I,onOpenChange:k}),(n==null?void 0:n.id)&&e.jsx(s.EmailScheduleDialog,{open:E,onOpenChange:_,dashboardId:n.id,dashboardName:n==null?void 0:n.title}),e.jsx(Xe.CalendarPreferencesDialog,{open:U,onOpenChange:F}),e.jsx(Xe.DashboardSummarySettingsDialog,{open:S,onOpenChange:R,dashboard:n,disabled:!d,onApply:l=>be({...n,summary:l})}),e.jsx(s.AlertDialog,{open:ue,onOpenChange:l=>{!l&&ge&&!w||(f(l),l||(M(null),G([]),ee(!1)))},children:e.jsxs(s.AlertDialogContent,{className:"max-w-sm",children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:w?"Save failed":"Saving dashboard"}),e.jsx(s.AlertDialogDescription,{className:"pt-2",children:w?"We could not save the dashboard. Please try again.":"Please wait while we save your changes."}),P.length>0&&e.jsxs("div",{className:"space-y-1 rounded-md border border-destructive/20 bg-destructive/5 p-3 text-left",children:[e.jsx("div",{className:"text-sm font-medium text-destructive",children:"What needs attention"}),e.jsx("ul",{className:"list-disc space-y-1 pl-4 text-xs text-muted-foreground",children:P.slice(0,5).map(l=>e.jsx("li",{children:l},l))})]})]}),e.jsx(s.AlertDialogFooter,{className:"flex-col gap-2 sm:flex-row sm:justify-end",children:w?e.jsxs(e.Fragment,{children:[e.jsx(s.AlertDialogCancel,{onClick:()=>{f(!1),M(null),G([]),ee(!1)},className:"m-0",children:"Close"}),e.jsx(s.AlertDialogAction,{onClick:()=>Se({closeAfterSave:H,navigateHomeAfterSave:xe==="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(O.UnsavedChangesAlert,{open:ys,onOpenChange:l=>{V(l)},onSave:Cs,onDiscard:Ms,isSaving:ge,saveLabel:"Save",discardLabel:"Discard"})]})]})}exports.default=Dt;