react-semaphor 0.1.179 → 0.1.180

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 (30) hide show
  1. package/dist/chunks/{dashboard-controls-CeT5saB7.js → dashboard-controls-Baw7eUyM.js} +3 -3
  2. package/dist/chunks/{dashboard-controls-O2Vl2SaH.js → dashboard-controls-CS3pAVZi.js} +339 -337
  3. package/dist/chunks/{dashboard-json--jGkpREU.js → dashboard-json-ClalWYi4.js} +1 -1
  4. package/dist/chunks/{dashboard-json-d1qZ8OYo.js → dashboard-json-Cz4bNnCC.js} +1 -1
  5. package/dist/chunks/{edit-dashboard-visual-ViDNkE8Q.js → edit-dashboard-visual-BMElXt-n.js} +30 -35
  6. package/dist/chunks/{edit-dashboard-visual-BsP87bZV.js → edit-dashboard-visual-DFJ5FJ7y.js} +11 -22
  7. package/dist/chunks/editor-action-buttons-DVWnnC_r.js +11 -0
  8. package/dist/chunks/{editor-action-buttons-F4_UU-Mk.js → editor-action-buttons-MtNYw1Bb.js} +57 -45
  9. package/dist/chunks/{index-v6ayK5K2.js → index-CAeKp6K8.js} +22589 -22037
  10. package/dist/chunks/{index-CFWw2cJ5.js → index-CfPKTeUk.js} +232 -227
  11. package/dist/chunks/notification-bell-2dZI5OV0.js +21 -0
  12. package/dist/chunks/notification-bell-YZ8VqdwA.js +870 -0
  13. package/dist/chunks/{resource-management-panel-Cn1aOr6L.js → resource-management-panel-Buhi-kvP.js} +1 -1
  14. package/dist/chunks/{resource-management-panel-CApVr9Vd.js → resource-management-panel-pxL28GXq.js} +133 -133
  15. package/dist/chunks/{use-role-aware-display-preferences-C-N0-Iik.js → use-role-aware-display-preferences-B_i2f9tn.js} +1 -1
  16. package/dist/chunks/{use-role-aware-display-preferences-Bxp6i8c7.js → use-role-aware-display-preferences-JljRcjrP.js} +1 -1
  17. package/dist/chunks/{use-visual-utils-D9lMGeVv.js → use-visual-utils-D3HjbsKO.js} +38 -38
  18. package/dist/chunks/{use-visual-utils-D19qzwzI.js → use-visual-utils-DPEHcmFT.js} +1 -1
  19. package/dist/dashboard/index.cjs +1 -1
  20. package/dist/dashboard/index.js +1 -1
  21. package/dist/index.cjs +1 -6
  22. package/dist/index.js +133 -126
  23. package/dist/style.css +1 -1
  24. package/dist/surfboard/index.cjs +1 -1
  25. package/dist/surfboard/index.js +1 -1
  26. package/dist/types/main.d.ts +262 -0
  27. package/package.json +1 -1
  28. package/dist/chunks/editor-action-buttons-DseT424l.js +0 -6
  29. package/dist/chunks/schedule-dashboard-B4KUKLfW.js +0 -416
  30. package/dist/chunks/schedule-dashboard-vvFw8B1E.js +0 -6
@@ -0,0 +1,21 @@
1
+ "use strict";const f=require("react"),t=require("./index-CfPKTeUk.js"),e=require("react/jsx-runtime"),N=require("./editor-action-buttons-DVWnnC_r.js"),T=require("./use-visual-utils-DPEHcmFT.js"),I=require("./index-8Crk3ROJ.js");/**
2
+ * @license lucide-react v0.453.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const P=t.createLucideIcon("CircleCheck",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);/**
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 V=t.createLucideIcon("CirclePlus",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M8 12h8",key:"1wcyev"}],["path",{d:"M12 8v8",key:"napkw2"}]]);/**
12
+ * @license lucide-react v0.453.0 - ISC
13
+ *
14
+ * This source code is licensed under the ISC license.
15
+ * See the LICENSE file in the root directory of this source tree.
16
+ */const k=t.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"}]]);/**
17
+ * @license lucide-react v0.453.0 - ISC
18
+ *
19
+ * This source code is licensed under the ISC license.
20
+ * See the LICENSE file in the root directory of this source tree.
21
+ */const M=t.createLucideIcon("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]),R=1e4,B=15e3,z=3e4,O=3e4,$=12e4,U=2*60*60*1e3;function q(s){const r=Date.now()-s.getTime();return r<O?R:r<$?B:z}function H(){const{authToken:s,tokenProps:r}=t.useSemaphorContext(),c=t.useExportStore(v=>v.activeExports),[o,h]=f.useState(typeof document<"u"?!document.hidden:!0),i=f.useRef(null),n=f.useRef(!1),a=f.useRef(void 0),m=r==null?void 0:r.apiServiceUrl,d=s==null?void 0:s.accessToken,g=f.useCallback(()=>{const v=t.useExportStore.getState().activeExports;return Array.from(v.values()).filter(b=>t.isExportInProgress(b.status))},[]);f.useEffect(()=>{if(typeof document>"u")return;const v=()=>{h(!document.hidden)};return document.addEventListener("visibilitychange",v),()=>{document.removeEventListener("visibilitychange",v)}},[]);const C=f.useCallback(async()=>{if(!m||!d){n.current=!1;return}const v=g();if(v.length===0){n.current=!1;return}const b=Date.now(),E=v.filter(x=>b-x.startedAt.getTime()>U);if(E.length>0){const{updateExport:x}=t.useExportStore.getState().actions;for(const l of E)x(l.id,{status:"failed",error:"Export timed out. Please try again or contact support.",lastUpdatedAt:new Date})}const p=v.filter(x=>b-x.startedAt.getTime()<=U);if(p.length===0){n.current=!1;return}const j=await Promise.allSettled(p.map(async x=>{try{const l=await t.getExportStatus(m,d,x.id);let w;if(l.status==="completed")try{w=await t.getDownloadUrl(m,d,x.id)}catch(D){console.error(`[useExportPolling] Failed to get download URL for ${x.id}:`,D)}return{id:x.id,status:l.status,progress:l.progress,completedChunks:l.completedChunks,completedAt:l.completedAt?new Date(l.completedAt):void 0,lastUpdatedAt:new Date,fileSize:l.fileSize,error:l.error,downloadUrl:w}}catch(l){return console.error(`[useExportPolling] Failed to poll export ${x.id}:`,l),null}})),{updateExport:S}=t.useExportStore.getState().actions;for(const x of j)x.status==="fulfilled"&&x.value&&S(x.value.id,x.value);const u=g();if(u.length>0&&!document.hidden){const x=u.reduce((w,D)=>D.startedAt<w?D.startedAt:w,u[0].startedAt),l=q(x);i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{var w;(w=a.current)==null||w.call(a)},l)}else n.current=!1},[m,d,g]);return f.useEffect(()=>{a.current=C},[C]),f.useEffect(()=>{var b;g().length>0&&o&&!n.current&&(n.current=!0,(b=a.current)==null||b.call(a))},[c,o,g]),f.useEffect(()=>{var b;const v=g();o&&v.length>0&&!n.current&&(n.current=!0,(b=a.current)==null||b.call(a))},[o,g]),f.useEffect(()=>{!o&&i.current&&(clearTimeout(i.current),i.current=null,n.current=!1)},[o]),f.useEffect(()=>()=>{i.current&&(clearTimeout(i.current),i.current=null)},[]),{isPolling:n.current,isTabVisible:o,inProgressCount:g().length}}function _(){const{authToken:s,tokenProps:r}=t.useSemaphorContext(),c=t.useExportStore(a=>a.activeExports),{addExport:o}=t.useExportActions(),h=f.useRef(!1),i=r==null?void 0:r.apiServiceUrl,n=s==null?void 0:s.accessToken;f.useEffect(()=>{if(h.current||!i||!n)return;(async()=>{try{const{exports:m}=await t.getExports(i,n,{status:["pending","processing","chunking","compacting","completed","failed"],limit:20});for(const d of m){if(c.has(d.id))continue;const g=d.totalChunks?Math.round(d.completedChunks/d.totalChunks*100):0;let C;if(d.status==="completed")try{C=await t.getDownloadUrl(i,n,d.id)}catch(b){console.error(`[useExportRecovery] Failed to get download URL for ${d.id}:`,b)}const v={id:d.id,status:d.status,progress:g,title:X(d),totalRows:d.totalRows,totalChunks:d.totalChunks,completedChunks:d.completedChunks,startedAt:new Date(d.createdAt),lastUpdatedAt:new Date,completedAt:d.completedAt?new Date(d.completedAt):void 0,fileSize:d.fileSize,error:d.error,expiresAt:new Date(d.expiresAt),downloadUrl:C};o(v)}h.current=!0}catch(m){console.error("[useExportRecovery] Failed to recover exports:",m),h.current=!0}})()},[i,n,o,c])}function X(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 G({open:s,onOpenChange:r,isLibraryVisual:c,currentVisualName:o,isSaving:h=!1,onConfirm:i}){const[n,a]=f.useState(c&&o?`Copy of ${o}`:o||""),[m,d]=f.useState(""),[g,C]=f.useState(!c),[v,b]=f.useState(!0);f.useEffect(()=>{s&&(a(c&&o?`Copy of ${o}`:o||""),d(""),C(!c),b(!0))},[s,c,o]);const E=()=>{n.trim()&&(!g&&!v||i({name:n.trim(),description:m.trim()||void 0,saveToLibrary:g,saveToCurrentDashboard:v}))},p=n.trim()&&(g||v);return e.jsx(t.Dialog,{open:s,onOpenChange:r,children:e.jsxs(t.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(t.DialogHeader,{children:[e.jsx(t.DialogTitle,{children:"Save Visual As"}),e.jsx(t.DialogDescription,{children:c?"Create a copy of this visual with a new name":"Save this visual to make it reusable"})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(t.Label,{htmlFor:"name",children:"Name"}),e.jsx(t.Input,{id:"name",value:n,onChange:j=>a(j.target.value),placeholder:"Enter visual name",disabled:h})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(t.Label,{htmlFor:"description",children:"Description (optional)"}),e.jsx(t.Textarea,{id:"description",value:m,onChange:j=>d(j.target.value),placeholder:"Enter visual description",rows:3,disabled:h})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(t.Label,{children:"Save to:"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.Checkbox,{id:"save-to-dashboard",checked:v,onCheckedChange:j=>b(!!j),disabled:h}),e.jsxs("label",{htmlFor:"save-to-dashboard",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:["Current Dashboard",e.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:c?"(add copy to this dashboard)":"(keep as local visual)"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.Checkbox,{id:"save-to-library",checked:g,onCheckedChange:j=>C(!!j),disabled:h}),e.jsxs("label",{htmlFor:"save-to-library",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:["Visual Library",e.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:c?"(save as new reusable visual)":"(make available to all dashboards)"})]})]})]}),!g&&!v&&e.jsx("p",{className:"text-sm text-destructive",children:"Please select at least one destination"})]})]}),e.jsxs(t.DialogFooter,{children:[e.jsx(t.Button,{variant:"outline",onClick:()=>r(!1),disabled:h,children:"Cancel"}),e.jsxs(t.Button,{onClick:E,disabled:!p||h,children:[h&&e.jsx(t.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),h?"Saving...":"Save"]})]})]})})}function W(){const[s,r]=f.useState(!1),[c,o]=f.useState(!1),[h,i]=f.useState(null),n=t.useEditorStore(l=>l.frame),a=t.useEditorStore(l=>l.card),m=t.useSelectedVisual(),d=t.useDashboardStore(l=>l.selectedSheetId),g=t.useDashboardStore(l=>l.actions.setIsDashboardPanelOpen),{getUpdatedFrame:C}=T.useVisualUtils(),{selectVisual:v}=t.useManagementActions(),{addFrame:b,setSelectedFrameId:E,setIsVisualEditing:p}=t.useDashboardActions(),j=!!(n!=null&&n.visualId),S=(()=>{var l,w;return((l=n==null?void 0:n.cards)==null?void 0:l.length)===1&&((w=n.cards[0])!=null&&w.title)?n.cards[0].title:m!=null&&m.title?m.title:(a==null?void 0:a.title)||"Untitled Visual"})(),u=t.useCreateVisualWithFrame(l=>{if(l!=null&&l.id){if(v(l),c&&h&&d){const w={...h,id:t.v4(),visualId:l.id};b(d,w,"end"),E(w.id),o(!1),i(null),p(!1)}g(!0),r(!1)}});return{saveAsDialogOpen:s,setSaveAsDialogOpen:r,handleSaveAs:async l=>{if(!d){t.ue.error("No sheet selected");return}const w=C(),A=w.cards.length===1?{...w,cards:w.cards.map(y=>({...y,title:l.name}))}:w;if(l.saveToLibrary){o(l.saveToCurrentDashboard),i(A);const y={title:l.name,description:l.description,frameObject:A,isPrivate:!1};u.mutate(y)}else if(l.saveToCurrentDashboard){const y={...A,id:t.v4(),visualId:void 0};b(d,y,"end"),E(y.id),t.ue.success("Visual saved to dashboard"),r(!1),p(!1)}},isLibraryVisual:j,currentVisualName:S,isSaving:u.isPending}}function Q({className:s}){const r=t.useEditorStore(u=>u.frame),c=t.useEditorStore(u=>u.card),o=t.useManagementStore(u=>u.selectedVisual),h=t.useDashboardStore(u=>u.selectedFrameId),i=t.useDashboardStore(u=>u.selectedSheetId),{setIsVisualEditing:n}=t.useDashboardActions(),a=!!(r!=null&&r.visualId||o!=null&&o.id),m=!!(r!=null&&r.visualId&&h),d=a&&!m,{saveAsDialogOpen:g,setSaveAsDialogOpen:C,handleSaveAs:v,isLibraryVisual:b,currentVisualName:E,isSaving:p}=W(),{handleAddLibraryVisual:j}=T.useVisualUtils(),S=async()=>{if(!i){t.ue.error("No dashboard sheet selected");return}if(!o){t.ue.error("No visual selected");return}const u=await j(o);u.success?(t.ue.success("Visual added to dashboard"),n(!1)):t.ue.error(u.error||"Failed to add visual to dashboard")};return e.jsxs(e.Fragment,{children:[!a&&e.jsx(N.EditorAcceptButton,{className:s,variant:"default"}),a&&e.jsxs(e.Fragment,{children:[m&&e.jsx(N.VisualApplyLocalButton,{className:s}),d&&i&&c&&(c.sql||t.hasValidCardConfig(c.config))&&e.jsxs(t.Button,{onClick:S,className:t.cn(s),size:"sm",variant:"outline",children:[e.jsx(V,{className:"mr-2 size-4 font-bold"}),"Add to Dashboard"]}),d&&e.jsx(N.VisualSaveButton,{className:s,variant:"default"}),m&&e.jsx(N.VisualSaveAndApplyButton,{className:s}),e.jsxs(t.DropdownMenu,{modal:!1,children:[e.jsx(t.DropdownMenuTrigger,{asChild:!0,children:e.jsx(t.Button,{variant:"outline",size:"sm",className:t.cn(s,"w-8 p-0"),children:e.jsx(t.EllipsisVertical,{className:"h-4 w-4"})})}),e.jsx(t.DropdownMenuContent,{align:"end",children:e.jsxs(t.DropdownMenuItem,{onClick:u=>{u.stopPropagation(),C(!0)},children:[e.jsx(N.Save,{className:"mr-2 h-4 w-4"}),"Save As..."]})})]})]}),!a&&e.jsxs(t.DropdownMenu,{modal:!1,children:[e.jsx(t.DropdownMenuTrigger,{asChild:!0,children:e.jsx(t.Button,{variant:"outline",size:"sm",className:t.cn(s,"w-8 p-0"),children:e.jsx(t.EllipsisVertical,{className:"h-4 w-4"})})}),e.jsx(t.DropdownMenuContent,{align:"end",children:e.jsxs(t.DropdownMenuItem,{onClick:()=>C(!0),children:[e.jsx(N.Save,{className:"mr-2 h-4 w-4"}),"Save As..."]})})]}),e.jsx(N.EditorCancelButton,{className:s}),e.jsx(G,{open:g,onOpenChange:u=>{p||C(u)},isLibraryVisual:b,currentVisualName:E,isSaving:p,onConfirm:v})]})}function Y({className:s,switchClassName:r}){const c=t.useEditorStore(a=>a.isDevMode),o=t.useDashboardStore(a=>a.isVisualEditing),{setIsDevMode:h}=t.useEditorActions(),{config:i}=f.useContext(t.SemaphorContext).tokenProps,n=(i==null?void 0:i.showAdvancedMode)!==!1;return!o||!n?null:e.jsxs("div",{className:t.cn("flex items-center space-x-2",s),children:[e.jsx(t.DevModeSwitch,{className:t.cn("",r),checked:c,onCheckedChange:()=>h(!c),id:"advanced-mode",icon:e.jsx(t.CodeXml,{className:"h-4 w-4"}),tooltip:"Advanced Mode"}),e.jsx("label",{htmlFor:"advanced-mode",className:"sr-only",children:"Advanced Mode"})]})}function Z({open:s,onOpenChange:r,onSave:c,onDiscard:o,isSaving:h}){const i=n=>{!n&&h||r(n)};return e.jsx(t.AlertDialog,{open:s,onOpenChange:i,children:e.jsxs(t.AlertDialogContent,{className:"max-w-md",children:[e.jsxs(t.AlertDialogHeader,{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-amber-100",children:e.jsx(t.TriangleAlert,{className:"h-5 w-5 text-amber-600"})}),e.jsx(t.AlertDialogTitle,{className:"text-xl",children:"Unsaved Changes"})]}),e.jsx(t.AlertDialogDescription,{className:"pt-2 text-base leading-relaxed",children:"You have unsaved changes to this dashboard. What would you like to do?"})]}),e.jsxs(t.AlertDialogFooter,{className:"flex-col gap-2 sm:flex-row sm:gap-2",children:[e.jsx(t.AlertDialogCancel,{disabled:h,className:"order-1 m-0 border-border/50 sm:order-1",children:"Cancel"}),e.jsx("button",{onClick:o,disabled:h,className:"order-2 rounded-md border border-destructive/20 bg-destructive/10 px-4 py-2 text-sm font-medium text-destructive transition-colors hover:bg-destructive/20 disabled:pointer-events-none disabled:opacity-50 sm:order-2",children:"Discard"}),e.jsx(t.AlertDialogAction,{onClick:c,disabled:h,className:"order-3 m-0 bg-primary text-primary-foreground hover:bg-primary/90 sm:order-3",children:h?e.jsxs(e.Fragment,{children:[e.jsx(t.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):"Save & Close"})]})]})})}function J(s,r,c,o){f.useEffect(()=>{s&&!c&&r&&o(t.cloneDeep(r))},[s,c,r,o])}function K({triggerButtonClassName:s}){const[r,c]=f.useState(!1),o=t.useDashboardStore(a=>{var m;return(m=a.dashboard)==null?void 0:m.id}),h=t.useDashboardStore(a=>{var m;return(m=a.dashboard)==null?void 0:m.title}),i=t.useDashboardStore(a=>{var m;return(m=a.dashboard)==null?void 0:m.sheets}),n=t.useDashboardStore(a=>a.selectedSheetId);return i==null||i.find(a=>a.id===n),o?e.jsxs(e.Fragment,{children:[e.jsx(t.IconButton,{tooltip:"Schedule Dashboard",className:t.cn("h-7 p-2",s),onClick:()=>c(!0),children:e.jsx(t.Clock,{className:"size-4"})}),e.jsx(t.EmailScheduleDialog,{open:r,onOpenChange:c,dashboardId:o,dashboardName:h})]}):null}function F({export:s,onRemove:r}){const c=()=>{s.downloadUrl&&window.open(s.downloadUrl,"_blank")},o=a=>{a.stopPropagation(),r==null||r(s.id)},h=()=>{switch(s.status){case"completed":return e.jsx(P,{className:"mt-0.5 h-5 w-5 shrink-0 text-green-600"});case"failed":return e.jsx(N.CircleX,{className:"mt-0.5 h-5 w-5 shrink-0 text-destructive"});default:return e.jsx(t.LoaderCircle,{className:"text-foreground-muted mt-0.5 h-5 w-5 shrink-0 animate-spin"})}},i=t.isExportInProgress(s.status),n=(()=>{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:[h(),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)})]})]}),i&&e.jsx("div",{className:"text-xs text-muted-foreground",children:n}),s.status==="failed"&&e.jsx("div",{className:"line-clamp-2 text-xs text-destructive",children:s.error||"Export failed"})]})]}),e.jsx(t.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0 opacity-0 transition-opacity group-hover:opacity-100",onClick:o,"aria-label":"Remove notification",children:e.jsx(t.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:I.formatDistanceToNow(s.startedAt,{addSuffix:!0})}),s.downloadUrl&&e.jsxs(t.Button,{size:"sm",variant:"outline",className:"h-8 bg-transparent",onClick:c,children:[e.jsx(t.Download,{className:"mr-1.5 h-3.5 w-3.5"}),"Download"]})]}),i&&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:I.formatDistanceToNow(s.startedAt,{addSuffix:!0})})]})]})}function L(){const{authToken:s,tokenProps:r}=t.useSemaphorContext(),c=t.useExportStore(p=>p.activeExports),{clearCompleted:o,removeExport:h,updateExport:i}=t.useExportActions(),[n,a]=f.useState(!1),[m,d]=f.useState(!1),g=Array.from(c.values()).sort((p,j)=>j.startedAt.getTime()-p.startedAt.getTime()),C=g.some(p=>p.status==="completed"||p.status==="failed"),v=f.useCallback(async()=>{const p=r==null?void 0:r.apiServiceUrl,j=s==null?void 0:s.accessToken;if(!(!p||!j)){a(!0);try{const S=Array.from(c.values());await Promise.all(S.map(async u=>{try{const x=await t.getExportStatus(p,j,u.id);let l;if(x.status==="completed")try{l=await t.getDownloadUrl(p,j,u.id)}catch(w){console.error(`Failed to get download URL for ${u.id}:`,w)}i(u.id,{status:x.status,progress:x.progress,completedChunks:x.completedChunks,completedAt:x.completedAt?new Date(x.completedAt):void 0,lastUpdatedAt:new Date,fileSize:x.fileSize,error:x.error,downloadUrl:l})}catch(x){console.error(`Failed to refresh export ${u.id}:`,x)}}))}finally{a(!1)}}},[c,s==null?void 0:s.accessToken,r==null?void 0:r.apiServiceUrl,i]),b=f.useCallback(async()=>{const p=r==null?void 0:r.apiServiceUrl,j=s==null?void 0:s.accessToken;if(!p||!j){o();return}d(!0);try{const S=g.filter(u=>u.status==="completed"||u.status==="failed");await Promise.all(S.map(u=>t.cancelExport(p,j,u.id).catch(x=>console.error(`Failed to delete export ${u.id}:`,x)))),o()}finally{d(!1)}},[g,r==null?void 0:r.apiServiceUrl,s==null?void 0:s.accessToken,o]),E=f.useCallback(async p=>{const j=r==null?void 0:r.apiServiceUrl,S=s==null?void 0:s.accessToken;if(j&&S)try{await t.cancelExport(j,S,p)}catch(u){console.error(`Failed to cancel export ${p}:`,u)}h(p)},[r==null?void 0:r.apiServiceUrl,s==null?void 0:s.accessToken,h]);return g.length===0?e.jsxs("div",{className:"p-6 text-center",children:[e.jsx(k,{className:"h-8 w-8 text-muted-foreground mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No active exports"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Large exports will appear here"})]}):e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"px-4 py-3 border-b flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(k,{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(t.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:v,disabled:n,title:"Refresh status",children:e.jsx(M,{className:`h-4 w-4 ${n?"animate-spin":""}`})}),C&&e.jsx(t.Button,{variant:"ghost",size:"sm",className:"h-7 text-sm px-2",onClick:b,disabled:m,children:m?"Clearing...":"Clear all"})]})]}),e.jsx("div",{className:"max-h-[350px] overflow-y-auto",children:e.jsx("div",{className:"divide-y",children:g.map(p=>e.jsx(F,{export:p,onRemove:E},p.id))})}),e.jsxs("div",{className:"px-4 py-2 border-t text-sm text-muted-foreground text-center",children:[g.length," total export",g.length!==1?"s":""]})]})}function ee(){const s=t.useExportStore(a=>a.activeExports),r=t.useInProgressExportsCount(),c=s.size>0,o=Array.from(s.values()).some(a=>a.status==="completed"||a.status==="failed"),i=r>0?r>9?"9+":String(r):null,n=c;return e.jsxs(t.Popover,{children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsxs(t.Button,{variant:"ghost",size:"icon",className:"relative h-8 w-8","aria-label":"Export notifications",children:[e.jsx(t.Bell,{className:"h-4 w-4"}),n&&e.jsx("span",{className:`absolute flex items-center justify-center rounded-full bg-primary text-primary-foreground ${i?"-right-0.5 -top-0.5 h-4 min-w-4 px-0.5 text-[10px] font-semibold":"right-0.5 top-0.5 h-2 w-2"}`,children:i})]})}),e.jsx(t.PopoverContent,{className:"w-80 p-0",align:"end",sideOffset:8,children:e.jsx(L,{})})]})}exports.AdvancedModeToggle=Y;exports.ExportNotificationItem=F;exports.ExportNotificationList=L;exports.NotificationBell=ee;exports.RefreshCw=M;exports.ScheduleDashboard=K;exports.UnsavedChangesAlert=Z;exports.VisualEditingControls=Q;exports.useExportPolling=H;exports.useExportRecovery=_;exports.usePristineSnapshotInitializer=J;