react-semaphor 0.1.290 → 0.1.292

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 (32) hide show
  1. package/dist/chunks/braces-0bzwctGp.js +23 -0
  2. package/dist/chunks/braces-hczcJsV8.js +6 -0
  3. package/dist/chunks/dashboard-controls-Db0F38eK.js +47 -0
  4. package/dist/chunks/dashboard-controls-DeUHM4uL.js +1970 -0
  5. package/dist/chunks/{dashboard-filter-controls-button-C4AMu723.js → dashboard-filter-controls-button-DDqEus_E.js} +54 -52
  6. package/dist/chunks/dashboard-filter-controls-button-DSQHVjjX.js +11 -0
  7. package/dist/chunks/{dashboard-json-C13EJaTK.js → dashboard-json-BDyKcoGT.js} +1 -1
  8. package/dist/chunks/{dashboard-json-BKs1UTLL.js → dashboard-json-COXiPm3N.js} +6 -6
  9. package/dist/chunks/{dashboard-summary-settings-dialog-fL9l0wUO.js → dashboard-summary-settings-dialog-CryMC_4x.js} +1 -1
  10. package/dist/chunks/{dashboard-summary-settings-dialog-T6aUgPAf.js → dashboard-summary-settings-dialog-DbcWMZsr.js} +1 -1
  11. package/dist/chunks/{edit-dashboard-visual-CKB34ird.js → edit-dashboard-visual-BqfzqW4i.js} +4 -9
  12. package/dist/chunks/{edit-dashboard-visual-CnVx0Xi7.js → edit-dashboard-visual-DLyimx6x.js} +11 -29
  13. package/dist/chunks/{index-Cr9Smn6Q.js → index-72yod5pb.js} +523 -516
  14. package/dist/chunks/{index-Cwg2SRSi.js → index-BQ6qu8FI.js} +93 -93
  15. package/dist/chunks/resource-management-panel-CSLGSJjC.js +6 -0
  16. package/dist/chunks/{resource-management-panel-DJgYduN9.js → resource-management-panel-DwPION_M.js} +22 -22
  17. package/dist/chunks/{use-create-flow-overlay-state-NGb4c5Ye.js → use-create-flow-overlay-state-UruHbtfS.js} +53 -53
  18. package/dist/chunks/{use-create-flow-overlay-state-DnI1SSKD.js → use-create-flow-overlay-state-zz9TYhdC.js} +1 -1
  19. package/dist/chunks/{use-visual-utils-ivCDI1cO.js → use-visual-utils-Bm-ZnkON.js} +1 -1
  20. package/dist/chunks/{use-visual-utils-BbxYtbzK.js → use-visual-utils-DPBqTRUC.js} +11 -11
  21. package/dist/dashboard/index.cjs +1 -1
  22. package/dist/dashboard/index.js +1 -1
  23. package/dist/index.cjs +1 -1
  24. package/dist/index.js +21 -21
  25. package/dist/style.css +1 -1
  26. package/dist/surfboard/index.cjs +1 -1
  27. package/dist/surfboard/index.js +2 -2
  28. package/package.json +1 -1
  29. package/dist/chunks/dashboard-controls-BSbG43wo.js +0 -42
  30. package/dist/chunks/dashboard-controls-LtQ98rvL.js +0 -1938
  31. package/dist/chunks/dashboard-filter-controls-button-CgoIPOZZ.js +0 -11
  32. package/dist/chunks/resource-management-panel-Dv18tosO.js +0 -6
@@ -1,11 +0,0 @@
1
- "use strict";const g=require("react"),e=require("./index-Cwg2SRSi.js"),t=require("react/jsx-runtime"),I=require("./use-create-flow-overlay-state-DnI1SSKD.js"),M=require("./use-visual-utils-ivCDI1cO.js"),L=require("./date-formatter-CqXdM6JO.js");/**
2
- * @license lucide-react v0.453.0 - ISC
3
- *
4
- * This source code is licensed under the ISC license.
5
- * See the LICENSE file in the root directory of this source tree.
6
- */const T=e.createLucideIcon("FileDown",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M12 18v-6",key:"17g6i2"}],["path",{d:"m9 15 3 3 3-3",key:"1npd3o"}]]);/**
7
- * @license lucide-react v0.453.0 - ISC
8
- *
9
- * This source code is licensed under the ISC license.
10
- * See the LICENSE file in the root directory of this source tree.
11
- */const P=e.createLucideIcon("FilterX",[["path",{d:"M13.013 3H2l8 9.46V19l4 2v-8.54l.9-1.055",key:"1fi1da"}],["path",{d:"m22 3-5 5",key:"12jva0"}],["path",{d:"m17 3 5 5",key:"k36vhe"}]]),V=1e4,z=15e3,O=3e4,R=3e4,H=12e4,k=2*60*60*1e3;function $(s){const r=Date.now()-s.getTime();return r<R?V:r<H?z:O}function _(){const{authToken:s,tokenProps:r}=e.useSemaphorContext(),m=e.useExportStore(p=>p.activeExports),[d,l]=g.useState(typeof document<"u"?!document.hidden:!0),h=g.useRef(null),o=g.useRef(!1),c=g.useRef(void 0),u=r==null?void 0:r.apiServiceUrl,n=s==null?void 0:s.accessToken,f=g.useCallback(()=>{const p=e.useExportStore.getState().activeExports;return Array.from(p.values()).filter(C=>e.isExportInProgress(C.status))},[]);g.useEffect(()=>{if(typeof document>"u")return;const p=()=>{l(!document.hidden)};return document.addEventListener("visibilitychange",p),()=>{document.removeEventListener("visibilitychange",p)}},[]);const b=g.useCallback(async()=>{if(!u||!n){o.current=!1;return}const p=f();if(p.length===0){o.current=!1;return}const C=Date.now(),D=p.filter(a=>C-a.startedAt.getTime()>k);if(D.length>0){const{updateExport:a}=e.useExportStore.getState().actions;for(const i of D)a(i.id,{status:"failed",error:"Export timed out. Please try again or contact support.",lastUpdatedAt:new Date})}const x=p.filter(a=>C-a.startedAt.getTime()<=k);if(x.length===0){o.current=!1;return}const j=await Promise.allSettled(x.map(async a=>{try{const i=await e.getExportStatus(u,n,a.id);let v;if(i.status==="completed")try{v=await e.getDownloadUrl(u,n,a.id)}catch(A){console.error(`[useExportPolling] Failed to get download URL for ${a.id}:`,A)}return{id:a.id,status:i.status,progress:i.progress,completedChunks:i.completedChunks,completedAt:i.completedAt?new Date(i.completedAt):void 0,lastUpdatedAt:new Date,fileSize:i.fileSize,error:i.error,downloadUrl:v}}catch(i){return console.error(`[useExportPolling] Failed to poll export ${a.id}:`,i),null}})),{updateExport:E}=e.useExportStore.getState().actions;for(const a of j)a.status==="fulfilled"&&a.value&&E(a.value.id,a.value);const w=f();if(w.length>0&&!document.hidden){const a=w.reduce((v,A)=>A.startedAt<v?A.startedAt:v,w[0].startedAt),i=$(a);h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{var v;(v=c.current)==null||v.call(c)},i)}else o.current=!1},[u,n,f]);return g.useEffect(()=>{c.current=b},[b]),g.useEffect(()=>{var C;f().length>0&&d&&!o.current&&(o.current=!0,(C=c.current)==null||C.call(c))},[m,d,f]),g.useEffect(()=>{var C;const p=f();d&&p.length>0&&!o.current&&(o.current=!0,(C=c.current)==null||C.call(c))},[d,f]),g.useEffect(()=>{!d&&h.current&&(clearTimeout(h.current),h.current=null,o.current=!1)},[d]),g.useEffect(()=>()=>{h.current&&(clearTimeout(h.current),h.current=null)},[]),{isPolling:o.current,isTabVisible:d,inProgressCount:f().length}}function q(){const{authToken:s,tokenProps:r}=e.useSemaphorContext(),m=e.useExportStore(c=>c.activeExports),{addExport:d}=e.useExportActions(),l=g.useRef(!1),h=r==null?void 0:r.apiServiceUrl,o=s==null?void 0:s.accessToken;g.useEffect(()=>{if(l.current||!h||!o)return;(async()=>{try{const{exports:u}=await e.getExports(h,o,{status:["pending","processing","chunking","compacting","completed","failed"],limit:20});for(const n of u){if(m.has(n.id))continue;const f=n.totalChunks?Math.round(n.completedChunks/n.totalChunks*100):0;let b;if(n.status==="completed")try{b=await e.getDownloadUrl(h,o,n.id)}catch(C){console.error(`[useExportRecovery] Failed to get download URL for ${n.id}:`,C)}const p={id:n.id,status:n.status,progress:f,title:X(n),totalRows:n.totalRows,totalChunks:n.totalChunks,completedChunks:n.completedChunks,startedAt:new Date(n.createdAt),lastUpdatedAt:new Date,completedAt:n.completedAt?new Date(n.completedAt):void 0,fileSize:n.fileSize,error:n.error,expiresAt:new Date(n.expiresAt),downloadUrl:b};d(p)}l.current=!0}catch(u){console.error("[useExportRecovery] Failed to recover exports:",u),l.current=!0}})()},[h,o,d,m])}function X(s){return s.title?s.title:e.isExportInProgress(s.status)?"Export in progress...":s.status==="completed"?"Export completed":s.status==="failed"?"Export failed":"Export"}function G({open:s,onOpenChange:r,isLibraryVisual:m,currentVisualName:d,isSaving:l=!1,destinationMode:h="both",onConfirm:o}){const[c,u]=g.useState(m&&d?`Copy of ${d}`:d||""),[n,f]=g.useState("");g.useEffect(()=>{s&&(u(m&&d?`Copy of ${d}`:d||""),f(""))},[s,m,d]);const b=!!c.trim(),p=h==="local"?{saveToLibrary:!1,saveToCurrentDashboard:!0,badgeType:"local",description:"Creates a local copy on the current dashboard.",actionLabel:"Add to Dashboard (Local)"}:h==="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"},C=()=>{!b||l||o({name:c.trim(),description:n.trim()||void 0,saveToLibrary:p.saveToLibrary,saveToCurrentDashboard:p.saveToCurrentDashboard})};return t.jsx(e.Dialog,{open:s,onOpenChange:r,children:t.jsxs(e.DialogContent,{className:"sm:max-w-[500px]",children:[t.jsxs(e.DialogHeader,{children:[t.jsxs(e.DialogTitle,{className:"flex items-center gap-2",children:[t.jsx("span",{children:"Save Visual As"}),p.badgeType!=="local"&&t.jsx(I.VisualBadge,{type:p.badgeType,showLabel:!0,className:"px-2 py-0.5"})]}),t.jsx(e.DialogDescription,{children:p.description})]}),t.jsxs("div",{className:"grid gap-4 py-4",children:[t.jsxs("div",{className:"grid gap-2",children:[t.jsx(e.Label,{htmlFor:"name",children:"Name"}),t.jsx(e.Input,{id:"name",value:c,onChange:D=>u(D.target.value),placeholder:"Enter visual name",disabled:l})]}),t.jsxs("div",{className:"grid gap-2",children:[t.jsx(e.Label,{htmlFor:"description",children:"Description (optional)"}),t.jsx(e.Textarea,{id:"description",value:n,onChange:D=>f(D.target.value),placeholder:"Enter visual description",rows:3,disabled:l})]})]}),t.jsxs(e.DialogFooter,{children:[t.jsx(e.Button,{variant:"outline",onClick:()=>r(!1),disabled:l,children:"Cancel"}),t.jsxs(e.Button,{onClick:C,disabled:!b||l,children:[l&&t.jsx(e.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),p.actionLabel]})]})]})})}function K(){const[s,r]=g.useState(!1),[m,d]=g.useState(!1),[l,h]=g.useState(null),o=e.useEditorStore(i=>i.frame),c=e.useEditorStore(i=>i.card),u=e.useSelectedVisual(),n=e.useDashboardStore(i=>i.selectedSheetId),f=e.useDashboardStore(i=>i.actions.setIsDashboardPanelOpen),{getUpdatedFrame:b}=M.useVisualUtils(),{selectVisual:p}=e.useManagementActions(),{addFrame:C,setSelectedFrameId:D,setIsVisualEditing:x}=e.useDashboardActions(),j=!!(o!=null&&o.visualId),E=(()=>{var i,v;return((i=o==null?void 0:o.cards)==null?void 0:i.length)===1&&((v=o.cards[0])!=null&&v.title)?o.cards[0].title:u!=null&&u.title?u.title:(c==null?void 0:c.title)||"Untitled Visual"})(),w=e.useCreateVisualWithFrame(i=>{if(i!=null&&i.id){if(p(i),m&&l&&n){const v={...l,id:e.v4(),visualId:i.id};C(n,v,"end"),D(v.id),d(!1),h(null),x(!1)}f(!0),r(!1)}});return{saveAsDialogOpen:s,setSaveAsDialogOpen:r,handleSaveAs:async i=>{if(!n){e.ue.error("No sheet selected");return}const v=b(),A=e.getDynamicFrameSaveIssue(v);if(A){e.ue.error(A);return}const N=v.cards.length===1?{...v,cards:v.cards.map(y=>({...y,title:i.name}))}:v;if(i.saveToLibrary){d(i.saveToCurrentDashboard),h(N);const y={title:i.name,description:i.description,frameObject:N,isPrivate:!1};w.mutate(y)}else if(i.saveToCurrentDashboard){const y={...N,id:e.v4(),visualId:void 0};C(n,y,"end"),D(y.id),e.ue.success("Visual saved to dashboard"),r(!1),x(!1)}},isLibraryVisual:j,currentVisualName:E,isSaving:w.isPending}}function Q(s={}){const r=e.useEditorStore(S=>S.frame),m=e.useManagementStore(S=>S.selectedVisual),d=e.useDashboardStore(S=>S.selectedFrameId),l=e.useDashboardStore(S=>S.selectedSheetId),{setIsVisualEditing:h,updateFrame:o}=e.useDashboardActions(),[c,u]=g.useState(!1),[n,f]=g.useState("both"),b=!!(r!=null&&r.visualId||m!=null&&m.id),p=!!(r!=null&&r.visualId&&d),C=b&&!p,{saveAsDialogOpen:D,setSaveAsDialogOpen:x,handleSaveAs:j,isLibraryVisual:E,currentVisualName:w,isSaving:a}=K(),{getUpdatedFrame:i}=M.useVisualUtils(),v=()=>{if(!l){e.ue.error("No sheet selected");return}if(c)return;u(!0);const S=i(),N=e.getDynamicFrameSaveIssue(S);if(N){u(!1),e.ue.error(N);return}const y={...S,visualId:void 0};o(l,y),setTimeout(()=>{u(!1),e.ue.success("Changes applied. Visual is now local to this dashboard"),h(!1)},300)},A=S=>{f(S),x(!0)};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"inline-flex items-center overflow-hidden rounded-[5px]",children:[!b&&t.jsx(I.EditorAcceptButton,{className:"rounded-none",variant:"default"}),b&&C&&t.jsx(I.VisualSaveButton,{className:"rounded-none",variant:"default"}),b&&p&&t.jsx(I.VisualSaveAndApplyButton,{className:"rounded-none"}),t.jsxs(e.DropdownMenu,{modal:!1,children:[t.jsx(e.DropdownMenuTrigger,{asChild:!0,children:t.jsx(e.Button,{variant:"default",size:"xs",className:"w-7 rounded-none border-l border-primary-foreground/20 px-0","aria-label":"Open visual save options",disabled:a||c,children:t.jsx(e.ChevronDown,{className:"h-3.5 w-3.5"})})}),t.jsxs(e.DropdownMenuContent,{align:"end",className:"min-w-[220px] rounded-[6px] border border-border/60 p-1 shadow-sm",children:[p&&t.jsxs(t.Fragment,{children:[t.jsxs(e.DropdownMenuItem,{onClick:v,disabled:c,children:[t.jsx(e.Check,{className:"h-3.5 w-3.5"}),c?"Applying...":"Apply Locally"]}),t.jsx(e.DropdownMenuSeparator,{})]}),t.jsxs(e.DropdownMenuItem,{onClick:()=>A("local"),disabled:a,children:[t.jsx(e.Plus,{className:"h-3.5 w-3.5"}),"Add to Dashboard (Local)"]}),t.jsxs(e.DropdownMenuItem,{onClick:()=>A("library"),disabled:a,children:[t.jsx(I.Library,{className:"h-3.5 w-3.5"}),"Save as Library Visual"]}),t.jsxs(e.DropdownMenuItem,{onClick:()=>A("both"),disabled:a,children:[t.jsx(I.Link2,{className:"h-3.5 w-3.5"}),"Save Copy as Linked Visual"]})]})]})]}),t.jsx(I.EditorCancelButton,{}),t.jsx(G,{open:D,onOpenChange:S=>{a||x(S)},isLibraryVisual:E,currentVisualName:w,isSaving:a,destinationMode:n,onConfirm:j})]})}function W({className:s}){const r=e.useEditorStore(u=>u.isDevMode),m=e.useDashboardStore(u=>u.isVisualEditing),{setIsDevMode:d}=e.useEditorActions(),{config:l}=g.useContext(e.SemaphorContext).tokenProps,h=(l==null?void 0:l.showAdvancedMode)!==!1;if(!m||!h)return null;const o="h-7 rounded-none border-0 bg-transparent px-2.5 shadow-none text-muted-foreground hover:bg-accent/50 hover:text-foreground",c="bg-muted text-foreground hover:bg-muted";return t.jsxs("div",{role:"radiogroup","aria-label":"Editor mode",className:e.cn("inline-flex items-stretch overflow-hidden rounded-[5px] border border-input bg-background",s),children:[t.jsxs(e.Button,{type:"button",variant:"ghost",size:"xs",role:"radio","aria-checked":!r,className:e.cn(o,!r&&c),onClick:()=>d(!1),children:[t.jsx(e.SlidersHorizontal,{className:"h-3.5 w-3.5"}),"Drag & drop"]}),t.jsxs(e.Button,{type:"button",variant:"ghost",size:"xs",role:"radio","aria-checked":r,className:e.cn(o,"border-l border-border/60",r&&c),onClick:()=>d(!0),children:[t.jsx(e.CodeXml,{className:"h-3.5 w-3.5"}),"SQL"]})]})}function Y({open:s,onOpenChange:r,onSave:m,onDiscard:d,isSaving:l,title:h="Unsaved changes",description:o="You have unsaved changes to this dashboard. What would you like to do?",cancelLabel:c="Cancel",discardLabel:u="Discard",saveLabel:n="Save"}){const f=b=>{!b&&l||r(b)};return t.jsx(e.AlertDialog,{open:s,onOpenChange:f,children:t.jsxs(e.AlertDialogContent,{children:[t.jsxs(e.AlertDialogHeader,{children:[t.jsx(e.AlertDialogTitle,{children:h}),t.jsx(e.AlertDialogDescription,{children:o})]}),t.jsxs(e.AlertDialogFooter,{children:[t.jsx(e.Button,{type:"button",size:"xs",onClick:d,disabled:l,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:u}),t.jsx(e.AlertDialogCancel,{disabled:l,children:c}),t.jsx(e.Button,{type:"button",size:"xs",onClick:m,disabled:l,children:l?t.jsxs(t.Fragment,{children:[t.jsx(e.LoaderCircle,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),"Saving..."]}):n})]})]})})}function Z(s,r,m,d){g.useEffect(()=>{s&&!m&&r&&d(e.cloneDeep(r))},[s,m,r,d])}function B({export:s,onRemove:r}){const m=()=>{s.downloadUrl&&window.open(s.downloadUrl,"_blank")},d=c=>{c.stopPropagation(),r==null||r(s.id)},l=()=>{switch(s.status){case"completed":return t.jsx(e.CircleCheck,{className:"mt-0.5 h-5 w-5 shrink-0 text-green-600"});case"failed":return t.jsx(I.CircleX,{className:"mt-0.5 h-5 w-5 shrink-0 text-destructive"});default:return t.jsx(e.LoaderCircle,{className:"text-foreground-muted mt-0.5 h-5 w-5 shrink-0 animate-spin"})}},h=e.isExportInProgress(s.status),o=(()=>{switch(s.status){case"pending":return"Queued...";case"processing":return"Processing...";case"chunking":return"Processing...";case"compacting":return"Finalizing...";default:return"Processing..."}})();return t.jsxs("div",{className:"group p-4 transition-colors hover:bg-muted/50",children:[t.jsxs("div",{className:"mb-2 flex items-start justify-between gap-3",children:[t.jsxs("div",{className:"flex min-w-0 flex-1 items-start gap-3",children:[l(),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("h4",{className:"mb-1 truncate text-sm font-medium",children:s.title}),s.status==="completed"&&t.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[t.jsxs("span",{children:[s.totalRows.toLocaleString()," rows"]}),s.fileSize&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:"•"}),t.jsx("span",{children:e.formatFileSize(s.fileSize)})]})]}),h&&t.jsx("div",{className:"text-xs text-muted-foreground",children:o}),s.status==="failed"&&t.jsx("div",{className:"line-clamp-2 text-xs text-destructive",children:s.error||"Export failed"})]})]}),t.jsx(e.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0 opacity-0 transition-opacity group-hover:opacity-100",onClick:d,"aria-label":"Remove notification",children:t.jsx(e.X,{className:"h-4 w-4"})})]}),t.jsxs("div",{className:"ml-8",children:[s.status==="completed"&&t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("span",{className:"text-xs text-muted-foreground",children:L.formatDistanceToNow(s.startedAt,{addSuffix:!0})}),s.downloadUrl&&t.jsxs(e.Button,{size:"sm",variant:"outline",className:"h-8 bg-transparent",onClick:m,children:[t.jsx(e.Download,{className:"mr-1.5 h-3.5 w-3.5"}),"Download"]})]}),h&&t.jsxs("div",{children:[t.jsx(e.Progress,{value:s.progress,className:"h-1.5"}),t.jsxs("span",{className:"mt-1 block text-xs text-muted-foreground",children:[s.progress,"% complete"]})]}),s.status==="failed"&&t.jsx("span",{className:"text-xs text-muted-foreground",children:L.formatDistanceToNow(s.startedAt,{addSuffix:!0})})]})]})}function U(){const{authToken:s,tokenProps:r}=e.useSemaphorContext(),m=e.useExportStore(x=>x.activeExports),{clearCompleted:d,removeExport:l,updateExport:h}=e.useExportActions(),[o,c]=g.useState(!1),[u,n]=g.useState(!1),f=Array.from(m.values()).sort((x,j)=>j.startedAt.getTime()-x.startedAt.getTime()),b=f.some(x=>x.status==="completed"||x.status==="failed"),p=g.useCallback(async()=>{const x=r==null?void 0:r.apiServiceUrl,j=s==null?void 0:s.accessToken;if(!(!x||!j)){c(!0);try{const E=Array.from(m.values());await Promise.all(E.map(async w=>{try{const a=await e.getExportStatus(x,j,w.id);let i;if(a.status==="completed")try{i=await e.getDownloadUrl(x,j,w.id)}catch(v){console.error(`Failed to get download URL for ${w.id}:`,v)}h(w.id,{status:a.status,progress:a.progress,completedChunks:a.completedChunks,completedAt:a.completedAt?new Date(a.completedAt):void 0,lastUpdatedAt:new Date,fileSize:a.fileSize,error:a.error,downloadUrl:i})}catch(a){console.error(`Failed to refresh export ${w.id}:`,a)}}))}finally{c(!1)}}},[m,s==null?void 0:s.accessToken,r==null?void 0:r.apiServiceUrl,h]),C=g.useCallback(async()=>{const x=r==null?void 0:r.apiServiceUrl,j=s==null?void 0:s.accessToken;if(!x||!j){d();return}n(!0);try{const E=f.filter(a=>a.status==="completed"||a.status==="failed"),w=await Promise.allSettled(E.map(async a=>(await e.cancelExport(x,j,a.id),a.id)));for(const a of w)a.status==="fulfilled"?l(a.value):console.error("Failed to delete export:",a.reason)}finally{n(!1)}},[f,r==null?void 0:r.apiServiceUrl,s==null?void 0:s.accessToken,d,l]),D=g.useCallback(async x=>{const j=r==null?void 0:r.apiServiceUrl,E=s==null?void 0:s.accessToken;if(j&&E)try{await e.cancelExport(j,E,x),l(x);return}catch(w){console.error(`Failed to cancel export ${x}:`,w)}l(x)},[r==null?void 0:r.apiServiceUrl,s==null?void 0:s.accessToken,l]);return f.length===0?t.jsxs("div",{className:"p-6 text-center",children:[t.jsx(T,{className:"mx-auto mb-2 h-8 w-8 text-muted-foreground"}),t.jsx("p",{className:"text-sm text-muted-foreground",children:"No active exports"}),t.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Large exports will appear here"})]}):t.jsxs("div",{className:"flex flex-col",children:[t.jsxs("div",{className:"flex items-center justify-between border-b px-4 py-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(T,{className:"h-5 w-5 text-muted-foreground"}),t.jsx("h4",{className:"font-semibold",children:"Exports"})]}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(e.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:p,disabled:o,title:"Refresh status",children:t.jsx(e.RefreshCw,{className:`h-4 w-4 ${o?"animate-spin":""}`})}),b&&t.jsx(e.Button,{variant:"ghost",size:"sm",className:"h-7 px-2 text-sm",onClick:C,disabled:u,children:u?"Clearing...":"Clear all"})]})]}),t.jsx("div",{className:"max-h-[350px] overflow-y-auto",children:t.jsx("div",{className:"divide-y",children:f.map(x=>t.jsx(B,{export:x,onRemove:D},x.id))})})]})}function J({variant:s}){const r=e.useExportStore(u=>u.activeExports),m=e.useInProgressExportsCount(),d=r.size>0,l=Array.from(r.values()).some(u=>u.status==="completed"||u.status==="failed"),o=m>0?m>9?"9+":String(m):null,c=d;return t.jsxs(e.Popover,{children:[t.jsx(e.PopoverTrigger,{asChild:!0,children:t.jsxs(e.Button,{variant:s??"ghost",size:"xs",className:"relative w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":"Export notifications",children:[t.jsx(e.Bell,{className:"h-3.5 w-3.5"}),c&&t.jsx("span",{className:`absolute flex items-center justify-center rounded-full bg-primary text-primary-foreground ${o?"-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:o})]})}),t.jsx(e.PopoverContent,{className:"w-80 p-0",align:"end",sideOffset:8,children:t.jsx(U,{})})]})}function ee(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 te({open:s,onOpenChange:r,trigger:m,showTrigger:d=!0,initialMode:l="manage"}){const h=l==="create",{forceClose:o,handleOpenChange:c,isCreateFlowActive:u,preventPassiveDismissDuringCreate:n,resolvedOpen:f,setIsCreateFlowActive:b}=I.useCreateFlowOverlayState({open:s,onOpenChange:r,initialCreateFlowActive:l==="create",dismissMode:d?"passive":"explicit-only"}),p=e.useDashboardStore(N=>N.dashboard),{setDashboardControlsModel:C}=e.useDashboardActions(),{participants:D}=e.useDashboardStructuralParticipants(e.getDashboardCards(p)),x=Array.from(new Map(D.flatMap(N=>N.fieldChoices.map(y=>{var F;return[y.value,{option:y,target:(F=N.fieldTargetMap)==null?void 0:F[y.value]}]}))).values()),j=Array.from(new Map(D.flatMap(N=>N.metricChoices.map(y=>{var F;return[y.value,{option:y,target:(F=N.metricTargetMap)==null?void 0:F[y.value]}]}))).values()),E=e.collectDashboardControlIds({...p||{},controls:[]}),w=e.buildDashboardStructuralParticipantIdsByControlId(p),a=(N,y,F)=>{C(N,y,ee(F))},i=g.useCallback(()=>{if(h){o();return}b(!1)},[h,o,b]),v=t.jsx(I.ControlDefinitionListEditor,{scope:"dashboard",controls:p.controls||[],reservedControlIds:E,defaultValues:p.defaultControlValues||{},usageByControlId:e.buildDashboardControlUsageById(p),availableFieldChoices:x,availableMetricChoices:j,structuralParticipants:D,structuralParticipantIdsByControlId:w,initialCreateFlow:l==="create",onCreateFlowActiveChange:b,onCreateFlowComplete:i,onChange:a,emptyMessage:"No dashboard controls yet."}),A=u?"Add dashboard control":"Dashboard Controls",S=t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx("h4",{className:"text-sm font-medium",children:"Dashboard Controls"}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"Add shared controls viewers can use across the dashboard. Each card can decide how to respond to the same control."})]}),v]});return d?t.jsxs(e.Popover,{open:f,onOpenChange:c,children:[t.jsx(e.PopoverTrigger,{asChild:!0,children:m||t.jsxs(e.Button,{variant:"outline",className:"h-7 px-2",size:"sm",children:[t.jsx(e.SlidersHorizontal,{className:"mr-2 h-4 w-4"}),"Controls"]})}),t.jsx(e.PopoverContent,{className:"w-[620px] max-w-[95vw] space-y-4",align:"end",onEscapeKeyDown:n,onPointerDownOutside:n,children:S})]}):t.jsx(e.Dialog,{open:f,onOpenChange:c,children:t.jsxs(e.DialogContent,{className:"flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",onEscapeKeyDown:n,onPointerDownOutside:n,children:[t.jsxs(e.DialogHeader,{className:u?"space-y-0":void 0,children:[t.jsx(e.DialogTitle,{className:"text-[15px]",children:A}),t.jsx(e.DialogDescription,{className:u?"sr-only":"text-[13px]",children:u?"Configure and add a shared dashboard control.":"Add shared controls viewers can use across the dashboard. Each card can decide how to respond to the same control."})]}),t.jsx("div",{className:"min-h-0 overflow-y-auto pr-1",children:v})]})})}function se({showFilters:s,onToggleFilters:r,onAddFilter:m,onAddControl:d,onManageControls:l,size:h="default",className:o,primaryButtonClassName:c,secondaryButtonClassName:u,dropdownContentClassName:n}){const f=h==="toolbar";return t.jsxs("div",{className:e.cn("relative inline-flex items-stretch overflow-hidden rounded-[5px] border border-input bg-background",o),children:[t.jsxs(e.Button,{variant:"ghost",size:"xs",className:e.cn(f?"h-8":"h-7","rounded-none border-0 bg-transparent pl-2.5 pr-2 shadow-none hover:bg-accent/50",c),onClick:r,children:[s?t.jsx(P,{className:"h-3.5 w-3.5"}):t.jsx(e.Filter,{className:"h-3.5 w-3.5"}),"Filter"]}),t.jsxs(e.DropdownMenu,{children:[t.jsx(e.DropdownMenuTrigger,{asChild:!0,children:t.jsx(e.Button,{variant:"ghost",size:"xs",className:e.cn(f?"h-8 w-7":"h-7 w-7","rounded-none border-0 border-l border-border/60 bg-transparent px-0 shadow-none hover:bg-accent/50",u),"aria-label":"Filter and control actions",children:t.jsx(e.ChevronDown,{className:"h-3.5 w-3.5"})})}),t.jsxs(e.DropdownMenuContent,{align:"start",className:e.cn("min-w-[180px] rounded-[6px] border border-border/60 p-1 shadow-sm",n),children:[t.jsxs(e.DropdownMenuItem,{onSelect:m,children:[t.jsx(e.Filter,{className:"h-3.5 w-3.5"}),"Add filter"]}),t.jsxs(e.DropdownMenuItem,{onSelect:d,children:[t.jsx(e.SlidersHorizontal,{className:"h-3.5 w-3.5"}),"Add control"]}),t.jsxs(e.DropdownMenuItem,{onSelect:l,children:[t.jsx(e.Pencil,{className:"h-3.5 w-3.5"}),"Manage controls"]})]})]})]})}exports.AdvancedModeToggle=W;exports.DashboardControlsSettings=te;exports.DashboardFilterControlsButton=se;exports.ExportNotificationItem=B;exports.ExportNotificationList=U;exports.NotificationBell=J;exports.UnsavedChangesAlert=Y;exports.VisualEditingControls=Q;exports.useExportPolling=_;exports.useExportRecovery=q;exports.usePristineSnapshotInitializer=Z;
@@ -1,6 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("./index-Cwg2SRSi.js"),h=require("react"),ne=require("./use-visual-utils-ivCDI1cO.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 ae=t.createLucideIcon("FolderOpen",[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]]);function ie(s,m={}){const{enabled:p=!0,eventType:l="mousedown"}=m,i=h.useRef(null);return h.useEffect(()=>{const x=w=>{const r=w.target;i.current&&i.current.contains(r)||r instanceof Element&&(r.closest("[data-radix-popper-content-wrapper]")||r.closest("[data-radix-select-content]")||r.closest("[data-radix-popover-content]")||r.closest("[data-radix-dropdown-menu-content]")||r.closest("[data-radix-tooltip-content]")||r.closest('[role="listbox"]')||r.closest('[role="option"]')||r.closest('[role="combobox"]'))||r instanceof Element&&r.hasAttribute("data-radix-")||s()};return p&&document.addEventListener(l,x),()=>{document.removeEventListener(l,x)}},[s,p,l]),i}function oe(){return e.jsx("div",{className:"space-y-1.5 py-1",children:[...Array(5)].map((s,m)=>e.jsxs("div",{className:"flex animate-pulse items-start gap-3 rounded-xl border border-transparent px-2.5 py-2.5",children:[e.jsx("div",{className:"mt-0.5 h-4 w-4 flex-shrink-0 rounded bg-muted/60"}),e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("div",{className:"h-4 w-3/5 rounded bg-muted/60"}),e.jsx("div",{className:"h-3 w-4/5 rounded bg-muted/40"})]})]},m))})}const le=s=>{const m=t.useDashboardStore(i=>i.isVisualEditing),p=t.useDashboardStore(i=>i.selectedFrameId),l=t.useEditorStore(i=>i.frame);return!!(m&&p&&(l==null?void 0:l.visualId)===s)};function de({visual:s,isDeleting:m,isDuplicating:p,onAddVisual:l,onOpenVisual:i,onEditDetails:x,onDeleteClick:w,onDuplicateVisual:r,onShareVisual:N,formatDate:b}){var O,T,U,P;const{selectVisual:f}=t.useManagementActions(),d=t.useIsVisualSelected(s.id),u=le(s.id),A=t.useDashboardStore(a=>a.isVisualEditing),{isConsoleMode:R}=t.useDashboardPreferences(),j=h.useRef(null),[S,v]=h.useState(!1),[E,L]=h.useState(!1);h.useEffect(()=>{p?(v(!0),L(!0)):E&&(v(!1),L(!1))},[p,E]),h.useEffect(()=>{u&&j.current&&j.current.scrollIntoView({behavior:"smooth",block:"center"})},[u]);const C=()=>{f(s),i==null||i(s)},y=a=>{a.currentTarget===a.target&&(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),C())};return e.jsxs("div",{ref:j,className:t.cn("group flex cursor-pointer items-start gap-1 rounded-[5px] px-2 py-1.5 transition-colors hover:bg-muted/50 focus-within:bg-muted/50",u?"bg-muted ring-1 ring-inset ring-foreground/20":d&&"bg-muted"),onClick:C,children:[e.jsxs("div",{role:"button",tabIndex:0,className:"min-w-0 flex-1 cursor-pointer focus-visible:outline-none",onKeyDown:y,children:[e.jsx("p",{className:"truncate text-[13px] font-medium leading-5 text-foreground",title:s.title||"Untitled Visual",children:s.title||"Untitled Visual"}),e.jsx("p",{className:"truncate text-[11px] leading-4 text-muted-foreground",title:s.description||"No description",children:(O=s.description)!=null&&O.trim()?s.description:"No description"})]}),e.jsx("div",{className:t.cn("flex shrink-0 items-center transition-opacity",d||u||S?"pointer-events-auto opacity-100":"pointer-events-none opacity-0 group-hover:pointer-events-auto group-hover:opacity-100 group-focus-within:pointer-events-auto group-focus-within:opacity-100"),onClick:a=>a.stopPropagation(),children:e.jsxs("div",{className:"inline-flex items-stretch overflow-hidden rounded-[5px] border border-border/60 bg-background",children:[e.jsxs(t.Button,{size:"xs",variant:"ghost",className:"rounded-none border-0 shadow-none hover:bg-accent/50",disabled:A,onClick:a=>{a.stopPropagation(),l(s)},"aria-label":`Add ${s.title||"visual"}`,children:[e.jsx(t.Plus,{className:"h-3.5 w-3.5"}),"Add"]}),e.jsxs(t.DropdownMenu,{modal:!1,open:S,onOpenChange:v,children:[e.jsx(t.DropdownMenuTrigger,{asChild:!0,children:e.jsx(t.Button,{size:"xs",variant:"ghost",className:"w-7 rounded-none border-0 border-l border-border/60 px-0 shadow-none hover:bg-accent/50","aria-label":"Open visual actions",children:e.jsx(t.EllipsisVertical,{className:"h-3.5 w-3.5"})})}),e.jsxs(t.DropdownMenuContent,{align:"end",className:"z-[51] w-44 rounded-[6px] border border-border/60 p-1 shadow-sm",children:[e.jsxs(t.DropdownMenuItem,{onClick:a=>{a.stopPropagation(),l(s)},disabled:A,children:[e.jsx(t.Plus,{className:"h-3.5 w-3.5"}),"Add"]}),e.jsxs(t.DropdownMenuItem,{onClick:a=>{a.stopPropagation(),i==null||i(s)},children:[e.jsx(ae,{className:"h-3.5 w-3.5"}),"Open"]}),e.jsxs(t.DropdownMenuItem,{onClick:a=>{a.preventDefault(),a.stopPropagation(),r(s.id)},disabled:p,children:[p?e.jsx(t.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(t.Copy,{className:"h-3.5 w-3.5"}),p?"Duplicating…":"Duplicate"]}),s.ownership.isOwner&&e.jsxs(e.Fragment,{children:[e.jsxs(t.DropdownMenuItem,{onClick:a=>{a.stopPropagation(),x==null||x(s)},children:[e.jsx(t.PenLine,{className:"h-3.5 w-3.5"}),"Edit details"]}),e.jsxs(t.DropdownMenuItem,{onClick:a=>{a.stopPropagation(),N(s)},children:[e.jsx(t.Users,{className:"h-3.5 w-3.5"}),"Share"]}),e.jsx(t.DropdownMenuSeparator,{}),e.jsxs(t.DropdownMenuItem,{onClick:a=>{a.stopPropagation(),w(s)},className:"text-destructive focus:bg-destructive/10 focus:text-destructive",disabled:m,children:[e.jsx(t.Trash2,{className:"h-3.5 w-3.5"}),m?"Deleting…":"Delete"]})]}),e.jsx(t.DropdownMenuSeparator,{}),e.jsxs("div",{className:"space-y-1 px-2 py-1.5 text-[11px] text-muted-foreground",children:[(((T=s.ownership.createdBy)==null?void 0:T.type)==="tenant"||((U=s.ownership.createdBy)==null?void 0:U.type)==="organization"&&R)&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(t.User,{className:"h-3 w-3"}),e.jsx("span",{children:((P=s.ownership.createdBy)==null?void 0:P.name)||"Unknown"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(t.Calendar,{className:"h-3 w-3"}),e.jsx("span",{children:b(s.lastModified)})]})]})]})]})]})})]})}function ce({searchQuery:s}){const[m,p]=h.useState(!1),[l,i]=h.useState(null),[x,w]=h.useState(!1),[r,N]=h.useState(null),[b,f]=h.useState(null),[d,u]=h.useState(null),{handleEditLibraryVisual:A,handleAddLibraryVisual:R}=ne.useVisualUtils(),{resources:j,isLoading:S,isError:v,updateResource:E,deleteResource:L,duplicateResource:C,isDeleting:y}=t.useVisualManagement(()=>{w(!1),N(null)}),O=j.filter(o=>{var M,c;return((M=o==null?void 0:o.title)==null?void 0:M.toLowerCase().includes(s.toLowerCase()))||((c=o==null?void 0:o.description)==null?void 0:c.toLowerCase().includes(s.toLowerCase()))}),T=o=>new Date(o).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),U=o=>{N(o),w(!0)},P=()=>{r&&L(r.id)},{startUpdating:a,stopUpdating:_,isUpdating:F}=t.useResourceUpdateState(),V=(o,M,c)=>{var Q;const B=Object.fromEntries(Object.entries(M).filter(([,I])=>I!==void 0));if(Object.keys(B).length===0){(Q=c==null?void 0:c.onSuccess)==null||Q.call(c);return}const D=Object.keys(B),H=D.length===1?D[0]:void 0;a(o,H),E({resourceId:o,data:B},{onSuccess:()=>{var I;_(o,H),(I=c==null?void 0:c.onSuccess)==null||I.call(c)},onError:()=>{var I;_(o,H),(I=c==null?void 0:c.onError)==null||I.call(c)}})},G=o=>{f(o),C(o,{onSettled:()=>f(null)})},z=o=>{A(o)},W=o=>{R(o)},X=o=>{i(o),p(!0)},Y=o=>{u(o)},$=()=>{u(null)},J=({title:o,description:M})=>{if(!d)return;const c={};o!==d.title&&(c.title=o),(d.description||"")!==M&&(c.description=M),V(d.id,c,{onSuccess:()=>{u(null)}})};return S?e.jsx(oe,{}):v?e.jsx(t.ScrollArea,{className:"w-full flex-1 pr-2",children:e.jsxs("div",{className:"flex flex-col items-center gap-1.5 px-4 py-10 text-center",children:[e.jsx("p",{className:"text-[12px] text-destructive",children:"Failed to load visuals"}),e.jsx(t.Button,{variant:"outline",size:"xs",onClick:()=>window.location.reload(),children:"Retry"})]})}):e.jsxs("div",{className:"flex h-full flex-1 flex-col",children:[e.jsx("div",{className:"flex flex-1 basis-0 flex-col gap-0.5 overflow-y-auto",children:O.length===0?e.jsxs("div",{className:"flex flex-col items-center gap-1.5 px-4 py-10 text-center",children:[e.jsx(t.Grid3x3,{className:"h-5 w-5 text-muted-foreground/60"}),e.jsx("h3",{className:"text-[13px] font-medium text-foreground",children:s?"No visuals found":"No visuals yet"}),e.jsx("p",{className:"text-[12px] text-muted-foreground",children:s?"Try adjusting your search.":'Click "New" above to add your first visual.'})]}):O.map(o=>e.jsx(de,{visual:o,onAddVisual:W,onOpenVisual:z,onEditDetails:Y,onDeleteClick:U,onDuplicateVisual:G,onShareVisual:X,isDeleting:y,isDuplicating:b===o.id,formatDate:T},o.id))}),m&&l&&e.jsx(t.ShareDialog,{resource:l,resourceType:t.ResourceType.VISUAL,onClose:()=>{p(!1),i(null)}}),d&&e.jsx(t.ResourceEditDialog,{open:!!d,resourceLabel:"Visual",initialTitle:d.title||"",initialDescription:d.description||"",onClose:$,onSave:J,isSaving:F(d.id)}),e.jsx(t.AlertDialog,{open:x,onOpenChange:o=>{!o&&y||(w(o),o||N(null))},children:e.jsxs(t.AlertDialogContent,{children:[e.jsxs(t.AlertDialogHeader,{children:[e.jsx(t.AlertDialogTitle,{children:"Delete Visual"}),e.jsxs(t.AlertDialogDescription,{children:['Are you sure you want to delete "',r==null?void 0:r.title,'"? This action cannot be undone.']})]}),e.jsxs(t.AlertDialogFooter,{children:[e.jsx(t.AlertDialogCancel,{disabled:y,children:"Cancel"}),e.jsxs(t.AlertDialogAction,{onClick:o=>{o.preventDefault(),o.stopPropagation(),P()},disabled:y,children:[y?e.jsx(t.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(t.Trash2,{className:"h-3.5 w-3.5"}),y?"Deleting…":"Delete"]})]})]})})]})}function ue({dashboard:s,isDeleting:m,isDuplicating:p,onLoadDashboard:l,onEditDetails:i,onDeleteClick:x,onDuplicateDashboard:w,onShareDashboard:r,formatDate:N,onDashboardItemClick:b}){var E,L;const{selectDashboard:f}=t.useManagementActions(),d=t.useIsDashboardSelected(s.id),{userContext:u,isLoading:A}=t.useCurrentUserInfo(),R=((E=u==null?void 0:u.permissions)==null?void 0:E.canEdit)??!1,j=A||!R,S=()=>{f(s),l(s.id),b==null||b(s.id)},v=C=>{C.currentTarget===C.target&&(C.key==="Enter"||C.key===" ")&&(C.preventDefault(),S())};return e.jsxs("div",{className:t.cn("group flex cursor-pointer items-start gap-1 rounded-[5px] px-2 py-1.5 transition-colors hover:bg-muted/50 focus-within:bg-muted/50",d&&"bg-muted"),onClick:S,children:[e.jsxs("div",{role:"button",tabIndex:0,className:"min-w-0 flex-1 cursor-pointer focus-visible:outline-none",onKeyDown:v,children:[e.jsx("p",{className:"truncate text-[13px] font-medium leading-5 text-foreground",title:s.title||"Untitled Dashboard",children:s.title||"Untitled Dashboard"}),e.jsx("p",{className:"truncate text-[11px] leading-4 text-muted-foreground",title:s.description||"No description",children:(L=s.description)!=null&&L.trim()?s.description:"No description"})]}),e.jsx("div",{className:t.cn("shrink-0 transition-opacity",d?"opacity-100":"opacity-0 group-hover:opacity-100 group-focus-within:opacity-100"),children:e.jsx(t.DashboardActionsMenu,{dashboard:s,isDeleting:m,isDuplicating:p,shouldHideActions:j,onEditDetails:i,onDeleteClick:x,onDuplicateDashboard:w,onShareDashboard:r,formatDate:N})})]})}function he({onRetry:s}){return e.jsx(t.ScrollArea,{className:"w-full flex-1 pr-2",children:e.jsxs("div",{className:"rounded-xl border border-dashed border-border/60 bg-muted/20 px-4 py-8 text-center text-muted-foreground",children:[e.jsx("p",{className:"text-sm text-destructive",children:"Failed to load dashboards"}),e.jsx(t.Button,{variant:"outline",size:"sm",className:"mt-2",onClick:s,children:"Retry"})]})})}function xe(s){var ee;const{searchQuery:m,onLoadDashboard:p,onEditDashboard:l,onDashboardItemClick:i}=s,[x,w]=h.useState(!1),[r,N]=h.useState(null),[b,f]=h.useState(!1),[d,u]=h.useState(null),[A,R]=h.useState(null),[j,S]=h.useState(null),v=t.useManagementStore(n=>n.lastSelectedDashboard),E=t.useManagementStore(n=>n.selectedDashboard),L=t.useManagementStore(n=>n.actions.selectDashboard),C=t.useManagementStore(n=>n.actions.clearSelectedDashboard),{tokenProps:y,id:O}=t.useSemaphorContext(),{resources:T,isLoading:U,isError:P,updateResource:a,deleteResource:_,duplicateResource:F,isDeleting:V}=t.useDashboardManagement(()=>{f(!1);const n=d==null?void 0:d.id;u(null),(E==null?void 0:E.id)===n&&(!(y!=null&&y.dashboard_id)&&!O?C():v&&v.id!==n&&L(v))}),{userContext:G}=t.useCurrentUserInfo(),z=((ee=G==null?void 0:G.permissions)==null?void 0:ee.canCreateDashboard)??!1,W=T.filter(n=>{var K,g;return((K=n==null?void 0:n.title)==null?void 0:K.toLowerCase().includes(m.toLowerCase()))||((g=n==null?void 0:n.description)==null?void 0:g.toLowerCase().includes(m.toLowerCase()))}),X=n=>new Date(n).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),Y=n=>{p==null||p(n)},$=n=>{u(n),f(!0)},J=()=>{d&&_(d.id)},o=n=>{R(n),F(n,{onSettled:()=>R(null)})},{startUpdating:M,stopUpdating:c,isUpdating:B}=t.useResourceUpdateState(),D=(n,K,g)=>{var se;const Z=Object.fromEntries(Object.entries(K).filter(([,q])=>q!==void 0));if(Object.keys(Z).length===0){(se=g==null?void 0:g.onSuccess)==null||se.call(g);return}const te=Object.keys(Z),k=te.length===1?te[0]:void 0;M(n,k),a({resourceId:n,data:Z},{onSuccess:()=>{var q;c(n,k),(q=g==null?void 0:g.onSuccess)==null||q.call(g)},onError:()=>{var q;c(n,k),(q=g==null?void 0:g.onError)==null||q.call(g)}})},H=n=>{N(n),w(!0)},Q=n=>{l==null||l(n.id),S(n)},I=()=>{S(null)},re=({title:n,description:K})=>{if(!j)return;const g={};n!==j.title&&(g.title=n),(j.description||"")!==K&&(g.description=K),D(j.id,g,{onSuccess:()=>{S(null)}})};return U?e.jsx(oe,{}):P?e.jsx(he,{onRetry:()=>window.location.reload()}):e.jsxs("div",{className:"flex h-full flex-1 flex-col",children:[e.jsx("div",{className:"flex flex-1 basis-0 flex-col gap-0.5 overflow-y-auto",children:W.length===0?e.jsxs("div",{className:"flex flex-col items-center gap-1.5 px-4 py-10 text-center",children:[e.jsx(t.ChartColumn,{className:"h-5 w-5 text-muted-foreground/60"}),e.jsx("h3",{className:"text-[13px] font-medium text-foreground",children:m?"No dashboards found":"No dashboards yet"}),e.jsx("p",{className:"text-[12px] text-muted-foreground",children:m?"Try adjusting your search.":z?'Click "New" above to add your first dashboard.':"No dashboards have been shared with you yet."})]}):W.map(n=>e.jsx(ue,{dashboard:n,isDeleting:V,isDuplicating:A===n.id,onLoadDashboard:Y,onEditDetails:Q,onDeleteClick:$,onDuplicateDashboard:o,onShareDashboard:H,formatDate:X,onDashboardItemClick:i},n.id))}),x&&r&&e.jsx(t.ShareDialog,{resource:r,resourceType:t.ResourceType.DASHBOARD,onClose:()=>{w(!1),N(null)}}),e.jsx(t.AlertDialog,{open:b,onOpenChange:n=>{!n&&V||(f(n),n||u(null))},children:e.jsxs(t.AlertDialogContent,{children:[e.jsxs(t.AlertDialogHeader,{children:[e.jsx(t.AlertDialogTitle,{children:"Delete Dashboard"}),e.jsxs(t.AlertDialogDescription,{children:['Are you sure you want to delete "',d==null?void 0:d.title,'"? This action cannot be undone.']})]}),e.jsxs(t.AlertDialogFooter,{children:[e.jsx(t.AlertDialogCancel,{disabled:V,children:"Cancel"}),e.jsxs(t.AlertDialogAction,{onClick:n=>{n.preventDefault(),n.stopPropagation(),J()},disabled:V,children:[V?e.jsx(t.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(t.Trash2,{className:"h-3.5 w-3.5"}),V?"Deleting…":"Delete"]})]})]})}),j&&e.jsx(t.ResourceEditDialog,{open:!!j,resourceLabel:"Dashboard",initialTitle:j.title||"",initialDescription:j.description||"",onClose:I,onSave:re,isSaving:B(j.id)})]})}function pe({open:s,onOpenChange:m,onSubmit:p,isCreating:l}){const[i,x]=h.useState(""),[w,r]=h.useState("");h.useEffect(()=>{s||(x(""),r(""))},[s]);const N=()=>{i.trim()&&p({title:i,description:w})},b=f=>{m(f)};return e.jsx(t.Dialog,{open:s,onOpenChange:b,children:e.jsxs(t.DialogContent,{children:[e.jsxs(t.DialogHeader,{children:[e.jsx(t.DialogTitle,{children:"Create New Visual"}),e.jsx(t.DialogDescription,{children:"Add a new visual to your library. You can configure it after creation."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{htmlFor:"title",children:"Visual Title"}),e.jsx(t.Input,{id:"title",placeholder:"Enter visual title...",value:i,onChange:f=>x(f.target.value),disabled:l,onKeyDown:f=>{f.key==="Enter"&&!f.shiftKey&&(f.preventDefault(),N())}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{htmlFor:"description",children:"Description (optional)"}),e.jsx(t.Input,{id:"description",placeholder:"Enter visual description...",value:w,onChange:f=>r(f.target.value),disabled:l})]})]}),e.jsxs(t.DialogFooter,{children:[e.jsx(t.Button,{variant:"outline",onClick:()=>b(!1),disabled:l,children:"Cancel"}),e.jsx(t.Button,{onClick:N,disabled:!i.trim()||l,children:l?e.jsxs(e.Fragment,{children:[e.jsx(t.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Creating..."]}):"Create Visual"})]})]})})}function me({isOpen:s,onClose:m,className:p,onDashboardItemClick:l,variant:i="inline"}){var c,B;const x=t.useDashboardStore(D=>D.isDashboardEditing),[w,r]=h.useState(!1),[N,b]=h.useState(""),[f,d]=h.useState(!1),{currentUser:u,userContext:A}=t.useCurrentUserInfo(),R=((c=A==null?void 0:A.permissions)==null?void 0:c.canCreateDashboard)??!1,{onCreateSuccess:j}=t.useDashboardCreation({onDashboardSelect:l}),{selectVisual:S}=t.useManagementActions(),{handleEditLibraryVisual:v}=ne.useVisualUtils(),{createResource:E,isCreating:L,refetch:C}=t.useDashboardManagement(),{createResource:y,isCreating:O}=t.useVisualManagement(void 0,D=>{r(!1),D&&(S(D),v(D))}),T=i==="overlay",U=x?"New Visual":"New",P=x?"New Visual":"New Dashboard",a=x?"Search visuals...":"Search dashboards...",_=x?"Collapse visuals panel":"Collapse dashboard panel",F=((u==null?void 0:u.name)??"").trim(),V=((u==null?void 0:u.email)??"").trim(),z=F&&F.toLowerCase()!=="undefined"?F:V||"Current user",W=((B=z.charAt(0))==null?void 0:B.toUpperCase())||"?",X=V&&V.toLowerCase()!=="undefined"?V:"",Y=ie(m,{enabled:s&&T}),$=t.cn("flex h-full flex-col border-r border-border/60 bg-background",T?t.cn("absolute inset-y-0 left-0 z-[51] w-60 overflow-hidden shadow-lg transition-transform duration-300 ease-in-out",s?"translate-x-0":"pointer-events-none -translate-x-full"):"w-full max-w-[17rem] min-w-[11rem] overflow-hidden",p),J=D=>{},o=D=>{console.log("Editing dashboard:",D)},M=D=>{E(D,{onSuccess:H=>{r(!1),j(H,C)}})};return e.jsx(e.Fragment,{children:(!T||s)&&e.jsxs("div",{ref:Y,className:$,children:[e.jsx("div",{className:"border-b border-border/60 bg-background",children:f?e.jsxs("div",{className:"flex h-11 items-center gap-1 px-3",children:[e.jsx(t.Search,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("input",{autoFocus:!0,value:N,onChange:D=>b(D.target.value),onKeyDown:D=>{D.key==="Escape"&&(b(""),d(!1))},placeholder:a,className:"h-7 min-w-0 flex-1 bg-transparent text-[13px] text-foreground placeholder:text-muted-foreground focus:outline-none","aria-label":a}),e.jsx(t.Button,{size:"xs",variant:"ghost",className:"w-7 shrink-0 px-0 text-muted-foreground hover:text-foreground",onClick:()=>{b(""),d(!1)},"aria-label":"Close search",children:e.jsx(t.X,{className:"h-3.5 w-3.5"})})]}):e.jsxs("div",{className:"flex h-11 items-center justify-between gap-2 px-3",children:[e.jsx("h2",{className:"whitespace-nowrap text-[13px] font-medium text-foreground",children:x?"Visuals":"Dashboards"}),e.jsxs("div",{className:"flex items-center gap-0.5",children:[e.jsx(t.Button,{size:"xs",variant:"ghost",onClick:()=>d(!0),className:"w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":"Search",children:e.jsx(t.Search,{className:"h-3.5 w-3.5"})}),(x||R)&&e.jsxs(t.Button,{size:"xs",variant:"outline",onClick:()=>r(!0),"aria-label":P,children:[e.jsx(t.Plus,{className:"h-3.5 w-3.5"}),U]}),e.jsx(t.Button,{size:"xs",variant:"ghost",className:"w-7 px-0 text-muted-foreground hover:text-foreground",onClick:m,"aria-label":_,children:e.jsx(t.PanelLeft,{className:"h-3.5 w-3.5"})})]})]})}),e.jsx("div",{className:"flex flex-1 flex-col overflow-auto px-1.5 py-2",children:x?e.jsx(ce,{searchQuery:N}):e.jsx(xe,{searchQuery:N,onLoadDashboard:J,onEditDashboard:o,onDashboardItemClick:l})}),u&&e.jsx(t.TooltipProvider,{children:e.jsx("div",{className:"border-t border-border/60 px-3 py-2",children:e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:e.jsxs("div",{className:"flex cursor-default items-center gap-2",children:[e.jsx("div",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-muted text-[10px] font-medium text-muted-foreground",children:W}),e.jsx("span",{className:"truncate text-[12px] text-muted-foreground",children:z})]})}),e.jsx(t.TooltipContent,{side:"top",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("div",{className:"font-medium",children:z}),X&&e.jsx("div",{className:"text-[11px] opacity-80",children:X}),u.role&&e.jsxs("div",{className:"text-[11px] opacity-80",children:["Role: ",t.toTitleCase(u.role.replace(/_/g," "))]})]})})]})})}),x?e.jsx(pe,{open:w,onOpenChange:r,onSubmit:y,isCreating:O}):e.jsx(t.CreateDashboardDialog,{open:w,onOpenChange:r,onSubmit:M,isCreating:L})]})})}exports.ResourceManagementPanel=me;