react-semaphor 0.1.321 → 0.1.322

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/brand-studio/index.js +4 -4
  2. package/dist/chunks/{braces-Cy5NEBa8.js → braces-ZjRH2Kl7.js} +1 -1
  3. package/dist/chunks/{calendar-preferences-dialog-CzoSmQNw.js → calendar-preferences-dialog-CZqePF6B.js} +1 -1
  4. package/dist/chunks/{calendar-preferences-dialog-D-0W76fR.js → calendar-preferences-dialog-t0OOALVd.js} +3 -3
  5. package/dist/chunks/{chevrons-up-down-DZTs1oVD.js → chevrons-up-down-CA-XvN1o.js} +1 -1
  6. package/dist/chunks/{dashboard-briefing-launcher-D5z1kf6J.js → dashboard-briefing-launcher-BYbnbZ9e.js} +6 -5
  7. package/dist/chunks/{dashboard-briefing-launcher-Cqm8NnVb.js → dashboard-briefing-launcher-d1_fm91W.js} +13 -13
  8. package/dist/chunks/dashboard-controls-B3HHMRPC.js +52 -0
  9. package/dist/chunks/dashboard-controls-BuChCKDm.js +2246 -0
  10. package/dist/chunks/{dashboard-json-BRx9CbrK.js → dashboard-json-DgoYjD0O.js} +2 -2
  11. package/dist/chunks/{dashboard-json-ezFjz7Fc.js → dashboard-json-M5-VFCtZ.js} +1 -1
  12. package/dist/chunks/{edit-dashboard-visual-Cw0KmT4i.js → edit-dashboard-visual-BH8DP1qq.js} +1 -1
  13. package/dist/chunks/{edit-dashboard-visual-sI6ds8MP.js → edit-dashboard-visual-DP31ytwJ.js} +616 -616
  14. package/dist/chunks/{index-BZg7rVe-.js → index-ChmS5nsv.js} +21344 -21136
  15. package/dist/chunks/{index-DX6Krdga.js → index-CodH6sqg.js} +194 -194
  16. package/dist/chunks/{palette-Bc-vOLSt.js → palette-D96DOM7E.js} +1 -1
  17. package/dist/chunks/{resource-management-panel-CRRUcnVu.js → resource-management-panel-D3vO68dH.js} +1 -1
  18. package/dist/chunks/{resource-management-panel-pN81x7Gw.js → resource-management-panel-gt__S0Pb.js} +18 -18
  19. package/dist/chunks/{save-CXa6cKaY.js → save-DxkSzUTZ.js} +1 -1
  20. package/dist/chunks/{switch-DdTUsWgd.js → switch-Deo2Ltmj.js} +6 -6
  21. package/dist/chunks/{use-create-flow-overlay-state-BfV5187a.js → use-create-flow-overlay-state-BZaSpL-c.js} +1 -1
  22. package/dist/chunks/{use-create-flow-overlay-state-B9ujZUon.js → use-create-flow-overlay-state-OA3iI54p.js} +4 -4
  23. package/dist/chunks/{use-visual-utils-D_uHFfTn.js → use-visual-utils-CMucAqbS.js} +1 -1
  24. package/dist/chunks/{use-visual-utils-PxijRlpS.js → use-visual-utils-CsXS-Zeh.js} +20 -20
  25. package/dist/dashboard/index.cjs +1 -1
  26. package/dist/dashboard/index.js +1 -1
  27. package/dist/index.cjs +1 -1
  28. package/dist/index.js +131 -130
  29. package/dist/style.css +1 -1
  30. package/dist/surfboard/index.cjs +1 -1
  31. package/dist/surfboard/index.js +2 -2
  32. package/dist/types/main.d.ts +145 -0
  33. package/package.json +1 -1
  34. package/dist/chunks/dashboard-controls-CRIwHD59.js +0 -1999
  35. package/dist/chunks/dashboard-controls-DSt7iwFC.js +0 -52
@@ -1,52 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("./switch-BXICAlvS.js"),s=require("./index-DX6Krdga.js"),y=require("react");require("./index-DRlMUglg.js");require("react-dom");const R=require("./dashboard-briefing-launcher-Cqm8NnVb.js"),Js=require("./index-D7KJindZ.js"),Ys=require("./calendar-preferences-dialog-CzoSmQNw.js"),Xs=require("./use-debounced-dirty-check-XHSwAefL.js"),Ie=require("./normalize-dashboard-for-dirty-check-BXRUMVb2.js"),ls=require("./save-CqrBQKG6.js"),Zs=require("./palette-CanPG11m.js"),et=require("./braces-C7BeIXvM.js");function st(t){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(a,n,r.get?r:{enumerable:!0,get:()=>t[n]})}}return a.default=t,Object.freeze(a)}const E=st(y);/**
2
- * @license lucide-react v0.453.0 - ISC
3
- *
4
- * This source code is licensed under the ISC license.
5
- * See the LICENSE file in the root directory of this source tree.
6
- */const tt=o.createLucideIcon("Glasses",[["circle",{cx:"6",cy:"15",r:"4",key:"vux9w4"}],["circle",{cx:"18",cy:"15",r:"4",key:"18o8ve"}],["path",{d:"M14 15a2 2 0 0 0-2-2 2 2 0 0 0-2 2",key:"1ag4bs"}],["path",{d:"M2.5 13 5 7c.7-1.3 1.4-2 3-2",key:"1hm1gs"}],["path",{d:"M21.5 13 19 7c-.7-1.3-1.5-2-3-2",key:"1r31ai"}]]);/**
7
- * @license lucide-react v0.453.0 - ISC
8
- *
9
- * This source code is licensed under the ISC license.
10
- * See the LICENSE file in the root directory of this source tree.
11
- */const at=o.createLucideIcon("Menu",[["line",{x1:"4",x2:"20",y1:"12",y2:"12",key:"1e0a9i"}],["line",{x1:"4",x2:"20",y1:"6",y2:"6",key:"1owob3"}],["line",{x1:"4",x2:"20",y1:"18",y2:"18",key:"yk5zj1"}]]);/**
12
- * @license lucide-react v0.453.0 - ISC
13
- *
14
- * This source code is licensed under the ISC license.
15
- * See the LICENSE file in the root directory of this source tree.
16
- */const rt=o.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
- * @license lucide-react v0.453.0 - ISC
18
- *
19
- * This source code is licensed under the ISC license.
20
- * See the LICENSE file in the root directory of this source tree.
21
- */const nt=o.createLucideIcon("Moon",[["path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z",key:"a7tn18"}]]);/**
22
- * @license lucide-react v0.453.0 - ISC
23
- *
24
- * This source code is licensed under the ISC license.
25
- * See the LICENSE file in the root directory of this source tree.
26
- */const ot=o.createLucideIcon("ShieldX",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m14.5 9.5-5 5",key:"17q4r4"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]]);/**
27
- * @license lucide-react v0.453.0 - ISC
28
- *
29
- * This source code is licensed under the ISC license.
30
- * See the LICENSE file in the root directory of this source tree.
31
- */const it=o.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"}]]);/**
32
- * @license lucide-react v0.453.0 - ISC
33
- *
34
- * This source code is licensed under the ISC license.
35
- * See the LICENSE file in the root directory of this source tree.
36
- */const Te=o.createLucideIcon("UserPlus",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]]);var Oe={exports:{}},Ae={};/**
37
- * @license React
38
- * use-sync-external-store-shim.production.js
39
- *
40
- * Copyright (c) Meta Platforms, Inc. and affiliates.
41
- *
42
- * This source code is licensed under the MIT license found in the
43
- * LICENSE file in the root directory of this source tree.
44
- */var ds;function ct(){if(ds)return Ae;ds=1;var t=y;function a(x,p){return x===p&&(x!==0||1/x===1/p)||x!==x&&p!==p}var n=typeof Object.is=="function"?Object.is:a,r=t.useState,i=t.useEffect,d=t.useLayoutEffect,h=t.useDebugValue;function c(x,p){var g=p(),b=r({inst:{value:g,getSnapshot:p}}),u=b[0].inst,D=b[1];return d(function(){u.value=g,u.getSnapshot=p,f(u)&&D({inst:u})},[x,g,p]),i(function(){return f(u)&&D({inst:u}),x(function(){f(u)&&D({inst:u})})},[x]),h(g),g}function f(x){var p=x.getSnapshot;x=x.value;try{var g=p();return!n(x,g)}catch{return!0}}function j(x,p){return p()}var m=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?j:c;return Ae.useSyncExternalStore=t.useSyncExternalStore!==void 0?t.useSyncExternalStore:m,Ae}var ke={};/**
45
- * @license React
46
- * use-sync-external-store-shim.development.js
47
- *
48
- * Copyright (c) Meta Platforms, Inc. and affiliates.
49
- *
50
- * This source code is licensed under the MIT license found in the
51
- * LICENSE file in the root directory of this source tree.
52
- */var us;function lt(){return us||(us=1,process.env.NODE_ENV!=="production"&&function(){function t(g,b){return g===b&&(g!==0||1/g===1/b)||g!==g&&b!==b}function a(g,b){m||i.startTransition===void 0||(m=!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 u=b();if(!x){var D=b();d(u,D)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),x=!0)}D=h({inst:{value:u,getSnapshot:b}});var w=D[0].inst,L=D[1];return f(function(){w.value=u,w.getSnapshot=b,n(w)&&L({inst:w})},[g,u,b]),c(function(){return n(w)&&L({inst:w}),g(function(){n(w)&&L({inst:w})})},[g]),j(u),u}function n(g){var b=g.getSnapshot;g=g.value;try{var u=b();return!d(g,u)}catch{return!0}}function r(g,b){return b()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var i=y,d=typeof Object.is=="function"?Object.is:t,h=i.useState,c=i.useEffect,f=i.useLayoutEffect,j=i.useDebugValue,m=!1,x=!1,p=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?r:a;ke.useSyncExternalStore=i.useSyncExternalStore!==void 0?i.useSyncExternalStore:p,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()),ke}process.env.NODE_ENV==="production"?Oe.exports=ct():Oe.exports=lt();var dt=Oe.exports;const ge=["light","dark","system"];function ut(){const{theme:t,setTheme:a}=s.useTheme(),n=o.useDashboardStore(h=>h.actions.setDashboardTheme);function r(){const h=ge.includes(t)?t:"system",c=ge[(ge.indexOf(h)+1)%ge.length];a(c),n(c)}const i=t==="light"?it:t==="dark"?nt:rt,d=t==="light"?"Theme: light (click for dark)":t==="dark"?"Theme: dark (click for system)":"Theme: system (click for light)";return e.jsx(o.Button,{type:"button",variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:r,"aria-label":d,title:d,children:e.jsx(i,{className:"h-3.5 w-3.5",strokeWidth:1.5})})}async function mt(t,a,n,r,i){if(!i)return null;const d=JSON.stringify(n),h=`${t}/v1/lens`;return await o.postRequest(h,i,{name:a,template:d,filterValues:r,operation:"create"})}async function Pe(t,a,n){if(!n)return null;const{id:r,template:i,filterValues:d,isDefault:h,shared:c}=a,f=`${t}/v1/lens`;return await o.postRequest(f,n,{lensId:r,template:i,filterValues:d,isDefault:h,shared:c,operation:"update"})}async function ht(t,a,n){if(!n)return null;const r=`${t}/v1/lens`;return await o.postRequest(r,n,{operation:"delete",lensId:a})}const pt="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function xt({open:t,onOpenChange:a}={}){const[n,r]=y.useState(""),[i,d]=y.useState(!1),h=o.useDashboardStore(C=>C.lenses),{setLenses:c,setSelectedLensId:f}=o.useDashboardActions(),[j,m]=y.useState(!1),[x,p]=y.useState(!1),g=t!==void 0,b=g?t:x,u=C=>{g||p(C),a==null||a(C)},D=o.useDashboardStore(C=>C.dashboard),w=o.useDashboardStore(C=>C.filterValues),{authToken:L,tokenProps:N}=s.useSemaphorContext();async function S(){m(!0);const C=await mt(N.apiServiceUrl,n,D,w,L==null?void 0:L.accessToken);C&&(c([...h||[],C]),f(C.id),u(!1)),m(!1)}return e.jsxs(s.Dialog,{open:b,onOpenChange:u,children:[g?null:e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsxs(o.Button,{variant:"secondary",size:"xs",children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Lens"]})}),e.jsxs(s.DialogContent,{className:"rounded-control border-border/60 sm:max-w-[420px] sm:rounded-control",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(o.Label,{htmlFor:"lens-name",className:pt,children:"Name"}),e.jsx(o.Input,{id:"lens-name",size:"xs",value:n,placeholder:"Monthly review, West region, …",onChange:C=>r(C.target.value)}),i&&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(o.Button,{variant:"outline",size:"xs",onClick:()=>u(!1),children:"Cancel"}),e.jsx(o.Button,{size:"xs",type:"submit",onClick:S,disabled:j||!n.trim(),children:j?"Creating…":"Create"})]})]})]})}function ft({includeLabel:t=!1}={}){const a=o.useDashboardStore(m=>m.lenses),n=o.useDashboardStore(m=>m.selectedLensId),{setLenses:r,setSelectedLensId:i}=o.useDashboardActions(),{authToken:d,tokenProps:h}=s.useSemaphorContext();async function c(m){i(m)}async function f(m){if(await ht(h.apiServiceUrl,m,d==null?void 0:d.accessToken)){const p=a==null?void 0:a.filter(g=>g.id!==m);r(p||[]),i("original")}}async function j(m){const x=a==null?void 0:a.map(b=>b.id===m.id?{...b,isDefault:!m.isDefault}:{...b,isDefault:!1});r(x||[]);const p={...m,isDefault:!m.isDefault};await Pe(h.apiServiceUrl,p,d==null?void 0:d.accessToken);const g=a==null?void 0:a.find(b=>b.isDefault);if(g&&g.id!==m.id){const b={...g,isDefault:!1};await Pe(h.apiServiceUrl,b,d==null?void 0:d.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:n,onValueChange:c,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),a==null?void 0:a.map(m=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:m.id,children:[e.jsx("p",{children:m.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(s.House,{onClick:x=>{x.preventDefault(),j(m)},className:o.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!m.isDefault,"text-green-500":m.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:x=>{x.preventDefault(),f(m.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},m.id))]})]})}function gt(){const{displayPreferences:t,shouldShowElement:a}=s.useDisplayPreferences(),{currentUser:n,userContext:r}=s.useCurrentUserInfo(),i=y.useMemo(()=>s.getRoleBasedDisplayOverrides(n),[n]),d=y.useMemo(()=>c=>i&&i[c]!==void 0&&i[c]===!1?!1:a(c),[i,a,t]),h=y.useMemo(()=>{var c,f,j,m,x;return{canEdit:((c=r==null?void 0:r.permissions)==null?void 0:c.canEdit)??s.canUserEdit(n),canUseFilters:((f=r==null?void 0:r.permissions)==null?void 0:f.canEdit)??s.canUserUseFilters(n),canManageDashboards:((j=r==null?void 0:r.permissions)==null?void 0:j.canCreateDashboard)??s.canUserManageDashboards(n),canCreateDashboards:((m=r==null?void 0:r.permissions)==null?void 0:m.canCreateDashboard)??s.canUserCreateDashboards(n),canAccessVisuals:((x=r==null?void 0:r.permissions)==null?void 0:x.canEdit)??s.canUserAccessVisuals(n)}},[n,r]);return{displayPreferences:t,shouldShowElement:d,permissions:h,currentUser:n}}const bt=async(t,a,n)=>{const r=`${t}/management/v1/groups`;return await o.postRequestRegular(r,a,n)},vt=async(t,a,n)=>{const r=`${t}/management/v1/groups/${n}`;await o.requestJsonRegular(r,a,"DELETE")},yt=async(t,a,n,r)=>{const i=`${t}/management/v1/groups/${n}/members`;return await o.postRequestRegular(i,a,r)},jt=async(t,a,n,r)=>{const i=`${t}/management/v1/groups/${n}/members`;await o.requestJsonRegular(i,a,"DELETE",r)};function St(){const{authToken:t,tokenProps:a}=s.useSemaphorContext(),n=s.useQueryClient();return s.useMutation({mutationFn:r=>bt(a.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r),onSuccess:()=>{n.invalidateQueries({queryKey:["groups"]}),s.ue.success("Group created successfully")},onError:r=>{console.error("Failed to create group:",r),s.ue.error("Failed to create group",{description:o.getRequestErrorMessage(r,"Failed to create group")})}})}function Dt(){const{authToken:t,tokenProps:a}=s.useSemaphorContext(),n=s.useQueryClient();return s.useMutation({mutationFn:r=>vt(a.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r),onSuccess:(r,i)=>{n.invalidateQueries({queryKey:["groups"]}),n.removeQueries({queryKey:["group",i]}),s.ue.success("Group deleted successfully")},onError:r=>{console.error("Failed to delete group:",r),s.ue.error("Failed to delete group",{description:o.getRequestErrorMessage(r,"Failed to delete group")})}})}function wt(){const{authToken:t,tokenProps:a}=s.useSemaphorContext(),n=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:i})=>yt(a.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r,i),onSuccess:(r,i)=>{n.invalidateQueries({queryKey:["group",i.groupId]}),n.invalidateQueries({queryKey:["group-members",i.groupId]}),n.invalidateQueries({queryKey:["groups"]}),s.ue.success("Members added successfully")},onError:r=>{console.error("Failed to add group members:",r),s.ue.error("Failed to add members",{description:o.getRequestErrorMessage(r,"Failed to add members")})}})}function Nt(){const{authToken:t,tokenProps:a}=s.useSemaphorContext(),n=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:i})=>jt(a.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r,i),onSuccess:(r,i)=>{n.invalidateQueries({queryKey:["group",i.groupId]}),n.invalidateQueries({queryKey:["group-members",i.groupId]}),n.invalidateQueries({queryKey:["groups"]}),s.ue.success("Members removed successfully")},onError:r=>{console.error("Failed to remove group members:",r),s.ue.error("Failed to remove members",{description:o.getRequestErrorMessage(r,"Failed to remove members")})}})}const ms="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function Ct({onSuccess:t,tenantId:a,isTenantUser:n}){const[r,i]=y.useState(""),[d,h]=y.useState(""),[c,f]=y.useState({}),j=St(),m=()=>{const p={};return r.trim()?r.length<3?p.name="Group name must be at least 3 characters":r.length>50&&(p.name="Group name must be less than 50 characters"):p.name="Group name is required",d&&d.length>200&&(p.description="Description must be less than 200 characters"),f(p),Object.keys(p).length===0},x=async p=>{if(p.preventDefault(),!m())return;const g={name:r.trim(),description:d.trim()||void 0,type:n?"TENANT_GROUP":"ORG_GROUP",...n&&a?{tenantId:a}:{}};try{await j.mutateAsync(g),i(""),h(""),f({}),t()}catch(b){console.error("Failed to create group:",b)}};return e.jsxs("form",{onSubmit:x,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(o.Label,{htmlFor:"group-name",className:ms,children:["Group name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(o.Input,{id:"group-name",size:"xs",placeholder:"e.g., Marketing Team, Engineering Squad",value:r,onChange:p=>{i(p.target.value),c.name&&f(g=>({...g,name:""}))},className:c.name?"border-destructive":"",disabled:j.isPending}),c.name&&e.jsx("p",{className:"text-[12px] text-destructive",children:c.name})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(o.Label,{htmlFor:"group-description",className:ms,children:"Description (optional)"}),e.jsx(s.Textarea,{id:"group-description",placeholder:"Describe the purpose of this group…",value:d,onChange:p=>{h(p.target.value),c.description&&f(g=>({...g,description:""}))},className:`text-[13px] ${c.description?"border-destructive":""}`,disabled:j.isPending,rows:3}),c.description?e.jsx("p",{className:"text-[12px] text-destructive",children:c.description}):e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[d.length,"/200"]})]}),e.jsxs("div",{className:"flex gap-2 text-[12px] text-muted-foreground",children:[e.jsx(o.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(o.Button,{type:"button",variant:"outline",size:"xs",onClick:()=>{i(""),h(""),f({})},disabled:j.isPending,children:"Clear"}),e.jsx(o.Button,{type:"submit",size:"xs",disabled:j.isPending||!r.trim(),children:j.isPending?e.jsxs(e.Fragment,{children:[e.jsx(o.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Creating…"]}):"Create group"})]})]})}function Mt(t,a=[]){let n=[];function r(d,h){const c=E.createContext(h);c.displayName=d+"Context";const f=n.length;n=[...n,h];const j=x=>{var w;const{scope:p,children:g,...b}=x,u=((w=p==null?void 0:p[t])==null?void 0:w[f])||c,D=E.useMemo(()=>b,Object.values(b));return e.jsx(u.Provider,{value:D,children:g})};j.displayName=d+"Provider";function m(x,p){var u;const g=((u=p==null?void 0:p[t])==null?void 0:u[f])||c,b=E.useContext(g);if(b)return b;if(h!==void 0)return h;throw new Error(`\`${x}\` must be used within \`${d}\``)}return[j,m]}const i=()=>{const d=n.map(h=>E.createContext(h));return function(c){const f=(c==null?void 0:c[t])||d;return E.useMemo(()=>({[`__scope${t}`]:{...c,[t]:f}}),[c,f])}};return i.scopeName=t,[r,Lt(i,...a)]}function Lt(...t){const a=t[0];if(t.length===1)return a;const n=()=>{const r=t.map(i=>({useScope:i(),scopeName:i.scopeName}));return function(d){const h=r.reduce((c,{useScope:f,scopeName:j})=>{const x=f(d)[`__scope${j}`];return{...c,...x}},{});return E.useMemo(()=>({[`__scope${a.scopeName}`]:h}),[h])}};return n.scopeName=a.scopeName,n}var Et=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],_e=Et.reduce((t,a)=>{const n=o.createSlot(`Primitive.${a}`),r=E.forwardRef((i,d)=>{const{asChild:h,...c}=i,f=h?n:a;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(f,{...c,ref:d})});return r.displayName=`Primitive.${a}`,{...t,[a]:r}},{});function It(){return dt.useSyncExternalStore(At,()=>!0,()=>!1)}function At(){return()=>{}}var Ue="Avatar",[kt]=Mt(Ue),[Tt,xs]=kt(Ue),fs=E.forwardRef((t,a)=>{const{__scopeAvatar:n,...r}=t,[i,d]=E.useState("idle");return e.jsx(Tt,{scope:n,imageLoadingStatus:i,onImageLoadingStatusChange:d,children:e.jsx(_e.span,{...r,ref:a})})});fs.displayName=Ue;var gs="AvatarImage",bs=E.forwardRef((t,a)=>{const{__scopeAvatar:n,src:r,onLoadingStatusChange:i=()=>{},...d}=t,h=xs(gs,n),c=Ot(r,d),f=o.useCallbackRef(j=>{i(j),h.onImageLoadingStatusChange(j)});return o.useLayoutEffect2(()=>{c!=="idle"&&f(c)},[c,f]),c==="loaded"?e.jsx(_e.img,{...d,ref:a,src:r}):null});bs.displayName=gs;var vs="AvatarFallback",ys=E.forwardRef((t,a)=>{const{__scopeAvatar:n,delayMs:r,...i}=t,d=xs(vs,n),[h,c]=E.useState(r===void 0);return E.useEffect(()=>{if(r!==void 0){const f=window.setTimeout(()=>c(!0),r);return()=>window.clearTimeout(f)}},[r]),h&&d.imageLoadingStatus!=="loaded"?e.jsx(_e.span,{...i,ref:a}):null});ys.displayName=vs;function hs(t,a){return t?a?(t.src!==a&&(t.src=a),t.complete&&t.naturalWidth>0?"loaded":"loading"):"error":"idle"}function Ot(t,{referrerPolicy:a,crossOrigin:n}){const r=It(),i=E.useRef(null),d=r?(i.current||(i.current=new window.Image),i.current):null,[h,c]=E.useState(()=>hs(d,t));return o.useLayoutEffect2(()=>{c(hs(d,t))},[d,t]),o.useLayoutEffect2(()=>{const f=x=>()=>{c(x)};if(!d)return;const j=f("loaded"),m=f("error");return d.addEventListener("load",j),d.addEventListener("error",m),a&&(d.referrerPolicy=a),typeof n=="string"&&(d.crossOrigin=n),()=>{d.removeEventListener("load",j),d.removeEventListener("error",m)}},[d,n,a]),h}var js=fs,Ss=bs,Ds=ys;const Re=E.forwardRef(({className:t,...a},n)=>e.jsx(js,{ref:n,className:o.cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",t),...a}));Re.displayName=js.displayName;const Pt=E.forwardRef(({className:t,...a},n)=>e.jsx(Ss,{ref:n,className:o.cn("aspect-square h-full w-full",t),...a}));Pt.displayName=Ss.displayName;const Fe=E.forwardRef(({className:t,...a},n)=>e.jsx(Ds,{ref:n,className:o.cn("flex h-full w-full items-center justify-center rounded-full bg-muted",t),...a}));Fe.displayName=Ds.displayName;function _t({open:t,onOpenChange:a,group:n,onUpdate:r}){const[i,d]=y.useState("members"),[h,c]=y.useState(""),[f,j]=y.useState([]),[m,x]=y.useState([]),{data:p,isLoading:g,refetch:b}=s.useGroupMembers(n.id),u=n.type==="TENANT_GROUP"?"tenant":"organization",{users:D,isLoading:w}=s.useUnifiedUsers({type:u,tenantId:n.tenantId||void 0,active:!0,limit:100}),L=wt(),N=Nt(),S=(p==null?void 0:p.members)||[],C=y.useMemo(()=>new Set(S.map(v=>v.userId)),[S]),G=y.useMemo(()=>D.filter(v=>!C.has(v.id)),[D,C]),F=y.useMemo(()=>{if(!h)return G;const v=h.toLowerCase();return G.filter(A=>{var O,q;return((O=A.name)==null?void 0:O.toLowerCase().includes(v))||((q=A.email)==null?void 0:q.toLowerCase().includes(v))})},[G,h]),M=y.useMemo(()=>{if(!h)return S;const v=h.toLowerCase();return S.filter(A=>{var O,q,H,Z;return((q=(O=A.user)==null?void 0:O.name)==null?void 0:q.toLowerCase().includes(v))||((Z=(H=A.user)==null?void 0:H.email)==null?void 0:Z.toLowerCase().includes(v))})},[S,h]),$=async()=>{if(f.length!==0)try{await L.mutateAsync({groupId:n.id,data:{userIds:f,userType:u==="tenant"?"tenant":"org"}}),j([]),d("members"),b(),r==null||r()}catch(v){console.error("Failed to add members:",v)}},be=async()=>{if(m.length!==0)try{await N.mutateAsync({groupId:n.id,data:{userIds:m}}),x([]),b(),r==null||r()}catch(v){console.error("Failed to remove members:",v)}},X=v=>{j(A=>A.includes(v)?A.filter(O=>O!==v):[...A,v])},ve=v=>{x(A=>A.includes(v)?A.filter(O=>O!==v):[...A,v])};return e.jsx(e.Fragment,{children:e.jsx(s.Dialog,{open:t,onOpenChange:a,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:n.name}),e.jsx("div",{className:"flex items-center gap-2 mt-1",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:[S.length," ",S.length===1?"member":"members"]})}),e.jsxs("p",{id:"group-members-description",className:"sr-only",children:["Add or remove members from the ",n.name," group"]})]}),e.jsxs(o.Tabs,{value:i,onValueChange:v=>{d(v),c(""),x([])},className:"mt-4",children:[e.jsxs(o.TabsList,{className:"grid w-full grid-cols-2",children:[e.jsx(o.TabsTrigger,{value:"members",children:"Current Members"}),e.jsx(o.TabsTrigger,{value:"add",children:"Add Members"})]}),e.jsxs(o.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(o.Input,{placeholder:"Search members...",value:h,onChange:v=>c(v.target.value),className:"pl-10"})]}),e.jsx(o.ScrollArea,{className:m.length>0?"h-[300px]":"h-[350px]",children:g?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(v=>e.jsx(s.Skeleton,{className:"h-16 w-full"},v))}):M.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(s.Users,{className:"h-12 w-12 mb-3 opacity-50"}),e.jsx("p",{className:"text-sm font-medium",children: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:M.map(v=>e.jsx(Ut,{member:v,selected:m.includes(v.userId),onToggle:()=>ve(v.userId)},v.id))})}),m.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:[m.length," member",m.length!==1?"s":""," selected"]}),e.jsx(o.Button,{variant:"destructive",size:"sm",onClick:be,disabled:N.isPending,children:N.isPending?e.jsxs(e.Fragment,{children:[e.jsx(o.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(o.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(o.Input,{placeholder:"Search users to add...",value:h,onChange:v=>c(v.target.value),className:"pl-10"})]}),e.jsx(o.ScrollArea,{className:"h-[300px]",children:w?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(v=>e.jsx(s.Skeleton,{className:"h-16 w-full"},v))}):F.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(Te,{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:F.map(v=>e.jsx(Rt,{user:v,selected:f.includes(v.id),onToggle:()=>X(v.id)},v.id))})}),f.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:[f.length," user",f.length!==1?"s":""," selected"]}),e.jsx(o.Button,{onClick:$,disabled:L.isPending,children:L.isPending?e.jsxs(e.Fragment,{children:[e.jsx(o.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Adding..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Te,{className:"mr-2 h-4 w-4"}),"Add Members"]})})]})]})]})]})})})}function Ut({member:t,selected:a,onToggle:n}){var i,d,h,c;const r=((d=(i=t.user)==null?void 0:i.name)==null?void 0:d.split(" ").map(f=>f[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:n,children:[e.jsx(s.Checkbox,{checked:a}),e.jsx(Re,{className:"h-8 w-8",children:e.jsx(Fe,{className:"text-xs",children:r})}),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:(c=t.user)==null?void 0:c.email})]})]})}function Rt({user:t,selected:a,onToggle:n}){var i;const r=((i=t.name)==null?void 0:i.split(" ").map(d=>d[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:n,children:[e.jsx(s.Checkbox,{checked:a}),e.jsx(Re,{className:"h-8 w-8",children:e.jsx(Fe,{className:"text-xs",children:r})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:t.name}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t.email})]})]})}function Ft({open:t,onOpenChange:a}){const[n,r]=y.useState("groups"),[i,d]=y.useState(""),[h,c]=y.useState(null),[f,j]=y.useState(!1),[m,x]=y.useState(null),{tokenProps:p}=s.useSemaphorContext(),{currentUser:g}=s.useCurrentUserInfo(),b=Dt(),u=(g==null?void 0:g.type)==="tenant",D=p==null?void 0:p.tenantId,{groups:w,isLoading:L,refetch:N}=s.useGroups({type:u?"TENANT_GROUP":"all",tenantId:u?D:void 0,includeMembers:!1}),S=w.filter(M=>{var $;return M.name.toLowerCase().includes(i.toLowerCase())||(($=M.description)==null?void 0:$.toLowerCase().includes(i.toLowerCase()))}),C=async()=>{if(m)try{await b.mutateAsync(m.id),x(null),N()}catch(M){console.error("Failed to delete group:",M)}},G=M=>{c(M),j(!0)},F=()=>{r("groups"),N()};return e.jsxs(e.Fragment,{children:[e.jsx(s.Dialog,{open:t,onOpenChange:a,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(o.Tabs,{value:n,onValueChange:r,className:"mt-2",children:[e.jsxs(o.TabsList,{className:"h-8 w-full justify-start gap-1 bg-transparent p-0 border-b border-border/60 rounded-none",children:[e.jsx(o.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(o.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(o.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(o.Input,{size:"xs",placeholder:"Search groups…",value:i,onChange:M=>d(M.target.value),className:"pl-7"})]}),e.jsx(o.ScrollArea,{className:"h-[400px]",children:L?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(M=>e.jsx(s.Skeleton,{className:"h-16 w-full rounded-[6px]"},M))}):S.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:i?"Try a different search.":"Create your first group to get started."})]}):e.jsx("div",{className:"space-y-2 pr-2",children:S.map(M=>e.jsx(Gt,{group:M,onManageMembers:()=>G(M),onDelete:()=>x(M),currentUserId:g==null?void 0:g.id},M.id))})})]})}),e.jsx(o.TabsContent,{value:"create",className:"mt-4",children:e.jsx(Ct,{onSuccess:F,tenantId:D,isTenantUser:u})})]})]})}),h&&e.jsx(_t,{open:f,onOpenChange:j,group:h,onUpdate:()=>N()}),e.jsx(s.AlertDialog,{open:!!m,onOpenChange:()=>x(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 "',m==null?void 0:m.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:C,disabled:b.isPending,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:b.isPending?e.jsxs(e.Fragment,{children:[e.jsx(o.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Deleting…"]}):"Delete group"})]})]})})]})}function Gt({group:t,onManageMembers:a,onDelete:n,currentUserId:r}){const i=t.createdBy===r;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 ",Js.format(new Date(t.createdAt),"MMM d, yyyy")]})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[e.jsx(o.Button,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:a,title:"Manage members","aria-label":"Manage members",children:e.jsx(Te,{className:"h-3.5 w-3.5"})}),i&&e.jsx(o.Button,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:bg-destructive/10 hover:text-destructive",onClick:n,title:"Delete group","aria-label":"Delete group",children:e.jsx(s.Trash2,{className:"h-3.5 w-3.5"})})]})]})})}function J(t,a,n){var d,h;const r=(t.controls||[]).find(c=>c.id===n);if(r)return r.label;const i=(h=(d=o.findCardById(t,a))==null?void 0:d.controls)==null?void 0:h.find(c=>c.id===n);return(i==null?void 0:i.label)||n}function Y(t,a){var n;return((n=o.findCardById(t,a))==null?void 0:n.title)||a}function $t(t){const{errors:a,dashboard:n}=t;if(!n)return a;const r=new Map;for(const i of a){const d=i.match(/^Card '(.+)' binding for control '(.+)' maps to missing metric '(.+)'\.$/);if(d){const[,m,x]=d,p=`${m}:${x}:missing-metric`;r.has(p)||r.set(p,`"${Y(n,m)}" has an outdated "${J(n,m,x)}" 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=i.match(/^Card '(.+)' binding for control '(.+)' maps to missing group-by field '(.+)'\.$/);if(h){const[,m,x]=h,p=`${m}:${x}:missing-group-by`;r.has(p)||r.set(p,`"${Y(n,m)}" has an outdated "${J(n,m,x)}" mapping. Some choices still point to fields that are no longer available on this card. Open the card controls and choose replacements.`);continue}const c=i.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid metric target\.$/);if(c){const[,m,x]=c,p=`${m}:${x}:invalid-metric`;r.has(p)||r.set(p,`"${Y(n,m)}" has an invalid "${J(n,m,x)}" metric mapping. Open the card controls and choose a valid metric for each option.`);continue}const f=i.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid group-by target\.$/);if(f){const[,m,x]=f,p=`${m}:${x}:invalid-group-by`;r.has(p)||r.set(p,`"${Y(n,m)}" has an invalid "${J(n,m,x)}" field mapping. Open the card controls and choose a valid field for each option.`);continue}const j=i.match(/^Card '(.+)' binding for control '(.+)' requires at least one temporal group-by field\.$/);if(j){const[,m,x]=j,p=`${m}:${x}:missing-temporal-group-by`;r.has(p)||r.set(p,`"${Y(n,m)}" can no longer use "${J(n,m,x)}" for time grain because the card does not currently group by a date field.`);continue}r.set(i,i)}return Array.from(r.values())}function qt(t,a){return typeof t=="boolean"?t:typeof a=="boolean"?a:!0}function ps(t,a){return{dashboard:s.cloneDeep(t),semanticExecutionPayload:s.cloneDeep(a)}}function Bt(){var ss,ts,as,rs,ns,os,is;R.useExportRecovery(),R.useExportPolling();const{authToken:t,tokenProps:a,id:n,showBriefings:r}=s.useSemaphorContext(),{isLocalDev:i}=s.useDashboardPreferences(),{openBrandStudioPreview:d}=s.useBrandStudioPreview(),{permissions:h}=gt(),c=s.useHasDashboardId(),{isLoading:f}=s.useDashboardQuery(),j=o.useDashboardStore(l=>l.theme),m=o.useDashboardStore(l=>l.isDownloadingPdf),x=o.useDashboardStore(l=>l.dashboardAssistantDraftScopeKey),p=o.useDashboardStore(l=>l.lenses),g=o.useDashboardStore(l=>l.selectedLensId),b=p==null?void 0:p.find(l=>l.id===g),u=o.useDashboardStore(l=>l.dashboard),D=o.useDashboardStore(l=>l.selectedSheetId),w=(ss=u==null?void 0:u.sheets)==null?void 0:ss.find(l=>l.id===D),L=o.isDocumentSheet(w),N=L?(ts=w==null?void 0:w.document)==null?void 0:ts.page:void 0,S=o.useDashboardStore(l=>l.isDashboardEditing),{setDashboardTitle:C}=o.useDashboardStore(l=>l.actions),[G,F]=y.useState(!1),[M,$]=y.useState(!1),[be,X]=y.useState(!1),[ve,v]=y.useState(!1),[A,O]=y.useState(!1),[q,H]=y.useState(!1),[Z,ee]=y.useState(!1),[se,te]=y.useState(null),[Ge,ae]=y.useState([]),[$e,re]=y.useState(!1),ws=o.useDashboardStore(l=>l.isDashboardPanelOpen),Ns=o.useDashboardStore(l=>l.actions.setIsDashboardPanelOpen),Cs=o.useDashboardStore(l=>l.filterValues),k=o.useDashboardStore(l=>l.isVisualEditing);o.useEditorStore(l=>l.card);const V=s.useManagementStore(l=>l.selectedDashboard),ne=s.useManagementStore(l=>l.initialDashboard);s.useManagementStore(l=>l.selectedVisual),o.useDashboardStore(l=>l.selectedFrameId),o.useEditorStore(l=>l.frame);const oe=V?(rs=V==null?void 0:V.permissions)==null?void 0:rs.canEdit:(as=ne==null?void 0:ne.permissions)==null?void 0:as.canEdit,qe=o.useDashboardStore(l=>l.showDashboardJSON),ye=o.useDashboardStore(l=>l.onSaveFunction),{setIsDashboardEditing:Be,setShowDashboardJSON:ze}=o.useDashboardStore(l=>l.actions),{setInitialDashboard:He,clearSelectedDashboard:je}=s.useManagementStore(l=>l.actions),{resources:ie}=s.useResourceManagement(s.ResourceType.DASHBOARD),{data:Se}=s.useUserPreferences(),Ms=((ns=Se==null?void 0:Se.preference)==null?void 0:ns.defaultDashboardId)||null,{mutate:Ls,isPending:Es}=s.useDefaultDashboardMutation(),{currentUser:Is}=s.useCurrentUserInfo(),As=s.canUserManageGroups(Is),_=V||ne,Ve=_?{id:_.id,title:(u==null?void 0:u.title)||_.title||"Dashboard"}:null,{handleAddNewFrame:ks}=s.useAddNewFrame(),[De,we]=y.useState(!1),[Ts,K]=y.useState(!1),[Ne,ce]=y.useState("close"),Q=s.useUpdateResource(s.ResourceType.DASHBOARD),[P,le]=y.useState(null),Os=async(l,I)=>{if(!(u!=null&&u.id)){console.log("No dashboard ID found");return}console.log("Updating dashboard title:",{dashboardId:u.id,newTitle:l,previousTitle:I}),Q.mutate({resourceId:u.id,data:{title:l}},{onSuccess:()=>{console.log("Dashboard title updated successfully"),s.ue.success("Dashboard title updated")},onError:U=>{console.error("Failed to update dashboard title:",U),s.ue.error("Failed to update dashboard title"),C(I)}})};y.useEffect(()=>{if(ie&&ie.length>0){const l=u==null?void 0:u.id;if(l){const I=ie.find(U=>U.id===l);I&&He(I)}}},[ie,u==null?void 0:u.id,He]);const W=a.orgUserId||a.tenantId,Ce=y.useMemo(()=>zt({accessToken:t==null?void 0:t.accessToken,dashboardId:(u==null?void 0:u.id)||n||a.dashboard_id,selectedSheetId:L?D:void 0,pageSize:N==null?void 0:N.size,orientation:N==null?void 0:N.orientation,theme:j}),[t==null?void 0:t.accessToken,n,u==null?void 0:u.id,L,N==null?void 0:N.orientation,N==null?void 0:N.size,D,j,a.dashboard_id]),Ke=S&&!k&&W&&oe,{setDashboard:Qe}=o.useDashboardStore(l=>l.actions),We=o.useDashboardStore(l=>l.semanticExecutionPayload),Ps=()=>{Be(!0)},Me=()=>{Be(!1),ze(!1),le(null)};y.useEffect(()=>{if(!S){P&&le(null);return}P||!u||f||le(ps(u,We))},[u,P,S,f,We]);const de=(P==null?void 0:P.dashboard)??null,{isDirty:Je,isDirtyPending:_s,resetDirty:ue}=Xs.useDebouncedDirtyCheck(u,de,300,1e3,Ie.serializeDashboardForDirtyCheck),Ye=y.useCallback(()=>de?Ie.serializeDashboardForDirtyCheck(u)!==Ie.serializeDashboardForDirtyCheck(de):!1,[u,de]),Xe=Je||_s,me=De||Q.isPending,Us=()=>{Ye()?(ce("close"),K(!0)):(Me(),ue())},Rs=async()=>{await Le({closeAfterSave:!0,navigateHomeAfterSave:Ne==="home"})},Fs=()=>{P&&Qe(P.dashboard,{semanticExecutionPayload:P.semanticExecutionPayload}),Me(),Ne==="home"&&je(),ce("close"),K(!1),ue()},Gs=()=>{P&&(Qe(P.dashboard,{semanticExecutionPayload:P.semanticExecutionPayload}),ue())},$s=()=>{if(S&&Ye()){ce("home"),K(!0);return}je()};async function Le(l){const I=o.useDashboardStore.getState().dashboard;if(!I)return;const U=(l==null?void 0:l.closeAfterSave)??$e,Ks=(l==null?void 0:l.navigateHomeAfterSave)??!1;re(U),U&&K(!1);const Qs=s.cloneDeep(I);ee(!0),te(null),ae([]),we(!0);const Ws={template:I};Q.mutate({resourceId:I.id,data:Ws},{onSuccess:T=>{var pe,xe,cs;const z=(T==null?void 0:T.id)||((pe=T==null?void 0:T.dashboard)==null?void 0:pe.id)||((xe=T==null?void 0:T.resource)==null?void 0:xe.id)||((cs=T==null?void 0:T.template)==null?void 0:cs.id)||null;if(!I.id&&z){const Ee=o.useAIInteractionStore.getState(),fe=Ee.pendingDashboardDraftMigration;(fe==null?void 0:fe.scopeKey)===x?Ee.actions.setPendingDashboardDraftMigrationExpectedDashboardId(z):fe&&Ee.actions.clearPendingDashboardDraftMigration()}we(!1),s.ue.success("Dashboard saved!"),le(ps(Qs,o.useDashboardStore.getState().semanticExecutionPayload)),ee(!1),re(!1),U&&(Me(),ue(),Ks&&je()),ce("close")},onError:T=>{we(!1),te("Failed to save dashboard. Please try again.");const z=T.details,pe=Array.isArray(z==null?void 0:z.errors)?(z.errors||[]).filter(xe=>typeof xe=="string"):[];ae($t({errors:pe,dashboard:I||void 0})),s.ue.error("Failed to save dashboard")}})}async function qs(){if(F(!0),!g||!b)return;const l=o.useDashboardStore.getState().dashboard;if(!l){F(!1);return}const I=JSON.stringify(l),U={...b,template:I,filterValues:Cs};await Pe(a.apiServiceUrl,U,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),ye==null||ye(l),F(!1)}const Ze=(b==null?void 0:b.name)||u.title;Q.isPending&&console.log("Title during update:",{title:Ze,dashboardStateTitle:u.title,dashboardId:u==null?void 0:u.id,currentLensName:b==null?void 0:b.name});const es=a.orgUserId||a.tenantId&&a.endUserId&&a.endUserEmail,Bs=!!es&&!!(t!=null&&t.accessToken)&&!!(a!=null&&a.apiServiceUrl),zs=c,B=(u==null?void 0:u.id)||null,Hs=qt((os=a.config)==null?void 0:os.showBriefings,r),he=!!B&&Ms===B,Vs=()=>{B&&Ls({dashboardId:he?null:B})};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:[es&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{"aria-label":"Manage Dashboards",tooltip:"Manage Dashboards",onClick:()=>{Ns(!ws)},className:"h-7 w-7 px-0",buttonProps:{size:"xs"},children:e.jsx(at,{className:"h-3.5 w-3.5"})}),zs&&!k&&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"})})]}),!k&&c&&(f?e.jsx("div",{className:"h-4 w-28 animate-pulse rounded-md bg-muted/70","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:Ze||"Untitled Dashboard",onSave:l=>{console.log("EditableText onSave called:",{newTitle:l,canEditDashboard:oe,dashboardId:u==null?void 0:u.id});const I=(u==null?void 0:u.title)||"";C(l),Os(l,I)},isEditable:oe&&!b,displayClassName:"text-[13px] font-medium",inputClassName:"text-[13px] font-medium",placeholder:"Dashboard Title",isPending:Q.isPending}),Bs&&B&&e.jsx(o.TooltipProvider,{children:e.jsxs(o.Tooltip,{children:[e.jsx(o.TooltipTrigger,{asChild:!0,children:e.jsx(o.Button,{variant:"ghost",size:"xs",onClick:Vs,disabled:Es||!(t!=null&&t.accessToken)||!(a!=null&&a.apiServiceUrl),className:"w-7 px-0","aria-label":he?"Remove as default dashboard":"Make this a default dashboard",children:e.jsx(s.Star,{className:o.cn("h-3.5 w-3.5 transition-colors",he?"fill-foreground text-foreground":"text-muted-foreground hover:text-foreground")})})}),e.jsx(o.TooltipContent,{children:e.jsx("p",{children:he?"Remove as default dashboard":"Make this a default dashboard"})})]})})]}))]}),e.jsxs("div",{className:"flex items-center gap-2",children:[k&&e.jsxs(e.Fragment,{children:[e.jsx(R.AdvancedModeToggle,{}),e.jsx(R.VisualEditingControls,{})]}),!k&&c&&((is=_==null?void 0:_.permissions)==null?void 0:is.canShare)&&e.jsxs(o.Button,{variant:"outline",size:"xs",onClick:()=>$(!0),children:[e.jsx(s.Share2,{className:"h-3.5 w-3.5"}),"Share"]}),!k&&!S&&c&&B&&Hs&&e.jsx(R.DashboardBriefingLauncher,{dashboardId:B,dashboardTitle:(u==null?void 0:u.title)||(_==null?void 0:_.title)}),!k&&S&&h.canUseFilters&&c&&e.jsx(R.DashboardFilterControlsLauncher,{}),S&&!k&&W&&b&&i&&c&&e.jsxs(o.Button,{variant:"secondary",size:"xs",disabled:G,onClick:qs,children:[e.jsx(ls.Save,{className:"h-3.5 w-3.5"}),"Save Lens"]}),S&&!k&&c&&!L&&e.jsxs(o.Button,{variant:"outline",size:"xs",disabled:!S,onClick:()=>ks(),children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Visual"]}),!k&&!S&&oe&&c&&e.jsxs(o.Button,{size:"xs",onClick:Ps,children:[e.jsx(s.Pencil,{className:"h-3.5 w-3.5"}),"Edit"]}),Ke&&c&&Je&&e.jsxs(o.Button,{variant:"outline",size:"xs",onClick:Gs,disabled:me,children:[e.jsx(R.Undo2,{className:"h-3.5 w-3.5"}),"Undo"]}),Ke&&c&&e.jsxs(o.Button,{size:"xs",className:o.cn(!Xe&&"opacity-60"),disabled:me||!Xe,onClick:()=>Le(),children:[me?e.jsx(o.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(ls.Save,{className:"h-3.5 w-3.5"}),me?"Saving...":"Save"]}),S&&!k&&c&&e.jsxs(o.Button,{variant:"outline",size:"xs",onClick:Us,children:[e.jsx(s.Cross2Icon,{className:"h-3.5 w-3.5"}),"Close"]}),!k&&c&&e.jsx("div",{className:"ml-2",children:e.jsx(R.NotificationBell,{})}),!k&&i&&e.jsx(ut,{}),!k&&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-control border border-border/60 p-1 shadow-sm",children:[e.jsx(s.DropdownMenuLabel,{children:"Reports"}),e.jsxs(s.DropdownMenuItem,{disabled:m,onSelect:()=>H(!0),children:[e.jsx(s.Download,{className:"h-3.5 w-3.5"}),"Export"]}),e.jsx(s.DropdownMenuSeparator,{}),As&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuLabel,{children:"Access"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>X(!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:()=>v(!0),children:[e.jsx(s.Calendar,{className:"h-3.5 w-3.5"}),"Calendar Preferences"]}),i&&c&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuSeparator,{}),e.jsx(s.DropdownMenuLabel,{children:"Developer"}),e.jsxs(s.DropdownMenuItem,{onSelect:()=>{var l;t!=null&&t.accessToken&&((l=navigator==null?void 0:navigator.clipboard)!=null&&l.writeText?navigator.clipboard.writeText(t.accessToken).then(()=>s.ue.success("Token copied to clipboard")).catch(()=>s.ue.error("Unable to copy token")):s.ue.error("Clipboard not available"))},children:[e.jsx(s.Copy,{className:"h-3.5 w-3.5"}),"Copy token"]}),L&&e.jsxs(s.DropdownMenuItem,{disabled:!Ce,onSelect:()=>{var l;if(!Ce){s.ue.error("Open a document sheet with a token to copy the local PDF URL");return}(l=navigator==null?void 0:navigator.clipboard)!=null&&l.writeText?navigator.clipboard.writeText(Ce).then(()=>s.ue.success("Local document PDF URL copied to clipboard")).catch(()=>s.ue.error("Unable to copy local document PDF URL")):s.ue.error("Clipboard not available")},children:[e.jsx(s.Copy,{className:"h-3.5 w-3.5"}),"Copy local document PDF URL"]}),e.jsxs(s.DropdownMenuItem,{onSelect:()=>o.invalidateToken(a.apiServiceUrl),children:[e.jsx(ot,{className:"h-3.5 w-3.5"}),"Invalidate token"]}),e.jsxs(s.DropdownMenuItem,{onSelect:d,children:[e.jsx(Zs.Palette,{className:"h-3.5 w-3.5"}),"Brand Studio"]}),S&&e.jsxs(s.DropdownMenuItem,{onSelect:()=>ze(!qe),children:[e.jsx(et.Braces,{className:"h-3.5 w-3.5"}),qe?"Hide dashboard JSON":"Show dashboard JSON"]}),W&&S&&e.jsxs(s.DropdownMenuItem,{onSelect:()=>O(!0),children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Add lens"]}),W&&e.jsxs(s.DropdownMenuSub,{children:[e.jsxs(s.DropdownMenuSubTrigger,{children:[e.jsx(tt,{className:"h-3.5 w-3.5"}),"Lenses"]}),e.jsx(s.DropdownMenuSubContent,{className:"w-60",children:e.jsx(ft,{})})]})]})]})]}),M&&Ve&&e.jsx(s.ShareDialog,{resource:Ve,resourceType:s.ResourceType.DASHBOARD,onClose:()=>$(!1)}),e.jsx(Ft,{open:be,onOpenChange:X}),e.jsx(Ys.CalendarPreferencesDialog,{open:ve,onOpenChange:v}),i&&W&&c&&e.jsx(xt,{open:A,onOpenChange:O}),c&&e.jsx(s.DownloadPdf,{open:q,onOpenChange:H}),e.jsx(s.AlertDialog,{open:Z,onOpenChange:l=>{!l&&De&&!se||(ee(l),l||(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(l=>e.jsx("li",{children:l},l))})]})]}),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:()=>{ee(!1),te(null),ae([]),re(!1)},className:"m-0",children:"Close"}),e.jsx(s.AlertDialogAction,{onClick:()=>Le({closeAfterSave:$e,navigateHomeAfterSave:Ne==="home"}),className:"m-0",children:"Retry"})]}):e.jsxs(s.AlertDialogAction,{disabled:!0,className:"m-0 cursor-default",children:[e.jsx(o.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]})})]})}),e.jsx(R.UnsavedChangesAlert,{open:Ts,onOpenChange:l=>{K(l)},onSave:Rs,onDiscard:Fs,isSaving:De,saveLabel:"Save",discardLabel:"Discard"})]})]})}function zt({accessToken:t,dashboardId:a,selectedSheetId:n,pageSize:r,orientation:i,theme:d}){if(!t||!n)return null;const h=new URL("http://localhost:5173/print-document");h.searchParams.set("token",t),a&&h.searchParams.set("dashboardId",a),h.searchParams.set("selectedSheetId",n),d&&h.searchParams.set("theme",d);const c=new URL("http://127.0.0.1:3002/");return c.searchParams.set("pdfMode","document"),c.searchParams.set("pageSize",r||"letter"),c.searchParams.set("orientation",i||"portrait"),c.searchParams.set("url",h.toString()),c.toString()}exports.default=Bt;