react-semaphor 0.1.302 → 0.1.304

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 (56) hide show
  1. package/dist/appearance/index.cjs +1 -1
  2. package/dist/appearance/index.js +1 -1
  3. package/dist/brand-studio/index.cjs +5 -5
  4. package/dist/brand-studio/index.js +334 -385
  5. package/dist/chunks/common-types-C6cAQgyh.js +9 -0
  6. package/dist/chunks/common-types-nBuCd3u2.js +1 -0
  7. package/dist/chunks/{dashboard-controls-CZuC_QjN.js → dashboard-controls-CyFZfGaN.js} +800 -776
  8. package/dist/chunks/dashboard-controls-DCZnUFI0.js +47 -0
  9. package/dist/chunks/{dashboard-filter-controls-button-kfb_T18o.js → dashboard-filter-controls-button-DI7XUgZK.js} +142 -142
  10. package/dist/chunks/{dashboard-filter-controls-button-2I1ltWQ9.js → dashboard-filter-controls-button-YQZ-oeN5.js} +3 -3
  11. package/dist/chunks/{dashboard-json-Df6v2Jem.js → dashboard-json-C6R2qixD.js} +3 -3
  12. package/dist/chunks/{dashboard-json-C3v6rBdp.js → dashboard-json-Z8jz16Yj.js} +1 -1
  13. package/dist/chunks/{dashboard-summary-settings-dialog-DKAaWq-G.js → dashboard-summary-settings-dialog-BlD77h63.js} +2 -2
  14. package/dist/chunks/{dashboard-summary-settings-dialog-BBALEHJQ.js → dashboard-summary-settings-dialog-DJyY-PB9.js} +1 -1
  15. package/dist/chunks/{edit-dashboard-visual-CGBYahAK.js → edit-dashboard-visual-CNGc1zcN.js} +33 -33
  16. package/dist/chunks/{edit-dashboard-visual-D8L0cl_U.js → edit-dashboard-visual-CfRJXwDR.js} +167 -168
  17. package/dist/chunks/{index-uRJmUpof.js → index-CJdxSyQq.js} +679 -656
  18. package/dist/chunks/index-D2vz3gvd.js +1360 -0
  19. package/dist/chunks/index-DRlMUglg.js +4 -0
  20. package/dist/chunks/{index-BmoR3VQT.js → index-GHhvGdF9.js} +42745 -40322
  21. package/dist/chunks/{palette-326-dgn0.js → palette-BqJlrRto.js} +7 -2
  22. package/dist/chunks/{palette-jd7xiGTg.js → palette-DD-i7bNS.js} +23 -3
  23. package/dist/chunks/{resource-management-panel-C_c-BwrC.js → resource-management-panel-7Y4ITzGH.js} +65 -65
  24. package/dist/chunks/{resource-management-panel-DrcEEARD.js → resource-management-panel-Bdus73Iu.js} +1 -1
  25. package/dist/chunks/{rotate-ccw-BugHcM1w.js → rotate-ccw-CdGW8Rxm.js} +1 -1
  26. package/dist/chunks/{rotate-ccw-yFwqBFJZ.js → rotate-ccw-X8MbX_hF.js} +1 -1
  27. package/dist/chunks/{save-CaybXtdd.js → save-CFBIhbHD.js} +1 -1
  28. package/dist/chunks/{save-DU0FXUlM.js → save-j-clxFtx.js} +1 -1
  29. package/dist/chunks/{switch-CZtMtqEj.js → switch-BFhVVwh9.js} +4285 -3275
  30. package/dist/chunks/switch-BH17qlxH.js +163 -0
  31. package/dist/chunks/use-create-flow-overlay-state-CSytlf2H.js +16 -0
  32. package/dist/chunks/{use-create-flow-overlay-state-84Xe8VrP.js → use-create-flow-overlay-state-CllZvyvE.js} +318 -316
  33. package/dist/chunks/{use-visual-utils-lp5DfmvL.js → use-visual-utils-CDO4kVX5.js} +1 -1
  34. package/dist/chunks/{use-visual-utils-z3ifg6Fd.js → use-visual-utils-CyjLzcDG.js} +2 -2
  35. package/dist/dashboard/index.cjs +1 -1
  36. package/dist/dashboard/index.js +5 -5
  37. package/dist/index.cjs +1 -1
  38. package/dist/index.js +61 -60
  39. package/dist/style.css +1 -1
  40. package/dist/surfboard/index.cjs +1 -1
  41. package/dist/surfboard/index.js +6 -6
  42. package/dist/types/dashboard.d.ts +168 -0
  43. package/dist/types/index.cjs +1 -1
  44. package/dist/types/index.js +8 -11
  45. package/dist/types/main.d.ts +195 -2
  46. package/dist/types/shared.d.ts +120 -0
  47. package/dist/types/surfboard.d.ts +168 -0
  48. package/dist/types/types.d.ts +168 -0
  49. package/package.json +1 -1
  50. package/dist/chunks/braces-CpOcaBNm.js +0 -6
  51. package/dist/chunks/braces-TYclg8Hl.js +0 -23
  52. package/dist/chunks/dashboard-controls-BkuB9TQX.js +0 -47
  53. package/dist/chunks/index-Cxb9UUro.js +0 -4
  54. package/dist/chunks/index-eM6MU4q_.js +0 -1361
  55. package/dist/chunks/switch-AmoR1YIA.js +0 -163
  56. package/dist/chunks/use-create-flow-overlay-state-CiKVJGWF.js +0 -16
@@ -0,0 +1,47 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("./switch-BH17qlxH.js"),s=require("./index-D2vz3gvd.js"),b=require("react");require("./index-DRlMUglg.js");require("react-dom");const G=require("./dashboard-filter-controls-button-YQZ-oeN5.js"),it=require("./index-D7KJindZ.js"),xs=require("./dashboard-summary-settings-dialog-DJyY-PB9.js"),lt=require("./use-debounced-dirty-check-XHSwAefL.js"),Fe=require("./normalize-dashboard-for-dirty-check-BXRUMVb2.js"),gs=require("./use-create-flow-overlay-state-CSytlf2H.js"),bs=require("./save-CFBIhbHD.js"),vs=require("./palette-BqJlrRto.js");function ct(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 I=ct(b);/**
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 dt=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 ut=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 mt=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 ht=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 pt=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 ft=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"}]]);var Re={exports:{}},_e={};/**
32
+ * @license React
33
+ * use-sync-external-store-shim.production.js
34
+ *
35
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
36
+ *
37
+ * This source code is licensed under the MIT license found in the
38
+ * LICENSE file in the root directory of this source tree.
39
+ */var ys;function xt(){if(ys)return _e;ys=1;var t=b;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,c=t.useEffect,m=t.useLayoutEffect,d=t.useDebugValue;function f(x,p){var u=p(),i=r({inst:{value:u,getSnapshot:p}}),y=i[0].inst,w=i[1];return m(function(){y.value=u,y.getSnapshot=p,g(y)&&w({inst:y})},[x,u,p]),c(function(){return g(y)&&w({inst:y}),x(function(){g(y)&&w({inst:y})})},[x]),d(u),u}function g(x){var p=x.getSnapshot;x=x.value;try{var u=p();return!n(x,u)}catch{return!0}}function v(x,p){return p()}var h=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?v:f;return _e.useSyncExternalStore=t.useSyncExternalStore!==void 0?t.useSyncExternalStore:h,_e}var Ue={};/**
40
+ * @license React
41
+ * use-sync-external-store-shim.development.js
42
+ *
43
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
44
+ *
45
+ * This source code is licensed under the MIT license found in the
46
+ * LICENSE file in the root directory of this source tree.
47
+ */var Ss;function gt(){return Ss||(Ss=1,process.env.NODE_ENV!=="production"&&function(){function t(u,i){return u===i&&(u!==0||1/u===1/i)||u!==u&&i!==i}function a(u,i){h||c.startTransition===void 0||(h=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var y=i();if(!x){var w=i();m(y,w)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),x=!0)}w=d({inst:{value:y,getSnapshot:i}});var D=w[0].inst,C=w[1];return g(function(){D.value=y,D.getSnapshot=i,n(D)&&C({inst:D})},[u,y,i]),f(function(){return n(D)&&C({inst:D}),u(function(){n(D)&&C({inst:D})})},[u]),v(y),y}function n(u){var i=u.getSnapshot;u=u.value;try{var y=i();return!m(u,y)}catch{return!0}}function r(u,i){return i()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var c=b,m=typeof Object.is=="function"?Object.is:t,d=c.useState,f=c.useEffect,g=c.useLayoutEffect,v=c.useDebugValue,h=!1,x=!1,p=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?r:a;Ue.useSyncExternalStore=c.useSyncExternalStore!==void 0?c.useSyncExternalStore:p,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()),Ue}process.env.NODE_ENV==="production"?Re.exports=xt():Re.exports=gt();var bt=Re.exports;const je=["light","dark","system"];function vt(){const{theme:t,setTheme:a}=s.useTheme(),n=o.useDashboardStore(d=>d.actions.setDashboardTheme);function r(){const d=je.includes(t)?t:"system",f=je[(je.indexOf(d)+1)%je.length];a(f),n(f)}const c=t==="light"?ft:t==="dark"?ht:mt,m=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":m,title:m,children:e.jsx(c,{className:"h-3.5 w-3.5",strokeWidth:1.5})})}async function yt(t,a,n,r,c){if(!c)return null;const m=JSON.stringify(n),d=`${t}/v1/lens`;return await o.postRequest(d,c,{name:a,template:m,filterValues:r,operation:"create"})}async function qe(t,a,n){if(!n)return null;const{id:r,template:c,filterValues:m,isDefault:d,shared:f}=a,g=`${t}/v1/lens`;return await o.postRequest(g,n,{lensId:r,template:c,filterValues:m,isDefault:d,shared:f,operation:"update"})}async function St(t,a,n){if(!n)return null;const r=`${t}/v1/lens`;return await o.postRequest(r,n,{operation:"delete",lensId:a})}const jt="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function Dt({open:t,onOpenChange:a}={}){const[n,r]=b.useState(""),[c,m]=b.useState(!1),d=o.useDashboardStore(M=>M.lenses),{setLenses:f,setSelectedLensId:g}=o.useDashboardActions(),[v,h]=b.useState(!1),[x,p]=b.useState(!1),u=t!==void 0,i=u?t:x,y=M=>{u||p(M),a==null||a(M)},w=o.useDashboardStore(M=>M.dashboard),D=o.useDashboardStore(M=>M.filterValues),{authToken:C,tokenProps:N}=s.useSemaphorContext();async function E(){h(!0);const M=await yt(N.apiServiceUrl,n,w,D,C==null?void 0:C.accessToken);M&&(f([...d||[],M]),g(M.id),y(!1)),h(!1)}return e.jsxs(s.Dialog,{open:i,onOpenChange:y,children:[u?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:jt,children:"Name"}),e.jsx(o.Input,{id:"lens-name",size:"xs",value:n,placeholder:"Monthly review, West region, …",onChange:M=>r(M.target.value)}),c&&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:()=>y(!1),children:"Cancel"}),e.jsx(o.Button,{size:"xs",type:"submit",onClick:E,disabled:v||!n.trim(),children:v?"Creating…":"Create"})]})]})]})}function wt({includeLabel:t=!1}={}){const a=o.useDashboardStore(h=>h.lenses),n=o.useDashboardStore(h=>h.selectedLensId),{setLenses:r,setSelectedLensId:c}=o.useDashboardActions(),{authToken:m,tokenProps:d}=s.useSemaphorContext();async function f(h){c(h)}async function g(h){if(await St(d.apiServiceUrl,h,m==null?void 0:m.accessToken)){const p=a==null?void 0:a.filter(u=>u.id!==h);r(p||[]),c("original")}}async function v(h){const x=a==null?void 0:a.map(i=>i.id===h.id?{...i,isDefault:!h.isDefault}:{...i,isDefault:!1});r(x||[]);const p={...h,isDefault:!h.isDefault};await qe(d.apiServiceUrl,p,m==null?void 0:m.accessToken);const u=a==null?void 0:a.find(i=>i.isDefault);if(u&&u.id!==h.id){const i={...u,isDefault:!1};await qe(d.apiServiceUrl,i,m==null?void 0:m.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:f,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),a==null?void 0:a.map(h=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:h.id,children:[e.jsx("p",{children:h.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(s.House,{onClick:x=>{x.preventDefault(),v(h)},className:o.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!h.isDefault,"text-green-500":h.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:x=>{x.preventDefault(),g(h.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},h.id))]})]})}function Ct(){const{displayPreferences:t,shouldShowElement:a}=s.useDisplayPreferences(),{currentUser:n,userContext:r}=s.useCurrentUserInfo(),c=b.useMemo(()=>s.getRoleBasedDisplayOverrides(n),[n]),m=b.useMemo(()=>f=>c&&c[f]!==void 0&&c[f]===!1?!1:a(f),[c,a,t]),d=b.useMemo(()=>{var f,g,v,h,x;return{canEdit:((f=r==null?void 0:r.permissions)==null?void 0:f.canEdit)??s.canUserEdit(n),canUseFilters:((g=r==null?void 0:r.permissions)==null?void 0:g.canEdit)??s.canUserUseFilters(n),canManageDashboards:((v=r==null?void 0:r.permissions)==null?void 0:v.canCreateDashboard)??s.canUserManageDashboards(n),canCreateDashboards:((h=r==null?void 0:r.permissions)==null?void 0:h.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:m,permissions:d,currentUser:n}}const Nt=async(t,a,n)=>{const r=`${t}/management/v1/groups`;return await o.postRequestRegular(r,a,n)},Mt=async(t,a,n)=>{const r=`${t}/management/v1/groups/${n}`;await o.requestJsonRegular(r,a,"DELETE")},It=async(t,a,n,r)=>{const c=`${t}/management/v1/groups/${n}/members`;return await o.postRequestRegular(c,a,r)},Et=async(t,a,n,r)=>{const c=`${t}/management/v1/groups/${n}/members`;await o.requestJsonRegular(c,a,"DELETE",r)};function Lt(){const{authToken:t,tokenProps:a}=s.useSemaphorContext(),n=s.useQueryClient();return s.useMutation({mutationFn:r=>Nt(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 At(){const{authToken:t,tokenProps:a}=s.useSemaphorContext(),n=s.useQueryClient();return s.useMutation({mutationFn:r=>Mt(a.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r),onSuccess:(r,c)=>{n.invalidateQueries({queryKey:["groups"]}),n.removeQueries({queryKey:["group",c]}),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 Ot(){const{authToken:t,tokenProps:a}=s.useSemaphorContext(),n=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:c})=>It(a.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r,c),onSuccess:(r,c)=>{n.invalidateQueries({queryKey:["group",c.groupId]}),n.invalidateQueries({queryKey:["group-members",c.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 kt(){const{authToken:t,tokenProps:a}=s.useSemaphorContext(),n=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:c})=>Et(a.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r,c),onSuccess:(r,c)=>{n.invalidateQueries({queryKey:["group",c.groupId]}),n.invalidateQueries({queryKey:["group-members",c.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 js="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function Tt({onSuccess:t,tenantId:a,isTenantUser:n}){const[r,c]=b.useState(""),[m,d]=b.useState(""),[f,g]=b.useState({}),v=Lt(),h=()=>{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",m&&m.length>200&&(p.description="Description must be less than 200 characters"),g(p),Object.keys(p).length===0},x=async p=>{if(p.preventDefault(),!h())return;const u={name:r.trim(),description:m.trim()||void 0,type:n?"TENANT_GROUP":"ORG_GROUP",...n&&a?{tenantId:a}:{}};try{await v.mutateAsync(u),c(""),d(""),g({}),t()}catch(i){console.error("Failed to create group:",i)}};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:js,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=>{c(p.target.value),f.name&&g(u=>({...u,name:""}))},className:f.name?"border-destructive":"",disabled:v.isPending}),f.name&&e.jsx("p",{className:"text-[12px] text-destructive",children:f.name})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(o.Label,{htmlFor:"group-description",className:js,children:"Description (optional)"}),e.jsx(s.Textarea,{id:"group-description",placeholder:"Describe the purpose of this group…",value:m,onChange:p=>{d(p.target.value),f.description&&g(u=>({...u,description:""}))},className:`text-[13px] ${f.description?"border-destructive":""}`,disabled:v.isPending,rows:3}),f.description?e.jsx("p",{className:"text-[12px] text-destructive",children:f.description}):e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[m.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:()=>{c(""),d(""),g({})},disabled:v.isPending,children:"Clear"}),e.jsx(o.Button,{type:"submit",size:"xs",disabled:v.isPending||!r.trim(),children:v.isPending?e.jsxs(e.Fragment,{children:[e.jsx(o.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Creating…"]}):"Create group"})]})]})}function Pt(t,a=[]){let n=[];function r(m,d){const f=I.createContext(d);f.displayName=m+"Context";const g=n.length;n=[...n,d];const v=x=>{var D;const{scope:p,children:u,...i}=x,y=((D=p==null?void 0:p[t])==null?void 0:D[g])||f,w=I.useMemo(()=>i,Object.values(i));return e.jsx(y.Provider,{value:w,children:u})};v.displayName=m+"Provider";function h(x,p){var y;const u=((y=p==null?void 0:p[t])==null?void 0:y[g])||f,i=I.useContext(u);if(i)return i;if(d!==void 0)return d;throw new Error(`\`${x}\` must be used within \`${m}\``)}return[v,h]}const c=()=>{const m=n.map(d=>I.createContext(d));return function(f){const g=(f==null?void 0:f[t])||m;return I.useMemo(()=>({[`__scope${t}`]:{...f,[t]:g}}),[f,g])}};return c.scopeName=t,[r,Ft(c,...a)]}function Ft(...t){const a=t[0];if(t.length===1)return a;const n=()=>{const r=t.map(c=>({useScope:c(),scopeName:c.scopeName}));return function(m){const d=r.reduce((f,{useScope:g,scopeName:v})=>{const x=g(m)[`__scope${v}`];return{...f,...x}},{});return I.useMemo(()=>({[`__scope${a.scopeName}`]:d}),[d])}};return n.scopeName=a.scopeName,n}var _t=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ge=_t.reduce((t,a)=>{const n=o.createSlot(`Primitive.${a}`),r=I.forwardRef((c,m)=>{const{asChild:d,...f}=c,g=d?n:a;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(g,{...f,ref:m})});return r.displayName=`Primitive.${a}`,{...t,[a]:r}},{});function Ut(){return bt.useSyncExternalStore(Rt,()=>!0,()=>!1)}function Rt(){return()=>{}}var $e="Avatar",[qt]=Pt($e),[Gt,Cs]=qt($e),Ns=I.forwardRef((t,a)=>{const{__scopeAvatar:n,...r}=t,[c,m]=I.useState("idle");return e.jsx(Gt,{scope:n,imageLoadingStatus:c,onImageLoadingStatusChange:m,children:e.jsx(Ge.span,{...r,ref:a})})});Ns.displayName=$e;var Ms="AvatarImage",Is=I.forwardRef((t,a)=>{const{__scopeAvatar:n,src:r,onLoadingStatusChange:c=()=>{},...m}=t,d=Cs(Ms,n),f=$t(r,m),g=o.useCallbackRef(v=>{c(v),d.onImageLoadingStatusChange(v)});return o.useLayoutEffect2(()=>{f!=="idle"&&g(f)},[f,g]),f==="loaded"?e.jsx(Ge.img,{...m,ref:a,src:r}):null});Is.displayName=Ms;var Es="AvatarFallback",Ls=I.forwardRef((t,a)=>{const{__scopeAvatar:n,delayMs:r,...c}=t,m=Cs(Es,n),[d,f]=I.useState(r===void 0);return I.useEffect(()=>{if(r!==void 0){const g=window.setTimeout(()=>f(!0),r);return()=>window.clearTimeout(g)}},[r]),d&&m.imageLoadingStatus!=="loaded"?e.jsx(Ge.span,{...c,ref:a}):null});Ls.displayName=Es;function Ds(t,a){return t?a?(t.src!==a&&(t.src=a),t.complete&&t.naturalWidth>0?"loaded":"loading"):"error":"idle"}function $t(t,{referrerPolicy:a,crossOrigin:n}){const r=Ut(),c=I.useRef(null),m=r?(c.current||(c.current=new window.Image),c.current):null,[d,f]=I.useState(()=>Ds(m,t));return o.useLayoutEffect2(()=>{f(Ds(m,t))},[m,t]),o.useLayoutEffect2(()=>{const g=x=>()=>{f(x)};if(!m)return;const v=g("loaded"),h=g("error");return m.addEventListener("load",v),m.addEventListener("error",h),a&&(m.referrerPolicy=a),typeof n=="string"&&(m.crossOrigin=n),()=>{m.removeEventListener("load",v),m.removeEventListener("error",h)}},[m,n,a]),d}var As=Ns,Os=Is,ks=Ls;const Be=I.forwardRef(({className:t,...a},n)=>e.jsx(As,{ref:n,className:o.cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",t),...a}));Be.displayName=As.displayName;const Bt=I.forwardRef(({className:t,...a},n)=>e.jsx(Os,{ref:n,className:o.cn("aspect-square h-full w-full",t),...a}));Bt.displayName=Os.displayName;const ze=I.forwardRef(({className:t,...a},n)=>e.jsx(ks,{ref:n,className:o.cn("flex h-full w-full items-center justify-center rounded-full bg-muted",t),...a}));ze.displayName=ks.displayName;function zt({open:t,onOpenChange:a,group:n,onUpdate:r}){const[c,m]=b.useState("members"),[d,f]=b.useState(""),[g,v]=b.useState([]),[h,x]=b.useState([]),{data:p,isLoading:u,refetch:i}=s.useGroupMembers(n.id),y=n.type==="TENANT_GROUP"?"tenant":"organization",{users:w,isLoading:D}=s.useUnifiedUsers({type:y,tenantId:n.tenantId||void 0,active:!0,limit:100}),C=Ot(),N=kt(),E=(p==null?void 0:p.members)||[],M=b.useMemo(()=>new Set(E.map(S=>S.userId)),[E]),P=b.useMemo(()=>w.filter(S=>!M.has(S.id)),[w,M]),_=b.useMemo(()=>{if(!d)return P;const S=d.toLowerCase();return P.filter(L=>{var F,q;return((F=L.name)==null?void 0:F.toLowerCase().includes(S))||((q=L.email)==null?void 0:q.toLowerCase().includes(S))})},[P,d]),j=b.useMemo(()=>{if(!d)return E;const S=d.toLowerCase();return E.filter(L=>{var F,q,te,K;return((q=(F=L.user)==null?void 0:F.name)==null?void 0:q.toLowerCase().includes(S))||((K=(te=L.user)==null?void 0:te.email)==null?void 0:K.toLowerCase().includes(S))})},[E,d]),R=async()=>{if(g.length!==0)try{await C.mutateAsync({groupId:n.id,data:{userIds:g,userType:y==="tenant"?"tenant":"org"}}),v([]),m("members"),i(),r==null||r()}catch(S){console.error("Failed to add members:",S)}},B=async()=>{if(h.length!==0)try{await N.mutateAsync({groupId:n.id,data:{userIds:h}}),x([]),i(),r==null||r()}catch(S){console.error("Failed to remove members:",S)}},V=S=>{v(L=>L.includes(S)?L.filter(F=>F!==S):[...L,S])},H=S=>{x(L=>L.includes(S)?L.filter(F=>F!==S):[...L,S])};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:[E.length," ",E.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:c,onValueChange:S=>{m(S),f(""),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:d,onChange:S=>f(S.target.value),className:"pl-10"})]}),e.jsx(o.ScrollArea,{className:h.length>0?"h-[300px]":"h-[350px]",children:u?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(S=>e.jsx(s.Skeleton,{className:"h-16 w-full"},S))}):j.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:d?"No members found":"No members yet"}),e.jsx("p",{className:"text-xs mt-1",children:d?"Try a different search":'Switch to the "Add Members" tab to add people to this group'})]}):e.jsx("div",{className:"space-y-2",children:j.map(S=>e.jsx(Vt,{member:S,selected:h.includes(S.userId),onToggle:()=>H(S.userId)},S.id))})}),h.length>0&&e.jsxs("div",{className:"flex items-center justify-between pt-4 border-t",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[h.length," member",h.length!==1?"s":""," selected"]}),e.jsx(o.Button,{variant:"destructive",size:"sm",onClick:B,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:d,onChange:S=>f(S.target.value),className:"pl-10"})]}),e.jsx(o.ScrollArea,{className:"h-[300px]",children:D?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(S=>e.jsx(s.Skeleton,{className:"h-16 w-full"},S))}):_.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(s.UserPlus,{className:"h-12 w-12 mb-3 opacity-50"}),e.jsx("p",{className:"text-sm font-medium",children:"No available users"}),e.jsx("p",{className:"text-xs mt-1",children:d?"Try a different search":"All eligible users are already members"})]}):e.jsx("div",{className:"space-y-2",children:_.map(S=>e.jsx(Ht,{user:S,selected:g.includes(S.id),onToggle:()=>V(S.id)},S.id))})}),g.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:[g.length," user",g.length!==1?"s":""," selected"]}),e.jsx(o.Button,{onClick:R,disabled:C.isPending,children:C.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(s.UserPlus,{className:"mr-2 h-4 w-4"}),"Add Members"]})})]})]})]})]})})})}function Vt({member:t,selected:a,onToggle:n}){var c,m,d,f;const r=((m=(c=t.user)==null?void 0:c.name)==null?void 0:m.split(" ").map(g=>g[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(Be,{className:"h-8 w-8",children:e.jsx(ze,{className:"text-xs",children:r})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:((d=t.user)==null?void 0:d.name)||"Unknown User"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(f=t.user)==null?void 0:f.email})]})]})}function Ht({user:t,selected:a,onToggle:n}){var c;const r=((c=t.name)==null?void 0:c.split(" ").map(m=>m[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(Be,{className:"h-8 w-8",children:e.jsx(ze,{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 Kt({open:t,onOpenChange:a}){const[n,r]=b.useState("groups"),[c,m]=b.useState(""),[d,f]=b.useState(null),[g,v]=b.useState(!1),[h,x]=b.useState(null),{tokenProps:p}=s.useSemaphorContext(),{currentUser:u}=s.useCurrentUserInfo(),i=At(),y=(u==null?void 0:u.type)==="tenant",w=p==null?void 0:p.tenantId,{groups:D,isLoading:C,refetch:N}=s.useGroups({type:y?"TENANT_GROUP":"all",tenantId:y?w:void 0,includeMembers:!1}),E=D.filter(j=>{var R;return j.name.toLowerCase().includes(c.toLowerCase())||((R=j.description)==null?void 0:R.toLowerCase().includes(c.toLowerCase()))}),M=async()=>{if(h)try{await i.mutateAsync(h.id),x(null),N()}catch(j){console.error("Failed to delete group:",j)}},P=j=>{f(j),v(!0)},_=()=>{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:c,onChange:j=>m(j.target.value),className:"pl-7"})]}),e.jsx(o.ScrollArea,{className:"h-[400px]",children:C?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(j=>e.jsx(s.Skeleton,{className:"h-16 w-full rounded-[6px]"},j))}):E.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx("p",{className:"text-[13px]",children:"No groups found."}),e.jsx("p",{className:"mt-1 text-[12px]",children:c?"Try a different search.":"Create your first group to get started."})]}):e.jsx("div",{className:"space-y-2 pr-2",children:E.map(j=>e.jsx(Qt,{group:j,onManageMembers:()=>P(j),onDelete:()=>x(j),currentUserId:u==null?void 0:u.id},j.id))})})]})}),e.jsx(o.TabsContent,{value:"create",className:"mt-4",children:e.jsx(Tt,{onSuccess:_,tenantId:w,isTenantUser:y})})]})]})}),d&&e.jsx(zt,{open:g,onOpenChange:v,group:d,onUpdate:()=>N()}),e.jsx(s.AlertDialog,{open:!!h,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 "',h==null?void 0:h.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:M,disabled:i.isPending,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:i.isPending?e.jsxs(e.Fragment,{children:[e.jsx(o.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Deleting…"]}):"Delete group"})]})]})})]})}function Qt({group:t,onManageMembers:a,onDelete:n,currentUserId:r}){const c=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 ",it.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(s.UserPlus,{className:"h-3.5 w-3.5"})}),c&&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 ee(t,a,n){var m,d;const r=(t.controls||[]).find(f=>f.id===n);if(r)return r.label;const c=(d=(m=o.findCardById(t,a))==null?void 0:m.controls)==null?void 0:d.find(f=>f.id===n);return(c==null?void 0:c.label)||n}function se(t,a){var n;return((n=o.findCardById(t,a))==null?void 0:n.title)||a}function Wt(t){const{errors:a,dashboard:n}=t;if(!n)return a;const r=new Map;for(const c of a){const m=c.match(/^Card '(.+)' binding for control '(.+)' maps to missing metric '(.+)'\.$/);if(m){const[,h,x]=m,p=`${h}:${x}:missing-metric`;r.has(p)||r.set(p,`"${se(n,h)}" has an outdated "${ee(n,h,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 d=c.match(/^Card '(.+)' binding for control '(.+)' maps to missing group-by field '(.+)'\.$/);if(d){const[,h,x]=d,p=`${h}:${x}:missing-group-by`;r.has(p)||r.set(p,`"${se(n,h)}" has an outdated "${ee(n,h,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 f=c.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid metric target\.$/);if(f){const[,h,x]=f,p=`${h}:${x}:invalid-metric`;r.has(p)||r.set(p,`"${se(n,h)}" has an invalid "${ee(n,h,x)}" metric mapping. Open the card controls and choose a valid metric for each option.`);continue}const g=c.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid group-by target\.$/);if(g){const[,h,x]=g,p=`${h}:${x}:invalid-group-by`;r.has(p)||r.set(p,`"${se(n,h)}" has an invalid "${ee(n,h,x)}" field mapping. Open the card controls and choose a valid field for each option.`);continue}const v=c.match(/^Card '(.+)' binding for control '(.+)' requires at least one temporal group-by field\.$/);if(v){const[,h,x]=v,p=`${h}:${x}:missing-temporal-group-by`;r.has(p)||r.set(p,`"${se(n,h)}" can no longer use "${ee(n,h,x)}" for time grain because the card does not currently group by a date field.`);continue}r.set(c,c)}return Array.from(r.values())}const Jt=["enum","multi_enum","text","number","boolean","date"];function Yt({open:t,onOpenChange:a,initialMode:n="manage"}){var _;const r=n==="create",{forceClose:c,handleOpenChange:m,isCreateFlowActive:d,preventPassiveDismissDuringCreate:f,resolvedOpen:g,setIsCreateFlowActive:v}=gs.useCreateFlowOverlayState({open:t,onOpenChange:a,initialCreateFlowActive:n==="create",dismissMode:"explicit-only"}),h=o.useDashboardStore(j=>j.dashboard),x=o.useDashboardStore(j=>j.selectedSheetId),{setDashboardInputs:p}=o.useDashboardActions(),u=(_=h.sheets)==null?void 0:_.find(j=>j.id===x),i=(u==null?void 0:u.kind)==="document"&&!!u.document,y=b.useMemo(()=>i&&(u!=null&&u.document)?s.getDocumentSheetDashboardInputs(h,u.id):[],[h,i,u==null?void 0:u.document,u==null?void 0:u.id]),w=b.useMemo(()=>y.filter(j=>j.kind==="control"),[y]),D=b.useMemo(()=>w.map(j=>j.control),[w]),C=b.useMemo(()=>Zt(D),[D]),N=b.useMemo(()=>Xt(h),[h]),E=b.useCallback(()=>{if(r){c();return}v(!1)},[r,c,v]),M=b.useCallback((j,R,B)=>{!i||!(u!=null&&u.document)||p(sa({allInputs:h.inputs||[],documentSheetId:u.id,currentDocumentInputs:y,nextControls:j,nextDefaultValues:R,change:B}))},[h.inputs,y,i,u,p]);if(!i||!(u!=null&&u.document))return null;const P=d?"Add document control":"Document Controls";return e.jsx(s.Dialog,{open:g,onOpenChange:m,children:e.jsxs(s.DialogContent,{className:"flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",onEscapeKeyDown:f,onPointerDownOutside:f,children:[e.jsxs(s.DialogHeader,{className:d?"space-y-0":void 0,children:[e.jsx(s.DialogTitle,{className:"text-[15px]",children:P}),e.jsx(s.DialogDescription,{className:d?"sr-only":"text-[13px]",children:d?"Configure and add a document-local control input.":"Add document-local control inputs. They are stored on this document sheet and are not dashboard controls."})]}),e.jsx("div",{className:"min-h-0 overflow-y-auto pr-1",children:e.jsx(gs.ControlDefinitionListEditor,{scope:"dashboard",controls:D,reservedControlIds:N,defaultValues:C,usageByControlId:{},availableFieldChoices:[],availableMetricChoices:[],structuralParticipants:[],structuralParticipantIdsByControlId:{},allowedControlTypes:Jt,initialCreateFlow:n==="create",onCreateFlowActiveChange:v,onCreateFlowComplete:E,onChange:M,emptyMessage:"No document controls yet."})})]})})}function Xt(t){return(t.controls||[]).map(a=>a.id)}function Zt(t){const a={};for(const n of t)n.defaultValue!==void 0&&(a[n.id]=n.defaultValue);return a}function ea(t,a){return a?Object.prototype.hasOwnProperty.call(a,t.id)?{...t,defaultValue:a[t.id]}:t.defaultValue===void 0?t:{...t,defaultValue:void 0}:t.defaultValue===void 0?t:{...t,defaultValue:void 0}}function sa({allInputs:t,documentSheetId:a,currentDocumentInputs:n,nextControls:r,nextDefaultValues:c,change:m}){const d=new Map(r.map(p=>[p.id,ea(p,c)])),f=(m==null?void 0:m.type)==="rename"?{oldId:m.oldId,newId:m.newId}:null,g=new Set,v=[];for(const p of n){if(p.kind!=="control"){v.push(p);continue}const u=d.get(p.control.id)||((f==null?void 0:f.oldId)===p.control.id?d.get(f.newId):void 0);if(!u)continue;g.add(u.id);const i=s.createUniqueDashboardInputVariableNameFromName(u.id,[...t,...v].filter(w=>w.id!==p.id)),y=u.id===i?u:{...u,id:i};v.push({...p,label:y.label,variableName:i,requiredAtExecution:y.requiredAtExecution,control:y})}for(const p of d.values())g.has(p.id)||v.push(s.createDashboardControlInputFromControl({control:p,existingInputs:[...t,...v],sheetId:a}));const h=new Set(n.map(p=>p.id));return[...t.filter(p=>!h.has(p.id)),...v]}function ws(t,a){return{dashboard:s.cloneDeep(t),semanticExecutionPayload:s.cloneDeep(a)}}function ta(){var cs,ds,us,ms,hs,ps;G.useExportRecovery(),G.useExportPolling();const{authToken:t,tokenProps:a,id:n}=s.useSemaphorContext(),{isLocalDev:r}=s.useDashboardPreferences(),{openBrandStudioPreview:c}=s.useBrandStudioPreview(),{permissions:m}=Ct(),d=s.useHasDashboardId(),{isLoading:f}=s.useDashboardQuery(),g=o.useDashboardStore(l=>l.theme),v=o.useDashboardStore(l=>l.isDownloadingPdf),h=o.useDashboardStore(l=>l.dashboardAssistantDraftScopeKey),x=o.useDashboardStore(l=>l.lenses),p=o.useDashboardStore(l=>l.selectedLensId),u=x==null?void 0:x.find(l=>l.id===p),i=o.useDashboardStore(l=>l.dashboard),y=o.useDashboardStore(l=>l.selectedSheetId),w=(cs=i==null?void 0:i.sheets)==null?void 0:cs.find(l=>l.id===y),D=o.isDocumentSheet(w),C=D?(ds=w==null?void 0:w.document)==null?void 0:ds.page:void 0,N=o.useDashboardStore(l=>l.isDashboardEditing),{setDashboardTitle:E}=o.useDashboardStore(l=>l.actions),[M,P]=b.useState(!1),[_,j]=b.useState(!1),[R,B]=b.useState(!1),[V,H]=b.useState(!1),[S,L]=b.useState(!1),[F,q]=b.useState(!1),[te,K]=b.useState(!1),[Ts,Ve]=b.useState(!1),[De,ae]=b.useState(null),[Ps,ne]=b.useState(!1),[re,oe]=b.useState(null),[He,ie]=b.useState([]),[Ke,le]=b.useState(!1),Fs=o.useDashboardStore(l=>l.isDashboardPanelOpen),_s=o.useDashboardStore(l=>l.actions.setIsDashboardPanelOpen),Us=o.useDashboardStore(l=>l.filterValues),O=o.useDashboardStore(l=>l.isVisualEditing);o.useEditorStore(l=>l.card);const Q=s.useManagementStore(l=>l.selectedDashboard),ce=s.useManagementStore(l=>l.initialDashboard);s.useManagementStore(l=>l.selectedVisual),o.useDashboardStore(l=>l.selectedFrameId),o.useEditorStore(l=>l.frame);const de=Q?(ms=Q==null?void 0:Q.permissions)==null?void 0:ms.canEdit:(us=ce==null?void 0:ce.permissions)==null?void 0:us.canEdit,ue=o.useDashboardStore(l=>l.showFilters),Qe=s.useAssistantLayoutStore(l=>l.setPanelOpen),We=o.useDashboardStore(l=>l.showDashboardJSON),we=o.useDashboardStore(l=>l.onSaveFunction),Je=o.useDashboardStore(l=>l.actions.setShowFilters),{setDocumentInspectorTab:Ye,setIsDashboardEditing:Xe,setShowDashboardJSON:Ze}=o.useDashboardStore(l=>l.actions),{setInitialDashboard:es,clearSelectedDashboard:Ce}=s.useManagementStore(l=>l.actions),{resources:me}=s.useResourceManagement(s.ResourceType.DASHBOARD),{data:Ne}=s.useUserPreferences(),Rs=((hs=Ne==null?void 0:Ne.preference)==null?void 0:hs.defaultDashboardId)||null,{mutate:qs,isPending:Gs}=s.useDefaultDashboardMutation(),{currentUser:$s}=s.useCurrentUserInfo(),Bs=s.canUserManageGroups($s),z=Q||ce,ss=z?{id:z.id,title:(i==null?void 0:i.title)||z.title||"Dashboard"}:null,{handleAddNewFrame:zs}=s.useAddNewFrame(),[Me,Ie]=b.useState(!1),[Vs,W]=b.useState(!1),[Ee,he]=b.useState("close"),J=s.useUpdateResource(s.ResourceType.DASHBOARD),[T,pe]=b.useState(null),ts=b.useCallback(l=>{window.setTimeout(()=>{ae(l)},0)},[]),Hs=async(l,A)=>{if(!(i!=null&&i.id)){console.log("No dashboard ID found");return}console.log("Updating dashboard title:",{dashboardId:i.id,newTitle:l,previousTitle:A}),J.mutate({resourceId:i.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"),E(A)}})};b.useEffect(()=>{if(me&&me.length>0){const l=i==null?void 0:i.id;if(l){const A=me.find(U=>U.id===l);A&&es(A)}}},[me,i==null?void 0:i.id,es]);const Y=a.orgUserId||a.tenantId,Le=b.useMemo(()=>aa({accessToken:t==null?void 0:t.accessToken,dashboardId:(i==null?void 0:i.id)||n||a.dashboard_id,selectedSheetId:D?y:void 0,pageSize:C==null?void 0:C.size,orientation:C==null?void 0:C.orientation,theme:g}),[t==null?void 0:t.accessToken,n,i==null?void 0:i.id,D,C==null?void 0:C.orientation,C==null?void 0:C.size,y,g,a.dashboard_id]),as=N&&!O&&Y&&de,{setDashboard:Ae}=o.useDashboardStore(l=>l.actions),Oe=o.useDashboardStore(l=>l.semanticExecutionPayload),Ks=()=>{Xe(!0)},ke=()=>{Xe(!1),Ze(!1),pe(null),ae(null)};b.useEffect(()=>{if(!N){T&&pe(null);return}T||!i||f||pe(ws(i,Oe))},[i,T,N,f,Oe]);const fe=(T==null?void 0:T.dashboard)??null,{isDirty:ns,isDirtyPending:Qs,resetDirty:xe}=lt.useDebouncedDirtyCheck(i,fe,300,1e3,Fe.serializeDashboardForDirtyCheck),rs=b.useCallback(()=>fe?Fe.serializeDashboardForDirtyCheck(i)!==Fe.serializeDashboardForDirtyCheck(fe):!1,[i,fe]),os=ns||Qs,ge=Me||J.isPending,Ws=()=>{rs()?(he("close"),W(!0)):(ke(),xe())},Js=async()=>{await Te({closeAfterSave:!0,navigateHomeAfterSave:Ee==="home"})},Ys=()=>{T&&Ae(T.dashboard,{semanticExecutionPayload:T.semanticExecutionPayload}),ke(),Ee==="home"&&Ce(),he("close"),W(!1),xe()},Xs=()=>{T&&(Ae(T.dashboard,{semanticExecutionPayload:T.semanticExecutionPayload}),xe())},Zs=()=>{if(N&&rs()){he("home"),W(!0);return}Ce()};async function Te(l){const A=o.useDashboardStore.getState().dashboard;if(!A)return;const U=(l==null?void 0:l.closeAfterSave)??Ke,nt=(l==null?void 0:l.navigateHomeAfterSave)??!1;le(U),U&&W(!1);const rt=s.cloneDeep(A);ne(!0),oe(null),ie([]),Ie(!0);const ot={template:A};J.mutate({resourceId:A.id,data:ot},{onSuccess:k=>{var ve,ye,fs;const $=(k==null?void 0:k.id)||((ve=k==null?void 0:k.dashboard)==null?void 0:ve.id)||((ye=k==null?void 0:k.resource)==null?void 0:ye.id)||((fs=k==null?void 0:k.template)==null?void 0:fs.id)||null;if(!A.id&&$){const Pe=o.useAIInteractionStore.getState(),Se=Pe.pendingDashboardDraftMigration;(Se==null?void 0:Se.scopeKey)===h?Pe.actions.setPendingDashboardDraftMigrationExpectedDashboardId($):Se&&Pe.actions.clearPendingDashboardDraftMigration()}Ie(!1),s.ue.success("Dashboard saved!"),pe(ws(rt,o.useDashboardStore.getState().semanticExecutionPayload)),ne(!1),le(!1),U&&(ke(),xe(),nt&&Ce()),he("close")},onError:k=>{Ie(!1),oe("Failed to save dashboard. Please try again.");const $=k.details,ve=Array.isArray($==null?void 0:$.errors)?($.errors||[]).filter(ye=>typeof ye=="string"):[];ie(Wt({errors:ve,dashboard:A||void 0})),s.ue.error("Failed to save dashboard")}})}async function et(){if(P(!0),!p||!u)return;const l=o.useDashboardStore.getState().dashboard;if(!l){P(!1);return}const A=JSON.stringify(l),U={...u,template:A,filterValues:Us};await qe(a.apiServiceUrl,U,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),we==null||we(l),P(!1)}const is=(u==null?void 0:u.name)||i.title,X=!!(i!=null&&i.id);J.isPending&&console.log("Title during update:",{title:is,dashboardStateTitle:i.title,dashboardId:i==null?void 0:i.id,currentLensName:u==null?void 0:u.name});const ls=a.orgUserId||a.tenantId&&a.endUserId&&a.endUserEmail,st=!!ls&&!!(t!=null&&t.accessToken)&&!!(a!=null&&a.apiServiceUrl);b.useEffect(()=>{!X&&V&&H(!1)},[X,V]);const tt=d,Z=(i==null?void 0:i.id)||null,be=!!Z&&Rs===Z,at=()=>{Z&&qs({dashboardId:be?null:Z})};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:[ls&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{"aria-label":"Manage Dashboards",tooltip:"Manage Dashboards",onClick:()=>{_s(!Fs)},className:"h-7 w-7 px-0",buttonProps:{size:"xs"},children:e.jsx(ut,{className:"h-3.5 w-3.5"})}),tt&&!O&&e.jsx(s.IconButton,{"aria-label":"Dashboard Hub",tooltip:"Dashboard Hub",onClick:Zs,className:"h-7 w-7 px-0",buttonProps:{size:"xs"},children:e.jsx(s.House,{className:"h-3.5 w-3.5"})})]}),!O&&d&&(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:is||"Untitled Dashboard",onSave:l=>{console.log("EditableText onSave called:",{newTitle:l,canEditDashboard:de,dashboardId:i==null?void 0:i.id});const A=(i==null?void 0:i.title)||"";E(l),Hs(l,A)},isEditable:de&&!u,displayClassName:"text-[13px] font-medium",inputClassName:"text-[13px] font-medium",placeholder:"Dashboard Title",isPending:J.isPending}),st&&Z&&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:at,disabled:Gs||!(t!=null&&t.accessToken)||!(a!=null&&a.apiServiceUrl),className:"w-7 px-0","aria-label":be?"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",be?"fill-foreground text-foreground":"text-muted-foreground hover:text-foreground")})})}),e.jsx(o.TooltipContent,{children:e.jsx("p",{children:be?"Remove as default dashboard":"Make this a default dashboard"})})]})})]}))]}),e.jsxs("div",{className:"flex items-center gap-2",children:[O&&e.jsxs(e.Fragment,{children:[e.jsx(G.AdvancedModeToggle,{}),e.jsx(G.VisualEditingControls,{})]}),!O&&d&&((ps=z==null?void 0:z.permissions)==null?void 0:ps.canShare)&&e.jsxs(o.Button,{variant:"outline",size:"xs",onClick:()=>j(!0),children:[e.jsx(s.Share2,{className:"h-3.5 w-3.5"}),"Share"]}),!O&&N&&m.canUseFilters&&d&&e.jsx(G.DashboardFilterControlsButton,{showFilters:D?!1:ue,onToggleFilters:()=>{if(D&&y){Ye(y,"inputs");return}ue||Qe("dashboard",!1),Je(!ue)},onAddFilter:()=>{if(D&&y){Ye(y,"inputs");return}ue||(Qe("dashboard",!1),Je(!0))},onAddControl:()=>{ts("create")},onManageControls:()=>ts("manage")}),N&&!O&&d&&De?D?e.jsx(Yt,{open:!0,onOpenChange:l=>{l||ae(null)},initialMode:De}):e.jsx(G.DashboardControlsSettings,{open:!0,onOpenChange:l=>{l||ae(null)},showTrigger:!1,initialMode:De}):null,N&&!O&&Y&&u&&r&&d&&e.jsxs(o.Button,{variant:"secondary",size:"xs",disabled:M,onClick:et,children:[e.jsx(bs.Save,{className:"h-3.5 w-3.5"}),"Save Lens"]}),N&&!O&&d&&!D&&e.jsxs(o.Button,{variant:"outline",size:"xs",disabled:!N,onClick:()=>zs(),children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Visual"]}),!O&&!N&&de&&d&&e.jsxs(o.Button,{size:"xs",onClick:Ks,children:[e.jsx(s.Pencil,{className:"h-3.5 w-3.5"}),"Edit"]}),as&&d&&ns&&e.jsxs(o.Button,{variant:"outline",size:"xs",onClick:Xs,disabled:ge,children:[e.jsx(s.Undo2,{className:"h-3.5 w-3.5"}),"Undo"]}),as&&d&&e.jsxs(o.Button,{size:"xs",className:o.cn(!os&&"opacity-60"),disabled:ge||!os,onClick:()=>Te(),children:[ge?e.jsx(o.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(bs.Save,{className:"h-3.5 w-3.5"}),ge?"Saving...":"Save"]}),N&&!O&&d&&e.jsxs(o.Button,{variant:"outline",size:"xs",onClick:Ws,children:[e.jsx(s.Cross2Icon,{className:"h-3.5 w-3.5"}),"Close"]}),!O&&d&&e.jsx("div",{className:"ml-2",children:e.jsx(G.NotificationBell,{})}),!O&&r&&e.jsx(vt,{}),!O&&d&&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:v,onSelect:()=>Ve(!0),children:[e.jsx(s.Download,{className:"h-3.5 w-3.5"}),"Export"]}),e.jsxs(s.DropdownMenuItem,{disabled:!X,onSelect:()=>{X&&H(!0)},children:[e.jsx(s.Clock,{className:"h-3.5 w-3.5"}),"Schedule"]}),e.jsx(s.DropdownMenuSeparator,{}),Bs&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuLabel,{children:"Access"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>B(!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:()=>L(!0),children:[e.jsx(s.Calendar,{className:"h-3.5 w-3.5"}),"Calendar Preferences"]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>q(!0),children:[e.jsx(s.FileText,{className:"h-3.5 w-3.5"}),"Summary Settings"]}),r&&d&&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"]}),D&&e.jsxs(s.DropdownMenuItem,{disabled:!Le,onSelect:()=>{var l;if(!Le){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(Le).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(pt,{className:"h-3.5 w-3.5"}),"Invalidate token"]}),e.jsxs(s.DropdownMenuItem,{onSelect:c,children:[e.jsx(vs.Palette,{className:"h-3.5 w-3.5"}),"Brand Studio"]}),N&&e.jsxs(s.DropdownMenuItem,{onSelect:()=>Ze(!We),children:[e.jsx(vs.Braces,{className:"h-3.5 w-3.5"}),We?"Hide dashboard JSON":"Show dashboard JSON"]}),Y&&N&&e.jsxs(s.DropdownMenuItem,{onSelect:()=>K(!0),children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Add lens"]}),Y&&e.jsxs(s.DropdownMenuSub,{children:[e.jsxs(s.DropdownMenuSubTrigger,{children:[e.jsx(dt,{className:"h-3.5 w-3.5"}),"Lenses"]}),e.jsx(s.DropdownMenuSubContent,{className:"w-60",children:e.jsx(wt,{})})]})]})]})]}),_&&ss&&e.jsx(s.ShareDialog,{resource:ss,resourceType:s.ResourceType.DASHBOARD,onClose:()=>j(!1)}),e.jsx(Kt,{open:R,onOpenChange:B}),X&&(i==null?void 0:i.id)&&e.jsx(s.EmailScheduleDialog,{open:V,onOpenChange:H,dashboardId:i.id,dashboardName:i==null?void 0:i.title}),e.jsx(xs.CalendarPreferencesDialog,{open:S,onOpenChange:L}),e.jsx(xs.DashboardSummarySettingsDialog,{open:F,onOpenChange:q,dashboard:i,disabled:!N,onApply:l=>Ae({...i,summary:l},{semanticExecutionPayload:Oe})}),r&&Y&&d&&e.jsx(Dt,{open:te,onOpenChange:K}),d&&e.jsx(s.DownloadPdf,{open:Ts,onOpenChange:Ve}),e.jsx(s.AlertDialog,{open:Ps,onOpenChange:l=>{!l&&Me&&!re||(ne(l),l||(oe(null),ie([]),le(!1)))},children:e.jsxs(s.AlertDialogContent,{className:"max-w-sm",children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:re?"Save failed":"Saving dashboard"}),e.jsx(s.AlertDialogDescription,{className:"pt-2",children:re?"We could not save the dashboard. Please try again.":"Please wait while we save your changes."}),He.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:He.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:re?e.jsxs(e.Fragment,{children:[e.jsx(s.AlertDialogCancel,{onClick:()=>{ne(!1),oe(null),ie([]),le(!1)},className:"m-0",children:"Close"}),e.jsx(s.AlertDialogAction,{onClick:()=>Te({closeAfterSave:Ke,navigateHomeAfterSave:Ee==="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(G.UnsavedChangesAlert,{open:Vs,onOpenChange:l=>{W(l)},onSave:Js,onDiscard:Ys,isSaving:Me,saveLabel:"Save",discardLabel:"Discard"})]})]})}function aa({accessToken:t,dashboardId:a,selectedSheetId:n,pageSize:r,orientation:c,theme:m}){if(!t||!n)return null;const d=new URL("http://localhost:5173/print-document");d.searchParams.set("token",t),a&&d.searchParams.set("dashboardId",a),d.searchParams.set("selectedSheetId",n),m&&d.searchParams.set("theme",m);const f=new URL("http://127.0.0.1:3002/");return f.searchParams.set("pdfMode","document"),f.searchParams.set("pageSize",r||"letter"),f.searchParams.set("orientation",c||"portrait"),f.searchParams.set("url",d.toString()),f.toString()}exports.default=ta;