react-semaphor 0.1.311 → 0.1.313

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 (49) hide show
  1. package/dist/brand-studio/index.cjs +1 -1
  2. package/dist/brand-studio/index.js +4 -4
  3. package/dist/chunks/{braces-DwaAt32i.js → braces-NfG5hX2c.js} +1 -1
  4. package/dist/chunks/{braces-CSECDaJQ.js → braces-raPCNcS4.js} +1 -1
  5. package/dist/chunks/{chevrons-up-down-DJhB8JNW.js → chevrons-up-down-BYzO4q5w.js} +1 -1
  6. package/dist/chunks/{chevrons-up-down-3vBEM7eI.js → chevrons-up-down-DiWloubI.js} +1 -1
  7. package/dist/chunks/dashboard-controls-DMsmUQkB.js +2043 -0
  8. package/dist/chunks/dashboard-controls-wPVXTTiH.js +57 -0
  9. package/dist/chunks/dashboard-filter-controls-launcher-CqXgWEa1.js +1540 -0
  10. package/dist/chunks/dashboard-filter-controls-launcher-DBmNn4EY.js +11 -0
  11. package/dist/chunks/{dashboard-json-GL_IXTCk.js → dashboard-json-CHoCrAp0.js} +2 -2
  12. package/dist/chunks/{dashboard-json-B_rQbUUz.js → dashboard-json-DMFZLkws.js} +1 -1
  13. package/dist/chunks/{dashboard-summary-settings-dialog-CcszMc1A.js → dashboard-summary-settings-dialog-CZkn4rtm.js} +3 -3
  14. package/dist/chunks/{dashboard-summary-settings-dialog-DgqFlYl9.js → dashboard-summary-settings-dialog-DoxcpXjk.js} +1 -1
  15. package/dist/chunks/{edit-dashboard-visual-nGSsSTYx.js → edit-dashboard-visual-B0Ae_O25.js} +4534 -4470
  16. package/dist/chunks/edit-dashboard-visual-CIP9G-Bu.js +183 -0
  17. package/dist/chunks/{index-9v7DehZd.js → index-D7e2Eyp_.js} +34869 -34317
  18. package/dist/chunks/{index-CGCrm-dj.js → index-DjZqoaV5.js} +228 -228
  19. package/dist/chunks/{palette-CI2J34i6.js → palette-7yJYVEvk.js} +1 -1
  20. package/dist/chunks/{palette-C5o9bLo6.js → palette-CJTdBzJB.js} +1 -1
  21. package/dist/chunks/{resource-management-panel-CNmVHnCz.js → resource-management-panel-B1mhnY97.js} +1 -1
  22. package/dist/chunks/{resource-management-panel-DTg9_DI9.js → resource-management-panel-CSkNW3es.js} +3 -3
  23. package/dist/chunks/{save-CMv91_Hz.js → save-B8x5Vi0W.js} +1 -1
  24. package/dist/chunks/{save-Cpz6BWx9.js → save-DDX_vrED.js} +1 -1
  25. package/dist/chunks/{switch-Dhoqe3OE.js → switch-DEPWsRhf.js} +114 -113
  26. package/dist/chunks/{switch-otrSiyjH.js → switch-DPaKnsb8.js} +14 -14
  27. package/dist/chunks/use-create-flow-overlay-state-7LiC_vaL.js +16 -0
  28. package/dist/chunks/{use-create-flow-overlay-state-C8WGfC8T.js → use-create-flow-overlay-state-BHQjJwik.js} +511 -483
  29. package/dist/chunks/{use-visual-utils-BeJ73yvV.js → use-visual-utils-Bz7kjSrk.js} +1 -1
  30. package/dist/chunks/{use-visual-utils-RkPa2gqQ.js → use-visual-utils-Dw-uLgop.js} +2 -2
  31. package/dist/dashboard/index.cjs +1 -1
  32. package/dist/dashboard/index.js +1 -1
  33. package/dist/index.cjs +1 -1
  34. package/dist/index.js +76 -74
  35. package/dist/style.css +1 -1
  36. package/dist/surfboard/index.cjs +1 -1
  37. package/dist/surfboard/index.js +2 -2
  38. package/dist/types/dashboard.d.ts +1 -1
  39. package/dist/types/main.d.ts +76 -23
  40. package/dist/types/shared.d.ts +1 -1
  41. package/dist/types/surfboard.d.ts +1 -1
  42. package/dist/types/types.d.ts +1 -1
  43. package/package.json +1 -1
  44. package/dist/chunks/dashboard-controls-CeKjYa7s.js +0 -2274
  45. package/dist/chunks/dashboard-controls-Ds8Hmo3Q.js +0 -57
  46. package/dist/chunks/dashboard-filter-controls-button-CWL2jJcu.js +0 -11
  47. package/dist/chunks/dashboard-filter-controls-button-Tk5lhwVV.js +0 -1116
  48. package/dist/chunks/edit-dashboard-visual-Bu2rxJjm.js +0 -183
  49. package/dist/chunks/use-create-flow-overlay-state-DiH6M1Cd.js +0 -16
@@ -0,0 +1,11 @@
1
+ "use strict";const e=require("react/jsx-runtime"),o=require("./switch-DPaKnsb8.js"),s=require("./index-DjZqoaV5.js"),k=require("./use-create-flow-overlay-state-7LiC_vaL.js"),v=require("react"),_=require("./use-visual-utils-Bz7kjSrk.js"),V=require("./date-formatter-D9Bvw5Qk.js");require("./index-DRlMUglg.js");require("react-dom");/**
2
+ * @license lucide-react v0.453.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const U=o.createLucideIcon("FileDown",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M12 18v-6",key:"17g6i2"}],["path",{d:"m9 15 3 3 3-3",key:"1npd3o"}]]);/**
7
+ * @license lucide-react v0.453.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */const X=o.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"}]]);function K({open:t,onOpenChange:a,isLibraryVisual:h,currentVisualName:u,isSaving:n=!1,destinationMode:p="both",onConfirm:d}){const[c,l]=v.useState(h&&u?`Copy of ${u}`:u||""),[r,x]=v.useState("");v.useEffect(()=>{t&&(l(h&&u?`Copy of ${u}`:u||""),x(""))},[t,h,u]);const C=!!c.trim(),i=p==="local"?{saveToLibrary:!1,saveToCurrentDashboard:!0,badgeType:"local",description:"Creates a local copy on the current dashboard.",actionLabel:"Add to Dashboard (Local)"}:p==="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"},m=()=>{!C||n||d({name:c.trim(),description:r.trim()||void 0,saveToLibrary:i.saveToLibrary,saveToCurrentDashboard:i.saveToCurrentDashboard})};return e.jsx(s.Dialog,{open:t,onOpenChange:a,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"}),i.badgeType!=="local"&&e.jsx(k.VisualBadge,{type:i.badgeType,showLabel:!0,className:"px-2 py-0.5"})]}),e.jsx(s.DialogDescription,{children:i.description})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(o.Label,{htmlFor:"name",children:"Name"}),e.jsx(o.Input,{id:"name",value:c,onChange:j=>l(j.target.value),placeholder:"Enter visual name",disabled:n})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(o.Label,{htmlFor:"description",children:"Description (optional)"}),e.jsx(s.Textarea,{id:"description",value:r,onChange:j=>x(j.target.value),placeholder:"Enter visual description",rows:3,disabled:n})]})]}),e.jsxs(s.DialogFooter,{children:[e.jsx(o.Button,{variant:"outline",onClick:()=>a(!1),disabled:n,children:"Cancel"}),e.jsxs(o.Button,{onClick:m,disabled:!C||n,children:[n&&e.jsx(o.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),i.actionLabel]})]})]})})}function Q(){const[t,a]=v.useState(!1),[h,u]=v.useState(!1),[n,p]=v.useState(null),[d,c]=v.useState(null),l=o.useEditorStore(g=>g.frame),r=o.useEditorStore(g=>g.card),x=s.useSelectedVisual(),C=o.useDashboardStore(g=>g.selectedSheetId),i=o.useDashboardStore(g=>g.dashboard),m=o.useDashboardStore(g=>g.actions.setIsDashboardPanelOpen),{getUpdatedFrame:j}=_.useVisualUtils(),{selectVisual:b}=s.useManagementActions(),{addFrame:D,setSelectedFrameId:N,setIsVisualEditing:E}=o.useDashboardActions(),f=s.useResolveExistingFrameSemanticExecutionPayload(),S=!!(l!=null&&l.visualId),I=(()=>{var g,y;return((g=l==null?void 0:l.cards)==null?void 0:g.length)===1&&((y=l.cards[0])!=null&&y.title)?l.cards[0].title:x!=null&&x.title?x.title:(r==null?void 0:r.title)||"Untitled Visual"})(),F=s.useCreateVisualWithFrame(g=>{g!=null&&g.id&&(b(g),h&&n&&d&&C&&(async()=>{try{const y={...n,id:o.v4(),visualId:g.id};D(C,y,{position:"end",semanticExecutionPayload:d}),N(y.id),u(!1),p(null),c(null),E(!1)}catch(y){console.error("Failed to promote semantic metadata for saved visual:",y),s.ue.error(y instanceof Error?y.message:"Failed to prepare semantic metadata for the saved visual")}})(),m(!0),a(!1))});return{saveAsDialogOpen:t,setSaveAsDialogOpen:a,handleSaveAs:async g=>{if(!C){s.ue.error("No sheet selected");return}const y=j(),P=o.getDynamicFrameSaveIssue(y);if(P){s.ue.error(P);return}const L=y.cards.length===1?{...y,cards:y.cards.map(T=>({...T,title:g.name}))}:y;if(g.saveToLibrary){let T=null;if(g.saveToCurrentDashboard)try{T=await f(L,{previousFrame:s.findDashboardFrameById(i,L.id)})}catch(O){console.error("Failed to prepare semantic metadata before saving visual:",O),s.ue.error(O instanceof Error?O.message:"Failed to prepare semantic metadata for the saved visual");return}u(g.saveToCurrentDashboard),p(L),c(T);const M={title:g.name,description:g.description,frameObject:L,isPrivate:!1};F.mutate(M)}else if(g.saveToCurrentDashboard){const T={...L,id:o.v4(),visualId:void 0};try{const M=await f(L,{previousFrame:s.findDashboardFrameById(i,L.id)});D(C,T,{position:"end",semanticExecutionPayload:M}),N(T.id),s.ue.success("Visual saved to dashboard"),a(!1),E(!1)}catch(M){console.error("Failed to save visual to dashboard:",M),s.ue.error(M instanceof Error?M.message:"Failed to prepare semantic metadata for the visual")}}},isLibraryVisual:S,currentVisualName:I,isSaving:F.isPending}}function Y(t={}){const a=o.useEditorStore(A=>A.frame),h=o.useEditorStore(A=>A.editorContext),u=s.useManagementStore(A=>A.selectedVisual),n=o.useDashboardStore(A=>A.selectedFrameId),p=o.useDashboardStore(A=>A.selectedSheetId),d=o.useDashboardStore(A=>A.dashboard),{setIsVisualEditing:c,updateFrame:l}=o.useDashboardActions(),[r,x]=v.useState(!1),[C,i]=v.useState("both"),m=s.useResolveExistingFrameSemanticExecutionPayload(),j=(h==null?void 0:h.type)==="documentSection",b=!!(a!=null&&a.visualId||u!=null&&u.id),D=!!(a!=null&&a.visualId&&n),N=b&&!D,{saveAsDialogOpen:E,setSaveAsDialogOpen:f,handleSaveAs:S,isLibraryVisual:I,currentVisualName:F,isSaving:w}=Q(),{getUpdatedFrame:g}=_.useVisualUtils();if(j)return e.jsxs(e.Fragment,{children:[e.jsx(k.EditorAcceptButton,{className:"rounded-control",variant:"default"}),e.jsx(k.EditorCancelButton,{})]});const y=async()=>{if(!p){s.ue.error("No sheet selected");return}if(r)return;x(!0);const A=g(),L=o.getDynamicFrameSaveIssue(A);if(L){x(!1),s.ue.error(L);return}const T={...A,visualId:void 0},M=s.findDashboardFrameById(d,T.id);try{const O=await m(T,{previousFrame:M});l(p,T,{semanticExecutionPayload:O})}catch(O){console.error("Failed to apply local semantic metadata:",O),x(!1),s.ue.error(O instanceof Error?O.message:"Failed to prepare semantic metadata for this visual");return}setTimeout(()=>{x(!1),s.ue.success("Changes applied. Visual is now local to this dashboard"),c(!1)},300)},P=A=>{i(A),f(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"inline-flex items-center overflow-hidden rounded-control",children:[!b&&e.jsx(k.EditorAcceptButton,{className:"!rounded-none",variant:"default"}),b&&N&&e.jsx(k.VisualSaveButton,{className:"!rounded-none",variant:"default"}),b&&D&&e.jsx(k.VisualSaveAndApplyButton,{className:"!rounded-none"}),e.jsxs(s.DropdownMenu,{modal:!1,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(o.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:w||r,children:e.jsx(o.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:y,disabled:r,children:[e.jsx(o.Check,{className:"h-3.5 w-3.5"}),r?"Applying...":"Apply Locally"]}),e.jsx(s.DropdownMenuSeparator,{})]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>P("local"),disabled:w,children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Add to Dashboard (Local)"]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>P("library"),disabled:w,children:[e.jsx(k.Library,{className:"h-3.5 w-3.5"}),"Save as Library Visual"]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>P("both"),disabled:w,children:[e.jsx(k.Link2,{className:"h-3.5 w-3.5"}),"Save Copy as Linked Visual"]})]})]})]}),e.jsx(k.EditorCancelButton,{}),e.jsx(K,{open:E,onOpenChange:A=>{w||f(A)},isLibraryVisual:I,currentVisualName:F,isSaving:w,destinationMode:C,onConfirm:S})]})}function Z({className:t}){const a=o.useEditorStore(r=>r.isDevMode),h=o.useDashboardStore(r=>r.isVisualEditing),{setIsDevMode:u}=o.useEditorActions(),{config:n}=v.useContext(s.SemaphorContext).tokenProps,p=(n==null?void 0:n.showAdvancedMode)!==!1;if(!h||!p)return null;const d=a?o.SlidersHorizontal:s.CodeXml,c=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:()=>u(!a),className:o.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(d,{className:"h-3 w-3 text-muted-foreground"}),c]})}function J({open:t,onOpenChange:a,onSave:h,onDiscard:u,isSaving:n,title:p="Unsaved changes",description:d="You have unsaved changes to this dashboard. What would you like to do?",cancelLabel:c="Cancel",discardLabel:l="Discard",saveLabel:r="Save"}){const x=C=>{!C&&n||a(C)};return e.jsx(s.AlertDialog,{open:t,onOpenChange:x,children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:p}),e.jsx(s.AlertDialogDescription,{children:d})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(o.Button,{type:"button",size:"xs",onClick:u,disabled:n,variant:"ghost",className:"mr-auto text-muted-foreground hover:bg-destructive/10 hover:text-destructive focus-visible:bg-destructive/10 focus-visible:text-destructive",children:l}),e.jsx(s.AlertDialogCancel,{disabled:n,children:c}),e.jsx(o.Button,{type:"button",size:"xs",onClick:h,disabled:n,children:n?e.jsxs(e.Fragment,{children:[e.jsx(o.LoaderCircle,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),"Saving..."]}):r})]})]})})}const ee=1e4,te=15e3,se=3e4,oe=3e4,ae=12e4,R=2*60*60*1e3;function re(t){const a=Date.now()-t.getTime();return a<oe?ee:a<ae?te:se}function ne(){const{authToken:t,tokenProps:a}=s.useSemaphorContext(),h=s.useExportStore(i=>i.activeExports),[u,n]=v.useState(typeof document<"u"?!document.hidden:!0),p=v.useRef(null),d=v.useRef(!1),c=v.useRef(void 0),l=a==null?void 0:a.apiServiceUrl,r=t==null?void 0:t.accessToken,x=v.useCallback(()=>{const i=s.useExportStore.getState().activeExports;return Array.from(i.values()).filter(m=>s.isExportInProgress(m.status))},[]);v.useEffect(()=>{if(typeof document>"u")return;const i=()=>{n(!document.hidden)};return document.addEventListener("visibilitychange",i),()=>{document.removeEventListener("visibilitychange",i)}},[]);const C=v.useCallback(async()=>{if(!l||!r){d.current=!1;return}const i=x();if(i.length===0){d.current=!1;return}const m=Date.now(),j=i.filter(f=>m-f.startedAt.getTime()>R);if(j.length>0){const{updateExport:f}=s.useExportStore.getState().actions;for(const S of j)f(S.id,{status:"failed",error:"Export timed out. Please try again or contact support.",lastUpdatedAt:new Date})}const b=i.filter(f=>m-f.startedAt.getTime()<=R);if(b.length===0){d.current=!1;return}const D=await Promise.allSettled(b.map(async f=>{try{const S=await s.getExportStatus(l,r,f.id);let I;if(S.status==="completed")try{I=await s.getDownloadUrl(l,r,f.id)}catch(F){console.error(`[useExportPolling] Failed to get download URL for ${f.id}:`,F)}return{id:f.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:I}}catch(S){return console.error(`[useExportPolling] Failed to poll export ${f.id}:`,S),null}})),{updateExport:N}=s.useExportStore.getState().actions;for(const f of D)f.status==="fulfilled"&&f.value&&N(f.value.id,f.value);const E=x();if(E.length>0&&!document.hidden){const f=E.reduce((I,F)=>F.startedAt<I?F.startedAt:I,E[0].startedAt),S=re(f);p.current&&clearTimeout(p.current),p.current=setTimeout(()=>{var I;(I=c.current)==null||I.call(c)},S)}else d.current=!1},[l,r,x]);return v.useEffect(()=>{c.current=C},[C]),v.useEffect(()=>{var m;x().length>0&&u&&!d.current&&(d.current=!0,(m=c.current)==null||m.call(c))},[h,u,x]),v.useEffect(()=>{var m;const i=x();u&&i.length>0&&!d.current&&(d.current=!0,(m=c.current)==null||m.call(c))},[u,x]),v.useEffect(()=>{!u&&p.current&&(clearTimeout(p.current),p.current=null,d.current=!1)},[u]),v.useEffect(()=>()=>{p.current&&(clearTimeout(p.current),p.current=null)},[]),{isPolling:d.current,isTabVisible:u,inProgressCount:x().length}}function ie(){const{authToken:t,tokenProps:a}=s.useSemaphorContext(),h=s.useExportStore(c=>c.activeExports),{addExport:u}=s.useExportActions(),n=v.useRef(!1),p=a==null?void 0:a.apiServiceUrl,d=t==null?void 0:t.accessToken;v.useEffect(()=>{if(n.current||!p||!d)return;(async()=>{try{const{exports:l}=await s.getExports(p,d,{status:["pending","processing","chunking","compacting","completed","failed"],limit:20});for(const r of l){if(h.has(r.id))continue;const x=r.totalChunks?Math.round(r.completedChunks/r.totalChunks*100):0;let C;if(r.status==="completed")try{C=await s.getDownloadUrl(p,d,r.id)}catch(m){console.error(`[useExportRecovery] Failed to get download URL for ${r.id}:`,m)}const i={id:r.id,status:r.status,progress:x,title:le(r),totalRows:r.totalRows,totalChunks:r.totalChunks,completedChunks:r.completedChunks,startedAt:new Date(r.createdAt),lastUpdatedAt:new Date,completedAt:r.completedAt?new Date(r.completedAt):void 0,fileSize:r.fileSize,error:r.error,expiresAt:new Date(r.expiresAt),downloadUrl:C};u(i)}n.current=!0}catch(l){console.error("[useExportRecovery] Failed to recover exports:",l),n.current=!0}})()},[p,d,u,h])}function le(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 q({export:t,onRemove:a}){const h=()=>{t.downloadUrl&&window.open(t.downloadUrl,"_blank")},u=c=>{c.stopPropagation(),a==null||a(t.id)},n=()=>{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(k.CircleX,{className:"mt-0.5 h-5 w-5 shrink-0 text-destructive"});default:return e.jsx(o.LoaderCircle,{className:"text-foreground-muted mt-0.5 h-5 w-5 shrink-0 animate-spin"})}},p=s.isExportInProgress(t.status),d=(()=>{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:[n(),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)})]})]}),p&&e.jsx("div",{className:"text-xs text-muted-foreground",children:d}),t.status==="failed"&&e.jsx("div",{className:"line-clamp-2 text-xs text-destructive",children:t.error||"Export failed"})]})]}),e.jsx(o.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0 opacity-0 transition-opacity group-hover:opacity-100",onClick:u,"aria-label":"Remove notification",children:e.jsx(o.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:V.formatDistanceToNow(t.startedAt,{addSuffix:!0})}),t.downloadUrl&&e.jsxs(o.Button,{size:"sm",variant:"outline",className:"h-8 bg-transparent",onClick:h,children:[e.jsx(s.Download,{className:"mr-1.5 h-3.5 w-3.5"}),"Download"]})]}),p&&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:V.formatDistanceToNow(t.startedAt,{addSuffix:!0})})]})]})}function H(){const{authToken:t,tokenProps:a}=s.useSemaphorContext(),h=s.useExportStore(b=>b.activeExports),{clearCompleted:u,removeExport:n,updateExport:p}=s.useExportActions(),[d,c]=v.useState(!1),[l,r]=v.useState(!1),x=Array.from(h.values()).sort((b,D)=>D.startedAt.getTime()-b.startedAt.getTime()),C=x.some(b=>b.status==="completed"||b.status==="failed"),i=v.useCallback(async()=>{const b=a==null?void 0:a.apiServiceUrl,D=t==null?void 0:t.accessToken;if(!(!b||!D)){c(!0);try{const N=Array.from(h.values());await Promise.all(N.map(async E=>{try{const f=await s.getExportStatus(b,D,E.id);let S;if(f.status==="completed")try{S=await s.getDownloadUrl(b,D,E.id)}catch(I){console.error(`Failed to get download URL for ${E.id}:`,I)}p(E.id,{status:f.status,progress:f.progress,completedChunks:f.completedChunks,completedAt:f.completedAt?new Date(f.completedAt):void 0,lastUpdatedAt:new Date,fileSize:f.fileSize,error:f.error,downloadUrl:S})}catch(f){console.error(`Failed to refresh export ${E.id}:`,f)}}))}finally{c(!1)}}},[h,t==null?void 0:t.accessToken,a==null?void 0:a.apiServiceUrl,p]),m=v.useCallback(async()=>{const b=a==null?void 0:a.apiServiceUrl,D=t==null?void 0:t.accessToken;if(!b||!D){u();return}r(!0);try{const N=x.filter(f=>f.status==="completed"||f.status==="failed"),E=await Promise.allSettled(N.map(async f=>(await s.cancelExport(b,D,f.id),f.id)));for(const f of E)f.status==="fulfilled"?n(f.value):console.error("Failed to delete export:",f.reason)}finally{r(!1)}},[x,a==null?void 0:a.apiServiceUrl,t==null?void 0:t.accessToken,u,n]),j=v.useCallback(async b=>{const D=a==null?void 0:a.apiServiceUrl,N=t==null?void 0:t.accessToken;if(D&&N)try{await s.cancelExport(D,N,b),n(b);return}catch(E){console.error(`Failed to cancel export ${b}:`,E)}n(b)},[a==null?void 0:a.apiServiceUrl,t==null?void 0:t.accessToken,n]);return x.length===0?e.jsxs("div",{className:"p-6 text-center",children:[e.jsx(U,{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(U,{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(o.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:i,disabled:d,title:"Refresh status",children:e.jsx(s.RefreshCw,{className:`h-4 w-4 ${d?"animate-spin":""}`})}),C&&e.jsx(o.Button,{variant:"ghost",size:"sm",className:"h-7 px-2 text-sm",onClick:m,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:x.map(b=>e.jsx(q,{export:b,onRemove:j},b.id))})})]})}function de({variant:t}){const a=s.useExportStore(l=>l.activeExports),h=s.useInProgressExportsCount(),u=a.size>0,n=Array.from(a.values()).some(l=>l.status==="completed"||l.status==="failed"),d=h>0?h>9?"9+":String(h):null,c=u;return e.jsxs(o.Popover,{children:[e.jsx(o.PopoverTrigger,{asChild:!0,children:e.jsxs(o.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"}),c&&e.jsx("span",{className:`absolute flex items-center justify-center rounded-full bg-primary text-primary-foreground ${d?"-right-0.5 -top-0.5 h-3.5 min-w-3.5 px-0.5 text-[9px] font-semibold":"right-1 top-1 h-1.5 w-1.5"}`,children:d})]})}),e.jsx(o.PopoverContent,{className:"w-80 p-0",align:"end",sideOffset:8,children:e.jsx(H,{})})]})}function ce(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 $({open:t,onOpenChange:a,trigger:h,showTrigger:u=!0,initialMode:n="manage"}){const p=n==="create",{forceClose:d,handleOpenChange:c,isCreateFlowActive:l,preventPassiveDismissDuringCreate:r,resolvedOpen:x,setIsCreateFlowActive:C}=k.useCreateFlowOverlayState({open:t,onOpenChange:a,initialCreateFlowActive:n==="create",dismissMode:u?"passive":"explicit-only"}),i=o.useDashboardStore(g=>g.dashboard),{setDashboardControlsModel:m}=o.useDashboardActions(),{participants:j}=s.useDashboardStructuralParticipants(o.getDashboardCards(i)),b=Array.from(new Map(j.flatMap(g=>g.fieldChoices.map(y=>{var P;return[y.value,{option:y,target:(P=g.fieldTargetMap)==null?void 0:P[y.value]}]}))).values()),D=Array.from(new Map(j.flatMap(g=>g.metricChoices.map(y=>{var P;return[y.value,{option:y,target:(P=g.metricTargetMap)==null?void 0:P[y.value]}]}))).values()),N=o.collectDashboardControlIds({...i||{},controls:[]}),E=s.buildDashboardStructuralParticipantIdsByControlId(i),f=(g,y,P)=>{m(g,y,ce(P))},S=v.useCallback(()=>{if(p){d();return}C(!1)},[p,d,C]),I=e.jsx(k.ControlDefinitionListEditor,{scope:"dashboard",controls:i.controls||[],reservedControlIds:N,defaultValues:i.defaultControlValues||{},usageByControlId:s.buildDashboardControlUsageById(i),availableFieldChoices:b,availableMetricChoices:D,structuralParticipants:j,structuralParticipantIdsByControlId:E,initialCreateFlow:n==="create",onCreateFlowActiveChange:C,onCreateFlowComplete:S,onChange:f,emptyMessage:"No dashboard controls yet."}),F=l?"Add dashboard control":"Dashboard Controls",w=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."})]}),I]});return u?e.jsxs(o.Popover,{open:x,onOpenChange:c,children:[e.jsx(o.PopoverTrigger,{asChild:!0,children:h||e.jsxs(o.Button,{variant:"outline",className:"h-7 px-2",size:"sm",children:[e.jsx(o.SlidersHorizontal,{className:"mr-2 h-4 w-4"}),"Controls"]})}),e.jsx(o.PopoverContent,{className:"w-[620px] max-w-[95vw] space-y-4",align:"end",onEscapeKeyDown:r,onPointerDownOutside:r,children:w})]}):e.jsx(s.Dialog,{open:x,onOpenChange:c,children:e.jsxs(s.DialogContent,{className:"flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",onEscapeKeyDown:r,onPointerDownOutside:r,children:[e.jsxs(s.DialogHeader,{className:l?"space-y-0":void 0,children:[e.jsx(s.DialogTitle,{className:"text-[15px]",children:F}),e.jsx(s.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:I})]})})}const ue=["enum","multi_enum","text","number","boolean","date"];function G({open:t,onOpenChange:a,initialMode:h="manage"}){var w;const u=h==="create",{forceClose:n,handleOpenChange:p,isCreateFlowActive:d,preventPassiveDismissDuringCreate:c,resolvedOpen:l,setIsCreateFlowActive:r}=k.useCreateFlowOverlayState({open:t,onOpenChange:a,initialCreateFlowActive:h==="create",dismissMode:"explicit-only"}),x=o.useDashboardStore(g=>g.dashboard),C=o.useDashboardStore(g=>g.selectedSheetId),{setDashboardInputs:i}=o.useDashboardActions(),m=(w=x.sheets)==null?void 0:w.find(g=>g.id===C),j=(m==null?void 0:m.kind)==="document"&&!!m.document,b=v.useMemo(()=>j&&(m!=null&&m.document)?s.getDocumentSheetDashboardInputs(x,m.id):[],[x,j,m==null?void 0:m.document,m==null?void 0:m.id]),D=v.useMemo(()=>b.filter(g=>g.kind==="control"),[b]),N=v.useMemo(()=>D.map(g=>g.control),[D]),E=v.useMemo(()=>he(N),[N]),f=v.useMemo(()=>me(x),[x]),S=v.useCallback(()=>{if(u){n();return}r(!1)},[u,n,r]),I=v.useCallback((g,y,P)=>{!j||!(m!=null&&m.document)||i(xe({allInputs:x.inputs||[],documentSheetId:m.id,currentDocumentInputs:b,nextControls:g,nextDefaultValues:y,change:P}))},[x.inputs,b,j,m,i]);if(!j||!(m!=null&&m.document))return null;const F=d?"Add document control":"Document Controls";return e.jsx(s.Dialog,{open:l,onOpenChange:p,children:e.jsxs(s.DialogContent,{className:"flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",onEscapeKeyDown:c,onPointerDownOutside:c,children:[e.jsxs(s.DialogHeader,{className:d?"space-y-0":void 0,children:[e.jsx(s.DialogTitle,{className:"text-[15px]",children:F}),e.jsx(s.DialogDescription,{className:d?"sr-only":"text-[13px]",children:d?"Configure and add a document-local control input.":"Add document-local control inputs. They are stored on this document sheet and are not dashboard controls."})]}),e.jsx("div",{className:"min-h-0 overflow-y-auto pr-1",children:e.jsx(k.ControlDefinitionListEditor,{scope:"dashboard",controls:N,reservedControlIds:f,defaultValues:E,usageByControlId:{},availableFieldChoices:[],availableMetricChoices:[],structuralParticipants:[],structuralParticipantIdsByControlId:{},allowedControlTypes:ue,initialCreateFlow:h==="create",onCreateFlowActiveChange:r,onCreateFlowComplete:S,onChange:I,emptyMessage:"No document controls yet."})})]})})}function me(t){return(t.controls||[]).map(a=>a.id)}function he(t){const a={};for(const h of t)h.defaultValue!==void 0&&(a[h.id]=h.defaultValue);return a}function pe(t,a){return a?Object.prototype.hasOwnProperty.call(a,t.id)?{...t,defaultValue:a[t.id]}:t.defaultValue===void 0?t:{...t,defaultValue:void 0}:t.defaultValue===void 0?t:{...t,defaultValue:void 0}}function xe({allInputs:t,documentSheetId:a,currentDocumentInputs:h,nextControls:u,nextDefaultValues:n,change:p}){const d=new Map(u.map(i=>[i.id,pe(i,n)])),c=(p==null?void 0:p.type)==="rename"?{oldId:p.oldId,newId:p.newId}:null,l=new Set,r=[];for(const i of h){if(i.kind!=="control"){r.push(i);continue}const m=d.get(i.control.id)||((c==null?void 0:c.oldId)===i.control.id?d.get(c.newId):void 0);if(!m)continue;l.add(m.id);const j=s.createUniqueDashboardInputVariableNameFromName(m.id,[...t,...r].filter(D=>D.id!==i.id)),b=m.id===j?m:{...m,id:j};r.push({...i,label:b.label,variableName:j,requiredAtExecution:b.requiredAtExecution,control:b})}for(const i of d.values())l.has(i.id)||r.push(s.createDashboardControlInputFromControl({control:i,existingInputs:[...t,...r],sheetId:a}));const x=new Set(h.map(i=>i.id));return[...t.filter(i=>!x.has(i.id)),...r]}function W({showFilters:t,onShowFiltersChange:a,pickerContent:h,settingsContent:u,size:n="default",className:p,primaryButtonClassName:d,secondaryButtonClassName:c,pickerContentClassName:l,settingsContentClassName:r}){const x=n==="toolbar",[C,i]=v.useState(!1),m=s.useSurfaceAppearance("interactive");return e.jsxs("div",{className:o.cn("relative inline-flex items-stretch overflow-hidden rounded-control border border-input bg-background",x?"h-8":"h-7",p),children:[e.jsxs(o.Popover,{open:t,onOpenChange:a,children:[e.jsx(o.PopoverTrigger,{asChild:!0,children:e.jsxs(o.Button,{variant:"ghost",size:"xs",className:o.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",d),children:[t?e.jsx(X,{className:"h-3.5 w-3.5"}):e.jsx(s.Filter,{className:"h-3.5 w-3.5"}),"Filter"]})}),e.jsx(o.PopoverContent,{align:"end",sideOffset:6,className:o.cn("w-auto rounded-card border border-border/60 p-0 shadow-sm",l),style:m.contentStyle,children:h})]}),e.jsxs(o.Popover,{open:C,onOpenChange:i,children:[e.jsx(o.PopoverTrigger,{asChild:!0,children:e.jsx(o.Button,{variant:"ghost",size:"xs",className:o.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",c),"aria-label":"Filter and control actions",children:e.jsx(o.ChevronDown,{className:"h-3.5 w-3.5"})})}),e.jsx(o.PopoverContent,{align:"end",sideOffset:6,className:o.cn("w-auto rounded-card border border-border/60 p-0 shadow-sm",r),style:m.contentStyle,children:u(()=>i(!1))})]})]})}function fe(){k.useSyncLegacyEditorState();const t=o.useDashboardStore(l=>l.selectedSheetId),a=o.useDashboardStore(l=>l.selectedFrameId),h=o.useDashboardStore(l=>l.dashboard),u=o.useDashboardStore(l=>l.actions.getSelectedFrame),{setSelectedFrameId:n}=o.useDashboardActions(),{setCard:p}=o.useEditorActions(),d=o.useEditorStore(l=>l.card.dataSource);return v.useEffect(()=>{var r,x;let l=u();if(!l){const C=(r=h==null?void 0:h.sheets)==null?void 0:r.find(m=>m.id===t),i=(x=C==null?void 0:C.frames)==null?void 0:x[0];i&&(n(i.id),l=i)}if(l){const C=l.cards.find(i=>i.id===l.activeCardId);C&&p(C)}},[u,t,a,h,n,p]),{hasEntities:!!(d!=null&&d.selectedEntities&&d.selectedEntities.length>0)}}function ge(){const t=o.useDashboardStore(c=>c.dashboard),a=o.useDashboardStore(c=>c.semanticExecutionPayload),h=o.useDashboardStore(c=>c.actions.addFilter),{hasEntities:u}=fe(),n=v.useMemo(()=>s.getGlobalDateFilterCoverage(t,a),[t,a]),d=!s.getGlobalDateFilter(t.filters)&&n.hasEligibleCards;return e.jsxs("div",{className:"flex h-[520px] w-[400px] flex-col",children:[d&&e.jsxs("div",{className:"border-b border-border/60 p-2",children:[e.jsxs("p",{className:"mb-1 flex items-center gap-1 px-1 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:[e.jsx(s.Sparkles,{className:"h-2.5 w-2.5"}),"Suggested"]}),e.jsxs("button",{type:"button",onClick:()=>h(s.createDefaultGlobalDateFilter()),title:`Eligible: ${n.eligibleCardCount} of ${n.totalCardCount} 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(s.CalendarRange,{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:"Global date filter"}),e.jsx("span",{className:"text-[11px] leading-[1.4] text-muted-foreground",children:"One date range, applied across every date-aware card on the dashboard."})]})]})]}),!u&&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."})]}),u&&e.jsx("div",{className:"flex flex-1 overflow-hidden",children:e.jsx(s.FilterableFieldsPanel,{context:"filter"})})]})}const z=!1;function ve({onAddFilter:t,onAddControl:a,onManageControls:h,onDismiss:u}){const n=o.useDashboardStore(c=>c.dashboard.filterLayout),{setFilterLayout:p}=o.useDashboardActions();n!=null&&n.displayMode;const d=(n==null?void 0:n.toolbarWrap)??!1;return n==null||n.showDownloadButton,e.jsxs("div",{className:"w-[300px]",children:[e.jsxs("div",{className:"p-1",children:[e.jsx(B,{icon:s.Filter,label:"Add filter",onClick:()=>{t(),u()}}),e.jsx(B,{icon:o.SlidersHorizontal,label:"Add control",onClick:()=>{a(),u()}}),e.jsx(B,{icon:s.Pencil,label:"Manage controls",onClick:()=>{h(),u()}})]}),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"}),z,e.jsx(be,{id:"filter-display-wrap",label:"Wrap to multiple lines",checked:d,onCheckedChange:c=>p({toolbarWrap:c===!0})}),z]})]})}function B({icon:t,label:a,onClick:h}){return e.jsxs("button",{type:"button",onClick:h,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"}),a]})}function be({id:t,label:a,checked:h,onCheckedChange:u}){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:h,onCheckedChange:u}),e.jsx(o.Label,{htmlFor:t,className:"cursor-pointer text-[12px] font-normal leading-[1.3]",children:a})]})}function Ce({size:t,className:a,primaryButtonClassName:h,secondaryButtonClassName:u,pickerContentClassName:n,settingsContentClassName:p}){var F;const[d,c]=v.useState(null),l=o.useDashboardStore(w=>w.dashboard),r=o.useDashboardStore(w=>w.selectedSheetId),x=o.useDashboardStore(w=>w.showFilters),C=s.useAssistantLayoutStore(w=>w.setPanelOpen),i=o.useDashboardStore(w=>w.actions),{setDocumentInspectorTab:m,setShowFilters:j}=i,b=(F=l.sheets)==null?void 0:F.find(w=>w.id===r),D=o.isDocumentSheet(b),N=v.useCallback(w=>{window.setTimeout(()=>{c(w)},0)},[]),E=v.useCallback(w=>{if(D&&r){w&&m(r,"inputs");return}w&&C("dashboard",!1),j(w)},[D,r,m,C,j]),f=v.useCallback(()=>{E(!0)},[E]),S=v.useCallback(()=>{N("create")},[N]),I=v.useCallback(()=>{N("manage")},[N]);return e.jsxs(e.Fragment,{children:[e.jsx(W,{showFilters:D?!1:x,onShowFiltersChange:E,pickerContent:e.jsx(ge,{}),settingsContent:w=>e.jsx(ve,{onAddFilter:f,onAddControl:S,onManageControls:I,onDismiss:w}),size:t,className:a,primaryButtonClassName:h,secondaryButtonClassName:u,pickerContentClassName:n,settingsContentClassName:p}),d?D?e.jsx(G,{open:!0,onOpenChange:w=>{w||c(null)},initialMode:d}):e.jsx($,{open:!0,onOpenChange:w=>{w||c(null)},showTrigger:!1,initialMode:d}):null]})}exports.AdvancedModeToggle=Z;exports.DashboardControlsSettings=$;exports.DashboardFilterControlsButton=W;exports.DashboardFilterControlsLauncher=Ce;exports.DocumentControlsSettings=G;exports.ExportNotificationItem=q;exports.ExportNotificationList=H;exports.NotificationBell=de;exports.UnsavedChangesAlert=J;exports.VisualEditingControls=Y;exports.useExportPolling=ne;exports.useExportRecovery=ie;
@@ -1,7 +1,7 @@
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-Dhoqe3OE.js";
4
- import "./index-9v7DehZd.js";
3
+ import { u as o, a as N, B as p, X as D, C as J } from "./switch-DEPWsRhf.js";
4
+ import "./index-D7e2Eyp_.js";
5
5
  import "./index-CJdxSyQq.js";
6
6
  import "react-dom";
7
7
  function C() {
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),o=require("react"),s=require("./switch-otrSiyjH.js");require("./index-CGCrm-dj.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
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),o=require("react"),s=require("./switch-DPaKnsb8.js");require("./index-DjZqoaV5.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,8 +1,8 @@
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 V, l as G, m as ge, n as re, o as I } from "./index-9v7DehZd.js";
4
- import { a as C, L as P, P as xe, b as Se, B as A, d as ye, e as X, f as Ne, S as we, g as Ce, h as ke, i as Te, j as Ie, k as Z, I as Pe } from "./switch-Dhoqe3OE.js";
5
- import { C as Ae } from "./chevrons-up-down-DJhB8JNW.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 V, l as G, m as ge, n as re, o as I } from "./index-D7e2Eyp_.js";
4
+ import { a as C, L as P, P as xe, b as Se, B as A, d as ye, e as X, f as Ne, S as we, g as Ce, h as ke, i as Te, j as Ie, k as Z, I as Pe } from "./switch-DEPWsRhf.js";
5
+ import { C as Ae } from "./chevrons-up-down-BYzO4q5w.js";
6
6
  function ze(r = {}) {
7
7
  var T, L, D, M;
8
8
  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-CGCrm-dj.js"),s=require("./switch-otrSiyjH.js"),q=require("./chevrons-up-down-3vBEM7eI.js");function X(n={}){var k,P,A,D;const{authToken:c,tokenProps:t}=a.useSemaphorContext(),v=n.enabled??!0,u=(c==null?void 0:c.accessToken)??null,f=(t==null?void 0:t.apiServiceUrl)??null,[N,j]=o.useState(!1),[S,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:((D=(A=t==null?void 0:t.params)==null?void 0:A.calendarContext)==null?void 0:D.weekStart)??null},g=o.useCallback(async()=>{if(!(!v||!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,v]);o.useEffect(()=>{v&&g()},[v,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:S,isClearing:h,error:y,updatePreferences:I,clearPreferences:C,refetch:g}}const z=[{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 Z(){try{const n=Intl;if(n.supportedValuesOf)return n.supportedValuesOf("timeZone")}catch{}return z.map(n=>n.value)}function J(n){switch(n){case"tenant":return"tenant";case"organization":return"organization";case"system":return"system";default:return"default"}}function _(n){const c=z.find(t=>t.value===n);return c?c.label:n}function K(n){const c=$.find(t=>t.value===n);return c?c.label:String(n)}function Y({open:n,onOpenChange:c}){var M,U,F;const{preferences:t,isLoading:v,isSaving:u,isClearing:f,updatePreferences:N,clearPreferences:j}=X({enabled:n}),S=t.tz||((M=t.inherited)==null?void 0:M.tz)||Intl.DateTimeFormat().resolvedOptions().timeZone,b=t.weekStart??((U=t.inherited)==null?void 0:U.weekStart)??1,[h,l]=o.useState(!t.userHasPrefs),[y,d]=o.useState(!1),[p,w]=o.useState(S),[T,g]=o.useState(b),[I,C]=o.useState(!1),k=o.useMemo(()=>Z(),[]),P=o.useMemo(()=>k.filter(r=>!z.some(V=>V.value===r)),[k]),A=o.useMemo(()=>_(p),[p]),D=t.inherited?_(t.inherited.tz):"UTC",m=t.inherited?K(t.inherited.weekStart):"Monday",i=J((F=t.inherited)==null?void 0:F.source);o.useEffect(()=>{if(!n){d(!1);return}y||(t.userHasPrefs!==void 0&&l(!t.userHasPrefs),w(S),g(b))},[n,y,t.userHasPrefs,S,b]);const x=async()=>{if(v){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||v;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:[D,", 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(q.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:z.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 E=6,O=1,R=20,H="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function Q(n){return Number.isNaN(n)?E:Math.min(R,Math.max(O,n))}function ee({open:n,onOpenChange:c,dashboard:t,onApply:v,disabled:u=!1}){const[f,N]=o.useState(!1),[j,S]=o.useState("top"),[b,h]=o.useState(String(E)),l=t.summary;o.useEffect(()=>{n&&(N((l==null?void 0:l.enabled)===!0),S((l==null?void 0:l.position)==="bottom"?"bottom":"top"),h(String((l==null?void 0:l.maxItems)??E)))},[n,l==null?void 0:l.enabled,l==null?void 0:l.position,l==null?void 0:l.maxItems]);const y=o.useMemo(()=>Q(Number.parseInt(b||`${E}`,10)),[b]),d=()=>{v({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=>S(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=Y;exports.DashboardSummarySettingsDialog=ee;
1
+ "use strict";const e=require("react/jsx-runtime"),o=require("react"),a=require("./index-DjZqoaV5.js"),s=require("./switch-DPaKnsb8.js"),q=require("./chevrons-up-down-DiWloubI.js");function X(n={}){var k,P,A,D;const{authToken:c,tokenProps:t}=a.useSemaphorContext(),v=n.enabled??!0,u=(c==null?void 0:c.accessToken)??null,f=(t==null?void 0:t.apiServiceUrl)??null,[N,j]=o.useState(!1),[S,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:((D=(A=t==null?void 0:t.params)==null?void 0:A.calendarContext)==null?void 0:D.weekStart)??null},g=o.useCallback(async()=>{if(!(!v||!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,v]);o.useEffect(()=>{v&&g()},[v,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:S,isClearing:h,error:y,updatePreferences:I,clearPreferences:C,refetch:g}}const z=[{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 Z(){try{const n=Intl;if(n.supportedValuesOf)return n.supportedValuesOf("timeZone")}catch{}return z.map(n=>n.value)}function J(n){switch(n){case"tenant":return"tenant";case"organization":return"organization";case"system":return"system";default:return"default"}}function _(n){const c=z.find(t=>t.value===n);return c?c.label:n}function K(n){const c=$.find(t=>t.value===n);return c?c.label:String(n)}function Y({open:n,onOpenChange:c}){var M,U,F;const{preferences:t,isLoading:v,isSaving:u,isClearing:f,updatePreferences:N,clearPreferences:j}=X({enabled:n}),S=t.tz||((M=t.inherited)==null?void 0:M.tz)||Intl.DateTimeFormat().resolvedOptions().timeZone,b=t.weekStart??((U=t.inherited)==null?void 0:U.weekStart)??1,[h,l]=o.useState(!t.userHasPrefs),[y,d]=o.useState(!1),[p,w]=o.useState(S),[T,g]=o.useState(b),[I,C]=o.useState(!1),k=o.useMemo(()=>Z(),[]),P=o.useMemo(()=>k.filter(r=>!z.some(V=>V.value===r)),[k]),A=o.useMemo(()=>_(p),[p]),D=t.inherited?_(t.inherited.tz):"UTC",m=t.inherited?K(t.inherited.weekStart):"Monday",i=J((F=t.inherited)==null?void 0:F.source);o.useEffect(()=>{if(!n){d(!1);return}y||(t.userHasPrefs!==void 0&&l(!t.userHasPrefs),w(S),g(b))},[n,y,t.userHasPrefs,S,b]);const x=async()=>{if(v){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||v;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:[D,", 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(q.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:z.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 E=6,O=1,R=20,H="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function Q(n){return Number.isNaN(n)?E:Math.min(R,Math.max(O,n))}function ee({open:n,onOpenChange:c,dashboard:t,onApply:v,disabled:u=!1}){const[f,N]=o.useState(!1),[j,S]=o.useState("top"),[b,h]=o.useState(String(E)),l=t.summary;o.useEffect(()=>{n&&(N((l==null?void 0:l.enabled)===!0),S((l==null?void 0:l.position)==="bottom"?"bottom":"top"),h(String((l==null?void 0:l.maxItems)??E)))},[n,l==null?void 0:l.enabled,l==null?void 0:l.position,l==null?void 0:l.maxItems]);const y=o.useMemo(()=>Q(Number.parseInt(b||`${E}`,10)),[b]),d=()=>{v({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=>S(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=Y;exports.DashboardSummarySettingsDialog=ee;