import{v as c,bf as w,bg as p}from"./index-3c1b2661.js";const y=e=>new Promise((t,n)=>{fetch(`/1.0/networks?project=${e}&recursion=1`).then(c).then(s=>t(s.metadata)).catch(n)}),i=(e,t)=>new Promise((n,s)=>{fetch(`/1.0/networks/${e}?project=${t}`).then(p).then(a=>n(a)).catch(s)}),$=(e,t)=>new Promise((n,s)=>{fetch(`/1.0/networks/${e}/state?project=${t}`).then(c).then(a=>n(a.metadata)).catch(s)}),N=(e,t,n)=>new Promise((s,a)=>{const o={name:e.name,description:e.description,type:e.type};Promise.allSettled(n.map(async r=>{await m(o,t,r.server_name)})).then(r=>{var f;const h=(f=r.find(d=>d.status==="rejected"))==null?void 0:f.reason;if(h){a(h);return}m(e,t).then(s).catch(a)}).catch(a)}),m=(e,t,n)=>new Promise((s,a)=>{const o=n?`&target=${n}`:"";fetch(`/1.0/networks?project=${t}${o}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(c).then(r=>s(r)).catch(async r=>{if(r.message==="Failed to fetch"){const h=await i(e.name??"",t);h&&s(h)}a(r)})}),g=(e,t)=>new Promise((n,s)=>{fetch(`/1.0/networks/${e.name??""}?project=${t}`,{method:"PUT",body:JSON.stringify(e),headers:{"Content-Type":"application/json","If-Match":e.etag??"invalid-etag"}}).then(c).then(a=>n(a)).catch(async a=>{if(a.message==="Failed to fetch"){const o=await i(e.name??"",t);w(e,o)&&n(o)}s(a)})}),P=(e,t,n)=>new Promise((s,a)=>{fetch(`/1.0/networks/${e}?project=${n}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})}).then(c).then(s).catch(async o=>{if(o.message==="Failed to fetch"){const r=await i(t,n);r&&s(r)}a(o)})}),k=(e,t)=>new Promise((n,s)=>{fetch(`/1.0/networks/${e}?project=${t}`,{method:"DELETE"}).then(c).then(n).catch(async a=>{a.message==="Failed to fetch"&&(await fetch(`/1.0/networks/${e}?project=${t}`)).status===404&&n(),s(a)})});export{m as a,$ as b,N as c,k as d,i as e,y as f,P as r,g as u};
