import{d4 as d,ad as p,j as e,ab as I,t as R,bv as x,n as T,U as v,r as j,d as t,K as O,q as F,d5 as g,b1 as h,e as B}from"./index-C88DWJny.js";import{C as k}from"./CancelOperationBtn-Cvp7jiFx.js";import{u as A}from"./useSortTableData-Gi73OjgT.js";import{P as o}from"./PageHeader-6_Og6mu3.js";const E=({operation:a})=>{const n=d(a),i=p(a);if(!i)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))&&n?e.jsx(I,{instanceName:i,projectName:n}):e.jsx("div",{className:"u-truncate u-text--muted",children:e.jsx(R,{type:"instance",value:i})})},K=()=>{const{isFetching:a}=x(),n=T(),i=v(),r=()=>{n.invalidateQueries({queryKey:[F.operations]})};return j.useEffect(r,[]),e.jsxs(t.ActionButton,{className:O("u-no-margin--bottom",{"has-icon":!i}),onClick:r,loading:a,disabled:a,children:[!i&&e.jsx(t.Icon,{name:"restart"}),e.jsx("span",{children:"Refresh"})]})},D=()=>{const a=t.useNotify(),{operations:n,isLoading:i,error:r}=x(),[l,N]=j.useState("");r&&a.failure("Loading operations failed",r);const b=[{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"}],f=s=>({Cancelled:"status-failed-small",Failure:"status-failed-small",Running:"status-in-progress-small",Success:"status-succeeded-small"})[s],u=n.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(E,{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:f(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}=A({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"}),n.length>0&&e.jsx(o.Search,{children:e.jsx(t.SearchBox,{className:"search-box margin-right--large u-no-margin--bottom",name:"search-operations",onChange:N,placeholder:"Search",value:l,"aria-label":"Search"})})]}),e.jsx(o.BaseActions,{children:e.jsx(K,{})})]}),children:[e.jsx(B,{}),e.jsxs(t.Row,{children:[n.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:b,sortable:!0,responsive:!0,onUpdateSort:C,emptyStateMsg:i?e.jsx(t.Spinner,{className:"u-loader",text:"Loading operations..."}):"No matching operations found"})})}),!i&&n.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{D as default};
