react-semaphor 0.1.295 → 0.1.296
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{braces-BdoTYzuj.js → braces-BNXseceK.js} +1 -1
- package/dist/chunks/{braces-DWldEFn5.js → braces-DVrX_3Q_.js} +1 -1
- package/dist/chunks/dashboard-controls-CKKZcVA5.js +2219 -0
- package/dist/chunks/dashboard-controls-DS2xJxHU.js +47 -0
- package/dist/chunks/dashboard-filter-controls-button-nqfmscB7.js +11 -0
- package/dist/chunks/{dashboard-filter-controls-button-XwenlcXw.js → dashboard-filter-controls-button-xPaIlNHP.js} +501 -495
- package/dist/chunks/{dashboard-json-CU55qPXj.js → dashboard-json-cuj9vYY9.js} +1 -1
- package/dist/chunks/{dashboard-json-V6m6lJ_c.js → dashboard-json-ovQyHWw6.js} +1 -1
- package/dist/chunks/{dashboard-summary-settings-dialog-DRLPzp1P.js → dashboard-summary-settings-dialog-BUg3Qyhh.js} +1 -1
- package/dist/chunks/{dashboard-summary-settings-dialog-0CIiWsKc.js → dashboard-summary-settings-dialog-DF076HeJ.js} +1 -1
- package/dist/chunks/{edit-dashboard-visual-8ha6EM_g.js → edit-dashboard-visual-32TAM00c.js} +5331 -5303
- package/dist/chunks/edit-dashboard-visual-BtiMcO-L.js +183 -0
- package/dist/chunks/{index-14M0TnH6.js → index-BDeJH9hO.js} +103265 -88338
- package/dist/chunks/index-Dbrs96G8.js +1533 -0
- package/dist/chunks/{resource-management-panel-CcDAn86l.js → resource-management-panel-2qcXsKwg.js} +2 -2
- package/dist/chunks/{resource-management-panel-BL5-5ouC.js → resource-management-panel-C4qoxy_g.js} +31 -30
- package/dist/chunks/use-create-flow-overlay-state-BMD3YRzU.js +21 -0
- package/dist/chunks/{use-create-flow-overlay-state-D3PxfjYv.js → use-create-flow-overlay-state-CHeppRNE.js} +572 -568
- package/dist/chunks/{use-visual-utils-CdIOq4nt.js → use-visual-utils-BIHLaVwh.js} +70 -68
- package/dist/chunks/use-visual-utils-dOYWf6nM.js +1 -0
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +113 -112
- package/dist/style.css +1 -1
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +2 -2
- package/dist/types/dashboard.d.ts +235 -1
- package/dist/types/main.d.ts +288 -1
- package/dist/types/shared.d.ts +204 -1
- package/dist/types/surfboard.d.ts +235 -1
- package/dist/types/types.d.ts +235 -1
- package/package.json +7 -1
- package/dist/chunks/dashboard-controls-B3lrnI_r.js +0 -47
- package/dist/chunks/dashboard-controls-D7U6E1sB.js +0 -2014
- package/dist/chunks/dashboard-filter-controls-button-D0AsV28-.js +0 -11
- package/dist/chunks/edit-dashboard-visual-sSLAkmgf.js +0 -183
- package/dist/chunks/index-Ze8VskG1.js +0 -1435
- package/dist/chunks/use-create-flow-overlay-state-BbQVNDCj.js +0 -21
- package/dist/chunks/use-visual-utils-kh8p2QFm.js +0 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),e=require("./index-Dbrs96G8.js"),g=require("react");require("react-dom");const G=require("./dashboard-filter-controls-button-nqfmscB7.js"),at=require("./date-formatter-CqXdM6JO.js"),xs=require("./dashboard-summary-settings-dialog-BUg3Qyhh.js"),nt=require("./use-debounced-dirty-check-XHSwAefL.js"),Fe=require("./normalize-dashboard-for-dirty-check-BXRUMVb2.js"),Se=require("./use-create-flow-overlay-state-BMD3YRzU.js"),rt=require("./braces-DVrX_3Q_.js");function ot(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const a=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(n,r,a.get?a:{enumerable:!0,get:()=>t[r]})}}return n.default=t,Object.freeze(n)}const N=ot(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 it=e.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 lt=e.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 ct=e.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 dt=e.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 ut=e.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 mt=e.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 gs;function ht(){if(gs)return _e;gs=1;var t=g;function n(f,h){return f===h&&(f!==0||1/f===1/h)||f!==f&&h!==h}var r=typeof Object.is=="function"?Object.is:n,a=t.useState,i=t.useEffect,c=t.useLayoutEffect,u=t.useDebugValue;function d(f,h){var o=h(),x=a({inst:{value:o,getSnapshot:h}}),y=x[0].inst,j=x[1];return c(function(){y.value=o,y.getSnapshot=h,p(y)&&j({inst:y})},[f,o,h]),i(function(){return p(y)&&j({inst:y}),f(function(){p(y)&&j({inst:y})})},[f]),u(o),o}function p(f){var h=f.getSnapshot;f=f.value;try{var o=h();return!r(f,o)}catch{return!0}}function b(f,h){return h()}var m=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?b:d;return _e.useSyncExternalStore=t.useSyncExternalStore!==void 0?t.useSyncExternalStore:m,_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 bs;function pt(){return bs||(bs=1,process.env.NODE_ENV!=="production"&&function(){function t(o,x){return o===x&&(o!==0||1/o===1/x)||o!==o&&x!==x}function n(o,x){m||i.startTransition===void 0||(m=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var y=x();if(!f){var j=x();c(y,j)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),f=!0)}j=u({inst:{value:y,getSnapshot:x}});var S=j[0].inst,C=j[1];return p(function(){S.value=y,S.getSnapshot=x,r(S)&&C({inst:S})},[o,y,x]),d(function(){return r(S)&&C({inst:S}),o(function(){r(S)&&C({inst:S})})},[o]),b(y),y}function r(o){var x=o.getSnapshot;o=o.value;try{var y=x();return!c(o,y)}catch{return!0}}function a(o,x){return x()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var i=g,c=typeof Object.is=="function"?Object.is:t,u=i.useState,d=i.useEffect,p=i.useLayoutEffect,b=i.useDebugValue,m=!1,f=!1,h=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?a:n;Ue.useSyncExternalStore=i.useSyncExternalStore!==void 0?i.useSyncExternalStore:h,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=ht():Re.exports=pt();var ft=Re.exports;const ye=["light","dark","system"];function xt(){const{theme:t,setTheme:n}=e.useTheme(),r=e.useDashboardStore(u=>u.actions.setDashboardTheme);function a(){const u=ye.includes(t)?t:"system",d=ye[(ye.indexOf(u)+1)%ye.length];n(d),r(d)}const i=t==="light"?mt:t==="dark"?dt:ct,c=t==="light"?"Theme: light (click for dark)":t==="dark"?"Theme: dark (click for system)":"Theme: system (click for light)";return s.jsx(e.Button,{type:"button",variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:a,"aria-label":c,title:c,children:s.jsx(i,{className:"h-3.5 w-3.5",strokeWidth:1.5})})}async function gt(t,n,r,a,i){if(!i)return null;const c=JSON.stringify(r),u=`${t}/v1/lens`;return await e.postRequest(u,i,{name:n,template:c,filterValues:a,operation:"create"})}async function Ge(t,n,r){if(!r)return null;const{id:a,template:i,filterValues:c,isDefault:u,shared:d}=n,p=`${t}/v1/lens`;return await e.postRequest(p,r,{lensId:a,template:i,filterValues:c,isDefault:u,shared:d,operation:"update"})}async function bt(t,n,r){if(!r)return null;const a=`${t}/v1/lens`;return await e.postRequest(a,r,{operation:"delete",lensId:n})}const vt="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function yt({open:t,onOpenChange:n}={}){const[r,a]=g.useState(""),[i,c]=g.useState(!1),u=e.useDashboardStore(w=>w.lenses),{setLenses:d,setSelectedLensId:p}=e.useDashboardActions(),[b,m]=g.useState(!1),[f,h]=g.useState(!1),o=t!==void 0,x=o?t:f,y=w=>{o||h(w),n==null||n(w)},j=e.useDashboardStore(w=>w.dashboard),S=e.useDashboardStore(w=>w.filterValues),{authToken:C,tokenProps:L}=e.useSemaphorContext();async function M(){m(!0);const w=await gt(L.apiServiceUrl,r,j,S,C==null?void 0:C.accessToken);w&&(d([...u||[],w]),p(w.id),y(!1)),m(!1)}return s.jsxs(e.Dialog,{open:x,onOpenChange:y,children:[o?null:s.jsx(e.DialogTrigger,{asChild:!0,children:s.jsxs(e.Button,{variant:"secondary",size:"xs",children:[s.jsx(e.Plus,{className:"h-3.5 w-3.5"}),"Lens"]})}),s.jsxs(e.DialogContent,{className:"rounded-[6px] border-border/60 sm:max-w-[420px] sm:rounded-[6px]",children:[s.jsxs(e.DialogHeader,{children:[s.jsx(e.DialogTitle,{className:"text-[15px]",children:"Create lens"}),s.jsx(e.DialogDescription,{className:"text-[13px] leading-5",children:"Lenses are private by default and are only visible to you."})]}),s.jsxs("div",{className:"space-y-1.5 py-1",children:[s.jsx(e.Label,{htmlFor:"lens-name",className:vt,children:"Name"}),s.jsx(e.Input,{id:"lens-name",size:"xs",value:r,placeholder:"Monthly review, West region, …",onChange:w=>a(w.target.value)}),i&&s.jsx("p",{className:"text-[12px] text-destructive",children:"A lens with this name already exists. Pick a different one."})]}),s.jsxs(e.DialogFooter,{children:[s.jsx(e.Button,{variant:"outline",size:"xs",onClick:()=>y(!1),children:"Cancel"}),s.jsx(e.Button,{size:"xs",type:"submit",onClick:M,disabled:b||!r.trim(),children:b?"Creating…":"Create"})]})]})]})}function St({includeLabel:t=!1}={}){const n=e.useDashboardStore(m=>m.lenses),r=e.useDashboardStore(m=>m.selectedLensId),{setLenses:a,setSelectedLensId:i}=e.useDashboardActions(),{authToken:c,tokenProps:u}=e.useSemaphorContext();async function d(m){i(m)}async function p(m){if(await bt(u.apiServiceUrl,m,c==null?void 0:c.accessToken)){const h=n==null?void 0:n.filter(o=>o.id!==m);a(h||[]),i("original")}}async function b(m){const f=n==null?void 0:n.map(x=>x.id===m.id?{...x,isDefault:!m.isDefault}:{...x,isDefault:!1});a(f||[]);const h={...m,isDefault:!m.isDefault};await Ge(u.apiServiceUrl,h,c==null?void 0:c.accessToken);const o=n==null?void 0:n.find(x=>x.isDefault);if(o&&o.id!==m.id){const x={...o,isDefault:!1};await Ge(u.apiServiceUrl,x,c==null?void 0:c.accessToken)}}return s.jsxs(s.Fragment,{children:[t?s.jsxs(s.Fragment,{children:[s.jsx(e.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),s.jsx(e.DropdownMenuSeparator,{})]}):null,s.jsxs(e.DropdownMenuRadioGroup,{value:r,onValueChange:d,children:[s.jsx(e.DropdownMenuRadioItem,{value:"original",children:"Original"}),n==null?void 0:n.map(m=>s.jsxs(e.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:m.id,children:[s.jsx("p",{children:m.name}),s.jsxs("span",{className:"flex items-center gap-3",children:[s.jsx(e.House,{onClick:f=>{f.preventDefault(),b(m)},className:e.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!m.isDefault,"text-green-500":m.isDefault}),strokeWidth:1.5}),s.jsx(e.Cross2Icon,{onClick:f=>{f.preventDefault(),p(m.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},m.id))]})]})}function jt(){const{displayPreferences:t,shouldShowElement:n}=e.useDisplayPreferences(),{currentUser:r,userContext:a}=e.useCurrentUserInfo(),i=g.useMemo(()=>e.getRoleBasedDisplayOverrides(r),[r]),c=g.useMemo(()=>d=>i&&i[d]!==void 0&&i[d]===!1?!1:n(d),[i,n,t]),u=g.useMemo(()=>{var d,p,b,m,f;return{canEdit:((d=a==null?void 0:a.permissions)==null?void 0:d.canEdit)??e.canUserEdit(r),canUseFilters:((p=a==null?void 0:a.permissions)==null?void 0:p.canEdit)??e.canUserUseFilters(r),canManageDashboards:((b=a==null?void 0:a.permissions)==null?void 0:b.canCreateDashboard)??e.canUserManageDashboards(r),canCreateDashboards:((m=a==null?void 0:a.permissions)==null?void 0:m.canCreateDashboard)??e.canUserCreateDashboards(r),canAccessVisuals:((f=a==null?void 0:a.permissions)==null?void 0:f.canEdit)??e.canUserAccessVisuals(r)}},[r,a]);return{displayPreferences:t,shouldShowElement:c,permissions:u,currentUser:r}}const Dt=async(t,n,r)=>{const a=`${t}/management/v1/groups`;return await e.postRequestRegular(a,n,r)},Ct=async(t,n,r)=>{const a=`${t}/management/v1/groups/${r}`;await e.requestJsonRegular(a,n,"DELETE")},wt=async(t,n,r,a)=>{const i=`${t}/management/v1/groups/${r}/members`;return await e.postRequestRegular(i,n,a)},Nt=async(t,n,r,a)=>{const i=`${t}/management/v1/groups/${r}/members`;await e.requestJsonRegular(i,n,"DELETE",a)};function Mt(){const{authToken:t,tokenProps:n}=e.useSemaphorContext(),r=e.useQueryClient();return e.useMutation({mutationFn:a=>Dt(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",a),onSuccess:()=>{r.invalidateQueries({queryKey:["groups"]}),e.ue.success("Group created successfully")},onError:a=>{console.error("Failed to create group:",a),e.ue.error("Failed to create group",{description:e.getRequestErrorMessage(a,"Failed to create group")})}})}function It(){const{authToken:t,tokenProps:n}=e.useSemaphorContext(),r=e.useQueryClient();return e.useMutation({mutationFn:a=>Ct(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",a),onSuccess:(a,i)=>{r.invalidateQueries({queryKey:["groups"]}),r.removeQueries({queryKey:["group",i]}),e.ue.success("Group deleted successfully")},onError:a=>{console.error("Failed to delete group:",a),e.ue.error("Failed to delete group",{description:e.getRequestErrorMessage(a,"Failed to delete group")})}})}function Et(){const{authToken:t,tokenProps:n}=e.useSemaphorContext(),r=e.useQueryClient();return e.useMutation({mutationFn:({groupId:a,data:i})=>wt(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",a,i),onSuccess:(a,i)=>{r.invalidateQueries({queryKey:["group",i.groupId]}),r.invalidateQueries({queryKey:["group-members",i.groupId]}),r.invalidateQueries({queryKey:["groups"]}),e.ue.success("Members added successfully")},onError:a=>{console.error("Failed to add group members:",a),e.ue.error("Failed to add members",{description:e.getRequestErrorMessage(a,"Failed to add members")})}})}function Lt(){const{authToken:t,tokenProps:n}=e.useSemaphorContext(),r=e.useQueryClient();return e.useMutation({mutationFn:({groupId:a,data:i})=>Nt(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",a,i),onSuccess:(a,i)=>{r.invalidateQueries({queryKey:["group",i.groupId]}),r.invalidateQueries({queryKey:["group-members",i.groupId]}),r.invalidateQueries({queryKey:["groups"]}),e.ue.success("Members removed successfully")},onError:a=>{console.error("Failed to remove group members:",a),e.ue.error("Failed to remove members",{description:e.getRequestErrorMessage(a,"Failed to remove members")})}})}const vs="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function At({onSuccess:t,tenantId:n,isTenantUser:r}){const[a,i]=g.useState(""),[c,u]=g.useState(""),[d,p]=g.useState({}),b=Mt(),m=()=>{const h={};return a.trim()?a.length<3?h.name="Group name must be at least 3 characters":a.length>50&&(h.name="Group name must be less than 50 characters"):h.name="Group name is required",c&&c.length>200&&(h.description="Description must be less than 200 characters"),p(h),Object.keys(h).length===0},f=async h=>{if(h.preventDefault(),!m())return;const o={name:a.trim(),description:c.trim()||void 0,type:r?"TENANT_GROUP":"ORG_GROUP",...r&&n?{tenantId:n}:{}};try{await b.mutateAsync(o),i(""),u(""),p({}),t()}catch(x){console.error("Failed to create group:",x)}};return s.jsxs("form",{onSubmit:f,className:"space-y-4",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs(e.Label,{htmlFor:"group-name",className:vs,children:["Group name ",s.jsx("span",{className:"text-destructive",children:"*"})]}),s.jsx(e.Input,{id:"group-name",size:"xs",placeholder:"e.g., Marketing Team, Engineering Squad",value:a,onChange:h=>{i(h.target.value),d.name&&p(o=>({...o,name:""}))},className:d.name?"border-destructive":"",disabled:b.isPending}),d.name&&s.jsx("p",{className:"text-[12px] text-destructive",children:d.name})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx(e.Label,{htmlFor:"group-description",className:vs,children:"Description (optional)"}),s.jsx(e.Textarea,{id:"group-description",placeholder:"Describe the purpose of this group…",value:c,onChange:h=>{u(h.target.value),d.description&&p(o=>({...o,description:""}))},className:`text-[13px] ${d.description?"border-destructive":""}`,disabled:b.isPending,rows:3}),d.description?s.jsx("p",{className:"text-[12px] text-destructive",children:d.description}):s.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[c.length,"/200"]})]}),s.jsxs("div",{className:"flex gap-2 text-[12px] text-muted-foreground",children:[s.jsx(e.Info,{className:"h-3.5 w-3.5 shrink-0 mt-0.5"}),s.jsx("p",{children:"This group will be accessible to users in your workspace. You can add members after creating it."})]}),s.jsxs("div",{className:"flex justify-end gap-1.5 pt-1",children:[s.jsx(e.Button,{type:"button",variant:"outline",size:"xs",onClick:()=>{i(""),u(""),p({})},disabled:b.isPending,children:"Clear"}),s.jsx(e.Button,{type:"submit",size:"xs",disabled:b.isPending||!a.trim(),children:b.isPending?s.jsxs(s.Fragment,{children:[s.jsx(e.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Creating…"]}):"Create group"})]})]})}function Ot(t,n=[]){let r=[];function a(c,u){const d=N.createContext(u);d.displayName=c+"Context";const p=r.length;r=[...r,u];const b=f=>{var S;const{scope:h,children:o,...x}=f,y=((S=h==null?void 0:h[t])==null?void 0:S[p])||d,j=N.useMemo(()=>x,Object.values(x));return s.jsx(y.Provider,{value:j,children:o})};b.displayName=c+"Provider";function m(f,h){var y;const o=((y=h==null?void 0:h[t])==null?void 0:y[p])||d,x=N.useContext(o);if(x)return x;if(u!==void 0)return u;throw new Error(`\`${f}\` must be used within \`${c}\``)}return[b,m]}const i=()=>{const c=r.map(u=>N.createContext(u));return function(d){const p=(d==null?void 0:d[t])||c;return N.useMemo(()=>({[`__scope${t}`]:{...d,[t]:p}}),[d,p])}};return i.scopeName=t,[a,kt(i,...n)]}function kt(...t){const n=t[0];if(t.length===1)return n;const r=()=>{const a=t.map(i=>({useScope:i(),scopeName:i.scopeName}));return function(c){const u=a.reduce((d,{useScope:p,scopeName:b})=>{const f=p(c)[`__scope${b}`];return{...d,...f}},{});return N.useMemo(()=>({[`__scope${n.scopeName}`]:u}),[u])}};return r.scopeName=n.scopeName,r}var Tt=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],$e=Tt.reduce((t,n)=>{const r=e.createSlot(`Primitive.${n}`),a=N.forwardRef((i,c)=>{const{asChild:u,...d}=i,p=u?r:n;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),s.jsx(p,{...d,ref:c})});return a.displayName=`Primitive.${n}`,{...t,[n]:a}},{});function Pt(){return ft.useSyncExternalStore(Ft,()=>!0,()=>!1)}function Ft(){return()=>{}}var qe="Avatar",[_t]=Ot(qe),[Ut,js]=_t(qe),Ds=N.forwardRef((t,n)=>{const{__scopeAvatar:r,...a}=t,[i,c]=N.useState("idle");return s.jsx(Ut,{scope:r,imageLoadingStatus:i,onImageLoadingStatusChange:c,children:s.jsx($e.span,{...a,ref:n})})});Ds.displayName=qe;var Cs="AvatarImage",ws=N.forwardRef((t,n)=>{const{__scopeAvatar:r,src:a,onLoadingStatusChange:i=()=>{},...c}=t,u=js(Cs,r),d=Rt(a,c),p=e.useCallbackRef(b=>{i(b),u.onImageLoadingStatusChange(b)});return e.useLayoutEffect2(()=>{d!=="idle"&&p(d)},[d,p]),d==="loaded"?s.jsx($e.img,{...c,ref:n,src:a}):null});ws.displayName=Cs;var Ns="AvatarFallback",Ms=N.forwardRef((t,n)=>{const{__scopeAvatar:r,delayMs:a,...i}=t,c=js(Ns,r),[u,d]=N.useState(a===void 0);return N.useEffect(()=>{if(a!==void 0){const p=window.setTimeout(()=>d(!0),a);return()=>window.clearTimeout(p)}},[a]),u&&c.imageLoadingStatus!=="loaded"?s.jsx($e.span,{...i,ref:n}):null});Ms.displayName=Ns;function ys(t,n){return t?n?(t.src!==n&&(t.src=n),t.complete&&t.naturalWidth>0?"loaded":"loading"):"error":"idle"}function Rt(t,{referrerPolicy:n,crossOrigin:r}){const a=Pt(),i=N.useRef(null),c=a?(i.current||(i.current=new window.Image),i.current):null,[u,d]=N.useState(()=>ys(c,t));return e.useLayoutEffect2(()=>{d(ys(c,t))},[c,t]),e.useLayoutEffect2(()=>{const p=f=>()=>{d(f)};if(!c)return;const b=p("loaded"),m=p("error");return c.addEventListener("load",b),c.addEventListener("error",m),n&&(c.referrerPolicy=n),typeof r=="string"&&(c.crossOrigin=r),()=>{c.removeEventListener("load",b),c.removeEventListener("error",m)}},[c,r,n]),u}var Is=Ds,Es=ws,Ls=Ms;const Be=N.forwardRef(({className:t,...n},r)=>s.jsx(Is,{ref:r,className:e.cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",t),...n}));Be.displayName=Is.displayName;const Gt=N.forwardRef(({className:t,...n},r)=>s.jsx(Es,{ref:r,className:e.cn("aspect-square h-full w-full",t),...n}));Gt.displayName=Es.displayName;const ze=N.forwardRef(({className:t,...n},r)=>s.jsx(Ls,{ref:r,className:e.cn("flex h-full w-full items-center justify-center rounded-full bg-muted",t),...n}));ze.displayName=Ls.displayName;function $t({open:t,onOpenChange:n,group:r,onUpdate:a}){const[i,c]=g.useState("members"),[u,d]=g.useState(""),[p,b]=g.useState([]),[m,f]=g.useState([]),{data:h,isLoading:o,refetch:x}=e.useGroupMembers(r.id),y=r.type==="TENANT_GROUP"?"tenant":"organization",{users:j,isLoading:S}=e.useUnifiedUsers({type:y,tenantId:r.tenantId||void 0,active:!0,limit:100}),C=Et(),L=Lt(),M=(h==null?void 0:h.members)||[],w=g.useMemo(()=>new Set(M.map(v=>v.userId)),[M]),F=g.useMemo(()=>j.filter(v=>!w.has(v.id)),[j,w]),P=g.useMemo(()=>{if(!u)return F;const v=u.toLowerCase();return F.filter(E=>{var k,q;return((k=E.name)==null?void 0:k.toLowerCase().includes(v))||((q=E.email)==null?void 0:q.toLowerCase().includes(v))})},[F,u]),D=g.useMemo(()=>{if(!u)return M;const v=u.toLowerCase();return M.filter(E=>{var k,q,V,ee;return((q=(k=E.user)==null?void 0:k.name)==null?void 0:q.toLowerCase().includes(v))||((ee=(V=E.user)==null?void 0:V.email)==null?void 0:ee.toLowerCase().includes(v))})},[M,u]),_=async()=>{if(p.length!==0)try{await C.mutateAsync({groupId:r.id,data:{userIds:p,userType:y==="tenant"?"tenant":"org"}}),b([]),c("members"),x(),a==null||a()}catch(v){console.error("Failed to add members:",v)}},$=async()=>{if(m.length!==0)try{await L.mutateAsync({groupId:r.id,data:{userIds:m}}),f([]),x(),a==null||a()}catch(v){console.error("Failed to remove members:",v)}},R=v=>{b(E=>E.includes(v)?E.filter(k=>k!==v):[...E,v])},je=v=>{f(E=>E.includes(v)?E.filter(k=>k!==v):[...E,v])};return s.jsx(s.Fragment,{children:s.jsx(e.Dialog,{open:t,onOpenChange:n,children:s.jsxs(e.DialogContent,{className:"max-w-3xl max-h-[80vh]","aria-describedby":"group-members-description",children:[s.jsxs(e.DialogHeader,{children:[s.jsx(e.DialogTitle,{children:r.name}),s.jsx("div",{className:"flex items-center gap-2 mt-1",children:s.jsxs("p",{className:"text-sm text-muted-foreground",children:[M.length," ",M.length===1?"member":"members"]})}),s.jsxs("p",{id:"group-members-description",className:"sr-only",children:["Add or remove members from the ",r.name," group"]})]}),s.jsxs(e.Tabs,{value:i,onValueChange:v=>{c(v),d(""),f([])},className:"mt-4",children:[s.jsxs(e.TabsList,{className:"grid w-full grid-cols-2",children:[s.jsx(e.TabsTrigger,{value:"members",children:"Current Members"}),s.jsx(e.TabsTrigger,{value:"add",children:"Add Members"})]}),s.jsxs(e.TabsContent,{value:"members",className:"mt-4 space-y-4",children:[s.jsxs("div",{className:"relative",children:[s.jsx(e.Search,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx(e.Input,{placeholder:"Search members...",value:u,onChange:v=>d(v.target.value),className:"pl-10"})]}),s.jsx(e.ScrollArea,{className:m.length>0?"h-[300px]":"h-[350px]",children:o?s.jsx("div",{className:"space-y-2",children:[1,2,3].map(v=>s.jsx(e.Skeleton,{className:"h-16 w-full"},v))}):D.length===0?s.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[s.jsx(e.Users,{className:"h-12 w-12 mb-3 opacity-50"}),s.jsx("p",{className:"text-sm font-medium",children:u?"No members found":"No members yet"}),s.jsx("p",{className:"text-xs mt-1",children:u?"Try a different search":'Switch to the "Add Members" tab to add people to this group'})]}):s.jsx("div",{className:"space-y-2",children:D.map(v=>s.jsx(qt,{member:v,selected:m.includes(v.userId),onToggle:()=>je(v.userId)},v.id))})}),m.length>0&&s.jsxs("div",{className:"flex items-center justify-between pt-4 border-t",children:[s.jsxs("span",{className:"text-sm text-muted-foreground",children:[m.length," member",m.length!==1?"s":""," selected"]}),s.jsx(e.Button,{variant:"destructive",size:"sm",onClick:$,disabled:L.isPending,children:L.isPending?s.jsxs(s.Fragment,{children:[s.jsx(e.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Removing..."]}):s.jsxs(s.Fragment,{children:[s.jsx(e.Trash2,{className:"mr-2 h-4 w-4"}),"Remove Selected"]})})]})]}),s.jsxs(e.TabsContent,{value:"add",className:"mt-4 space-y-4",children:[s.jsxs("div",{className:"relative",children:[s.jsx(e.Search,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx(e.Input,{placeholder:"Search users to add...",value:u,onChange:v=>d(v.target.value),className:"pl-10"})]}),s.jsx(e.ScrollArea,{className:"h-[300px]",children:S?s.jsx("div",{className:"space-y-2",children:[1,2,3].map(v=>s.jsx(e.Skeleton,{className:"h-16 w-full"},v))}):P.length===0?s.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[s.jsx(e.UserPlus,{className:"h-12 w-12 mb-3 opacity-50"}),s.jsx("p",{className:"text-sm font-medium",children:"No available users"}),s.jsx("p",{className:"text-xs mt-1",children:u?"Try a different search":"All eligible users are already members"})]}):s.jsx("div",{className:"space-y-2",children:P.map(v=>s.jsx(Bt,{user:v,selected:p.includes(v.id),onToggle:()=>R(v.id)},v.id))})}),p.length>0&&s.jsxs("div",{className:"flex items-center justify-between pt-4 border-t",children:[s.jsxs("span",{className:"text-sm text-muted-foreground",children:[p.length," user",p.length!==1?"s":""," selected"]}),s.jsx(e.Button,{onClick:_,disabled:C.isPending,children:C.isPending?s.jsxs(s.Fragment,{children:[s.jsx(e.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Adding..."]}):s.jsxs(s.Fragment,{children:[s.jsx(e.UserPlus,{className:"mr-2 h-4 w-4"}),"Add Members"]})})]})]})]})]})})})}function qt({member:t,selected:n,onToggle:r}){var i,c,u,d;const a=((c=(i=t.user)==null?void 0:i.name)==null?void 0:c.split(" ").map(p=>p[0]).join("").toUpperCase())||"?";return s.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg border bg-card hover:bg-muted/50 cursor-pointer",onClick:r,children:[s.jsx(e.Checkbox,{checked:n}),s.jsx(Be,{className:"h-8 w-8",children:s.jsx(ze,{className:"text-xs",children:a})}),s.jsxs("div",{className:"flex-1",children:[s.jsx("p",{className:"text-sm font-medium",children:((u=t.user)==null?void 0:u.name)||"Unknown User"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:(d=t.user)==null?void 0:d.email})]})]})}function Bt({user:t,selected:n,onToggle:r}){var i;const a=((i=t.name)==null?void 0:i.split(" ").map(c=>c[0]).join("").toUpperCase())||"?";return s.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg border bg-card hover:bg-muted/50 cursor-pointer",onClick:r,children:[s.jsx(e.Checkbox,{checked:n}),s.jsx(Be,{className:"h-8 w-8",children:s.jsx(ze,{className:"text-xs",children:a})}),s.jsxs("div",{className:"flex-1",children:[s.jsx("p",{className:"text-sm font-medium",children:t.name}),s.jsx("p",{className:"text-xs text-muted-foreground",children:t.email})]})]})}function zt({open:t,onOpenChange:n}){const[r,a]=g.useState("groups"),[i,c]=g.useState(""),[u,d]=g.useState(null),[p,b]=g.useState(!1),[m,f]=g.useState(null),{tokenProps:h}=e.useSemaphorContext(),{currentUser:o}=e.useCurrentUserInfo(),x=It(),y=(o==null?void 0:o.type)==="tenant",j=h==null?void 0:h.tenantId,{groups:S,isLoading:C,refetch:L}=e.useGroups({type:y?"TENANT_GROUP":"all",tenantId:y?j:void 0,includeMembers:!1}),M=S.filter(D=>{var _;return D.name.toLowerCase().includes(i.toLowerCase())||((_=D.description)==null?void 0:_.toLowerCase().includes(i.toLowerCase()))}),w=async()=>{if(m)try{await x.mutateAsync(m.id),f(null),L()}catch(D){console.error("Failed to delete group:",D)}},F=D=>{d(D),b(!0)},P=()=>{a("groups"),L()};return s.jsxs(s.Fragment,{children:[s.jsx(e.Dialog,{open:t,onOpenChange:n,children:s.jsxs(e.DialogContent,{className:"max-h-[80vh] max-w-3xl rounded-[6px] border-border/60 sm:rounded-[6px]",children:[s.jsxs(e.DialogHeader,{children:[s.jsx(e.DialogTitle,{className:"text-[15px]",children:"Group management"}),s.jsx(e.DialogDescription,{className:"text-[13px] leading-5",children:"Manage groups, create new ones, and control membership."})]}),s.jsxs(e.Tabs,{value:r,onValueChange:a,className:"mt-2",children:[s.jsxs(e.TabsList,{className:"h-8 w-full justify-start gap-1 bg-transparent p-0 border-b border-border/60 rounded-none",children:[s.jsx(e.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"}),s.jsx(e.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"})]}),s.jsx(e.TabsContent,{value:"groups",className:"mt-4",children:s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"relative",children:[s.jsx(e.Search,{className:"absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),s.jsx(e.Input,{size:"xs",placeholder:"Search groups…",value:i,onChange:D=>c(D.target.value),className:"pl-7"})]}),s.jsx(e.ScrollArea,{className:"h-[400px]",children:C?s.jsx("div",{className:"space-y-2",children:[1,2,3].map(D=>s.jsx(e.Skeleton,{className:"h-16 w-full rounded-[6px]"},D))}):M.length===0?s.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[s.jsx("p",{className:"text-[13px]",children:"No groups found."}),s.jsx("p",{className:"mt-1 text-[12px]",children:i?"Try a different search.":"Create your first group to get started."})]}):s.jsx("div",{className:"space-y-2 pr-2",children:M.map(D=>s.jsx(Vt,{group:D,onManageMembers:()=>F(D),onDelete:()=>f(D),currentUserId:o==null?void 0:o.id},D.id))})})]})}),s.jsx(e.TabsContent,{value:"create",className:"mt-4",children:s.jsx(At,{onSuccess:P,tenantId:j,isTenantUser:y})})]})]})}),u&&s.jsx($t,{open:p,onOpenChange:b,group:u,onUpdate:()=>L()}),s.jsx(e.AlertDialog,{open:!!m,onOpenChange:()=>f(null),children:s.jsxs(e.AlertDialogContent,{children:[s.jsxs(e.AlertDialogHeader,{children:[s.jsx(e.AlertDialogTitle,{children:"Delete group"}),s.jsxs(e.AlertDialogDescription,{children:['Delete "',m==null?void 0:m.name,`"? This removes all members and can't be undone.`]})]}),s.jsxs(e.AlertDialogFooter,{children:[s.jsx(e.AlertDialogCancel,{children:"Cancel"}),s.jsx(e.AlertDialogAction,{onClick:w,disabled:x.isPending,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:x.isPending?s.jsxs(s.Fragment,{children:[s.jsx(e.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Deleting…"]}):"Delete group"})]})]})})]})}function Vt({group:t,onManageMembers:n,onDelete:r,currentUserId:a}){const i=t.createdBy===a;return s.jsx("div",{className:"rounded-[6px] border border-border/60 bg-card px-3 py-2.5 transition-colors hover:bg-muted/30",children:s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[s.jsx("h4",{className:"text-[13px] font-medium text-foreground",children:t.name}),t.description&&s.jsx("p",{className:"text-[12px] text-muted-foreground",children:t.description}),s.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-[11px] text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(e.Users,{className:"h-3 w-3"}),t.memberCount," ",t.memberCount===1?"member":"members"]}),s.jsxs("span",{children:["Created ",at.format(new Date(t.createdAt),"MMM d, yyyy")]})]})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[s.jsx(e.Button,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:n,title:"Manage members","aria-label":"Manage members",children:s.jsx(e.UserPlus,{className:"h-3.5 w-3.5"})}),i&&s.jsx(e.Button,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:bg-destructive/10 hover:text-destructive",onClick:r,title:"Delete group","aria-label":"Delete group",children:s.jsx(e.Trash2,{className:"h-3.5 w-3.5"})})]})]})})}function X(t,n,r){var c,u;const a=(t.controls||[]).find(d=>d.id===r);if(a)return a.label;const i=(u=(c=e.findCardById(t,n))==null?void 0:c.controls)==null?void 0:u.find(d=>d.id===r);return(i==null?void 0:i.label)||r}function Z(t,n){var r;return((r=e.findCardById(t,n))==null?void 0:r.title)||n}function Ht(t){const{errors:n,dashboard:r}=t;if(!r)return n;const a=new Map;for(const i of n){const c=i.match(/^Card '(.+)' binding for control '(.+)' maps to missing metric '(.+)'\.$/);if(c){const[,m,f]=c,h=`${m}:${f}:missing-metric`;a.has(h)||a.set(h,`"${Z(r,m)}" has an outdated "${X(r,m,f)}" mapping. Some choices still point to metrics that are no longer available on this card. Open the card controls and choose replacements.`);continue}const u=i.match(/^Card '(.+)' binding for control '(.+)' maps to missing group-by field '(.+)'\.$/);if(u){const[,m,f]=u,h=`${m}:${f}:missing-group-by`;a.has(h)||a.set(h,`"${Z(r,m)}" has an outdated "${X(r,m,f)}" mapping. Some choices still point to fields that are no longer available on this card. Open the card controls and choose replacements.`);continue}const d=i.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid metric target\.$/);if(d){const[,m,f]=d,h=`${m}:${f}:invalid-metric`;a.has(h)||a.set(h,`"${Z(r,m)}" has an invalid "${X(r,m,f)}" metric mapping. Open the card controls and choose a valid metric for each option.`);continue}const p=i.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid group-by target\.$/);if(p){const[,m,f]=p,h=`${m}:${f}:invalid-group-by`;a.has(h)||a.set(h,`"${Z(r,m)}" has an invalid "${X(r,m,f)}" field mapping. Open the card controls and choose a valid field for each option.`);continue}const b=i.match(/^Card '(.+)' binding for control '(.+)' requires at least one temporal group-by field\.$/);if(b){const[,m,f]=b,h=`${m}:${f}:missing-temporal-group-by`;a.has(h)||a.set(h,`"${Z(r,m)}" can no longer use "${X(r,m,f)}" for time grain because the card does not currently group by a date field.`);continue}a.set(i,i)}return Array.from(a.values())}const Kt=["enum","multi_enum","text","number","boolean","date"];function Qt({open:t,onOpenChange:n,initialMode:r="manage"}){var P;const a=r==="create",{forceClose:i,handleOpenChange:c,isCreateFlowActive:u,preventPassiveDismissDuringCreate:d,resolvedOpen:p,setIsCreateFlowActive:b}=Se.useCreateFlowOverlayState({open:t,onOpenChange:n,initialCreateFlowActive:r==="create",dismissMode:"explicit-only"}),m=e.useDashboardStore(D=>D.dashboard),f=e.useDashboardStore(D=>D.selectedSheetId),{updateSheetDocument:h}=e.useDashboardActions(),o=(P=m.sheets)==null?void 0:P.find(D=>D.id===f),x=(o==null?void 0:o.kind)==="document"&&!!o.document,y=g.useMemo(()=>x&&(o!=null&&o.document)?o.document.inputs||[]:[],[x,o==null?void 0:o.document]),j=g.useMemo(()=>y.filter(D=>D.kind==="control"),[y]),S=g.useMemo(()=>j.map(D=>D.control),[j]),C=g.useMemo(()=>Jt(S),[S]),L=g.useMemo(()=>Wt(m),[m]),M=g.useCallback(()=>{if(a){i();return}b(!1)},[a,i,b]),w=g.useCallback((D,_,$)=>{!x||!(o!=null&&o.document)||h(o.id,R=>({...R,inputs:Xt({currentInputs:R.inputs||[],nextControls:D,nextDefaultValues:_,change:$})}))},[x,o,h]);if(!x||!(o!=null&&o.document))return null;const F=u?"Add document control":"Document Controls";return s.jsx(e.Dialog,{open:p,onOpenChange:c,children:s.jsxs(e.DialogContent,{className:"flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",onEscapeKeyDown:d,onPointerDownOutside:d,children:[s.jsxs(e.DialogHeader,{className:u?"space-y-0":void 0,children:[s.jsx(e.DialogTitle,{className:"text-[15px]",children:F}),s.jsx(e.DialogDescription,{className:u?"sr-only":"text-[13px]",children:u?"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."})]}),s.jsx("div",{className:"min-h-0 overflow-y-auto pr-1",children:s.jsx(Se.ControlDefinitionListEditor,{scope:"dashboard",controls:S,reservedControlIds:L,defaultValues:C,usageByControlId:{},availableFieldChoices:[],availableMetricChoices:[],structuralParticipants:[],structuralParticipantIdsByControlId:{},allowedControlTypes:Kt,initialCreateFlow:r==="create",onCreateFlowActiveChange:b,onCreateFlowComplete:M,onChange:w,emptyMessage:"No document controls yet."})})]})})}function Wt(t){return(t.controls||[]).map(n=>n.id)}function Jt(t){const n={};for(const r of t)r.defaultValue!==void 0&&(n[r.id]=r.defaultValue);return n}function Yt(t,n){return n?Object.prototype.hasOwnProperty.call(n,t.id)?{...t,defaultValue:n[t.id]}:t.defaultValue===void 0?t:{...t,defaultValue:void 0}:t.defaultValue===void 0?t:{...t,defaultValue:void 0}}function Xt({currentInputs:t,nextControls:n,nextDefaultValues:r,change:a}){const i=new Map(n.map(p=>[p.id,Yt(p,r)])),c=(a==null?void 0:a.type)==="rename"?{oldId:a.oldId,newId:a.newId}:null,u=new Set,d=[];for(const p of t){if(p.kind!=="control"){d.push(p);continue}const b=i.get(p.control.id)||((c==null?void 0:c.oldId)===p.control.id?i.get(c.newId):void 0);b&&(u.add(b.id),d.push({...p,label:b.label,requiredAtExecution:b.requiredAtExecution,control:b}))}for(const p of i.values())u.has(p.id)||d.push(e.createDocumentControlInputFromControl({control:p,existingInputs:d}));return d}function Ss(t,n){return{dashboard:e.cloneDeep(t),semanticExecutionPayload:e.cloneDeep(n)}}function Zt(){var cs,ds,us,ms,hs,ps;G.useExportRecovery(),G.useExportPolling();const{authToken:t,tokenProps:n,id:r}=e.useSemaphorContext(),{isLocalDev:a}=e.useDashboardPreferences(),{permissions:i}=jt(),c=e.useHasDashboardId(),{isLoading:u}=e.useDashboardQuery(),d=e.useDashboardStore(l=>l.theme),p=e.useDashboardStore(l=>l.isDownloadingPdf),b=e.useDashboardStore(l=>l.dashboardAssistantDraftScopeKey),m=e.useDashboardStore(l=>l.lenses),f=e.useDashboardStore(l=>l.selectedLensId),h=m==null?void 0:m.find(l=>l.id===f),o=e.useDashboardStore(l=>l.dashboard),x=e.useDashboardStore(l=>l.selectedSheetId),y=(cs=o==null?void 0:o.sheets)==null?void 0:cs.find(l=>l.id===x),j=e.isDocumentSheet(y),S=j?(ds=y==null?void 0:y.document)==null?void 0:ds.page:void 0,C=e.useDashboardStore(l=>l.isDashboardEditing),{setDashboardTitle:L}=e.useDashboardStore(l=>l.actions),[M,w]=g.useState(!1),[F,P]=g.useState(!1),[D,_]=g.useState(!1),[$,R]=g.useState(!1),[je,v]=g.useState(!1),[E,k]=g.useState(!1),[q,V]=g.useState(!1),[ee,Ve]=g.useState(!1),[De,se]=g.useState(null),[As,te]=g.useState(!1),[ae,ne]=g.useState(null),[He,re]=g.useState([]),[Ke,oe]=g.useState(!1),Os=e.useDashboardStore(l=>l.isDashboardPanelOpen),ks=e.useDashboardStore(l=>l.actions.setIsDashboardPanelOpen),Ts=e.useDashboardStore(l=>l.filterValues),A=e.useDashboardStore(l=>l.isVisualEditing);e.useEditorStore(l=>l.card);const H=e.useManagementStore(l=>l.selectedDashboard),ie=e.useManagementStore(l=>l.initialDashboard);e.useManagementStore(l=>l.selectedVisual),e.useDashboardStore(l=>l.selectedFrameId),e.useEditorStore(l=>l.frame);const le=H?(ms=H==null?void 0:H.permissions)==null?void 0:ms.canEdit:(us=ie==null?void 0:ie.permissions)==null?void 0:us.canEdit,ce=e.useDashboardStore(l=>l.showFilters),Qe=e.useAssistantLayoutStore(l=>l.setPanelOpen),We=e.useDashboardStore(l=>l.showDashboardJSON),Ce=e.useDashboardStore(l=>l.onSaveFunction),Je=e.useDashboardStore(l=>l.actions.setShowFilters),{setDocumentInspectorTab:Ye,setIsDashboardEditing:Xe,setShowDashboardJSON:Ze}=e.useDashboardStore(l=>l.actions),{setInitialDashboard:es,clearSelectedDashboard:we}=e.useManagementStore(l=>l.actions),{resources:de}=e.useResourceManagement(e.ResourceType.DASHBOARD),{data:Ne}=e.useUserPreferences(),Ps=((hs=Ne==null?void 0:Ne.preference)==null?void 0:hs.defaultDashboardId)||null,{mutate:Fs,isPending:_s}=e.useDefaultDashboardMutation(),{currentUser:Us}=e.useCurrentUserInfo(),Rs=e.canUserManageGroups(Us),z=H||ie,ss=z?{id:z.id,title:(o==null?void 0:o.title)||z.title||"Dashboard"}:null,{handleAddNewFrame:Gs}=e.useAddNewFrame(),[Me,Ie]=g.useState(!1),[$s,K]=g.useState(!1),[Ee,ue]=g.useState("close"),Q=e.useUpdateResource(e.ResourceType.DASHBOARD),[T,me]=g.useState(null),ts=g.useCallback(l=>{window.setTimeout(()=>{se(l)},0)},[]),qs=async(l,I)=>{if(!(o!=null&&o.id)){console.log("No dashboard ID found");return}console.log("Updating dashboard title:",{dashboardId:o.id,newTitle:l,previousTitle:I}),Q.mutate({resourceId:o.id,data:{title:l}},{onSuccess:()=>{console.log("Dashboard title updated successfully"),e.ue.success("Dashboard title updated")},onError:U=>{console.error("Failed to update dashboard title:",U),e.ue.error("Failed to update dashboard title"),L(I)}})};g.useEffect(()=>{if(de&&de.length>0){const l=o==null?void 0:o.id;if(l){const I=de.find(U=>U.id===l);I&&es(I)}}},[de,o==null?void 0:o.id,es]);const W=n.orgUserId||n.tenantId,Le=g.useMemo(()=>ea({accessToken:t==null?void 0:t.accessToken,dashboardId:(o==null?void 0:o.id)||r||n.dashboard_id,selectedSheetId:j?x:void 0,pageSize:S==null?void 0:S.size,orientation:S==null?void 0:S.orientation,theme:d}),[t==null?void 0:t.accessToken,r,o==null?void 0:o.id,j,S==null?void 0:S.orientation,S==null?void 0:S.size,x,d,n.dashboard_id]),as=C&&!A&&W&&le,{setDashboard:Ae}=e.useDashboardStore(l=>l.actions),Oe=e.useDashboardStore(l=>l.semanticExecutionPayload),Bs=()=>{Xe(!0)},ke=()=>{Xe(!1),Ze(!1),me(null),se(null)};g.useEffect(()=>{if(!C){T&&me(null);return}T||!o||u||me(Ss(o,Oe))},[o,T,C,u,Oe]);const he=(T==null?void 0:T.dashboard)??null,{isDirty:ns,isDirtyPending:zs,resetDirty:pe}=nt.useDebouncedDirtyCheck(o,he,300,1e3,Fe.serializeDashboardForDirtyCheck),rs=g.useCallback(()=>he?Fe.serializeDashboardForDirtyCheck(o)!==Fe.serializeDashboardForDirtyCheck(he):!1,[o,he]),os=ns||zs,fe=Me||Q.isPending,Vs=()=>{rs()?(ue("close"),K(!0)):(ke(),pe())},Hs=async()=>{await Te({closeAfterSave:!0,navigateHomeAfterSave:Ee==="home"})},Ks=()=>{T&&Ae(T.dashboard,{semanticExecutionPayload:T.semanticExecutionPayload}),ke(),Ee==="home"&&we(),ue("close"),K(!1),pe()},Qs=()=>{T&&(Ae(T.dashboard,{semanticExecutionPayload:T.semanticExecutionPayload}),pe())},Ws=()=>{if(C&&rs()){ue("home"),K(!0);return}we()};async function Te(l){const I=e.useDashboardStore.getState().dashboard;if(!I)return;const U=(l==null?void 0:l.closeAfterSave)??Ke,et=(l==null?void 0:l.navigateHomeAfterSave)??!1;oe(U),U&&K(!1);const st=e.cloneDeep(I);te(!0),ne(null),re([]),Ie(!0);const tt={template:I};Q.mutate({resourceId:I.id,data:tt},{onSuccess:O=>{var ge,be,fs;const B=(O==null?void 0:O.id)||((ge=O==null?void 0:O.dashboard)==null?void 0:ge.id)||((be=O==null?void 0:O.resource)==null?void 0:be.id)||((fs=O==null?void 0:O.template)==null?void 0:fs.id)||null;if(!I.id&&B){const Pe=e.useAIInteractionStore.getState(),ve=Pe.pendingDashboardDraftMigration;(ve==null?void 0:ve.scopeKey)===b?Pe.actions.setPendingDashboardDraftMigrationExpectedDashboardId(B):ve&&Pe.actions.clearPendingDashboardDraftMigration()}Ie(!1),e.ue.success("Dashboard saved!"),me(Ss(st,e.useDashboardStore.getState().semanticExecutionPayload)),te(!1),oe(!1),U&&(ke(),pe(),et&&we()),ue("close")},onError:O=>{Ie(!1),ne("Failed to save dashboard. Please try again.");const B=O.details,ge=Array.isArray(B==null?void 0:B.errors)?(B.errors||[]).filter(be=>typeof be=="string"):[];re(Ht({errors:ge,dashboard:I||void 0})),e.ue.error("Failed to save dashboard")}})}async function Js(){if(w(!0),!f||!h)return;const l=e.useDashboardStore.getState().dashboard;if(!l){w(!1);return}const I=JSON.stringify(l),U={...h,template:I,filterValues:Ts};await Ge(n.apiServiceUrl,U,t==null?void 0:t.accessToken),e.ue.success("Lens saved"),Ce==null||Ce(l),w(!1)}const is=(h==null?void 0:h.name)||o.title,J=!!(o!=null&&o.id);Q.isPending&&console.log("Title during update:",{title:is,dashboardStateTitle:o.title,dashboardId:o==null?void 0:o.id,currentLensName:h==null?void 0:h.name});const ls=n.orgUserId||n.tenantId&&n.endUserId&&n.endUserEmail,Ys=!!ls&&!!(t!=null&&t.accessToken)&&!!(n!=null&&n.apiServiceUrl);g.useEffect(()=>{!J&&$&&R(!1)},[J,$]);const Xs=c,Y=(o==null?void 0:o.id)||null,xe=!!Y&&Ps===Y,Zs=()=>{Y&&Fs({dashboardId:xe?null:Y})};return s.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:[s.jsxs("div",{className:"flex items-center gap-2",children:[ls&&s.jsxs(s.Fragment,{children:[s.jsx(e.IconButton,{"aria-label":"Manage Dashboards",tooltip:"Manage Dashboards",onClick:()=>{ks(!Os)},className:"h-7 w-7 px-0",buttonProps:{size:"xs"},children:s.jsx(lt,{className:"h-3.5 w-3.5"})}),Xs&&!A&&s.jsx(e.IconButton,{"aria-label":"Dashboard Hub",tooltip:"Dashboard Hub",onClick:Ws,className:"h-7 w-7 px-0",buttonProps:{size:"xs"},children:s.jsx(e.House,{className:"h-3.5 w-3.5"})})]}),!A&&c&&(u?s.jsx("div",{className:"h-4 w-28 animate-pulse rounded-md bg-muted/70","aria-label":"Loading dashboard title",role:"status",children:s.jsx("span",{className:"sr-only",children:"Loading dashboard title"})}):s.jsxs(s.Fragment,{children:[s.jsx(e.EditableText,{value:is||"Untitled Dashboard",onSave:l=>{console.log("EditableText onSave called:",{newTitle:l,canEditDashboard:le,dashboardId:o==null?void 0:o.id});const I=(o==null?void 0:o.title)||"";L(l),qs(l,I)},isEditable:le&&!h,displayClassName:"text-[13px] font-medium",inputClassName:"text-[13px] font-medium",placeholder:"Dashboard Title",isPending:Q.isPending}),Ys&&Y&&s.jsx(e.TooltipProvider,{children:s.jsxs(e.Tooltip,{children:[s.jsx(e.TooltipTrigger,{asChild:!0,children:s.jsx(e.Button,{variant:"ghost",size:"xs",onClick:Zs,disabled:_s||!(t!=null&&t.accessToken)||!(n!=null&&n.apiServiceUrl),className:"w-7 px-0","aria-label":xe?"Remove as default dashboard":"Make this a default dashboard",children:s.jsx(e.Star,{className:e.cn("h-3.5 w-3.5 transition-colors",xe?"fill-foreground text-foreground":"text-muted-foreground hover:text-foreground")})})}),s.jsx(e.TooltipContent,{children:s.jsx("p",{children:xe?"Remove as default dashboard":"Make this a default dashboard"})})]})})]}))]}),s.jsxs("div",{className:"flex items-center gap-2",children:[A&&s.jsxs(s.Fragment,{children:[s.jsx(G.AdvancedModeToggle,{}),s.jsx(G.VisualEditingControls,{})]}),!A&&c&&((ps=z==null?void 0:z.permissions)==null?void 0:ps.canShare)&&s.jsxs(e.Button,{variant:"outline",size:"xs",onClick:()=>P(!0),children:[s.jsx(e.Share2,{className:"h-3.5 w-3.5"}),"Share"]}),!A&&C&&i.canUseFilters&&c&&s.jsx(G.DashboardFilterControlsButton,{showFilters:j?!1:ce,onToggleFilters:()=>{if(j&&x){Ye(x,"inputs");return}ce||Qe("dashboard",!1),Je(!ce)},onAddFilter:()=>{if(j&&x){Ye(x,"inputs");return}ce||(Qe("dashboard",!1),Je(!0))},onAddControl:()=>{ts("create")},onManageControls:()=>ts("manage")}),C&&!A&&c&&De?j?s.jsx(Qt,{open:!0,onOpenChange:l=>{l||se(null)},initialMode:De}):s.jsx(G.DashboardControlsSettings,{open:!0,onOpenChange:l=>{l||se(null)},showTrigger:!1,initialMode:De}):null,C&&!A&&W&&h&&a&&c&&s.jsxs(e.Button,{variant:"secondary",size:"xs",disabled:M,onClick:Js,children:[s.jsx(Se.Save,{className:"h-3.5 w-3.5"}),"Save Lens"]}),C&&!A&&c&&!j&&s.jsxs(e.Button,{variant:"outline",size:"xs",disabled:!C,onClick:()=>Gs(),children:[s.jsx(e.Plus,{className:"h-3.5 w-3.5"}),"Visual"]}),!A&&!C&&le&&c&&s.jsxs(e.Button,{size:"xs",onClick:Bs,children:[s.jsx(e.Pencil,{className:"h-3.5 w-3.5"}),"Edit"]}),as&&c&&ns&&s.jsxs(e.Button,{variant:"outline",size:"xs",onClick:Qs,disabled:fe,children:[s.jsx(e.Undo2,{className:"h-3.5 w-3.5"}),"Undo"]}),as&&c&&s.jsxs(e.Button,{size:"xs",className:e.cn(!os&&"opacity-60"),disabled:fe||!os,onClick:()=>Te(),children:[fe?s.jsx(e.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}):s.jsx(Se.Save,{className:"h-3.5 w-3.5"}),fe?"Saving...":"Save"]}),C&&!A&&c&&s.jsxs(e.Button,{variant:"outline",size:"xs",onClick:Vs,children:[s.jsx(e.Cross2Icon,{className:"h-3.5 w-3.5"}),"Close"]}),!A&&c&&s.jsx("div",{className:"ml-2",children:s.jsx(G.NotificationBell,{})}),!A&&a&&s.jsx(xt,{}),!A&&c&&s.jsxs(e.DropdownMenu,{children:[s.jsx(e.DropdownMenuTrigger,{asChild:!0,children:s.jsx(e.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:s.jsx(e.EllipsisVertical,{className:"h-3.5 w-3.5"})})}),s.jsxs(e.DropdownMenuContent,{align:"end",className:"w-56 rounded-[6px] border border-border/60 p-1 shadow-sm",children:[s.jsx(e.DropdownMenuLabel,{children:"Reports"}),s.jsxs(e.DropdownMenuItem,{disabled:p,onSelect:()=>Ve(!0),children:[s.jsx(e.Download,{className:"h-3.5 w-3.5"}),"Export"]}),s.jsxs(e.DropdownMenuItem,{disabled:!J,onSelect:()=>{J&&R(!0)},children:[s.jsx(e.Clock,{className:"h-3.5 w-3.5"}),"Schedule"]}),s.jsx(e.DropdownMenuSeparator,{}),Rs&&s.jsxs(s.Fragment,{children:[s.jsx(e.DropdownMenuLabel,{children:"Access"}),s.jsxs(e.DropdownMenuItem,{onClick:()=>_(!0),children:[s.jsx(e.Users,{className:"h-3.5 w-3.5"}),"Manage Groups"]}),s.jsx(e.DropdownMenuSeparator,{})]}),s.jsx(e.DropdownMenuLabel,{children:"Preferences"}),s.jsxs(e.DropdownMenuItem,{onClick:()=>v(!0),children:[s.jsx(e.Calendar,{className:"h-3.5 w-3.5"}),"Calendar Preferences"]}),s.jsxs(e.DropdownMenuItem,{onClick:()=>k(!0),children:[s.jsx(e.FileText,{className:"h-3.5 w-3.5"}),"Summary Settings"]}),a&&c&&s.jsxs(s.Fragment,{children:[s.jsx(e.DropdownMenuSeparator,{}),s.jsx(e.DropdownMenuLabel,{children:"Developer"}),s.jsxs(e.DropdownMenuItem,{onSelect:()=>{var l;t!=null&&t.accessToken&&((l=navigator==null?void 0:navigator.clipboard)!=null&&l.writeText?navigator.clipboard.writeText(t.accessToken).then(()=>e.ue.success("Token copied to clipboard")).catch(()=>e.ue.error("Unable to copy token")):e.ue.error("Clipboard not available"))},children:[s.jsx(e.Copy,{className:"h-3.5 w-3.5"}),"Copy token"]}),j&&s.jsxs(e.DropdownMenuItem,{disabled:!Le,onSelect:()=>{var l;if(!Le){e.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(()=>e.ue.success("Local document PDF URL copied to clipboard")).catch(()=>e.ue.error("Unable to copy local document PDF URL")):e.ue.error("Clipboard not available")},children:[s.jsx(e.Copy,{className:"h-3.5 w-3.5"}),"Copy local document PDF URL"]}),s.jsxs(e.DropdownMenuItem,{onSelect:()=>e.invalidateToken(n.apiServiceUrl),children:[s.jsx(ut,{className:"h-3.5 w-3.5"}),"Invalidate token"]}),C&&s.jsxs(e.DropdownMenuItem,{onSelect:()=>Ze(!We),children:[s.jsx(rt.Braces,{className:"h-3.5 w-3.5"}),We?"Hide dashboard JSON":"Show dashboard JSON"]}),W&&C&&s.jsxs(e.DropdownMenuItem,{onSelect:()=>V(!0),children:[s.jsx(e.Plus,{className:"h-3.5 w-3.5"}),"Add lens"]}),W&&s.jsxs(e.DropdownMenuSub,{children:[s.jsxs(e.DropdownMenuSubTrigger,{children:[s.jsx(it,{className:"h-3.5 w-3.5"}),"Lenses"]}),s.jsx(e.DropdownMenuSubContent,{className:"w-60",children:s.jsx(St,{})})]})]})]})]}),F&&ss&&s.jsx(e.ShareDialog,{resource:ss,resourceType:e.ResourceType.DASHBOARD,onClose:()=>P(!1)}),s.jsx(zt,{open:D,onOpenChange:_}),J&&(o==null?void 0:o.id)&&s.jsx(e.EmailScheduleDialog,{open:$,onOpenChange:R,dashboardId:o.id,dashboardName:o==null?void 0:o.title}),s.jsx(xs.CalendarPreferencesDialog,{open:je,onOpenChange:v}),s.jsx(xs.DashboardSummarySettingsDialog,{open:E,onOpenChange:k,dashboard:o,disabled:!C,onApply:l=>Ae({...o,summary:l},{semanticExecutionPayload:Oe})}),a&&W&&c&&s.jsx(yt,{open:q,onOpenChange:V}),c&&s.jsx(e.DownloadPdf,{open:ee,onOpenChange:Ve}),s.jsx(e.AlertDialog,{open:As,onOpenChange:l=>{!l&&Me&&!ae||(te(l),l||(ne(null),re([]),oe(!1)))},children:s.jsxs(e.AlertDialogContent,{className:"max-w-sm",children:[s.jsxs(e.AlertDialogHeader,{children:[s.jsx(e.AlertDialogTitle,{children:ae?"Save failed":"Saving dashboard"}),s.jsx(e.AlertDialogDescription,{className:"pt-2",children:ae?"We could not save the dashboard. Please try again.":"Please wait while we save your changes."}),He.length>0&&s.jsxs("div",{className:"space-y-1 rounded-md border border-destructive/20 bg-destructive/5 p-3 text-left",children:[s.jsx("div",{className:"text-sm font-medium text-destructive",children:"What needs attention"}),s.jsx("ul",{className:"list-disc space-y-1 pl-4 text-xs text-muted-foreground",children:He.slice(0,5).map(l=>s.jsx("li",{children:l},l))})]})]}),s.jsx(e.AlertDialogFooter,{className:"flex-col gap-2 sm:flex-row sm:justify-end",children:ae?s.jsxs(s.Fragment,{children:[s.jsx(e.AlertDialogCancel,{onClick:()=>{te(!1),ne(null),re([]),oe(!1)},className:"m-0",children:"Close"}),s.jsx(e.AlertDialogAction,{onClick:()=>Te({closeAfterSave:Ke,navigateHomeAfterSave:Ee==="home"}),className:"m-0",children:"Retry"})]}):s.jsxs(e.AlertDialogAction,{disabled:!0,className:"m-0 cursor-default",children:[s.jsx(e.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]})})]})}),s.jsx(G.UnsavedChangesAlert,{open:$s,onOpenChange:l=>{K(l)},onSave:Hs,onDiscard:Ks,isSaving:Me,saveLabel:"Save",discardLabel:"Discard"})]})]})}function ea({accessToken:t,dashboardId:n,selectedSheetId:r,pageSize:a,orientation:i,theme:c}){if(!t||!r)return null;const u=new URL("http://localhost:5173/print-document");u.searchParams.set("token",t),n&&u.searchParams.set("dashboardId",n),u.searchParams.set("selectedSheetId",r),c&&u.searchParams.set("theme",c);const d=new URL("http://127.0.0.1:3002/");return d.searchParams.set("pdfMode","document"),d.searchParams.set("pageSize",a||"letter"),d.searchParams.set("orientation",i||"portrait"),d.searchParams.set("url",u.toString()),d.toString()}exports.default=Zt;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";const v=require("react"),e=require("./index-Dbrs96G8.js"),t=require("react/jsx-runtime"),I=require("./use-create-flow-overlay-state-BMD3YRzU.js"),z=require("./use-visual-utils-dOYWf6nM.js"),M=require("./date-formatter-CqXdM6JO.js");/**
|
|
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 U=e.createLucideIcon("FileDown",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M12 18v-6",key:"17g6i2"}],["path",{d:"m9 15 3 3 3-3",key:"1npd3o"}]]);/**
|
|
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 H=e.createLucideIcon("FilterX",[["path",{d:"M13.013 3H2l8 9.46V19l4 2v-8.54l.9-1.055",key:"1fi1da"}],["path",{d:"m22 3-5 5",key:"12jva0"}],["path",{d:"m17 3 5 5",key:"k36vhe"}]]),$=1e4,_=15e3,q=3e4,X=3e4,G=12e4,V=2*60*60*1e3;function K(s){const r=Date.now()-s.getTime();return r<X?$:r<G?_:q}function Q(){const{authToken:s,tokenProps:r}=e.useSemaphorContext(),f=e.useExportStore(p=>p.activeExports),[l,n]=v.useState(typeof document<"u"?!document.hidden:!0),c=v.useRef(null),d=v.useRef(!1),u=v.useRef(void 0),i=r==null?void 0:r.apiServiceUrl,a=s==null?void 0:s.accessToken,h=v.useCallback(()=>{const p=e.useExportStore.getState().activeExports;return Array.from(p.values()).filter(w=>e.isExportInProgress(w.status))},[]);v.useEffect(()=>{if(typeof document>"u")return;const p=()=>{n(!document.hidden)};return document.addEventListener("visibilitychange",p),()=>{document.removeEventListener("visibilitychange",p)}},[]);const b=v.useCallback(async()=>{if(!i||!a){d.current=!1;return}const p=h();if(p.length===0){d.current=!1;return}const w=Date.now(),E=p.filter(o=>w-o.startedAt.getTime()>V);if(E.length>0){const{updateExport:o}=e.useExportStore.getState().actions;for(const C of E)o(C.id,{status:"failed",error:"Export timed out. Please try again or contact support.",lastUpdatedAt:new Date})}const x=p.filter(o=>w-o.startedAt.getTime()<=V);if(x.length===0){d.current=!1;return}const y=await Promise.allSettled(x.map(async o=>{try{const C=await e.getExportStatus(i,a,o.id);let S;if(C.status==="completed")try{S=await e.getDownloadUrl(i,a,o.id)}catch(F){console.error(`[useExportPolling] Failed to get download URL for ${o.id}:`,F)}return{id:o.id,status:C.status,progress:C.progress,completedChunks:C.completedChunks,completedAt:C.completedAt?new Date(C.completedAt):void 0,lastUpdatedAt:new Date,fileSize:C.fileSize,error:C.error,downloadUrl:S}}catch(C){return console.error(`[useExportPolling] Failed to poll export ${o.id}:`,C),null}})),{updateExport:N}=e.useExportStore.getState().actions;for(const o of y)o.status==="fulfilled"&&o.value&&N(o.value.id,o.value);const j=h();if(j.length>0&&!document.hidden){const o=j.reduce((S,F)=>F.startedAt<S?F.startedAt:S,j[0].startedAt),C=K(o);c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{var S;(S=u.current)==null||S.call(u)},C)}else d.current=!1},[i,a,h]);return v.useEffect(()=>{u.current=b},[b]),v.useEffect(()=>{var w;h().length>0&&l&&!d.current&&(d.current=!0,(w=u.current)==null||w.call(u))},[f,l,h]),v.useEffect(()=>{var w;const p=h();l&&p.length>0&&!d.current&&(d.current=!0,(w=u.current)==null||w.call(u))},[l,h]),v.useEffect(()=>{!l&&c.current&&(clearTimeout(c.current),c.current=null,d.current=!1)},[l]),v.useEffect(()=>()=>{c.current&&(clearTimeout(c.current),c.current=null)},[]),{isPolling:d.current,isTabVisible:l,inProgressCount:h().length}}function W(){const{authToken:s,tokenProps:r}=e.useSemaphorContext(),f=e.useExportStore(u=>u.activeExports),{addExport:l}=e.useExportActions(),n=v.useRef(!1),c=r==null?void 0:r.apiServiceUrl,d=s==null?void 0:s.accessToken;v.useEffect(()=>{if(n.current||!c||!d)return;(async()=>{try{const{exports:i}=await e.getExports(c,d,{status:["pending","processing","chunking","compacting","completed","failed"],limit:20});for(const a of i){if(f.has(a.id))continue;const h=a.totalChunks?Math.round(a.completedChunks/a.totalChunks*100):0;let b;if(a.status==="completed")try{b=await e.getDownloadUrl(c,d,a.id)}catch(w){console.error(`[useExportRecovery] Failed to get download URL for ${a.id}:`,w)}const p={id:a.id,status:a.status,progress:h,title:Y(a),totalRows:a.totalRows,totalChunks:a.totalChunks,completedChunks:a.completedChunks,startedAt:new Date(a.createdAt),lastUpdatedAt:new Date,completedAt:a.completedAt?new Date(a.completedAt):void 0,fileSize:a.fileSize,error:a.error,expiresAt:new Date(a.expiresAt),downloadUrl:b};l(p)}n.current=!0}catch(i){console.error("[useExportRecovery] Failed to recover exports:",i),n.current=!0}})()},[c,d,l,f])}function Y(s){return s.title?s.title:e.isExportInProgress(s.status)?"Export in progress...":s.status==="completed"?"Export completed":s.status==="failed"?"Export failed":"Export"}function Z({open:s,onOpenChange:r,isLibraryVisual:f,currentVisualName:l,isSaving:n=!1,destinationMode:c="both",onConfirm:d}){const[u,i]=v.useState(f&&l?`Copy of ${l}`:l||""),[a,h]=v.useState("");v.useEffect(()=>{s&&(i(f&&l?`Copy of ${l}`:l||""),h(""))},[s,f,l]);const b=!!u.trim(),p=c==="local"?{saveToLibrary:!1,saveToCurrentDashboard:!0,badgeType:"local",description:"Creates a local copy on the current dashboard.",actionLabel:"Add to Dashboard (Local)"}:c==="library"?{saveToLibrary:!0,saveToCurrentDashboard:!1,badgeType:"library",description:"Creates a reusable visual in Visual Library.",actionLabel:"Save as Library Visual"}:{saveToLibrary:!0,saveToCurrentDashboard:!0,badgeType:"linked",description:"Creates a new library visual and adds a linked copy to this dashboard.",actionLabel:"Save Copy as Linked Visual"},w=()=>{!b||n||d({name:u.trim(),description:a.trim()||void 0,saveToLibrary:p.saveToLibrary,saveToCurrentDashboard:p.saveToCurrentDashboard})};return t.jsx(e.Dialog,{open:s,onOpenChange:r,children:t.jsxs(e.DialogContent,{className:"sm:max-w-[500px]",children:[t.jsxs(e.DialogHeader,{children:[t.jsxs(e.DialogTitle,{className:"flex items-center gap-2",children:[t.jsx("span",{children:"Save Visual As"}),p.badgeType!=="local"&&t.jsx(I.VisualBadge,{type:p.badgeType,showLabel:!0,className:"px-2 py-0.5"})]}),t.jsx(e.DialogDescription,{children:p.description})]}),t.jsxs("div",{className:"grid gap-4 py-4",children:[t.jsxs("div",{className:"grid gap-2",children:[t.jsx(e.Label,{htmlFor:"name",children:"Name"}),t.jsx(e.Input,{id:"name",value:u,onChange:E=>i(E.target.value),placeholder:"Enter visual name",disabled:n})]}),t.jsxs("div",{className:"grid gap-2",children:[t.jsx(e.Label,{htmlFor:"description",children:"Description (optional)"}),t.jsx(e.Textarea,{id:"description",value:a,onChange:E=>h(E.target.value),placeholder:"Enter visual description",rows:3,disabled:n})]})]}),t.jsxs(e.DialogFooter,{children:[t.jsx(e.Button,{variant:"outline",onClick:()=>r(!1),disabled:n,children:"Cancel"}),t.jsxs(e.Button,{onClick:w,disabled:!b||n,children:[n&&t.jsx(e.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),p.actionLabel]})]})]})})}function J(){const[s,r]=v.useState(!1),[f,l]=v.useState(!1),[n,c]=v.useState(null),[d,u]=v.useState(null),i=e.useEditorStore(m=>m.frame),a=e.useEditorStore(m=>m.card),h=e.useSelectedVisual(),b=e.useDashboardStore(m=>m.selectedSheetId),p=e.useDashboardStore(m=>m.dashboard),w=e.useDashboardStore(m=>m.actions.setIsDashboardPanelOpen),{getUpdatedFrame:E}=z.useVisualUtils(),{selectVisual:x}=e.useManagementActions(),{addFrame:y,setSelectedFrameId:N,setIsVisualEditing:j}=e.useDashboardActions(),o=e.useResolveExistingFrameSemanticExecutionPayload(),C=!!(i!=null&&i.visualId),S=(()=>{var m,g;return((m=i==null?void 0:i.cards)==null?void 0:m.length)===1&&((g=i.cards[0])!=null&&g.title)?i.cards[0].title:h!=null&&h.title?h.title:(a==null?void 0:a.title)||"Untitled Visual"})(),F=e.useCreateVisualWithFrame(m=>{m!=null&&m.id&&(x(m),f&&n&&d&&b&&(async()=>{try{const g={...n,id:e.v4(),visualId:m.id};y(b,g,{position:"end",semanticExecutionPayload:d}),N(g.id),l(!1),c(null),u(null),j(!1)}catch(g){console.error("Failed to promote semantic metadata for saved visual:",g),e.ue.error(g instanceof Error?g.message:"Failed to prepare semantic metadata for the saved visual")}})(),w(!0),r(!1))});return{saveAsDialogOpen:s,setSaveAsDialogOpen:r,handleSaveAs:async m=>{if(!b){e.ue.error("No sheet selected");return}const g=E(),A=e.getDynamicFrameSaveIssue(g);if(A){e.ue.error(A);return}const T=g.cards.length===1?{...g,cards:g.cards.map(L=>({...L,title:m.name}))}:g;if(m.saveToLibrary){let L=null;if(m.saveToCurrentDashboard)try{L=await o(T,{previousFrame:e.findDashboardFrameById(p,T.id)})}catch(P){console.error("Failed to prepare semantic metadata before saving visual:",P),e.ue.error(P instanceof Error?P.message:"Failed to prepare semantic metadata for the saved visual");return}l(m.saveToCurrentDashboard),c(T),u(L);const B={title:m.name,description:m.description,frameObject:T,isPrivate:!1};F.mutate(B)}else if(m.saveToCurrentDashboard){const L={...T,id:e.v4(),visualId:void 0};try{const B=await o(T,{previousFrame:e.findDashboardFrameById(p,T.id)});y(b,L,{position:"end",semanticExecutionPayload:B}),N(L.id),e.ue.success("Visual saved to dashboard"),r(!1),j(!1)}catch(B){console.error("Failed to save visual to dashboard:",B),e.ue.error(B instanceof Error?B.message:"Failed to prepare semantic metadata for the visual")}}},isLibraryVisual:C,currentVisualName:S,isSaving:F.isPending}}function ee(s={}){const r=e.useEditorStore(D=>D.frame),f=e.useEditorStore(D=>D.editorContext),l=e.useManagementStore(D=>D.selectedVisual),n=e.useDashboardStore(D=>D.selectedFrameId),c=e.useDashboardStore(D=>D.selectedSheetId),d=e.useDashboardStore(D=>D.dashboard),{setIsVisualEditing:u,updateFrame:i}=e.useDashboardActions(),[a,h]=v.useState(!1),[b,p]=v.useState("both"),w=e.useResolveExistingFrameSemanticExecutionPayload(),E=(f==null?void 0:f.type)==="documentSection",x=!!(r!=null&&r.visualId||l!=null&&l.id),y=!!(r!=null&&r.visualId&&n),N=x&&!y,{saveAsDialogOpen:j,setSaveAsDialogOpen:o,handleSaveAs:C,isLibraryVisual:S,currentVisualName:F,isSaving:k}=J(),{getUpdatedFrame:m}=z.useVisualUtils();if(E)return t.jsxs(t.Fragment,{children:[t.jsx(I.EditorAcceptButton,{className:"rounded-[5px]",variant:"default"}),t.jsx(I.EditorCancelButton,{})]});const g=async()=>{if(!c){e.ue.error("No sheet selected");return}if(a)return;h(!0);const D=m(),T=e.getDynamicFrameSaveIssue(D);if(T){h(!1),e.ue.error(T);return}const L={...D,visualId:void 0},B=e.findDashboardFrameById(d,L.id);try{const P=await w(L,{previousFrame:B});i(c,L,{semanticExecutionPayload:P})}catch(P){console.error("Failed to apply local semantic metadata:",P),h(!1),e.ue.error(P instanceof Error?P.message:"Failed to prepare semantic metadata for this visual");return}setTimeout(()=>{h(!1),e.ue.success("Changes applied. Visual is now local to this dashboard"),u(!1)},300)},A=D=>{p(D),o(!0)};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"inline-flex items-center overflow-hidden rounded-[5px]",children:[!x&&t.jsx(I.EditorAcceptButton,{className:"rounded-none",variant:"default"}),x&&N&&t.jsx(I.VisualSaveButton,{className:"rounded-none",variant:"default"}),x&&y&&t.jsx(I.VisualSaveAndApplyButton,{className:"rounded-none"}),t.jsxs(e.DropdownMenu,{modal:!1,children:[t.jsx(e.DropdownMenuTrigger,{asChild:!0,children:t.jsx(e.Button,{variant:"default",size:"xs",className:"w-7 rounded-none border-l border-primary-foreground/20 px-0","aria-label":"Open visual save options",disabled:k||a,children:t.jsx(e.ChevronDown,{className:"h-3.5 w-3.5"})})}),t.jsxs(e.DropdownMenuContent,{align:"end",className:"min-w-[220px] rounded-[6px] border border-border/60 p-1 shadow-sm",children:[y&&t.jsxs(t.Fragment,{children:[t.jsxs(e.DropdownMenuItem,{onClick:g,disabled:a,children:[t.jsx(e.Check,{className:"h-3.5 w-3.5"}),a?"Applying...":"Apply Locally"]}),t.jsx(e.DropdownMenuSeparator,{})]}),t.jsxs(e.DropdownMenuItem,{onClick:()=>A("local"),disabled:k,children:[t.jsx(e.Plus,{className:"h-3.5 w-3.5"}),"Add to Dashboard (Local)"]}),t.jsxs(e.DropdownMenuItem,{onClick:()=>A("library"),disabled:k,children:[t.jsx(I.Library,{className:"h-3.5 w-3.5"}),"Save as Library Visual"]}),t.jsxs(e.DropdownMenuItem,{onClick:()=>A("both"),disabled:k,children:[t.jsx(I.Link2,{className:"h-3.5 w-3.5"}),"Save Copy as Linked Visual"]})]})]})]}),t.jsx(I.EditorCancelButton,{}),t.jsx(Z,{open:j,onOpenChange:D=>{k||o(D)},isLibraryVisual:S,currentVisualName:F,isSaving:k,destinationMode:b,onConfirm:C})]})}function te({className:s}){const r=e.useEditorStore(i=>i.isDevMode),f=e.useDashboardStore(i=>i.isVisualEditing),{setIsDevMode:l}=e.useEditorActions(),{config:n}=v.useContext(e.SemaphorContext).tokenProps,c=(n==null?void 0:n.showAdvancedMode)!==!1;if(!f||!c)return null;const d="h-full rounded-none border-0 bg-transparent px-2.5 shadow-none text-muted-foreground hover:bg-accent/50 hover:text-foreground",u="bg-muted text-foreground hover:bg-muted";return t.jsxs("div",{role:"radiogroup","aria-label":"Editor mode",className:e.cn("inline-flex h-7 items-stretch overflow-hidden rounded-[5px] border border-input bg-background",s),children:[t.jsxs(e.Button,{type:"button",variant:"ghost",size:"xs",role:"radio","aria-checked":!r,className:e.cn(d,!r&&u),onClick:()=>l(!1),children:[t.jsx(e.SlidersHorizontal,{className:"h-3.5 w-3.5"}),"Drag & drop"]}),t.jsxs(e.Button,{type:"button",variant:"ghost",size:"xs",role:"radio","aria-checked":r,className:e.cn(d,"border-l border-border/60",r&&u),onClick:()=>l(!0),children:[t.jsx(e.CodeXml,{className:"h-3.5 w-3.5"}),"SQL"]})]})}function se({open:s,onOpenChange:r,onSave:f,onDiscard:l,isSaving:n,title:c="Unsaved changes",description:d="You have unsaved changes to this dashboard. What would you like to do?",cancelLabel:u="Cancel",discardLabel:i="Discard",saveLabel:a="Save"}){const h=b=>{!b&&n||r(b)};return t.jsx(e.AlertDialog,{open:s,onOpenChange:h,children:t.jsxs(e.AlertDialogContent,{children:[t.jsxs(e.AlertDialogHeader,{children:[t.jsx(e.AlertDialogTitle,{children:c}),t.jsx(e.AlertDialogDescription,{children:d})]}),t.jsxs(e.AlertDialogFooter,{children:[t.jsx(e.Button,{type:"button",size:"xs",onClick:l,disabled:n,variant:"ghost",className:"mr-auto text-muted-foreground hover:bg-destructive/10 hover:text-destructive focus-visible:bg-destructive/10 focus-visible:text-destructive",children:i}),t.jsx(e.AlertDialogCancel,{disabled:n,children:u}),t.jsx(e.Button,{type:"button",size:"xs",onClick:f,disabled:n,children:n?t.jsxs(t.Fragment,{children:[t.jsx(e.LoaderCircle,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),"Saving..."]}):a})]})]})})}function O({export:s,onRemove:r}){const f=()=>{s.downloadUrl&&window.open(s.downloadUrl,"_blank")},l=u=>{u.stopPropagation(),r==null||r(s.id)},n=()=>{switch(s.status){case"completed":return t.jsx(e.CircleCheck,{className:"mt-0.5 h-5 w-5 shrink-0 text-green-600"});case"failed":return t.jsx(I.CircleX,{className:"mt-0.5 h-5 w-5 shrink-0 text-destructive"});default:return t.jsx(e.LoaderCircle,{className:"text-foreground-muted mt-0.5 h-5 w-5 shrink-0 animate-spin"})}},c=e.isExportInProgress(s.status),d=(()=>{switch(s.status){case"pending":return"Queued...";case"processing":return"Processing...";case"chunking":return"Processing...";case"compacting":return"Finalizing...";default:return"Processing..."}})();return t.jsxs("div",{className:"group p-4 transition-colors hover:bg-muted/50",children:[t.jsxs("div",{className:"mb-2 flex items-start justify-between gap-3",children:[t.jsxs("div",{className:"flex min-w-0 flex-1 items-start gap-3",children:[n(),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("h4",{className:"mb-1 truncate text-sm font-medium",children:s.title}),s.status==="completed"&&t.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[t.jsxs("span",{children:[s.totalRows.toLocaleString()," rows"]}),s.fileSize&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:"•"}),t.jsx("span",{children:e.formatFileSize(s.fileSize)})]})]}),c&&t.jsx("div",{className:"text-xs text-muted-foreground",children:d}),s.status==="failed"&&t.jsx("div",{className:"line-clamp-2 text-xs text-destructive",children:s.error||"Export failed"})]})]}),t.jsx(e.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0 opacity-0 transition-opacity group-hover:opacity-100",onClick:l,"aria-label":"Remove notification",children:t.jsx(e.X,{className:"h-4 w-4"})})]}),t.jsxs("div",{className:"ml-8",children:[s.status==="completed"&&t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("span",{className:"text-xs text-muted-foreground",children:M.formatDistanceToNow(s.startedAt,{addSuffix:!0})}),s.downloadUrl&&t.jsxs(e.Button,{size:"sm",variant:"outline",className:"h-8 bg-transparent",onClick:f,children:[t.jsx(e.Download,{className:"mr-1.5 h-3.5 w-3.5"}),"Download"]})]}),c&&t.jsxs("div",{children:[t.jsx(e.Progress,{value:s.progress,className:"h-1.5"}),t.jsxs("span",{className:"mt-1 block text-xs text-muted-foreground",children:[s.progress,"% complete"]})]}),s.status==="failed"&&t.jsx("span",{className:"text-xs text-muted-foreground",children:M.formatDistanceToNow(s.startedAt,{addSuffix:!0})})]})]})}function R(){const{authToken:s,tokenProps:r}=e.useSemaphorContext(),f=e.useExportStore(x=>x.activeExports),{clearCompleted:l,removeExport:n,updateExport:c}=e.useExportActions(),[d,u]=v.useState(!1),[i,a]=v.useState(!1),h=Array.from(f.values()).sort((x,y)=>y.startedAt.getTime()-x.startedAt.getTime()),b=h.some(x=>x.status==="completed"||x.status==="failed"),p=v.useCallback(async()=>{const x=r==null?void 0:r.apiServiceUrl,y=s==null?void 0:s.accessToken;if(!(!x||!y)){u(!0);try{const N=Array.from(f.values());await Promise.all(N.map(async j=>{try{const o=await e.getExportStatus(x,y,j.id);let C;if(o.status==="completed")try{C=await e.getDownloadUrl(x,y,j.id)}catch(S){console.error(`Failed to get download URL for ${j.id}:`,S)}c(j.id,{status:o.status,progress:o.progress,completedChunks:o.completedChunks,completedAt:o.completedAt?new Date(o.completedAt):void 0,lastUpdatedAt:new Date,fileSize:o.fileSize,error:o.error,downloadUrl:C})}catch(o){console.error(`Failed to refresh export ${j.id}:`,o)}}))}finally{u(!1)}}},[f,s==null?void 0:s.accessToken,r==null?void 0:r.apiServiceUrl,c]),w=v.useCallback(async()=>{const x=r==null?void 0:r.apiServiceUrl,y=s==null?void 0:s.accessToken;if(!x||!y){l();return}a(!0);try{const N=h.filter(o=>o.status==="completed"||o.status==="failed"),j=await Promise.allSettled(N.map(async o=>(await e.cancelExport(x,y,o.id),o.id)));for(const o of j)o.status==="fulfilled"?n(o.value):console.error("Failed to delete export:",o.reason)}finally{a(!1)}},[h,r==null?void 0:r.apiServiceUrl,s==null?void 0:s.accessToken,l,n]),E=v.useCallback(async x=>{const y=r==null?void 0:r.apiServiceUrl,N=s==null?void 0:s.accessToken;if(y&&N)try{await e.cancelExport(y,N,x),n(x);return}catch(j){console.error(`Failed to cancel export ${x}:`,j)}n(x)},[r==null?void 0:r.apiServiceUrl,s==null?void 0:s.accessToken,n]);return h.length===0?t.jsxs("div",{className:"p-6 text-center",children:[t.jsx(U,{className:"mx-auto mb-2 h-8 w-8 text-muted-foreground"}),t.jsx("p",{className:"text-sm text-muted-foreground",children:"No active exports"}),t.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Large exports will appear here"})]}):t.jsxs("div",{className:"flex flex-col",children:[t.jsxs("div",{className:"flex items-center justify-between border-b px-4 py-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(U,{className:"h-5 w-5 text-muted-foreground"}),t.jsx("h4",{className:"font-semibold",children:"Exports"})]}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(e.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:p,disabled:d,title:"Refresh status",children:t.jsx(e.RefreshCw,{className:`h-4 w-4 ${d?"animate-spin":""}`})}),b&&t.jsx(e.Button,{variant:"ghost",size:"sm",className:"h-7 px-2 text-sm",onClick:w,disabled:i,children:i?"Clearing...":"Clear all"})]})]}),t.jsx("div",{className:"max-h-[350px] overflow-y-auto",children:t.jsx("div",{className:"divide-y",children:h.map(x=>t.jsx(O,{export:x,onRemove:E},x.id))})})]})}function re({variant:s}){const r=e.useExportStore(i=>i.activeExports),f=e.useInProgressExportsCount(),l=r.size>0,n=Array.from(r.values()).some(i=>i.status==="completed"||i.status==="failed"),d=f>0?f>9?"9+":String(f):null,u=l;return t.jsxs(e.Popover,{children:[t.jsx(e.PopoverTrigger,{asChild:!0,children:t.jsxs(e.Button,{variant:s??"ghost",size:"xs",className:"relative w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":"Export notifications",children:[t.jsx(e.Bell,{className:"h-3.5 w-3.5"}),u&&t.jsx("span",{className:`absolute flex items-center justify-center rounded-full bg-primary text-primary-foreground ${d?"-right-0.5 -top-0.5 h-3.5 min-w-3.5 px-0.5 text-[9px] font-semibold":"right-1 top-1 h-1.5 w-1.5"}`,children:d})]})}),t.jsx(e.PopoverContent,{className:"w-80 p-0",align:"end",sideOffset:8,children:t.jsx(R,{})})]})}function ae(s){if(s)return{renamed:s.type==="rename"?{oldId:s.oldId,newId:s.newId}:void 0,removedControlId:s.type==="remove"?s.controlId:void 0,cardBindingsById:s.type==="add"||s.type==="update"?s.cardBindingsById:void 0,affectedBindingControlIds:s.type==="add"||s.type==="update"?s.affectedBindingControlIds:void 0}}function oe({open:s,onOpenChange:r,trigger:f,showTrigger:l=!0,initialMode:n="manage"}){const c=n==="create",{forceClose:d,handleOpenChange:u,isCreateFlowActive:i,preventPassiveDismissDuringCreate:a,resolvedOpen:h,setIsCreateFlowActive:b}=I.useCreateFlowOverlayState({open:s,onOpenChange:r,initialCreateFlowActive:n==="create",dismissMode:l?"passive":"explicit-only"}),p=e.useDashboardStore(m=>m.dashboard),{setDashboardControlsModel:w}=e.useDashboardActions(),{participants:E}=e.useDashboardStructuralParticipants(e.getDashboardCards(p)),x=Array.from(new Map(E.flatMap(m=>m.fieldChoices.map(g=>{var A;return[g.value,{option:g,target:(A=m.fieldTargetMap)==null?void 0:A[g.value]}]}))).values()),y=Array.from(new Map(E.flatMap(m=>m.metricChoices.map(g=>{var A;return[g.value,{option:g,target:(A=m.metricTargetMap)==null?void 0:A[g.value]}]}))).values()),N=e.collectDashboardControlIds({...p||{},controls:[]}),j=e.buildDashboardStructuralParticipantIdsByControlId(p),o=(m,g,A)=>{w(m,g,ae(A))},C=v.useCallback(()=>{if(c){d();return}b(!1)},[c,d,b]),S=t.jsx(I.ControlDefinitionListEditor,{scope:"dashboard",controls:p.controls||[],reservedControlIds:N,defaultValues:p.defaultControlValues||{},usageByControlId:e.buildDashboardControlUsageById(p),availableFieldChoices:x,availableMetricChoices:y,structuralParticipants:E,structuralParticipantIdsByControlId:j,initialCreateFlow:n==="create",onCreateFlowActiveChange:b,onCreateFlowComplete:C,onChange:o,emptyMessage:"No dashboard controls yet."}),F=i?"Add dashboard control":"Dashboard Controls",k=t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx("h4",{className:"text-sm font-medium",children:"Dashboard Controls"}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"Add shared controls viewers can use across the dashboard. Each card can decide how to respond to the same control."})]}),S]});return l?t.jsxs(e.Popover,{open:h,onOpenChange:u,children:[t.jsx(e.PopoverTrigger,{asChild:!0,children:f||t.jsxs(e.Button,{variant:"outline",className:"h-7 px-2",size:"sm",children:[t.jsx(e.SlidersHorizontal,{className:"mr-2 h-4 w-4"}),"Controls"]})}),t.jsx(e.PopoverContent,{className:"w-[620px] max-w-[95vw] space-y-4",align:"end",onEscapeKeyDown:a,onPointerDownOutside:a,children:k})]}):t.jsx(e.Dialog,{open:h,onOpenChange:u,children:t.jsxs(e.DialogContent,{className:"flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",onEscapeKeyDown:a,onPointerDownOutside:a,children:[t.jsxs(e.DialogHeader,{className:i?"space-y-0":void 0,children:[t.jsx(e.DialogTitle,{className:"text-[15px]",children:F}),t.jsx(e.DialogDescription,{className:i?"sr-only":"text-[13px]",children:i?"Configure and add a shared dashboard control.":"Add shared controls viewers can use across the dashboard. Each card can decide how to respond to the same control."})]}),t.jsx("div",{className:"min-h-0 overflow-y-auto pr-1",children:S})]})})}function ne({showFilters:s,onToggleFilters:r,onAddFilter:f,onAddControl:l,onManageControls:n,size:c="default",className:d,primaryButtonClassName:u,secondaryButtonClassName:i,dropdownContentClassName:a}){const h=c==="toolbar";return t.jsxs("div",{className:e.cn("relative inline-flex items-stretch overflow-hidden rounded-[5px] border border-input bg-background",h?"h-8":"h-7",d),children:[t.jsxs(e.Button,{variant:"ghost",size:"xs",className:e.cn("h-full rounded-none border-0 bg-transparent pl-2.5 pr-2 shadow-none hover:bg-accent/50",u),onClick:r,children:[s?t.jsx(H,{className:"h-3.5 w-3.5"}):t.jsx(e.Filter,{className:"h-3.5 w-3.5"}),"Filter"]}),t.jsxs(e.DropdownMenu,{children:[t.jsx(e.DropdownMenuTrigger,{asChild:!0,children:t.jsx(e.Button,{variant:"ghost",size:"xs",className:e.cn("h-full w-7 rounded-none border-0 border-l border-border/60 bg-transparent px-0 shadow-none hover:bg-accent/50",i),"aria-label":"Filter and control actions",children:t.jsx(e.ChevronDown,{className:"h-3.5 w-3.5"})})}),t.jsxs(e.DropdownMenuContent,{align:"start",className:e.cn("min-w-[180px] rounded-[6px] border border-border/60 p-1 shadow-sm",a),children:[t.jsxs(e.DropdownMenuItem,{onSelect:f,children:[t.jsx(e.Filter,{className:"h-3.5 w-3.5"}),"Add filter"]}),t.jsxs(e.DropdownMenuItem,{onSelect:l,children:[t.jsx(e.SlidersHorizontal,{className:"h-3.5 w-3.5"}),"Add control"]}),t.jsxs(e.DropdownMenuItem,{onSelect:n,children:[t.jsx(e.Pencil,{className:"h-3.5 w-3.5"}),"Manage controls"]})]})]})]})}exports.AdvancedModeToggle=te;exports.DashboardControlsSettings=oe;exports.DashboardFilterControlsButton=ne;exports.ExportNotificationItem=O;exports.ExportNotificationList=R;exports.NotificationBell=re;exports.UnsavedChangesAlert=se;exports.VisualEditingControls=ee;exports.useExportPolling=Q;exports.useExportRecovery=W;
|