react-semaphor 0.1.434 → 0.1.436
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{dashboard-yWFfL8DR.js → dashboard-DB97Qehi.js} +15660 -15642
- package/dist/chunks/{dashboard-briefing-launcher-Btxf_WwP.js → dashboard-briefing-launcher-BBUSizLQ.js} +752 -740
- package/dist/chunks/dashboard-briefing-launcher-C8_pyleA.js +31 -0
- package/dist/chunks/dashboard-controls-D8ob37pk.js +36 -0
- package/dist/chunks/{dashboard-controls-QDvheX2S.js → dashboard-controls-c1BKqObc.js} +883 -873
- package/dist/chunks/{dashboard-json-Cy30BkTb.js → dashboard-json-5z_cenUT.js} +1 -1
- package/dist/chunks/{dashboard-json-Cjeju9_w.js → dashboard-json-CkTVRqge.js} +1 -1
- package/dist/chunks/{dashboard-czW777OP.js → dashboard-nvGHASLa.js} +187 -187
- package/dist/chunks/{edit-dashboard-visual-B9K3RbmG.js → edit-dashboard-visual-MCDuE3GS.js} +2 -2
- package/dist/chunks/{edit-dashboard-visual-CZ_VwF0R.js → edit-dashboard-visual-q4YYssFo.js} +1 -1
- package/dist/chunks/{report-preferences-dialog-DQoLS75q.js → report-preferences-dialog-CZhv1HKW.js} +1 -1
- package/dist/chunks/{report-preferences-dialog-CLVxbcNw.js → report-preferences-dialog-DGbUoySN.js} +1 -1
- package/dist/chunks/{use-create-flow-overlay-state-C7q1RJRX.js → use-create-flow-overlay-state-CK3794Xa.js} +1 -1
- package/dist/chunks/{use-create-flow-overlay-state-DDW51h9w.js → use-create-flow-overlay-state-i0V_ZEiS.js} +1 -1
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/data-app-builder/index.cjs +1 -1
- package/dist/data-app-builder/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +4 -4
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +2 -2
- package/dist/types/dashboard.d.ts +2 -0
- package/dist/types/main.d.ts +2 -0
- package/dist/types/surfboard.d.ts +2 -0
- package/dist/types/types.d.ts +2 -0
- package/package.json +1 -1
- package/dist/chunks/dashboard-briefing-launcher-BFbnlzAS.js +0 -31
- package/dist/chunks/dashboard-controls-B1EJzIqs.js +0 -36
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";const e=require("react/jsx-runtime"),p=require("react"),s=require("./dashboard-nvGHASLa.js"),n=require("./code-editor-BSENCZwR.js"),je=require("./layout-grid-B08pP7v6.js"),X=require("./index-jSrCwPQz.js"),U=require("./use-create-flow-overlay-state-CK3794Xa.js");require("./analyze-result-contract-BswhsmWT.js");require("../value-format-preferences/index.cjs");const Re=require("./search-Dcud9ajy.js"),ye=require("./csv-utils-Co0WxHke.js");require("./index-Dpm_VET4.js");require("./comparison-document-migration-DbU_BTxR.js");require("react-dom");const Q=require("../briefings/index.cjs");/**
|
|
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 Ue=X.createLucideIcon("ArrowUpRight",[["path",{d:"M7 7h10v10",key:"1tivn9"}],["path",{d:"M7 17 17 7",key:"1vkiza"}]]);/**
|
|
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 Oe=X.createLucideIcon("CalendarRange",[["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2",key:"1hopcy"}],["path",{d:"M16 2v4",key:"4m81vk"}],["path",{d:"M3 10h18",key:"8toen8"}],["path",{d:"M8 2v4",key:"1cmpym"}],["path",{d:"M17 14h-6",key:"bkmgh3"}],["path",{d:"M13 18H7",key:"bb0bb7"}],["path",{d:"M7 14h.01",key:"1qa3f1"}],["path",{d:"M17 18h.01",key:"1bdyru"}]]);/**
|
|
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 ze=X.createLucideIcon("CircleX",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]);/**
|
|
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 we=X.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"}]]);/**
|
|
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 _e=X.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"}]]);/**
|
|
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 $e=X.createLucideIcon("Newspaper",[["path",{d:"M4 22h16a2 2 0 0 0 2-2V4a2 2 0 0 0-2-2H8a2 2 0 0 0-2 2v16a2 2 0 0 1-2 2Zm0 0a2 2 0 0 1-2-2v-9c0-1.1.9-2 2-2h2",key:"7pis2x"}],["path",{d:"M18 14h-8",key:"sponae"}],["path",{d:"M15 18h-5",key:"95g1m2"}],["path",{d:"M10 6h8v4h-8V6Z",key:"smlsk5"}]]);function qe(){return e.jsx("div",{className:"space-y-1.5 py-1",children:[...Array(5)].map((t,r)=>e.jsxs("div",{className:"flex animate-pulse items-start gap-3 rounded-xl border border-transparent px-2.5 py-2.5",children:[e.jsx("div",{className:"mt-0.5 h-4 w-4 flex-shrink-0 rounded bg-muted/60"}),e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("div",{className:"h-4 w-3/5 rounded bg-muted/60"}),e.jsx("div",{className:"h-3 w-4/5 rounded bg-muted/40"})]})]},r))})}function He({open:t,onOpenChange:r,onSubmit:l,isCreating:o}){const[a,d]=p.useState(""),[h,x]=p.useState("");p.useEffect(()=>{t||(d(""),x(""))},[t]);const c=()=>{a.trim()&&l({title:a,description:h})},u=i=>{r(i)};return e.jsx(s.Dialog,{open:t,onOpenChange:u,children:e.jsxs(s.DialogContent,{showCloseButton:!1,className:"flex max-w-lg grid-cols-none flex-col gap-0 overflow-hidden rounded-[6px] border-border/60 p-0 shadow-lg",children:[e.jsxs("div",{className:"flex h-10 shrink-0 items-center justify-between gap-2 border-b border-border/60 px-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(je.LayoutGrid,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"flex min-w-0 items-baseline gap-2",children:[e.jsx(s.DialogTitle,{className:"truncate text-[13px] font-medium leading-none tracking-normal",children:"New library visual"}),e.jsx("span",{className:"shrink-0 text-[10px] font-medium uppercase leading-none tracking-[0.08em] text-muted-foreground",children:"Visual"})]})]}),e.jsx(n.Button,{size:"xs",variant:"ghost",className:"w-7 px-0 text-muted-foreground hover:text-foreground",onClick:()=>u(!1),"aria-label":"Close",disabled:o,children:e.jsx(X.X,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"space-y-3 px-4 py-3",children:[e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Create a saved visual that can be reused across dashboards."}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(n.Label,{htmlFor:"visual-title",className:"text-[12px]",children:"Name"}),e.jsx(n.Input,{id:"visual-title",size:"sm",placeholder:"Untitled visual",value:a,onChange:i=>d(i.target.value),disabled:o,onKeyDown:i=>{i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),c())}})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(n.Label,{htmlFor:"visual-description",className:"text-[12px]",children:"Description"}),e.jsx(n.Input,{id:"visual-description",size:"sm",placeholder:"Optional",value:h,onChange:i=>x(i.target.value),disabled:o})]})]}),e.jsxs("div",{className:"flex shrink-0 justify-end gap-2 border-t border-border/60 px-4 py-2.5",children:[e.jsx(n.Button,{size:"xs",variant:"outline",onClick:()=>u(!1),disabled:o,children:"Cancel"}),e.jsx(n.Button,{size:"xs",onClick:c,disabled:!a.trim()||o,children:o?e.jsxs(e.Fragment,{children:[e.jsx(n.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Creating..."]}):"Create library visual"})]})]})})}function Se(t){return t?new Date(t).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"Unknown"}function Ee(t,r){var o;const l=(o=t.ownership.createdBy)==null?void 0:o.type;return l==="tenant"||l==="organization"&&r}function Ce(t,r){var l,o;return Ee(t,r)?((l=t.ownership.createdBy)==null?void 0:l.name)||((o=t.createdByTenantUserRel)==null?void 0:o.name)||t.lastModifiedBy||"Unknown":"Organization"}function We(t,r){return Ce(t,r).split(/\s+/).filter(Boolean).slice(0,2).map(o=>o.charAt(0).toUpperCase()).join("")||"?"}function Ge(t){const r=(t||"").toLowerCase();return r.includes("table")?n.Table2:r.includes("pie")||r.includes("donut")?s.ChartPie:r.includes("line")?s.ChartLine:r.includes("bar")?n.ChartColumn:je.LayoutGrid}function Xe({visual:t}){const r=t.ownership.status==="public"?"Public":t.ownership.status==="shared"||t.ownership.sharedCount>0?"Shared":"Private";return e.jsx("span",{className:"inline-flex items-center rounded-[4px] border border-border/60 px-1.5 py-px text-[11px] text-muted-foreground",children:r})}function Ke({open:t,onOpenChange:r}){const[l,o]=p.useState(""),[a,d]=p.useState(new Set),[h,x]=p.useState(!1),[c,u]=p.useState(null),[i,g]=p.useState(null),[m,f]=p.useState(!1),[y,C]=p.useState(null),[k,A]=p.useState(null),D=()=>{d(new Set),u(null),g(null),f(!1),C(null)},b=()=>{r(!1),D()},{selectVisual:S}=s.useManagementActions(),{handleAddLibraryVisual:E,handleEditLibraryVisual:M}=U.useVisualUtils(),{isConsoleMode:v}=s.useDashboardPreferences(),{resources:w,isLoading:I,isError:F,createResource:$,updateResource:T,deleteResourceAsync:P,duplicateResource:B,isCreating:ae,isDeleting:q}=s.useVisualManagement(void 0,j=>{x(!1),j&&(S(j),M(j),b())}),{startUpdating:le,stopUpdating:K,isUpdating:ge}=s.useResourceUpdateState(),W=w,O=p.useMemo(()=>{const j=l.trim().toLowerCase();return j?W.filter(L=>{var R,Z,ee;return((R=L.title)==null?void 0:R.toLowerCase().includes(j))||((Z=L.description)==null?void 0:Z.toLowerCase().includes(j))||((ee=L.kind)==null?void 0:ee.toLowerCase().includes(j))}):W},[l,W]),Y=p.useMemo(()=>W.filter(j=>a.has(j.id)),[a,W]),te=Y.filter(j=>j.permissions.canDelete),se=Y.filter(j=>j.permissions.canShare),ce=O.length>0&&O.every(j=>a.has(j.id)),he=O.some(j=>a.has(j.id)),re=j=>{const L=new Set(a);j(L),d(L)},oe=j=>{re(L=>{L.has(j)?L.delete(j):L.add(j)})},G=()=>{d(j=>{const L=new Set(j);return ce?O.forEach(R=>L.delete(R.id)):O.forEach(R=>L.add(R.id)),L})},de=async j=>{(await E(j)).success&&b()},z=async()=>{const j=Y;if(j.length===0)return;let L=!1;for(const R of j)if(!(await E(R)).success){L=!0;break}L||b()},_=j=>{M(j),b()},J=j=>{A(j),B(j,{onSettled:()=>A(null)})},ie=()=>{if(te.length===0){s.ue.error("Select a visual you can delete");return}C(null),f(!0)},me=async()=>{const j=y?[y]:te;try{for(const L of j)await P(L.id);d(L=>{const R=new Set(L);return j.forEach(Z=>R.delete(Z.id)),R}),f(!1),C(null)}catch{}},be=()=>{if(Y.length!==1){s.ue.error("Select one visual to share");return}const[j]=Y;if(!j.permissions.canShare){s.ue.error("You do not have permission to share this visual");return}u(j)},ue=({title:j,description:L})=>{if(!i)return;const R={};if(j!==i.title&&(R.title=j),(i.description||"")!==L&&(R.description=L),Object.keys(R).length===0){g(null);return}const Z=Object.keys(R),ee=Z.length===1?Z[0]:void 0;le(i.id,ee),T({resourceId:i.id,data:R},{onSuccess:()=>{K(i.id,ee),g(null)},onError:()=>{K(i.id,ee)}})},ne=j=>{r(j),j||D()},H=y?1:te.length;return e.jsxs(e.Fragment,{children:[e.jsx(s.Dialog,{open:t,onOpenChange:ne,children:e.jsxs(s.DialogContent,{showCloseButton:!1,className:"flex max-h-[80vh] w-[min(72rem,calc(100vw-2rem))] max-w-none grid-cols-none flex-col gap-0 overflow-hidden rounded-[6px] border-border/60 p-0 shadow-lg",children:[e.jsxs("div",{className:"flex h-10 shrink-0 items-center justify-between gap-2 border-b border-border/60 px-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(n.Table2,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"flex min-w-0 items-baseline gap-2",children:[e.jsx(s.DialogTitle,{className:"truncate text-[13px] font-medium leading-none tracking-normal",children:"Visuals library"}),e.jsx("span",{className:"shrink-0 text-[10px] font-medium uppercase leading-none tracking-[0.08em] text-muted-foreground",children:"Add to dashboard"})]})]}),e.jsx(n.Button,{size:"xs",variant:"ghost",className:"w-7 px-0 text-muted-foreground hover:text-foreground",onClick:()=>ne(!1),"aria-label":"Close visuals library",children:"×"})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border/60 px-3 py-2",children:[e.jsxs("div",{className:"relative min-w-[12rem] flex-1 md:max-w-md",children:[e.jsx(Re.Search,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx("input",{autoFocus:!0,value:l,onChange:j=>o(j.target.value),placeholder:"Search visuals...",className:"h-7 w-full rounded-control border border-input bg-background pl-7 pr-2 text-[12px] text-foreground placeholder:text-muted-foreground focus:border-ring focus:outline-none","aria-label":"Search visuals"})]}),e.jsxs(n.Button,{size:"xs",variant:"outline",className:"ml-auto",onClick:()=>x(!0),children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"New library visual"]})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:I?e.jsx("div",{className:"p-3",children:e.jsx(qe,{})}):F?e.jsx("div",{className:"flex flex-col items-center gap-2 px-4 py-12 text-center",children:e.jsx("p",{className:"text-[13px] text-destructive",children:"Failed to load visuals"})}):O.length===0?e.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-12 text-center",children:[e.jsx(je.LayoutGrid,{className:"h-5 w-5 text-muted-foreground/60"}),e.jsx("p",{className:"text-[13px] font-medium",children:l?"No visuals found":"No visuals yet"}),e.jsx("p",{className:"text-[12px] text-muted-foreground",children:l?"Try a different search.":"Create a saved visual to add it here."})]}):e.jsx(Qe,{visuals:O,selectedIds:a,allFilteredSelected:ce,someFilteredSelected:he,onSelectAll:G,onToggleSelection:oe,onAddVisual:de,onOpenVisual:_,onEditDetails:g,onShareVisual:u,onDeleteVisual:j=>{C(j),f(!0)},onDuplicateVisual:J,duplicatingId:k,isDeleting:q,isConsoleMode:v})}),e.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-t border-border/60 px-3 py-2",children:[e.jsx("div",{className:"flex min-w-0 items-center gap-1.5",children:a.size>0&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-[12px] text-muted-foreground",children:[e.jsx("span",{className:"font-medium tabular-nums text-foreground",children:a.size})," ","selected"]}),e.jsx(n.Button,{size:"xs",variant:"ghost",onClick:()=>d(new Set),children:"Clear"}),e.jsxs(n.Button,{size:"xs",variant:"outline",onClick:be,disabled:Y.length!==1||se.length!==1,children:[e.jsx(s.Share2,{className:"h-3.5 w-3.5"}),"Share"]}),e.jsxs(n.Button,{size:"xs",variant:"outline",className:"text-destructive hover:text-destructive",onClick:ie,disabled:te.length===0,children:[e.jsx(s.Trash2,{className:"h-3.5 w-3.5"}),"Delete ",te.length||a.size]})]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(n.Button,{size:"xs",variant:"outline",onClick:()=>ne(!1),children:"Close"}),e.jsxs(n.Button,{size:"xs",onClick:z,disabled:a.size===0,children:[e.jsx(n.Check,{className:"h-3.5 w-3.5"}),a.size===0?"Add to dashboard":`Add ${a.size} visual${a.size===1?"":"s"}`]})]})]})]})}),e.jsx(He,{open:h,onOpenChange:x,onSubmit:$,isCreating:ae}),c&&e.jsx(s.ShareDialog,{resource:c,resourceType:s.ResourceType.VISUAL,onClose:()=>u(null)}),i&&e.jsx(s.ResourceEditDialog,{open:!!i,resourceLabel:"Visual",initialTitle:i.title||"",initialDescription:i.description||"",onClose:()=>g(null),onSave:ue,isSaving:ge(i.id)}),e.jsx(s.AlertDialog,{open:m,onOpenChange:j=>{!j&&q||(f(j),j||C(null))},children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsxs(s.AlertDialogTitle,{children:["Delete ",H," visual",H===1?"":"s","?"]}),e.jsx(s.AlertDialogDescription,{children:"This cannot be undone. Visuals already added to dashboards may need to be removed from those dashboards separately."})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{disabled:q,children:"Cancel"}),e.jsxs(s.AlertDialogAction,{onClick:j=>{j.preventDefault(),me()},disabled:q||H===0,children:[q?e.jsx(n.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(s.Trash2,{className:"h-3.5 w-3.5"}),q?"Deleting...":"Delete"]})]})]})})]})}function Qe({visuals:t,selectedIds:r,allFilteredSelected:l,someFilteredSelected:o,onSelectAll:a,onToggleSelection:d,onAddVisual:h,onOpenVisual:x,onEditDetails:c,onShareVisual:u,onDeleteVisual:i,onDuplicateVisual:g,duplicatingId:m,isDeleting:f,isConsoleMode:y}){return e.jsxs("div",{className:"min-w-[48rem]",children:[e.jsxs("div",{className:"grid h-9 grid-cols-[2.5rem_minmax(14rem,1.8fr)_minmax(10rem,1fr)_8rem_7rem_5rem_5.5rem] items-center border-b border-border/60 px-3 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:[e.jsx(s.Checkbox,{checked:l?!0:o?"indeterminate":!1,onCheckedChange:a,"aria-label":"Select all visuals"}),e.jsx("span",{children:"Name"}),e.jsx("span",{children:"Created by"}),e.jsx("span",{children:"Updated"}),e.jsx("span",{children:"Visibility"}),e.jsx("span",{className:"text-right",children:"Shared"}),e.jsx("span",{className:"text-right",children:"Actions"})]}),t.map(C=>e.jsx(Ye,{visual:C,selected:r.has(C.id),onToggleSelection:d,onAddVisual:h,onOpenVisual:x,onEditDetails:c,onShareVisual:u,onDeleteVisual:i,onDuplicateVisual:g,duplicatingId:m,isDeleting:f,isConsoleMode:y},C.id))]})}function Ye({visual:t,selected:r,onToggleSelection:l,onAddVisual:o,onOpenVisual:a,onEditDetails:d,onShareVisual:h,onDeleteVisual:x,onDuplicateVisual:c,duplicatingId:u,isDeleting:i,isConsoleMode:g}){var y;const m=Ge(t.kind),f=()=>{o(t)};return e.jsxs("div",{className:n.cn("group grid min-h-12 grid-cols-[2.5rem_minmax(14rem,1.8fr)_minmax(10rem,1fr)_8rem_7rem_5rem_5.5rem] items-center border-b border-border/50 px-3 text-[13px] hover:bg-muted/50",r&&"bg-muted/70"),children:[e.jsx("div",{children:e.jsx(s.Checkbox,{checked:r,onCheckedChange:()=>l(t.id),"aria-label":`Select ${t.title||"visual"}`})}),e.jsxs("button",{type:"button",className:"flex min-w-0 items-center gap-2 rounded-[4px] text-left outline-none focus-visible:ring-1 focus-visible:ring-ring",onClick:f,"aria-label":`Add ${t.title||"visual"} to dashboard`,children:[e.jsx(m,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate font-medium text-foreground",title:t.title||"Untitled Visual",children:t.title||"Untitled Visual"}),((y=t.description)==null?void 0:y.trim())&&e.jsx("div",{className:"truncate text-[11px] text-muted-foreground",title:t.description,children:t.description})]})]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("div",{className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-muted text-[9px] font-medium text-muted-foreground",children:We(t,g)}),e.jsx("span",{className:"truncate text-muted-foreground",children:Ce(t,g)})]}),e.jsx("span",{className:"text-muted-foreground",children:Se(t.updatedAt)}),e.jsx(Xe,{visual:t}),e.jsx("span",{className:"text-right tabular-nums text-muted-foreground",children:t.ownership.sharedCount>0?t.ownership.sharedCount:"—"}),e.jsx(Ze,{visual:t,onOpenVisual:a,onEditDetails:d,onShareVisual:h,onDeleteVisual:x,onDuplicateVisual:c,duplicatingId:u,isDeleting:i,isConsoleMode:g})]})}function Ze({visual:t,onOpenVisual:r,onEditDetails:l,onShareVisual:o,onDeleteVisual:a,onDuplicateVisual:d,duplicatingId:h,isDeleting:x,isConsoleMode:c}){return e.jsxs("div",{className:"flex items-center justify-end gap-0.5 opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100",onClick:u=>u.stopPropagation(),children:[e.jsx(n.Button,{size:"xs",variant:"ghost",className:"w-7 px-0",onClick:()=>r(t),"aria-label":"Edit visual",children:e.jsx(s.PenLine,{className:"h-3.5 w-3.5"})}),e.jsxs(s.DropdownMenu,{modal:!1,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(n.Button,{size:"xs",variant:"ghost",className:"w-7 px-0","aria-label":"More actions",children:e.jsx(s.Ellipsis,{className:"h-3.5 w-3.5"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"z-[60] w-44 rounded-[6px] border-border/60 p-1 shadow-sm",children:[e.jsxs(s.DropdownMenuItem,{onClick:()=>r(t),children:[e.jsx(s.PenLine,{className:"h-3.5 w-3.5"}),"Edit visual"]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>d(t.id),disabled:h===t.id,children:[h===t.id?e.jsx(n.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(s.Copy,{className:"h-3.5 w-3.5"}),h===t.id?"Duplicating...":"Duplicate"]}),t.permissions.canEdit&&e.jsxs(s.DropdownMenuItem,{onClick:()=>l(t),children:[e.jsx(s.PenLine,{className:"h-3.5 w-3.5"}),"Edit details"]}),t.permissions.canShare&&e.jsxs(s.DropdownMenuItem,{onClick:()=>o(t),children:[e.jsx(s.Share2,{className:"h-3.5 w-3.5"}),"Share"]}),t.permissions.canDelete&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuItem,{className:"text-destructive focus:bg-destructive/10 focus:text-destructive",onClick:()=>a(t),disabled:x,children:[e.jsx(s.Trash2,{className:"h-3.5 w-3.5"}),x?"Deleting...":"Delete"]})]}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs("div",{className:"space-y-1 px-2 py-1.5 text-[11px] text-muted-foreground",children:[Ee(t,c)&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(s.User,{className:"h-3 w-3"}),e.jsx("span",{className:"truncate",children:Ce(t,c)})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(s.Calendar,{className:"h-3 w-3"}),e.jsx("span",{children:Se(t.updatedAt)})]})]})]})]})]})}function Je({open:t,onOpenChange:r,isLibraryVisual:l,currentVisualName:o,isSaving:a=!1,destinationMode:d="both",onConfirm:h}){const[x,c]=p.useState(l&&o?`Copy of ${o}`:o||""),[u,i]=p.useState("");p.useEffect(()=>{t&&(c(l&&o?`Copy of ${o}`:o||""),i(""))},[t,l,o]);const g=!!x.trim(),m=d==="local"?{saveToLibrary:!1,saveToCurrentDashboard:!0,badgeType:"local",description:"Creates a local copy on the current dashboard.",actionLabel:"Add to Dashboard (Local)"}:d==="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"},f=()=>{!g||a||h({name:x.trim(),description:u.trim()||void 0,saveToLibrary:m.saveToLibrary,saveToCurrentDashboard:m.saveToCurrentDashboard})};return e.jsx(s.Dialog,{open:t,onOpenChange:r,children:e.jsxs(s.DialogContent,{className:"sm:max-w-[500px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsxs(s.DialogTitle,{className:"flex items-center gap-2",children:[e.jsx("span",{children:"Save Visual As"}),m.badgeType!=="local"&&e.jsx(U.VisualBadge,{type:m.badgeType,showLabel:!0,className:"px-2 py-0.5"})]}),e.jsx(s.DialogDescription,{children:m.description})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(n.Label,{htmlFor:"name",children:"Name"}),e.jsx(n.Input,{id:"name",value:x,onChange:y=>c(y.target.value),placeholder:"Enter visual name",disabled:a})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(n.Label,{htmlFor:"description",children:"Description (optional)"}),e.jsx(s.Textarea,{id:"description",value:u,onChange:y=>i(y.target.value),placeholder:"Enter visual description",rows:3,disabled:a})]})]}),e.jsxs(s.DialogFooter,{children:[e.jsx(n.Button,{variant:"outline",onClick:()=>r(!1),disabled:a,children:"Cancel"}),e.jsxs(n.Button,{onClick:f,disabled:!g||a,children:[a&&e.jsx(n.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),m.actionLabel]})]})]})})}function et(){const[t,r]=p.useState(!1),[l,o]=p.useState(!1),[a,d]=p.useState(null),[h,x]=p.useState(null),c=n.useEditorStore(v=>v.frame),u=n.useEditorStore(v=>v.card),i=s.useSelectedVisual(),g=n.useDashboardStore(v=>v.selectedSheetId),m=n.useDashboardStore(v=>v.dashboard),{getUpdatedFrame:f}=U.useVisualUtils(),{selectVisual:y}=s.useManagementActions(),{addFrame:C,setSelectedFrameId:k,setIsVisualEditing:A}=n.useDashboardActions(),D=s.useResolveExistingFrameSemanticExecutionPayload(),b=!!(c!=null&&c.visualId),S=(()=>{var v,w;return((v=c==null?void 0:c.cards)==null?void 0:v.length)===1&&((w=c.cards[0])!=null&&w.title)?c.cards[0].title:i!=null&&i.title?i.title:(u==null?void 0:u.title)||"Untitled Visual"})(),E=s.useCreateVisualWithFrame(v=>{v!=null&&v.id&&(y(v),l&&a&&h&&g&&(async()=>{try{const w={...a,id:n.v4(),visualId:v.id};C(g,w,{position:"end",semanticExecutionPayload:h}),k(w.id),o(!1),d(null),x(null),A(!1)}catch(w){console.error("Failed to promote semantic metadata for saved visual:",w),s.ue.error(w instanceof Error?w.message:"Failed to prepare semantic metadata for the saved visual")}})(),r(!1))});return{saveAsDialogOpen:t,setSaveAsDialogOpen:r,handleSaveAs:async v=>{if(!g){s.ue.error("No sheet selected");return}const w=f(),I=n.getDynamicFrameSaveIssue(w);if(I){s.ue.error(I);return}const $=w.cards.length===1?{...w,cards:w.cards.map(T=>({...T,title:v.name}))}:w;if(v.saveToLibrary){let T=null;if(v.saveToCurrentDashboard)try{T=await D($,{previousFrame:n.findDashboardFrameById(m,$.id)})}catch(B){console.error("Failed to prepare semantic metadata before saving visual:",B),s.ue.error(B instanceof Error?B.message:"Failed to prepare semantic metadata for the saved visual");return}o(v.saveToCurrentDashboard),d($),x(T);const P={title:v.name,description:v.description,frameObject:$,isPrivate:!1};E.mutate(P)}else if(v.saveToCurrentDashboard){const T={...$,id:n.v4(),visualId:void 0};try{const P=await D($,{previousFrame:n.findDashboardFrameById(m,$.id)});C(g,T,{position:"end",semanticExecutionPayload:P}),k(T.id),s.ue.success("Visual saved to dashboard"),r(!1),A(!1)}catch(P){console.error("Failed to save visual to dashboard:",P),s.ue.error(P instanceof Error?P.message:"Failed to prepare semantic metadata for the visual")}}},isLibraryVisual:b,currentVisualName:S,isSaving:E.isPending}}function tt(t={}){var P;const{preferences:r}=s.useDashboardPreferences(),l=((P=r==null?void 0:r.uiMode)==null?void 0:P.inspection)===!0,o=n.useEditorStore(B=>B.frame),a=n.useEditorStore(B=>B.editorContext),d=s.useManagementStore(B=>B.selectedVisual),h=n.useDashboardStore(B=>B.selectedFrameId),x=n.useDashboardStore(B=>B.selectedSheetId),c=n.useDashboardStore(B=>B.dashboard),{setIsVisualEditing:u,updateFrame:i}=n.useDashboardActions(),[g,m]=p.useState(!1),[f,y]=p.useState("both"),C=s.useResolveExistingFrameSemanticExecutionPayload(),k=(a==null?void 0:a.type)==="documentSection",A=!!(o!=null&&o.visualId||d!=null&&d.id),D=!!(o!=null&&o.visualId&&h),b=A&&!D,{saveAsDialogOpen:S,setSaveAsDialogOpen:E,handleSaveAs:M,isLibraryVisual:v,currentVisualName:w,isSaving:I}=et(),{getUpdatedFrame:F}=U.useVisualUtils();if(l)return e.jsxs(e.Fragment,{children:[e.jsx(U.EditorAcceptButton,{className:"rounded-control",variant:"default"}),e.jsx(U.EditorCancelButton,{})]});if(k)return e.jsxs(e.Fragment,{children:[e.jsx(U.EditorAcceptButton,{className:"rounded-control",variant:"default"}),e.jsx(U.EditorCancelButton,{})]});const $=async()=>{if(!x){s.ue.error("No sheet selected");return}if(g)return;m(!0);const B=F(),ae=n.getDynamicFrameSaveIssue(B);if(ae){m(!1),s.ue.error(ae);return}const q={...B,visualId:void 0},le=n.findDashboardFrameById(c,q.id);try{const K=await C(q,{previousFrame:le});i(x,q,{semanticExecutionPayload:K})}catch(K){console.error("Failed to apply local semantic metadata:",K),m(!1),s.ue.error(K instanceof Error?K.message:"Failed to prepare semantic metadata for this visual");return}setTimeout(()=>{m(!1),s.ue.success("Changes applied. Visual is now local to this dashboard"),u(!1)},300)},T=B=>{y(B),E(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"inline-flex items-center overflow-hidden rounded-control",children:[!A&&e.jsx(U.EditorAcceptButton,{className:"!rounded-none",variant:"default"}),A&&b&&e.jsx(U.VisualSaveButton,{className:"!rounded-none",variant:"default"}),A&&D&&e.jsx(U.VisualSaveAndApplyButton,{className:"!rounded-none"}),e.jsxs(s.DropdownMenu,{modal:!1,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(n.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:I||g,children:e.jsx(X.ChevronDown,{className:"h-3.5 w-3.5"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"min-w-[220px] rounded-control border border-border/60 p-1 shadow-sm",children:[D&&e.jsxs(e.Fragment,{children:[e.jsxs(s.DropdownMenuItem,{onClick:$,disabled:g,children:[e.jsx(n.Check,{className:"h-3.5 w-3.5"}),g?"Applying...":"Apply Locally"]}),e.jsx(s.DropdownMenuSeparator,{})]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>T("local"),disabled:I,children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Add to Dashboard (Local)"]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>T("library"),disabled:I,children:[e.jsx(U.Library,{className:"h-3.5 w-3.5"}),"Save as Library Visual"]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>T("both"),disabled:I,children:[e.jsx(U.Link2,{className:"h-3.5 w-3.5"}),"Save Copy as Linked Visual"]})]})]})]}),e.jsx(U.EditorCancelButton,{}),e.jsx(Je,{open:S,onOpenChange:B=>{I||E(B)},isLibraryVisual:v,currentVisualName:w,isSaving:I,destinationMode:f,onConfirm:M})]})}function st({className:t}){const r=n.useEditorStore(u=>u.isDevMode),l=n.useDashboardStore(u=>u.isVisualEditing),{setIsDevMode:o}=n.useEditorActions(),{config:a}=p.useContext(s.SemaphorContext).tokenProps,d=(a==null?void 0:a.showAdvancedMode)!==!1;if(!l||!d)return null;const h=r?n.SlidersHorizontal:s.CodeXml,x=r?"Drag & drop":"SQL",c=r?"Switch to drag-and-drop mode":"Switch to SQL mode";return e.jsxs("button",{type:"button","aria-label":c,title:c,onClick:()=>o(!r),className:n.cn("inline-flex h-7 items-center gap-1.5 rounded-control border border-input bg-background px-2 text-[12px] font-medium text-foreground transition-colors hover:bg-muted/40 focus-visible:border-ring focus-visible:outline-none",t),children:[e.jsx(h,{className:"h-3 w-3 text-muted-foreground"}),x]})}function rt({open:t,onOpenChange:r,onSave:l,onDiscard:o,isSaving:a,title:d="Unsaved changes",description:h="You have unsaved changes to this dashboard. What would you like to do?",cancelLabel:x="Cancel",discardLabel:c="Discard",saveLabel:u="Save"}){const i=g=>{!g&&a||r(g)};return e.jsx(s.AlertDialog,{open:t,onOpenChange:i,children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:d}),e.jsx(s.AlertDialogDescription,{children:h})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(n.Button,{type:"button",size:"xs",onClick:o,disabled:a,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:c}),e.jsx(s.AlertDialogCancel,{disabled:a,children:x}),e.jsx(n.Button,{type:"button",size:"xs",onClick:l,disabled:a,children:a?e.jsxs(e.Fragment,{children:[e.jsx(n.LoaderCircle,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),"Saving..."]}):u})]})]})})}const nt=1e4,at=15e3,ot=3e4,it=3e4,lt=12e4,Ne=2*60*60*1e3;function ct(t){const r=Date.now()-t.getTime();return r<it?nt:r<lt?at:ot}function dt(){const{authToken:t,tokenProps:r}=s.useSemaphorContext(),l=s.useExportStore(m=>m.activeExports),[o,a]=p.useState(typeof document<"u"?!document.hidden:!0),d=p.useRef(null),h=p.useRef(!1),x=p.useRef(void 0),c=r==null?void 0:r.apiServiceUrl,u=t==null?void 0:t.accessToken,i=p.useCallback(()=>{const m=s.useExportStore.getState().activeExports;return Array.from(m.values()).filter(f=>s.isExportInProgress(f.status))},[]);p.useEffect(()=>{if(typeof document>"u")return;const m=()=>{a(!document.hidden)};return document.addEventListener("visibilitychange",m),()=>{document.removeEventListener("visibilitychange",m)}},[]);const g=p.useCallback(async()=>{if(!c||!u){h.current=!1;return}const m=i();if(m.length===0){h.current=!1;return}const f=Date.now(),y=m.filter(b=>f-b.startedAt.getTime()>Ne);if(y.length>0){const{updateExport:b}=s.useExportStore.getState().actions;for(const S of y)b(S.id,{status:"failed",error:"Export timed out. Please try again or contact support.",lastUpdatedAt:new Date})}const C=m.filter(b=>f-b.startedAt.getTime()<=Ne);if(C.length===0){h.current=!1;return}const k=await Promise.allSettled(C.map(async b=>{try{const S=await s.getExportStatus(c,u,b.id);let E;if(S.status==="completed")try{E=await s.getDownloadUrl(c,u,b.id)}catch(M){console.error(`[useExportPolling] Failed to get download URL for ${b.id}:`,M)}return{id:b.id,status:S.status,progress:S.progress,completedChunks:S.completedChunks,completedAt:S.completedAt?new Date(S.completedAt):void 0,lastUpdatedAt:new Date,fileSize:S.fileSize,error:S.error,downloadUrl:E}}catch(S){return console.error(`[useExportPolling] Failed to poll export ${b.id}:`,S),null}})),{updateExport:A}=s.useExportStore.getState().actions;for(const b of k)b.status==="fulfilled"&&b.value&&A(b.value.id,b.value);const D=i();if(D.length>0&&!document.hidden){const b=D.reduce((E,M)=>M.startedAt<E?M.startedAt:E,D[0].startedAt),S=ct(b);d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{var E;(E=x.current)==null||E.call(x)},S)}else h.current=!1},[c,u,i]);return p.useEffect(()=>{x.current=g},[g]),p.useEffect(()=>{var f;i().length>0&&o&&!h.current&&(h.current=!0,(f=x.current)==null||f.call(x))},[l,o,i]),p.useEffect(()=>{var f;const m=i();o&&m.length>0&&!h.current&&(h.current=!0,(f=x.current)==null||f.call(x))},[o,i]),p.useEffect(()=>{!o&&d.current&&(clearTimeout(d.current),d.current=null,h.current=!1)},[o]),p.useEffect(()=>()=>{d.current&&(clearTimeout(d.current),d.current=null)},[]),{isPolling:h.current,isTabVisible:o,inProgressCount:i().length}}function ut(){const{authToken:t,tokenProps:r}=s.useSemaphorContext(),l=s.useExportStore(x=>x.activeExports),{addExport:o}=s.useExportActions(),a=p.useRef(!1),d=r==null?void 0:r.apiServiceUrl,h=t==null?void 0:t.accessToken;p.useEffect(()=>{if(a.current||!d||!h)return;(async()=>{try{const{exports:c}=await s.getExports(d,h,{status:["pending","processing","chunking","compacting","completed","failed"],limit:20});for(const u of c){if(l.has(u.id))continue;const i=u.totalChunks?Math.round(u.completedChunks/u.totalChunks*100):0;let g;if(u.status==="completed")try{g=await s.getDownloadUrl(d,h,u.id)}catch(f){console.error(`[useExportRecovery] Failed to get download URL for ${u.id}:`,f)}const m={id:u.id,status:u.status,progress:i,title:ht(u),totalRows:u.totalRows,totalChunks:u.totalChunks,completedChunks:u.completedChunks,startedAt:new Date(u.createdAt),lastUpdatedAt:new Date,completedAt:u.completedAt?new Date(u.completedAt):void 0,fileSize:u.fileSize,error:u.error,expiresAt:new Date(u.expiresAt),downloadUrl:g};o(m)}a.current=!0}catch(c){console.error("[useExportRecovery] Failed to recover exports:",c),a.current=!0}})()},[d,h,o,l])}function ht(t){return t.title?t.title:s.isExportInProgress(t.status)?"Export in progress...":t.status==="completed"?"Export completed":t.status==="failed"?"Export failed":"Export"}function ke({export:t,onRemove:r}){const l=()=>{t.downloadUrl&&window.open(t.downloadUrl,"_blank")},o=x=>{x.stopPropagation(),r==null||r(t.id)},a=()=>{switch(t.status){case"completed":return e.jsx(s.CircleCheck,{className:"mt-0.5 h-5 w-5 shrink-0 text-green-600"});case"failed":return e.jsx(ze,{className:"mt-0.5 h-5 w-5 shrink-0 text-destructive"});default:return e.jsx(n.LoaderCircle,{className:"text-foreground-muted mt-0.5 h-5 w-5 shrink-0 animate-spin"})}},d=s.isExportInProgress(t.status),h=(()=>{switch(t.status){case"pending":return"Queued...";case"processing":return"Processing...";case"chunking":return"Processing...";case"compacting":return"Finalizing...";default:return"Processing..."}})();return e.jsxs("div",{className:"group p-4 transition-colors hover:bg-muted/50",children:[e.jsxs("div",{className:"mb-2 flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-start gap-3",children:[a(),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h4",{className:"mb-1 truncate text-sm font-medium",children:t.title}),t.status==="completed"&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("span",{children:[t.totalRows.toLocaleString()," rows"]}),t.fileSize&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"•"}),e.jsx("span",{children:s.formatFileSize(t.fileSize)})]})]}),d&&e.jsx("div",{className:"text-xs text-muted-foreground",children:h}),t.status==="failed"&&e.jsx("div",{className:"line-clamp-2 text-xs text-destructive",children:t.error||"Export failed"})]})]}),e.jsx(n.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0 opacity-0 transition-opacity group-hover:opacity-100",onClick:o,"aria-label":"Remove notification",children:e.jsx(X.X,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"ml-8",children:[t.status==="completed"&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:ye.formatDistanceToNow(t.startedAt,{addSuffix:!0})}),t.downloadUrl&&e.jsxs(n.Button,{size:"sm",variant:"outline",className:"h-8 bg-transparent",onClick:l,children:[e.jsx(s.Download,{className:"mr-1.5 h-3.5 w-3.5"}),"Download"]})]}),d&&e.jsxs("div",{children:[e.jsx(s.Progress,{value:t.progress,className:"h-1.5"}),e.jsxs("span",{className:"mt-1 block text-xs text-muted-foreground",children:[t.progress,"% complete"]})]}),t.status==="failed"&&e.jsx("span",{className:"text-xs text-muted-foreground",children:ye.formatDistanceToNow(t.startedAt,{addSuffix:!0})})]})]})}function Ae(){const{authToken:t,tokenProps:r}=s.useSemaphorContext(),l=s.useExportStore(C=>C.activeExports),{clearCompleted:o,removeExport:a,updateExport:d}=s.useExportActions(),[h,x]=p.useState(!1),[c,u]=p.useState(!1),i=Array.from(l.values()).sort((C,k)=>k.startedAt.getTime()-C.startedAt.getTime()),g=i.some(C=>C.status==="completed"||C.status==="failed"),m=p.useCallback(async()=>{const C=r==null?void 0:r.apiServiceUrl,k=t==null?void 0:t.accessToken;if(!(!C||!k)){x(!0);try{const A=Array.from(l.values());await Promise.all(A.map(async D=>{try{const b=await s.getExportStatus(C,k,D.id);let S;if(b.status==="completed")try{S=await s.getDownloadUrl(C,k,D.id)}catch(E){console.error(`Failed to get download URL for ${D.id}:`,E)}d(D.id,{status:b.status,progress:b.progress,completedChunks:b.completedChunks,completedAt:b.completedAt?new Date(b.completedAt):void 0,lastUpdatedAt:new Date,fileSize:b.fileSize,error:b.error,downloadUrl:S})}catch(b){console.error(`Failed to refresh export ${D.id}:`,b)}}))}finally{x(!1)}}},[l,t==null?void 0:t.accessToken,r==null?void 0:r.apiServiceUrl,d]),f=p.useCallback(async()=>{const C=r==null?void 0:r.apiServiceUrl,k=t==null?void 0:t.accessToken;if(!C||!k){o();return}u(!0);try{const A=i.filter(b=>b.status==="completed"||b.status==="failed"),D=await Promise.allSettled(A.map(async b=>(await s.cancelExport(C,k,b.id),b.id)));for(const b of D)b.status==="fulfilled"?a(b.value):console.error("Failed to delete export:",b.reason)}finally{u(!1)}},[i,r==null?void 0:r.apiServiceUrl,t==null?void 0:t.accessToken,o,a]),y=p.useCallback(async C=>{const k=r==null?void 0:r.apiServiceUrl,A=t==null?void 0:t.accessToken;if(k&&A)try{await s.cancelExport(k,A,C),a(C);return}catch(D){console.error(`Failed to cancel export ${C}:`,D)}a(C)},[r==null?void 0:r.apiServiceUrl,t==null?void 0:t.accessToken,a]);return i.length===0?e.jsxs("div",{className:"p-6 text-center",children:[e.jsx(we,{className:"mx-auto mb-2 h-8 w-8 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No active exports"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Large exports will appear here"})]}):e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(we,{className:"h-5 w-5 text-muted-foreground"}),e.jsx("h4",{className:"font-semibold",children:"Exports"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(n.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:m,disabled:h,title:"Refresh status",children:e.jsx(s.RefreshCw,{className:`h-4 w-4 ${h?"animate-spin":""}`})}),g&&e.jsx(n.Button,{variant:"ghost",size:"sm",className:"h-7 px-2 text-sm",onClick:f,disabled:c,children:c?"Clearing...":"Clear all"})]})]}),e.jsx("div",{className:"max-h-[350px] overflow-y-auto",children:e.jsx("div",{className:"divide-y",children:i.map(C=>e.jsx(ke,{export:C,onRemove:y},C.id))})})]})}function mt({variant:t}){const r=s.useExportStore(c=>c.activeExports),l=s.useInProgressExportsCount(),o=r.size>0,a=Array.from(r.values()).some(c=>c.status==="completed"||c.status==="failed"),h=l>0?l>9?"9+":String(l):null,x=o;return e.jsxs(n.Popover,{children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{variant:t??"ghost",size:"xs",className:"relative w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":"Export notifications",children:[e.jsx(s.Bell,{className:"h-3.5 w-3.5"}),x&&e.jsx("span",{className:`absolute flex items-center justify-center rounded-full bg-primary text-primary-foreground ${h?"-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:h})]})}),e.jsx(n.PopoverContent,{className:"w-80 p-0",align:"end",sideOffset:8,children:e.jsx(Ae,{})})]})}function xt(t){if(t)return{renamed:t.type==="rename"?{oldId:t.oldId,newId:t.newId}:void 0,removedControlId:t.type==="remove"?t.controlId:void 0,cardBindingsById:t.type==="add"||t.type==="update"?t.cardBindingsById:void 0,affectedBindingControlIds:t.type==="add"||t.type==="update"?t.affectedBindingControlIds:void 0}}function Be({open:t,onOpenChange:r,trigger:l,showTrigger:o=!0,initialMode:a="manage"}){const d=a==="create",{forceClose:h,handleOpenChange:x,isCreateFlowActive:c,preventPassiveDismissDuringCreate:u,resolvedOpen:i,setIsCreateFlowActive:g}=U.useCreateFlowOverlayState({open:t,onOpenChange:r,initialCreateFlowActive:a==="create",dismissMode:o?"passive":"explicit-only"}),m=n.useDashboardStore(w=>w.dashboard),{setDashboardControlsModel:f}=n.useDashboardActions(),{participants:y}=s.useDashboardStructuralParticipants(n.getDashboardCards(m)),C=Array.from(new Map(y.flatMap(w=>w.fieldChoices.map(I=>{var F;return[I.value,{option:I,target:(F=w.fieldTargetMap)==null?void 0:F[I.value]}]}))).values()),k=Array.from(new Map(y.flatMap(w=>w.metricChoices.map(I=>{var F;return[I.value,{option:I,target:(F=w.metricTargetMap)==null?void 0:F[I.value]}]}))).values()),A=n.collectDashboardControlIds({...m||{},controls:[]}),D=s.buildDashboardStructuralParticipantIdsByControlId(m),b=(w,I,F)=>{f(w,I,xt(F))},S=p.useCallback(()=>{if(d){h();return}g(!1)},[d,h,g]),E=e.jsx(U.ControlDefinitionListEditor,{scope:"dashboard",controls:m.controls||[],reservedControlIds:A,defaultValues:m.defaultControlValues||{},usageByControlId:s.buildDashboardControlUsageById(m),availableFieldChoices:C,availableMetricChoices:k,structuralParticipants:y,structuralParticipantIdsByControlId:D,initialCreateFlow:a==="create",onCreateFlowActiveChange:g,onCreateFlowComplete:S,onChange:b,emptyMessage:"No dashboard controls yet."}),M=c?"Add dashboard control":"Dashboard Controls",v=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Dashboard Controls"}),e.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."})]}),E]});return o?e.jsxs(n.Popover,{open:i,onOpenChange:x,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:l||e.jsxs(n.Button,{variant:"outline",className:"h-7 px-2",size:"sm",children:[e.jsx(n.SlidersHorizontal,{className:"mr-2 h-4 w-4"}),"Controls"]})}),e.jsx(n.PopoverContent,{className:"w-[620px] max-w-[95vw] space-y-4",align:"end",onEscapeKeyDown:u,onPointerDownOutside:u,children:v})]}):e.jsx(s.Dialog,{open:i,onOpenChange:x,children:e.jsxs(s.DialogContent,{className:"flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",onEscapeKeyDown:u,onPointerDownOutside:u,children:[e.jsxs(s.DialogHeader,{className:c?"space-y-0":void 0,children:[e.jsx(s.DialogTitle,{className:"text-[15px]",children:M}),e.jsx(s.DialogDescription,{className:c?"sr-only":"text-[13px]",children:c?"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."})]}),e.jsx("div",{className:"min-h-0 overflow-y-auto pr-1",children:E})]})})}const pt=["enum","multi_enum","text","number","boolean","date"];function Ie({open:t,onOpenChange:r,initialMode:l="manage"}){var v;const o=l==="create",{forceClose:a,handleOpenChange:d,isCreateFlowActive:h,preventPassiveDismissDuringCreate:x,resolvedOpen:c,setIsCreateFlowActive:u}=U.useCreateFlowOverlayState({open:t,onOpenChange:r,initialCreateFlowActive:l==="create",dismissMode:"explicit-only"}),i=n.useDashboardStore(w=>w.dashboard),g=n.useDashboardStore(w=>w.selectedSheetId),{setDashboardInputs:m}=n.useDashboardActions(),f=(v=i.sheets)==null?void 0:v.find(w=>w.id===g),y=(f==null?void 0:f.kind)==="document"&&!!f.document,C=p.useMemo(()=>y&&(f!=null&&f.document)?s.getDocumentSheetDashboardInputs(i,f.id):[],[i,y,f==null?void 0:f.document,f==null?void 0:f.id]),k=p.useMemo(()=>C.filter(w=>w.kind==="control"),[C]),A=p.useMemo(()=>k.map(w=>w.control),[k]),D=p.useMemo(()=>gt(A),[A]),b=p.useMemo(()=>ft(i),[i]),S=p.useCallback(()=>{if(o){a();return}u(!1)},[o,a,u]),E=p.useCallback((w,I,F)=>{!y||!(f!=null&&f.document)||m(vt({allInputs:i.inputs||[],documentSheetId:f.id,currentDocumentInputs:C,nextControls:w,nextDefaultValues:I,change:F}))},[i.inputs,C,y,f,m]);if(!y||!(f!=null&&f.document))return null;const M=h?"Add document control":"Document Controls";return e.jsx(s.Dialog,{open:c,onOpenChange:d,children:e.jsxs(s.DialogContent,{className:"flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",onEscapeKeyDown:x,onPointerDownOutside:x,children:[e.jsxs(s.DialogHeader,{className:h?"space-y-0":void 0,children:[e.jsx(s.DialogTitle,{className:"text-[15px]",children:M}),e.jsx(s.DialogDescription,{className:h?"sr-only":"text-[13px]",children:h?"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(U.ControlDefinitionListEditor,{scope:"dashboard",controls:A,reservedControlIds:b,defaultValues:D,usageByControlId:{},availableFieldChoices:[],availableMetricChoices:[],structuralParticipants:[],structuralParticipantIdsByControlId:{},allowedControlTypes:pt,initialCreateFlow:l==="create",onCreateFlowActiveChange:u,onCreateFlowComplete:S,onChange:E,emptyMessage:"No document controls yet."})})]})})}function ft(t){return(t.controls||[]).map(r=>r.id)}function gt(t){const r={};for(const l of t)l.defaultValue!==void 0&&(r[l.id]=l.defaultValue);return r}function bt(t,r){return r?Object.prototype.hasOwnProperty.call(r,t.id)?{...t,defaultValue:r[t.id]}:t.defaultValue===void 0?t:{...t,defaultValue:void 0}:t.defaultValue===void 0?t:{...t,defaultValue:void 0}}function vt({allInputs:t,documentSheetId:r,currentDocumentInputs:l,nextControls:o,nextDefaultValues:a,change:d}){const h=new Map(o.map(m=>[m.id,bt(m,a)])),x=(d==null?void 0:d.type)==="rename"?{oldId:d.oldId,newId:d.newId}:null,c=new Set,u=[];for(const m of l){if(m.kind!=="control"){u.push(m);continue}const f=h.get(m.control.id)||((x==null?void 0:x.oldId)===m.control.id?h.get(x.newId):void 0);if(!f)continue;c.add(f.id);const y=s.createUniqueDashboardInputVariableNameFromName(f.id,[...t,...u].filter(k=>k.id!==m.id)),C=f.id===y?f:{...f,id:y};u.push({...m,label:C.label,variableName:y,requiredAtExecution:C.requiredAtExecution,control:C})}for(const m of h.values())c.has(m.id)||u.push(s.createDashboardControlInputFromControl({control:m,existingInputs:[...t,...u],sheetId:r}));const i=new Set(l.map(m=>m.id));return[...t.filter(m=>!i.has(m.id)),...u]}function Fe({showFilters:t,onShowFiltersChange:r,pickerContent:l,settingsContent:o,size:a="default",className:d,primaryButtonClassName:h,secondaryButtonClassName:x,pickerContentClassName:c,settingsContentClassName:u}){const i=a==="toolbar",[g,m]=p.useState(!1),f=s.useSurfaceAppearance("interactive");return e.jsxs("div",{className:n.cn("relative inline-flex items-stretch overflow-hidden rounded-control border border-input bg-background",i?"h-8":"h-7",d),children:[e.jsxs(n.Popover,{open:t,onOpenChange:r,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{variant:"ghost",size:"xs",className:n.cn("h-full rounded-none border-0 bg-transparent pl-2.5 pr-2 shadow-none hover:bg-accent/50 data-[state=open]:bg-accent/60",h),children:[t?e.jsx(_e,{className:"h-3.5 w-3.5"}):e.jsx(s.Filter,{className:"h-3.5 w-3.5"}),"Filter"]})}),e.jsx(n.PopoverContent,{align:"end",sideOffset:6,className:n.cn("w-auto rounded-card border border-border/60 p-0 shadow-sm",c),style:f.contentStyle,children:l})]}),e.jsxs(n.Popover,{open:g,onOpenChange:m,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsx(n.Button,{variant:"ghost",size:"xs",className:n.cn("h-full w-7 rounded-none border-0 border-l border-border/60 bg-transparent px-0 shadow-none hover:bg-accent/50 data-[state=open]:bg-accent/60",x),"aria-label":"Filter and control actions",children:e.jsx(X.ChevronDown,{className:"h-3.5 w-3.5"})})}),e.jsx(n.PopoverContent,{align:"end",sideOffset:6,className:n.cn("w-auto rounded-card border border-border/60 p-0 shadow-sm",u),style:f.contentStyle,children:o(()=>m(!1))})]})]})}function jt(){U.useSyncLegacyEditorState();const t=n.useDashboardStore(c=>c.selectedSheetId),r=n.useDashboardStore(c=>c.selectedFrameId),l=n.useDashboardStore(c=>c.dashboard),o=n.useDashboardStore(c=>c.actions.getSelectedFrame),{setSelectedFrameId:a}=n.useDashboardActions(),{setCard:d}=n.useEditorActions(),h=n.useEditorStore(c=>c.card.dataSource);return p.useEffect(()=>{var u,i;let c=o();if(!c){const g=(u=l==null?void 0:l.sheets)==null?void 0:u.find(f=>f.id===t),m=(i=g==null?void 0:g.frames)==null?void 0:i[0];m&&(a(m.id),c=m)}if(c){const g=c.cards.find(m=>m.id===c.activeCardId);g&&d(g)}},[o,t,r,l,a,d]),{hasEntities:!!(h!=null&&h.selectedEntities&&h.selectedEntities.length>0)}}function Ct(){const t=n.useDashboardStore(c=>c.dashboard),r=n.useDashboardStore(c=>c.semanticExecutionPayload),l=n.useDashboardStore(c=>c.actions.addFilter),{hasEntities:o}=jt(),{isLoading:a}=s.useFilterableFields(),d=p.useMemo(()=>n.getGlobalDateFilterCoverage(t,r),[t,r]),x=!n.getGlobalDateFilter(t.filters)&&d.hasEligibleCards&&!a;return e.jsxs("div",{className:"flex h-[520px] w-[400px] flex-col",children:[x&&e.jsx("div",{className:"border-b border-border/60 p-2",children:e.jsxs("button",{type:"button",onClick:()=>l(n.createDefaultGlobalDateFilter()),title:`Applies to ${d.eligibleCardCount} of ${d.totalCardCount} date-aware cards`,className:"flex w-full items-start gap-2 rounded-[4px] px-2 py-1.5 text-left outline-none transition-colors hover:bg-muted/40 focus-visible:bg-muted/40 focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-border",children:[e.jsx(Oe,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsxs("span",{className:"flex min-w-0 flex-col",children:[e.jsx("span",{className:"text-[12px] font-medium text-foreground",children:"Add global date filter"}),e.jsx("span",{className:"text-[11px] leading-[1.4] text-muted-foreground",children:"One date range across all date-aware cards."})]})]})}),!o&&e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center px-6 py-8 text-center",children:[e.jsx(s.Database,{className:"mb-3 h-10 w-10 text-muted-foreground/50"}),e.jsx("h3",{className:"mb-1 text-[13px] font-medium text-foreground",children:"No fields configured"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Configure a data source for this card to enable filtering."})]}),o&&e.jsx("div",{className:"flex flex-1 overflow-hidden",children:e.jsx(s.FilterableFieldsPanel,{context:"filter"})})]})}const De=!1;function yt({onAddFilter:t,onAddControl:r,onManageControls:l,onDismiss:o}){const a=n.useDashboardStore(x=>x.dashboard.filterLayout),{setFilterLayout:d}=n.useDashboardActions();a!=null&&a.displayMode;const h=(a==null?void 0:a.toolbarWrap)??!1;return a==null||a.showDownloadButton,e.jsxs("div",{className:"w-[300px]",children:[e.jsxs("div",{className:"p-1",children:[e.jsx(ve,{icon:s.Filter,label:"Add filter",onClick:()=>{t(),o()}}),e.jsx(ve,{icon:n.SlidersHorizontal,label:"Add control",onClick:()=>{r(),o()}}),e.jsx(ve,{icon:s.Pencil,label:"Manage controls",onClick:()=>{l(),o()}})]}),e.jsx("div",{className:"border-t border-border/60"}),e.jsxs("div",{className:"space-y-1 p-2",children:[e.jsx("p",{className:"px-1 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Display"}),De,e.jsx(wt,{id:"filter-display-wrap",label:"Wrap to multiple lines",checked:h,onCheckedChange:x=>d({toolbarWrap:x===!0})}),De]})]})}function ve({icon:t,label:r,onClick:l}){return e.jsxs("button",{type:"button",onClick:l,className:"flex w-full items-center gap-2 rounded-[4px] px-2 py-1.5 text-left text-[13px] text-foreground transition-colors hover:bg-muted/40",children:[e.jsx(t,{className:"h-3.5 w-3.5 text-muted-foreground"}),r]})}function wt({id:t,label:r,checked:l,onCheckedChange:o}){return e.jsxs("div",{className:"flex items-center gap-2 rounded-[4px] px-1 py-1 transition-colors hover:bg-muted/40",children:[e.jsx(s.Checkbox,{id:t,checked:l,onCheckedChange:o}),e.jsx(n.Label,{htmlFor:t,className:"cursor-pointer text-[12px] font-normal leading-[1.3]",children:r})]})}function Nt({size:t,className:r,primaryButtonClassName:l,secondaryButtonClassName:o,pickerContentClassName:a,settingsContentClassName:d}){var M;const[h,x]=p.useState(null),c=n.useDashboardStore(v=>v.dashboard),u=n.useDashboardStore(v=>v.selectedSheetId),i=n.useDashboardStore(v=>v.showFilters),g=s.useAssistantLayoutStore(v=>v.setPanelOpen),m=n.useDashboardStore(v=>v.actions),{setDocumentInspectorTab:f,setShowFilters:y}=m,C=(M=c.sheets)==null?void 0:M.find(v=>v.id===u),k=n.isDocumentSheet(C),A=p.useCallback(v=>{window.setTimeout(()=>{x(v)},0)},[]),D=p.useCallback(v=>{if(k&&u){v&&f(u,"inputs");return}v&&g("dashboard",!1),y(v)},[k,u,f,g,y]),b=p.useCallback(()=>{D(!0)},[D]),S=p.useCallback(()=>{A("create")},[A]),E=p.useCallback(()=>{A("manage")},[A]);return e.jsxs(e.Fragment,{children:[e.jsx(Fe,{showFilters:k?!1:i,onShowFiltersChange:D,pickerContent:e.jsx(Ct,{}),settingsContent:v=>e.jsx(yt,{onAddFilter:b,onAddControl:S,onManageControls:E,onDismiss:v}),size:t,className:r,primaryButtonClassName:l,secondaryButtonClassName:o,pickerContentClassName:a,settingsContentClassName:d}),h?k?e.jsx(Ie,{open:!0,onOpenChange:v=>{v||x(null)},initialMode:h}):e.jsx(Be,{open:!0,onOpenChange:v=>{v||x(null)},showTrigger:!1,initialMode:h}):null]})}function Le({disabled:t,briefingCount:r,className:l,onClick:o}){const a=typeof r=="number"&&r>0;return e.jsxs(n.Button,{type:"button",size:"xs",variant:"outline",disabled:t,className:n.cn("gap-1.5",l),onClick:o,"aria-label":"Reports & briefings",children:[e.jsx($e,{className:"h-3.5 w-3.5"}),"Reports & briefings",a?e.jsx("span",{className:"ml-0.5 rounded-control bg-muted px-1 text-[10px] tabular-nums text-foreground/70",children:r}):null]})}const Dt="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",Te="inline-flex h-7 items-center gap-1.5 rounded-control px-2 text-[12px] text-muted-foreground hover:bg-muted hover:text-foreground disabled:opacity-50",fe="inline-flex h-7 items-center gap-1.5 rounded-control bg-primary px-3 text-[12px] font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50";function St(t){return t==="dashboard"?"This dashboard":"Project"}function Et(t){if(!t)return"Never";const r=new Date(t);if(Number.isNaN(r.getTime()))return"Unknown";const l=Date.now()-r.getTime(),o=Math.round(l/6e4);if(o<1)return"now";if(o<60)return`${o}m ago`;const a=Math.round(o/60);if(a<24)return`${a}h ago`;const d=Math.round(a/24);if(d<7)return`${d}d ago`;const h=Math.round(d/7);return h<5?`${h}w ago`:`${Math.round(d/30)}mo ago`}function kt(t){return t.scheduleExpr?Q.describeBriefingSchedule(t.scheduleExpr,t.timezone||"UTC")??"Invalid schedule":"On demand"}function At(t){if(t.lastRunStatus){const r=t.lastRunStatus.toString().toUpperCase();return r==="SUCCESS"?"Last run completed.":r==="FAILED"?"Last run failed.":`Last run ${t.lastRunStatus.toString().toLowerCase()}`}return null}function Me(t){return t.hasActiveRun?"Running":t.lastRunStatus?`Last run ${t.lastRunStatus.toString().toLowerCase()}`:"Idle"}function Bt(t){return t.source.type==="dashboard"?"This dashboard":"Project"}function It({activeView:t,onChange:r}){return e.jsx("div",{className:"flex shrink-0 items-center gap-1 rounded-control bg-muted p-0.5",role:"tablist","aria-label":"Briefing source view",children:["dashboard","project"].map(l=>{const o=t===l;return e.jsx("button",{type:"button",role:"tab","aria-selected":o,onClick:()=>r(l),className:n.cn("h-6 rounded-[3px] px-2 text-[11px] transition-colors",o?"bg-background font-medium text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:St(l)},l)})})}function Ft({briefings:t,dashboardLabel:r,sourceView:l,error:o,loading:a,onSourceViewChange:d,onClose:h,onEdit:x,onNew:c,canCreate:u,canCreateScheduledReport:i,analyticalBriefingsEnabled:g,onRunNow:m,onTogglePause:f,onDelete:y,selectingId:C,busyId:k,manageBriefingsHref:A,contentKind:D,hideHeader:b=!1}){const S=t.length,E=t.filter(F=>F.status==="ACTIVE").length,M=D==="reports"?S===1?"report":"reports":D==="briefings"?S===1?"briefing":"briefings":S===1?"item":"items",v=t.find(F=>F.hasActiveRun)??null,w=D??"reports & briefings",I=l==="dashboard"?r:`Project ${w}`;return e.jsxs("section",{"aria-label":`Dashboard ${w.replace("&","and")}`,className:"flex h-full min-h-0 flex-col bg-background text-foreground",children:[b?null:e.jsxs("header",{className:"flex items-start justify-between gap-3 border-b border-border px-4 py-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:Dt,children:w}),e.jsx("h2",{className:"mt-0.5 truncate text-[14px] font-semibold leading-5",children:I})]}),e.jsx("button",{type:"button",onClick:h,className:"rounded-control p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":`Close ${w.replace("&","and")} panel`,children:e.jsx(X.X,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border px-4 py-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx(It,{activeView:l,onChange:d}),e.jsx("div",{className:"flex min-w-0 items-center gap-1.5 text-[11px] text-muted-foreground",children:a&&S===0?e.jsxs("span",{children:["Loading ",w,"…"]}):S===0?e.jsxs("span",{children:["No ",w," yet"]}):e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"font-medium text-foreground/80",children:[S," ",M]}),e.jsx("span",{className:"text-border",children:"·"}),e.jsxs("span",{children:[E," active"]})]})})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[a?e.jsx(n.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}):null,S>0&&u?g&&i?e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsxs("button",{className:fe,children:[e.jsx(s.Plus,{className:"h-3 w-3"})," New"]})}),e.jsxs(s.DropdownMenuContent,{align:"end",children:[e.jsx(s.DropdownMenuItem,{onClick:()=>c("scheduled_report"),children:"Schedule a report"}),e.jsx(s.DropdownMenuItem,{onClick:()=>c("analytical_briefing"),children:"Create analytical briefing"})]})]}):i?e.jsxs("button",{onClick:()=>c("scheduled_report"),className:fe,children:[e.jsx(s.Plus,{className:"h-3 w-3"})," Schedule report"]}):g?e.jsxs("button",{onClick:()=>c("analytical_briefing"),className:fe,children:[e.jsx(s.Plus,{className:"h-3 w-3"})," New briefing"]}):null:null]})]}),v?e.jsxs("div",{className:"flex items-center gap-2 border-b border-border bg-muted/60 px-4 py-2 text-[12px]",children:[e.jsx(n.LoaderCircle,{className:"h-3 w-3 shrink-0 animate-spin text-muted-foreground"}),e.jsx("span",{className:"font-medium text-foreground",children:v.name}),e.jsx("span",{className:"text-border",children:"·"}),e.jsx("span",{className:"truncate text-muted-foreground",children:Me(v)})]}):null,e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[o?e.jsx("div",{className:"m-4 rounded-card border border-destructive/30 bg-destructive/10 px-3 py-2 text-[12px] text-destructive",children:o}):null,!a&&t.length===0&&!o?e.jsx(Lt,{onNew:c,canCreate:u,canCreateScheduledReport:i,analyticalBriefingsEnabled:g,contentKind:D}):null,t.map(F=>e.jsx(Mt,{briefing:F,isOpening:C===F.id,isBusy:k===F.id,onOpen:()=>x(F.id),onRunNow:()=>m(F),onTogglePause:()=>f(F),onDelete:()=>y(F)},F.id))]}),A?e.jsx("div",{className:"border-t border-border px-4 py-2.5",children:e.jsxs("a",{href:A,className:n.cn(Te,"h-6 px-1 text-[11px]"),children:["Manage all reports & briefings",e.jsx(Ue,{className:"h-3 w-3"})]})}):null]})}function Lt({onNew:t,canCreate:r,canCreateScheduledReport:l,analyticalBriefingsEnabled:o,contentKind:a}){const d=a==="reports"?{title:"No reports yet",description:"Schedule an emailed dashboard or visual report to see it here."}:a==="briefings"?{title:"No briefings yet",description:"Create an analytical briefing to monitor this dashboard and brief your team."}:null;return e.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-8 py-12 text-center",children:[e.jsx(Tt,{className:"mb-5 h-[88px] w-[112px] text-border"}),e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:(d==null?void 0:d.title)??"Have an analyst brief your team"}),e.jsx("p",{className:"mt-1.5 max-w-[320px] text-[12px] leading-5 text-muted-foreground",children:(d==null?void 0:d.description)??"Describe what to watch. An analyst digs into this dashboard and the data behind it, then briefs your team on the cadence you choose."}),r?e.jsxs("div",{className:"mt-4 flex flex-wrap justify-center gap-2",children:[l?e.jsxs("button",{onClick:()=>t("scheduled_report"),className:fe,children:[e.jsx(s.Plus,{className:"h-3 w-3"})," Schedule a report"]}):null,o?e.jsx("button",{onClick:()=>t("analytical_briefing"),className:Te,children:"Create analytical briefing"}):null]}):null]})}function Tt({className:t}){return e.jsxs("svg",{viewBox:"0 0 112 88",fill:"none",xmlns:"http://www.w3.org/2000/svg",role:"presentation","aria-hidden":"true",className:t,children:[e.jsx("rect",{x:"22",y:"6",width:"60",height:"72",rx:"3",stroke:"currentColor",strokeWidth:"1.25"}),e.jsx("line",{x1:"30",y1:"16",x2:"64",y2:"16",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),e.jsx("line",{x1:"30",y1:"21",x2:"52",y2:"21",stroke:"currentColor",strokeWidth:"1",strokeLinecap:"round",opacity:"0.5"}),e.jsx("circle",{cx:"31",cy:"32",r:"1",fill:"currentColor",opacity:"0.6"}),e.jsx("line",{x1:"35",y1:"32",x2:"72",y2:"32",stroke:"currentColor",strokeWidth:"1",opacity:"0.4",strokeLinecap:"round"}),e.jsx("circle",{cx:"31",cy:"38",r:"1",fill:"currentColor",opacity:"0.6"}),e.jsx("line",{x1:"35",y1:"38",x2:"68",y2:"38",stroke:"currentColor",strokeWidth:"1",opacity:"0.4",strokeLinecap:"round"}),e.jsx("circle",{cx:"31",cy:"44",r:"1",fill:"currentColor",opacity:"0.6"}),e.jsx("line",{x1:"35",y1:"44",x2:"74",y2:"44",stroke:"currentColor",strokeWidth:"1",opacity:"0.4",strokeLinecap:"round"}),e.jsx("rect",{x:"30",y:"64",width:"5",height:"8",rx:"0.5",fill:"currentColor",opacity:"0.55"}),e.jsx("rect",{x:"38",y:"60",width:"5",height:"12",rx:"0.5",fill:"currentColor",opacity:"0.7"}),e.jsx("rect",{x:"46",y:"56",width:"5",height:"16",rx:"0.5",fill:"currentColor",opacity:"0.85"}),e.jsx("rect",{x:"54",y:"62",width:"5",height:"10",rx:"0.5",fill:"currentColor",opacity:"0.6"}),e.jsx("rect",{x:"62",y:"58",width:"5",height:"14",rx:"0.5",fill:"currentColor",opacity:"0.75"}),e.jsx("circle",{cx:"86",cy:"62",r:"10",fill:"var(--background, white)",stroke:"currentColor",strokeWidth:"1.25"}),e.jsx("line",{x1:"93.5",y1:"69.5",x2:"100",y2:"76",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]})}function Mt({briefing:t,isOpening:r,isBusy:l,onOpen:o,onRunNow:a,onTogglePause:d,onDelete:h}){const x=t.status==="PAUSED",c=t.hasActiveRun,u=At(t),i=Et(t.lastRunAt),g=t.lastRunStatus,m=Q.getBriefingPresentation(t),f=g==="SUCCESS"?s.briefingTone.success.dot:g==="FAILED"?s.briefingTone.danger.dot:g?s.briefingTone.warning.dot:s.briefingTone.neutral.dot;return e.jsxs("div",{className:n.cn("group relative border-b border-border/60 px-4 py-3 transition-colors hover:bg-muted/60",x&&"opacity-70"),children:[e.jsxs("div",{role:"button",tabIndex:0,onClick:o,onKeyDown:y=>{(y.key==="Enter"||y.key===" ")&&(y.preventDefault(),o())},className:"cursor-pointer pr-8",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate text-[13px] font-medium text-foreground",children:t.name}),x?e.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:"· Paused"}):null]}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-1.5 text-[11px] text-muted-foreground",children:[e.jsx("span",{children:m.typeLabel}),e.jsx("span",{className:"text-border",children:"·"}),e.jsx("span",{children:Bt(t)}),e.jsx("span",{className:"text-border",children:"·"}),e.jsx(s.Clock,{className:"h-3 w-3"}),e.jsx("span",{className:"truncate",children:kt(t)}),t.lastRunAt?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-border",children:"·"}),e.jsxs("span",{children:["Last run ",i]})]}):null]}),u||c?e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5 text-[12px] leading-[1.5] text-foreground/80",children:[c?e.jsx(n.LoaderCircle,{className:"h-3 w-3 shrink-0 animate-spin text-muted-foreground/70"}):e.jsx("span",{className:n.cn("inline-block h-1.5 w-1.5 shrink-0 rounded-full",f)}),e.jsx("span",{className:"truncate",children:c?Me(t):u})]}):null]}),e.jsx("div",{className:"absolute right-3 top-3",children:l?e.jsx(n.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground/70"}):r?e.jsx(n.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground/70"}):e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx("button",{type:"button",onClick:y=>y.stopPropagation(),className:"inline-flex h-6 w-6 items-center justify-center rounded-control text-muted-foreground/70 opacity-60 hover:bg-muted hover:text-foreground/80 focus-visible:opacity-100 group-hover:opacity-100","aria-label":`${m.noun==="report"?"Report":"Briefing"} actions`,children:e.jsx(s.Ellipsis,{className:"h-3.5 w-3.5"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-44",children:[e.jsxs(s.DropdownMenuItem,{onClick:o,children:[e.jsx(s.Pencil,{className:"h-3.5 w-3.5"}),"Edit ",m.noun]}),e.jsxs(s.DropdownMenuItem,{onClick:y=>{y.preventDefault(),a()},children:[e.jsx(s.Zap,{className:"h-3.5 w-3.5"}),"Run now"]}),t.scheduleExpr?e.jsx(s.DropdownMenuItem,{onClick:y=>{y.preventDefault(),d()},children:x?e.jsxs(e.Fragment,{children:[e.jsx(s.Play,{className:"h-3.5 w-3.5"}),"Resume"]}):e.jsxs(e.Fragment,{children:[e.jsx(s.Pause,{className:"h-3.5 w-3.5"}),"Pause"]})}):null,e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuItem,{onClick:y=>{y.preventDefault(),h()},className:"text-destructive focus:bg-destructive/10 focus:text-destructive",children:[e.jsx(s.Trash2,{className:"h-3.5 w-3.5"}),"Delete ",m.noun]})]})]})})]})}const Pt=2e3,Vt=20*6e4;function Rt(t){return(t==null?void 0:t.trim())||"This dashboard"}function Ut(t){return t==="This dashboard"?"Watch this dashboard":`Watch ${t}`}function Ot(t,r,l){return r!=="dashboard"?t:t.filter(o=>o.source.type==="dashboard"&&o.source.dashboardId===l)}async function zt(t){const l=[];let o=1,a=0,d=Number.POSITIVE_INFINITY;for(;a<d;){const h=await t.apiClient.listBriefings(t.apiServiceUrl,t.token,{scope:"organization",page:o,pageSize:100});if(l.push(...h.briefings),a+=h.briefings.length,d=h.total,h.briefings.length===0||a>=d)break;o+=1}return l}const _t={listBriefings:s.listBriefings,getBriefing:s.getBriefing,pauseBriefing:s.pauseBriefing,resumeBriefing:s.resumeBriefing,deleteBriefing:s.deleteBriefing,runBriefingNow:s.runBriefingNow};function $t({briefingId:t,initialRun:r,apiServiceUrl:l,token:o,onTerminal:a,onTimeout:d,onExpand:h}){const[x,c]=p.useState(r),{startRun:u}=s.useBriefingRunPolling({apiServiceUrl:l,token:o,intervalMs:Pt,timeoutMs:Vt,fetchRun:({apiServiceUrl:g,token:m,runId:f})=>s.getBriefingRun(g,m,t,f),onRun:g=>{c(g)},onTerminalRun:g=>{a(g)},onTimeout:()=>{d()}}),i=p.useRef(!1);return p.useEffect(()=>{i.current||(i.current=!0,s.isActiveBriefingRunStatus(r.status)?u(r):s.isTerminalBriefingRunStatus(r.status)&&a(r))},[r,a,u]),e.jsx(s.BackgroundRunPill,{run:x,onExpand:h})}function qt(t){return e.jsx(s.BriefingUiCapabilitiesBoundary,{children:e.jsx(Ht,{...t})})}function Ht({dashboardId:t,dashboardTitle:r,apiServiceUrl:l,token:o,disabled:a,className:d,manageBriefingsHref:h,open:x,onOpenChange:c,hideTrigger:u=!1,workflowIntent:i,client:g}){const{authToken:m,tokenProps:f}=s.useSemaphorContext(),y=s.useBriefingUiCapabilities(),C=!i||y.canCreate&&(i==="scheduled_report"||y.analyticalBriefingsEnabled),[k,A]=p.useState(!1),D=x??k,b=N=>{x===void 0&&A(N),c==null||c(N)},[S,E]=p.useState(i?"author":"list"),[M,v]=p.useState(i??"analytical_briefing"),[w,I]=p.useState("dashboard"),[F,$]=p.useState([]),[T,P]=p.useState(null),B=i&&!C&&!T?"list":S,[ae,q]=p.useState(!1),[le,K]=p.useState(null),[ge,W]=p.useState(null),[O,Y]=p.useState(null),[te,se]=p.useState(null),ce=p.useRef(null),he=p.useRef(D);p.useEffect(()=>{const N=D&&!he.current;he.current=D,!(!N||!i)&&(P(null),I("dashboard"),v(i),E("author"),se(null))},[D,i]);const[re,oe]=p.useState(null),[G,de]=p.useState(null),z=l??(f==null?void 0:f.apiServiceUrl),_=o??(m==null?void 0:m.accessToken),J=p.useMemo(()=>({..._t,...g}),[g]),ie=Rt(r),me=p.useMemo(()=>{const N=Ot(F,w,t);if(!i)return N;const V=i==="scheduled_report"?"report":"briefing";return N.filter(xe=>Q.getBriefingPresentation(xe).noun===V)},[t,F,w,i]),be=p.useMemo(()=>w==="dashboard"?{source:{type:"dashboard",dashboardId:t},label:ie,detail:Ut(ie)}:{source:{type:"project"},label:"This project",detail:"Use any data in this project."},[t,ie,w]),ue=!!(z&&_),ne=Q.getBriefingCreationIntents({canCreate:y.canCreate,analyticalBriefingsEnabled:y.analyticalBriefingsEnabled,scheduledReportAvailable:w==="dashboard"}),H=p.useCallback(async()=>{if(!(!z||!_)){q(!0),se(null);try{$(await zt({apiClient:J,apiServiceUrl:z,token:_}))}catch(N){se(N instanceof Error?N.message:"Could not load briefings.")}finally{q(!1)}}},[J,z,_]);p.useEffect(()=>{!D||B!=="list"||!ue||H()},[ue,B,H,D]);const j=()=>{P(null),I("dashboard"),E("list"),b(!0)},L=N=>{P(null),v(N),E("author")},R=async N=>{if(!(!z||!_)){K(N),se(null);try{const V=await J.getBriefing(z,_,N);P(V.briefing),E("author")}catch(V){se(V instanceof Error?V.message:"Could not open briefing.")}finally{K(null)}}},Z=async N=>{if(!(!z||!_)){W(N.id);try{await J.runBriefingNow(z,_,N.id,{requestId:Wt()}),H()}catch(V){s.ue.error(V instanceof Error?V.message:"Could not start the run.")}finally{W(null)}}},ee=async N=>{if(!z||!_)return;const{noun:V}=Q.getBriefingPresentation(N),xe=V==="report"?"Report":"Briefing";W(N.id);try{const pe=N.status==="PAUSED"?await J.resumeBriefing(z,_,N.id):await J.pauseBriefing(z,_,N.id);s.ue.success(pe.briefing.status==="PAUSED"?`${xe} paused`:`${xe} resumed`),H()}catch(pe){s.ue.error(pe instanceof Error?pe.message:`Could not update the ${V} status.`)}finally{W(null)}},Pe=async()=>{if(!O||!z||!_)return;const N=O;W(N.id);try{await J.deleteBriefing(z,_,N.id);const{noun:V}=Q.getBriefingPresentation(N);s.ue.success(`${V==="report"?"Report":"Briefing"} deleted`),Y(null),H()}catch(V){s.ue.error(V instanceof Error?V.message:"Could not delete the briefing.")}finally{W(null)}},Ve=me.length;return y.surfaceVisible?e.jsxs(s.Sheet,{open:D,onOpenChange:b,children:[u?null:e.jsx(Le,{disabled:a||!ue,briefingCount:Ve,className:d,onClick:j}),e.jsxs(s.SheetContent,{ref:ce,side:"right",hideClose:!0,className:"flex h-full w-full flex-col overflow-hidden p-0 outline-none sm:max-w-[560px]",onOpenAutoFocus:N=>{var V;N.preventDefault(),(V=ce.current)==null||V.focus({preventScroll:!0})},children:[e.jsxs(s.SheetHeader,{className:"sr-only",children:[e.jsx(s.SheetTitle,{children:"Reports & briefings"}),e.jsx(s.SheetDescription,{children:"Manage reports and briefings for this dashboard."})]}),i?e.jsxs("div",{className:"flex shrink-0 items-start justify-between gap-3 border-b border-border pl-4 pr-3 pt-2",children:[e.jsxs("div",{className:"flex items-center gap-5",role:"tablist","aria-label":i==="scheduled_report"?"Email report workflow":"Analytical briefing workflow",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":B==="author",disabled:!C,className:n.cn("-mb-px border-b-2 px-0.5 pb-2 text-[12px] transition-colors",B==="author"?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground",!C&&"cursor-not-allowed opacity-50"),onClick:()=>{C&&(P(null),v(i),I("dashboard"),E("author"))},children:T?`Edit ${Q.getBriefingPresentation(T).noun}`:i==="scheduled_report"?"Schedule report":"Create briefing"}),e.jsx("button",{type:"button",role:"tab","aria-selected":B==="list",className:n.cn("-mb-px border-b-2 px-0.5 pb-2 text-[12px] transition-colors",B==="list"?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),onClick:()=>E("list"),children:i==="scheduled_report"?"Manage reports":"Manage briefings"})]}),e.jsx("button",{type:"button",onClick:()=>b(!1),className:"rounded-control p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":i==="scheduled_report"?"Close email report workflow":"Close analytical briefing workflow",children:e.jsx(X.X,{className:"h-3.5 w-3.5"})})]}):null,B==="list"?e.jsx(Ft,{briefings:me,dashboardLabel:ie,sourceView:w,error:te,loading:ae,onSourceViewChange:I,onClose:()=>b(!1),onEdit:N=>{R(N)},onNew:L,canCreate:!i&&ne.length>0,canCreateScheduledReport:ne.includes("scheduled_report"),analyticalBriefingsEnabled:ne.includes("analytical_briefing"),onRunNow:N=>{Z(N)},onTogglePause:N=>{ee(N)},onDelete:N=>Y(N),selectingId:le,busyId:ge,manageBriefingsHref:h,contentKind:i==="scheduled_report"?"reports":i==="analytical_briefing"?"briefings":void 0,hideHeader:!!i}):e.jsx(s.BriefingAuthor,{apiServiceUrl:z,token:_,briefing:T,intent:M,sourceContext:T?void 0:be,title:T?`Edit ${Q.getBriefingPresentation(T).noun}`:M==="scheduled_report"?"Schedule report":"Create analytical briefing",hideHeader:!!i,className:"h-full min-h-0 max-w-none border-0 shadow-none",onBack:i?void 0:()=>E("list"),onCancel:()=>b(!1),onDeleted:()=>{const N=T?Q.getBriefingPresentation(T).noun:"briefing";s.ue.success(`${N==="report"?"Report":"Briefing"} deleted`),P(null),E("list"),H()},onRunStarted:()=>{},onSaved:N=>{P(N),H()},onMinimizeRun:({briefing:N,run:V})=>{oe({briefing:N,run:V}),b(!1)}})]}),re&&z&&_?e.jsx($t,{briefingId:re.briefing.id,initialRun:re.run,apiServiceUrl:z,token:_,onTerminal:N=>{de({briefing:re.briefing,run:N}),oe(null),H()},onTimeout:()=>{oe(null),H()},onExpand:()=>{P(re.briefing),E("author"),oe(null),b(!0)}}):null,G?e.jsx("div",{className:"fixed bottom-4 right-4 z-50 w-[360px]",children:e.jsx(s.RunCompletionBanner,{title:G.run.status==="SUCCESS"?`${G.briefing.name} is ready`:`${G.briefing.name} run failed`,durationSeconds:G.run.startedAt&&G.run.completedAt?Math.max(0,Math.floor((new Date(G.run.completedAt).getTime()-new Date(G.run.startedAt).getTime())/1e3)):null,status:G.run.status==="SUCCESS"?"success":"failed",onView:()=>{P(G.briefing),E("author"),de(null),b(!0)},onDismiss:()=>de(null)})}):null,e.jsx(s.AlertDialog,{open:!!O,onOpenChange:N=>{N||Y(null)},children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsxs(s.AlertDialogTitle,{children:["Delete"," ",O?Q.getBriefingPresentation(O).noun:"briefing","?"]}),e.jsxs(s.AlertDialogDescription,{children:["This permanently deletes ",e.jsx("strong",{children:O==null?void 0:O.name}),". Recipients will stop receiving it."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsxs(s.AlertDialogAction,{className:"bg-destructive/90 hover:bg-destructive",onClick:Pe,children:["Delete"," ",O?Q.getBriefingPresentation(O).noun:"briefing"]})]})]})})]}):null}function Wt(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`briefing-run-now-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}exports.AdvancedModeToggle=st;exports.DashboardBriefingLauncher=qt;exports.DashboardControlsSettings=Be;exports.DashboardFilterControlsButton=Fe;exports.DashboardFilterControlsLauncher=Nt;exports.DocumentControlsSettings=Ie;exports.ExportNotificationItem=ke;exports.ExportNotificationList=Ae;exports.NotificationBell=mt;exports.UnsavedChangesAlert=rt;exports.VisualEditingControls=tt;exports.VisualsLibraryDialog=Ke;exports.WatchDashboardButton=Le;exports.useExportPolling=dt;exports.useExportRecovery=ut;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),l=require("./code-editor-BSENCZwR.js"),s=require("./dashboard-nvGHASLa.js"),T=require("./index-jSrCwPQz.js");require("./analyze-result-contract-BswhsmWT.js");require("../value-format-preferences/index.cjs");const f=require("react");require("./index-Dpm_VET4.js");require("./comparison-document-migration-DbU_BTxR.js");const ss=require("react-dom");require("../briefings/index.cjs");const q=require("./dashboard-briefing-launcher-C8_pyleA.js"),wt=require("./search-Dcud9ajy.js"),Dt=require("./index-D7KJindZ.js"),rs=require("./report-preferences-dialog-DGbUoySN.js"),as=require("./use-debounced-dirty-check-XHSwAefL.js"),Ge=require("./normalize-dashboard-for-dirty-check-BXRUMVb2.js"),bt=require("./save-Xdc4pnys.js"),ns=require("./palette-C0yjT5Tv.js"),os=require("./braces-CbO-aIwH.js");function is(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const r=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(n,a,r.get?r:{enumerable:!0,get:()=>t[a]})}}return n.default=t,Object.freeze(n)}const A=is(f);/**
|
|
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 ds=T.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 ls=T.createLucideIcon("Monitor",[["rect",{width:"20",height:"14",x:"2",y:"3",rx:"2",key:"48i651"}],["line",{x1:"8",x2:"16",y1:"21",y2:"21",key:"1svkeh"}],["line",{x1:"12",x2:"12",y1:"17",y2:"21",key:"vw1qmm"}]]);/**
|
|
12
|
+
* @license lucide-react v0.453.0 - ISC
|
|
13
|
+
*
|
|
14
|
+
* This source code is licensed under the ISC license.
|
|
15
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
+
*/const cs=T.createLucideIcon("Moon",[["path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z",key:"a7tn18"}]]);/**
|
|
17
|
+
* @license lucide-react v0.453.0 - ISC
|
|
18
|
+
*
|
|
19
|
+
* This source code is licensed under the ISC license.
|
|
20
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
+
*/const us=T.createLucideIcon("ShieldX",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m14.5 9.5-5 5",key:"17q4r4"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]]);/**
|
|
22
|
+
* @license lucide-react v0.453.0 - ISC
|
|
23
|
+
*
|
|
24
|
+
* This source code is licensed under the ISC license.
|
|
25
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
+
*/const ms=T.createLucideIcon("Sun",[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m4.93 4.93 1.41 1.41",key:"149t6j"}],["path",{d:"m17.66 17.66 1.41 1.41",key:"ptbguv"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"m6.34 17.66-1.41 1.41",key:"1m8zz5"}],["path",{d:"m19.07 4.93-1.41 1.41",key:"1shlcs"}]]);/**
|
|
27
|
+
* @license lucide-react v0.453.0 - ISC
|
|
28
|
+
*
|
|
29
|
+
* This source code is licensed under the ISC license.
|
|
30
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
31
|
+
*/const hs=T.createLucideIcon("UserPlus",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]]);/**
|
|
32
|
+
* @license lucide-react v0.453.0 - ISC
|
|
33
|
+
*
|
|
34
|
+
* This source code is licensed under the ISC license.
|
|
35
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
36
|
+
*/const Nt=T.createLucideIcon("UserRound",[["circle",{cx:"12",cy:"8",r:"5",key:"1hypcn"}],["path",{d:"M20 21a8 8 0 0 0-16 0",key:"rfgkzh"}]]),ke=["light","dark","system"];function ps(){const{theme:t,setTheme:n}=s.useTheme(),a=l.useDashboardStore(p=>p.actions.setDashboardTheme);function r(){const p=ke.includes(t)?t:"system",c=ke[(ke.indexOf(p)+1)%ke.length];n(c),a(c)}const o=t==="light"?ms:t==="dark"?cs:ls,u=t==="light"?"Theme: light (click for dark)":t==="dark"?"Theme: dark (click for system)":"Theme: system (click for light)";return e.jsx(l.Button,{type:"button",variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:r,"aria-label":u,title:u,children:e.jsx(o,{className:"h-3.5 w-3.5",strokeWidth:1.5})})}function St(t){const n=new Date().toISOString(),a=s.buildDashboardSheetsInputExecutionSnapshot({dashboard:t.dashboard,sheetIds:(t.dashboard.sheets||[]).filter(r=>r.kind!=="document").map(r=>r.id),sheetKind:"dashboard",mode:"dashboard",generatedAt:n,runtimeValues:{dashboardInputValues:t.dashboardInputValues,filterValues:t.filterValues,controlValues:t.controlValues,inlineFilterValuesMap:t.inlineFilterValuesMap,cardControlValuesMap:t.cardControlValuesMap}}).snapshot;return{generatedAt:n,dashboardInputValues:a.dashboardInputValues}}async function xs(t,n,a,r,o,u){if(!u)return null;const p=JSON.stringify(a),c=`${t}/v1/lens`;return await l.postRequest(c,u,{name:n,template:p,filterValues:r,inputValues:o,operation:"create"})}async function ze(t,n,a){if(!a)return null;const{id:r,template:o,filterValues:u,inputValues:p,isDefault:c,shared:v}=n,y=`${t}/v1/lens`;return await l.postRequest(y,a,{lensId:r,template:o,filterValues:u,inputValues:p,isDefault:c,shared:v,operation:"update"})}async function fs(t,n,a){if(!a)return null;const r=`${t}/v1/lens`;return await l.postRequest(r,a,{operation:"delete",lensId:n})}const gs="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function bs({open:t,onOpenChange:n}={}){const[a,r]=f.useState(""),[o,u]=f.useState(!1),p=l.useDashboardStore(w=>w.lenses),{setLenses:c,setSelectedLensId:v}=l.useDashboardActions(),[y,d]=f.useState(!1),[m,b]=f.useState(!1),x=t!==void 0,j=x?t:m,D=w=>{x||b(w),n==null||n(w)},N=l.useDashboardStore(w=>w.dashboard),C=l.useDashboardStore(w=>w.filterValues),{authToken:h,tokenProps:F}=s.useSemaphorContext();async function P(){d(!0);const w=l.useDashboardStore.getState(),k=St({dashboard:N,dashboardInputValues:w.dashboardInputValues,filterValues:C,controlValues:w.controlValues,inlineFilterValuesMap:w.inlineFilterValuesMap,cardControlValuesMap:w.cardControlValuesMap}),S=await xs(F.apiServiceUrl,a,N,C,k,h==null?void 0:h.accessToken);S&&(c([...p||[],S]),v(S.id),D(!1)),d(!1)}return e.jsxs(s.Dialog,{open:j,onOpenChange:D,children:[x?null:e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsxs(l.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(l.Label,{htmlFor:"lens-name",className:gs,children:"Name"}),e.jsx(l.Input,{id:"lens-name",size:"xs",value:a,placeholder:"Monthly review, West region, …",onChange:w=>r(w.target.value)}),o&&e.jsx("p",{className:"text-[12px] text-destructive",children:"A lens with this name already exists. Pick a different one."})]}),e.jsxs(s.DialogFooter,{children:[e.jsx(l.Button,{variant:"outline",size:"xs",onClick:()=>D(!1),children:"Cancel"}),e.jsx(l.Button,{size:"xs",type:"submit",onClick:P,disabled:y||!a.trim(),children:y?"Creating…":"Create"})]})]})]})}function vs({includeLabel:t=!1}={}){const n=l.useDashboardStore(d=>d.lenses),a=l.useDashboardStore(d=>d.selectedLensId),{setLenses:r,setSelectedLensId:o}=l.useDashboardActions(),{authToken:u,tokenProps:p}=s.useSemaphorContext();async function c(d){o(d)}async function v(d){if(await fs(p.apiServiceUrl,d,u==null?void 0:u.accessToken)){const b=n==null?void 0:n.filter(x=>x.id!==d);r(b||[]),o("original")}}async function y(d){const m=n==null?void 0:n.map(j=>j.id===d.id?{...j,isDefault:!d.isDefault}:{...j,isDefault:!1});r(m||[]);const b={...d,isDefault:!d.isDefault};await ze(p.apiServiceUrl,b,u==null?void 0:u.accessToken);const x=n==null?void 0:n.find(j=>j.isDefault);if(x&&x.id!==d.id){const j={...x,isDefault:!1};await ze(p.apiServiceUrl,j,u==null?void 0:u.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:a,onValueChange:c,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),n==null?void 0:n.map(d=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:d.id,children:[e.jsx("p",{children:d.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(s.House,{onClick:m=>{m.preventDefault(),y(d)},className:l.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!d.isDefault,"text-green-500":d.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:m=>{m.preventDefault(),v(d.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},d.id))]})]})}function ys(){const{displayPreferences:t,shouldShowElement:n}=s.useDisplayPreferences(),{currentUser:a,userContext:r}=s.useCurrentUserInfo(),o=f.useMemo(()=>s.getRoleBasedDisplayOverrides(a),[a]),u=f.useMemo(()=>c=>o&&o[c]!==void 0&&o[c]===!1?!1:n(c),[o,n,t]),p=f.useMemo(()=>{var c,v,y,d,m;return{canEdit:((c=r==null?void 0:r.permissions)==null?void 0:c.canEdit)??s.canUserEdit(a),canUseFilters:((v=r==null?void 0:r.permissions)==null?void 0:v.canEdit)??s.canUserUseFilters(a),canManageDashboards:((y=r==null?void 0:r.permissions)==null?void 0:y.canCreateDashboard)??s.canUserManageDashboards(a),canCreateDashboards:((d=r==null?void 0:r.permissions)==null?void 0:d.canCreateDashboard)??s.canUserCreateDashboards(a),canAccessVisuals:((m=r==null?void 0:r.permissions)==null?void 0:m.canEdit)??s.canUserAccessVisuals(a)}},[a,r]);return{displayPreferences:t,shouldShowElement:u,permissions:p,currentUser:a}}var _e="Avatar",[js]=l.createContextScope(_e),ws=[0,()=>{}],[Ds,Ct]=js(_e),He=A.forwardRef((t,n)=>{const{__scopeAvatar:a,...r}=t,[o,u]=A.useState("idle"),[p,c]=Ss();return e.jsx(Ds,{scope:a,imageLoadingStatus:o,setImageLoadingStatus:u,imageCount:p,setImageCount:c,children:e.jsx(l.Primitive.span,{...r,ref:n})})});He.displayName=_e;var kt="AvatarImage",Ke=A.forwardRef((t,n)=>{const{__scopeAvatar:a,src:r,onLoadingStatusChange:o,...u}=t,p=Ct(kt,a);Cs(p.setImageCount);const c=Ns(r,{referrerPolicy:u.referrerPolicy,crossOrigin:u.crossOrigin,loadingStatus:p.imageLoadingStatus,setLoadingStatus:p.setImageLoadingStatus}),v=l.useCallbackRef(d=>{o==null||o(d)}),y=A.useRef(c);return l.useLayoutEffect2(()=>{const d=y.current;y.current=c,c!==d&&v(c)},[c,v]),c==="loaded"?e.jsx(l.Primitive.img,{...u,ref:n,src:r}):null});Ke.displayName=kt;var Mt="AvatarFallback",Qe=A.forwardRef((t,n)=>{const{__scopeAvatar:a,delayMs:r,...o}=t,u=Ct(Mt,a),[p,c]=A.useState(r===void 0);return A.useEffect(()=>{if(r!==void 0){const v=window.setTimeout(()=>c(!0),r);return()=>window.clearTimeout(v)}},[r]),p&&u.imageLoadingStatus!=="loaded"?e.jsx(l.Primitive.span,{...o,ref:n}):null});Qe.displayName=Mt;function Ns(t,{loadingStatus:n,setLoadingStatus:a,referrerPolicy:r,crossOrigin:o}){return l.useLayoutEffect2(()=>{if(!t){a("error");return}const u=new window.Image,p=v=>{const y=v.currentTarget;a(vt(y))},c=()=>a("error");return u.addEventListener("load",p),u.addEventListener("error",c),r&&(u.referrerPolicy=r),u.crossOrigin=o??null,u.src=t,a(vt(u)),()=>{u.removeEventListener("load",p),u.removeEventListener("error",c),a("idle")}},[t,o,r,a]),n}function vt(t){return t.complete?t.naturalWidth>0?"loaded":"error":"loading"}function Ss(){let t=ws;{t=A.useState(0);const[n]=t,a=A.useRef(!1);A.useEffect(()=>{n>1&&!a.current&&(a.current=!0,console.warn("Avatar: Only one `Avatar.Image` component should be rendered per `Avatar.Root`, but multiple were detected. This will lead to unexpected behavior."))},[n])}return t}function Cs(t){A.useEffect(()=>(t(n=>n+1),()=>{t(n=>n-1)}),[t])}const It=A.forwardRef(({className:t,...n},a)=>e.jsx(He,{ref:a,className:l.cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",t),...n}));It.displayName=He.displayName;const ks=A.forwardRef(({className:t,...n},a)=>e.jsx(Ke,{ref:a,className:l.cn("aspect-square h-full w-full",t),...n}));ks.displayName=Ke.displayName;const Lt=A.forwardRef(({className:t,...n},a)=>e.jsx(Qe,{ref:a,className:l.cn("flex h-full w-full items-center justify-center rounded-full bg-muted",t),...n}));Lt.displayName=Qe.displayName;const Ms=async(t,n,a)=>{const r=`${t}/management/v1/groups`;return await l.postRequestRegular(r,n,a)},Is=async(t,n,a,r)=>{const o=`${t}/management/v1/groups/${a}`;return l.requestJsonRegular(o,n,"PATCH",r)},Ls=async(t,n,a)=>{const r=`${t}/management/v1/groups/${a}`;await l.requestJsonRegular(r,n,"DELETE")},Es=async(t,n,a,r)=>{const o=`${t}/management/v1/groups/${a}/members`;return await l.postRequestRegular(o,n,r)},As=async(t,n,a,r)=>{const o=`${t}/management/v1/groups/${a}/members`;await l.requestJsonRegular(o,n,"DELETE",r)};function Ps(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:r=>Ms(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r),onSuccess:()=>{a.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:l.getRequestErrorMessage(r,"Failed to create group")})}})}function Rs(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:o})=>Is(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r,o),onSuccess:(r,o)=>{a.invalidateQueries({queryKey:["group",o.groupId]}),a.invalidateQueries({queryKey:["groups"]}),s.ue.success("Group updated successfully")},onError:r=>{console.error("Failed to update group:",r),s.ue.error("Failed to update group",{description:l.getRequestErrorMessage(r,"Failed to update group")})}})}function Us(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:r=>Ls(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r),onSuccess:(r,o)=>{a.invalidateQueries({queryKey:["groups"]}),a.removeQueries({queryKey:["group",o]}),s.ue.success("Group deleted successfully")},onError:r=>{console.error("Failed to delete group:",r),s.ue.error("Failed to delete group",{description:l.getRequestErrorMessage(r,"Failed to delete group")})}})}function Fs(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:o})=>Es(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r,o),onSuccess:(r,o)=>{a.invalidateQueries({queryKey:["group",o.groupId]}),a.invalidateQueries({queryKey:["group-members",o.groupId]}),a.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:l.getRequestErrorMessage(r,"Failed to add members")})}})}function Ts(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:o})=>As(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r,o),onSuccess:(r,o)=>{a.invalidateQueries({queryKey:["group",o.groupId]}),a.invalidateQueries({queryKey:["group-members",o.groupId]}),a.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:l.getRequestErrorMessage(r,"Failed to remove members")})}})}const Os=[];function Vs({open:t,onOpenChange:n}){var h,F,P;const{tokenProps:a}=s.useSemaphorContext(),{currentUser:r}=s.useCurrentUserInfo(),o=(r==null?void 0:r.type)==="tenant",u=a==null?void 0:a.tenantId,{groups:p,isLoading:c,error:v,refetch:y}=s.useGroups({type:o?"TENANT_GROUP":"all",tenantId:o?u:void 0,includeMembers:!1}),d=v?Et(v,"Unable to load groups."):null,[m,b]=f.useState({kind:"list"}),[x,j]=f.useState(null),D=Us();f.useEffect(()=>{t||(b({kind:"list"}),j(null))},[t]);const N=m.kind==="members"&&p.find(w=>w.id===m.groupId)||null,C=async()=>{if(x)try{await D.mutateAsync(x.id),j(null),b({kind:"list"}),y()}catch{}};return e.jsx(s.Dialog,{open:t,onOpenChange:n,children:e.jsxs(s.DialogContent,{className:"flex max-h-[640px] w-[720px] max-w-[92vw] flex-col gap-0 overflow-hidden p-0",children:[m.kind==="list"?e.jsxs("div",{className:"shrink-0 border-b border-border px-5 pt-4 pb-3.5",children:[e.jsx(s.DialogTitle,{className:"text-[15px] font-semibold tracking-tight",children:"Group management"}),e.jsx(s.DialogDescription,{className:"mt-1 text-[12px] leading-[1.5] text-muted-foreground",children:"Organize people into groups for shared access."})]}):m.kind==="create"?e.jsxs("div",{className:"flex h-10 shrink-0 items-center gap-1.5 border-b border-border px-5",children:[e.jsx("button",{type:"button",onClick:()=>b({kind:"list"}),"aria-label":"Back",className:"-ml-1 flex h-6 w-6 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-accent hover:text-foreground",children:e.jsx(s.ArrowLeft,{className:"h-3.5 w-3.5"})}),e.jsx(s.DialogTitle,{className:"truncate text-[13px] font-medium",children:"New group"}),e.jsx(s.DialogDescription,{className:"sr-only",children:"Create a new group to organize members."})]}):null,m.kind==="list"&&e.jsx(qs,{groups:p,isLoading:c,errorMessage:d,onRetry:()=>y(),currentUserId:r==null?void 0:r.id,onOpenGroup:w=>b({kind:"members",groupId:w}),onCreate:()=>b({kind:"create"}),onDeleteRequest:w=>j(w)}),m.kind==="members"&&N&&e.jsx(Gs,{group:N,isTenantViewer:o,canEdit:((h=N.permissions)==null?void 0:h.canEdit)??N.createdBy===(r==null?void 0:r.id),canDelete:((F=N.permissions)==null?void 0:F.canDelete)??N.createdBy===(r==null?void 0:r.id),canManageMembers:((P=N.permissions)==null?void 0:P.canManageMembers)??N.createdBy===(r==null?void 0:r.id),onBack:()=>b({kind:"list"}),onMembersChanged:y,onUpdated:y,onRequestDelete:()=>j(N)},N.id),m.kind==="create"&&e.jsx(zs,{isTenantUser:o,tenantId:u,onCancel:()=>b({kind:"list"}),onCreated:w=>{y(),b({kind:"members",groupId:w})}}),x&&e.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border bg-muted/40 px-5 py-2.5",children:[e.jsxs("div",{className:"min-w-0 text-[12px] text-foreground",children:["Delete ",e.jsx("span",{className:"font-medium",children:x.name}),"?",e.jsx("span",{className:"ml-2 text-muted-foreground",children:"Members lose any access granted via this group."})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>j(null),disabled:D.isPending,className:"h-7 rounded-[5px] px-2.5 text-[12px] font-medium text-foreground/80 hover:bg-background",children:"Cancel"}),e.jsxs("button",{type:"button",onClick:C,disabled:D.isPending,className:"inline-flex h-7 items-center gap-1.5 rounded-[5px] bg-rose-600 px-2.5 text-[12px] font-medium text-white hover:bg-rose-700 disabled:opacity-60",children:[D.isPending?e.jsx(l.LoaderCircle,{className:"h-3 w-3 animate-spin"}):e.jsx(s.Trash2,{className:"h-3 w-3"}),"Delete group"]})]})]})]})})}function qs({groups:t,isLoading:n,errorMessage:a,onRetry:r,currentUserId:o,onOpenGroup:u,onCreate:p,onDeleteRequest:c}){const[v,y]=f.useState(""),d=f.useMemo(()=>t.filter(m=>!v.trim()||m.name.toLowerCase().includes(v.toLowerCase())||(m.description||"").toLowerCase().includes(v.toLowerCase())),[t,v]);return e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-5 py-2.5",children:[e.jsxs("div",{className:"flex flex-1 items-center gap-2 rounded-[5px] border border-border bg-background px-2 focus-within:border-foreground/40",children:[e.jsx(wt.Search,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("input",{value:v,onChange:m=>y(m.target.value),placeholder:"Search groups…",className:"h-7 flex-1 bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground focus:outline-none"}),v&&e.jsx("button",{type:"button",onClick:()=>y(""),className:"flex h-4 w-4 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-accent hover:text-foreground",children:e.jsx(T.X,{className:"h-2.5 w-2.5"})})]}),e.jsxs("button",{type:"button",onClick:p,className:"inline-flex h-7 items-center gap-1.5 rounded-[5px] bg-foreground px-2.5 text-[12px] font-medium text-background hover:opacity-90",children:[e.jsx(s.Plus,{className:"h-3 w-3"}),"New group"]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:n?e.jsx("div",{className:"space-y-px p-3",children:[1,2,3].map(m=>e.jsx("div",{className:"h-12 animate-pulse rounded-[4px] bg-muted/60"},m))}):a?e.jsx(At,{title:"Can't load groups",message:a,onRetry:r}):d.length===0&&t.length===0?e.jsx($s,{onCreate:p}):d.length===0?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-1 py-10 text-center",children:[e.jsxs("div",{className:"text-[12px] text-foreground",children:['No groups match "',v,'"']}),e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"Try a different search."})]}):d.map(m=>{var b;return e.jsx(Bs,{group:m,canDelete:((b=m.permissions)==null?void 0:b.canDelete)??m.createdBy===o,onClick:()=>u(m.id),onDelete:()=>c(m)},m.id)})})]})}function Bs({group:t,canDelete:n,onClick:a,onDelete:r}){let o="";try{o=Dt.format(new Date(t.createdAt),"MMM d, yyyy")}catch{o=""}return e.jsxs("button",{type:"button",onClick:a,className:"group flex w-full items-center gap-3 border-b border-border/60 px-5 py-2.5 text-left hover:bg-accent/40",children:[e.jsx("div",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-[4px] border border-border bg-background text-muted-foreground",children:e.jsx(s.UsersRound,{className:"h-3.5 w-3.5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-foreground",children:t.name}),e.jsxs("div",{className:"mt-0.5 flex items-center gap-2 text-[11px] text-muted-foreground",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Nt,{className:"h-2.5 w-2.5"}),t.memberCount," member",t.memberCount===1?"":"s"]}),o&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-border",children:"·"}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(s.Calendar,{className:"h-2.5 w-2.5"}),o]})]}),t.description&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-border",children:"·"}),e.jsx("span",{className:"truncate text-muted-foreground",children:t.description})]})]})]}),e.jsxs("div",{className:"flex items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100",children:[n&&e.jsx("span",{role:"button",tabIndex:0,onClick:u=>{u.stopPropagation(),r()},onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&(u.preventDefault(),u.stopPropagation(),r())},"aria-label":`Delete ${t.name}`,className:"flex h-6 w-6 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-accent hover:text-foreground",children:e.jsx(s.Trash2,{className:"h-3 w-3"})}),e.jsx(wt.ChevronRight,{className:"h-3.5 w-3.5 text-muted-foreground"})]})]})}function $s({onCreate:t}){return e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 py-12 text-center",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-full border border-border bg-muted/40 text-muted-foreground",children:e.jsx(s.Users,{className:"h-4 w-4"})}),e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:"No groups yet"}),e.jsx("div",{className:"max-w-[320px] text-[11.5px] leading-[1.55] text-muted-foreground",children:"Groups let you grant shared access to dashboards. Create one and add members."}),e.jsxs("button",{type:"button",onClick:t,className:"mt-1 inline-flex h-7 items-center gap-1.5 rounded-[5px] bg-foreground px-2.5 text-[12px] font-medium text-background hover:opacity-90",children:[e.jsx(s.Plus,{className:"h-3 w-3"}),"New group"]})]})}function Gs({group:t,isTenantViewer:n,canEdit:a,canDelete:r,canManageMembers:o,onBack:u,onMembersChanged:p,onUpdated:c,onRequestDelete:v}){const{data:y,isLoading:d,error:m,refetch:b}=s.useGroupMembers(t.id),x=(y==null?void 0:y.members)??Os,j=m?Et(m,"Unable to load members for this group."):null,D=t.type==="TENANT_GROUP"?"tenant":"organization",{users:N}=s.useUnifiedUsers({type:D,tenantId:t.tenantId||void 0,active:!0,limit:200}),C=f.useMemo(()=>new Set(x.map(g=>g.userId)),[x]),h=Fs(),F=Ts(),P=Rs(),[w,k]=f.useState(!1),[S,Q]=f.useState(t.name),[Me,B]=f.useState(!1),[X,$]=f.useState(t.description||""),[Y,Z]=f.useState(""),[Ie,ee]=f.useState(!1),me=f.useMemo(()=>{const g=Y.trim().toLowerCase();return N.filter(R=>!C.has(R.id)).filter(R=>!g||(R.name||"").toLowerCase().includes(g)||(R.email||"").toLowerCase().includes(g)).slice(0,50)},[N,C,Y]),W=async()=>{const g=S.trim();if(k(!1),g.length>=3&&g!==t.name)try{await P.mutateAsync({groupId:t.id,data:{name:g}}),c()}catch{}},he=async()=>{const g=X.trim();if(B(!1),g!==(t.description||""))try{await P.mutateAsync({groupId:t.id,data:{description:g}}),c()}catch{}},pe=async g=>{if(o){Z(""),ee(!1);try{await h.mutateAsync({groupId:t.id,data:{userIds:[g.id],userType:D==="tenant"?"tenant":"org"}}),b(),p()}catch{}}},Le=async g=>{if(o)try{await F.mutateAsync({groupId:t.id,data:{userIds:[g]}}),b(),p()}catch{}};let G="";try{G=Dt.format(new Date(t.createdAt),"MMM d, yyyy")}catch{G=""}return e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex h-10 shrink-0 items-center gap-1.5 border-b border-border px-5",children:[e.jsx("button",{type:"button",onClick:u,"aria-label":"Back",className:"-ml-1 flex h-6 w-6 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-accent hover:text-foreground",children:e.jsx(s.ArrowLeft,{className:"h-3.5 w-3.5"})}),w?e.jsx("input",{autoFocus:!0,value:S,onChange:g=>Q(g.target.value),onBlur:W,onKeyDown:g=>{g.key==="Enter"&&W(),g.key==="Escape"&&(Q(t.name),k(!1))},className:"h-6 min-w-0 flex-1 rounded-[3px] border border-border bg-background px-1.5 text-[13px] font-medium text-foreground focus:border-foreground/40 focus:outline-none"}):e.jsx("button",{type:"button",onClick:()=>{a&&(Q(t.name),k(!0))},title:a?"Click to rename":t.name,disabled:!a,className:"truncate rounded-[3px] px-1 text-[13px] font-medium text-foreground enabled:hover:bg-accent disabled:cursor-default",children:t.name}),e.jsxs("span",{className:"ml-1 inline-flex shrink-0 items-center gap-1 text-[10.5px] text-muted-foreground",children:[e.jsx(Nt,{className:"h-2.5 w-2.5"}),x.length," member",x.length===1?"":"s"]})]}),e.jsx("div",{className:"shrink-0 border-b border-border px-5 py-2.5",children:Me?e.jsxs("div",{children:[e.jsx("textarea",{autoFocus:!0,rows:2,value:X,onChange:g=>$(g.target.value),maxLength:200,onKeyDown:g=>{g.key==="Escape"&&($(t.description||""),B(!1)),g.key==="Enter"&&(g.metaKey||g.ctrlKey)&&he()},placeholder:"What is this group for?",className:"block w-full resize-none rounded-[5px] border border-border bg-background px-2 py-1.5 text-[12px] text-foreground placeholder:text-muted-foreground focus:border-foreground/40 focus:outline-none"}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-between",children:[e.jsxs("span",{className:"text-[10.5px] text-muted-foreground",children:[X.length,"/200 · Esc to cancel · ⌘↩ to save"]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>{$(t.description||""),B(!1)},className:"h-6 rounded-[5px] px-2 text-[11px] font-medium text-foreground/80 hover:bg-accent",children:"Cancel"}),e.jsx("button",{type:"button",onClick:he,className:"inline-flex h-6 items-center rounded-[5px] bg-foreground px-2 text-[11px] font-medium text-background hover:opacity-90",children:"Save"})]})]})]}):e.jsxs("button",{type:"button",onClick:()=>{a&&($(t.description||""),B(!0))},disabled:!a,title:a?"Click to edit description":void 0,className:"block w-full rounded-[3px] px-1 py-0.5 text-left enabled:hover:bg-accent/40 disabled:cursor-default",children:[t.description?e.jsx("p",{className:"text-[12px] leading-[1.55] text-foreground/90",children:t.description}):e.jsx("p",{className:"text-[12px] leading-[1.55] text-muted-foreground",children:a?"Add a description…":"No description"}),e.jsxs("p",{className:"mt-1 text-[10.5px] text-muted-foreground",children:[G?`Created ${G}`:"Recently created",a?" · You can edit this group":""]})]})}),o&&e.jsx(_s,{query:Y,setQuery:Z,open:Ie,setOpen:ee,candidates:me,showKindChip:!n,onAdd:pe,busy:h.isPending}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:d?e.jsx("div",{className:"space-y-px p-3",children:[1,2,3].map(g=>e.jsx("div",{className:"h-10 animate-pulse rounded-[4px] bg-muted/60"},g))}):j?e.jsx(At,{title:"Can't load members",message:j,onRetry:()=>b()}):x.length===0?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-1 py-10 text-center",children:[e.jsx("div",{className:"text-[12px] text-foreground",children:"No members yet"}),e.jsx("div",{className:"text-[11px] text-muted-foreground",children:o?"Search above to add people to this group.":"This group does not have any members."})]}):x.map(g=>{var R,z,_,te,H,se;return e.jsxs("div",{className:"group flex items-center gap-2 border-b border-border/60 px-5 py-2",children:[e.jsx(Pt,{name:((R=g.user)==null?void 0:R.name)||((z=g.user)==null?void 0:z.email)||"?"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[12.5px] font-medium text-foreground",children:((_=g.user)==null?void 0:_.name)||((te=g.user)==null?void 0:te.email)||"Unknown"}),((H=g.user)==null?void 0:H.email)&&g.user.name&&e.jsx("div",{className:"truncate text-[10.5px] text-muted-foreground",children:g.user.email})]}),!n&&e.jsx("span",{className:"text-[10px] uppercase tracking-[0.06em] text-muted-foreground",children:g.userType}),e.jsx("button",{type:"button",onClick:()=>Le(g.userId),disabled:!o||F.isPending,"aria-label":`Remove ${((se=g.user)==null?void 0:se.name)||"member"}`,className:"flex h-6 w-6 items-center justify-center rounded-[3px] text-muted-foreground opacity-0 transition-opacity hover:bg-accent hover:text-foreground group-hover:opacity-100 disabled:opacity-30",children:e.jsx(T.X,{className:"h-3 w-3"})})]},g.id)})}),r&&e.jsx("div",{className:"flex shrink-0 items-center justify-end gap-1.5 border-t border-border bg-muted/30 px-5 py-2.5",children:e.jsxs("button",{type:"button",onClick:v,className:"inline-flex h-7 items-center gap-1.5 rounded-[5px] border border-rose-200 bg-background px-2.5 text-[12px] font-medium text-rose-600 hover:bg-rose-50 dark:border-rose-900/60 dark:text-rose-400 dark:hover:bg-rose-950/30",children:[e.jsx(s.Trash2,{className:"h-3 w-3"}),"Delete group"]})})]})}function zs({isTenantUser:t,tenantId:n,onCancel:a,onCreated:r}){const[o,u]=f.useState(""),[p,c]=f.useState(""),[v,y]=f.useState(null),d=Ps(),m=o.trim().length>=3&&o.trim().length<=50,b=async()=>{if(!m)return;y(null);const x={name:o.trim(),description:p.trim()||void 0,type:t?"TENANT_GROUP":"ORG_GROUP",...t&&n?{tenantId:n}:{}};try{const j=await d.mutateAsync(x),D=j==null?void 0:j.id;D?r(D):a()}catch(j){y(j instanceof Error?j.message:"Failed to create group")}};return e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:[e.jsx(yt,{children:"Name"}),e.jsx("input",{autoFocus:!0,value:o,onChange:x=>u(x.target.value),placeholder:"Marketing leads, North America sales, …",maxLength:50,className:"mt-1 block h-7 w-full rounded-[5px] border border-border bg-background px-2 text-[12px] text-foreground placeholder:text-muted-foreground focus:border-foreground/40 focus:outline-none"}),e.jsx("div",{className:"mt-1 text-[10.5px] text-muted-foreground",children:"3–50 characters."}),e.jsxs("div",{className:"mt-4",children:[e.jsx(yt,{children:"Description (optional)"}),e.jsx("textarea",{rows:2,value:p,onChange:x=>c(x.target.value),maxLength:200,placeholder:"What is this group for?",className:"mt-1 block w-full resize-none rounded-[5px] border border-border bg-background px-2 py-1.5 text-[12px] text-foreground placeholder:text-muted-foreground focus:border-foreground/40 focus:outline-none"}),e.jsxs("div",{className:"mt-1 flex justify-end text-[10.5px] text-muted-foreground",children:[p.length,"/200"]})]}),v&&e.jsx("div",{className:"mt-3 rounded-[5px] border border-rose-200 bg-rose-50 px-2 py-1.5 text-[11.5px] text-rose-700 dark:border-rose-900/60 dark:bg-rose-950/30 dark:text-rose-300",children:v})]}),e.jsxs("div",{className:"flex shrink-0 items-center justify-end gap-1.5 border-t border-border bg-muted/30 px-5 py-2.5",children:[e.jsx("button",{type:"button",onClick:a,disabled:d.isPending,className:"h-7 rounded-[5px] px-2.5 text-[12px] font-medium text-foreground/80 hover:bg-accent",children:"Cancel"}),e.jsx("button",{type:"button",onClick:b,disabled:!m||d.isPending,className:"inline-flex h-7 items-center gap-1.5 rounded-[5px] bg-foreground px-2.5 text-[12px] font-medium text-background hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-60",children:d.isPending?e.jsxs(e.Fragment,{children:[e.jsx(l.LoaderCircle,{className:"h-3 w-3 animate-spin"}),"Creating…"]}):e.jsxs(e.Fragment,{children:[e.jsx(s.Plus,{className:"h-3 w-3"}),"Create group"]})})]})]})}function _s({query:t,setQuery:n,open:a,setOpen:r,candidates:o,showKindChip:u,onAdd:p,busy:c}){const v=f.useRef(null),y=f.useRef(null),[d,m]=f.useState(null);f.useLayoutEffect(()=>{if(!a){m(null);return}const x=()=>{const j=v.current;if(!j)return;const D=j.getBoundingClientRect(),N=240,h=window.innerHeight-D.bottom<N+16&&D.top>N;m({left:D.left,top:h?D.top-6:D.bottom+6,width:D.width,above:h})};return x(),window.addEventListener("resize",x),window.addEventListener("scroll",x,!0),()=>{window.removeEventListener("resize",x),window.removeEventListener("scroll",x,!0)}},[a,o.length]),f.useEffect(()=>{if(!a)return;const x=j=>{var N,C;const D=j.target;(N=v.current)!=null&&N.contains(D)||(C=y.current)!=null&&C.contains(D)||r(!1)};return document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[a,r]);const b=a&&o.length>0&&d;return e.jsxs("div",{className:"shrink-0 border-b border-border px-5 py-2.5",children:[e.jsxs("div",{ref:v,className:"flex items-center gap-2 rounded-[5px] border border-border bg-background px-2 focus-within:border-foreground/40",children:[e.jsx(hs,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("input",{value:t,onChange:x=>{n(x.target.value),r(!0)},onFocus:()=>r(!0),placeholder:"Add a member by name or email…",disabled:c,className:"h-7 flex-1 bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground focus:outline-none disabled:cursor-not-allowed"})]}),b&&typeof document<"u"&&ss.createPortal(e.jsx("div",{ref:y,style:{position:"fixed",left:d.left,top:d.top,width:d.width,transform:d.above?"translateY(-100%)":void 0},className:"z-[60] max-h-[240px] overflow-y-auto rounded-[5px] border border-border bg-background shadow-[0_8px_24px_-12px_rgba(0,0,0,0.18)]",children:o.map(x=>e.jsxs("button",{type:"button",onClick:()=>p(x),className:"flex w-full items-center gap-2 border-b border-border/60 px-2.5 py-2 text-left last:border-b-0 hover:bg-accent",children:[e.jsx(Pt,{name:x.name||x.email||"?"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[12px] font-medium text-foreground",children:x.name||x.email||"Unknown"}),x.email&&x.name&&e.jsx("div",{className:"truncate text-[10.5px] text-muted-foreground",children:x.email})]}),u&&x.type&&e.jsx("span",{className:"text-[10px] uppercase tracking-[0.06em] text-muted-foreground",children:x.type==="tenant"?"tenant":"org"})]},x.id))}),document.body)]})}function Et(t,n){if(!t)return n;if(t instanceof Error){const a=t.message||"",r=a.match(/\{[\s\S]*"error"\s*:\s*"([^"]+)"[\s\S]*\}/);return r?r[1]:a||n}return typeof t=="string"?t:n}function At({title:t,message:n,onRetry:a}){return e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 px-6 py-10 text-center",children:[e.jsx("div",{className:"text-[12.5px] font-medium text-foreground",children:t}),e.jsx("div",{className:"max-w-[360px] text-[11.5px] leading-[1.55] text-muted-foreground",children:n}),a&&e.jsx("button",{type:"button",onClick:a,className:"mt-1 inline-flex h-7 items-center rounded-[5px] border border-border bg-background px-2.5 text-[11.5px] font-medium text-foreground hover:bg-accent",children:"Try again"})]})}function yt({children:t}){return e.jsx("label",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:t})}function Pt({name:t}){const n=t.split(" ").map(a=>a[0]).filter(Boolean).slice(0,2).join("").toUpperCase();return e.jsx(It,{className:"h-6 w-6 shrink-0",children:e.jsx(Lt,{className:"text-[9px] font-semibold",children:n||"?"})})}function ce(t,n,a){var u,p;const r=(t.controls||[]).find(c=>c.id===a);if(r)return r.label;const o=(p=(u=l.findCardById(t,n))==null?void 0:u.controls)==null?void 0:p.find(c=>c.id===a);return(o==null?void 0:o.label)||a}function ue(t,n){var a;return((a=l.findCardById(t,n))==null?void 0:a.title)||n}function Hs(t){const{errors:n,dashboard:a}=t;if(!a)return n;const r=new Map;for(const o of n){const u=o.match(/^Card '(.+)' binding for control '(.+)' maps to missing metric '(.+)'\.$/);if(u){const[,d,m]=u,b=`${d}:${m}:missing-metric`;r.has(b)||r.set(b,`"${ue(a,d)}" has an outdated "${ce(a,d,m)}" mapping. Some choices still point to metrics that are no longer available on this card. Open the card controls and choose replacements.`);continue}const p=o.match(/^Card '(.+)' binding for control '(.+)' maps to missing group-by field '(.+)'\.$/);if(p){const[,d,m]=p,b=`${d}:${m}:missing-group-by`;r.has(b)||r.set(b,`"${ue(a,d)}" has an outdated "${ce(a,d,m)}" mapping. Some choices still point to fields that are no longer available on this card. Open the card controls and choose replacements.`);continue}const c=o.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid metric target\.$/);if(c){const[,d,m]=c,b=`${d}:${m}:invalid-metric`;r.has(b)||r.set(b,`"${ue(a,d)}" has an invalid "${ce(a,d,m)}" metric mapping. Open the card controls and choose a valid metric for each option.`);continue}const v=o.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid group-by target\.$/);if(v){const[,d,m]=v,b=`${d}:${m}:invalid-group-by`;r.has(b)||r.set(b,`"${ue(a,d)}" has an invalid "${ce(a,d,m)}" field mapping. Open the card controls and choose a valid field for each option.`);continue}const y=o.match(/^Card '(.+)' binding for control '(.+)' requires at least one temporal group-by field\.$/);if(y){const[,d,m]=y,b=`${d}:${m}:missing-temporal-group-by`;r.has(b)||r.set(b,`"${ue(a,d)}" can no longer use "${ce(a,d,m)}" for time grain because the card does not currently group by a date field.`);continue}r.set(o,o)}return Array.from(r.values())}function Ks({visible:t,onSelect:n}){return t?e.jsxs(s.DropdownMenuItem,{onSelect:n,children:[e.jsx(s.CalendarClock,{className:"h-3.5 w-3.5"}),"Schedule email report"]}):null}function Qs({scheduleReportVisible:t,analyticalBriefingVisible:n,onScheduleReport:a,onCreateAnalyticalBriefing:r}){return e.jsxs(e.Fragment,{children:[e.jsx(Ks,{visible:t,onSelect:a}),n?e.jsxs(s.DropdownMenuItem,{onSelect:r,children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Create analytical briefing"]}):null]})}function jt(t,n){return{dashboard:s.cloneDeep(t),semanticExecutionPayload:s.cloneDeep(n)}}function Ws(){var lt,ct,ut,mt,ht,pt,xt,ft;q.useExportRecovery(),q.useExportPolling();const{authToken:t,tokenProps:n,id:a,showBriefings:r}=s.useSemaphorContext(),o=s.useBriefingUiCapabilities(),{isLocalDev:u,preferences:p}=s.useDashboardPreferences(),c=((lt=p==null?void 0:p.uiMode)==null?void 0:lt.inspection)===!0,{openBrandStudioPreview:v}=s.useBrandStudioPreview(),{permissions:y}=ys(),d=s.useHasDashboardId(),{isLoading:m}=s.useDashboardQuery(),b=l.useDashboardStore(i=>i.theme),x=l.useDashboardStore(i=>i.isDownloadingPdf),j=l.useDashboardStore(i=>i.dashboardAssistantDraftScopeKey),D=l.useDashboardStore(i=>i.lenses),N=l.useDashboardStore(i=>i.selectedLensId),C=D==null?void 0:D.find(i=>i.id===N),h=l.useDashboardStore(i=>i.dashboard),F=l.useDashboardStore(i=>i.selectedSheetId),P=(ct=h==null?void 0:h.sheets)==null?void 0:ct.find(i=>i.id===F),w=l.isDocumentSheet(P),k=w?(ut=P==null?void 0:P.document)==null?void 0:ut.page:void 0,S=l.useDashboardStore(i=>i.isDashboardEditing),{setDashboardTitle:Q}=l.useDashboardStore(i=>i.actions),[Me,B]=f.useState(!1),[X,$]=f.useState(!1),[Y,Z]=f.useState(!1),[Ie,ee]=f.useState(!1),[me,W]=f.useState(null),[he,pe]=f.useState(!1),[Le,G]=f.useState(!1),[g,R]=f.useState(!1),[z,_]=f.useState(null),[te,H]=f.useState([]),[se,xe]=f.useState(!1),[Rt,We]=f.useState(!1),Je=l.useDashboardStore(i=>i.filterValues),L=l.useDashboardStore(i=>i.isVisualEditing);l.useEditorStore(i=>i.card);const re=s.useManagementStore(i=>i.selectedDashboard),fe=s.useManagementStore(i=>i.initialDashboard);s.useManagementStore(i=>i.selectedVisual),l.useDashboardStore(i=>i.selectedFrameId),l.useEditorStore(i=>i.frame);const ge=re?(ht=re==null?void 0:re.permissions)==null?void 0:ht.canEdit:(mt=fe==null?void 0:fe.permissions)==null?void 0:mt.canEdit,Xe=l.useDashboardStore(i=>i.showDashboardJSON),Ee=l.useDashboardStore(i=>i.onSaveFunction),{setIsDashboardEditing:Ye,setShowDashboardJSON:Ze}=l.useDashboardStore(i=>i.actions),{setInitialDashboard:et,clearSelectedDashboard:Ae}=s.useManagementStore(i=>i.actions),ae=!!n.orgUserId||!!(n.tenantId&&n.endUserId&&n.endUserEmail),{resources:be}=s.useResourceManagement(s.ResourceType.DASHBOARD),{data:Pe}=s.useUserPreferences(),Ut=((pt=Pe==null?void 0:Pe.preference)==null?void 0:pt.defaultDashboardId)||null,{mutate:Ft,isPending:Tt}=s.useDefaultDashboardMutation(),{currentUser:Ot}=s.useCurrentUserInfo(),Vt=s.canUserManageGroups(Ot),O=re||fe,J=s.resolveDashboardControlsVisibility({config:n.config,canNavigateDashboardHub:ae,canShareDashboard:((xt=O==null?void 0:O.permissions)==null?void 0:xt.canShare)===!0,canManageGroups:Vt}),tt=O?{id:O.id,title:(h==null?void 0:h.title)||O.title||"Dashboard"}:null,{handleAddNewFrame:qt}=s.useAddNewFrame(),[Re,Ue]=f.useState(!1),[Bt,ne]=f.useState(!1),[Fe,ve]=f.useState("close"),oe=s.useUpdateResource(s.ResourceType.DASHBOARD),[I,ye]=f.useState(null),$t=async(i,M)=>{if(!c){if(!(h!=null&&h.id)){console.log("No dashboard ID found");return}console.log("Updating dashboard title:",{dashboardId:h.id,newTitle:i,previousTitle:M}),oe.mutate({resourceId:h.id,data:{title:i}},{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"),Q(M)}})}};f.useEffect(()=>{if(be&&be.length>0){const i=h==null?void 0:h.id;if(i){const M=be.find(U=>U.id===i);M&&et(M)}}},[be,h==null?void 0:h.id,et]);const ie=n.orgUserId||n.tenantId,Te=f.useMemo(()=>Js({accessToken:t==null?void 0:t.accessToken,dashboardId:(h==null?void 0:h.id)||a||n.dashboard_id,selectedSheetId:w?F:void 0,pageSize:k==null?void 0:k.size,orientation:k==null?void 0:k.orientation,theme:b}),[t==null?void 0:t.accessToken,a,h==null?void 0:h.id,w,k==null?void 0:k.orientation,k==null?void 0:k.size,F,b,n.dashboard_id]),st=S&&!L&&!c&&ie&&ge,{setDashboard:Oe}=l.useDashboardStore(i=>i.actions),rt=l.useDashboardStore(i=>i.semanticExecutionPayload),Gt=()=>{Ye(!0)},je=()=>{Ye(!1),Ze(!1),ye(null)};f.useEffect(()=>{if(!S){I&&ye(null);return}I||!h||m||ye(jt(h,rt))},[h,I,S,m,rt]);const we=(I==null?void 0:I.dashboard)??null,{isDirty:at,isDirtyPending:zt,resetDirty:de}=as.useDebouncedDirtyCheck(h,we,300,1e3,Ge.serializeDashboardForDirtyCheck),nt=f.useCallback(()=>we?Ge.serializeDashboardForDirtyCheck(h)!==Ge.serializeDashboardForDirtyCheck(we):!1,[h,we]),ot=at||zt,De=Re||oe.isPending,_t=()=>{if(c){I&&Oe(I.dashboard,{semanticExecutionPayload:I.semanticExecutionPayload}),je(),de();return}nt()?(ve("close"),ne(!0)):(je(),de())},Ht=async()=>{await Ve({closeAfterSave:!0,navigateHomeAfterSave:Fe==="home"})},Kt=()=>{const i=Fe==="home"&&!!ae;I&&Oe(I.dashboard,{semanticExecutionPayload:I.semanticExecutionPayload}),je(),i&&Ae(),ve("close"),ne(!1),de()},Qt=()=>{I&&(Oe(I.dashboard,{semanticExecutionPayload:I.semanticExecutionPayload}),de())},Wt=()=>{if(ae){if(S&&nt()){ve("home"),ne(!0);return}Ae()}};async function Ve(i){if(c)return;const M=l.useDashboardStore.getState().dashboard;if(!M)return;const U=(i==null?void 0:i.closeAfterSave)??se,qe=(i==null?void 0:i.navigateHomeAfterSave)??!1;xe(U),U&&ne(!1);const Be=s.cloneDeep(M);R(!0),_(null),H([]),Ue(!0);const ts={template:M};oe.mutate({resourceId:M.id,data:ts},{onSuccess:E=>{var Ne,Se,gt;const K=(E==null?void 0:E.id)||((Ne=E==null?void 0:E.dashboard)==null?void 0:Ne.id)||((Se=E==null?void 0:E.resource)==null?void 0:Se.id)||((gt=E==null?void 0:E.template)==null?void 0:gt.id)||null;if(!M.id&&K){const $e=l.useAIInteractionStore.getState(),Ce=$e.pendingDashboardDraftMigration;(Ce==null?void 0:Ce.scopeKey)===j?$e.actions.setPendingDashboardDraftMigrationExpectedDashboardId(K):Ce&&$e.actions.clearPendingDashboardDraftMigration()}Ue(!1),s.ue.success("Dashboard saved!"),ye(jt(Be,l.useDashboardStore.getState().semanticExecutionPayload)),R(!1),xe(!1),U&&(je(),de(),qe&&ae&&Ae()),ve("close")},onError:E=>{Ue(!1),_("Failed to save dashboard. Please try again.");const K=E.details,Ne=Array.isArray(K==null?void 0:K.errors)?(K.errors||[]).filter(Se=>typeof Se=="string"):[];H(Hs({errors:Ne,dashboard:M||void 0})),s.ue.error("Failed to save dashboard")}})}async function Jt(){if(c||(B(!0),!N||!C))return;const i=l.useDashboardStore.getState().dashboard;if(!i){B(!1);return}const M=JSON.stringify(i),U=l.useDashboardStore.getState(),qe=St({dashboard:i,dashboardInputValues:U.dashboardInputValues,filterValues:Je,controlValues:U.controlValues,inlineFilterValuesMap:U.inlineFilterValuesMap,cardControlValuesMap:U.cardControlValuesMap}),Be={...C,template:M,filterValues:Je,inputValues:qe};await ze(n.apiServiceUrl,Be,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),Ee==null||Ee(i),B(!1)}const it=(C==null?void 0:C.name)||h.title;oe.isPending&&console.log("Title during update:",{title:it,dashboardStateTitle:h.title,dashboardId:h==null?void 0:h.id,currentLensName:C==null?void 0:C.name});const Xt=ae&&!!(t!=null&&t.accessToken)&&!!(n!=null&&n.apiServiceUrl),Yt=!c&&J.showDashboardHub&&Xt,Zt=!c&&d&&J.showDashboardHub,V=(h==null?void 0:h.id)||null,dt=s.resolveDashboardBriefingsVisibility((ft=n.config)==null?void 0:ft.showBriefings,r),le=!!V&&Ut===V,es=()=>{!V||c||Ft({dashboardId:le?null:V})};return!d&&!L?null:e.jsxs("div",{className:"flex h-11 shrink-0 items-center justify-between gap-2 overflow-x-auto border-b px-4 py-2",role:"dashboard-controls",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[Zt&&!L&&e.jsx(s.IconButton,{"aria-label":"Dashboard Hub",tooltip:"Dashboard Hub",onClick:Wt,className:"h-7 w-7 px-0",buttonProps:{size:"xs"},children:e.jsx(s.House,{className:"h-3.5 w-3.5"})}),!L&&d&&(m?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:it||"Untitled Dashboard",onSave:i=>{console.log("EditableText onSave called:",{newTitle:i,canEditDashboard:ge,dashboardId:h==null?void 0:h.id});const M=(h==null?void 0:h.title)||"";Q(i),$t(i,M)},isEditable:s.resolveDashboardTitleEditability({isDashboardEditing:S,canEditDashboard:ge===!0&&!c,hasCurrentLens:!!C}),displayClassName:"text-[13px] font-medium",inputClassName:"text-[13px] font-medium",placeholder:"Dashboard Title",isPending:oe.isPending}),J.showDashboardHub&&le&&e.jsx("span",{className:"shrink-0 rounded-[4px] border border-border/60 px-1.5 py-px text-[10px] font-medium uppercase tracking-[0.06em] text-muted-foreground",title:"Default dashboard",children:"Default"}),Yt&&V&&e.jsx(l.TooltipProvider,{children:e.jsxs(l.Tooltip,{children:[e.jsx(l.TooltipTrigger,{asChild:!0,children:e.jsx(l.Button,{variant:"ghost",size:"xs",onClick:es,disabled:Tt||!(t!=null&&t.accessToken)||!(n!=null&&n.apiServiceUrl),className:"w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":le?"Clear default dashboard":"Set as default dashboard",children:le?e.jsx(s.PinOff,{className:"h-3.5 w-3.5"}):e.jsx(s.Pin,{className:"h-3.5 w-3.5"})})}),e.jsx(l.TooltipContent,{children:e.jsx("p",{children:le?"Clear default":"Set as default"})})]})})]}))]}),e.jsxs("div",{className:"flex items-center gap-2",children:[L&&e.jsxs(e.Fragment,{children:[e.jsx(q.AdvancedModeToggle,{}),e.jsx(q.VisualEditingControls,{})]}),!L&&d&&!c&&J.showDashboardSharing&&e.jsxs(l.Button,{variant:"outline",size:"xs",onClick:()=>$(!0),children:[e.jsx(s.Share2,{className:"h-3.5 w-3.5"}),"Share"]}),!L&&S&&!c&&y.canUseFilters&&d&&e.jsx(q.DashboardFilterControlsLauncher,{}),S&&!L&&!c&&ie&&C&&u&&d&&e.jsxs(l.Button,{variant:"secondary",size:"xs",disabled:Me,onClick:Jt,children:[e.jsx(bt.Save,{className:"h-3.5 w-3.5"}),"Save Lens"]}),S&&!L&&!c&&d&&!w&&e.jsxs("div",{className:"inline-flex h-7 items-stretch overflow-hidden rounded-control border border-input bg-background",children:[e.jsxs(l.Button,{variant:"ghost",size:"xs",disabled:!S,onClick:()=>void qt(),className:"h-full rounded-none border-0 shadow-none hover:bg-accent",children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Visual"]}),e.jsxs(s.DropdownMenu,{modal:!1,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(l.Button,{variant:"ghost",size:"xs",className:"h-full w-7 rounded-none border-0 border-l border-border/60 px-0 shadow-none hover:bg-accent","aria-label":"Open visual options",disabled:!S,children:e.jsx(T.ChevronDown,{className:"h-3.5 w-3.5"})})}),e.jsx(s.DropdownMenuContent,{align:"end",className:"z-[60] w-48 rounded-[6px] border-border/60 p-1 shadow-sm",children:e.jsxs(s.DropdownMenuItem,{onClick:()=>We(!0),children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"From library..."]})})]}),e.jsx(q.VisualsLibraryDialog,{open:Rt,onOpenChange:We})]}),!L&&!S&&(ge||c)&&d&&e.jsxs(l.Button,{size:"xs",onClick:Gt,children:[e.jsx(s.Pencil,{className:"h-3.5 w-3.5"}),"Edit"]}),st&&d&&at&&e.jsxs(l.Button,{variant:"outline",size:"xs",onClick:Qt,disabled:De,children:[e.jsx(s.Undo2,{className:"h-3.5 w-3.5"}),"Undo"]}),st&&d&&e.jsxs(l.Button,{size:"xs",className:l.cn(!ot&&"opacity-60"),disabled:De||!ot,onClick:()=>Ve(),children:[De?e.jsx(l.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(bt.Save,{className:"h-3.5 w-3.5"}),De?"Saving...":"Save"]}),S&&!L&&d&&e.jsxs(l.Button,{variant:"outline",size:"xs",onClick:_t,children:[e.jsx(s.Cross2Icon,{className:"h-3.5 w-3.5"}),"Close"]}),!L&&d&&e.jsx("div",{className:"ml-2",children:e.jsx(q.NotificationBell,{})}),!L&&u&&e.jsx(ps,{}),!L&&d&&!c&&e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"More Options",className:"w-7 px-0 text-muted-foreground hover:text-foreground",buttonProps:{size:"xs",variant:"ghost","aria-label":"More dashboard options"},children:e.jsx(s.EllipsisVertical,{className:"h-3.5 w-3.5"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-56 rounded-control border border-border/60 p-1 shadow-sm",children:[e.jsx(s.DropdownMenuLabel,{children:"Reports & briefings"}),e.jsxs(s.DropdownMenuItem,{disabled:x,onSelect:()=>G(!0),children:[e.jsx(s.Download,{className:"h-3.5 w-3.5"}),"Export"]}),e.jsx(Qs,{scheduleReportVisible:!!(dt&&o.surfaceVisible&&V&&!S),analyticalBriefingVisible:!!(dt&&o.surfaceVisible&&V&&!S),onScheduleReport:()=>W("scheduled_report"),onCreateAnalyticalBriefing:()=>W("analytical_briefing")}),e.jsx(s.DropdownMenuSeparator,{}),J.showGroupManagement&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuLabel,{children:"Access"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>Z(!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:()=>ee(!0),children:[e.jsx(s.Calendar,{className:"h-3.5 w-3.5"}),"Report preferences"]}),u&&d&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuSeparator,{}),e.jsx(s.DropdownMenuLabel,{children:"Developer"}),e.jsxs(s.DropdownMenuItem,{onSelect:()=>{var i;t!=null&&t.accessToken&&((i=navigator==null?void 0:navigator.clipboard)!=null&&i.writeText?navigator.clipboard.writeText(t.accessToken).then(()=>s.ue.success("Token copied to clipboard")).catch(()=>s.ue.error("Unable to copy token")):s.ue.error("Clipboard not available"))},children:[e.jsx(s.Copy,{className:"h-3.5 w-3.5"}),"Copy token"]}),w&&e.jsxs(s.DropdownMenuItem,{disabled:!Te,onSelect:()=>{var i;if(!Te){s.ue.error("Open a document sheet with a token to copy the local PDF URL");return}(i=navigator==null?void 0:navigator.clipboard)!=null&&i.writeText?navigator.clipboard.writeText(Te).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:()=>l.invalidateToken(n.apiServiceUrl),children:[e.jsx(us,{className:"h-3.5 w-3.5"}),"Invalidate token"]}),e.jsxs(s.DropdownMenuItem,{onSelect:v,children:[e.jsx(ns.Palette,{className:"h-3.5 w-3.5"}),"Brand Studio"]}),S&&e.jsxs(s.DropdownMenuItem,{onSelect:()=>Ze(!Xe),children:[e.jsx(os.Braces,{className:"h-3.5 w-3.5"}),Xe?"Hide dashboard JSON":"Show dashboard JSON"]}),ie&&S&&e.jsxs(s.DropdownMenuItem,{onSelect:()=>pe(!0),children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Add lens"]}),ie&&e.jsxs(s.DropdownMenuSub,{children:[e.jsxs(s.DropdownMenuSubTrigger,{children:[e.jsx(ds,{className:"h-3.5 w-3.5"}),"Lenses"]}),e.jsx(s.DropdownMenuSubContent,{className:"w-60",children:e.jsx(vs,{})})]})]})]})]}),X&&tt&&e.jsx(s.ShareDialog,{resource:tt,resourceType:s.ResourceType.DASHBOARD,onClose:()=>$(!1)}),J.showGroupManagement&&e.jsx(Vs,{open:Y,onOpenChange:Z}),e.jsx(rs.ReportPreferencesDialog,{open:Ie,onOpenChange:ee}),V&&me?e.jsx(q.DashboardBriefingLauncher,{dashboardId:V,dashboardTitle:(h==null?void 0:h.title)||(O==null?void 0:O.title),open:!0,onOpenChange:i=>{i||W(null)},hideTrigger:!0,workflowIntent:me}):null,u&&ie&&d&&e.jsx(bs,{open:he,onOpenChange:pe}),d&&e.jsx(s.DownloadPdf,{open:Le,onOpenChange:G}),e.jsx(s.AlertDialog,{open:g,onOpenChange:i=>{!i&&Re&&!z||(R(i),i||(_(null),H([]),xe(!1)))},children:e.jsxs(s.AlertDialogContent,{className:"max-w-sm",children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:z?"Save failed":"Saving dashboard"}),e.jsx(s.AlertDialogDescription,{className:"pt-2",children:z?"We could not save the dashboard. Please try again.":"Please wait while we save your changes."}),te.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:te.slice(0,5).map(i=>e.jsx("li",{children:i},i))})]})]}),e.jsx(s.AlertDialogFooter,{className:"flex-col gap-2 sm:flex-row sm:justify-end",children:z?e.jsxs(e.Fragment,{children:[e.jsx(s.AlertDialogCancel,{onClick:()=>{R(!1),_(null),H([]),xe(!1)},className:"m-0",children:"Close"}),e.jsx(s.AlertDialogAction,{onClick:()=>Ve({closeAfterSave:se,navigateHomeAfterSave:Fe==="home"}),className:"m-0",children:"Retry"})]}):e.jsxs(s.AlertDialogAction,{disabled:!0,className:"m-0 cursor-default",children:[e.jsx(l.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]})})]})}),e.jsx(q.UnsavedChangesAlert,{open:Bt,onOpenChange:i=>{ne(i)},onSave:Ht,onDiscard:Kt,isSaving:Re,saveLabel:"Save",discardLabel:"Discard"})]})]})}function Js({accessToken:t,dashboardId:n,selectedSheetId:a,pageSize:r,orientation:o,theme:u}){if(!t||!a)return null;const p=new URL("http://localhost:5173/print-document");p.searchParams.set("token",t),n&&p.searchParams.set("dashboardId",n),p.searchParams.set("selectedSheetId",a),u&&p.searchParams.set("theme",u);const c=new URL("http://127.0.0.1:3002/");return c.searchParams.set("pdfMode","document"),c.searchParams.set("pageSize",r||"letter"),c.searchParams.set("orientation",o||"portrait"),c.searchParams.set("url",p.toString()),c.toString()}exports.default=Ws;
|