react-semaphor 0.1.293 → 0.1.295
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.
- package/dist/chunks/{braces-BwW2HFlB.js → braces-BdoTYzuj.js} +1 -1
- package/dist/chunks/{braces-C7GP95Fp.js → braces-DWldEFn5.js} +1 -1
- package/dist/chunks/{dashboard-controls-DgUc38Tn.js → dashboard-controls-B3lrnI_r.js} +9 -9
- package/dist/chunks/{dashboard-controls-jrkoCSY_.js → dashboard-controls-D7U6E1sB.js} +504 -472
- package/dist/chunks/dashboard-filter-controls-button-D0AsV28-.js +11 -0
- package/dist/chunks/dashboard-filter-controls-button-XwenlcXw.js +1152 -0
- package/dist/chunks/{dashboard-json-COjT-zjQ.js → dashboard-json-CU55qPXj.js} +1 -1
- package/dist/chunks/{dashboard-json-C0NiRL-A.js → dashboard-json-V6m6lJ_c.js} +1 -1
- package/dist/chunks/{dashboard-summary-settings-dialog-CGuFl7Xe.js → dashboard-summary-settings-dialog-0CIiWsKc.js} +1 -1
- package/dist/chunks/{dashboard-summary-settings-dialog-CXqaN_zj.js → dashboard-summary-settings-dialog-DRLPzp1P.js} +1 -1
- package/dist/chunks/{edit-dashboard-visual-ppdXk86H.js → edit-dashboard-visual-8ha6EM_g.js} +2205 -2147
- package/dist/chunks/edit-dashboard-visual-sSLAkmgf.js +183 -0
- package/dist/chunks/{index-9z-jMqN8.js → index-14M0TnH6.js} +35272 -33064
- package/dist/chunks/index-Ze8VskG1.js +1435 -0
- package/dist/chunks/{resource-management-panel-CP8cegZP.js → resource-management-panel-BL5-5ouC.js} +64 -64
- package/dist/chunks/{resource-management-panel-os6AuEKT.js → resource-management-panel-CcDAn86l.js} +1 -1
- package/dist/chunks/use-create-flow-overlay-state-BbQVNDCj.js +21 -0
- package/dist/chunks/{use-create-flow-overlay-state-wpuqRZX5.js → use-create-flow-overlay-state-D3PxfjYv.js} +430 -425
- package/dist/chunks/use-visual-utils-CdIOq4nt.js +337 -0
- package/dist/chunks/use-visual-utils-kh8p2QFm.js +1 -0
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +258 -253
- package/dist/style.css +1 -1
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +2 -2
- package/dist/types/dashboard.d.ts +65 -0
- package/dist/types/main.d.ts +79 -4
- package/dist/types/shared.d.ts +40 -0
- package/dist/types/surfboard.d.ts +65 -0
- package/dist/types/types.d.ts +65 -0
- package/package.json +1 -1
- package/dist/chunks/dashboard-filter-controls-button-B19UWmsK.js +0 -11
- package/dist/chunks/dashboard-filter-controls-button-DGH4DxJ8.js +0 -1109
- package/dist/chunks/edit-dashboard-visual-CDOz4LWO.js +0 -183
- package/dist/chunks/index-K25f5Rqr.js +0 -1435
- package/dist/chunks/use-create-flow-overlay-state-CecnMS_v.js +0 -21
- package/dist/chunks/use-visual-utils-BTfG-ppd.js +0 -1
- package/dist/chunks/use-visual-utils-BhRKGJql.js +0 -334
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-Ze8VskG1.js"),f=require("react");require("react-dom");const R=require("./dashboard-filter-controls-button-D0AsV28-.js"),Qs=require("./date-formatter-CqXdM6JO.js"),is=require("./dashboard-summary-settings-dialog-DRLPzp1P.js"),Ws=require("./use-debounced-dirty-check-XHSwAefL.js"),Ie=require("./normalize-dashboard-for-dirty-check-BXRUMVb2.js"),ls=require("./use-create-flow-overlay-state-BbQVNDCj.js"),Js=require("./braces-DWldEFn5.js");function Ys(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const a=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(n,r,a.get?a:{enumerable:!0,get:()=>t[r]})}}return n.default=t,Object.freeze(n)}const w=Ys(f);/**
|
|
2
2
|
* @license lucide-react v0.453.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
5
5
|
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const
|
|
6
|
+
*/const Xs=s.createLucideIcon("Glasses",[["circle",{cx:"6",cy:"15",r:"4",key:"vux9w4"}],["circle",{cx:"18",cy:"15",r:"4",key:"18o8ve"}],["path",{d:"M14 15a2 2 0 0 0-2-2 2 2 0 0 0-2 2",key:"1ag4bs"}],["path",{d:"M2.5 13 5 7c.7-1.3 1.4-2 3-2",key:"1hm1gs"}],["path",{d:"M21.5 13 19 7c-.7-1.3-1.5-2-3-2",key:"1r31ai"}]]);/**
|
|
7
7
|
* @license lucide-react v0.453.0 - ISC
|
|
8
8
|
*
|
|
9
9
|
* This source code is licensed under the ISC license.
|
|
10
10
|
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/const
|
|
11
|
+
*/const Zs=s.createLucideIcon("Menu",[["line",{x1:"4",x2:"20",y1:"12",y2:"12",key:"1e0a9i"}],["line",{x1:"4",x2:"20",y1:"6",y2:"6",key:"1owob3"}],["line",{x1:"4",x2:"20",y1:"18",y2:"18",key:"yk5zj1"}]]);/**
|
|
12
12
|
* @license lucide-react v0.453.0 - ISC
|
|
13
13
|
*
|
|
14
14
|
* This source code is licensed under the ISC license.
|
|
15
15
|
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
-
*/const
|
|
16
|
+
*/const et=s.createLucideIcon("Monitor",[["rect",{width:"20",height:"14",x:"2",y:"3",rx:"2",key:"48i651"}],["line",{x1:"8",x2:"16",y1:"21",y2:"21",key:"1svkeh"}],["line",{x1:"12",x2:"12",y1:"17",y2:"21",key:"vw1qmm"}]]);/**
|
|
17
17
|
* @license lucide-react v0.453.0 - ISC
|
|
18
18
|
*
|
|
19
19
|
* This source code is licensed under the ISC license.
|
|
20
20
|
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
-
*/const
|
|
21
|
+
*/const st=s.createLucideIcon("Moon",[["path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z",key:"a7tn18"}]]);/**
|
|
22
22
|
* @license lucide-react v0.453.0 - ISC
|
|
23
23
|
*
|
|
24
24
|
* This source code is licensed under the ISC license.
|
|
25
25
|
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
-
*/const
|
|
26
|
+
*/const tt=s.createLucideIcon("ShieldX",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m14.5 9.5-5 5",key:"17q4r4"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]]);/**
|
|
27
27
|
* @license lucide-react v0.453.0 - ISC
|
|
28
28
|
*
|
|
29
29
|
* This source code is licensed under the ISC license.
|
|
30
30
|
* See the LICENSE file in the root directory of this source tree.
|
|
31
|
-
*/const
|
|
31
|
+
*/const at=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 Te={exports:{}},ke={};/**
|
|
32
32
|
* @license React
|
|
33
33
|
* use-sync-external-store-shim.production.js
|
|
34
34
|
*
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
*
|
|
37
37
|
* This source code is licensed under the MIT license found in the
|
|
38
38
|
* LICENSE file in the root directory of this source tree.
|
|
39
|
-
*/var
|
|
39
|
+
*/var cs;function rt(){if(cs)return ke;cs=1;var t=f;function n(u,o){return u===o&&(u!==0||1/u===1/o)||u!==u&&o!==o}var r=typeof Object.is=="function"?Object.is:n,a=t.useState,l=t.useEffect,c=t.useLayoutEffect,h=t.useDebugValue;function m(u,o){var p=o(),g=a({inst:{value:p,getSnapshot:o}}),S=g[0].inst,y=g[1];return c(function(){S.value=p,S.getSnapshot=o,x(S)&&y({inst:S})},[u,p,o]),l(function(){return x(S)&&y({inst:S}),u(function(){x(S)&&y({inst:S})})},[u]),h(p),p}function x(u){var o=u.getSnapshot;u=u.value;try{var p=o();return!r(u,p)}catch{return!0}}function b(u,o){return o()}var d=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?b:m;return ke.useSyncExternalStore=t.useSyncExternalStore!==void 0?t.useSyncExternalStore:d,ke}var Oe={};/**
|
|
40
40
|
* @license React
|
|
41
41
|
* use-sync-external-store-shim.development.js
|
|
42
42
|
*
|
|
@@ -44,4 +44,4 @@
|
|
|
44
44
|
*
|
|
45
45
|
* This source code is licensed under the MIT license found in the
|
|
46
46
|
* LICENSE file in the root directory of this source tree.
|
|
47
|
-
*/var ls;function tt(){return ls||(ls=1,process.env.NODE_ENV!=="production"&&function(){function t(p,g){return p===g&&(p!==0||1/p===1/g)||p!==p&&g!==g}function n(p,g){d||l.startTransition===void 0||(d=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var S=g();if(!u){var j=g();c(S,j)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),u=!0)}j=h({inst:{value:S,getSnapshot:g}});var N=j[0].inst,C=j[1];return x(function(){N.value=S,N.getSnapshot=g,r(N)&&C({inst:N})},[p,S,g]),m(function(){return r(N)&&C({inst:N}),p(function(){r(N)&&C({inst:N})})},[p]),b(S),S}function r(p){var g=p.getSnapshot;p=p.value;try{var S=g();return!c(p,S)}catch{return!0}}function a(p,g){return g()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var l=f,c=typeof Object.is=="function"?Object.is:t,h=l.useState,m=l.useEffect,x=l.useLayoutEffect,b=l.useDebugValue,d=!1,u=!1,o=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?a:n;Ie.useSyncExternalStore=l.useSyncExternalStore!==void 0?l.useSyncExternalStore:o,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()),Ie}process.env.NODE_ENV==="production"?ke.exports=st():ke.exports=tt();var at=ke.exports;const fe=["light","dark","system"];function rt(){const{theme:t,setTheme:n}=s.useTheme(),r=s.useDashboardStore(h=>h.actions.setDashboardTheme);function a(){const h=fe.includes(t)?t:"system",m=fe[(fe.indexOf(h)+1)%fe.length];n(m),r(m)}const l=t==="light"?et:t==="dark"?Xs:Ys,c=t==="light"?"Theme: light (click for dark)":t==="dark"?"Theme: dark (click for system)":"Theme: system (click for light)";return e.jsx(s.Button,{type:"button",variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:a,"aria-label":c,title:c,children:e.jsx(l,{className:"h-3.5 w-3.5",strokeWidth:1.5})})}async function nt(t,n,r,a,l){if(!l)return null;const c=JSON.stringify(r),h=`${t}/v1/lens`;return await s.postRequest(h,l,{name:n,template:c,filterValues:a,operation:"create"})}async function Oe(t,n,r){if(!r)return null;const{id:a,template:l,filterValues:c,isDefault:h,shared:m}=n,x=`${t}/v1/lens`;return await s.postRequest(x,r,{lensId:a,template:l,filterValues:c,isDefault:h,shared:m,operation:"update"})}async function ot(t,n,r){if(!r)return null;const a=`${t}/v1/lens`;return await s.postRequest(a,r,{operation:"delete",lensId:n})}const it="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function lt({open:t,onOpenChange:n}={}){const[r,a]=f.useState(""),[l,c]=f.useState(!1),h=s.useDashboardStore(y=>y.lenses),{setLenses:m,setSelectedLensId:x}=s.useDashboardActions(),[b,d]=f.useState(!1),[u,o]=f.useState(!1),p=t!==void 0,g=p?t:u,S=y=>{p||o(y),n==null||n(y)},j=s.useDashboardStore(y=>y.dashboard),N=s.useDashboardStore(y=>y.filterValues),{authToken:C,tokenProps:O}=s.useSemaphorContext();async function E(){d(!0);const y=await nt(O.apiServiceUrl,r,j,N,C==null?void 0:C.accessToken);y&&(m([...h||[],y]),x(y.id),S(!1)),d(!1)}return e.jsxs(s.Dialog,{open:g,onOpenChange:S,children:[p?null:e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"secondary",size:"xs",children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Lens"]})}),e.jsxs(s.DialogContent,{className:"rounded-[6px] border-border/60 sm:max-w-[420px] sm:rounded-[6px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{className:"text-[15px]",children:"Create lens"}),e.jsx(s.DialogDescription,{className:"text-[13px] leading-5",children:"Lenses are private by default and are only visible to you."})]}),e.jsxs("div",{className:"space-y-1.5 py-1",children:[e.jsx(s.Label,{htmlFor:"lens-name",className:it,children:"Name"}),e.jsx(s.Input,{id:"lens-name",size:"xs",value:r,placeholder:"Monthly review, West region, …",onChange:y=>a(y.target.value)}),l&&e.jsx("p",{className:"text-[12px] text-destructive",children:"A lens with this name already exists. Pick a different one."})]}),e.jsxs(s.DialogFooter,{children:[e.jsx(s.Button,{variant:"outline",size:"xs",onClick:()=>S(!1),children:"Cancel"}),e.jsx(s.Button,{size:"xs",type:"submit",onClick:E,disabled:b||!r.trim(),children:b?"Creating…":"Create"})]})]})]})}function ct({includeLabel:t=!1}={}){const n=s.useDashboardStore(d=>d.lenses),r=s.useDashboardStore(d=>d.selectedLensId),{setLenses:a,setSelectedLensId:l}=s.useDashboardActions(),{authToken:c,tokenProps:h}=s.useSemaphorContext();async function m(d){l(d)}async function x(d){if(await ot(h.apiServiceUrl,d,c==null?void 0:c.accessToken)){const o=n==null?void 0:n.filter(p=>p.id!==d);a(o||[]),l("original")}}async function b(d){const u=n==null?void 0:n.map(g=>g.id===d.id?{...g,isDefault:!d.isDefault}:{...g,isDefault:!1});a(u||[]);const o={...d,isDefault:!d.isDefault};await Oe(h.apiServiceUrl,o,c==null?void 0:c.accessToken);const p=n==null?void 0:n.find(g=>g.isDefault);if(p&&p.id!==d.id){const g={...p,isDefault:!1};await Oe(h.apiServiceUrl,g,c==null?void 0:c.accessToken)}}return e.jsxs(e.Fragment,{children:[t?e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(s.DropdownMenuSeparator,{})]}):null,e.jsxs(s.DropdownMenuRadioGroup,{value:r,onValueChange:m,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),n==null?void 0:n.map(d=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:d.id,children:[e.jsx("p",{children:d.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(s.House,{onClick:u=>{u.preventDefault(),b(d)},className:s.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!d.isDefault,"text-green-500":d.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:u=>{u.preventDefault(),x(d.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},d.id))]})]})}function dt(){const{displayPreferences:t,shouldShowElement:n}=s.useDisplayPreferences(),{currentUser:r,userContext:a}=s.useCurrentUserInfo(),l=f.useMemo(()=>s.getRoleBasedDisplayOverrides(r),[r]),c=f.useMemo(()=>m=>l&&l[m]!==void 0&&l[m]===!1?!1:n(m),[l,n,t]),h=f.useMemo(()=>{var m,x,b,d,u;return{canEdit:((m=a==null?void 0:a.permissions)==null?void 0:m.canEdit)??s.canUserEdit(r),canUseFilters:((x=a==null?void 0:a.permissions)==null?void 0:x.canEdit)??s.canUserUseFilters(r),canManageDashboards:((b=a==null?void 0:a.permissions)==null?void 0:b.canCreateDashboard)??s.canUserManageDashboards(r),canCreateDashboards:((d=a==null?void 0:a.permissions)==null?void 0:d.canCreateDashboard)??s.canUserCreateDashboards(r),canAccessVisuals:((u=a==null?void 0:a.permissions)==null?void 0:u.canEdit)??s.canUserAccessVisuals(r)}},[r,a]);return{displayPreferences:t,shouldShowElement:c,permissions:h,currentUser:r}}const ut=async(t,n,r)=>{const a=`${t}/management/v1/groups`;return await s.postRequestRegular(a,n,r)},mt=async(t,n,r)=>{const a=`${t}/management/v1/groups/${r}`;await s.requestJsonRegular(a,n,"DELETE")},ht=async(t,n,r,a)=>{const l=`${t}/management/v1/groups/${r}/members`;return await s.postRequestRegular(l,n,a)},pt=async(t,n,r,a)=>{const l=`${t}/management/v1/groups/${r}/members`;await s.requestJsonRegular(l,n,"DELETE",a)};function xt(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:a=>ut(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",a),onSuccess:()=>{r.invalidateQueries({queryKey:["groups"]}),s.ue.success("Group created successfully")},onError:a=>{console.error("Failed to create group:",a),s.ue.error("Failed to create group",{description:s.getRequestErrorMessage(a,"Failed to create group")})}})}function ft(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:a=>mt(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",a),onSuccess:(a,l)=>{r.invalidateQueries({queryKey:["groups"]}),r.removeQueries({queryKey:["group",l]}),s.ue.success("Group deleted successfully")},onError:a=>{console.error("Failed to delete group:",a),s.ue.error("Failed to delete group",{description:s.getRequestErrorMessage(a,"Failed to delete group")})}})}function gt(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:({groupId:a,data:l})=>ht(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",a,l),onSuccess:(a,l)=>{r.invalidateQueries({queryKey:["group",l.groupId]}),r.invalidateQueries({queryKey:["group-members",l.groupId]}),r.invalidateQueries({queryKey:["groups"]}),s.ue.success("Members added successfully")},onError:a=>{console.error("Failed to add group members:",a),s.ue.error("Failed to add members",{description:s.getRequestErrorMessage(a,"Failed to add members")})}})}function bt(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:({groupId:a,data:l})=>pt(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",a,l),onSuccess:(a,l)=>{r.invalidateQueries({queryKey:["group",l.groupId]}),r.invalidateQueries({queryKey:["group-members",l.groupId]}),r.invalidateQueries({queryKey:["groups"]}),s.ue.success("Members removed successfully")},onError:a=>{console.error("Failed to remove group members:",a),s.ue.error("Failed to remove members",{description:s.getRequestErrorMessage(a,"Failed to remove members")})}})}const cs="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function vt({onSuccess:t,tenantId:n,isTenantUser:r}){const[a,l]=f.useState(""),[c,h]=f.useState(""),[m,x]=f.useState({}),b=xt(),d=()=>{const o={};return a.trim()?a.length<3?o.name="Group name must be at least 3 characters":a.length>50&&(o.name="Group name must be less than 50 characters"):o.name="Group name is required",c&&c.length>200&&(o.description="Description must be less than 200 characters"),x(o),Object.keys(o).length===0},u=async o=>{if(o.preventDefault(),!d())return;const p={name:a.trim(),description:c.trim()||void 0,type:r?"TENANT_GROUP":"ORG_GROUP",...r&&n?{tenantId:n}:{}};try{await b.mutateAsync(p),l(""),h(""),x({}),t()}catch(g){console.error("Failed to create group:",g)}};return e.jsxs("form",{onSubmit:u,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(s.Label,{htmlFor:"group-name",className:cs,children:["Group name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(s.Input,{id:"group-name",size:"xs",placeholder:"e.g., Marketing Team, Engineering Squad",value:a,onChange:o=>{l(o.target.value),m.name&&x(p=>({...p,name:""}))},className:m.name?"border-destructive":"",disabled:b.isPending}),m.name&&e.jsx("p",{className:"text-[12px] text-destructive",children:m.name})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{htmlFor:"group-description",className:cs,children:"Description (optional)"}),e.jsx(s.Textarea,{id:"group-description",placeholder:"Describe the purpose of this group…",value:c,onChange:o=>{h(o.target.value),m.description&&x(p=>({...p,description:""}))},className:`text-[13px] ${m.description?"border-destructive":""}`,disabled:b.isPending,rows:3}),m.description?e.jsx("p",{className:"text-[12px] text-destructive",children:m.description}):e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[c.length,"/200"]})]}),e.jsxs("div",{className:"flex gap-2 text-[12px] text-muted-foreground",children:[e.jsx(s.Info,{className:"h-3.5 w-3.5 shrink-0 mt-0.5"}),e.jsx("p",{children:"This group will be accessible to users in your workspace. You can add members after creating it."})]}),e.jsxs("div",{className:"flex justify-end gap-1.5 pt-1",children:[e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:()=>{l(""),h(""),x({})},disabled:b.isPending,children:"Clear"}),e.jsx(s.Button,{type:"submit",size:"xs",disabled:b.isPending||!a.trim(),children:b.isPending?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Creating…"]}):"Create group"})]})]})}function St(t,n=[]){let r=[];function a(c,h){const m=w.createContext(h);m.displayName=c+"Context";const x=r.length;r=[...r,h];const b=u=>{var N;const{scope:o,children:p,...g}=u,S=((N=o==null?void 0:o[t])==null?void 0:N[x])||m,j=w.useMemo(()=>g,Object.values(g));return e.jsx(S.Provider,{value:j,children:p})};b.displayName=c+"Provider";function d(u,o){var S;const p=((S=o==null?void 0:o[t])==null?void 0:S[x])||m,g=w.useContext(p);if(g)return g;if(h!==void 0)return h;throw new Error(`\`${u}\` must be used within \`${c}\``)}return[b,d]}const l=()=>{const c=r.map(h=>w.createContext(h));return function(m){const x=(m==null?void 0:m[t])||c;return w.useMemo(()=>({[`__scope${t}`]:{...m,[t]:x}}),[m,x])}};return l.scopeName=t,[a,jt(l,...n)]}function jt(...t){const n=t[0];if(t.length===1)return n;const r=()=>{const a=t.map(l=>({useScope:l(),scopeName:l.scopeName}));return function(c){const h=a.reduce((m,{useScope:x,scopeName:b})=>{const u=x(c)[`__scope${b}`];return{...m,...u}},{});return w.useMemo(()=>({[`__scope${n.scopeName}`]:h}),[h])}};return r.scopeName=n.scopeName,r}var yt=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Te=yt.reduce((t,n)=>{const r=s.createSlot(`Primitive.${n}`),a=w.forwardRef((l,c)=>{const{asChild:h,...m}=l,x=h?r:n;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(x,{...m,ref:c})});return a.displayName=`Primitive.${n}`,{...t,[n]:a}},{});function Dt(){return at.useSyncExternalStore(Nt,()=>!0,()=>!1)}function Nt(){return()=>{}}var Pe="Avatar",[wt]=St(Pe),[Ct,us]=wt(Pe),ms=w.forwardRef((t,n)=>{const{__scopeAvatar:r,...a}=t,[l,c]=w.useState("idle");return e.jsx(Ct,{scope:r,imageLoadingStatus:l,onImageLoadingStatusChange:c,children:e.jsx(Te.span,{...a,ref:n})})});ms.displayName=Pe;var hs="AvatarImage",ps=w.forwardRef((t,n)=>{const{__scopeAvatar:r,src:a,onLoadingStatusChange:l=()=>{},...c}=t,h=us(hs,r),m=Mt(a,c),x=s.useCallbackRef(b=>{l(b),h.onImageLoadingStatusChange(b)});return s.useLayoutEffect2(()=>{m!=="idle"&&x(m)},[m,x]),m==="loaded"?e.jsx(Te.img,{...c,ref:n,src:a}):null});ps.displayName=hs;var xs="AvatarFallback",fs=w.forwardRef((t,n)=>{const{__scopeAvatar:r,delayMs:a,...l}=t,c=us(xs,r),[h,m]=w.useState(a===void 0);return w.useEffect(()=>{if(a!==void 0){const x=window.setTimeout(()=>m(!0),a);return()=>window.clearTimeout(x)}},[a]),h&&c.imageLoadingStatus!=="loaded"?e.jsx(Te.span,{...l,ref:n}):null});fs.displayName=xs;function ds(t,n){return t?n?(t.src!==n&&(t.src=n),t.complete&&t.naturalWidth>0?"loaded":"loading"):"error":"idle"}function Mt(t,{referrerPolicy:n,crossOrigin:r}){const a=Dt(),l=w.useRef(null),c=a?(l.current||(l.current=new window.Image),l.current):null,[h,m]=w.useState(()=>ds(c,t));return s.useLayoutEffect2(()=>{m(ds(c,t))},[c,t]),s.useLayoutEffect2(()=>{const x=u=>()=>{m(u)};if(!c)return;const b=x("loaded"),d=x("error");return c.addEventListener("load",b),c.addEventListener("error",d),n&&(c.referrerPolicy=n),typeof r=="string"&&(c.crossOrigin=r),()=>{c.removeEventListener("load",b),c.removeEventListener("error",d)}},[c,r,n]),h}var gs=ms,bs=ps,vs=fs;const Fe=w.forwardRef(({className:t,...n},r)=>e.jsx(gs,{ref:r,className:s.cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",t),...n}));Fe.displayName=gs.displayName;const Lt=w.forwardRef(({className:t,...n},r)=>e.jsx(bs,{ref:r,className:s.cn("aspect-square h-full w-full",t),...n}));Lt.displayName=bs.displayName;const _e=w.forwardRef(({className:t,...n},r)=>e.jsx(vs,{ref:r,className:s.cn("flex h-full w-full items-center justify-center rounded-full bg-muted",t),...n}));_e.displayName=vs.displayName;function Et({open:t,onOpenChange:n,group:r,onUpdate:a}){const[l,c]=f.useState("members"),[h,m]=f.useState(""),[x,b]=f.useState([]),[d,u]=f.useState([]),{data:o,isLoading:p,refetch:g}=s.useGroupMembers(r.id),S=r.type==="TENANT_GROUP"?"tenant":"organization",{users:j,isLoading:N}=s.useUnifiedUsers({type:S,tenantId:r.tenantId||void 0,active:!0,limit:100}),C=gt(),O=bt(),E=(o==null?void 0:o.members)||[],y=f.useMemo(()=>new Set(E.map(v=>v.userId)),[E]),T=f.useMemo(()=>j.filter(v=>!y.has(v.id)),[j,y]),$=f.useMemo(()=>{if(!h)return T;const v=h.toLowerCase();return T.filter(M=>{var k,P;return((k=M.name)==null?void 0:k.toLowerCase().includes(v))||((P=M.email)==null?void 0:P.toLowerCase().includes(v))})},[T,h]),D=f.useMemo(()=>{if(!h)return E;const v=h.toLowerCase();return E.filter(M=>{var k,P,ee,U;return((P=(k=M.user)==null?void 0:k.name)==null?void 0:P.toLowerCase().includes(v))||((U=(ee=M.user)==null?void 0:ee.email)==null?void 0:U.toLowerCase().includes(v))})},[E,h]),q=async()=>{if(x.length!==0)try{await C.mutateAsync({groupId:r.id,data:{userIds:x,userType:S==="tenant"?"tenant":"org"}}),b([]),c("members"),g(),a==null||a()}catch(v){console.error("Failed to add members:",v)}},X=async()=>{if(d.length!==0)try{await O.mutateAsync({groupId:r.id,data:{userIds:d}}),u([]),g(),a==null||a()}catch(v){console.error("Failed to remove members:",v)}},ge=v=>{b(M=>M.includes(v)?M.filter(k=>k!==v):[...M,v])},Z=v=>{u(M=>M.includes(v)?M.filter(k=>k!==v):[...M,v])};return e.jsx(e.Fragment,{children:e.jsx(s.Dialog,{open:t,onOpenChange:n,children:e.jsxs(s.DialogContent,{className:"max-w-3xl max-h-[80vh]","aria-describedby":"group-members-description",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:r.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 ",r.name," group"]})]}),e.jsxs(s.Tabs,{value:l,onValueChange:v=>{c(v),m(""),u([])},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:h,onChange:v=>m(v.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:d.length>0?"h-[300px]":"h-[350px]",children:p?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(v=>e.jsx(s.Skeleton,{className:"h-16 w-full"},v))}):D.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:h?"No members found":"No members yet"}),e.jsx("p",{className:"text-xs mt-1",children:h?"Try a different search":'Switch to the "Add Members" tab to add people to this group'})]}):e.jsx("div",{className:"space-y-2",children:D.map(v=>e.jsx(At,{member:v,selected:d.includes(v.userId),onToggle:()=>Z(v.userId)},v.id))})}),d.length>0&&e.jsxs("div",{className:"flex items-center justify-between pt-4 border-t",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[d.length," member",d.length!==1?"s":""," selected"]}),e.jsx(s.Button,{variant:"destructive",size:"sm",onClick:X,disabled:O.isPending,children:O.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:h,onChange:v=>m(v.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(v=>e.jsx(s.Skeleton,{className:"h-16 w-full"},v))}):$.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:h?"Try a different search":"All eligible users are already members"})]}):e.jsx("div",{className:"space-y-2",children:$.map(v=>e.jsx(It,{user:v,selected:x.includes(v.id),onToggle:()=>ge(v.id)},v.id))})}),x.length>0&&e.jsxs("div",{className:"flex items-center justify-between pt-4 border-t",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[x.length," user",x.length!==1?"s":""," selected"]}),e.jsx(s.Button,{onClick:q,disabled:C.isPending,children:C.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 At({member:t,selected:n,onToggle:r}){var l,c,h,m;const a=((c=(l=t.user)==null?void 0:l.name)==null?void 0:c.split(" ").map(x=>x[0]).join("").toUpperCase())||"?";return e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg border bg-card hover:bg-muted/50 cursor-pointer",onClick:r,children:[e.jsx(s.Checkbox,{checked:n}),e.jsx(Fe,{className:"h-8 w-8",children:e.jsx(_e,{className:"text-xs",children:a})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:((h=t.user)==null?void 0:h.name)||"Unknown User"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(m=t.user)==null?void 0:m.email})]})]})}function It({user:t,selected:n,onToggle:r}){var l;const a=((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:r,children:[e.jsx(s.Checkbox,{checked:n}),e.jsx(Fe,{className:"h-8 w-8",children:e.jsx(_e,{className:"text-xs",children:a})}),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 kt({open:t,onOpenChange:n}){const[r,a]=f.useState("groups"),[l,c]=f.useState(""),[h,m]=f.useState(null),[x,b]=f.useState(!1),[d,u]=f.useState(null),{tokenProps:o}=s.useSemaphorContext(),{currentUser:p}=s.useCurrentUserInfo(),g=ft(),S=(p==null?void 0:p.type)==="tenant",j=o==null?void 0:o.tenantId,{groups:N,isLoading:C,refetch:O}=s.useGroups({type:S?"TENANT_GROUP":"all",tenantId:S?j:void 0,includeMembers:!1}),E=N.filter(D=>{var q;return D.name.toLowerCase().includes(l.toLowerCase())||((q=D.description)==null?void 0:q.toLowerCase().includes(l.toLowerCase()))}),y=async()=>{if(d)try{await g.mutateAsync(d.id),u(null),O()}catch(D){console.error("Failed to delete group:",D)}},T=D=>{m(D),b(!0)},$=()=>{a("groups"),O()};return e.jsxs(e.Fragment,{children:[e.jsx(s.Dialog,{open:t,onOpenChange:n,children:e.jsxs(s.DialogContent,{className:"max-h-[80vh] max-w-3xl rounded-[6px] border-border/60 sm:rounded-[6px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{className:"text-[15px]",children:"Group management"}),e.jsx(s.DialogDescription,{className:"text-[13px] leading-5",children:"Manage groups, create new ones, and control membership."})]}),e.jsxs(s.Tabs,{value:r,onValueChange:a,className:"mt-2",children:[e.jsxs(s.TabsList,{className:"h-8 w-full justify-start gap-1 bg-transparent p-0 border-b border-border/60 rounded-none",children:[e.jsx(s.TabsTrigger,{value:"groups",className:"h-8 rounded-none border-b-2 border-transparent bg-transparent px-3 text-[13px] data-[state=active]:border-foreground data-[state=active]:bg-transparent data-[state=active]:shadow-none",children:"Groups"}),e.jsx(s.TabsTrigger,{value:"create",className:"h-8 rounded-none border-b-2 border-transparent bg-transparent px-3 text-[13px] data-[state=active]:border-foreground data-[state=active]:bg-transparent data-[state=active]:shadow-none",children:"Create group"})]}),e.jsx(s.TabsContent,{value:"groups",className:"mt-4",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(s.Search,{className:"absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx(s.Input,{size:"xs",placeholder:"Search groups…",value:l,onChange:D=>c(D.target.value),className:"pl-7"})]}),e.jsx(s.ScrollArea,{className:"h-[400px]",children:C?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(D=>e.jsx(s.Skeleton,{className:"h-16 w-full rounded-[6px]"},D))}):E.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx("p",{className:"text-[13px]",children:"No groups found."}),e.jsx("p",{className:"mt-1 text-[12px]",children:l?"Try a different search.":"Create your first group to get started."})]}):e.jsx("div",{className:"space-y-2 pr-2",children:E.map(D=>e.jsx(Ot,{group:D,onManageMembers:()=>T(D),onDelete:()=>u(D),currentUserId:p==null?void 0:p.id},D.id))})})]})}),e.jsx(s.TabsContent,{value:"create",className:"mt-4",children:e.jsx(vt,{onSuccess:$,tenantId:j,isTenantUser:S})})]})]})}),h&&e.jsx(Et,{open:x,onOpenChange:b,group:h,onUpdate:()=>O()}),e.jsx(s.AlertDialog,{open:!!d,onOpenChange:()=>u(null),children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Delete group"}),e.jsxs(s.AlertDialogDescription,{children:['Delete "',d==null?void 0:d.name,`"? This removes all members and can't be undone.`]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:y,disabled:g.isPending,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:g.isPending?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Deleting…"]}):"Delete group"})]})]})})]})}function Ot({group:t,onManageMembers:n,onDelete:r,currentUserId:a}){const l=t.createdBy===a;return e.jsx("div",{className:"rounded-[6px] border border-border/60 bg-card px-3 py-2.5 transition-colors hover:bg-muted/30",children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[e.jsx("h4",{className:"text-[13px] font-medium text-foreground",children:t.name}),t.description&&e.jsx("p",{className:"text-[12px] text-muted-foreground",children:t.description}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-[11px] text-muted-foreground",children:[e.jsxs("span",{className:"inline-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 ",Hs.format(new Date(t.createdAt),"MMM d, yyyy")]})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[e.jsx(s.Button,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:n,title:"Manage members","aria-label":"Manage members",children:e.jsx(s.UserPlus,{className:"h-3.5 w-3.5"})}),l&&e.jsx(s.Button,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:bg-destructive/10 hover:text-destructive",onClick:r,title:"Delete group","aria-label":"Delete group",children:e.jsx(s.Trash2,{className:"h-3.5 w-3.5"})})]})]})})}function J(t,n,r){var c,h;const a=(t.controls||[]).find(m=>m.id===r);if(a)return a.label;const l=(h=(c=s.findCardById(t,n))==null?void 0:c.controls)==null?void 0:h.find(m=>m.id===r);return(l==null?void 0:l.label)||r}function Y(t,n){var r;return((r=s.findCardById(t,n))==null?void 0:r.title)||n}function Tt(t){const{errors:n,dashboard:r}=t;if(!r)return n;const a=new Map;for(const l of n){const c=l.match(/^Card '(.+)' binding for control '(.+)' maps to missing metric '(.+)'\.$/);if(c){const[,d,u]=c,o=`${d}:${u}:missing-metric`;a.has(o)||a.set(o,`"${Y(r,d)}" has an outdated "${J(r,d,u)}" mapping. Some choices still point to metrics that are no longer available on this card. Open the card controls and choose replacements.`);continue}const h=l.match(/^Card '(.+)' binding for control '(.+)' maps to missing group-by field '(.+)'\.$/);if(h){const[,d,u]=h,o=`${d}:${u}:missing-group-by`;a.has(o)||a.set(o,`"${Y(r,d)}" has an outdated "${J(r,d,u)}" 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=l.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid metric target\.$/);if(m){const[,d,u]=m,o=`${d}:${u}:invalid-metric`;a.has(o)||a.set(o,`"${Y(r,d)}" has an invalid "${J(r,d,u)}" metric mapping. Open the card controls and choose a valid metric for each option.`);continue}const x=l.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid group-by target\.$/);if(x){const[,d,u]=x,o=`${d}:${u}:invalid-group-by`;a.has(o)||a.set(o,`"${Y(r,d)}" has an invalid "${J(r,d,u)}" field mapping. Open the card controls and choose a valid field for each option.`);continue}const b=l.match(/^Card '(.+)' binding for control '(.+)' requires at least one temporal group-by field\.$/);if(b){const[,d,u]=b,o=`${d}:${u}:missing-temporal-group-by`;a.has(o)||a.set(o,`"${Y(r,d)}" can no longer use "${J(r,d,u)}" for time grain because the card does not currently group by a date field.`);continue}a.set(l,l)}return Array.from(a.values())}function Pt(){var es,ss,ts,as;R.useExportRecovery(),R.useExportPolling();const{authToken:t,tokenProps:n,id:r}=s.useSemaphorContext(),{isLocalDev:a}=s.useDashboardPreferences(),{permissions:l}=dt(),c=s.useHasDashboardId(),{isLoading:h}=s.useDashboardQuery();s.useDashboardStore(i=>i.theme);const m=s.useDashboardStore(i=>i.isDownloadingPdf),x=s.useDashboardStore(i=>i.dashboardAssistantDraftScopeKey),b=s.useDashboardStore(i=>i.lenses),d=s.useDashboardStore(i=>i.selectedLensId),u=b==null?void 0:b.find(i=>i.id===d),o=s.useDashboardStore(i=>i.dashboard);s.useDashboardStore(i=>i.selectedSheetId);const p=s.useDashboardStore(i=>i.isDashboardEditing),{setDashboardTitle:g}=s.useDashboardStore(i=>i.actions),[S,j]=f.useState(!1),[N,C]=f.useState(!1),[O,E]=f.useState(!1),[y,T]=f.useState(!1),[$,D]=f.useState(!1),[q,X]=f.useState(!1),[ge,Z]=f.useState(!1),[v,M]=f.useState(!1),[k,P]=f.useState(null),[ee,U]=f.useState(!1),[se,te]=f.useState(null),[Re,ae]=f.useState([]),[Ue,re]=f.useState(!1),Ss=s.useDashboardStore(i=>i.isDashboardPanelOpen),js=s.useDashboardStore(i=>i.actions.setIsDashboardPanelOpen),ys=s.useDashboardStore(i=>i.filterValues),A=s.useDashboardStore(i=>i.isVisualEditing);s.useEditorStore(i=>i.card);const z=s.useManagementStore(i=>i.selectedDashboard),ne=s.useManagementStore(i=>i.initialDashboard);s.useManagementStore(i=>i.selectedVisual),s.useDashboardStore(i=>i.selectedFrameId),s.useEditorStore(i=>i.frame);const oe=z?(ss=z==null?void 0:z.permissions)==null?void 0:ss.canEdit:(es=ne==null?void 0:ne.permissions)==null?void 0:es.canEdit,ie=s.useDashboardStore(i=>i.showFilters),Ge=s.useAssistantLayoutStore(i=>i.setPanelOpen),$e=s.useDashboardStore(i=>i.showDashboardJSON),be=s.useDashboardStore(i=>i.onSaveFunction),qe=s.useDashboardStore(i=>i.actions.setShowFilters),{setIsDashboardEditing:Be,setShowDashboardJSON:ze}=s.useDashboardStore(i=>i.actions),{setInitialDashboard:He,clearSelectedDashboard:ve}=s.useManagementStore(i=>i.actions),{resources:le}=s.useResourceManagement(s.ResourceType.DASHBOARD),{data:Se}=s.useUserPreferences(),Ds=((ts=Se==null?void 0:Se.preference)==null?void 0:ts.defaultDashboardId)||null,{mutate:Ns,isPending:ws}=s.useDefaultDashboardMutation(),{currentUser:Cs}=s.useCurrentUserInfo(),Ms=s.canUserManageGroups(Cs),B=z||ne,Ve=B?{id:B.id,title:(o==null?void 0:o.title)||B.title||"Dashboard"}:null,{handleAddNewFrame:Ls}=s.useAddNewFrame(),[je,ye]=f.useState(!1),[Es,H]=f.useState(!1),[De,ce]=f.useState("close"),V=s.useUpdateResource(s.ResourceType.DASHBOARD),[F,Ne]=f.useState(null),Ke=f.useCallback(i=>{window.setTimeout(()=>{P(i)},0)},[]),As=async(i,L)=>{if(!(o!=null&&o.id)){console.log("No dashboard ID found");return}console.log("Updating dashboard title:",{dashboardId:o.id,newTitle:i,previousTitle:L}),V.mutate({resourceId:o.id,data:{title:i}},{onSuccess:()=>{console.log("Dashboard title updated successfully"),s.ue.success("Dashboard title updated")},onError:_=>{console.error("Failed to update dashboard title:",_),s.ue.error("Failed to update dashboard title"),g(L)}})};f.useEffect(()=>{if(le&&le.length>0){const i=o==null?void 0:o.id;if(i){const L=le.find(_=>_.id===i);L&&He(L)}}},[le,o==null?void 0:o.id,He]);const K=n.orgUserId||n.tenantId,Qe=p&&!A&&K&&oe,{setDashboard:we}=s.useDashboardStore(i=>i.actions),Is=()=>{Be(!0)},Ce=()=>{Be(!1),ze(!1),Ne(null),P(null)};R.usePristineSnapshotInitializer(p,o,F,i=>Ne(i));const{isDirty:We,isDirtyPending:ks,resetDirty:de}=Vs.useDebouncedDirtyCheck(o,F,300,1e3,Ee.serializeDashboardForDirtyCheck),Je=f.useCallback(()=>F?Ee.serializeDashboardForDirtyCheck(o)!==Ee.serializeDashboardForDirtyCheck(F):!1,[o,F]),Ye=We||ks,ue=je||V.isPending,Os=()=>{Je()?(ce("close"),H(!0)):(Ce(),de())},Ts=async()=>{await Me({closeAfterSave:!0,navigateHomeAfterSave:De==="home"})},Ps=()=>{F&&we(F),Ce(),De==="home"&&ve(),ce("close"),H(!1),de()},Fs=()=>{F&&(we(F),de())},_s=()=>{if(p&&Je()){ce("home"),H(!0);return}ve()};async function Me(i){const L=s.useDashboardStore.getState().dashboard;if(!L)return;const _=(i==null?void 0:i.closeAfterSave)??Ue,qs=(i==null?void 0:i.navigateHomeAfterSave)??!1;re(_),_&&H(!1);const Bs=s.cloneDeep(L);U(!0),te(null),ae([]),ye(!0);const zs={template:L};V.mutate({resourceId:L.id,data:zs},{onSuccess:I=>{var he,pe,rs;const G=(I==null?void 0:I.id)||((he=I==null?void 0:I.dashboard)==null?void 0:he.id)||((pe=I==null?void 0:I.resource)==null?void 0:pe.id)||((rs=I==null?void 0:I.template)==null?void 0:rs.id)||null;if(!L.id&&G){const Le=s.useAIInteractionStore.getState(),xe=Le.pendingDashboardDraftMigration;(xe==null?void 0:xe.scopeKey)===x?Le.actions.setPendingDashboardDraftMigrationExpectedDashboardId(G):xe&&Le.actions.clearPendingDashboardDraftMigration()}ye(!1),s.ue.success("Dashboard saved!"),Ne(Bs),U(!1),re(!1),_&&(Ce(),de(),qs&&ve()),ce("close")},onError:I=>{ye(!1),te("Failed to save dashboard. Please try again.");const G=I.details,he=Array.isArray(G==null?void 0:G.errors)?(G.errors||[]).filter(pe=>typeof pe=="string"):[];ae(Tt({errors:he,dashboard:L||void 0})),s.ue.error("Failed to save dashboard")}})}async function Rs(){if(j(!0),!d||!u)return;const i=s.useDashboardStore.getState().dashboard;if(!i){j(!1);return}const L=JSON.stringify(i),_={...u,template:L,filterValues:ys};await Oe(n.apiServiceUrl,_,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),be==null||be(i),j(!1)}const Xe=(u==null?void 0:u.name)||o.title,Q=!!(o!=null&&o.id);V.isPending&&console.log("Title during update:",{title:Xe,dashboardStateTitle:o.title,dashboardId:o==null?void 0:o.id,currentLensName:u==null?void 0:u.name});const Ze=n.orgUserId||n.tenantId&&n.endUserId&&n.endUserEmail,Us=!!Ze&&!!(t!=null&&t.accessToken)&&!!(n!=null&&n.apiServiceUrl);f.useEffect(()=>{!Q&&y&&T(!1)},[Q,y]);const Gs=c,W=(o==null?void 0:o.id)||null,me=!!W&&Ds===W,$s=()=>{W&&Ns({dashboardId:me?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:()=>{js(!Ss)},className:"h-7 w-7 px-0",buttonProps:{size:"xs"},children:e.jsx(Js,{className:"h-3.5 w-3.5"})}),Gs&&!A&&e.jsx(s.IconButton,{"aria-label":"Dashboard Hub",tooltip:"Dashboard Hub",onClick:_s,className:"h-7 w-7 px-0",buttonProps:{size:"xs"},children:e.jsx(s.House,{className:"h-3.5 w-3.5"})})]}),!A&&c&&(h?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:Xe||"Untitled Dashboard",onSave:i=>{console.log("EditableText onSave called:",{newTitle:i,canEditDashboard:oe,dashboardId:o==null?void 0:o.id});const L=(o==null?void 0:o.title)||"";g(i),As(i,L)},isEditable:oe&&!u,displayClassName:"text-[13px] font-medium",inputClassName:"text-[13px] font-medium",placeholder:"Dashboard Title",isPending:V.isPending}),Us&&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:"xs",onClick:$s,disabled:ws||!(t!=null&&t.accessToken)||!(n!=null&&n.apiServiceUrl),className:"w-7 px-0","aria-label":me?"Remove as default dashboard":"Make this a default dashboard",children:e.jsx(s.Star,{className:s.cn("h-3.5 w-3.5 transition-colors",me?"fill-foreground text-foreground":"text-muted-foreground hover:text-foreground")})})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{children:me?"Remove as default dashboard":"Make this a default dashboard"})})]})})]}))]}),e.jsxs("div",{className:"flex items-center gap-2",children:[A&&e.jsxs(e.Fragment,{children:[e.jsx(R.AdvancedModeToggle,{}),e.jsx(R.VisualEditingControls,{})]}),!A&&c&&((as=B==null?void 0:B.permissions)==null?void 0:as.canShare)&&e.jsxs(s.Button,{variant:"outline",size:"xs",onClick:()=>C(!0),children:[e.jsx(s.Share2,{className:"h-3.5 w-3.5"}),"Share"]}),!A&&p&&l.canUseFilters&&c&&e.jsx(R.DashboardFilterControlsButton,{showFilters:ie,onToggleFilters:()=>{ie||Ge("dashboard",!1),qe(!ie)},onAddFilter:()=>{ie||(Ge("dashboard",!1),qe(!0))},onAddControl:()=>{Ke("create")},onManageControls:()=>Ke("manage")}),p&&!A&&c&&k?e.jsx(R.DashboardControlsSettings,{open:!0,onOpenChange:i=>{i||P(null)},showTrigger:!1,initialMode:k}):null,p&&!A&&K&&u&&a&&c&&e.jsxs(s.Button,{variant:"secondary",size:"xs",disabled:S,onClick:Rs,children:[e.jsx(os.Save,{className:"h-3.5 w-3.5"}),"Save Lens"]}),p&&!A&&c&&e.jsxs(s.Button,{variant:"outline",size:"xs",disabled:!p,onClick:()=>Ls(),children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Visual"]}),!A&&!p&&oe&&c&&e.jsxs(s.Button,{size:"xs",onClick:Is,children:[e.jsx(s.Pencil,{className:"h-3.5 w-3.5"}),"Edit"]}),Qe&&c&&We&&e.jsxs(s.Button,{variant:"outline",size:"xs",onClick:Fs,disabled:ue,children:[e.jsx(s.Undo2,{className:"h-3.5 w-3.5"}),"Undo"]}),Qe&&c&&e.jsxs(s.Button,{size:"xs",className:s.cn(!Ye&&"opacity-60"),disabled:ue||!Ye,onClick:()=>Me(),children:[ue?e.jsx(s.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(os.Save,{className:"h-3.5 w-3.5"}),ue?"Saving...":"Save"]}),p&&!A&&c&&e.jsxs(s.Button,{variant:"outline",size:"xs",onClick:Os,children:[e.jsx(s.Cross2Icon,{className:"h-3.5 w-3.5"}),"Close"]}),!A&&c&&e.jsx("div",{className:"ml-2",children:e.jsx(R.NotificationBell,{})}),!A&&a&&e.jsx(rt,{}),!A&&c&&e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"More Options",className:"w-7 px-0 text-muted-foreground hover:text-foreground",buttonProps:{size:"xs",variant:"ghost","aria-label":"More dashboard options"},children:e.jsx(s.EllipsisVertical,{className:"h-3.5 w-3.5"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-56 rounded-[6px] border border-border/60 p-1 shadow-sm",children:[e.jsx(s.DropdownMenuLabel,{children:"Reports"}),e.jsxs(s.DropdownMenuItem,{disabled:m,onSelect:()=>M(!0),children:[e.jsx(s.Download,{className:"h-3.5 w-3.5"}),"Export"]}),e.jsxs(s.DropdownMenuItem,{disabled:!Q,onSelect:()=>{Q&&T(!0)},children:[e.jsx(s.Clock,{className:"h-3.5 w-3.5"}),"Schedule"]}),e.jsx(s.DropdownMenuSeparator,{}),Ms&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuLabel,{children:"Access"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>E(!0),children:[e.jsx(s.Users,{className:"h-3.5 w-3.5"}),"Manage Groups"]}),e.jsx(s.DropdownMenuSeparator,{})]}),e.jsx(s.DropdownMenuLabel,{children:"Preferences"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>D(!0),children:[e.jsx(s.Calendar,{className:"h-3.5 w-3.5"}),"Calendar Preferences"]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>X(!0),children:[e.jsx(s.FileText,{className:"h-3.5 w-3.5"}),"Summary Settings"]}),a&&c&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuSeparator,{}),e.jsx(s.DropdownMenuLabel,{children:"Developer"}),e.jsxs(s.DropdownMenuItem,{onSelect:()=>{var i;t!=null&&t.accessToken&&((i=navigator==null?void 0:navigator.clipboard)!=null&&i.writeText?navigator.clipboard.writeText(t.accessToken).then(()=>s.ue.success("Token copied to clipboard")).catch(()=>s.ue.error("Unable to copy token")):s.ue.error("Clipboard not available"))},children:[e.jsx(s.Copy,{className:"h-3.5 w-3.5"}),"Copy token"]}),e.jsxs(s.DropdownMenuItem,{onSelect:()=>s.invalidateToken(n.apiServiceUrl),children:[e.jsx(Zs,{className:"h-3.5 w-3.5"}),"Invalidate token"]}),p&&e.jsxs(s.DropdownMenuItem,{onSelect:()=>ze(!$e),children:[e.jsx(Ks.Braces,{className:"h-3.5 w-3.5"}),$e?"Hide dashboard JSON":"Show dashboard JSON"]}),K&&p&&e.jsxs(s.DropdownMenuItem,{onSelect:()=>Z(!0),children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Add lens"]}),K&&e.jsxs(s.DropdownMenuSub,{children:[e.jsxs(s.DropdownMenuSubTrigger,{children:[e.jsx(Ws,{className:"h-3.5 w-3.5"}),"Lenses"]}),e.jsx(s.DropdownMenuSubContent,{className:"w-60",children:e.jsx(ct,{})})]})]})]})]}),N&&Ve&&e.jsx(s.ShareDialog,{resource:Ve,resourceType:s.ResourceType.DASHBOARD,onClose:()=>C(!1)}),e.jsx(kt,{open:O,onOpenChange:E}),Q&&(o==null?void 0:o.id)&&e.jsx(s.EmailScheduleDialog,{open:y,onOpenChange:T,dashboardId:o.id,dashboardName:o==null?void 0:o.title}),e.jsx(ns.CalendarPreferencesDialog,{open:$,onOpenChange:D}),e.jsx(ns.DashboardSummarySettingsDialog,{open:q,onOpenChange:X,dashboard:o,disabled:!p,onApply:i=>we({...o,summary:i})}),a&&K&&c&&e.jsx(lt,{open:ge,onOpenChange:Z}),c&&e.jsx(s.DownloadPdf,{open:v,onOpenChange:M}),e.jsx(s.AlertDialog,{open:ee,onOpenChange:i=>{!i&&je&&!se||(U(i),i||(te(null),ae([]),re(!1)))},children:e.jsxs(s.AlertDialogContent,{className:"max-w-sm",children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:se?"Save failed":"Saving dashboard"}),e.jsx(s.AlertDialogDescription,{className:"pt-2",children:se?"We could not save the dashboard. Please try again.":"Please wait while we save your changes."}),Re.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:Re.slice(0,5).map(i=>e.jsx("li",{children:i},i))})]})]}),e.jsx(s.AlertDialogFooter,{className:"flex-col gap-2 sm:flex-row sm:justify-end",children:se?e.jsxs(e.Fragment,{children:[e.jsx(s.AlertDialogCancel,{onClick:()=>{U(!1),te(null),ae([]),re(!1)},className:"m-0",children:"Close"}),e.jsx(s.AlertDialogAction,{onClick:()=>Me({closeAfterSave:Ue,navigateHomeAfterSave:De==="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(R.UnsavedChangesAlert,{open:Es,onOpenChange:i=>{H(i)},onSave:Ts,onDiscard:Ps,isSaving:je,saveLabel:"Save",discardLabel:"Discard"})]})]})}exports.default=Pt;
|
|
47
|
+
*/var ds;function nt(){return ds||(ds=1,process.env.NODE_ENV!=="production"&&function(){function t(p,g){return p===g&&(p!==0||1/p===1/g)||p!==p&&g!==g}function n(p,g){d||l.startTransition===void 0||(d=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var S=g();if(!u){var y=g();c(S,y)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),u=!0)}y=h({inst:{value:S,getSnapshot:g}});var N=y[0].inst,C=y[1];return x(function(){N.value=S,N.getSnapshot=g,r(N)&&C({inst:N})},[p,S,g]),m(function(){return r(N)&&C({inst:N}),p(function(){r(N)&&C({inst:N})})},[p]),b(S),S}function r(p){var g=p.getSnapshot;p=p.value;try{var S=g();return!c(p,S)}catch{return!0}}function a(p,g){return g()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var l=f,c=typeof Object.is=="function"?Object.is:t,h=l.useState,m=l.useEffect,x=l.useLayoutEffect,b=l.useDebugValue,d=!1,u=!1,o=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?a:n;Oe.useSyncExternalStore=l.useSyncExternalStore!==void 0?l.useSyncExternalStore:o,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()),Oe}process.env.NODE_ENV==="production"?Te.exports=rt():Te.exports=nt();var ot=Te.exports;const be=["light","dark","system"];function it(){const{theme:t,setTheme:n}=s.useTheme(),r=s.useDashboardStore(h=>h.actions.setDashboardTheme);function a(){const h=be.includes(t)?t:"system",m=be[(be.indexOf(h)+1)%be.length];n(m),r(m)}const l=t==="light"?at:t==="dark"?st:et,c=t==="light"?"Theme: light (click for dark)":t==="dark"?"Theme: dark (click for system)":"Theme: system (click for light)";return e.jsx(s.Button,{type:"button",variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:a,"aria-label":c,title:c,children:e.jsx(l,{className:"h-3.5 w-3.5",strokeWidth:1.5})})}async function lt(t,n,r,a,l){if(!l)return null;const c=JSON.stringify(r),h=`${t}/v1/lens`;return await s.postRequest(h,l,{name:n,template:c,filterValues:a,operation:"create"})}async function Pe(t,n,r){if(!r)return null;const{id:a,template:l,filterValues:c,isDefault:h,shared:m}=n,x=`${t}/v1/lens`;return await s.postRequest(x,r,{lensId:a,template:l,filterValues:c,isDefault:h,shared:m,operation:"update"})}async function ct(t,n,r){if(!r)return null;const a=`${t}/v1/lens`;return await s.postRequest(a,r,{operation:"delete",lensId:n})}const dt="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function ut({open:t,onOpenChange:n}={}){const[r,a]=f.useState(""),[l,c]=f.useState(!1),h=s.useDashboardStore(j=>j.lenses),{setLenses:m,setSelectedLensId:x}=s.useDashboardActions(),[b,d]=f.useState(!1),[u,o]=f.useState(!1),p=t!==void 0,g=p?t:u,S=j=>{p||o(j),n==null||n(j)},y=s.useDashboardStore(j=>j.dashboard),N=s.useDashboardStore(j=>j.filterValues),{authToken:C,tokenProps:T}=s.useSemaphorContext();async function L(){d(!0);const j=await lt(T.apiServiceUrl,r,y,N,C==null?void 0:C.accessToken);j&&(m([...h||[],j]),x(j.id),S(!1)),d(!1)}return e.jsxs(s.Dialog,{open:g,onOpenChange:S,children:[p?null:e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"secondary",size:"xs",children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Lens"]})}),e.jsxs(s.DialogContent,{className:"rounded-[6px] border-border/60 sm:max-w-[420px] sm:rounded-[6px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{className:"text-[15px]",children:"Create lens"}),e.jsx(s.DialogDescription,{className:"text-[13px] leading-5",children:"Lenses are private by default and are only visible to you."})]}),e.jsxs("div",{className:"space-y-1.5 py-1",children:[e.jsx(s.Label,{htmlFor:"lens-name",className:dt,children:"Name"}),e.jsx(s.Input,{id:"lens-name",size:"xs",value:r,placeholder:"Monthly review, West region, …",onChange:j=>a(j.target.value)}),l&&e.jsx("p",{className:"text-[12px] text-destructive",children:"A lens with this name already exists. Pick a different one."})]}),e.jsxs(s.DialogFooter,{children:[e.jsx(s.Button,{variant:"outline",size:"xs",onClick:()=>S(!1),children:"Cancel"}),e.jsx(s.Button,{size:"xs",type:"submit",onClick:L,disabled:b||!r.trim(),children:b?"Creating…":"Create"})]})]})]})}function mt({includeLabel:t=!1}={}){const n=s.useDashboardStore(d=>d.lenses),r=s.useDashboardStore(d=>d.selectedLensId),{setLenses:a,setSelectedLensId:l}=s.useDashboardActions(),{authToken:c,tokenProps:h}=s.useSemaphorContext();async function m(d){l(d)}async function x(d){if(await ct(h.apiServiceUrl,d,c==null?void 0:c.accessToken)){const o=n==null?void 0:n.filter(p=>p.id!==d);a(o||[]),l("original")}}async function b(d){const u=n==null?void 0:n.map(g=>g.id===d.id?{...g,isDefault:!d.isDefault}:{...g,isDefault:!1});a(u||[]);const o={...d,isDefault:!d.isDefault};await Pe(h.apiServiceUrl,o,c==null?void 0:c.accessToken);const p=n==null?void 0:n.find(g=>g.isDefault);if(p&&p.id!==d.id){const g={...p,isDefault:!1};await Pe(h.apiServiceUrl,g,c==null?void 0:c.accessToken)}}return e.jsxs(e.Fragment,{children:[t?e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(s.DropdownMenuSeparator,{})]}):null,e.jsxs(s.DropdownMenuRadioGroup,{value:r,onValueChange:m,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),n==null?void 0:n.map(d=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:d.id,children:[e.jsx("p",{children:d.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(s.House,{onClick:u=>{u.preventDefault(),b(d)},className:s.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!d.isDefault,"text-green-500":d.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:u=>{u.preventDefault(),x(d.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},d.id))]})]})}function ht(){const{displayPreferences:t,shouldShowElement:n}=s.useDisplayPreferences(),{currentUser:r,userContext:a}=s.useCurrentUserInfo(),l=f.useMemo(()=>s.getRoleBasedDisplayOverrides(r),[r]),c=f.useMemo(()=>m=>l&&l[m]!==void 0&&l[m]===!1?!1:n(m),[l,n,t]),h=f.useMemo(()=>{var m,x,b,d,u;return{canEdit:((m=a==null?void 0:a.permissions)==null?void 0:m.canEdit)??s.canUserEdit(r),canUseFilters:((x=a==null?void 0:a.permissions)==null?void 0:x.canEdit)??s.canUserUseFilters(r),canManageDashboards:((b=a==null?void 0:a.permissions)==null?void 0:b.canCreateDashboard)??s.canUserManageDashboards(r),canCreateDashboards:((d=a==null?void 0:a.permissions)==null?void 0:d.canCreateDashboard)??s.canUserCreateDashboards(r),canAccessVisuals:((u=a==null?void 0:a.permissions)==null?void 0:u.canEdit)??s.canUserAccessVisuals(r)}},[r,a]);return{displayPreferences:t,shouldShowElement:c,permissions:h,currentUser:r}}const pt=async(t,n,r)=>{const a=`${t}/management/v1/groups`;return await s.postRequestRegular(a,n,r)},xt=async(t,n,r)=>{const a=`${t}/management/v1/groups/${r}`;await s.requestJsonRegular(a,n,"DELETE")},ft=async(t,n,r,a)=>{const l=`${t}/management/v1/groups/${r}/members`;return await s.postRequestRegular(l,n,a)},gt=async(t,n,r,a)=>{const l=`${t}/management/v1/groups/${r}/members`;await s.requestJsonRegular(l,n,"DELETE",a)};function bt(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:a=>pt(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",a),onSuccess:()=>{r.invalidateQueries({queryKey:["groups"]}),s.ue.success("Group created successfully")},onError:a=>{console.error("Failed to create group:",a),s.ue.error("Failed to create group",{description:s.getRequestErrorMessage(a,"Failed to create group")})}})}function vt(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:a=>xt(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",a),onSuccess:(a,l)=>{r.invalidateQueries({queryKey:["groups"]}),r.removeQueries({queryKey:["group",l]}),s.ue.success("Group deleted successfully")},onError:a=>{console.error("Failed to delete group:",a),s.ue.error("Failed to delete group",{description:s.getRequestErrorMessage(a,"Failed to delete group")})}})}function St(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:({groupId:a,data:l})=>ft(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",a,l),onSuccess:(a,l)=>{r.invalidateQueries({queryKey:["group",l.groupId]}),r.invalidateQueries({queryKey:["group-members",l.groupId]}),r.invalidateQueries({queryKey:["groups"]}),s.ue.success("Members added successfully")},onError:a=>{console.error("Failed to add group members:",a),s.ue.error("Failed to add members",{description:s.getRequestErrorMessage(a,"Failed to add members")})}})}function yt(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:({groupId:a,data:l})=>gt(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",a,l),onSuccess:(a,l)=>{r.invalidateQueries({queryKey:["group",l.groupId]}),r.invalidateQueries({queryKey:["group-members",l.groupId]}),r.invalidateQueries({queryKey:["groups"]}),s.ue.success("Members removed successfully")},onError:a=>{console.error("Failed to remove group members:",a),s.ue.error("Failed to remove members",{description:s.getRequestErrorMessage(a,"Failed to remove members")})}})}const us="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function jt({onSuccess:t,tenantId:n,isTenantUser:r}){const[a,l]=f.useState(""),[c,h]=f.useState(""),[m,x]=f.useState({}),b=bt(),d=()=>{const o={};return a.trim()?a.length<3?o.name="Group name must be at least 3 characters":a.length>50&&(o.name="Group name must be less than 50 characters"):o.name="Group name is required",c&&c.length>200&&(o.description="Description must be less than 200 characters"),x(o),Object.keys(o).length===0},u=async o=>{if(o.preventDefault(),!d())return;const p={name:a.trim(),description:c.trim()||void 0,type:r?"TENANT_GROUP":"ORG_GROUP",...r&&n?{tenantId:n}:{}};try{await b.mutateAsync(p),l(""),h(""),x({}),t()}catch(g){console.error("Failed to create group:",g)}};return e.jsxs("form",{onSubmit:u,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(s.Label,{htmlFor:"group-name",className:us,children:["Group name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(s.Input,{id:"group-name",size:"xs",placeholder:"e.g., Marketing Team, Engineering Squad",value:a,onChange:o=>{l(o.target.value),m.name&&x(p=>({...p,name:""}))},className:m.name?"border-destructive":"",disabled:b.isPending}),m.name&&e.jsx("p",{className:"text-[12px] text-destructive",children:m.name})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{htmlFor:"group-description",className:us,children:"Description (optional)"}),e.jsx(s.Textarea,{id:"group-description",placeholder:"Describe the purpose of this group…",value:c,onChange:o=>{h(o.target.value),m.description&&x(p=>({...p,description:""}))},className:`text-[13px] ${m.description?"border-destructive":""}`,disabled:b.isPending,rows:3}),m.description?e.jsx("p",{className:"text-[12px] text-destructive",children:m.description}):e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[c.length,"/200"]})]}),e.jsxs("div",{className:"flex gap-2 text-[12px] text-muted-foreground",children:[e.jsx(s.Info,{className:"h-3.5 w-3.5 shrink-0 mt-0.5"}),e.jsx("p",{children:"This group will be accessible to users in your workspace. You can add members after creating it."})]}),e.jsxs("div",{className:"flex justify-end gap-1.5 pt-1",children:[e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:()=>{l(""),h(""),x({})},disabled:b.isPending,children:"Clear"}),e.jsx(s.Button,{type:"submit",size:"xs",disabled:b.isPending||!a.trim(),children:b.isPending?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Creating…"]}):"Create group"})]})]})}function Dt(t,n=[]){let r=[];function a(c,h){const m=w.createContext(h);m.displayName=c+"Context";const x=r.length;r=[...r,h];const b=u=>{var N;const{scope:o,children:p,...g}=u,S=((N=o==null?void 0:o[t])==null?void 0:N[x])||m,y=w.useMemo(()=>g,Object.values(g));return e.jsx(S.Provider,{value:y,children:p})};b.displayName=c+"Provider";function d(u,o){var S;const p=((S=o==null?void 0:o[t])==null?void 0:S[x])||m,g=w.useContext(p);if(g)return g;if(h!==void 0)return h;throw new Error(`\`${u}\` must be used within \`${c}\``)}return[b,d]}const l=()=>{const c=r.map(h=>w.createContext(h));return function(m){const x=(m==null?void 0:m[t])||c;return w.useMemo(()=>({[`__scope${t}`]:{...m,[t]:x}}),[m,x])}};return l.scopeName=t,[a,Nt(l,...n)]}function Nt(...t){const n=t[0];if(t.length===1)return n;const r=()=>{const a=t.map(l=>({useScope:l(),scopeName:l.scopeName}));return function(c){const h=a.reduce((m,{useScope:x,scopeName:b})=>{const u=x(c)[`__scope${b}`];return{...m,...u}},{});return w.useMemo(()=>({[`__scope${n.scopeName}`]:h}),[h])}};return r.scopeName=n.scopeName,r}var wt=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Fe=wt.reduce((t,n)=>{const r=s.createSlot(`Primitive.${n}`),a=w.forwardRef((l,c)=>{const{asChild:h,...m}=l,x=h?r:n;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(x,{...m,ref:c})});return a.displayName=`Primitive.${n}`,{...t,[n]:a}},{});function Ct(){return ot.useSyncExternalStore(Mt,()=>!0,()=>!1)}function Mt(){return()=>{}}var _e="Avatar",[Et]=Dt(_e),[Lt,ps]=Et(_e),xs=w.forwardRef((t,n)=>{const{__scopeAvatar:r,...a}=t,[l,c]=w.useState("idle");return e.jsx(Lt,{scope:r,imageLoadingStatus:l,onImageLoadingStatusChange:c,children:e.jsx(Fe.span,{...a,ref:n})})});xs.displayName=_e;var fs="AvatarImage",gs=w.forwardRef((t,n)=>{const{__scopeAvatar:r,src:a,onLoadingStatusChange:l=()=>{},...c}=t,h=ps(fs,r),m=At(a,c),x=s.useCallbackRef(b=>{l(b),h.onImageLoadingStatusChange(b)});return s.useLayoutEffect2(()=>{m!=="idle"&&x(m)},[m,x]),m==="loaded"?e.jsx(Fe.img,{...c,ref:n,src:a}):null});gs.displayName=fs;var bs="AvatarFallback",vs=w.forwardRef((t,n)=>{const{__scopeAvatar:r,delayMs:a,...l}=t,c=ps(bs,r),[h,m]=w.useState(a===void 0);return w.useEffect(()=>{if(a!==void 0){const x=window.setTimeout(()=>m(!0),a);return()=>window.clearTimeout(x)}},[a]),h&&c.imageLoadingStatus!=="loaded"?e.jsx(Fe.span,{...l,ref:n}):null});vs.displayName=bs;function ms(t,n){return t?n?(t.src!==n&&(t.src=n),t.complete&&t.naturalWidth>0?"loaded":"loading"):"error":"idle"}function At(t,{referrerPolicy:n,crossOrigin:r}){const a=Ct(),l=w.useRef(null),c=a?(l.current||(l.current=new window.Image),l.current):null,[h,m]=w.useState(()=>ms(c,t));return s.useLayoutEffect2(()=>{m(ms(c,t))},[c,t]),s.useLayoutEffect2(()=>{const x=u=>()=>{m(u)};if(!c)return;const b=x("loaded"),d=x("error");return c.addEventListener("load",b),c.addEventListener("error",d),n&&(c.referrerPolicy=n),typeof r=="string"&&(c.crossOrigin=r),()=>{c.removeEventListener("load",b),c.removeEventListener("error",d)}},[c,r,n]),h}var Ss=xs,ys=gs,js=vs;const Re=w.forwardRef(({className:t,...n},r)=>e.jsx(Ss,{ref:r,className:s.cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",t),...n}));Re.displayName=Ss.displayName;const It=w.forwardRef(({className:t,...n},r)=>e.jsx(ys,{ref:r,className:s.cn("aspect-square h-full w-full",t),...n}));It.displayName=ys.displayName;const Ue=w.forwardRef(({className:t,...n},r)=>e.jsx(js,{ref:r,className:s.cn("flex h-full w-full items-center justify-center rounded-full bg-muted",t),...n}));Ue.displayName=js.displayName;function kt({open:t,onOpenChange:n,group:r,onUpdate:a}){const[l,c]=f.useState("members"),[h,m]=f.useState(""),[x,b]=f.useState([]),[d,u]=f.useState([]),{data:o,isLoading:p,refetch:g}=s.useGroupMembers(r.id),S=r.type==="TENANT_GROUP"?"tenant":"organization",{users:y,isLoading:N}=s.useUnifiedUsers({type:S,tenantId:r.tenantId||void 0,active:!0,limit:100}),C=St(),T=yt(),L=(o==null?void 0:o.members)||[],j=f.useMemo(()=>new Set(L.map(v=>v.userId)),[L]),P=f.useMemo(()=>y.filter(v=>!j.has(v.id)),[y,j]),$=f.useMemo(()=>{if(!h)return P;const v=h.toLowerCase();return P.filter(M=>{var k,F;return((k=M.name)==null?void 0:k.toLowerCase().includes(v))||((F=M.email)==null?void 0:F.toLowerCase().includes(v))})},[P,h]),D=f.useMemo(()=>{if(!h)return L;const v=h.toLowerCase();return L.filter(M=>{var k,F,ee,U;return((F=(k=M.user)==null?void 0:k.name)==null?void 0:F.toLowerCase().includes(v))||((U=(ee=M.user)==null?void 0:ee.email)==null?void 0:U.toLowerCase().includes(v))})},[L,h]),q=async()=>{if(x.length!==0)try{await C.mutateAsync({groupId:r.id,data:{userIds:x,userType:S==="tenant"?"tenant":"org"}}),b([]),c("members"),g(),a==null||a()}catch(v){console.error("Failed to add members:",v)}},X=async()=>{if(d.length!==0)try{await T.mutateAsync({groupId:r.id,data:{userIds:d}}),u([]),g(),a==null||a()}catch(v){console.error("Failed to remove members:",v)}},ve=v=>{b(M=>M.includes(v)?M.filter(k=>k!==v):[...M,v])},Z=v=>{u(M=>M.includes(v)?M.filter(k=>k!==v):[...M,v])};return e.jsx(e.Fragment,{children:e.jsx(s.Dialog,{open:t,onOpenChange:n,children:e.jsxs(s.DialogContent,{className:"max-w-3xl max-h-[80vh]","aria-describedby":"group-members-description",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:r.name}),e.jsx("div",{className:"flex items-center gap-2 mt-1",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:[L.length," ",L.length===1?"member":"members"]})}),e.jsxs("p",{id:"group-members-description",className:"sr-only",children:["Add or remove members from the ",r.name," group"]})]}),e.jsxs(s.Tabs,{value:l,onValueChange:v=>{c(v),m(""),u([])},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:h,onChange:v=>m(v.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:d.length>0?"h-[300px]":"h-[350px]",children:p?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(v=>e.jsx(s.Skeleton,{className:"h-16 w-full"},v))}):D.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:h?"No members found":"No members yet"}),e.jsx("p",{className:"text-xs mt-1",children:h?"Try a different search":'Switch to the "Add Members" tab to add people to this group'})]}):e.jsx("div",{className:"space-y-2",children:D.map(v=>e.jsx(Ot,{member:v,selected:d.includes(v.userId),onToggle:()=>Z(v.userId)},v.id))})}),d.length>0&&e.jsxs("div",{className:"flex items-center justify-between pt-4 border-t",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[d.length," member",d.length!==1?"s":""," selected"]}),e.jsx(s.Button,{variant:"destructive",size:"sm",onClick:X,disabled:T.isPending,children:T.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:h,onChange:v=>m(v.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(v=>e.jsx(s.Skeleton,{className:"h-16 w-full"},v))}):$.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:h?"Try a different search":"All eligible users are already members"})]}):e.jsx("div",{className:"space-y-2",children:$.map(v=>e.jsx(Tt,{user:v,selected:x.includes(v.id),onToggle:()=>ve(v.id)},v.id))})}),x.length>0&&e.jsxs("div",{className:"flex items-center justify-between pt-4 border-t",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[x.length," user",x.length!==1?"s":""," selected"]}),e.jsx(s.Button,{onClick:q,disabled:C.isPending,children:C.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 Ot({member:t,selected:n,onToggle:r}){var l,c,h,m;const a=((c=(l=t.user)==null?void 0:l.name)==null?void 0:c.split(" ").map(x=>x[0]).join("").toUpperCase())||"?";return e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg border bg-card hover:bg-muted/50 cursor-pointer",onClick:r,children:[e.jsx(s.Checkbox,{checked:n}),e.jsx(Re,{className:"h-8 w-8",children:e.jsx(Ue,{className:"text-xs",children:a})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:((h=t.user)==null?void 0:h.name)||"Unknown User"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(m=t.user)==null?void 0:m.email})]})]})}function Tt({user:t,selected:n,onToggle:r}){var l;const a=((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:r,children:[e.jsx(s.Checkbox,{checked:n}),e.jsx(Re,{className:"h-8 w-8",children:e.jsx(Ue,{className:"text-xs",children:a})}),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 Pt({open:t,onOpenChange:n}){const[r,a]=f.useState("groups"),[l,c]=f.useState(""),[h,m]=f.useState(null),[x,b]=f.useState(!1),[d,u]=f.useState(null),{tokenProps:o}=s.useSemaphorContext(),{currentUser:p}=s.useCurrentUserInfo(),g=vt(),S=(p==null?void 0:p.type)==="tenant",y=o==null?void 0:o.tenantId,{groups:N,isLoading:C,refetch:T}=s.useGroups({type:S?"TENANT_GROUP":"all",tenantId:S?y:void 0,includeMembers:!1}),L=N.filter(D=>{var q;return D.name.toLowerCase().includes(l.toLowerCase())||((q=D.description)==null?void 0:q.toLowerCase().includes(l.toLowerCase()))}),j=async()=>{if(d)try{await g.mutateAsync(d.id),u(null),T()}catch(D){console.error("Failed to delete group:",D)}},P=D=>{m(D),b(!0)},$=()=>{a("groups"),T()};return e.jsxs(e.Fragment,{children:[e.jsx(s.Dialog,{open:t,onOpenChange:n,children:e.jsxs(s.DialogContent,{className:"max-h-[80vh] max-w-3xl rounded-[6px] border-border/60 sm:rounded-[6px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{className:"text-[15px]",children:"Group management"}),e.jsx(s.DialogDescription,{className:"text-[13px] leading-5",children:"Manage groups, create new ones, and control membership."})]}),e.jsxs(s.Tabs,{value:r,onValueChange:a,className:"mt-2",children:[e.jsxs(s.TabsList,{className:"h-8 w-full justify-start gap-1 bg-transparent p-0 border-b border-border/60 rounded-none",children:[e.jsx(s.TabsTrigger,{value:"groups",className:"h-8 rounded-none border-b-2 border-transparent bg-transparent px-3 text-[13px] data-[state=active]:border-foreground data-[state=active]:bg-transparent data-[state=active]:shadow-none",children:"Groups"}),e.jsx(s.TabsTrigger,{value:"create",className:"h-8 rounded-none border-b-2 border-transparent bg-transparent px-3 text-[13px] data-[state=active]:border-foreground data-[state=active]:bg-transparent data-[state=active]:shadow-none",children:"Create group"})]}),e.jsx(s.TabsContent,{value:"groups",className:"mt-4",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(s.Search,{className:"absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx(s.Input,{size:"xs",placeholder:"Search groups…",value:l,onChange:D=>c(D.target.value),className:"pl-7"})]}),e.jsx(s.ScrollArea,{className:"h-[400px]",children:C?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(D=>e.jsx(s.Skeleton,{className:"h-16 w-full rounded-[6px]"},D))}):L.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx("p",{className:"text-[13px]",children:"No groups found."}),e.jsx("p",{className:"mt-1 text-[12px]",children:l?"Try a different search.":"Create your first group to get started."})]}):e.jsx("div",{className:"space-y-2 pr-2",children:L.map(D=>e.jsx(Ft,{group:D,onManageMembers:()=>P(D),onDelete:()=>u(D),currentUserId:p==null?void 0:p.id},D.id))})})]})}),e.jsx(s.TabsContent,{value:"create",className:"mt-4",children:e.jsx(jt,{onSuccess:$,tenantId:y,isTenantUser:S})})]})]})}),h&&e.jsx(kt,{open:x,onOpenChange:b,group:h,onUpdate:()=>T()}),e.jsx(s.AlertDialog,{open:!!d,onOpenChange:()=>u(null),children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Delete group"}),e.jsxs(s.AlertDialogDescription,{children:['Delete "',d==null?void 0:d.name,`"? This removes all members and can't be undone.`]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:j,disabled:g.isPending,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:g.isPending?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Deleting…"]}):"Delete group"})]})]})})]})}function Ft({group:t,onManageMembers:n,onDelete:r,currentUserId:a}){const l=t.createdBy===a;return e.jsx("div",{className:"rounded-[6px] border border-border/60 bg-card px-3 py-2.5 transition-colors hover:bg-muted/30",children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[e.jsx("h4",{className:"text-[13px] font-medium text-foreground",children:t.name}),t.description&&e.jsx("p",{className:"text-[12px] text-muted-foreground",children:t.description}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-[11px] text-muted-foreground",children:[e.jsxs("span",{className:"inline-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 ",Qs.format(new Date(t.createdAt),"MMM d, yyyy")]})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[e.jsx(s.Button,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:n,title:"Manage members","aria-label":"Manage members",children:e.jsx(s.UserPlus,{className:"h-3.5 w-3.5"})}),l&&e.jsx(s.Button,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:bg-destructive/10 hover:text-destructive",onClick:r,title:"Delete group","aria-label":"Delete group",children:e.jsx(s.Trash2,{className:"h-3.5 w-3.5"})})]})]})})}function J(t,n,r){var c,h;const a=(t.controls||[]).find(m=>m.id===r);if(a)return a.label;const l=(h=(c=s.findCardById(t,n))==null?void 0:c.controls)==null?void 0:h.find(m=>m.id===r);return(l==null?void 0:l.label)||r}function Y(t,n){var r;return((r=s.findCardById(t,n))==null?void 0:r.title)||n}function _t(t){const{errors:n,dashboard:r}=t;if(!r)return n;const a=new Map;for(const l of n){const c=l.match(/^Card '(.+)' binding for control '(.+)' maps to missing metric '(.+)'\.$/);if(c){const[,d,u]=c,o=`${d}:${u}:missing-metric`;a.has(o)||a.set(o,`"${Y(r,d)}" has an outdated "${J(r,d,u)}" mapping. Some choices still point to metrics that are no longer available on this card. Open the card controls and choose replacements.`);continue}const h=l.match(/^Card '(.+)' binding for control '(.+)' maps to missing group-by field '(.+)'\.$/);if(h){const[,d,u]=h,o=`${d}:${u}:missing-group-by`;a.has(o)||a.set(o,`"${Y(r,d)}" has an outdated "${J(r,d,u)}" 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=l.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid metric target\.$/);if(m){const[,d,u]=m,o=`${d}:${u}:invalid-metric`;a.has(o)||a.set(o,`"${Y(r,d)}" has an invalid "${J(r,d,u)}" metric mapping. Open the card controls and choose a valid metric for each option.`);continue}const x=l.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid group-by target\.$/);if(x){const[,d,u]=x,o=`${d}:${u}:invalid-group-by`;a.has(o)||a.set(o,`"${Y(r,d)}" has an invalid "${J(r,d,u)}" field mapping. Open the card controls and choose a valid field for each option.`);continue}const b=l.match(/^Card '(.+)' binding for control '(.+)' requires at least one temporal group-by field\.$/);if(b){const[,d,u]=b,o=`${d}:${u}:missing-temporal-group-by`;a.has(o)||a.set(o,`"${Y(r,d)}" can no longer use "${J(r,d,u)}" for time grain because the card does not currently group by a date field.`);continue}a.set(l,l)}return Array.from(a.values())}function hs(t,n){return{dashboard:s.cloneDeep(t),semanticExecutionPayload:s.cloneDeep(n)}}function Rt(){var ts,as,rs,ns;R.useExportRecovery(),R.useExportPolling();const{authToken:t,tokenProps:n,id:r}=s.useSemaphorContext(),{isLocalDev:a}=s.useDashboardPreferences(),{permissions:l}=ht(),c=s.useHasDashboardId(),{isLoading:h}=s.useDashboardQuery();s.useDashboardStore(i=>i.theme);const m=s.useDashboardStore(i=>i.isDownloadingPdf),x=s.useDashboardStore(i=>i.dashboardAssistantDraftScopeKey),b=s.useDashboardStore(i=>i.lenses),d=s.useDashboardStore(i=>i.selectedLensId),u=b==null?void 0:b.find(i=>i.id===d),o=s.useDashboardStore(i=>i.dashboard);s.useDashboardStore(i=>i.selectedSheetId);const p=s.useDashboardStore(i=>i.isDashboardEditing),{setDashboardTitle:g}=s.useDashboardStore(i=>i.actions),[S,y]=f.useState(!1),[N,C]=f.useState(!1),[T,L]=f.useState(!1),[j,P]=f.useState(!1),[$,D]=f.useState(!1),[q,X]=f.useState(!1),[ve,Z]=f.useState(!1),[v,M]=f.useState(!1),[k,F]=f.useState(null),[ee,U]=f.useState(!1),[se,te]=f.useState(null),[Ge,ae]=f.useState([]),[$e,re]=f.useState(!1),Ds=s.useDashboardStore(i=>i.isDashboardPanelOpen),Ns=s.useDashboardStore(i=>i.actions.setIsDashboardPanelOpen),ws=s.useDashboardStore(i=>i.filterValues),A=s.useDashboardStore(i=>i.isVisualEditing);s.useEditorStore(i=>i.card);const z=s.useManagementStore(i=>i.selectedDashboard),ne=s.useManagementStore(i=>i.initialDashboard);s.useManagementStore(i=>i.selectedVisual),s.useDashboardStore(i=>i.selectedFrameId),s.useEditorStore(i=>i.frame);const oe=z?(as=z==null?void 0:z.permissions)==null?void 0:as.canEdit:(ts=ne==null?void 0:ne.permissions)==null?void 0:ts.canEdit,ie=s.useDashboardStore(i=>i.showFilters),qe=s.useAssistantLayoutStore(i=>i.setPanelOpen),Be=s.useDashboardStore(i=>i.showDashboardJSON),Se=s.useDashboardStore(i=>i.onSaveFunction),ze=s.useDashboardStore(i=>i.actions.setShowFilters),{setIsDashboardEditing:He,setShowDashboardJSON:Ve}=s.useDashboardStore(i=>i.actions),{setInitialDashboard:Ke,clearSelectedDashboard:ye}=s.useManagementStore(i=>i.actions),{resources:le}=s.useResourceManagement(s.ResourceType.DASHBOARD),{data:je}=s.useUserPreferences(),Cs=((rs=je==null?void 0:je.preference)==null?void 0:rs.defaultDashboardId)||null,{mutate:Ms,isPending:Es}=s.useDefaultDashboardMutation(),{currentUser:Ls}=s.useCurrentUserInfo(),As=s.canUserManageGroups(Ls),B=z||ne,Qe=B?{id:B.id,title:(o==null?void 0:o.title)||B.title||"Dashboard"}:null,{handleAddNewFrame:Is}=s.useAddNewFrame(),[De,Ne]=f.useState(!1),[ks,H]=f.useState(!1),[we,ce]=f.useState("close"),V=s.useUpdateResource(s.ResourceType.DASHBOARD),[O,de]=f.useState(null),We=f.useCallback(i=>{window.setTimeout(()=>{F(i)},0)},[]),Os=async(i,E)=>{if(!(o!=null&&o.id)){console.log("No dashboard ID found");return}console.log("Updating dashboard title:",{dashboardId:o.id,newTitle:i,previousTitle:E}),V.mutate({resourceId:o.id,data:{title:i}},{onSuccess:()=>{console.log("Dashboard title updated successfully"),s.ue.success("Dashboard title updated")},onError:_=>{console.error("Failed to update dashboard title:",_),s.ue.error("Failed to update dashboard title"),g(E)}})};f.useEffect(()=>{if(le&&le.length>0){const i=o==null?void 0:o.id;if(i){const E=le.find(_=>_.id===i);E&&Ke(E)}}},[le,o==null?void 0:o.id,Ke]);const K=n.orgUserId||n.tenantId,Je=p&&!A&&K&&oe,{setDashboard:Ce}=s.useDashboardStore(i=>i.actions),Me=s.useDashboardStore(i=>i.semanticExecutionPayload),Ts=()=>{He(!0)},Ee=()=>{He(!1),Ve(!1),de(null),F(null)};f.useEffect(()=>{if(!p){O&&de(null);return}O||!o||h||de(hs(o,Me))},[o,O,p,h,Me]);const ue=(O==null?void 0:O.dashboard)??null,{isDirty:Ye,isDirtyPending:Ps,resetDirty:me}=Ws.useDebouncedDirtyCheck(o,ue,300,1e3,Ie.serializeDashboardForDirtyCheck),Xe=f.useCallback(()=>ue?Ie.serializeDashboardForDirtyCheck(o)!==Ie.serializeDashboardForDirtyCheck(ue):!1,[o,ue]),Ze=Ye||Ps,he=De||V.isPending,Fs=()=>{Xe()?(ce("close"),H(!0)):(Ee(),me())},_s=async()=>{await Le({closeAfterSave:!0,navigateHomeAfterSave:we==="home"})},Rs=()=>{O&&Ce(O.dashboard,{semanticExecutionPayload:O.semanticExecutionPayload}),Ee(),we==="home"&&ye(),ce("close"),H(!1),me()},Us=()=>{O&&(Ce(O.dashboard,{semanticExecutionPayload:O.semanticExecutionPayload}),me())},Gs=()=>{if(p&&Xe()){ce("home"),H(!0);return}ye()};async function Le(i){const E=s.useDashboardStore.getState().dashboard;if(!E)return;const _=(i==null?void 0:i.closeAfterSave)??$e,Hs=(i==null?void 0:i.navigateHomeAfterSave)??!1;re(_),_&&H(!1);const Vs=s.cloneDeep(E);U(!0),te(null),ae([]),Ne(!0);const Ks={template:E};V.mutate({resourceId:E.id,data:Ks},{onSuccess:I=>{var xe,fe,os;const G=(I==null?void 0:I.id)||((xe=I==null?void 0:I.dashboard)==null?void 0:xe.id)||((fe=I==null?void 0:I.resource)==null?void 0:fe.id)||((os=I==null?void 0:I.template)==null?void 0:os.id)||null;if(!E.id&&G){const Ae=s.useAIInteractionStore.getState(),ge=Ae.pendingDashboardDraftMigration;(ge==null?void 0:ge.scopeKey)===x?Ae.actions.setPendingDashboardDraftMigrationExpectedDashboardId(G):ge&&Ae.actions.clearPendingDashboardDraftMigration()}Ne(!1),s.ue.success("Dashboard saved!"),de(hs(Vs,s.useDashboardStore.getState().semanticExecutionPayload)),U(!1),re(!1),_&&(Ee(),me(),Hs&&ye()),ce("close")},onError:I=>{Ne(!1),te("Failed to save dashboard. Please try again.");const G=I.details,xe=Array.isArray(G==null?void 0:G.errors)?(G.errors||[]).filter(fe=>typeof fe=="string"):[];ae(_t({errors:xe,dashboard:E||void 0})),s.ue.error("Failed to save dashboard")}})}async function $s(){if(y(!0),!d||!u)return;const i=s.useDashboardStore.getState().dashboard;if(!i){y(!1);return}const E=JSON.stringify(i),_={...u,template:E,filterValues:ws};await Pe(n.apiServiceUrl,_,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),Se==null||Se(i),y(!1)}const es=(u==null?void 0:u.name)||o.title,Q=!!(o!=null&&o.id);V.isPending&&console.log("Title during update:",{title:es,dashboardStateTitle:o.title,dashboardId:o==null?void 0:o.id,currentLensName:u==null?void 0:u.name});const ss=n.orgUserId||n.tenantId&&n.endUserId&&n.endUserEmail,qs=!!ss&&!!(t!=null&&t.accessToken)&&!!(n!=null&&n.apiServiceUrl);f.useEffect(()=>{!Q&&j&&P(!1)},[Q,j]);const Bs=c,W=(o==null?void 0:o.id)||null,pe=!!W&&Cs===W,zs=()=>{W&&Ms({dashboardId:pe?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:[ss&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{"aria-label":"Manage Dashboards",tooltip:"Manage Dashboards",onClick:()=>{Ns(!Ds)},className:"h-7 w-7 px-0",buttonProps:{size:"xs"},children:e.jsx(Zs,{className:"h-3.5 w-3.5"})}),Bs&&!A&&e.jsx(s.IconButton,{"aria-label":"Dashboard Hub",tooltip:"Dashboard Hub",onClick:Gs,className:"h-7 w-7 px-0",buttonProps:{size:"xs"},children:e.jsx(s.House,{className:"h-3.5 w-3.5"})})]}),!A&&c&&(h?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:es||"Untitled Dashboard",onSave:i=>{console.log("EditableText onSave called:",{newTitle:i,canEditDashboard:oe,dashboardId:o==null?void 0:o.id});const E=(o==null?void 0:o.title)||"";g(i),Os(i,E)},isEditable:oe&&!u,displayClassName:"text-[13px] font-medium",inputClassName:"text-[13px] font-medium",placeholder:"Dashboard Title",isPending:V.isPending}),qs&&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:"xs",onClick:zs,disabled:Es||!(t!=null&&t.accessToken)||!(n!=null&&n.apiServiceUrl),className:"w-7 px-0","aria-label":pe?"Remove as default dashboard":"Make this a default dashboard",children:e.jsx(s.Star,{className:s.cn("h-3.5 w-3.5 transition-colors",pe?"fill-foreground text-foreground":"text-muted-foreground hover:text-foreground")})})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{children:pe?"Remove as default dashboard":"Make this a default dashboard"})})]})})]}))]}),e.jsxs("div",{className:"flex items-center gap-2",children:[A&&e.jsxs(e.Fragment,{children:[e.jsx(R.AdvancedModeToggle,{}),e.jsx(R.VisualEditingControls,{})]}),!A&&c&&((ns=B==null?void 0:B.permissions)==null?void 0:ns.canShare)&&e.jsxs(s.Button,{variant:"outline",size:"xs",onClick:()=>C(!0),children:[e.jsx(s.Share2,{className:"h-3.5 w-3.5"}),"Share"]}),!A&&p&&l.canUseFilters&&c&&e.jsx(R.DashboardFilterControlsButton,{showFilters:ie,onToggleFilters:()=>{ie||qe("dashboard",!1),ze(!ie)},onAddFilter:()=>{ie||(qe("dashboard",!1),ze(!0))},onAddControl:()=>{We("create")},onManageControls:()=>We("manage")}),p&&!A&&c&&k?e.jsx(R.DashboardControlsSettings,{open:!0,onOpenChange:i=>{i||F(null)},showTrigger:!1,initialMode:k}):null,p&&!A&&K&&u&&a&&c&&e.jsxs(s.Button,{variant:"secondary",size:"xs",disabled:S,onClick:$s,children:[e.jsx(ls.Save,{className:"h-3.5 w-3.5"}),"Save Lens"]}),p&&!A&&c&&e.jsxs(s.Button,{variant:"outline",size:"xs",disabled:!p,onClick:()=>Is(),children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Visual"]}),!A&&!p&&oe&&c&&e.jsxs(s.Button,{size:"xs",onClick:Ts,children:[e.jsx(s.Pencil,{className:"h-3.5 w-3.5"}),"Edit"]}),Je&&c&&Ye&&e.jsxs(s.Button,{variant:"outline",size:"xs",onClick:Us,disabled:he,children:[e.jsx(s.Undo2,{className:"h-3.5 w-3.5"}),"Undo"]}),Je&&c&&e.jsxs(s.Button,{size:"xs",className:s.cn(!Ze&&"opacity-60"),disabled:he||!Ze,onClick:()=>Le(),children:[he?e.jsx(s.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(ls.Save,{className:"h-3.5 w-3.5"}),he?"Saving...":"Save"]}),p&&!A&&c&&e.jsxs(s.Button,{variant:"outline",size:"xs",onClick:Fs,children:[e.jsx(s.Cross2Icon,{className:"h-3.5 w-3.5"}),"Close"]}),!A&&c&&e.jsx("div",{className:"ml-2",children:e.jsx(R.NotificationBell,{})}),!A&&a&&e.jsx(it,{}),!A&&c&&e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"More Options",className:"w-7 px-0 text-muted-foreground hover:text-foreground",buttonProps:{size:"xs",variant:"ghost","aria-label":"More dashboard options"},children:e.jsx(s.EllipsisVertical,{className:"h-3.5 w-3.5"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-56 rounded-[6px] border border-border/60 p-1 shadow-sm",children:[e.jsx(s.DropdownMenuLabel,{children:"Reports"}),e.jsxs(s.DropdownMenuItem,{disabled:m,onSelect:()=>M(!0),children:[e.jsx(s.Download,{className:"h-3.5 w-3.5"}),"Export"]}),e.jsxs(s.DropdownMenuItem,{disabled:!Q,onSelect:()=>{Q&&P(!0)},children:[e.jsx(s.Clock,{className:"h-3.5 w-3.5"}),"Schedule"]}),e.jsx(s.DropdownMenuSeparator,{}),As&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuLabel,{children:"Access"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>L(!0),children:[e.jsx(s.Users,{className:"h-3.5 w-3.5"}),"Manage Groups"]}),e.jsx(s.DropdownMenuSeparator,{})]}),e.jsx(s.DropdownMenuLabel,{children:"Preferences"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>D(!0),children:[e.jsx(s.Calendar,{className:"h-3.5 w-3.5"}),"Calendar Preferences"]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>X(!0),children:[e.jsx(s.FileText,{className:"h-3.5 w-3.5"}),"Summary Settings"]}),a&&c&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuSeparator,{}),e.jsx(s.DropdownMenuLabel,{children:"Developer"}),e.jsxs(s.DropdownMenuItem,{onSelect:()=>{var i;t!=null&&t.accessToken&&((i=navigator==null?void 0:navigator.clipboard)!=null&&i.writeText?navigator.clipboard.writeText(t.accessToken).then(()=>s.ue.success("Token copied to clipboard")).catch(()=>s.ue.error("Unable to copy token")):s.ue.error("Clipboard not available"))},children:[e.jsx(s.Copy,{className:"h-3.5 w-3.5"}),"Copy token"]}),e.jsxs(s.DropdownMenuItem,{onSelect:()=>s.invalidateToken(n.apiServiceUrl),children:[e.jsx(tt,{className:"h-3.5 w-3.5"}),"Invalidate token"]}),p&&e.jsxs(s.DropdownMenuItem,{onSelect:()=>Ve(!Be),children:[e.jsx(Js.Braces,{className:"h-3.5 w-3.5"}),Be?"Hide dashboard JSON":"Show dashboard JSON"]}),K&&p&&e.jsxs(s.DropdownMenuItem,{onSelect:()=>Z(!0),children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Add lens"]}),K&&e.jsxs(s.DropdownMenuSub,{children:[e.jsxs(s.DropdownMenuSubTrigger,{children:[e.jsx(Xs,{className:"h-3.5 w-3.5"}),"Lenses"]}),e.jsx(s.DropdownMenuSubContent,{className:"w-60",children:e.jsx(mt,{})})]})]})]})]}),N&&Qe&&e.jsx(s.ShareDialog,{resource:Qe,resourceType:s.ResourceType.DASHBOARD,onClose:()=>C(!1)}),e.jsx(Pt,{open:T,onOpenChange:L}),Q&&(o==null?void 0:o.id)&&e.jsx(s.EmailScheduleDialog,{open:j,onOpenChange:P,dashboardId:o.id,dashboardName:o==null?void 0:o.title}),e.jsx(is.CalendarPreferencesDialog,{open:$,onOpenChange:D}),e.jsx(is.DashboardSummarySettingsDialog,{open:q,onOpenChange:X,dashboard:o,disabled:!p,onApply:i=>Ce({...o,summary:i},{semanticExecutionPayload:Me})}),a&&K&&c&&e.jsx(ut,{open:ve,onOpenChange:Z}),c&&e.jsx(s.DownloadPdf,{open:v,onOpenChange:M}),e.jsx(s.AlertDialog,{open:ee,onOpenChange:i=>{!i&&De&&!se||(U(i),i||(te(null),ae([]),re(!1)))},children:e.jsxs(s.AlertDialogContent,{className:"max-w-sm",children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:se?"Save failed":"Saving dashboard"}),e.jsx(s.AlertDialogDescription,{className:"pt-2",children:se?"We could not save the dashboard. Please try again.":"Please wait while we save your changes."}),Ge.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:Ge.slice(0,5).map(i=>e.jsx("li",{children:i},i))})]})]}),e.jsx(s.AlertDialogFooter,{className:"flex-col gap-2 sm:flex-row sm:justify-end",children:se?e.jsxs(e.Fragment,{children:[e.jsx(s.AlertDialogCancel,{onClick:()=>{U(!1),te(null),ae([]),re(!1)},className:"m-0",children:"Close"}),e.jsx(s.AlertDialogAction,{onClick:()=>Le({closeAfterSave:$e,navigateHomeAfterSave:we==="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(R.UnsavedChangesAlert,{open:ks,onOpenChange:i=>{H(i)},onSave:_s,onDiscard:Rs,isSaving:De,saveLabel:"Save",discardLabel:"Discard"})]})]})}exports.default=Rt;
|