react-semaphor 0.1.302 → 0.1.304

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/appearance/index.cjs +1 -1
  2. package/dist/appearance/index.js +1 -1
  3. package/dist/brand-studio/index.cjs +5 -5
  4. package/dist/brand-studio/index.js +334 -385
  5. package/dist/chunks/common-types-C6cAQgyh.js +9 -0
  6. package/dist/chunks/common-types-nBuCd3u2.js +1 -0
  7. package/dist/chunks/{dashboard-controls-CZuC_QjN.js → dashboard-controls-CyFZfGaN.js} +800 -776
  8. package/dist/chunks/dashboard-controls-DCZnUFI0.js +47 -0
  9. package/dist/chunks/{dashboard-filter-controls-button-kfb_T18o.js → dashboard-filter-controls-button-DI7XUgZK.js} +142 -142
  10. package/dist/chunks/{dashboard-filter-controls-button-2I1ltWQ9.js → dashboard-filter-controls-button-YQZ-oeN5.js} +3 -3
  11. package/dist/chunks/{dashboard-json-Df6v2Jem.js → dashboard-json-C6R2qixD.js} +3 -3
  12. package/dist/chunks/{dashboard-json-C3v6rBdp.js → dashboard-json-Z8jz16Yj.js} +1 -1
  13. package/dist/chunks/{dashboard-summary-settings-dialog-DKAaWq-G.js → dashboard-summary-settings-dialog-BlD77h63.js} +2 -2
  14. package/dist/chunks/{dashboard-summary-settings-dialog-BBALEHJQ.js → dashboard-summary-settings-dialog-DJyY-PB9.js} +1 -1
  15. package/dist/chunks/{edit-dashboard-visual-CGBYahAK.js → edit-dashboard-visual-CNGc1zcN.js} +33 -33
  16. package/dist/chunks/{edit-dashboard-visual-D8L0cl_U.js → edit-dashboard-visual-CfRJXwDR.js} +167 -168
  17. package/dist/chunks/{index-uRJmUpof.js → index-CJdxSyQq.js} +679 -656
  18. package/dist/chunks/index-D2vz3gvd.js +1360 -0
  19. package/dist/chunks/index-DRlMUglg.js +4 -0
  20. package/dist/chunks/{index-BmoR3VQT.js → index-GHhvGdF9.js} +42745 -40322
  21. package/dist/chunks/{palette-326-dgn0.js → palette-BqJlrRto.js} +7 -2
  22. package/dist/chunks/{palette-jd7xiGTg.js → palette-DD-i7bNS.js} +23 -3
  23. package/dist/chunks/{resource-management-panel-C_c-BwrC.js → resource-management-panel-7Y4ITzGH.js} +65 -65
  24. package/dist/chunks/{resource-management-panel-DrcEEARD.js → resource-management-panel-Bdus73Iu.js} +1 -1
  25. package/dist/chunks/{rotate-ccw-BugHcM1w.js → rotate-ccw-CdGW8Rxm.js} +1 -1
  26. package/dist/chunks/{rotate-ccw-yFwqBFJZ.js → rotate-ccw-X8MbX_hF.js} +1 -1
  27. package/dist/chunks/{save-CaybXtdd.js → save-CFBIhbHD.js} +1 -1
  28. package/dist/chunks/{save-DU0FXUlM.js → save-j-clxFtx.js} +1 -1
  29. package/dist/chunks/{switch-CZtMtqEj.js → switch-BFhVVwh9.js} +4285 -3275
  30. package/dist/chunks/switch-BH17qlxH.js +163 -0
  31. package/dist/chunks/use-create-flow-overlay-state-CSytlf2H.js +16 -0
  32. package/dist/chunks/{use-create-flow-overlay-state-84Xe8VrP.js → use-create-flow-overlay-state-CllZvyvE.js} +318 -316
  33. package/dist/chunks/{use-visual-utils-lp5DfmvL.js → use-visual-utils-CDO4kVX5.js} +1 -1
  34. package/dist/chunks/{use-visual-utils-z3ifg6Fd.js → use-visual-utils-CyjLzcDG.js} +2 -2
  35. package/dist/dashboard/index.cjs +1 -1
  36. package/dist/dashboard/index.js +5 -5
  37. package/dist/index.cjs +1 -1
  38. package/dist/index.js +61 -60
  39. package/dist/style.css +1 -1
  40. package/dist/surfboard/index.cjs +1 -1
  41. package/dist/surfboard/index.js +6 -6
  42. package/dist/types/dashboard.d.ts +168 -0
  43. package/dist/types/index.cjs +1 -1
  44. package/dist/types/index.js +8 -11
  45. package/dist/types/main.d.ts +195 -2
  46. package/dist/types/shared.d.ts +120 -0
  47. package/dist/types/surfboard.d.ts +168 -0
  48. package/dist/types/types.d.ts +168 -0
  49. package/package.json +1 -1
  50. package/dist/chunks/braces-CpOcaBNm.js +0 -6
  51. package/dist/chunks/braces-TYclg8Hl.js +0 -23
  52. package/dist/chunks/dashboard-controls-BkuB9TQX.js +0 -47
  53. package/dist/chunks/index-Cxb9UUro.js +0 -4
  54. package/dist/chunks/index-eM6MU4q_.js +0 -1361
  55. package/dist/chunks/switch-AmoR1YIA.js +0 -163
  56. package/dist/chunks/use-create-flow-overlay-state-CiKVJGWF.js +0 -16
@@ -1,11 +1,11 @@
1
- "use strict";const g=require("react"),t=require("./index-eM6MU4q_.js"),e=require("react/jsx-runtime"),a=require("./switch-AmoR1YIA.js"),F=require("./use-create-flow-overlay-state-CiKVJGWF.js"),R=require("./use-visual-utils-lp5DfmvL.js"),U=require("./date-formatter-D9Bvw5Qk.js");/**
1
+ "use strict";const g=require("react"),t=require("./index-D2vz3gvd.js"),e=require("react/jsx-runtime"),r=require("./switch-BH17qlxH.js"),F=require("./use-create-flow-overlay-state-CSytlf2H.js"),R=require("./use-visual-utils-CDO4kVX5.js"),U=require("./date-formatter-D9Bvw5Qk.js");/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
5
5
  * See the LICENSE file in the root directory of this source tree.
6
- */const V=a.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"}]]);/**
6
+ */const V=r.createLucideIcon("FileDown",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M12 18v-6",key:"17g6i2"}],["path",{d:"m9 15 3 3 3-3",key:"1npd3o"}]]);/**
7
7
  * @license lucide-react v0.453.0 - ISC
8
8
  *
9
9
  * This source code is licensed under the ISC license.
10
10
  * See the LICENSE file in the root directory of this source tree.
11
- */const $=a.createLucideIcon("FilterX",[["path",{d:"M13.013 3H2l8 9.46V19l4 2v-8.54l.9-1.055",key:"1fi1da"}],["path",{d:"m22 3-5 5",key:"12jva0"}],["path",{d:"m17 3 5 5",key:"k36vhe"}]]),_=1e4,q=15e3,X=3e4,G=3e4,Q=12e4,O=2*60*60*1e3;function K(s){const r=Date.now()-s.getTime();return r<G?_:r<Q?q:X}function W(){const{authToken:s,tokenProps:r}=t.useSemaphorContext(),v=t.useExportStore(x=>x.activeExports),[d,i]=g.useState(typeof document<"u"?!document.hidden:!0),c=g.useRef(null),u=g.useRef(!1),m=g.useRef(void 0),l=r==null?void 0:r.apiServiceUrl,o=s==null?void 0:s.accessToken,p=g.useCallback(()=>{const x=t.useExportStore.getState().activeExports;return Array.from(x.values()).filter(y=>t.isExportInProgress(y.status))},[]);g.useEffect(()=>{if(typeof document>"u")return;const x=()=>{i(!document.hidden)};return document.addEventListener("visibilitychange",x),()=>{document.removeEventListener("visibilitychange",x)}},[]);const C=g.useCallback(async()=>{if(!l||!o){u.current=!1;return}const x=p();if(x.length===0){u.current=!1;return}const y=Date.now(),N=x.filter(n=>y-n.startedAt.getTime()>O);if(N.length>0){const{updateExport:n}=t.useExportStore.getState().actions;for(const w of N)n(w.id,{status:"failed",error:"Export timed out. Please try again or contact support.",lastUpdatedAt:new Date})}const f=x.filter(n=>y-n.startedAt.getTime()<=O);if(f.length===0){u.current=!1;return}const j=await Promise.allSettled(f.map(async n=>{try{const w=await t.getExportStatus(l,o,n.id);let E;if(w.status==="completed")try{E=await t.getDownloadUrl(l,o,n.id)}catch(L){console.error(`[useExportPolling] Failed to get download URL for ${n.id}:`,L)}return{id:n.id,status:w.status,progress:w.progress,completedChunks:w.completedChunks,completedAt:w.completedAt?new Date(w.completedAt):void 0,lastUpdatedAt:new Date,fileSize:w.fileSize,error:w.error,downloadUrl:E}}catch(w){return console.error(`[useExportPolling] Failed to poll export ${n.id}:`,w),null}})),{updateExport:A}=t.useExportStore.getState().actions;for(const n of j)n.status==="fulfilled"&&n.value&&A(n.value.id,n.value);const D=p();if(D.length>0&&!document.hidden){const n=D.reduce((E,L)=>L.startedAt<E?L.startedAt:E,D[0].startedAt),w=K(n);c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{var E;(E=m.current)==null||E.call(m)},w)}else u.current=!1},[l,o,p]);return g.useEffect(()=>{m.current=C},[C]),g.useEffect(()=>{var y;p().length>0&&d&&!u.current&&(u.current=!0,(y=m.current)==null||y.call(m))},[v,d,p]),g.useEffect(()=>{var y;const x=p();d&&x.length>0&&!u.current&&(u.current=!0,(y=m.current)==null||y.call(m))},[d,p]),g.useEffect(()=>{!d&&c.current&&(clearTimeout(c.current),c.current=null,u.current=!1)},[d]),g.useEffect(()=>()=>{c.current&&(clearTimeout(c.current),c.current=null)},[]),{isPolling:u.current,isTabVisible:d,inProgressCount:p().length}}function Y(){const{authToken:s,tokenProps:r}=t.useSemaphorContext(),v=t.useExportStore(m=>m.activeExports),{addExport:d}=t.useExportActions(),i=g.useRef(!1),c=r==null?void 0:r.apiServiceUrl,u=s==null?void 0:s.accessToken;g.useEffect(()=>{if(i.current||!c||!u)return;(async()=>{try{const{exports:l}=await t.getExports(c,u,{status:["pending","processing","chunking","compacting","completed","failed"],limit:20});for(const o of l){if(v.has(o.id))continue;const p=o.totalChunks?Math.round(o.completedChunks/o.totalChunks*100):0;let C;if(o.status==="completed")try{C=await t.getDownloadUrl(c,u,o.id)}catch(y){console.error(`[useExportRecovery] Failed to get download URL for ${o.id}:`,y)}const x={id:o.id,status:o.status,progress:p,title:Z(o),totalRows:o.totalRows,totalChunks:o.totalChunks,completedChunks:o.completedChunks,startedAt:new Date(o.createdAt),lastUpdatedAt:new Date,completedAt:o.completedAt?new Date(o.completedAt):void 0,fileSize:o.fileSize,error:o.error,expiresAt:new Date(o.expiresAt),downloadUrl:C};d(x)}i.current=!0}catch(l){console.error("[useExportRecovery] Failed to recover exports:",l),i.current=!0}})()},[c,u,d,v])}function Z(s){return s.title?s.title:t.isExportInProgress(s.status)?"Export in progress...":s.status==="completed"?"Export completed":s.status==="failed"?"Export failed":"Export"}function J({open:s,onOpenChange:r,isLibraryVisual:v,currentVisualName:d,isSaving:i=!1,destinationMode:c="both",onConfirm:u}){const[m,l]=g.useState(v&&d?`Copy of ${d}`:d||""),[o,p]=g.useState("");g.useEffect(()=>{s&&(l(v&&d?`Copy of ${d}`:d||""),p(""))},[s,v,d]);const C=!!m.trim(),x=c==="local"?{saveToLibrary:!1,saveToCurrentDashboard:!0,badgeType:"local",description:"Creates a local copy on the current dashboard.",actionLabel:"Add to Dashboard (Local)"}:c==="library"?{saveToLibrary:!0,saveToCurrentDashboard:!1,badgeType:"library",description:"Creates a reusable visual in Visual Library.",actionLabel:"Save as Library Visual"}:{saveToLibrary:!0,saveToCurrentDashboard:!0,badgeType:"linked",description:"Creates a new library visual and adds a linked copy to this dashboard.",actionLabel:"Save Copy as Linked Visual"},y=()=>{!C||i||u({name:m.trim(),description:o.trim()||void 0,saveToLibrary:x.saveToLibrary,saveToCurrentDashboard:x.saveToCurrentDashboard})};return e.jsx(t.Dialog,{open:s,onOpenChange:r,children:e.jsxs(t.DialogContent,{className:"sm:max-w-[500px]",children:[e.jsxs(t.DialogHeader,{children:[e.jsxs(t.DialogTitle,{className:"flex items-center gap-2",children:[e.jsx("span",{children:"Save Visual As"}),x.badgeType!=="local"&&e.jsx(F.VisualBadge,{type:x.badgeType,showLabel:!0,className:"px-2 py-0.5"})]}),e.jsx(t.DialogDescription,{children:x.description})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(a.Label,{htmlFor:"name",children:"Name"}),e.jsx(a.Input,{id:"name",value:m,onChange:N=>l(N.target.value),placeholder:"Enter visual name",disabled:i})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(a.Label,{htmlFor:"description",children:"Description (optional)"}),e.jsx(t.Textarea,{id:"description",value:o,onChange:N=>p(N.target.value),placeholder:"Enter visual description",rows:3,disabled:i})]})]}),e.jsxs(t.DialogFooter,{children:[e.jsx(a.Button,{variant:"outline",onClick:()=>r(!1),disabled:i,children:"Cancel"}),e.jsxs(a.Button,{onClick:y,disabled:!C||i,children:[i&&e.jsx(a.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),x.actionLabel]})]})]})})}function ee(){const[s,r]=g.useState(!1),[v,d]=g.useState(!1),[i,c]=g.useState(null),[u,m]=g.useState(null),l=a.useEditorStore(h=>h.frame),o=a.useEditorStore(h=>h.card),p=t.useSelectedVisual(),C=a.useDashboardStore(h=>h.selectedSheetId),x=a.useDashboardStore(h=>h.dashboard),y=a.useDashboardStore(h=>h.actions.setIsDashboardPanelOpen),{getUpdatedFrame:N}=R.useVisualUtils(),{selectVisual:f}=t.useManagementActions(),{addFrame:j,setSelectedFrameId:A,setIsVisualEditing:D}=a.useDashboardActions(),n=t.useResolveExistingFrameSemanticExecutionPayload(),w=!!(l!=null&&l.visualId),E=(()=>{var h,b;return((h=l==null?void 0:l.cards)==null?void 0:h.length)===1&&((b=l.cards[0])!=null&&b.title)?l.cards[0].title:p!=null&&p.title?p.title:(o==null?void 0:o.title)||"Untitled Visual"})(),L=t.useCreateVisualWithFrame(h=>{h!=null&&h.id&&(f(h),v&&i&&u&&C&&(async()=>{try{const b={...i,id:a.v4(),visualId:h.id};j(C,b,{position:"end",semanticExecutionPayload:u}),A(b.id),d(!1),c(null),m(null),D(!1)}catch(b){console.error("Failed to promote semantic metadata for saved visual:",b),t.ue.error(b instanceof Error?b.message:"Failed to prepare semantic metadata for the saved visual")}})(),y(!0),r(!1))});return{saveAsDialogOpen:s,setSaveAsDialogOpen:r,handleSaveAs:async h=>{if(!C){t.ue.error("No sheet selected");return}const b=N(),I=a.getDynamicFrameSaveIssue(b);if(I){t.ue.error(I);return}const P=b.cards.length===1?{...b,cards:b.cards.map(T=>({...T,title:h.name}))}:b;if(h.saveToLibrary){let T=null;if(h.saveToCurrentDashboard)try{T=await n(P,{previousFrame:t.findDashboardFrameById(x,P.id)})}catch(M){console.error("Failed to prepare semantic metadata before saving visual:",M),t.ue.error(M instanceof Error?M.message:"Failed to prepare semantic metadata for the saved visual");return}d(h.saveToCurrentDashboard),c(P),m(T);const B={title:h.name,description:h.description,frameObject:P,isPrivate:!1};L.mutate(B)}else if(h.saveToCurrentDashboard){const T={...P,id:a.v4(),visualId:void 0};try{const B=await n(P,{previousFrame:t.findDashboardFrameById(x,P.id)});j(C,T,{position:"end",semanticExecutionPayload:B}),A(T.id),t.ue.success("Visual saved to dashboard"),r(!1),D(!1)}catch(B){console.error("Failed to save visual to dashboard:",B),t.ue.error(B instanceof Error?B.message:"Failed to prepare semantic metadata for the visual")}}},isLibraryVisual:w,currentVisualName:E,isSaving:L.isPending}}function te(s={}){const r=a.useEditorStore(S=>S.frame),v=a.useEditorStore(S=>S.editorContext),d=t.useManagementStore(S=>S.selectedVisual),i=a.useDashboardStore(S=>S.selectedFrameId),c=a.useDashboardStore(S=>S.selectedSheetId),u=a.useDashboardStore(S=>S.dashboard),{setIsVisualEditing:m,updateFrame:l}=a.useDashboardActions(),[o,p]=g.useState(!1),[C,x]=g.useState("both"),y=t.useResolveExistingFrameSemanticExecutionPayload(),N=(v==null?void 0:v.type)==="documentSection",f=!!(r!=null&&r.visualId||d!=null&&d.id),j=!!(r!=null&&r.visualId&&i),A=f&&!j,{saveAsDialogOpen:D,setSaveAsDialogOpen:n,handleSaveAs:w,isLibraryVisual:E,currentVisualName:L,isSaving:k}=ee(),{getUpdatedFrame:h}=R.useVisualUtils();if(N)return e.jsxs(e.Fragment,{children:[e.jsx(F.EditorAcceptButton,{className:"rounded-control",variant:"default"}),e.jsx(F.EditorCancelButton,{})]});const b=async()=>{if(!c){t.ue.error("No sheet selected");return}if(o)return;p(!0);const S=h(),P=a.getDynamicFrameSaveIssue(S);if(P){p(!1),t.ue.error(P);return}const T={...S,visualId:void 0},B=t.findDashboardFrameById(u,T.id);try{const M=await y(T,{previousFrame:B});l(c,T,{semanticExecutionPayload:M})}catch(M){console.error("Failed to apply local semantic metadata:",M),p(!1),t.ue.error(M instanceof Error?M.message:"Failed to prepare semantic metadata for this visual");return}setTimeout(()=>{p(!1),t.ue.success("Changes applied. Visual is now local to this dashboard"),m(!1)},300)},I=S=>{x(S),n(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"inline-flex items-center overflow-hidden rounded-control",children:[!f&&e.jsx(F.EditorAcceptButton,{className:"!rounded-none",variant:"default"}),f&&A&&e.jsx(F.VisualSaveButton,{className:"!rounded-none",variant:"default"}),f&&j&&e.jsx(F.VisualSaveAndApplyButton,{className:"!rounded-none"}),e.jsxs(t.DropdownMenu,{modal:!1,children:[e.jsx(t.DropdownMenuTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"default",size:"xs",className:"w-7 !rounded-none border-l border-primary-foreground/20 px-0","aria-label":"Open visual save options",disabled:k||o,children:e.jsx(a.ChevronDown,{className:"h-3.5 w-3.5"})})}),e.jsxs(t.DropdownMenuContent,{align:"end",className:"min-w-[220px] rounded-control border border-border/60 p-1 shadow-sm",children:[j&&e.jsxs(e.Fragment,{children:[e.jsxs(t.DropdownMenuItem,{onClick:b,disabled:o,children:[e.jsx(a.Check,{className:"h-3.5 w-3.5"}),o?"Applying...":"Apply Locally"]}),e.jsx(t.DropdownMenuSeparator,{})]}),e.jsxs(t.DropdownMenuItem,{onClick:()=>I("local"),disabled:k,children:[e.jsx(t.Plus,{className:"h-3.5 w-3.5"}),"Add to Dashboard (Local)"]}),e.jsxs(t.DropdownMenuItem,{onClick:()=>I("library"),disabled:k,children:[e.jsx(F.Library,{className:"h-3.5 w-3.5"}),"Save as Library Visual"]}),e.jsxs(t.DropdownMenuItem,{onClick:()=>I("both"),disabled:k,children:[e.jsx(F.Link2,{className:"h-3.5 w-3.5"}),"Save Copy as Linked Visual"]})]})]})]}),e.jsx(F.EditorCancelButton,{}),e.jsx(J,{open:D,onOpenChange:S=>{k||n(S)},isLibraryVisual:E,currentVisualName:L,isSaving:k,destinationMode:C,onConfirm:w})]})}function se({className:s}){const r=a.useEditorStore(o=>o.isDevMode),v=a.useDashboardStore(o=>o.isVisualEditing),{setIsDevMode:d}=a.useEditorActions(),{config:i}=g.useContext(t.SemaphorContext).tokenProps,c=(i==null?void 0:i.showAdvancedMode)!==!1;if(!v||!c)return null;const u=r?a.SlidersHorizontal:t.CodeXml,m=r?"Drag & drop":"SQL",l=r?"Switch to drag-and-drop mode":"Switch to SQL mode";return e.jsxs("button",{type:"button","aria-label":l,title:l,onClick:()=>d(!r),className:a.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",s),children:[e.jsx(u,{className:"h-3 w-3 text-muted-foreground"}),m]})}function re({open:s,onOpenChange:r,onSave:v,onDiscard:d,isSaving:i,title:c="Unsaved changes",description:u="You have unsaved changes to this dashboard. What would you like to do?",cancelLabel:m="Cancel",discardLabel:l="Discard",saveLabel:o="Save"}){const p=C=>{!C&&i||r(C)};return e.jsx(t.AlertDialog,{open:s,onOpenChange:p,children:e.jsxs(t.AlertDialogContent,{children:[e.jsxs(t.AlertDialogHeader,{children:[e.jsx(t.AlertDialogTitle,{children:c}),e.jsx(t.AlertDialogDescription,{children:u})]}),e.jsxs(t.AlertDialogFooter,{children:[e.jsx(a.Button,{type:"button",size:"xs",onClick:d,disabled:i,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:l}),e.jsx(t.AlertDialogCancel,{disabled:i,children:m}),e.jsx(a.Button,{type:"button",size:"xs",onClick:v,disabled:i,children:i?e.jsxs(e.Fragment,{children:[e.jsx(a.LoaderCircle,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),"Saving..."]}):o})]})]})})}function z({export:s,onRemove:r}){const v=()=>{s.downloadUrl&&window.open(s.downloadUrl,"_blank")},d=m=>{m.stopPropagation(),r==null||r(s.id)},i=()=>{switch(s.status){case"completed":return e.jsx(t.CircleCheck,{className:"mt-0.5 h-5 w-5 shrink-0 text-green-600"});case"failed":return e.jsx(F.CircleX,{className:"mt-0.5 h-5 w-5 shrink-0 text-destructive"});default:return e.jsx(a.LoaderCircle,{className:"text-foreground-muted mt-0.5 h-5 w-5 shrink-0 animate-spin"})}},c=t.isExportInProgress(s.status),u=(()=>{switch(s.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:[i(),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h4",{className:"mb-1 truncate text-sm font-medium",children:s.title}),s.status==="completed"&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("span",{children:[s.totalRows.toLocaleString()," rows"]}),s.fileSize&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"•"}),e.jsx("span",{children:t.formatFileSize(s.fileSize)})]})]}),c&&e.jsx("div",{className:"text-xs text-muted-foreground",children:u}),s.status==="failed"&&e.jsx("div",{className:"line-clamp-2 text-xs text-destructive",children:s.error||"Export failed"})]})]}),e.jsx(a.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0 opacity-0 transition-opacity group-hover:opacity-100",onClick:d,"aria-label":"Remove notification",children:e.jsx(a.X,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"ml-8",children:[s.status==="completed"&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:U.formatDistanceToNow(s.startedAt,{addSuffix:!0})}),s.downloadUrl&&e.jsxs(a.Button,{size:"sm",variant:"outline",className:"h-8 bg-transparent",onClick:v,children:[e.jsx(t.Download,{className:"mr-1.5 h-3.5 w-3.5"}),"Download"]})]}),c&&e.jsxs("div",{children:[e.jsx(t.Progress,{value:s.progress,className:"h-1.5"}),e.jsxs("span",{className:"mt-1 block text-xs text-muted-foreground",children:[s.progress,"% complete"]})]}),s.status==="failed"&&e.jsx("span",{className:"text-xs text-muted-foreground",children:U.formatDistanceToNow(s.startedAt,{addSuffix:!0})})]})]})}function H(){const{authToken:s,tokenProps:r}=t.useSemaphorContext(),v=t.useExportStore(f=>f.activeExports),{clearCompleted:d,removeExport:i,updateExport:c}=t.useExportActions(),[u,m]=g.useState(!1),[l,o]=g.useState(!1),p=Array.from(v.values()).sort((f,j)=>j.startedAt.getTime()-f.startedAt.getTime()),C=p.some(f=>f.status==="completed"||f.status==="failed"),x=g.useCallback(async()=>{const f=r==null?void 0:r.apiServiceUrl,j=s==null?void 0:s.accessToken;if(!(!f||!j)){m(!0);try{const A=Array.from(v.values());await Promise.all(A.map(async D=>{try{const n=await t.getExportStatus(f,j,D.id);let w;if(n.status==="completed")try{w=await t.getDownloadUrl(f,j,D.id)}catch(E){console.error(`Failed to get download URL for ${D.id}:`,E)}c(D.id,{status:n.status,progress:n.progress,completedChunks:n.completedChunks,completedAt:n.completedAt?new Date(n.completedAt):void 0,lastUpdatedAt:new Date,fileSize:n.fileSize,error:n.error,downloadUrl:w})}catch(n){console.error(`Failed to refresh export ${D.id}:`,n)}}))}finally{m(!1)}}},[v,s==null?void 0:s.accessToken,r==null?void 0:r.apiServiceUrl,c]),y=g.useCallback(async()=>{const f=r==null?void 0:r.apiServiceUrl,j=s==null?void 0:s.accessToken;if(!f||!j){d();return}o(!0);try{const A=p.filter(n=>n.status==="completed"||n.status==="failed"),D=await Promise.allSettled(A.map(async n=>(await t.cancelExport(f,j,n.id),n.id)));for(const n of D)n.status==="fulfilled"?i(n.value):console.error("Failed to delete export:",n.reason)}finally{o(!1)}},[p,r==null?void 0:r.apiServiceUrl,s==null?void 0:s.accessToken,d,i]),N=g.useCallback(async f=>{const j=r==null?void 0:r.apiServiceUrl,A=s==null?void 0:s.accessToken;if(j&&A)try{await t.cancelExport(j,A,f),i(f);return}catch(D){console.error(`Failed to cancel export ${f}:`,D)}i(f)},[r==null?void 0:r.apiServiceUrl,s==null?void 0:s.accessToken,i]);return p.length===0?e.jsxs("div",{className:"p-6 text-center",children:[e.jsx(V,{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(V,{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(a.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:x,disabled:u,title:"Refresh status",children:e.jsx(t.RefreshCw,{className:`h-4 w-4 ${u?"animate-spin":""}`})}),C&&e.jsx(a.Button,{variant:"ghost",size:"sm",className:"h-7 px-2 text-sm",onClick:y,disabled:l,children:l?"Clearing...":"Clear all"})]})]}),e.jsx("div",{className:"max-h-[350px] overflow-y-auto",children:e.jsx("div",{className:"divide-y",children:p.map(f=>e.jsx(z,{export:f,onRemove:N},f.id))})})]})}function ae({variant:s}){const r=t.useExportStore(l=>l.activeExports),v=t.useInProgressExportsCount(),d=r.size>0,i=Array.from(r.values()).some(l=>l.status==="completed"||l.status==="failed"),u=v>0?v>9?"9+":String(v):null,m=d;return e.jsxs(a.Popover,{children:[e.jsx(a.PopoverTrigger,{asChild:!0,children:e.jsxs(a.Button,{variant:s??"ghost",size:"xs",className:"relative w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":"Export notifications",children:[e.jsx(t.Bell,{className:"h-3.5 w-3.5"}),m&&e.jsx("span",{className:`absolute flex items-center justify-center rounded-full bg-primary text-primary-foreground ${u?"-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:u})]})}),e.jsx(a.PopoverContent,{className:"w-80 p-0",align:"end",sideOffset:8,children:e.jsx(H,{})})]})}function oe(s){if(s)return{renamed:s.type==="rename"?{oldId:s.oldId,newId:s.newId}:void 0,removedControlId:s.type==="remove"?s.controlId:void 0,cardBindingsById:s.type==="add"||s.type==="update"?s.cardBindingsById:void 0,affectedBindingControlIds:s.type==="add"||s.type==="update"?s.affectedBindingControlIds:void 0}}function ne({open:s,onOpenChange:r,trigger:v,showTrigger:d=!0,initialMode:i="manage"}){const c=i==="create",{forceClose:u,handleOpenChange:m,isCreateFlowActive:l,preventPassiveDismissDuringCreate:o,resolvedOpen:p,setIsCreateFlowActive:C}=F.useCreateFlowOverlayState({open:s,onOpenChange:r,initialCreateFlowActive:i==="create",dismissMode:d?"passive":"explicit-only"}),x=a.useDashboardStore(h=>h.dashboard),{setDashboardControlsModel:y}=a.useDashboardActions(),{participants:N}=t.useDashboardStructuralParticipants(a.getDashboardCards(x)),f=Array.from(new Map(N.flatMap(h=>h.fieldChoices.map(b=>{var I;return[b.value,{option:b,target:(I=h.fieldTargetMap)==null?void 0:I[b.value]}]}))).values()),j=Array.from(new Map(N.flatMap(h=>h.metricChoices.map(b=>{var I;return[b.value,{option:b,target:(I=h.metricTargetMap)==null?void 0:I[b.value]}]}))).values()),A=t.collectDashboardControlIds({...x||{},controls:[]}),D=t.buildDashboardStructuralParticipantIdsByControlId(x),n=(h,b,I)=>{y(h,b,oe(I))},w=g.useCallback(()=>{if(c){u();return}C(!1)},[c,u,C]),E=e.jsx(F.ControlDefinitionListEditor,{scope:"dashboard",controls:x.controls||[],reservedControlIds:A,defaultValues:x.defaultControlValues||{},usageByControlId:t.buildDashboardControlUsageById(x),availableFieldChoices:f,availableMetricChoices:j,structuralParticipants:N,structuralParticipantIdsByControlId:D,initialCreateFlow:i==="create",onCreateFlowActiveChange:C,onCreateFlowComplete:w,onChange:n,emptyMessage:"No dashboard controls yet."}),L=l?"Add dashboard control":"Dashboard Controls",k=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 d?e.jsxs(a.Popover,{open:p,onOpenChange:m,children:[e.jsx(a.PopoverTrigger,{asChild:!0,children:v||e.jsxs(a.Button,{variant:"outline",className:"h-7 px-2",size:"sm",children:[e.jsx(a.SlidersHorizontal,{className:"mr-2 h-4 w-4"}),"Controls"]})}),e.jsx(a.PopoverContent,{className:"w-[620px] max-w-[95vw] space-y-4",align:"end",onEscapeKeyDown:o,onPointerDownOutside:o,children:k})]}):e.jsx(t.Dialog,{open:p,onOpenChange:m,children:e.jsxs(t.DialogContent,{className:"flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",onEscapeKeyDown:o,onPointerDownOutside:o,children:[e.jsxs(t.DialogHeader,{className:l?"space-y-0":void 0,children:[e.jsx(t.DialogTitle,{className:"text-[15px]",children:L}),e.jsx(t.DialogDescription,{className:l?"sr-only":"text-[13px]",children:l?"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})]})})}function ie({showFilters:s,onToggleFilters:r,onAddFilter:v,onAddControl:d,onManageControls:i,size:c="default",className:u,primaryButtonClassName:m,secondaryButtonClassName:l,dropdownContentClassName:o}){const p=c==="toolbar";return e.jsxs("div",{className:a.cn("relative inline-flex items-stretch overflow-hidden rounded-control border border-input bg-background",p?"h-8":"h-7",u),children:[e.jsxs(a.Button,{variant:"ghost",size:"xs",className:a.cn("h-full rounded-none border-0 bg-transparent pl-2.5 pr-2 shadow-none hover:bg-accent/50",m),onClick:r,children:[s?e.jsx($,{className:"h-3.5 w-3.5"}):e.jsx(t.Filter,{className:"h-3.5 w-3.5"}),"Filter"]}),e.jsxs(t.DropdownMenu,{children:[e.jsx(t.DropdownMenuTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"ghost",size:"xs",className:a.cn("h-full w-7 rounded-none border-0 border-l border-border/60 bg-transparent px-0 shadow-none hover:bg-accent/50",l),"aria-label":"Filter and control actions",children:e.jsx(a.ChevronDown,{className:"h-3.5 w-3.5"})})}),e.jsxs(t.DropdownMenuContent,{align:"start",className:a.cn("min-w-[180px] rounded-control border border-border/60 p-1 shadow-sm",o),children:[e.jsxs(t.DropdownMenuItem,{onSelect:v,children:[e.jsx(t.Filter,{className:"h-3.5 w-3.5"}),"Add filter"]}),e.jsxs(t.DropdownMenuItem,{onSelect:d,children:[e.jsx(a.SlidersHorizontal,{className:"h-3.5 w-3.5"}),"Add control"]}),e.jsxs(t.DropdownMenuItem,{onSelect:i,children:[e.jsx(t.Pencil,{className:"h-3.5 w-3.5"}),"Manage controls"]})]})]})]})}exports.AdvancedModeToggle=se;exports.DashboardControlsSettings=ne;exports.DashboardFilterControlsButton=ie;exports.ExportNotificationItem=z;exports.ExportNotificationList=H;exports.NotificationBell=ae;exports.UnsavedChangesAlert=re;exports.VisualEditingControls=te;exports.useExportPolling=W;exports.useExportRecovery=Y;
11
+ */const $=r.createLucideIcon("FilterX",[["path",{d:"M13.013 3H2l8 9.46V19l4 2v-8.54l.9-1.055",key:"1fi1da"}],["path",{d:"m22 3-5 5",key:"12jva0"}],["path",{d:"m17 3 5 5",key:"k36vhe"}]]),_=1e4,q=15e3,X=3e4,G=3e4,Q=12e4,O=2*60*60*1e3;function K(s){const a=Date.now()-s.getTime();return a<G?_:a<Q?q:X}function W(){const{authToken:s,tokenProps:a}=t.useSemaphorContext(),v=t.useExportStore(x=>x.activeExports),[d,i]=g.useState(typeof document<"u"?!document.hidden:!0),c=g.useRef(null),u=g.useRef(!1),m=g.useRef(void 0),l=a==null?void 0:a.apiServiceUrl,o=s==null?void 0:s.accessToken,p=g.useCallback(()=>{const x=t.useExportStore.getState().activeExports;return Array.from(x.values()).filter(y=>t.isExportInProgress(y.status))},[]);g.useEffect(()=>{if(typeof document>"u")return;const x=()=>{i(!document.hidden)};return document.addEventListener("visibilitychange",x),()=>{document.removeEventListener("visibilitychange",x)}},[]);const C=g.useCallback(async()=>{if(!l||!o){u.current=!1;return}const x=p();if(x.length===0){u.current=!1;return}const y=Date.now(),N=x.filter(n=>y-n.startedAt.getTime()>O);if(N.length>0){const{updateExport:n}=t.useExportStore.getState().actions;for(const w of N)n(w.id,{status:"failed",error:"Export timed out. Please try again or contact support.",lastUpdatedAt:new Date})}const f=x.filter(n=>y-n.startedAt.getTime()<=O);if(f.length===0){u.current=!1;return}const j=await Promise.allSettled(f.map(async n=>{try{const w=await t.getExportStatus(l,o,n.id);let E;if(w.status==="completed")try{E=await t.getDownloadUrl(l,o,n.id)}catch(L){console.error(`[useExportPolling] Failed to get download URL for ${n.id}:`,L)}return{id:n.id,status:w.status,progress:w.progress,completedChunks:w.completedChunks,completedAt:w.completedAt?new Date(w.completedAt):void 0,lastUpdatedAt:new Date,fileSize:w.fileSize,error:w.error,downloadUrl:E}}catch(w){return console.error(`[useExportPolling] Failed to poll export ${n.id}:`,w),null}})),{updateExport:A}=t.useExportStore.getState().actions;for(const n of j)n.status==="fulfilled"&&n.value&&A(n.value.id,n.value);const D=p();if(D.length>0&&!document.hidden){const n=D.reduce((E,L)=>L.startedAt<E?L.startedAt:E,D[0].startedAt),w=K(n);c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{var E;(E=m.current)==null||E.call(m)},w)}else u.current=!1},[l,o,p]);return g.useEffect(()=>{m.current=C},[C]),g.useEffect(()=>{var y;p().length>0&&d&&!u.current&&(u.current=!0,(y=m.current)==null||y.call(m))},[v,d,p]),g.useEffect(()=>{var y;const x=p();d&&x.length>0&&!u.current&&(u.current=!0,(y=m.current)==null||y.call(m))},[d,p]),g.useEffect(()=>{!d&&c.current&&(clearTimeout(c.current),c.current=null,u.current=!1)},[d]),g.useEffect(()=>()=>{c.current&&(clearTimeout(c.current),c.current=null)},[]),{isPolling:u.current,isTabVisible:d,inProgressCount:p().length}}function Y(){const{authToken:s,tokenProps:a}=t.useSemaphorContext(),v=t.useExportStore(m=>m.activeExports),{addExport:d}=t.useExportActions(),i=g.useRef(!1),c=a==null?void 0:a.apiServiceUrl,u=s==null?void 0:s.accessToken;g.useEffect(()=>{if(i.current||!c||!u)return;(async()=>{try{const{exports:l}=await t.getExports(c,u,{status:["pending","processing","chunking","compacting","completed","failed"],limit:20});for(const o of l){if(v.has(o.id))continue;const p=o.totalChunks?Math.round(o.completedChunks/o.totalChunks*100):0;let C;if(o.status==="completed")try{C=await t.getDownloadUrl(c,u,o.id)}catch(y){console.error(`[useExportRecovery] Failed to get download URL for ${o.id}:`,y)}const x={id:o.id,status:o.status,progress:p,title:Z(o),totalRows:o.totalRows,totalChunks:o.totalChunks,completedChunks:o.completedChunks,startedAt:new Date(o.createdAt),lastUpdatedAt:new Date,completedAt:o.completedAt?new Date(o.completedAt):void 0,fileSize:o.fileSize,error:o.error,expiresAt:new Date(o.expiresAt),downloadUrl:C};d(x)}i.current=!0}catch(l){console.error("[useExportRecovery] Failed to recover exports:",l),i.current=!0}})()},[c,u,d,v])}function Z(s){return s.title?s.title:t.isExportInProgress(s.status)?"Export in progress...":s.status==="completed"?"Export completed":s.status==="failed"?"Export failed":"Export"}function J({open:s,onOpenChange:a,isLibraryVisual:v,currentVisualName:d,isSaving:i=!1,destinationMode:c="both",onConfirm:u}){const[m,l]=g.useState(v&&d?`Copy of ${d}`:d||""),[o,p]=g.useState("");g.useEffect(()=>{s&&(l(v&&d?`Copy of ${d}`:d||""),p(""))},[s,v,d]);const C=!!m.trim(),x=c==="local"?{saveToLibrary:!1,saveToCurrentDashboard:!0,badgeType:"local",description:"Creates a local copy on the current dashboard.",actionLabel:"Add to Dashboard (Local)"}:c==="library"?{saveToLibrary:!0,saveToCurrentDashboard:!1,badgeType:"library",description:"Creates a reusable visual in Visual Library.",actionLabel:"Save as Library Visual"}:{saveToLibrary:!0,saveToCurrentDashboard:!0,badgeType:"linked",description:"Creates a new library visual and adds a linked copy to this dashboard.",actionLabel:"Save Copy as Linked Visual"},y=()=>{!C||i||u({name:m.trim(),description:o.trim()||void 0,saveToLibrary:x.saveToLibrary,saveToCurrentDashboard:x.saveToCurrentDashboard})};return e.jsx(t.Dialog,{open:s,onOpenChange:a,children:e.jsxs(t.DialogContent,{className:"sm:max-w-[500px]",children:[e.jsxs(t.DialogHeader,{children:[e.jsxs(t.DialogTitle,{className:"flex items-center gap-2",children:[e.jsx("span",{children:"Save Visual As"}),x.badgeType!=="local"&&e.jsx(F.VisualBadge,{type:x.badgeType,showLabel:!0,className:"px-2 py-0.5"})]}),e.jsx(t.DialogDescription,{children:x.description})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(r.Label,{htmlFor:"name",children:"Name"}),e.jsx(r.Input,{id:"name",value:m,onChange:N=>l(N.target.value),placeholder:"Enter visual name",disabled:i})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(r.Label,{htmlFor:"description",children:"Description (optional)"}),e.jsx(t.Textarea,{id:"description",value:o,onChange:N=>p(N.target.value),placeholder:"Enter visual description",rows:3,disabled:i})]})]}),e.jsxs(t.DialogFooter,{children:[e.jsx(r.Button,{variant:"outline",onClick:()=>a(!1),disabled:i,children:"Cancel"}),e.jsxs(r.Button,{onClick:y,disabled:!C||i,children:[i&&e.jsx(r.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),x.actionLabel]})]})]})})}function ee(){const[s,a]=g.useState(!1),[v,d]=g.useState(!1),[i,c]=g.useState(null),[u,m]=g.useState(null),l=r.useEditorStore(h=>h.frame),o=r.useEditorStore(h=>h.card),p=t.useSelectedVisual(),C=r.useDashboardStore(h=>h.selectedSheetId),x=r.useDashboardStore(h=>h.dashboard),y=r.useDashboardStore(h=>h.actions.setIsDashboardPanelOpen),{getUpdatedFrame:N}=R.useVisualUtils(),{selectVisual:f}=t.useManagementActions(),{addFrame:j,setSelectedFrameId:A,setIsVisualEditing:D}=r.useDashboardActions(),n=t.useResolveExistingFrameSemanticExecutionPayload(),w=!!(l!=null&&l.visualId),E=(()=>{var h,b;return((h=l==null?void 0:l.cards)==null?void 0:h.length)===1&&((b=l.cards[0])!=null&&b.title)?l.cards[0].title:p!=null&&p.title?p.title:(o==null?void 0:o.title)||"Untitled Visual"})(),L=t.useCreateVisualWithFrame(h=>{h!=null&&h.id&&(f(h),v&&i&&u&&C&&(async()=>{try{const b={...i,id:r.v4(),visualId:h.id};j(C,b,{position:"end",semanticExecutionPayload:u}),A(b.id),d(!1),c(null),m(null),D(!1)}catch(b){console.error("Failed to promote semantic metadata for saved visual:",b),t.ue.error(b instanceof Error?b.message:"Failed to prepare semantic metadata for the saved visual")}})(),y(!0),a(!1))});return{saveAsDialogOpen:s,setSaveAsDialogOpen:a,handleSaveAs:async h=>{if(!C){t.ue.error("No sheet selected");return}const b=N(),I=r.getDynamicFrameSaveIssue(b);if(I){t.ue.error(I);return}const P=b.cards.length===1?{...b,cards:b.cards.map(T=>({...T,title:h.name}))}:b;if(h.saveToLibrary){let T=null;if(h.saveToCurrentDashboard)try{T=await n(P,{previousFrame:t.findDashboardFrameById(x,P.id)})}catch(M){console.error("Failed to prepare semantic metadata before saving visual:",M),t.ue.error(M instanceof Error?M.message:"Failed to prepare semantic metadata for the saved visual");return}d(h.saveToCurrentDashboard),c(P),m(T);const B={title:h.name,description:h.description,frameObject:P,isPrivate:!1};L.mutate(B)}else if(h.saveToCurrentDashboard){const T={...P,id:r.v4(),visualId:void 0};try{const B=await n(P,{previousFrame:t.findDashboardFrameById(x,P.id)});j(C,T,{position:"end",semanticExecutionPayload:B}),A(T.id),t.ue.success("Visual saved to dashboard"),a(!1),D(!1)}catch(B){console.error("Failed to save visual to dashboard:",B),t.ue.error(B instanceof Error?B.message:"Failed to prepare semantic metadata for the visual")}}},isLibraryVisual:w,currentVisualName:E,isSaving:L.isPending}}function te(s={}){const a=r.useEditorStore(S=>S.frame),v=r.useEditorStore(S=>S.editorContext),d=t.useManagementStore(S=>S.selectedVisual),i=r.useDashboardStore(S=>S.selectedFrameId),c=r.useDashboardStore(S=>S.selectedSheetId),u=r.useDashboardStore(S=>S.dashboard),{setIsVisualEditing:m,updateFrame:l}=r.useDashboardActions(),[o,p]=g.useState(!1),[C,x]=g.useState("both"),y=t.useResolveExistingFrameSemanticExecutionPayload(),N=(v==null?void 0:v.type)==="documentSection",f=!!(a!=null&&a.visualId||d!=null&&d.id),j=!!(a!=null&&a.visualId&&i),A=f&&!j,{saveAsDialogOpen:D,setSaveAsDialogOpen:n,handleSaveAs:w,isLibraryVisual:E,currentVisualName:L,isSaving:k}=ee(),{getUpdatedFrame:h}=R.useVisualUtils();if(N)return e.jsxs(e.Fragment,{children:[e.jsx(F.EditorAcceptButton,{className:"rounded-control",variant:"default"}),e.jsx(F.EditorCancelButton,{})]});const b=async()=>{if(!c){t.ue.error("No sheet selected");return}if(o)return;p(!0);const S=h(),P=r.getDynamicFrameSaveIssue(S);if(P){p(!1),t.ue.error(P);return}const T={...S,visualId:void 0},B=t.findDashboardFrameById(u,T.id);try{const M=await y(T,{previousFrame:B});l(c,T,{semanticExecutionPayload:M})}catch(M){console.error("Failed to apply local semantic metadata:",M),p(!1),t.ue.error(M instanceof Error?M.message:"Failed to prepare semantic metadata for this visual");return}setTimeout(()=>{p(!1),t.ue.success("Changes applied. Visual is now local to this dashboard"),m(!1)},300)},I=S=>{x(S),n(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"inline-flex items-center overflow-hidden rounded-control",children:[!f&&e.jsx(F.EditorAcceptButton,{className:"!rounded-none",variant:"default"}),f&&A&&e.jsx(F.VisualSaveButton,{className:"!rounded-none",variant:"default"}),f&&j&&e.jsx(F.VisualSaveAndApplyButton,{className:"!rounded-none"}),e.jsxs(t.DropdownMenu,{modal:!1,children:[e.jsx(t.DropdownMenuTrigger,{asChild:!0,children:e.jsx(r.Button,{variant:"default",size:"xs",className:"w-7 !rounded-none border-l border-primary-foreground/20 px-0","aria-label":"Open visual save options",disabled:k||o,children:e.jsx(r.ChevronDown,{className:"h-3.5 w-3.5"})})}),e.jsxs(t.DropdownMenuContent,{align:"end",className:"min-w-[220px] rounded-control border border-border/60 p-1 shadow-sm",children:[j&&e.jsxs(e.Fragment,{children:[e.jsxs(t.DropdownMenuItem,{onClick:b,disabled:o,children:[e.jsx(r.Check,{className:"h-3.5 w-3.5"}),o?"Applying...":"Apply Locally"]}),e.jsx(t.DropdownMenuSeparator,{})]}),e.jsxs(t.DropdownMenuItem,{onClick:()=>I("local"),disabled:k,children:[e.jsx(t.Plus,{className:"h-3.5 w-3.5"}),"Add to Dashboard (Local)"]}),e.jsxs(t.DropdownMenuItem,{onClick:()=>I("library"),disabled:k,children:[e.jsx(F.Library,{className:"h-3.5 w-3.5"}),"Save as Library Visual"]}),e.jsxs(t.DropdownMenuItem,{onClick:()=>I("both"),disabled:k,children:[e.jsx(F.Link2,{className:"h-3.5 w-3.5"}),"Save Copy as Linked Visual"]})]})]})]}),e.jsx(F.EditorCancelButton,{}),e.jsx(J,{open:D,onOpenChange:S=>{k||n(S)},isLibraryVisual:E,currentVisualName:L,isSaving:k,destinationMode:C,onConfirm:w})]})}function se({className:s}){const a=r.useEditorStore(o=>o.isDevMode),v=r.useDashboardStore(o=>o.isVisualEditing),{setIsDevMode:d}=r.useEditorActions(),{config:i}=g.useContext(t.SemaphorContext).tokenProps,c=(i==null?void 0:i.showAdvancedMode)!==!1;if(!v||!c)return null;const u=a?r.SlidersHorizontal:t.CodeXml,m=a?"Drag & drop":"SQL",l=a?"Switch to drag-and-drop mode":"Switch to SQL mode";return e.jsxs("button",{type:"button","aria-label":l,title:l,onClick:()=>d(!a),className:r.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",s),children:[e.jsx(u,{className:"h-3 w-3 text-muted-foreground"}),m]})}function re({open:s,onOpenChange:a,onSave:v,onDiscard:d,isSaving:i,title:c="Unsaved changes",description:u="You have unsaved changes to this dashboard. What would you like to do?",cancelLabel:m="Cancel",discardLabel:l="Discard",saveLabel:o="Save"}){const p=C=>{!C&&i||a(C)};return e.jsx(t.AlertDialog,{open:s,onOpenChange:p,children:e.jsxs(t.AlertDialogContent,{children:[e.jsxs(t.AlertDialogHeader,{children:[e.jsx(t.AlertDialogTitle,{children:c}),e.jsx(t.AlertDialogDescription,{children:u})]}),e.jsxs(t.AlertDialogFooter,{children:[e.jsx(r.Button,{type:"button",size:"xs",onClick:d,disabled:i,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:l}),e.jsx(t.AlertDialogCancel,{disabled:i,children:m}),e.jsx(r.Button,{type:"button",size:"xs",onClick:v,disabled:i,children:i?e.jsxs(e.Fragment,{children:[e.jsx(r.LoaderCircle,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),"Saving..."]}):o})]})]})})}function z({export:s,onRemove:a}){const v=()=>{s.downloadUrl&&window.open(s.downloadUrl,"_blank")},d=m=>{m.stopPropagation(),a==null||a(s.id)},i=()=>{switch(s.status){case"completed":return e.jsx(t.CircleCheck,{className:"mt-0.5 h-5 w-5 shrink-0 text-green-600"});case"failed":return e.jsx(F.CircleX,{className:"mt-0.5 h-5 w-5 shrink-0 text-destructive"});default:return e.jsx(r.LoaderCircle,{className:"text-foreground-muted mt-0.5 h-5 w-5 shrink-0 animate-spin"})}},c=t.isExportInProgress(s.status),u=(()=>{switch(s.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:[i(),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h4",{className:"mb-1 truncate text-sm font-medium",children:s.title}),s.status==="completed"&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("span",{children:[s.totalRows.toLocaleString()," rows"]}),s.fileSize&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"•"}),e.jsx("span",{children:t.formatFileSize(s.fileSize)})]})]}),c&&e.jsx("div",{className:"text-xs text-muted-foreground",children:u}),s.status==="failed"&&e.jsx("div",{className:"line-clamp-2 text-xs text-destructive",children:s.error||"Export failed"})]})]}),e.jsx(r.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0 opacity-0 transition-opacity group-hover:opacity-100",onClick:d,"aria-label":"Remove notification",children:e.jsx(r.X,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"ml-8",children:[s.status==="completed"&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:U.formatDistanceToNow(s.startedAt,{addSuffix:!0})}),s.downloadUrl&&e.jsxs(r.Button,{size:"sm",variant:"outline",className:"h-8 bg-transparent",onClick:v,children:[e.jsx(t.Download,{className:"mr-1.5 h-3.5 w-3.5"}),"Download"]})]}),c&&e.jsxs("div",{children:[e.jsx(t.Progress,{value:s.progress,className:"h-1.5"}),e.jsxs("span",{className:"mt-1 block text-xs text-muted-foreground",children:[s.progress,"% complete"]})]}),s.status==="failed"&&e.jsx("span",{className:"text-xs text-muted-foreground",children:U.formatDistanceToNow(s.startedAt,{addSuffix:!0})})]})]})}function H(){const{authToken:s,tokenProps:a}=t.useSemaphorContext(),v=t.useExportStore(f=>f.activeExports),{clearCompleted:d,removeExport:i,updateExport:c}=t.useExportActions(),[u,m]=g.useState(!1),[l,o]=g.useState(!1),p=Array.from(v.values()).sort((f,j)=>j.startedAt.getTime()-f.startedAt.getTime()),C=p.some(f=>f.status==="completed"||f.status==="failed"),x=g.useCallback(async()=>{const f=a==null?void 0:a.apiServiceUrl,j=s==null?void 0:s.accessToken;if(!(!f||!j)){m(!0);try{const A=Array.from(v.values());await Promise.all(A.map(async D=>{try{const n=await t.getExportStatus(f,j,D.id);let w;if(n.status==="completed")try{w=await t.getDownloadUrl(f,j,D.id)}catch(E){console.error(`Failed to get download URL for ${D.id}:`,E)}c(D.id,{status:n.status,progress:n.progress,completedChunks:n.completedChunks,completedAt:n.completedAt?new Date(n.completedAt):void 0,lastUpdatedAt:new Date,fileSize:n.fileSize,error:n.error,downloadUrl:w})}catch(n){console.error(`Failed to refresh export ${D.id}:`,n)}}))}finally{m(!1)}}},[v,s==null?void 0:s.accessToken,a==null?void 0:a.apiServiceUrl,c]),y=g.useCallback(async()=>{const f=a==null?void 0:a.apiServiceUrl,j=s==null?void 0:s.accessToken;if(!f||!j){d();return}o(!0);try{const A=p.filter(n=>n.status==="completed"||n.status==="failed"),D=await Promise.allSettled(A.map(async n=>(await t.cancelExport(f,j,n.id),n.id)));for(const n of D)n.status==="fulfilled"?i(n.value):console.error("Failed to delete export:",n.reason)}finally{o(!1)}},[p,a==null?void 0:a.apiServiceUrl,s==null?void 0:s.accessToken,d,i]),N=g.useCallback(async f=>{const j=a==null?void 0:a.apiServiceUrl,A=s==null?void 0:s.accessToken;if(j&&A)try{await t.cancelExport(j,A,f),i(f);return}catch(D){console.error(`Failed to cancel export ${f}:`,D)}i(f)},[a==null?void 0:a.apiServiceUrl,s==null?void 0:s.accessToken,i]);return p.length===0?e.jsxs("div",{className:"p-6 text-center",children:[e.jsx(V,{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(V,{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(r.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:x,disabled:u,title:"Refresh status",children:e.jsx(t.RefreshCw,{className:`h-4 w-4 ${u?"animate-spin":""}`})}),C&&e.jsx(r.Button,{variant:"ghost",size:"sm",className:"h-7 px-2 text-sm",onClick:y,disabled:l,children:l?"Clearing...":"Clear all"})]})]}),e.jsx("div",{className:"max-h-[350px] overflow-y-auto",children:e.jsx("div",{className:"divide-y",children:p.map(f=>e.jsx(z,{export:f,onRemove:N},f.id))})})]})}function ae({variant:s}){const a=t.useExportStore(l=>l.activeExports),v=t.useInProgressExportsCount(),d=a.size>0,i=Array.from(a.values()).some(l=>l.status==="completed"||l.status==="failed"),u=v>0?v>9?"9+":String(v):null,m=d;return e.jsxs(r.Popover,{children:[e.jsx(r.PopoverTrigger,{asChild:!0,children:e.jsxs(r.Button,{variant:s??"ghost",size:"xs",className:"relative w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":"Export notifications",children:[e.jsx(t.Bell,{className:"h-3.5 w-3.5"}),m&&e.jsx("span",{className:`absolute flex items-center justify-center rounded-full bg-primary text-primary-foreground ${u?"-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:u})]})}),e.jsx(r.PopoverContent,{className:"w-80 p-0",align:"end",sideOffset:8,children:e.jsx(H,{})})]})}function oe(s){if(s)return{renamed:s.type==="rename"?{oldId:s.oldId,newId:s.newId}:void 0,removedControlId:s.type==="remove"?s.controlId:void 0,cardBindingsById:s.type==="add"||s.type==="update"?s.cardBindingsById:void 0,affectedBindingControlIds:s.type==="add"||s.type==="update"?s.affectedBindingControlIds:void 0}}function ne({open:s,onOpenChange:a,trigger:v,showTrigger:d=!0,initialMode:i="manage"}){const c=i==="create",{forceClose:u,handleOpenChange:m,isCreateFlowActive:l,preventPassiveDismissDuringCreate:o,resolvedOpen:p,setIsCreateFlowActive:C}=F.useCreateFlowOverlayState({open:s,onOpenChange:a,initialCreateFlowActive:i==="create",dismissMode:d?"passive":"explicit-only"}),x=r.useDashboardStore(h=>h.dashboard),{setDashboardControlsModel:y}=r.useDashboardActions(),{participants:N}=t.useDashboardStructuralParticipants(r.getDashboardCards(x)),f=Array.from(new Map(N.flatMap(h=>h.fieldChoices.map(b=>{var I;return[b.value,{option:b,target:(I=h.fieldTargetMap)==null?void 0:I[b.value]}]}))).values()),j=Array.from(new Map(N.flatMap(h=>h.metricChoices.map(b=>{var I;return[b.value,{option:b,target:(I=h.metricTargetMap)==null?void 0:I[b.value]}]}))).values()),A=r.collectDashboardControlIds({...x||{},controls:[]}),D=t.buildDashboardStructuralParticipantIdsByControlId(x),n=(h,b,I)=>{y(h,b,oe(I))},w=g.useCallback(()=>{if(c){u();return}C(!1)},[c,u,C]),E=e.jsx(F.ControlDefinitionListEditor,{scope:"dashboard",controls:x.controls||[],reservedControlIds:A,defaultValues:x.defaultControlValues||{},usageByControlId:t.buildDashboardControlUsageById(x),availableFieldChoices:f,availableMetricChoices:j,structuralParticipants:N,structuralParticipantIdsByControlId:D,initialCreateFlow:i==="create",onCreateFlowActiveChange:C,onCreateFlowComplete:w,onChange:n,emptyMessage:"No dashboard controls yet."}),L=l?"Add dashboard control":"Dashboard Controls",k=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 d?e.jsxs(r.Popover,{open:p,onOpenChange:m,children:[e.jsx(r.PopoverTrigger,{asChild:!0,children:v||e.jsxs(r.Button,{variant:"outline",className:"h-7 px-2",size:"sm",children:[e.jsx(r.SlidersHorizontal,{className:"mr-2 h-4 w-4"}),"Controls"]})}),e.jsx(r.PopoverContent,{className:"w-[620px] max-w-[95vw] space-y-4",align:"end",onEscapeKeyDown:o,onPointerDownOutside:o,children:k})]}):e.jsx(t.Dialog,{open:p,onOpenChange:m,children:e.jsxs(t.DialogContent,{className:"flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",onEscapeKeyDown:o,onPointerDownOutside:o,children:[e.jsxs(t.DialogHeader,{className:l?"space-y-0":void 0,children:[e.jsx(t.DialogTitle,{className:"text-[15px]",children:L}),e.jsx(t.DialogDescription,{className:l?"sr-only":"text-[13px]",children:l?"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})]})})}function ie({showFilters:s,onToggleFilters:a,onAddFilter:v,onAddControl:d,onManageControls:i,size:c="default",className:u,primaryButtonClassName:m,secondaryButtonClassName:l,dropdownContentClassName:o}){const p=c==="toolbar";return e.jsxs("div",{className:r.cn("relative inline-flex items-stretch overflow-hidden rounded-control border border-input bg-background",p?"h-8":"h-7",u),children:[e.jsxs(r.Button,{variant:"ghost",size:"xs",className:r.cn("h-full rounded-none border-0 bg-transparent pl-2.5 pr-2 shadow-none hover:bg-accent/50",m),onClick:a,children:[s?e.jsx($,{className:"h-3.5 w-3.5"}):e.jsx(t.Filter,{className:"h-3.5 w-3.5"}),"Filter"]}),e.jsxs(t.DropdownMenu,{children:[e.jsx(t.DropdownMenuTrigger,{asChild:!0,children:e.jsx(r.Button,{variant:"ghost",size:"xs",className:r.cn("h-full w-7 rounded-none border-0 border-l border-border/60 bg-transparent px-0 shadow-none hover:bg-accent/50",l),"aria-label":"Filter and control actions",children:e.jsx(r.ChevronDown,{className:"h-3.5 w-3.5"})})}),e.jsxs(t.DropdownMenuContent,{align:"start",className:r.cn("min-w-[180px] rounded-control border border-border/60 p-1 shadow-sm",o),children:[e.jsxs(t.DropdownMenuItem,{onSelect:v,children:[e.jsx(t.Filter,{className:"h-3.5 w-3.5"}),"Add filter"]}),e.jsxs(t.DropdownMenuItem,{onSelect:d,children:[e.jsx(r.SlidersHorizontal,{className:"h-3.5 w-3.5"}),"Add control"]}),e.jsxs(t.DropdownMenuItem,{onSelect:i,children:[e.jsx(t.Pencil,{className:"h-3.5 w-3.5"}),"Manage controls"]})]})]})]})}exports.AdvancedModeToggle=se;exports.DashboardControlsSettings=ne;exports.DashboardFilterControlsButton=ie;exports.ExportNotificationItem=z;exports.ExportNotificationList=H;exports.NotificationBell=ae;exports.UnsavedChangesAlert=re;exports.VisualEditingControls=te;exports.useExportPolling=W;exports.useExportRecovery=Y;
@@ -1,8 +1,8 @@
1
1
  import { jsxs as i, jsx as t } from "react/jsx-runtime";
2
2
  import { useMemo as m, useState as b, useRef as f, useEffect as S } from "react";
3
- import { u as o, a as N, B as p, X as D, C as J } from "./switch-CZtMtqEj.js";
4
- import "./index-BmoR3VQT.js";
5
- import "./index-uRJmUpof.js";
3
+ import { u as o, a as N, B as p, X as D, C as J } from "./switch-BFhVVwh9.js";
4
+ import "./index-GHhvGdF9.js";
5
+ import "./index-CJdxSyQq.js";
6
6
  import "react-dom";
7
7
  function C() {
8
8
  const e = o((s) => s.dashboard), c = o((s) => s.actions.setDashboard), h = o(
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),o=require("react"),s=require("./switch-AmoR1YIA.js");require("./index-eM6MU4q_.js");require("./index-Cxb9UUro.js");require("react-dom");function b(){const t=s.useDashboardStore(e=>e.dashboard),c=s.useDashboardStore(e=>e.actions.setDashboard),u=s.useDashboardStore(e=>e.showDashboardJSON),h=s.useDashboardStore(e=>e.actions.setShowDashboardJSON),a=o.useMemo(()=>t?JSON.stringify(t,null,2):"",[t]),[l,d]=o.useState(a),n=o.useRef(a);return o.useEffect(()=>{a!==n.current&&(d(a),n.current=a)},[a]),r.jsxs("div",{className:s.cn("relative p-2",{hidden:!u}),children:[r.jsxs(s.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>h(!1),children:[r.jsx(s.X,{className:"mr-2 h-4 w-4"}),"Close"]}),r.jsx("div",{className:"h-[550px] overflow-hidden",children:r.jsx(s.CodeEditor,{value:l,onValueChange:e=>{d(e);try{const i=JSON.parse(e);n.current=JSON.stringify(i,null,2),c(i)}catch{}},language:"json"})})]})}exports.default=b;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),o=require("react"),s=require("./switch-BH17qlxH.js");require("./index-D2vz3gvd.js");require("./index-DRlMUglg.js");require("react-dom");function b(){const t=s.useDashboardStore(e=>e.dashboard),c=s.useDashboardStore(e=>e.actions.setDashboard),u=s.useDashboardStore(e=>e.showDashboardJSON),h=s.useDashboardStore(e=>e.actions.setShowDashboardJSON),a=o.useMemo(()=>t?JSON.stringify(t,null,2):"",[t]),[l,d]=o.useState(a),n=o.useRef(a);return o.useEffect(()=>{a!==n.current&&(d(a),n.current=a)},[a]),r.jsxs("div",{className:s.cn("relative p-2",{hidden:!u}),children:[r.jsxs(s.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>h(!1),children:[r.jsx(s.X,{className:"mr-2 h-4 w-4"}),"Close"]}),r.jsx("div",{className:"h-[550px] overflow-hidden",children:r.jsx(s.CodeEditor,{value:l,onValueChange:e=>{d(e);try{const i=JSON.parse(e);n.current=JSON.stringify(i,null,2),c(i)}catch{}},language:"json"})})]})}exports.default=b;
@@ -1,7 +1,7 @@
1
1
  import { jsx as e, jsxs as a, Fragment as ue } from "react/jsx-runtime";
2
2
  import me, { useState as f, useCallback as H, useEffect as q, useMemo as U } from "react";
3
- import { u as he, b as Q, c as ee, d as ae, e as te, f as se, R, g as $, C as fe, h as pe, i as be, j as ve, k as ge, l as V, m as G, n as xe, o as re, p as I } from "./index-BmoR3VQT.js";
4
- import { a as k, L as P, P as Se, b as ye, B as A, d as Ne, e as X, f as we, S as ke, g as Ce, h as Te, i as Ie, j as Pe, k as Z, I as Ae } from "./switch-CZtMtqEj.js";
3
+ import { u as he, b as Q, c as ee, d as ae, e as te, f as se, R, g as $, C as fe, h as pe, i as be, j as ve, k as ge, l as V, m as G, n as xe, o as re, p as I } from "./index-GHhvGdF9.js";
4
+ import { a as k, L as P, P as Se, b as ye, B as A, d as Ne, e as X, f as we, S as ke, g as Ce, h as Te, i as Ie, j as Pe, k as Z, I as Ae } from "./switch-BFhVVwh9.js";
5
5
  function ze(r = {}) {
6
6
  var T, L, D, M;
7
7
  const { authToken: i, tokenProps: t } = he(), g = r.enabled ?? !0, o = (i == null ? void 0 : i.accessToken) ?? null, h = (t == null ? void 0 : t.apiServiceUrl) ?? null, [N, S] = f(!1), [x, b] = f(!1), [u, n] = f(!1), [y, c] = f(null), [p, w] = f(null), z = p || {
@@ -1 +1 @@
1
- "use strict";const e=require("react/jsx-runtime"),o=require("react"),a=require("./index-eM6MU4q_.js"),s=require("./switch-AmoR1YIA.js");function q(n={}){var k,P,A,E;const{authToken:c,tokenProps:t}=a.useSemaphorContext(),S=n.enabled??!0,u=(c==null?void 0:c.accessToken)??null,f=(t==null?void 0:t.apiServiceUrl)??null,[N,j]=o.useState(!1),[v,b]=o.useState(!1),[h,l]=o.useState(!1),[y,d]=o.useState(null),[p,w]=o.useState(null),T=p||{tz:((P=(k=t==null?void 0:t.params)==null?void 0:k.calendarContext)==null?void 0:P.tz)||null,weekStart:((E=(A=t==null?void 0:t.params)==null?void 0:A.calendarContext)==null?void 0:E.weekStart)??null},g=o.useCallback(async()=>{if(!(!S||!u||!f)){j(!0),d(null);try{const m=await fetch(`${f}/v1/user-preferences/calendar`,{method:"GET",headers:{Authorization:`Bearer ${u}`}});if(!m.ok){const x=await m.json().catch(()=>({}));throw new Error(x.error||"Failed to fetch preferences")}const i=await m.json();w({tz:i.tz,weekStart:i.weekStart,source:i.source,isInherited:i.isInherited,userHasPrefs:i.userHasPrefs,inherited:i.inherited})}catch(m){const i=m instanceof Error?m.message:"Unknown error";d(i)}finally{j(!1)}}},[u,f,S]);o.useEffect(()=>{S&&g()},[S,g]);const I=o.useCallback(async m=>{if(!u||!f)return d("Not authenticated"),!1;b(!0),d(null);try{const i=await fetch(`${f}/v1/user-preferences/calendar`,{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:`Bearer ${u}`},body:JSON.stringify(m)});if(!i.ok){const x=await i.json().catch(()=>({}));throw new Error(x.error||"Failed to update preferences")}return await g(),!0}catch(i){const x=i instanceof Error?i.message:"Unknown error";return d(x),!1}finally{b(!1)}},[u,f,g]),C=o.useCallback(async()=>{if(!u||!f)return d("Not authenticated"),!1;l(!0),d(null);try{const m=await fetch(`${f}/v1/user-preferences/calendar`,{method:"DELETE",headers:{Authorization:`Bearer ${u}`}});if(!m.ok){const x=await m.json().catch(()=>({}));throw new Error(x.error||"Failed to clear preferences")}const i=await m.text();if(i)try{const x=JSON.parse(i);return w({tz:x.tz,weekStart:x.weekStart,source:x.source,isInherited:x.isInherited??!0,userHasPrefs:!1,inherited:x.inherited}),!0}catch{}return await g(),!0}catch(m){const i=m instanceof Error?m.message:"Unknown error";return d(i),!1}finally{l(!1)}},[u,f,g]);return{preferences:T,isLoading:N,isSaving:v,isClearing:h,error:y,updatePreferences:I,clearPreferences:C,refetch:g}}const D=[{value:"America/New_York",label:"Eastern Time (US & Canada)"},{value:"America/Chicago",label:"Central Time (US & Canada)"},{value:"America/Denver",label:"Mountain Time (US & Canada)"},{value:"America/Los_Angeles",label:"Pacific Time (US & Canada)"},{value:"America/Phoenix",label:"Arizona"},{value:"America/Anchorage",label:"Alaska"},{value:"Pacific/Honolulu",label:"Hawaii"},{value:"Europe/London",label:"London"},{value:"Europe/Paris",label:"Paris, Berlin, Rome"},{value:"Asia/Tokyo",label:"Tokyo"},{value:"Asia/Shanghai",label:"Beijing, Shanghai"},{value:"Asia/Kolkata",label:"Mumbai, New Delhi"},{value:"Australia/Sydney",label:"Sydney"},{value:"UTC",label:"UTC"}],$=[{value:0,label:"Sunday"},{value:1,label:"Monday"},{value:6,label:"Saturday"}],B="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function X(){try{const n=Intl;if(n.supportedValuesOf)return n.supportedValuesOf("timeZone")}catch{}return D.map(n=>n.value)}function Z(n){switch(n){case"tenant":return"tenant";case"organization":return"organization";case"system":return"system";default:return"default"}}function _(n){const c=D.find(t=>t.value===n);return c?c.label:n}function J(n){const c=$.find(t=>t.value===n);return c?c.label:String(n)}function K({open:n,onOpenChange:c}){var M,F,U;const{preferences:t,isLoading:S,isSaving:u,isClearing:f,updatePreferences:N,clearPreferences:j}=q({enabled:n}),v=t.tz||((M=t.inherited)==null?void 0:M.tz)||Intl.DateTimeFormat().resolvedOptions().timeZone,b=t.weekStart??((F=t.inherited)==null?void 0:F.weekStart)??1,[h,l]=o.useState(!t.userHasPrefs),[y,d]=o.useState(!1),[p,w]=o.useState(v),[T,g]=o.useState(b),[I,C]=o.useState(!1),k=o.useMemo(()=>X(),[]),P=o.useMemo(()=>k.filter(r=>!D.some(V=>V.value===r)),[k]),A=o.useMemo(()=>_(p),[p]),E=t.inherited?_(t.inherited.tz):"UTC",m=t.inherited?J(t.inherited.weekStart):"Monday",i=Z((U=t.inherited)==null?void 0:U.source);o.useEffect(()=>{if(!n){d(!1);return}y||(t.userHasPrefs!==void 0&&l(!t.userHasPrefs),w(v),g(b))},[n,y,t.userHasPrefs,v,b]);const x=async()=>{if(S){a.ue.error("Preferences are still loading. Please try again.");return}h?await j()?(a.ue.success("Now using default settings. Please refresh the page to apply changes.",{duration:5e3}),c(!1)):a.ue.error("Failed to save preferences. Please try again."):await N({tz:p,weekStart:T})?(a.ue.success("Preferences saved. Please refresh the page to apply changes.",{duration:5e3}),c(!1)):a.ue.error("Failed to save preferences. Please try again.")},G=()=>{c(!1)},L=u||f,W=L||S;return e.jsx(a.Dialog,{open:n,onOpenChange:c,children:e.jsxs(a.DialogContent,{className:"rounded-control border-border/60 sm:max-w-[440px] sm:rounded-control",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{className:"text-[15px]",children:"Calendar preferences"}),e.jsx(a.DialogDescription,{className:"text-[13px] leading-5",children:"Set your timezone and week-start for date calculations and displays."})]}),e.jsxs("div",{className:"space-y-4 py-1",children:[e.jsxs(a.RadioGroup,{value:h?"defaults":"custom",onValueChange:r=>{d(!0),l(r==="defaults")},className:"space-y-0.5",children:[e.jsxs("label",{htmlFor:"mode-defaults",className:s.cn("flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",h&&"bg-muted/50"),onClick:()=>{d(!0),l(!0)},children:[e.jsx(a.RadioGroupItem,{value:"defaults",id:"mode-defaults",className:"mt-0.5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"text-[13px] font-medium text-foreground",children:["Use ",i," defaults"]}),e.jsxs("p",{className:"text-[12px] text-muted-foreground",children:[E,", week starts ",m]})]})]}),e.jsxs("label",{htmlFor:"mode-custom",className:s.cn("flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",!h&&"bg-muted/50"),onClick:()=>{d(!0),l(!1)},children:[e.jsx(a.RadioGroupItem,{value:"custom",id:"mode-custom",className:"mt-0.5"}),e.jsx("p",{className:"flex-1 text-[13px] font-medium text-foreground",children:"Use custom settings"})]})]}),e.jsxs("div",{className:s.cn("space-y-4 border-t border-border/60 pt-4 transition-opacity",h&&"pointer-events-none opacity-50"),children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:B,children:"Timezone"}),e.jsxs(s.Popover,{open:I,onOpenChange:C,modal:!0,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",size:"xs",role:"combobox","aria-expanded":I,className:"w-full justify-between text-[12px] font-normal",disabled:h,children:[e.jsx("span",{className:"truncate",children:A}),e.jsx(a.ChevronsUpDown,{className:"ml-2 h-3.5 w-3.5 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"z-50 w-[--radix-popover-trigger-width] p-0",align:"start",children:e.jsxs(a.Command,{className:"overflow-visible",children:[e.jsx(a.CommandInput,{placeholder:"Search timezones…"}),e.jsxs(a.CommandList,{children:[e.jsx(a.CommandEmpty,{children:"No timezone found."}),e.jsx(a.CommandGroup,{heading:"Common",children:D.map(r=>e.jsxs(a.CommandItem,{value:`${r.value} ${r.label}`,onSelect:()=>{d(!0),w(r.value),C(!1)},children:[e.jsx(s.Check,{className:s.cn("h-3.5 w-3.5",p===r.value?"opacity-100":"opacity-0")}),e.jsx("span",{className:"flex-1",children:r.label}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:r.value})]},r.value))}),e.jsx(a.CommandSeparator,{}),e.jsx(a.CommandGroup,{heading:"All timezones",children:P.map(r=>e.jsxs(a.CommandItem,{value:r,onSelect:()=>{d(!0),w(r),C(!1)},children:[e.jsx(s.Check,{className:s.cn("h-3.5 w-3.5",p===r?"opacity-100":"opacity-0")}),r]},r))})]})]})})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:B,children:"Week starts on"}),e.jsx(a.RadioGroup,{value:String(T),onValueChange:r=>{d(!0),g(Number(r))},className:"flex gap-4",disabled:h,children:$.map(r=>e.jsxs("label",{htmlFor:`week-start-${r.value}`,className:s.cn("flex cursor-pointer items-center gap-2 text-[13px]",h&&"cursor-not-allowed"),children:[e.jsx(a.RadioGroupItem,{value:String(r.value),id:`week-start-${r.value}`,disabled:h}),r.label]},r.value))})]})]})]}),e.jsxs(a.DialogFooter,{children:[e.jsx(s.Button,{variant:"outline",size:"xs",onClick:G,disabled:L,children:"Cancel"}),e.jsx(s.Button,{size:"xs",onClick:x,disabled:W,children:L?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving…"]}):"Save"})]})]})})}const z=6,O=1,R=20,H="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function Y(n){return Number.isNaN(n)?z:Math.min(R,Math.max(O,n))}function Q({open:n,onOpenChange:c,dashboard:t,onApply:S,disabled:u=!1}){const[f,N]=o.useState(!1),[j,v]=o.useState("top"),[b,h]=o.useState(String(z)),l=t.summary;o.useEffect(()=>{n&&(N((l==null?void 0:l.enabled)===!0),v((l==null?void 0:l.position)==="bottom"?"bottom":"top"),h(String((l==null?void 0:l.maxItems)??z)))},[n,l==null?void 0:l.enabled,l==null?void 0:l.position,l==null?void 0:l.maxItems]);const y=o.useMemo(()=>Y(Number.parseInt(b||`${z}`,10)),[b]),d=()=>{S({enabled:f,position:j,maxItems:y}),c(!1)};return e.jsx(a.Dialog,{open:n,onOpenChange:c,children:e.jsxs(a.DialogContent,{className:"rounded-control border-border/60 sm:max-w-[420px] sm:rounded-control",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{className:"text-[15px]",children:"Summary Settings"}),e.jsx(a.DialogDescription,{className:"text-[13px] leading-5",children:"Configure dashboard-level summary display. Card-level summary settings still control which cards contribute."})]}),e.jsxs("div",{className:"space-y-4 py-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{htmlFor:"dashboard-summary-enabled",className:"text-[13px]",children:"Enable dashboard summary"}),e.jsx(s.Switch,{size:"xs",id:"dashboard-summary-enabled",checked:f,disabled:u,onCheckedChange:N})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{htmlFor:"dashboard-summary-position",className:H,children:"Position"}),e.jsxs(s.Select,{value:j,disabled:u,onValueChange:p=>v(p),children:[e.jsx(s.SelectTrigger,{id:"dashboard-summary-position",size:"xs",children:e.jsx(s.SelectValue,{placeholder:"Select position"})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"top",children:"Top"}),e.jsx(s.SelectItem,{value:"bottom",children:"Bottom"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{htmlFor:"dashboard-summary-max-items",className:H,children:"Max items"}),e.jsx(s.Input,{size:"xs",id:"dashboard-summary-max-items",type:"number",min:O,max:R,disabled:u,value:b,onChange:p=>h(p.target.value),onBlur:()=>h(String(y))}),e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Display limit only. Computation is unchanged."})]}),u&&e.jsx("p",{className:"text-[12px] text-amber-700",children:"Enter dashboard edit mode to modify summary settings."})]}),e.jsxs(a.DialogFooter,{children:[e.jsx(s.Button,{variant:"outline",size:"xs",onClick:()=>c(!1),children:"Cancel"}),e.jsx(s.Button,{size:"xs",onClick:d,disabled:u,children:"Apply"})]})]})})}exports.CalendarPreferencesDialog=K;exports.DashboardSummarySettingsDialog=Q;
1
+ "use strict";const e=require("react/jsx-runtime"),o=require("react"),a=require("./index-D2vz3gvd.js"),s=require("./switch-BH17qlxH.js");function q(n={}){var k,P,A,E;const{authToken:c,tokenProps:t}=a.useSemaphorContext(),S=n.enabled??!0,u=(c==null?void 0:c.accessToken)??null,f=(t==null?void 0:t.apiServiceUrl)??null,[N,j]=o.useState(!1),[v,b]=o.useState(!1),[h,l]=o.useState(!1),[y,d]=o.useState(null),[p,w]=o.useState(null),T=p||{tz:((P=(k=t==null?void 0:t.params)==null?void 0:k.calendarContext)==null?void 0:P.tz)||null,weekStart:((E=(A=t==null?void 0:t.params)==null?void 0:A.calendarContext)==null?void 0:E.weekStart)??null},g=o.useCallback(async()=>{if(!(!S||!u||!f)){j(!0),d(null);try{const m=await fetch(`${f}/v1/user-preferences/calendar`,{method:"GET",headers:{Authorization:`Bearer ${u}`}});if(!m.ok){const x=await m.json().catch(()=>({}));throw new Error(x.error||"Failed to fetch preferences")}const i=await m.json();w({tz:i.tz,weekStart:i.weekStart,source:i.source,isInherited:i.isInherited,userHasPrefs:i.userHasPrefs,inherited:i.inherited})}catch(m){const i=m instanceof Error?m.message:"Unknown error";d(i)}finally{j(!1)}}},[u,f,S]);o.useEffect(()=>{S&&g()},[S,g]);const I=o.useCallback(async m=>{if(!u||!f)return d("Not authenticated"),!1;b(!0),d(null);try{const i=await fetch(`${f}/v1/user-preferences/calendar`,{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:`Bearer ${u}`},body:JSON.stringify(m)});if(!i.ok){const x=await i.json().catch(()=>({}));throw new Error(x.error||"Failed to update preferences")}return await g(),!0}catch(i){const x=i instanceof Error?i.message:"Unknown error";return d(x),!1}finally{b(!1)}},[u,f,g]),C=o.useCallback(async()=>{if(!u||!f)return d("Not authenticated"),!1;l(!0),d(null);try{const m=await fetch(`${f}/v1/user-preferences/calendar`,{method:"DELETE",headers:{Authorization:`Bearer ${u}`}});if(!m.ok){const x=await m.json().catch(()=>({}));throw new Error(x.error||"Failed to clear preferences")}const i=await m.text();if(i)try{const x=JSON.parse(i);return w({tz:x.tz,weekStart:x.weekStart,source:x.source,isInherited:x.isInherited??!0,userHasPrefs:!1,inherited:x.inherited}),!0}catch{}return await g(),!0}catch(m){const i=m instanceof Error?m.message:"Unknown error";return d(i),!1}finally{l(!1)}},[u,f,g]);return{preferences:T,isLoading:N,isSaving:v,isClearing:h,error:y,updatePreferences:I,clearPreferences:C,refetch:g}}const D=[{value:"America/New_York",label:"Eastern Time (US & Canada)"},{value:"America/Chicago",label:"Central Time (US & Canada)"},{value:"America/Denver",label:"Mountain Time (US & Canada)"},{value:"America/Los_Angeles",label:"Pacific Time (US & Canada)"},{value:"America/Phoenix",label:"Arizona"},{value:"America/Anchorage",label:"Alaska"},{value:"Pacific/Honolulu",label:"Hawaii"},{value:"Europe/London",label:"London"},{value:"Europe/Paris",label:"Paris, Berlin, Rome"},{value:"Asia/Tokyo",label:"Tokyo"},{value:"Asia/Shanghai",label:"Beijing, Shanghai"},{value:"Asia/Kolkata",label:"Mumbai, New Delhi"},{value:"Australia/Sydney",label:"Sydney"},{value:"UTC",label:"UTC"}],$=[{value:0,label:"Sunday"},{value:1,label:"Monday"},{value:6,label:"Saturday"}],B="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function X(){try{const n=Intl;if(n.supportedValuesOf)return n.supportedValuesOf("timeZone")}catch{}return D.map(n=>n.value)}function Z(n){switch(n){case"tenant":return"tenant";case"organization":return"organization";case"system":return"system";default:return"default"}}function _(n){const c=D.find(t=>t.value===n);return c?c.label:n}function J(n){const c=$.find(t=>t.value===n);return c?c.label:String(n)}function K({open:n,onOpenChange:c}){var M,F,U;const{preferences:t,isLoading:S,isSaving:u,isClearing:f,updatePreferences:N,clearPreferences:j}=q({enabled:n}),v=t.tz||((M=t.inherited)==null?void 0:M.tz)||Intl.DateTimeFormat().resolvedOptions().timeZone,b=t.weekStart??((F=t.inherited)==null?void 0:F.weekStart)??1,[h,l]=o.useState(!t.userHasPrefs),[y,d]=o.useState(!1),[p,w]=o.useState(v),[T,g]=o.useState(b),[I,C]=o.useState(!1),k=o.useMemo(()=>X(),[]),P=o.useMemo(()=>k.filter(r=>!D.some(V=>V.value===r)),[k]),A=o.useMemo(()=>_(p),[p]),E=t.inherited?_(t.inherited.tz):"UTC",m=t.inherited?J(t.inherited.weekStart):"Monday",i=Z((U=t.inherited)==null?void 0:U.source);o.useEffect(()=>{if(!n){d(!1);return}y||(t.userHasPrefs!==void 0&&l(!t.userHasPrefs),w(v),g(b))},[n,y,t.userHasPrefs,v,b]);const x=async()=>{if(S){a.ue.error("Preferences are still loading. Please try again.");return}h?await j()?(a.ue.success("Now using default settings. Please refresh the page to apply changes.",{duration:5e3}),c(!1)):a.ue.error("Failed to save preferences. Please try again."):await N({tz:p,weekStart:T})?(a.ue.success("Preferences saved. Please refresh the page to apply changes.",{duration:5e3}),c(!1)):a.ue.error("Failed to save preferences. Please try again.")},G=()=>{c(!1)},L=u||f,W=L||S;return e.jsx(a.Dialog,{open:n,onOpenChange:c,children:e.jsxs(a.DialogContent,{className:"rounded-control border-border/60 sm:max-w-[440px] sm:rounded-control",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{className:"text-[15px]",children:"Calendar preferences"}),e.jsx(a.DialogDescription,{className:"text-[13px] leading-5",children:"Set your timezone and week-start for date calculations and displays."})]}),e.jsxs("div",{className:"space-y-4 py-1",children:[e.jsxs(a.RadioGroup,{value:h?"defaults":"custom",onValueChange:r=>{d(!0),l(r==="defaults")},className:"space-y-0.5",children:[e.jsxs("label",{htmlFor:"mode-defaults",className:s.cn("flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",h&&"bg-muted/50"),onClick:()=>{d(!0),l(!0)},children:[e.jsx(a.RadioGroupItem,{value:"defaults",id:"mode-defaults",className:"mt-0.5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"text-[13px] font-medium text-foreground",children:["Use ",i," defaults"]}),e.jsxs("p",{className:"text-[12px] text-muted-foreground",children:[E,", week starts ",m]})]})]}),e.jsxs("label",{htmlFor:"mode-custom",className:s.cn("flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",!h&&"bg-muted/50"),onClick:()=>{d(!0),l(!1)},children:[e.jsx(a.RadioGroupItem,{value:"custom",id:"mode-custom",className:"mt-0.5"}),e.jsx("p",{className:"flex-1 text-[13px] font-medium text-foreground",children:"Use custom settings"})]})]}),e.jsxs("div",{className:s.cn("space-y-4 border-t border-border/60 pt-4 transition-opacity",h&&"pointer-events-none opacity-50"),children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:B,children:"Timezone"}),e.jsxs(s.Popover,{open:I,onOpenChange:C,modal:!0,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",size:"xs",role:"combobox","aria-expanded":I,className:"w-full justify-between text-[12px] font-normal",disabled:h,children:[e.jsx("span",{className:"truncate",children:A}),e.jsx(a.ChevronsUpDown,{className:"ml-2 h-3.5 w-3.5 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"z-50 w-[--radix-popover-trigger-width] p-0",align:"start",children:e.jsxs(a.Command,{className:"overflow-visible",children:[e.jsx(a.CommandInput,{placeholder:"Search timezones…"}),e.jsxs(a.CommandList,{children:[e.jsx(a.CommandEmpty,{children:"No timezone found."}),e.jsx(a.CommandGroup,{heading:"Common",children:D.map(r=>e.jsxs(a.CommandItem,{value:`${r.value} ${r.label}`,onSelect:()=>{d(!0),w(r.value),C(!1)},children:[e.jsx(s.Check,{className:s.cn("h-3.5 w-3.5",p===r.value?"opacity-100":"opacity-0")}),e.jsx("span",{className:"flex-1",children:r.label}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:r.value})]},r.value))}),e.jsx(a.CommandSeparator,{}),e.jsx(a.CommandGroup,{heading:"All timezones",children:P.map(r=>e.jsxs(a.CommandItem,{value:r,onSelect:()=>{d(!0),w(r),C(!1)},children:[e.jsx(s.Check,{className:s.cn("h-3.5 w-3.5",p===r?"opacity-100":"opacity-0")}),r]},r))})]})]})})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:B,children:"Week starts on"}),e.jsx(a.RadioGroup,{value:String(T),onValueChange:r=>{d(!0),g(Number(r))},className:"flex gap-4",disabled:h,children:$.map(r=>e.jsxs("label",{htmlFor:`week-start-${r.value}`,className:s.cn("flex cursor-pointer items-center gap-2 text-[13px]",h&&"cursor-not-allowed"),children:[e.jsx(a.RadioGroupItem,{value:String(r.value),id:`week-start-${r.value}`,disabled:h}),r.label]},r.value))})]})]})]}),e.jsxs(a.DialogFooter,{children:[e.jsx(s.Button,{variant:"outline",size:"xs",onClick:G,disabled:L,children:"Cancel"}),e.jsx(s.Button,{size:"xs",onClick:x,disabled:W,children:L?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving…"]}):"Save"})]})]})})}const z=6,O=1,R=20,H="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function Y(n){return Number.isNaN(n)?z:Math.min(R,Math.max(O,n))}function Q({open:n,onOpenChange:c,dashboard:t,onApply:S,disabled:u=!1}){const[f,N]=o.useState(!1),[j,v]=o.useState("top"),[b,h]=o.useState(String(z)),l=t.summary;o.useEffect(()=>{n&&(N((l==null?void 0:l.enabled)===!0),v((l==null?void 0:l.position)==="bottom"?"bottom":"top"),h(String((l==null?void 0:l.maxItems)??z)))},[n,l==null?void 0:l.enabled,l==null?void 0:l.position,l==null?void 0:l.maxItems]);const y=o.useMemo(()=>Y(Number.parseInt(b||`${z}`,10)),[b]),d=()=>{S({enabled:f,position:j,maxItems:y}),c(!1)};return e.jsx(a.Dialog,{open:n,onOpenChange:c,children:e.jsxs(a.DialogContent,{className:"rounded-control border-border/60 sm:max-w-[420px] sm:rounded-control",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{className:"text-[15px]",children:"Summary Settings"}),e.jsx(a.DialogDescription,{className:"text-[13px] leading-5",children:"Configure dashboard-level summary display. Card-level summary settings still control which cards contribute."})]}),e.jsxs("div",{className:"space-y-4 py-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{htmlFor:"dashboard-summary-enabled",className:"text-[13px]",children:"Enable dashboard summary"}),e.jsx(s.Switch,{size:"xs",id:"dashboard-summary-enabled",checked:f,disabled:u,onCheckedChange:N})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{htmlFor:"dashboard-summary-position",className:H,children:"Position"}),e.jsxs(s.Select,{value:j,disabled:u,onValueChange:p=>v(p),children:[e.jsx(s.SelectTrigger,{id:"dashboard-summary-position",size:"xs",children:e.jsx(s.SelectValue,{placeholder:"Select position"})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"top",children:"Top"}),e.jsx(s.SelectItem,{value:"bottom",children:"Bottom"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{htmlFor:"dashboard-summary-max-items",className:H,children:"Max items"}),e.jsx(s.Input,{size:"xs",id:"dashboard-summary-max-items",type:"number",min:O,max:R,disabled:u,value:b,onChange:p=>h(p.target.value),onBlur:()=>h(String(y))}),e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Display limit only. Computation is unchanged."})]}),u&&e.jsx("p",{className:"text-[12px] text-amber-700",children:"Enter dashboard edit mode to modify summary settings."})]}),e.jsxs(a.DialogFooter,{children:[e.jsx(s.Button,{variant:"outline",size:"xs",onClick:()=>c(!1),children:"Cancel"}),e.jsx(s.Button,{size:"xs",onClick:d,disabled:u,children:"Apply"})]})]})})}exports.CalendarPreferencesDialog=K;exports.DashboardSummarySettingsDialog=Q;