import{v as i,d as l,r as m,i as f,j as c,q as u}from"./index-3c1b2661.js";const h=e=>{var n,a,s;const t=(r,o)=>new Date(o.created_at).getTime()-new Date(r.created_at).getTime();(n=e.failure)==null||n.sort(t),(a=e.success)==null||a.sort(t),(s=e.running)==null||s.sort(t)},y=e=>new Promise((t,n)=>{fetch(`/1.0/operations?project=${e}&recursion=1`).then(i).then(a=>(h(a.metadata),t(a.metadata))).catch(n)}),g=()=>new Promise((e,t)=>{fetch("/1.0/operations?all-projects=true&recursion=1").then(i).then(n=>(h(n.metadata),e(n.metadata))).catch(t)}),p=e=>new Promise((t,n)=>{fetch(`/1.0/operations/${e}`,{method:"DELETE"}).then(i).then(t).catch(n)}),w=({operation:e,project:t})=>{const n=l.useNotify(),[a,s]=m.useState(!1),r=f(),o=()=>{s(!0),p(e.id).then(()=>{n.success("Operation cancelled")}).catch(d=>{n.failure("Operation cancellation failed",d)}).finally(()=>{s(!1),r.invalidateQueries({queryKey:t?[u.operations,t]:[u.operations]})})};return e.status!=="Running"?null:c.jsx(l.ConfirmationButton,{onHoverText:e.may_cancel?"Cancel operation":"Cannot cancel operation at this stage",className:"u-no-margin--bottom",loading:a,disabled:!e.may_cancel,confirmationModalProps:{title:"Confirm cancel",children:c.jsx("p",{children:"This will cancel the operation."}),confirmButtonLabel:"Cancel operation",onConfirm:o,cancelButtonLabel:"Go back"},shiftClickEnabled:!0,showShiftClickHint:!0,children:c.jsx("span",{children:"Cancel"})})};export{w as C,g as a,y as f};
