import{j as e,a9 as d,l as j,r as N,d as i,q as f,a4 as m,L as y}from"./index-BTX30BGB.js";import{B as b}from"./BaseLayout-C9qzVjMS.js";import{I as S,C as I}from"./CancelOperationBtn-BAFhVSPL.js";import{I as L}from"./ItemName-dyLHCvED.js";import{b as u,g as R}from"./operations-Bh89JbNy.js";import{N as w}from"./NotificationRow-BrFpgHY8.js";const F=({operation:s})=>{const n=u(s),a=R(s);if(!a)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(s.status==="Success"&&s.description==="Creating instance"||r.includes(s.description))&&n?e.jsx(S,{instance:{name:a,project:n}}):e.jsx(L,{item:{name:a}})},O=()=>{const{isFetching:s}=d(),n=j(),a=()=>{n.invalidateQueries({queryKey:[f.operations]})};return N.useEffect(a,[]),e.jsxs(i.ActionButton,{className:"u-no-margin--bottom has-icon",onClick:a,loading:s,children:[e.jsx(i.Icon,{name:"restart"}),e.jsx("span",{children:"Refresh"})]})},B=()=>{const s=i.useNotify(),{operations:n,isLoading:a,error:r}=d();r&&s.failure("Loading operations failed",r);const c=[{content:"Time",className:"time",sortKey:"created_at"},{content:"Action",className:"action",sortKey:"action"},{content:"Info",className:"info"},{content:"Status",className:"status",sortKey:"status"},{"aria-label":"Actions",className:"cancel u-align--right"}],g=t=>({Cancelled:"status-failed-small",Failure:"status-failed-small",Running:"status-in-progress-small",Success:"status-succeeded-small"})[t],h=n.map(t=>{const o=u(t);return{columns:[{content:e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:["Initiated: ",m(t.created_at)]}),e.jsxs("div",{className:"u-text--muted",children:["Last update: ",m(t.updated_at)]})]}),role:"rowheader","aria-label":"Time",className:"time"},{content:e.jsxs(e.Fragment,{children:[e.jsx("div",{children:t.description}),e.jsx("div",{className:"u-truncate u-text--muted",children:e.jsx(F,{operation:t})}),e.jsxs("div",{className:"u-text--muted u-truncate",title:o,children:["Project: ",o]})]}),role:"rowheader","aria-label":"Action",className:"action"},{content:e.jsxs(e.Fragment,{children:[e.jsx("div",{children:t.err}),Object.entries(t.metadata??{}).map(([x,l],p)=>e.jsxs("span",{title:JSON.stringify(l),children:[x,": ",JSON.stringify(l)]},p))]}),role:"rowheader","aria-label":"Info",className:"info"},{content:e.jsxs(e.Fragment,{children:[e.jsx(i.Icon,{name:g(t.status),className:"status-icon"}),t.status]}),role:"rowheader","aria-label":"Status",className:"status"},{content:e.jsx(I,{operation:t}),role:"rowheader",className:"u-align--right cancel","aria-label":"Actions"}],sortData:{created_at:t.created_at,action:t.description,status:t.status}}});return e.jsx(e.Fragment,{children:e.jsxs(b,{title:"Ongoing operations",controls:e.jsx(O,{}),children:[e.jsx(w,{}),e.jsxs(i.Row,{children:[n.length>0&&e.jsx(i.MainTable,{headers:c,rows:h,paginate:30,responsive:!0,sortable:!0,className:"operation-list",emptyStateMsg:a?e.jsx(y,{text:"Loading operations..."}):"No data to display"}),!a&&n.length===0&&e.jsx(i.EmptyState,{className:"empty-state",image:e.jsx(i.Icon,{name:"status",className:"empty-state-icon"}),title:"No operations found",children:e.jsx("p",{children:"There are no ongoing operations."})})]})]})})};export{B as default};
