react-semaphor 0.1.435 → 0.1.437
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/{dashboard-BSHDErvU.js → dashboard--OqogTLn.js} +23217 -23170
- package/dist/chunks/{dashboard-Bp3M6YmS.js → dashboard-BJr7m1TP.js} +208 -208
- package/dist/chunks/dashboard-briefing-launcher-BRjtoHFz.js +31 -0
- package/dist/chunks/{dashboard-briefing-launcher-D-QS3bYN.js → dashboard-briefing-launcher-Cegf8sog.js} +752 -740
- package/dist/chunks/{dashboard-controls-BKaTTk-y.js → dashboard-controls-BjWzQbOT.js} +884 -874
- package/dist/chunks/dashboard-controls-DbOKYwbJ.js +36 -0
- package/dist/chunks/{dashboard-json-BkL6Xf10.js → dashboard-json-BYHE2Xi7.js} +1 -1
- package/dist/chunks/{dashboard-json-DrOZ5EP1.js → dashboard-json-D3rtzp8l.js} +1 -1
- package/dist/chunks/{edit-dashboard-visual-DOFAJpQh.js → edit-dashboard-visual-3rc-aeNO.js} +2 -2
- package/dist/chunks/{edit-dashboard-visual-BcV0QmRp.js → edit-dashboard-visual-BKTpoR38.js} +702 -699
- package/dist/chunks/{report-preferences-dialog-BiCnXwKt.js → report-preferences-dialog-CoYKKbFc.js} +1 -1
- package/dist/chunks/{report-preferences-dialog-Nib_Yl_j.js → report-preferences-dialog-VVM61k5R.js} +1 -1
- package/dist/chunks/{use-create-flow-overlay-state-CG5Se5yF.js → use-create-flow-overlay-state-CpH9832I.js} +1 -1
- package/dist/chunks/{use-create-flow-overlay-state-CNdny3Z2.js → use-create-flow-overlay-state-Doo8NeYf.js} +1 -1
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/data-app-builder/index.cjs +1 -1
- package/dist/data-app-builder/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +4 -4
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +2 -2
- package/dist/types/dashboard.d.ts +2 -0
- package/dist/types/main.d.ts +2 -0
- package/dist/types/surfboard.d.ts +2 -0
- package/dist/types/types.d.ts +2 -0
- package/package.json +1 -1
- package/dist/chunks/dashboard-briefing-launcher-C9phmdyP.js +0 -31
- package/dist/chunks/dashboard-controls-Znhp6MTa.js +0 -36
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),d=require("./code-editor-BSENCZwR.js"),t=require("./dashboard-Bp3M6YmS.js"),U=require("./index-jSrCwPQz.js");require("./analyze-result-contract-BswhsmWT.js");require("../value-format-preferences/index.cjs");const g=require("react");require("./index-Dpm_VET4.js");require("./comparison-document-migration-DbU_BTxR.js");const Zs=require("react-dom");require("../briefings/index.cjs");const V=require("./dashboard-briefing-launcher-C9phmdyP.js"),ys=require("./search-Dcud9ajy.js"),js=require("./index-D7KJindZ.js"),et=require("./report-preferences-dialog-BiCnXwKt.js"),st=require("./use-debounced-dirty-check-XHSwAefL.js"),Be=require("./normalize-dashboard-for-dirty-check-BXRUMVb2.js"),fs=require("./save-Xdc4pnys.js"),tt=require("./palette-C0yjT5Tv.js"),rt=require("./braces-CbO-aIwH.js");function at(s){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const a in s)if(a!=="default"){const r=Object.getOwnPropertyDescriptor(s,a);Object.defineProperty(n,a,r.get?r:{enumerable:!0,get:()=>s[a]})}}return n.default=s,Object.freeze(n)}const L=at(g);/**
|
|
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 nt=U.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 ot=U.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"}]]);/**
|
|
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 it=U.createLucideIcon("Moon",[["path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z",key:"a7tn18"}]]);/**
|
|
17
|
-
* @license lucide-react v0.453.0 - ISC
|
|
18
|
-
*
|
|
19
|
-
* This source code is licensed under the ISC license.
|
|
20
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
-
*/const dt=U.createLucideIcon("ShieldX",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m14.5 9.5-5 5",key:"17q4r4"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]]);/**
|
|
22
|
-
* @license lucide-react v0.453.0 - ISC
|
|
23
|
-
*
|
|
24
|
-
* This source code is licensed under the ISC license.
|
|
25
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
-
*/const lt=U.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"}]]);/**
|
|
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 ct=U.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"}]]);/**
|
|
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 ws=U.createLucideIcon("UserRound",[["circle",{cx:"12",cy:"8",r:"5",key:"1hypcn"}],["path",{d:"M20 21a8 8 0 0 0-16 0",key:"rfgkzh"}]]),Se=["light","dark","system"];function ut(){const{theme:s,setTheme:n}=t.useTheme(),a=d.useDashboardStore(x=>x.actions.setDashboardTheme);function r(){const x=Se.includes(s)?s:"system",h=Se[(Se.indexOf(x)+1)%Se.length];n(h),a(h)}const o=s==="light"?lt:s==="dark"?it:ot,c=s==="light"?"Theme: light (click for dark)":s==="dark"?"Theme: dark (click for system)":"Theme: system (click for light)";return e.jsx(d.Button,{type:"button",variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:r,"aria-label":c,title:c,children:e.jsx(o,{className:"h-3.5 w-3.5",strokeWidth:1.5})})}function Ds(s){const n=new Date().toISOString(),a=t.buildDashboardSheetsInputExecutionSnapshot({dashboard:s.dashboard,sheetIds:(s.dashboard.sheets||[]).filter(r=>r.kind!=="document").map(r=>r.id),sheetKind:"dashboard",mode:"dashboard",generatedAt:n,runtimeValues:{dashboardInputValues:s.dashboardInputValues,filterValues:s.filterValues,controlValues:s.controlValues,inlineFilterValuesMap:s.inlineFilterValuesMap,cardControlValuesMap:s.cardControlValuesMap}}).snapshot;return{generatedAt:n,dashboardInputValues:a.dashboardInputValues}}async function mt(s,n,a,r,o,c){if(!c)return null;const x=JSON.stringify(a),h=`${s}/v1/lens`;return await d.postRequest(h,c,{name:n,template:x,filterValues:r,inputValues:o,operation:"create"})}async function $e(s,n,a){if(!a)return null;const{id:r,template:o,filterValues:c,inputValues:x,isDefault:h,shared:p}=n,j=`${s}/v1/lens`;return await d.postRequest(j,a,{lensId:r,template:o,filterValues:c,inputValues:x,isDefault:h,shared:p,operation:"update"})}async function ht(s,n,a){if(!a)return null;const r=`${s}/v1/lens`;return await d.postRequest(r,a,{operation:"delete",lensId:n})}const pt="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function xt({open:s,onOpenChange:n}={}){const[a,r]=g.useState(""),[o,c]=g.useState(!1),x=d.useDashboardStore(y=>y.lenses),{setLenses:h,setSelectedLensId:p}=d.useDashboardActions(),[j,l]=g.useState(!1),[m,v]=g.useState(!1),f=s!==void 0,D=f?s:m,w=y=>{f||v(y),n==null||n(y)},u=d.useDashboardStore(y=>y.dashboard),k=d.useDashboardStore(y=>y.filterValues),{authToken:S,tokenProps:E}=t.useSemaphorContext();async function N(){l(!0);const y=d.useDashboardStore.getState(),q=Ds({dashboard:u,dashboardInputValues:y.dashboardInputValues,filterValues:k,controlValues:y.controlValues,inlineFilterValuesMap:y.inlineFilterValuesMap,cardControlValuesMap:y.cardControlValuesMap}),B=await mt(E.apiServiceUrl,a,u,k,q,S==null?void 0:S.accessToken);B&&(h([...x||[],B]),p(B.id),w(!1)),l(!1)}return e.jsxs(t.Dialog,{open:D,onOpenChange:w,children:[f?null:e.jsx(t.DialogTrigger,{asChild:!0,children:e.jsxs(d.Button,{variant:"secondary",size:"xs",children:[e.jsx(t.Plus,{className:"h-3.5 w-3.5"}),"Lens"]})}),e.jsxs(t.DialogContent,{className:"rounded-control border-border/60 sm:max-w-[420px] sm:rounded-control",children:[e.jsxs(t.DialogHeader,{children:[e.jsx(t.DialogTitle,{className:"text-[15px]",children:"Create lens"}),e.jsx(t.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(d.Label,{htmlFor:"lens-name",className:pt,children:"Name"}),e.jsx(d.Input,{id:"lens-name",size:"xs",value:a,placeholder:"Monthly review, West region, …",onChange:y=>r(y.target.value)}),o&&e.jsx("p",{className:"text-[12px] text-destructive",children:"A lens with this name already exists. Pick a different one."})]}),e.jsxs(t.DialogFooter,{children:[e.jsx(d.Button,{variant:"outline",size:"xs",onClick:()=>w(!1),children:"Cancel"}),e.jsx(d.Button,{size:"xs",type:"submit",onClick:N,disabled:j||!a.trim(),children:j?"Creating…":"Create"})]})]})]})}function ft({includeLabel:s=!1}={}){const n=d.useDashboardStore(l=>l.lenses),a=d.useDashboardStore(l=>l.selectedLensId),{setLenses:r,setSelectedLensId:o}=d.useDashboardActions(),{authToken:c,tokenProps:x}=t.useSemaphorContext();async function h(l){o(l)}async function p(l){if(await ht(x.apiServiceUrl,l,c==null?void 0:c.accessToken)){const v=n==null?void 0:n.filter(f=>f.id!==l);r(v||[]),o("original")}}async function j(l){const m=n==null?void 0:n.map(D=>D.id===l.id?{...D,isDefault:!l.isDefault}:{...D,isDefault:!1});r(m||[]);const v={...l,isDefault:!l.isDefault};await $e(x.apiServiceUrl,v,c==null?void 0:c.accessToken);const f=n==null?void 0:n.find(D=>D.isDefault);if(f&&f.id!==l.id){const D={...f,isDefault:!1};await $e(x.apiServiceUrl,D,c==null?void 0:c.accessToken)}}return e.jsxs(e.Fragment,{children:[s?e.jsxs(e.Fragment,{children:[e.jsx(t.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(t.DropdownMenuSeparator,{})]}):null,e.jsxs(t.DropdownMenuRadioGroup,{value:a,onValueChange:h,children:[e.jsx(t.DropdownMenuRadioItem,{value:"original",children:"Original"}),n==null?void 0:n.map(l=>e.jsxs(t.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:l.id,children:[e.jsx("p",{children:l.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(t.House,{onClick:m=>{m.preventDefault(),j(l)},className:d.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!l.isDefault,"text-green-500":l.isDefault}),strokeWidth:1.5}),e.jsx(t.Cross2Icon,{onClick:m=>{m.preventDefault(),p(l.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},l.id))]})]})}function gt(){const{displayPreferences:s,shouldShowElement:n}=t.useDisplayPreferences(),{currentUser:a,userContext:r}=t.useCurrentUserInfo(),o=g.useMemo(()=>t.getRoleBasedDisplayOverrides(a),[a]),c=g.useMemo(()=>h=>o&&o[h]!==void 0&&o[h]===!1?!1:n(h),[o,n,s]),x=g.useMemo(()=>{var h,p,j,l,m;return{canEdit:((h=r==null?void 0:r.permissions)==null?void 0:h.canEdit)??t.canUserEdit(a),canUseFilters:((p=r==null?void 0:r.permissions)==null?void 0:p.canEdit)??t.canUserUseFilters(a),canManageDashboards:((j=r==null?void 0:r.permissions)==null?void 0:j.canCreateDashboard)??t.canUserManageDashboards(a),canCreateDashboards:((l=r==null?void 0:r.permissions)==null?void 0:l.canCreateDashboard)??t.canUserCreateDashboards(a),canAccessVisuals:((m=r==null?void 0:r.permissions)==null?void 0:m.canEdit)??t.canUserAccessVisuals(a)}},[a,r]);return{displayPreferences:s,shouldShowElement:c,permissions:x,currentUser:a}}var Ge="Avatar",[bt]=d.createContextScope(Ge),vt=[0,()=>{}],[yt,Ns]=bt(Ge),ze=L.forwardRef((s,n)=>{const{__scopeAvatar:a,...r}=s,[o,c]=L.useState("idle"),[x,h]=wt();return e.jsx(yt,{scope:a,imageLoadingStatus:o,setImageLoadingStatus:c,imageCount:x,setImageCount:h,children:e.jsx(d.Primitive.span,{...r,ref:n})})});ze.displayName=Ge;var Ss="AvatarImage",_e=L.forwardRef((s,n)=>{const{__scopeAvatar:a,src:r,onLoadingStatusChange:o,...c}=s,x=Ns(Ss,a);Dt(x.setImageCount);const h=jt(r,{referrerPolicy:c.referrerPolicy,crossOrigin:c.crossOrigin,loadingStatus:x.imageLoadingStatus,setLoadingStatus:x.setImageLoadingStatus}),p=d.useCallbackRef(l=>{o==null||o(l)}),j=L.useRef(h);return d.useLayoutEffect2(()=>{const l=j.current;j.current=h,h!==l&&p(h)},[h,p]),h==="loaded"?e.jsx(d.Primitive.img,{...c,ref:n,src:r}):null});_e.displayName=Ss;var Cs="AvatarFallback",He=L.forwardRef((s,n)=>{const{__scopeAvatar:a,delayMs:r,...o}=s,c=Ns(Cs,a),[x,h]=L.useState(r===void 0);return L.useEffect(()=>{if(r!==void 0){const p=window.setTimeout(()=>h(!0),r);return()=>window.clearTimeout(p)}},[r]),x&&c.imageLoadingStatus!=="loaded"?e.jsx(d.Primitive.span,{...o,ref:n}):null});He.displayName=Cs;function jt(s,{loadingStatus:n,setLoadingStatus:a,referrerPolicy:r,crossOrigin:o}){return d.useLayoutEffect2(()=>{if(!s){a("error");return}const c=new window.Image,x=p=>{const j=p.currentTarget;a(gs(j))},h=()=>a("error");return c.addEventListener("load",x),c.addEventListener("error",h),r&&(c.referrerPolicy=r),c.crossOrigin=o??null,c.src=s,a(gs(c)),()=>{c.removeEventListener("load",x),c.removeEventListener("error",h),a("idle")}},[s,o,r,a]),n}function gs(s){return s.complete?s.naturalWidth>0?"loaded":"error":"loading"}function wt(){let s=vt;{s=L.useState(0);const[n]=s,a=L.useRef(!1);L.useEffect(()=>{n>1&&!a.current&&(a.current=!0,console.warn("Avatar: Only one `Avatar.Image` component should be rendered per `Avatar.Root`, but multiple were detected. This will lead to unexpected behavior."))},[n])}return s}function Dt(s){L.useEffect(()=>(s(n=>n+1),()=>{s(n=>n-1)}),[s])}const ks=L.forwardRef(({className:s,...n},a)=>e.jsx(ze,{ref:a,className:d.cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",s),...n}));ks.displayName=ze.displayName;const Nt=L.forwardRef(({className:s,...n},a)=>e.jsx(_e,{ref:a,className:d.cn("aspect-square h-full w-full",s),...n}));Nt.displayName=_e.displayName;const Ms=L.forwardRef(({className:s,...n},a)=>e.jsx(He,{ref:a,className:d.cn("flex h-full w-full items-center justify-center rounded-full bg-muted",s),...n}));Ms.displayName=He.displayName;const St=async(s,n,a)=>{const r=`${s}/management/v1/groups`;return await d.postRequestRegular(r,n,a)},Ct=async(s,n,a,r)=>{const o=`${s}/management/v1/groups/${a}`;return d.requestJsonRegular(o,n,"PATCH",r)},kt=async(s,n,a)=>{const r=`${s}/management/v1/groups/${a}`;await d.requestJsonRegular(r,n,"DELETE")},Mt=async(s,n,a,r)=>{const o=`${s}/management/v1/groups/${a}/members`;return await d.postRequestRegular(o,n,r)},It=async(s,n,a,r)=>{const o=`${s}/management/v1/groups/${a}/members`;await d.requestJsonRegular(o,n,"DELETE",r)};function Lt(){const{authToken:s,tokenProps:n}=t.useSemaphorContext(),a=t.useQueryClient();return t.useMutation({mutationFn:r=>St(n.apiServiceUrl,(s==null?void 0:s.accessToken)||"",r),onSuccess:()=>{a.invalidateQueries({queryKey:["groups"]}),t.ue.success("Group created successfully")},onError:r=>{console.error("Failed to create group:",r),t.ue.error("Failed to create group",{description:d.getRequestErrorMessage(r,"Failed to create group")})}})}function Et(){const{authToken:s,tokenProps:n}=t.useSemaphorContext(),a=t.useQueryClient();return t.useMutation({mutationFn:({groupId:r,data:o})=>Ct(n.apiServiceUrl,(s==null?void 0:s.accessToken)||"",r,o),onSuccess:(r,o)=>{a.invalidateQueries({queryKey:["group",o.groupId]}),a.invalidateQueries({queryKey:["groups"]}),t.ue.success("Group updated successfully")},onError:r=>{console.error("Failed to update group:",r),t.ue.error("Failed to update group",{description:d.getRequestErrorMessage(r,"Failed to update group")})}})}function At(){const{authToken:s,tokenProps:n}=t.useSemaphorContext(),a=t.useQueryClient();return t.useMutation({mutationFn:r=>kt(n.apiServiceUrl,(s==null?void 0:s.accessToken)||"",r),onSuccess:(r,o)=>{a.invalidateQueries({queryKey:["groups"]}),a.removeQueries({queryKey:["group",o]}),t.ue.success("Group deleted successfully")},onError:r=>{console.error("Failed to delete group:",r),t.ue.error("Failed to delete group",{description:d.getRequestErrorMessage(r,"Failed to delete group")})}})}function Pt(){const{authToken:s,tokenProps:n}=t.useSemaphorContext(),a=t.useQueryClient();return t.useMutation({mutationFn:({groupId:r,data:o})=>Mt(n.apiServiceUrl,(s==null?void 0:s.accessToken)||"",r,o),onSuccess:(r,o)=>{a.invalidateQueries({queryKey:["group",o.groupId]}),a.invalidateQueries({queryKey:["group-members",o.groupId]}),a.invalidateQueries({queryKey:["groups"]}),t.ue.success("Members added successfully")},onError:r=>{console.error("Failed to add group members:",r),t.ue.error("Failed to add members",{description:d.getRequestErrorMessage(r,"Failed to add members")})}})}function Rt(){const{authToken:s,tokenProps:n}=t.useSemaphorContext(),a=t.useQueryClient();return t.useMutation({mutationFn:({groupId:r,data:o})=>It(n.apiServiceUrl,(s==null?void 0:s.accessToken)||"",r,o),onSuccess:(r,o)=>{a.invalidateQueries({queryKey:["group",o.groupId]}),a.invalidateQueries({queryKey:["group-members",o.groupId]}),a.invalidateQueries({queryKey:["groups"]}),t.ue.success("Members removed successfully")},onError:r=>{console.error("Failed to remove group members:",r),t.ue.error("Failed to remove members",{description:d.getRequestErrorMessage(r,"Failed to remove members")})}})}const Ut=[];function Ft({open:s,onOpenChange:n}){var S,E,N;const{tokenProps:a}=t.useSemaphorContext(),{currentUser:r}=t.useCurrentUserInfo(),o=(r==null?void 0:r.type)==="tenant",c=a==null?void 0:a.tenantId,{groups:x,isLoading:h,error:p,refetch:j}=t.useGroups({type:o?"TENANT_GROUP":"all",tenantId:o?c:void 0,includeMembers:!1}),l=p?Is(p,"Unable to load groups."):null,[m,v]=g.useState({kind:"list"}),[f,D]=g.useState(null),w=At();g.useEffect(()=>{s||(v({kind:"list"}),D(null))},[s]);const u=m.kind==="members"&&x.find(y=>y.id===m.groupId)||null,k=async()=>{if(f)try{await w.mutateAsync(f.id),D(null),v({kind:"list"}),j()}catch{}};return e.jsx(t.Dialog,{open:s,onOpenChange:n,children:e.jsxs(t.DialogContent,{className:"flex max-h-[640px] w-[720px] max-w-[92vw] flex-col gap-0 overflow-hidden p-0",children:[m.kind==="list"?e.jsxs("div",{className:"shrink-0 border-b border-border px-5 pt-4 pb-3.5",children:[e.jsx(t.DialogTitle,{className:"text-[15px] font-semibold tracking-tight",children:"Group management"}),e.jsx(t.DialogDescription,{className:"mt-1 text-[12px] leading-[1.5] text-muted-foreground",children:"Organize people into groups for shared access."})]}):m.kind==="create"?e.jsxs("div",{className:"flex h-10 shrink-0 items-center gap-1.5 border-b border-border px-5",children:[e.jsx("button",{type:"button",onClick:()=>v({kind:"list"}),"aria-label":"Back",className:"-ml-1 flex h-6 w-6 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-accent hover:text-foreground",children:e.jsx(t.ArrowLeft,{className:"h-3.5 w-3.5"})}),e.jsx(t.DialogTitle,{className:"truncate text-[13px] font-medium",children:"New group"}),e.jsx(t.DialogDescription,{className:"sr-only",children:"Create a new group to organize members."})]}):null,m.kind==="list"&&e.jsx(Tt,{groups:x,isLoading:h,errorMessage:l,onRetry:()=>j(),currentUserId:r==null?void 0:r.id,onOpenGroup:y=>v({kind:"members",groupId:y}),onCreate:()=>v({kind:"create"}),onDeleteRequest:y=>D(y)}),m.kind==="members"&&u&&e.jsx(qt,{group:u,isTenantViewer:o,canEdit:((S=u.permissions)==null?void 0:S.canEdit)??u.createdBy===(r==null?void 0:r.id),canDelete:((E=u.permissions)==null?void 0:E.canDelete)??u.createdBy===(r==null?void 0:r.id),canManageMembers:((N=u.permissions)==null?void 0:N.canManageMembers)??u.createdBy===(r==null?void 0:r.id),onBack:()=>v({kind:"list"}),onMembersChanged:j,onUpdated:j,onRequestDelete:()=>D(u)},u.id),m.kind==="create"&&e.jsx(Bt,{isTenantUser:o,tenantId:c,onCancel:()=>v({kind:"list"}),onCreated:y=>{j(),v({kind:"members",groupId:y})}}),f&&e.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border bg-muted/40 px-5 py-2.5",children:[e.jsxs("div",{className:"min-w-0 text-[12px] text-foreground",children:["Delete ",e.jsx("span",{className:"font-medium",children:f.name}),"?",e.jsx("span",{className:"ml-2 text-muted-foreground",children:"Members lose any access granted via this group."})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>D(null),disabled:w.isPending,className:"h-7 rounded-[5px] px-2.5 text-[12px] font-medium text-foreground/80 hover:bg-background",children:"Cancel"}),e.jsxs("button",{type:"button",onClick:k,disabled:w.isPending,className:"inline-flex h-7 items-center gap-1.5 rounded-[5px] bg-rose-600 px-2.5 text-[12px] font-medium text-white hover:bg-rose-700 disabled:opacity-60",children:[w.isPending?e.jsx(d.LoaderCircle,{className:"h-3 w-3 animate-spin"}):e.jsx(t.Trash2,{className:"h-3 w-3"}),"Delete group"]})]})]})]})})}function Tt({groups:s,isLoading:n,errorMessage:a,onRetry:r,currentUserId:o,onOpenGroup:c,onCreate:x,onDeleteRequest:h}){const[p,j]=g.useState(""),l=g.useMemo(()=>s.filter(m=>!p.trim()||m.name.toLowerCase().includes(p.toLowerCase())||(m.description||"").toLowerCase().includes(p.toLowerCase())),[s,p]);return e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-5 py-2.5",children:[e.jsxs("div",{className:"flex flex-1 items-center gap-2 rounded-[5px] border border-border bg-background px-2 focus-within:border-foreground/40",children:[e.jsx(ys.Search,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("input",{value:p,onChange:m=>j(m.target.value),placeholder:"Search groups…",className:"h-7 flex-1 bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground focus:outline-none"}),p&&e.jsx("button",{type:"button",onClick:()=>j(""),className:"flex h-4 w-4 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-accent hover:text-foreground",children:e.jsx(U.X,{className:"h-2.5 w-2.5"})})]}),e.jsxs("button",{type:"button",onClick:x,className:"inline-flex h-7 items-center gap-1.5 rounded-[5px] bg-foreground px-2.5 text-[12px] font-medium text-background hover:opacity-90",children:[e.jsx(t.Plus,{className:"h-3 w-3"}),"New group"]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:n?e.jsx("div",{className:"space-y-px p-3",children:[1,2,3].map(m=>e.jsx("div",{className:"h-12 animate-pulse rounded-[4px] bg-muted/60"},m))}):a?e.jsx(Ls,{title:"Can't load groups",message:a,onRetry:r}):l.length===0&&s.length===0?e.jsx(Vt,{onCreate:x}):l.length===0?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-1 py-10 text-center",children:[e.jsxs("div",{className:"text-[12px] text-foreground",children:['No groups match "',p,'"']}),e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"Try a different search."})]}):l.map(m=>{var v;return e.jsx(Ot,{group:m,canDelete:((v=m.permissions)==null?void 0:v.canDelete)??m.createdBy===o,onClick:()=>c(m.id),onDelete:()=>h(m)},m.id)})})]})}function Ot({group:s,canDelete:n,onClick:a,onDelete:r}){let o="";try{o=js.format(new Date(s.createdAt),"MMM d, yyyy")}catch{o=""}return e.jsxs("button",{type:"button",onClick:a,className:"group flex w-full items-center gap-3 border-b border-border/60 px-5 py-2.5 text-left hover:bg-accent/40",children:[e.jsx("div",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-[4px] border border-border bg-background text-muted-foreground",children:e.jsx(t.UsersRound,{className:"h-3.5 w-3.5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-foreground",children:s.name}),e.jsxs("div",{className:"mt-0.5 flex items-center gap-2 text-[11px] text-muted-foreground",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(ws,{className:"h-2.5 w-2.5"}),s.memberCount," member",s.memberCount===1?"":"s"]}),o&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-border",children:"·"}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(t.Calendar,{className:"h-2.5 w-2.5"}),o]})]}),s.description&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-border",children:"·"}),e.jsx("span",{className:"truncate text-muted-foreground",children:s.description})]})]})]}),e.jsxs("div",{className:"flex items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100",children:[n&&e.jsx("span",{role:"button",tabIndex:0,onClick:c=>{c.stopPropagation(),r()},onKeyDown:c=>{(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),c.stopPropagation(),r())},"aria-label":`Delete ${s.name}`,className:"flex h-6 w-6 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-accent hover:text-foreground",children:e.jsx(t.Trash2,{className:"h-3 w-3"})}),e.jsx(ys.ChevronRight,{className:"h-3.5 w-3.5 text-muted-foreground"})]})]})}function Vt({onCreate:s}){return e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 py-12 text-center",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-full border border-border bg-muted/40 text-muted-foreground",children:e.jsx(t.Users,{className:"h-4 w-4"})}),e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:"No groups yet"}),e.jsx("div",{className:"max-w-[320px] text-[11.5px] leading-[1.55] text-muted-foreground",children:"Groups let you grant shared access to dashboards. Create one and add members."}),e.jsxs("button",{type:"button",onClick:s,className:"mt-1 inline-flex h-7 items-center gap-1.5 rounded-[5px] bg-foreground px-2.5 text-[12px] font-medium text-background hover:opacity-90",children:[e.jsx(t.Plus,{className:"h-3 w-3"}),"New group"]})]})}function qt({group:s,isTenantViewer:n,canEdit:a,canDelete:r,canManageMembers:o,onBack:c,onMembersChanged:x,onUpdated:h,onRequestDelete:p}){const{data:j,isLoading:l,error:m,refetch:v}=t.useGroupMembers(s.id),f=(j==null?void 0:j.members)??Ut,D=m?Is(m,"Unable to load members for this group."):null,w=s.type==="TENANT_GROUP"?"tenant":"organization",{users:u}=t.useUnifiedUsers({type:w,tenantId:s.tenantId||void 0,active:!0,limit:200}),k=g.useMemo(()=>new Set(f.map(b=>b.userId)),[f]),S=Pt(),E=Rt(),N=Et(),[y,q]=g.useState(!1),[B,$]=g.useState(s.name),[Ce,G]=g.useState(!1),[J,z]=g.useState(s.description||""),[X,Y]=g.useState(""),[ce,Q]=g.useState(!1),ke=g.useMemo(()=>{const b=X.trim().toLowerCase();return u.filter(A=>!k.has(A.id)).filter(A=>!b||(A.name||"").toLowerCase().includes(b)||(A.email||"").toLowerCase().includes(b)).slice(0,50)},[u,k,X]),Z=async()=>{const b=B.trim();if(q(!1),b.length>=3&&b!==s.name)try{await N.mutateAsync({groupId:s.id,data:{name:b}}),h()}catch{}},ue=async()=>{const b=J.trim();if(G(!1),b!==(s.description||""))try{await N.mutateAsync({groupId:s.id,data:{description:b}}),h()}catch{}},me=async b=>{if(o){Y(""),Q(!1);try{await S.mutateAsync({groupId:s.id,data:{userIds:[b.id],userType:w==="tenant"?"tenant":"org"}}),v(),x()}catch{}}},Me=async b=>{if(o)try{await E.mutateAsync({groupId:s.id,data:{userIds:[b]}}),v(),x()}catch{}};let F="";try{F=js.format(new Date(s.createdAt),"MMM d, yyyy")}catch{F=""}return e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex h-10 shrink-0 items-center gap-1.5 border-b border-border px-5",children:[e.jsx("button",{type:"button",onClick:c,"aria-label":"Back",className:"-ml-1 flex h-6 w-6 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-accent hover:text-foreground",children:e.jsx(t.ArrowLeft,{className:"h-3.5 w-3.5"})}),y?e.jsx("input",{autoFocus:!0,value:B,onChange:b=>$(b.target.value),onBlur:Z,onKeyDown:b=>{b.key==="Enter"&&Z(),b.key==="Escape"&&($(s.name),q(!1))},className:"h-6 min-w-0 flex-1 rounded-[3px] border border-border bg-background px-1.5 text-[13px] font-medium text-foreground focus:border-foreground/40 focus:outline-none"}):e.jsx("button",{type:"button",onClick:()=>{a&&($(s.name),q(!0))},title:a?"Click to rename":s.name,disabled:!a,className:"truncate rounded-[3px] px-1 text-[13px] font-medium text-foreground enabled:hover:bg-accent disabled:cursor-default",children:s.name}),e.jsxs("span",{className:"ml-1 inline-flex shrink-0 items-center gap-1 text-[10.5px] text-muted-foreground",children:[e.jsx(ws,{className:"h-2.5 w-2.5"}),f.length," member",f.length===1?"":"s"]})]}),e.jsx("div",{className:"shrink-0 border-b border-border px-5 py-2.5",children:Ce?e.jsxs("div",{children:[e.jsx("textarea",{autoFocus:!0,rows:2,value:J,onChange:b=>z(b.target.value),maxLength:200,onKeyDown:b=>{b.key==="Escape"&&(z(s.description||""),G(!1)),b.key==="Enter"&&(b.metaKey||b.ctrlKey)&&ue()},placeholder:"What is this group for?",className:"block w-full resize-none rounded-[5px] border border-border bg-background px-2 py-1.5 text-[12px] text-foreground placeholder:text-muted-foreground focus:border-foreground/40 focus:outline-none"}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-between",children:[e.jsxs("span",{className:"text-[10.5px] text-muted-foreground",children:[J.length,"/200 · Esc to cancel · ⌘↩ to save"]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>{z(s.description||""),G(!1)},className:"h-6 rounded-[5px] px-2 text-[11px] font-medium text-foreground/80 hover:bg-accent",children:"Cancel"}),e.jsx("button",{type:"button",onClick:ue,className:"inline-flex h-6 items-center rounded-[5px] bg-foreground px-2 text-[11px] font-medium text-background hover:opacity-90",children:"Save"})]})]})]}):e.jsxs("button",{type:"button",onClick:()=>{a&&(z(s.description||""),G(!0))},disabled:!a,title:a?"Click to edit description":void 0,className:"block w-full rounded-[3px] px-1 py-0.5 text-left enabled:hover:bg-accent/40 disabled:cursor-default",children:[s.description?e.jsx("p",{className:"text-[12px] leading-[1.55] text-foreground/90",children:s.description}):e.jsx("p",{className:"text-[12px] leading-[1.55] text-muted-foreground",children:a?"Add a description…":"No description"}),e.jsxs("p",{className:"mt-1 text-[10.5px] text-muted-foreground",children:[F?`Created ${F}`:"Recently created",a?" · You can edit this group":""]})]})}),o&&e.jsx($t,{query:X,setQuery:Y,open:ce,setOpen:Q,candidates:ke,showKindChip:!n,onAdd:me,busy:S.isPending}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:l?e.jsx("div",{className:"space-y-px p-3",children:[1,2,3].map(b=>e.jsx("div",{className:"h-10 animate-pulse rounded-[4px] bg-muted/60"},b))}):D?e.jsx(Ls,{title:"Can't load members",message:D,onRetry:()=>v()}):f.length===0?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-1 py-10 text-center",children:[e.jsx("div",{className:"text-[12px] text-foreground",children:"No members yet"}),e.jsx("div",{className:"text-[11px] text-muted-foreground",children:o?"Search above to add people to this group.":"This group does not have any members."})]}):f.map(b=>{var A,ee,_,se,H,he;return e.jsxs("div",{className:"group flex items-center gap-2 border-b border-border/60 px-5 py-2",children:[e.jsx(Es,{name:((A=b.user)==null?void 0:A.name)||((ee=b.user)==null?void 0:ee.email)||"?"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[12.5px] font-medium text-foreground",children:((_=b.user)==null?void 0:_.name)||((se=b.user)==null?void 0:se.email)||"Unknown"}),((H=b.user)==null?void 0:H.email)&&b.user.name&&e.jsx("div",{className:"truncate text-[10.5px] text-muted-foreground",children:b.user.email})]}),!n&&e.jsx("span",{className:"text-[10px] uppercase tracking-[0.06em] text-muted-foreground",children:b.userType}),e.jsx("button",{type:"button",onClick:()=>Me(b.userId),disabled:!o||E.isPending,"aria-label":`Remove ${((he=b.user)==null?void 0:he.name)||"member"}`,className:"flex h-6 w-6 items-center justify-center rounded-[3px] text-muted-foreground opacity-0 transition-opacity hover:bg-accent hover:text-foreground group-hover:opacity-100 disabled:opacity-30",children:e.jsx(U.X,{className:"h-3 w-3"})})]},b.id)})}),r&&e.jsx("div",{className:"flex shrink-0 items-center justify-end gap-1.5 border-t border-border bg-muted/30 px-5 py-2.5",children:e.jsxs("button",{type:"button",onClick:p,className:"inline-flex h-7 items-center gap-1.5 rounded-[5px] border border-rose-200 bg-background px-2.5 text-[12px] font-medium text-rose-600 hover:bg-rose-50 dark:border-rose-900/60 dark:text-rose-400 dark:hover:bg-rose-950/30",children:[e.jsx(t.Trash2,{className:"h-3 w-3"}),"Delete group"]})})]})}function Bt({isTenantUser:s,tenantId:n,onCancel:a,onCreated:r}){const[o,c]=g.useState(""),[x,h]=g.useState(""),[p,j]=g.useState(null),l=Lt(),m=o.trim().length>=3&&o.trim().length<=50,v=async()=>{if(!m)return;j(null);const f={name:o.trim(),description:x.trim()||void 0,type:s?"TENANT_GROUP":"ORG_GROUP",...s&&n?{tenantId:n}:{}};try{const D=await l.mutateAsync(f),w=D==null?void 0:D.id;w?r(w):a()}catch(D){j(D instanceof Error?D.message:"Failed to create group")}};return e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:[e.jsx(bs,{children:"Name"}),e.jsx("input",{autoFocus:!0,value:o,onChange:f=>c(f.target.value),placeholder:"Marketing leads, North America sales, …",maxLength:50,className:"mt-1 block h-7 w-full rounded-[5px] border border-border bg-background px-2 text-[12px] text-foreground placeholder:text-muted-foreground focus:border-foreground/40 focus:outline-none"}),e.jsx("div",{className:"mt-1 text-[10.5px] text-muted-foreground",children:"3–50 characters."}),e.jsxs("div",{className:"mt-4",children:[e.jsx(bs,{children:"Description (optional)"}),e.jsx("textarea",{rows:2,value:x,onChange:f=>h(f.target.value),maxLength:200,placeholder:"What is this group for?",className:"mt-1 block w-full resize-none rounded-[5px] border border-border bg-background px-2 py-1.5 text-[12px] text-foreground placeholder:text-muted-foreground focus:border-foreground/40 focus:outline-none"}),e.jsxs("div",{className:"mt-1 flex justify-end text-[10.5px] text-muted-foreground",children:[x.length,"/200"]})]}),p&&e.jsx("div",{className:"mt-3 rounded-[5px] border border-rose-200 bg-rose-50 px-2 py-1.5 text-[11.5px] text-rose-700 dark:border-rose-900/60 dark:bg-rose-950/30 dark:text-rose-300",children:p})]}),e.jsxs("div",{className:"flex shrink-0 items-center justify-end gap-1.5 border-t border-border bg-muted/30 px-5 py-2.5",children:[e.jsx("button",{type:"button",onClick:a,disabled:l.isPending,className:"h-7 rounded-[5px] px-2.5 text-[12px] font-medium text-foreground/80 hover:bg-accent",children:"Cancel"}),e.jsx("button",{type:"button",onClick:v,disabled:!m||l.isPending,className:"inline-flex h-7 items-center gap-1.5 rounded-[5px] bg-foreground px-2.5 text-[12px] font-medium text-background hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-60",children:l.isPending?e.jsxs(e.Fragment,{children:[e.jsx(d.LoaderCircle,{className:"h-3 w-3 animate-spin"}),"Creating…"]}):e.jsxs(e.Fragment,{children:[e.jsx(t.Plus,{className:"h-3 w-3"}),"Create group"]})})]})]})}function $t({query:s,setQuery:n,open:a,setOpen:r,candidates:o,showKindChip:c,onAdd:x,busy:h}){const p=g.useRef(null),j=g.useRef(null),[l,m]=g.useState(null);g.useLayoutEffect(()=>{if(!a){m(null);return}const f=()=>{const D=p.current;if(!D)return;const w=D.getBoundingClientRect(),u=240,S=window.innerHeight-w.bottom<u+16&&w.top>u;m({left:w.left,top:S?w.top-6:w.bottom+6,width:w.width,above:S})};return f(),window.addEventListener("resize",f),window.addEventListener("scroll",f,!0),()=>{window.removeEventListener("resize",f),window.removeEventListener("scroll",f,!0)}},[a,o.length]),g.useEffect(()=>{if(!a)return;const f=D=>{var u,k;const w=D.target;(u=p.current)!=null&&u.contains(w)||(k=j.current)!=null&&k.contains(w)||r(!1)};return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[a,r]);const v=a&&o.length>0&&l;return e.jsxs("div",{className:"shrink-0 border-b border-border px-5 py-2.5",children:[e.jsxs("div",{ref:p,className:"flex items-center gap-2 rounded-[5px] border border-border bg-background px-2 focus-within:border-foreground/40",children:[e.jsx(ct,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("input",{value:s,onChange:f=>{n(f.target.value),r(!0)},onFocus:()=>r(!0),placeholder:"Add a member by name or email…",disabled:h,className:"h-7 flex-1 bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground focus:outline-none disabled:cursor-not-allowed"})]}),v&&typeof document<"u"&&Zs.createPortal(e.jsx("div",{ref:j,style:{position:"fixed",left:l.left,top:l.top,width:l.width,transform:l.above?"translateY(-100%)":void 0},className:"z-[60] max-h-[240px] overflow-y-auto rounded-[5px] border border-border bg-background shadow-[0_8px_24px_-12px_rgba(0,0,0,0.18)]",children:o.map(f=>e.jsxs("button",{type:"button",onClick:()=>x(f),className:"flex w-full items-center gap-2 border-b border-border/60 px-2.5 py-2 text-left last:border-b-0 hover:bg-accent",children:[e.jsx(Es,{name:f.name||f.email||"?"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[12px] font-medium text-foreground",children:f.name||f.email||"Unknown"}),f.email&&f.name&&e.jsx("div",{className:"truncate text-[10.5px] text-muted-foreground",children:f.email})]}),c&&f.type&&e.jsx("span",{className:"text-[10px] uppercase tracking-[0.06em] text-muted-foreground",children:f.type==="tenant"?"tenant":"org"})]},f.id))}),document.body)]})}function Is(s,n){if(!s)return n;if(s instanceof Error){const a=s.message||"",r=a.match(/\{[\s\S]*"error"\s*:\s*"([^"]+)"[\s\S]*\}/);return r?r[1]:a||n}return typeof s=="string"?s:n}function Ls({title:s,message:n,onRetry:a}){return e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 px-6 py-10 text-center",children:[e.jsx("div",{className:"text-[12.5px] font-medium text-foreground",children:s}),e.jsx("div",{className:"max-w-[360px] text-[11.5px] leading-[1.55] text-muted-foreground",children:n}),a&&e.jsx("button",{type:"button",onClick:a,className:"mt-1 inline-flex h-7 items-center rounded-[5px] border border-border bg-background px-2.5 text-[11.5px] font-medium text-foreground hover:bg-accent",children:"Try again"})]})}function bs({children:s}){return e.jsx("label",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:s})}function Es({name:s}){const n=s.split(" ").map(a=>a[0]).filter(Boolean).slice(0,2).join("").toUpperCase();return e.jsx(ks,{className:"h-6 w-6 shrink-0",children:e.jsx(Ms,{className:"text-[9px] font-semibold",children:n||"?"})})}function de(s,n,a){var c,x;const r=(s.controls||[]).find(h=>h.id===a);if(r)return r.label;const o=(x=(c=d.findCardById(s,n))==null?void 0:c.controls)==null?void 0:x.find(h=>h.id===a);return(o==null?void 0:o.label)||a}function le(s,n){var a;return((a=d.findCardById(s,n))==null?void 0:a.title)||n}function Gt(s){const{errors:n,dashboard:a}=s;if(!a)return n;const r=new Map;for(const o of n){const c=o.match(/^Card '(.+)' binding for control '(.+)' maps to missing metric '(.+)'\.$/);if(c){const[,l,m]=c,v=`${l}:${m}:missing-metric`;r.has(v)||r.set(v,`"${le(a,l)}" has an outdated "${de(a,l,m)}" mapping. Some choices still point to metrics that are no longer available on this card. Open the card controls and choose replacements.`);continue}const x=o.match(/^Card '(.+)' binding for control '(.+)' maps to missing group-by field '(.+)'\.$/);if(x){const[,l,m]=x,v=`${l}:${m}:missing-group-by`;r.has(v)||r.set(v,`"${le(a,l)}" has an outdated "${de(a,l,m)}" mapping. Some choices still point to fields that are no longer available on this card. Open the card controls and choose replacements.`);continue}const h=o.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid metric target\.$/);if(h){const[,l,m]=h,v=`${l}:${m}:invalid-metric`;r.has(v)||r.set(v,`"${le(a,l)}" has an invalid "${de(a,l,m)}" metric mapping. Open the card controls and choose a valid metric for each option.`);continue}const p=o.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid group-by target\.$/);if(p){const[,l,m]=p,v=`${l}:${m}:invalid-group-by`;r.has(v)||r.set(v,`"${le(a,l)}" has an invalid "${de(a,l,m)}" field mapping. Open the card controls and choose a valid field for each option.`);continue}const j=o.match(/^Card '(.+)' binding for control '(.+)' requires at least one temporal group-by field\.$/);if(j){const[,l,m]=j,v=`${l}:${m}:missing-temporal-group-by`;r.has(v)||r.set(v,`"${le(a,l)}" can no longer use "${de(a,l,m)}" for time grain because the card does not currently group by a date field.`);continue}r.set(o,o)}return Array.from(r.values())}function zt({visible:s,onSelect:n}){return s?e.jsxs(t.DropdownMenuItem,{onSelect:n,children:[e.jsx(t.CalendarClock,{className:"h-3.5 w-3.5"}),"Schedule email report"]}):null}function _t({scheduleReportVisible:s,analyticalBriefingVisible:n,onScheduleReport:a,onCreateAnalyticalBriefing:r}){return e.jsxs(e.Fragment,{children:[e.jsx(zt,{visible:s,onSelect:a}),n?e.jsxs(t.DropdownMenuItem,{onSelect:r,children:[e.jsx(t.Plus,{className:"h-3.5 w-3.5"}),"Create analytical briefing"]}):null]})}function vs(s,n){return{dashboard:t.cloneDeep(s),semanticExecutionPayload:t.cloneDeep(n)}}function Ht(){var ds,ls,cs,us,ms,hs,ps;V.useExportRecovery(),V.useExportPolling();const{authToken:s,tokenProps:n,id:a,showBriefings:r}=t.useSemaphorContext(),o=t.useBriefingUiCapabilities(),{isLocalDev:c}=t.useDashboardPreferences(),{openBrandStudioPreview:x}=t.useBrandStudioPreview(),{permissions:h}=gt(),p=t.useHasDashboardId(),{isLoading:j}=t.useDashboardQuery(),l=d.useDashboardStore(i=>i.theme),m=d.useDashboardStore(i=>i.isDownloadingPdf),v=d.useDashboardStore(i=>i.dashboardAssistantDraftScopeKey),f=d.useDashboardStore(i=>i.lenses),D=d.useDashboardStore(i=>i.selectedLensId),w=f==null?void 0:f.find(i=>i.id===D),u=d.useDashboardStore(i=>i.dashboard),k=d.useDashboardStore(i=>i.selectedSheetId),S=(ds=u==null?void 0:u.sheets)==null?void 0:ds.find(i=>i.id===k),E=d.isDocumentSheet(S),N=E?(ls=S==null?void 0:S.document)==null?void 0:ls.page:void 0,y=d.useDashboardStore(i=>i.isDashboardEditing),{setDashboardTitle:q}=d.useDashboardStore(i=>i.actions),[B,$]=g.useState(!1),[Ce,G]=g.useState(!1),[J,z]=g.useState(!1),[X,Y]=g.useState(!1),[ce,Q]=g.useState(null),[ke,Z]=g.useState(!1),[ue,me]=g.useState(!1),[Me,F]=g.useState(!1),[b,A]=g.useState(null),[ee,_]=g.useState([]),[se,H]=g.useState(!1),[he,Ke]=g.useState(!1),Qe=d.useDashboardStore(i=>i.filterValues),M=d.useDashboardStore(i=>i.isVisualEditing);d.useEditorStore(i=>i.card);const te=t.useManagementStore(i=>i.selectedDashboard),pe=t.useManagementStore(i=>i.initialDashboard);t.useManagementStore(i=>i.selectedVisual),d.useDashboardStore(i=>i.selectedFrameId),d.useEditorStore(i=>i.frame);const xe=te?(us=te==null?void 0:te.permissions)==null?void 0:us.canEdit:(cs=pe==null?void 0:pe.permissions)==null?void 0:cs.canEdit,We=d.useDashboardStore(i=>i.showDashboardJSON),Ie=d.useDashboardStore(i=>i.onSaveFunction),{setIsDashboardEditing:Je,setShowDashboardJSON:Xe}=d.useDashboardStore(i=>i.actions),{setInitialDashboard:Ye,clearSelectedDashboard:Le}=t.useManagementStore(i=>i.actions),re=!!n.orgUserId||!!(n.tenantId&&n.endUserId&&n.endUserEmail),{resources:fe}=t.useResourceManagement(t.ResourceType.DASHBOARD),{data:Ee}=t.useUserPreferences(),As=((ms=Ee==null?void 0:Ee.preference)==null?void 0:ms.defaultDashboardId)||null,{mutate:Ps,isPending:Rs}=t.useDefaultDashboardMutation(),{currentUser:Us}=t.useCurrentUserInfo(),Fs=t.canUserManageGroups(Us),T=te||pe,W=t.resolveDashboardControlsVisibility({config:n.config,canNavigateDashboardHub:re,canShareDashboard:((hs=T==null?void 0:T.permissions)==null?void 0:hs.canShare)===!0,canManageGroups:Fs}),Ze=T?{id:T.id,title:(u==null?void 0:u.title)||T.title||"Dashboard"}:null,{handleAddNewFrame:Ts}=t.useAddNewFrame(),[Ae,Pe]=g.useState(!1),[Os,ae]=g.useState(!1),[Re,ge]=g.useState("close"),ne=t.useUpdateResource(t.ResourceType.DASHBOARD),[P,be]=g.useState(null),Vs=async(i,C)=>{if(!(u!=null&&u.id)){console.log("No dashboard ID found");return}console.log("Updating dashboard title:",{dashboardId:u.id,newTitle:i,previousTitle:C}),ne.mutate({resourceId:u.id,data:{title:i}},{onSuccess:()=>{console.log("Dashboard title updated successfully"),t.ue.success("Dashboard title updated")},onError:R=>{console.error("Failed to update dashboard title:",R),t.ue.error("Failed to update dashboard title"),q(C)}})};g.useEffect(()=>{if(fe&&fe.length>0){const i=u==null?void 0:u.id;if(i){const C=fe.find(R=>R.id===i);C&&Ye(C)}}},[fe,u==null?void 0:u.id,Ye]);const oe=n.orgUserId||n.tenantId,Ue=g.useMemo(()=>Kt({accessToken:s==null?void 0:s.accessToken,dashboardId:(u==null?void 0:u.id)||a||n.dashboard_id,selectedSheetId:E?k:void 0,pageSize:N==null?void 0:N.size,orientation:N==null?void 0:N.orientation,theme:l}),[s==null?void 0:s.accessToken,a,u==null?void 0:u.id,E,N==null?void 0:N.orientation,N==null?void 0:N.size,k,l,n.dashboard_id]),es=y&&!M&&oe&&xe,{setDashboard:ss}=d.useDashboardStore(i=>i.actions),ts=d.useDashboardStore(i=>i.semanticExecutionPayload),qs=()=>{Je(!0)},Fe=()=>{Je(!1),Xe(!1),be(null)};g.useEffect(()=>{if(!y){P&&be(null);return}P||!u||j||be(vs(u,ts))},[u,P,y,j,ts]);const ve=(P==null?void 0:P.dashboard)??null,{isDirty:rs,isDirtyPending:Bs,resetDirty:ye}=st.useDebouncedDirtyCheck(u,ve,300,1e3,Be.serializeDashboardForDirtyCheck),as=g.useCallback(()=>ve?Be.serializeDashboardForDirtyCheck(u)!==Be.serializeDashboardForDirtyCheck(ve):!1,[u,ve]),ns=rs||Bs,je=Ae||ne.isPending,$s=()=>{as()?(ge("close"),ae(!0)):(Fe(),ye())},Gs=async()=>{await Te({closeAfterSave:!0,navigateHomeAfterSave:Re==="home"})},zs=()=>{const i=Re==="home"&&!!re;P&&ss(P.dashboard,{semanticExecutionPayload:P.semanticExecutionPayload}),Fe(),i&&Le(),ge("close"),ae(!1),ye()},_s=()=>{P&&(ss(P.dashboard,{semanticExecutionPayload:P.semanticExecutionPayload}),ye())},Hs=()=>{if(re){if(y&&as()){ge("home"),ae(!0);return}Le()}};async function Te(i){const C=d.useDashboardStore.getState().dashboard;if(!C)return;const R=(i==null?void 0:i.closeAfterSave)??se,Oe=(i==null?void 0:i.navigateHomeAfterSave)??!1;H(R),R&&ae(!1);const Ve=t.cloneDeep(C);F(!0),A(null),_([]),Pe(!0);const Ys={template:C};ne.mutate({resourceId:C.id,data:Ys},{onSuccess:I=>{var we,De,xs;const K=(I==null?void 0:I.id)||((we=I==null?void 0:I.dashboard)==null?void 0:we.id)||((De=I==null?void 0:I.resource)==null?void 0:De.id)||((xs=I==null?void 0:I.template)==null?void 0:xs.id)||null;if(!C.id&&K){const qe=d.useAIInteractionStore.getState(),Ne=qe.pendingDashboardDraftMigration;(Ne==null?void 0:Ne.scopeKey)===v?qe.actions.setPendingDashboardDraftMigrationExpectedDashboardId(K):Ne&&qe.actions.clearPendingDashboardDraftMigration()}Pe(!1),t.ue.success("Dashboard saved!"),be(vs(Ve,d.useDashboardStore.getState().semanticExecutionPayload)),F(!1),H(!1),R&&(Fe(),ye(),Oe&&re&&Le()),ge("close")},onError:I=>{Pe(!1),A("Failed to save dashboard. Please try again.");const K=I.details,we=Array.isArray(K==null?void 0:K.errors)?(K.errors||[]).filter(De=>typeof De=="string"):[];_(Gt({errors:we,dashboard:C||void 0})),t.ue.error("Failed to save dashboard")}})}async function Ks(){if($(!0),!D||!w)return;const i=d.useDashboardStore.getState().dashboard;if(!i){$(!1);return}const C=JSON.stringify(i),R=d.useDashboardStore.getState(),Oe=Ds({dashboard:i,dashboardInputValues:R.dashboardInputValues,filterValues:Qe,controlValues:R.controlValues,inlineFilterValuesMap:R.inlineFilterValuesMap,cardControlValuesMap:R.cardControlValuesMap}),Ve={...w,template:C,filterValues:Qe,inputValues:Oe};await $e(n.apiServiceUrl,Ve,s==null?void 0:s.accessToken),t.ue.success("Lens saved"),Ie==null||Ie(i),$(!1)}const os=(w==null?void 0:w.name)||u.title;ne.isPending&&console.log("Title during update:",{title:os,dashboardStateTitle:u.title,dashboardId:u==null?void 0:u.id,currentLensName:w==null?void 0:w.name});const Qs=re&&!!(s!=null&&s.accessToken)&&!!(n!=null&&n.apiServiceUrl),Ws=W.showDashboardHub&&Qs,Js=p&&W.showDashboardHub,O=(u==null?void 0:u.id)||null,is=t.resolveDashboardBriefingsVisibility((ps=n.config)==null?void 0:ps.showBriefings,r),ie=!!O&&As===O,Xs=()=>{O&&Ps({dashboardId:ie?null:O})};return!p&&!M?null: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:[Js&&!M&&e.jsx(t.IconButton,{"aria-label":"Dashboard Hub",tooltip:"Dashboard Hub",onClick:Hs,className:"h-7 w-7 px-0",buttonProps:{size:"xs"},children:e.jsx(t.House,{className:"h-3.5 w-3.5"})}),!M&&p&&(j?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(t.EditableText,{value:os||"Untitled Dashboard",onSave:i=>{console.log("EditableText onSave called:",{newTitle:i,canEditDashboard:xe,dashboardId:u==null?void 0:u.id});const C=(u==null?void 0:u.title)||"";q(i),Vs(i,C)},isEditable:t.resolveDashboardTitleEditability({isDashboardEditing:y,canEditDashboard:xe===!0,hasCurrentLens:!!w}),displayClassName:"text-[13px] font-medium",inputClassName:"text-[13px] font-medium",placeholder:"Dashboard Title",isPending:ne.isPending}),W.showDashboardHub&&ie&&e.jsx("span",{className:"shrink-0 rounded-[4px] border border-border/60 px-1.5 py-px text-[10px] font-medium uppercase tracking-[0.06em] text-muted-foreground",title:"Default dashboard",children:"Default"}),Ws&&O&&e.jsx(d.TooltipProvider,{children:e.jsxs(d.Tooltip,{children:[e.jsx(d.TooltipTrigger,{asChild:!0,children:e.jsx(d.Button,{variant:"ghost",size:"xs",onClick:Xs,disabled:Rs||!(s!=null&&s.accessToken)||!(n!=null&&n.apiServiceUrl),className:"w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":ie?"Clear default dashboard":"Set as default dashboard",children:ie?e.jsx(t.PinOff,{className:"h-3.5 w-3.5"}):e.jsx(t.Pin,{className:"h-3.5 w-3.5"})})}),e.jsx(d.TooltipContent,{children:e.jsx("p",{children:ie?"Clear default":"Set as default"})})]})})]}))]}),e.jsxs("div",{className:"flex items-center gap-2",children:[M&&e.jsxs(e.Fragment,{children:[e.jsx(V.AdvancedModeToggle,{}),e.jsx(V.VisualEditingControls,{})]}),!M&&p&&W.showDashboardSharing&&e.jsxs(d.Button,{variant:"outline",size:"xs",onClick:()=>G(!0),children:[e.jsx(t.Share2,{className:"h-3.5 w-3.5"}),"Share"]}),!M&&y&&h.canUseFilters&&p&&e.jsx(V.DashboardFilterControlsLauncher,{}),y&&!M&&oe&&w&&c&&p&&e.jsxs(d.Button,{variant:"secondary",size:"xs",disabled:B,onClick:Ks,children:[e.jsx(fs.Save,{className:"h-3.5 w-3.5"}),"Save Lens"]}),y&&!M&&p&&!E&&e.jsxs("div",{className:"inline-flex h-7 items-stretch overflow-hidden rounded-control border border-input bg-background",children:[e.jsxs(d.Button,{variant:"ghost",size:"xs",disabled:!y,onClick:()=>void Ts(),className:"h-full rounded-none border-0 shadow-none hover:bg-accent",children:[e.jsx(t.Plus,{className:"h-3.5 w-3.5"}),"Visual"]}),e.jsxs(t.DropdownMenu,{modal:!1,children:[e.jsx(t.DropdownMenuTrigger,{asChild:!0,children:e.jsx(d.Button,{variant:"ghost",size:"xs",className:"h-full w-7 rounded-none border-0 border-l border-border/60 px-0 shadow-none hover:bg-accent","aria-label":"Open visual options",disabled:!y,children:e.jsx(U.ChevronDown,{className:"h-3.5 w-3.5"})})}),e.jsx(t.DropdownMenuContent,{align:"end",className:"z-[60] w-48 rounded-[6px] border-border/60 p-1 shadow-sm",children:e.jsxs(t.DropdownMenuItem,{onClick:()=>Ke(!0),children:[e.jsx(t.Plus,{className:"h-3.5 w-3.5"}),"From library..."]})})]}),e.jsx(V.VisualsLibraryDialog,{open:he,onOpenChange:Ke})]}),!M&&!y&&xe&&p&&e.jsxs(d.Button,{size:"xs",onClick:qs,children:[e.jsx(t.Pencil,{className:"h-3.5 w-3.5"}),"Edit"]}),es&&p&&rs&&e.jsxs(d.Button,{variant:"outline",size:"xs",onClick:_s,disabled:je,children:[e.jsx(t.Undo2,{className:"h-3.5 w-3.5"}),"Undo"]}),es&&p&&e.jsxs(d.Button,{size:"xs",className:d.cn(!ns&&"opacity-60"),disabled:je||!ns,onClick:()=>Te(),children:[je?e.jsx(d.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(fs.Save,{className:"h-3.5 w-3.5"}),je?"Saving...":"Save"]}),y&&!M&&p&&e.jsxs(d.Button,{variant:"outline",size:"xs",onClick:$s,children:[e.jsx(t.Cross2Icon,{className:"h-3.5 w-3.5"}),"Close"]}),!M&&p&&e.jsx("div",{className:"ml-2",children:e.jsx(V.NotificationBell,{})}),!M&&c&&e.jsx(ut,{}),!M&&p&&e.jsxs(t.DropdownMenu,{children:[e.jsx(t.DropdownMenuTrigger,{asChild:!0,children:e.jsx(t.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(t.EllipsisVertical,{className:"h-3.5 w-3.5"})})}),e.jsxs(t.DropdownMenuContent,{align:"end",className:"w-56 rounded-control border border-border/60 p-1 shadow-sm",children:[e.jsx(t.DropdownMenuLabel,{children:"Reports & briefings"}),e.jsxs(t.DropdownMenuItem,{disabled:m,onSelect:()=>me(!0),children:[e.jsx(t.Download,{className:"h-3.5 w-3.5"}),"Export"]}),e.jsx(_t,{scheduleReportVisible:!!(is&&o.surfaceVisible&&O&&!y),analyticalBriefingVisible:!!(is&&o.surfaceVisible&&O&&!y),onScheduleReport:()=>Q("scheduled_report"),onCreateAnalyticalBriefing:()=>Q("analytical_briefing")}),e.jsx(t.DropdownMenuSeparator,{}),W.showGroupManagement&&e.jsxs(e.Fragment,{children:[e.jsx(t.DropdownMenuLabel,{children:"Access"}),e.jsxs(t.DropdownMenuItem,{onClick:()=>z(!0),children:[e.jsx(t.Users,{className:"h-3.5 w-3.5"}),"Manage Groups"]}),e.jsx(t.DropdownMenuSeparator,{})]}),e.jsx(t.DropdownMenuLabel,{children:"Preferences"}),e.jsxs(t.DropdownMenuItem,{onClick:()=>Y(!0),children:[e.jsx(t.Calendar,{className:"h-3.5 w-3.5"}),"Report preferences"]}),c&&p&&e.jsxs(e.Fragment,{children:[e.jsx(t.DropdownMenuSeparator,{}),e.jsx(t.DropdownMenuLabel,{children:"Developer"}),e.jsxs(t.DropdownMenuItem,{onSelect:()=>{var i;s!=null&&s.accessToken&&((i=navigator==null?void 0:navigator.clipboard)!=null&&i.writeText?navigator.clipboard.writeText(s.accessToken).then(()=>t.ue.success("Token copied to clipboard")).catch(()=>t.ue.error("Unable to copy token")):t.ue.error("Clipboard not available"))},children:[e.jsx(t.Copy,{className:"h-3.5 w-3.5"}),"Copy token"]}),E&&e.jsxs(t.DropdownMenuItem,{disabled:!Ue,onSelect:()=>{var i;if(!Ue){t.ue.error("Open a document sheet with a token to copy the local PDF URL");return}(i=navigator==null?void 0:navigator.clipboard)!=null&&i.writeText?navigator.clipboard.writeText(Ue).then(()=>t.ue.success("Local document PDF URL copied to clipboard")).catch(()=>t.ue.error("Unable to copy local document PDF URL")):t.ue.error("Clipboard not available")},children:[e.jsx(t.Copy,{className:"h-3.5 w-3.5"}),"Copy local document PDF URL"]}),e.jsxs(t.DropdownMenuItem,{onSelect:()=>d.invalidateToken(n.apiServiceUrl),children:[e.jsx(dt,{className:"h-3.5 w-3.5"}),"Invalidate token"]}),e.jsxs(t.DropdownMenuItem,{onSelect:x,children:[e.jsx(tt.Palette,{className:"h-3.5 w-3.5"}),"Brand Studio"]}),y&&e.jsxs(t.DropdownMenuItem,{onSelect:()=>Xe(!We),children:[e.jsx(rt.Braces,{className:"h-3.5 w-3.5"}),We?"Hide dashboard JSON":"Show dashboard JSON"]}),oe&&y&&e.jsxs(t.DropdownMenuItem,{onSelect:()=>Z(!0),children:[e.jsx(t.Plus,{className:"h-3.5 w-3.5"}),"Add lens"]}),oe&&e.jsxs(t.DropdownMenuSub,{children:[e.jsxs(t.DropdownMenuSubTrigger,{children:[e.jsx(nt,{className:"h-3.5 w-3.5"}),"Lenses"]}),e.jsx(t.DropdownMenuSubContent,{className:"w-60",children:e.jsx(ft,{})})]})]})]})]}),Ce&&Ze&&e.jsx(t.ShareDialog,{resource:Ze,resourceType:t.ResourceType.DASHBOARD,onClose:()=>G(!1)}),W.showGroupManagement&&e.jsx(Ft,{open:J,onOpenChange:z}),e.jsx(et.ReportPreferencesDialog,{open:X,onOpenChange:Y}),O&&ce?e.jsx(V.DashboardBriefingLauncher,{dashboardId:O,dashboardTitle:(u==null?void 0:u.title)||(T==null?void 0:T.title),open:!0,onOpenChange:i=>{i||Q(null)},hideTrigger:!0,workflowIntent:ce}):null,c&&oe&&p&&e.jsx(xt,{open:ke,onOpenChange:Z}),p&&e.jsx(t.DownloadPdf,{open:ue,onOpenChange:me}),e.jsx(t.AlertDialog,{open:Me,onOpenChange:i=>{!i&&Ae&&!b||(F(i),i||(A(null),_([]),H(!1)))},children:e.jsxs(t.AlertDialogContent,{className:"max-w-sm",children:[e.jsxs(t.AlertDialogHeader,{children:[e.jsx(t.AlertDialogTitle,{children:b?"Save failed":"Saving dashboard"}),e.jsx(t.AlertDialogDescription,{className:"pt-2",children:b?"We could not save the dashboard. Please try again.":"Please wait while we save your changes."}),ee.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:ee.slice(0,5).map(i=>e.jsx("li",{children:i},i))})]})]}),e.jsx(t.AlertDialogFooter,{className:"flex-col gap-2 sm:flex-row sm:justify-end",children:b?e.jsxs(e.Fragment,{children:[e.jsx(t.AlertDialogCancel,{onClick:()=>{F(!1),A(null),_([]),H(!1)},className:"m-0",children:"Close"}),e.jsx(t.AlertDialogAction,{onClick:()=>Te({closeAfterSave:se,navigateHomeAfterSave:Re==="home"}),className:"m-0",children:"Retry"})]}):e.jsxs(t.AlertDialogAction,{disabled:!0,className:"m-0 cursor-default",children:[e.jsx(d.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]})})]})}),e.jsx(V.UnsavedChangesAlert,{open:Os,onOpenChange:i=>{ae(i)},onSave:Gs,onDiscard:zs,isSaving:Ae,saveLabel:"Save",discardLabel:"Discard"})]})]})}function Kt({accessToken:s,dashboardId:n,selectedSheetId:a,pageSize:r,orientation:o,theme:c}){if(!s||!a)return null;const x=new URL("http://localhost:5173/print-document");x.searchParams.set("token",s),n&&x.searchParams.set("dashboardId",n),x.searchParams.set("selectedSheetId",a),c&&x.searchParams.set("theme",c);const h=new URL("http://127.0.0.1:3002/");return h.searchParams.set("pdfMode","document"),h.searchParams.set("pageSize",r||"letter"),h.searchParams.set("orientation",o||"portrait"),h.searchParams.set("url",x.toString()),h.toString()}exports.default=Ht;
|