import{bo as w,C as d,ce as N,bn as l,cn as R,co as k}from"./index-BGoV7aa6.js";const S=["can_edit","can_delete"],g=async(n,e,o)=>{const t=new URLSearchParams;return t.set("project",n),t.set("recursion","1"),w(t,o),N(t,e,S),fetch(`/1.0/networks?${t.toString()}`).then(d).then(a=>a.metadata.filter(s=>!["loopback","unknown"].includes(s.type)))},$=async(n,e,o)=>new Promise((t,a)=>{Promise.allSettled(e.map(async c=>g(n,o,c.server_name))).then(c=>{const s=[];for(let r=0;r<e.length;r++){const i=e[r].server_name,h=c[r];h.status==="rejected"&&a(k(h,i)),h.status==="fulfilled"&&h.value.forEach(m=>s.push({...m,memberName:i}))}t(s)}).catch(a)}),p=async(n,e,o,t)=>{const a=new URLSearchParams;return a.set("project",e),w(a,t),N(a,o,S),fetch(`/1.0/networks/${encodeURIComponent(n)}?${a.toString()}`).then(l).then(c=>c)},_=async(n,e,o,t)=>new Promise((a,c)=>{Promise.allSettled(o.map(async s=>p(n,e,t,s.server_name))).then(s=>{const r=[];for(let i=0;i<o.length;i++){const h=o[i].server_name,m=s[i];if(m.status==="rejected"&&c(k(m,h)),m.status==="fulfilled"){const f=s[i];r.push({...f.value,memberName:h})}}a(r)}).catch(c)}),L=async(n,e,o)=>{const t=new URLSearchParams;return t.set("project",e),w(t,o),fetch(`/1.0/networks/${encodeURIComponent(n)}/state?${t.toString()}`).then(d).then(a=>a.metadata)},T=async(n,e,o,t,a)=>new Promise((c,s)=>{Promise.allSettled(o.map(async r=>{const i={name:n.name,type:n.type,config:{parent:t==null?void 0:t[r.server_name],"bridge.external_interfaces":a==null?void 0:a[r.server_name]}};return y(i,e,r.server_name)})).then(r=>{var h,m;const i=(h=r.find(f=>f.status==="rejected"))==null?void 0:h.reason;if(i){s(i);return}(m=n.config)==null||delete m.parent,y(n,e).then(c).catch(s)}).catch(s)}),y=async(n,e,o)=>{const t=new URLSearchParams;return t.set("project",e),w(t,o),new Promise((a,c)=>{fetch(`/1.0/networks?${t.toString()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)}).then(d).then(a).catch(async s=>{s.message==="Failed to fetch"&&await p(n.name??"",e,!1,o)&&a(),c(s)})})},u=async(n,e,o)=>{const t=new URLSearchParams;return t.set("project",e),w(t,o),new Promise((a,c)=>{fetch(`/1.0/networks/${encodeURIComponent(n.name)}?${t.toString()}`,{method:"PUT",body:JSON.stringify(n),headers:{"Content-Type":"application/json","If-Match":n.etag??""}}).then(d).then(a).catch(async s=>{if(s.message==="Failed to fetch"){const r=await p(n.name??"",e,!1,o);R(n,r)&&a()}c(s)})})},O=async(n,e,o,t,a,c)=>new Promise((s,r)=>{Promise.allSettled(o.map(async i=>{const h=i.server_name,m={...c};t!=null&&t[h]&&(m.parent=t[h]),a!=null&&a[h]&&(m["bridge.external_interfaces"]=a[h]);const f={name:n.name,type:n.type,config:m};return u(f,e,h)})).then(i=>{var m;const h=(m=i.find(f=>f.status==="rejected"))==null?void 0:m.reason;if(h){r(h);return}u({...n,etag:""},e).then(s).catch(r)}).catch(r)}),v=async(n,e,o)=>{const t=new URLSearchParams;return t.set("project",o),new Promise((a,c)=>{fetch(`/1.0/networks/${encodeURIComponent(n)}?${t.toString()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e})}).then(d).then(a).catch(async s=>{s.message==="Failed to fetch"&&await p(e,o,!1)&&a(),c(s)})})},F=async(n,e)=>{const o=new URLSearchParams;return o.set("project",e),new Promise((t,a)=>{fetch(`/1.0/networks/${encodeURIComponent(n)}?${o.toString()}`,{method:"DELETE"}).then(d).then(t).catch(async c=>{c.message==="Failed to fetch"&&(await fetch(`/1.0/networks/${encodeURIComponent(n)}?project=${encodeURIComponent(e)}`)).status===404&&t(),a(c)})})},j=async n=>{const e=new URLSearchParams;return e.set("project",n),e.set("recursion","1"),fetch(`/1.0/network-allocations?${e.toString()}`).then(d).then(o=>o.metadata)};export{y as a,u as b,T as c,F as d,L as e,p as f,j as g,g as h,$ as i,_ as j,v as r,O as u};
