import{v as r,a5 as g,ad as d,ae as m,af as u,aL as f,aM as $,aN as P}from"./index-CzUo07dn.js";const I=(e,n,t=2)=>new Promise((s,c)=>{fetch(`/1.0/instances/${e}?project=${n}&recursion=${t}`).then(g).then(a=>s(a)).catch(c)}),y=(e,n)=>new Promise((t,s)=>{let c=`/1.0/instances?project=${e}&recursion=2`;n&&(c+=`&filter=${n}`),fetch(c).then(r).then(a=>t(a.metadata)).catch(s)}),S=(e,n,t)=>new Promise((s,c)=>{fetch(`/1.0/instances?project=${n}&target=${t??""}`,{method:"POST",body:e}).then(r).then(s).catch(c)}),O=(e,n)=>new Promise((t,s)=>{fetch(`/1.0/instances/${e.name}?project=${n}`,{method:"PUT",body:JSON.stringify(e),headers:{"If-Match":e.etag??"invalid-etag"}}).then(r).then(t).catch(s)}),T=(e,n,t)=>new Promise((s,c)=>{fetch(`/1.0/instances/${e}?project=${t}`,{method:"POST",body:JSON.stringify({name:n})}).then(r).then(s).catch(c)}),b=(e,n,t)=>{let s=`/1.0/instances/${e.name}?project=${e.project}`;return n&&(s+=`&target=${n}`),new Promise((c,a)=>{fetch(s,{method:"POST",body:JSON.stringify({migration:!0,live:e.type==="virtual-machine"&&e.status==="Running",pool:t})}).then(r).then(c).catch(a)})},E=e=>i(e.name,e.project,"start"),N=(e,n)=>i(e.name,e.project,"stop",n),k=e=>i(e.name,e.project,"freeze"),v=e=>i(e.name,e.project,"unfreeze"),J=(e,n)=>i(e.name,e.project,"restart",n),i=(e,n,t,s)=>new Promise((c,a)=>{fetch(`/1.0/instances/${e}/state?project=${n}`,{method:"PUT",body:JSON.stringify({action:t,force:s})}).then(r).then(c).catch(a)}),R=(e,n,t)=>{const s=[];return new Promise(c=>{Promise.allSettled(e.map(async({name:a,project:h,action:p})=>await i(a,h,p,n).then(o=>{t.set(o.metadata.id,()=>d(s),l=>m(s,l),()=>u(s,e.length,c))}).catch(o=>{m(s,o instanceof Error?o.message:""),u(s,e.length,c)})))})},w=e=>new Promise((n,t)=>{fetch(`/1.0/instances/${e.name}?project=${e.project}`,{method:"DELETE"}).then(r).then(n).catch(t)}),x=(e,n)=>{const t=[];return new Promise(s=>{Promise.allSettled(e.map(async c=>await w(c).then(a=>{n.set(a.metadata.id,()=>d(t),h=>m(t,h),()=>u(t,e.length,s))}).catch(a=>{m(t,a instanceof Error?a.message:""),u(t,e.length,s)})))})},z=(e,n,t)=>new Promise((s,c)=>{fetch(`/1.0/instances/${e}/exec?project=${n}&wait=10`,{method:"POST",body:JSON.stringify({command:[t.command],"wait-for-websocket":!0,environment:t.environment.reduce((a,h)=>({...a,[h.key]:h.value}),{}),interactive:!0,group:t.group,user:t.user})}).then(r).then(a=>s(a)).catch(c)}),L=(e,n)=>new Promise((t,s)=>{fetch(`/1.0/instances/${e}/console?project=${n}&wait=10`,{method:"POST",body:JSON.stringify({type:"vga",force:!0,width:0,height:0})}).then(r).then(c=>t(c)).catch(s)}),B=(e,n)=>new Promise((t,s)=>{fetch(`/1.0/instances/${e}/console?project=${n}&wait=10`,{method:"POST",body:JSON.stringify({"wait-for-websocket":!0,type:"console",force:!0})}).then(r).then(c=>t(c)).catch(s)}),U=(e,n)=>new Promise((t,s)=>{fetch(`/1.0/instances/${e}/console?project=${n}`,{method:"GET"}).then(f).then(c=>t(c)).catch(s)}),_=(e,n)=>new Promise((t,s)=>{fetch(`/1.0/instances/${e}/logs?project=${n}`,{method:"GET"}).then(r).then(c=>t(c.metadata)).catch(s)}),C=(e,n,t)=>new Promise((s,c)=>{fetch(`/1.0/instances/${e}/logs/${t}?project=${n}`,{method:"GET"}).then(f).then(a=>s(a)).catch(c)}),F=(e,n,t,s,c,a)=>new Promise((h,p)=>{P.post(`/1.0/instances?project=${t}`,e,{headers:{"Content-Type":"application/octet-stream","X-Incus-name":n,"X-Incus-pool":s},onUploadProgress:o=>{c({percentage:o.progress?Math.floor(o.progress*100):0,loaded:o.loaded,total:o.total})},signal:a.signal}).then(o=>o.data).then(h).catch(p)}),G=(e,n,t,s)=>new Promise((c,a)=>{fetch(`/1.0/instances/${e}/backups?project=${n}`,{method:"POST",body:JSON.stringify({compression_algorithm:"gzip",expires_at:t,instance_only:!1,name:s,optimized_storage:!0})}).then(r).then(h=>c(h)).catch(a)}),M=e=>new Promise((n,t)=>{fetch(`/1.0/instances/${e.name}/console?project=${e.project}&type=vga`).then($).then(s=>n(URL.createObjectURL(s))).catch(t)});export{z as a,y as b,S as c,O as d,L as e,M as f,U as g,B as h,C as i,_ as j,w as k,G as l,I as m,R as n,x as o,v as p,N as q,T as r,E as s,k as t,F as u,J as v,b as w};
