import{bI as d,J as p,j as e,R,l as I,aO as x,h as O,w as T,r as j,d as t,s as v,q as F,bJ as g,aq as h}from"./index-lOezWVmi.js";import{C as k}from"./CancelOperationBtn-CJq64G7m.js";import{N as B}from"./NotificationRow-DdxAfFhk.js";import{u as q}from"./useSortTableData-DWeqi6jP.js";import{P as o}from"./PageHeader-DVTHSBni.js";const A=({operation:a})=>{const i=d(a),n=p(a);if(!n)return null;const r=["Restarting instance","Starting instance","Stopping instance","Unfreezing instance","Freezing instance","Snapshotting instance","Restoring snapshot","Deleting snapshot","Updating snapshot","Updating instance","Renaming instance","Executing command","Showing console"];return(a.status==="Success"&&a.description==="Creating instance"||r.includes(a.description))&&i?e.jsx(R,{type:"instance",value:n,to:`/ui/project/${encodeURIComponent(i)}/instance/${encodeURIComponent(n)}`}):e.jsx("div",{className:"u-truncate u-text--muted",children:e.jsx(I,{type:"instance",value:n})})},E=()=>{const{isFetching:a}=x(),i=O(),n=T(),r=()=>{i.invalidateQueries({queryKey:[F.operations]})};return j.useEffect(r,[]),e.jsxs(t.ActionButton,{className:v("u-no-margin--bottom",{"has-icon":!n}),onClick:r,loading:a,disabled:a,children:[!n&&e.jsx(t.Icon,{name:"restart"}),e.jsx("span",{children:"Refresh"})]})},J=()=>{const a=t.useNotify(),{operations:i,isLoading:n,error:r}=x(),[l,N]=j.useState("");r&&a.failure("Loading operations failed",r);const f=[{content:"Time",className:"time",sortKey:"created_at"},{content:"Action",className:"action",sortKey:"action"},{content:"Info",className:"info"},{content:"Status",className:"status status-header",sortKey:"status"},{"aria-label":"Actions",className:"cancel u-align--right"}],b=s=>({Cancelled:"status-failed-small",Failure:"status-failed-small",Running:"status-in-progress-small",Success:"status-succeeded-small"})[s],u=i.filter(s=>{const c=l.toLowerCase();return s.description.toLowerCase().includes(c)||d(s).toLowerCase().includes(c)||s.status.toLowerCase().includes(c)||p(s).toLowerCase().includes(c)}),S=u.map(s=>{const c=d(s);return{key:s.id,columns:[{content:e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"date-pair",children:["Initiated:"," ",g(h(s.created_at))]}),e.jsxs("div",{className:"date-pair u-text--muted",children:["Last update:"," ",g(h(s.updated_at))]})]}),role:"cell","aria-label":"Time",className:"time"},{content:e.jsxs(e.Fragment,{children:[e.jsx("div",{children:s.description}),e.jsx(A,{operation:s}),e.jsxs("div",{className:"u-text--muted u-truncate",title:c,children:["Project: ",c]})]}),role:"rowheader","aria-label":"Action",className:"action"},{content:e.jsxs(e.Fragment,{children:[s.err&&e.jsx("div",{children:s.err}),Object.entries(s.metadata??{}).map(([w,m],L)=>e.jsxs("span",{title:JSON.stringify(m),children:[w,": ",JSON.stringify(m)]},L))]}),role:"cell","aria-label":"Info",className:"info"},{content:e.jsxs(e.Fragment,{children:[e.jsx(t.Icon,{name:b(s.status),className:"status-icon"}),s.status]}),role:"cell","aria-label":"Status",className:"status"},{content:e.jsx(k,{operation:s}),role:"cell",className:"u-align--right cancel","aria-label":"Actions"}],sortData:{created_at:s.created_at,action:s.description,status:s.status}}}),{rows:y,updateSort:C}=q({rows:S});return e.jsx(e.Fragment,{children:e.jsxs(t.CustomLayout,{mainClassName:"operation-list",contentClassName:"u-no-padding--bottom",header:e.jsxs(o,{children:[e.jsxs(o.Left,{children:[e.jsx(o.Title,{children:"Ongoing operations"}),i.length>0&&e.jsx(o.Search,{children:e.jsx(t.SearchBox,{className:"search-box margin-right u-no-margin--bottom",name:"search-operations",onChange:N,placeholder:"Search",value:l,"aria-label":"Search"})})]}),e.jsx(o.BaseActions,{children:e.jsx(E,{})})]}),children:[e.jsx(B,{}),e.jsxs(t.Row,{children:[i.length>0&&e.jsx(t.ScrollableTable,{dependencies:[u,a.notification],tableId:"operation-table",belowIds:["status-bar"],children:e.jsx(t.TablePagination,{data:y,id:"pagination",itemName:"operation",className:"u-no-margin--top","aria-label":"Table pagination control",children:e.jsx(t.MainTable,{id:"operation-table",headers:f,sortable:!0,responsive:!0,onUpdateSort:C,emptyStateMsg:n?e.jsx(t.Spinner,{className:"u-loader",text:"Loading operations..."}):"No matching operations found"})})}),!n&&i.length===0&&e.jsx(t.EmptyState,{className:"empty-state",image:e.jsx(t.Icon,{name:"status",className:"empty-state-icon"}),title:"No operations found",children:e.jsx("p",{children:"There are no ongoing operations."})})]})]})})};export{J as default};
