import{F as _,j as A,aa as $,af as E,W as z,ag as I,$ as U,q as g,n as W,x as q,D as B}from"./ReferenceContentLoader-jQeEHBuo.js";import"./navigation-BK47qCFk.js";import{w as F}from"./DeleteSidebarListElement.vue-DU9GbhpY.js";import{q as P}from"./Form.vue-Cl2WzsME.js";import{d as j,g as k,w as R,c as f,o,a as w,F as D,f as i,y as C,e as V,b as c,x as L,l as M,u as t,t as O,A as v}from"./index-D86EVCbM.js";import"./__vite-browser-external-D7Ct-6yo.js";import"./ViewLayoutSection.vue-Cvh5w_-L.js";const T={class:"bg-b-1 divide-0.5 flex w-full flex-col divide-y text-sm"},G=j({__name:"CollectionServerForm",props:{collectionId:{default:""},serverUid:{default:""}},setup(S){const r=S,{activeWorkspaceCollections:n}=_(),{servers:b,serverMutators:p}=A(),d=[{label:"URL",key:"url",placeholder:"https://void.scalar.com",type:"text"},{label:"Description",key:"description",placeholder:"Production",type:"text"}],a=k(()=>{const s=n.value.find(e=>e.uid===r.collectionId);return b[s&&typeof r.serverUid=="string"&&r.serverUid==="default"?s.servers[0]??"":s?.servers.find(e=>e===r.serverUid)??""]}),x=k(()=>{var s,e;return(s=a.value)!=null&&s.url?((e=a.value.url.match($.PATH))==null?void 0:e.map(l=>l.slice(1,-1)))??[]:[]});R(x,s=>{if(!a.value)return;const e=a.value.variables?{...a.value.variables}:{};Object.keys(e).forEach(l=>{s.includes(l)||delete e[l]}),s.forEach(l=>{e[l]||(e[l]={default:""})}),p.edit(a.value.uid,"variables",e)},{immediate:!0});const h=(s,e)=>{!n.value||!a.value||p.edit(a.value.uid,s,e)},y=(s,e)=>{if(!a.value)return;const l=a.value.variables||{};l[s]={...l[s],default:e},p.edit(a.value.uid,"variables",l)};return(s,e)=>(o(),f("div",T,[a.value?(o(),f(D,{key:0},[i(P,{data:a.value,onUpdate:h,options:d},null,8,["data"]),a.value.variables?(o(),C(E,{key:0,variables:a.value.variables,"onUpdate:variable":y},null,8,["variables"])):w("",!0)],64)):w("",!0)]))}}),H={class:"flex h-full w-full flex-col gap-12 px-1.5 pt-8"},Y={class:"flex flex-col gap-4"},X={class:"bg-b-2 overflow-hidden rounded-lg border"},J={class:"flex items-center justify-between py-1 pl-3 pr-1 text-sm"},K={key:1},Q={class:"text-c-3 flex h-full items-center justify-center rounded-lg border p-4"},oe=j({__name:"CollectionServers",setup(S){const{activeCollection:r}=_(),{servers:n,events:b,serverMutators:p}=A(),d=z(),a=V(null),x=k(()=>{var e;return!n||!((e=r.value)!=null&&e.servers)?[]:Object.values(n).filter(l=>{var m;return(m=r.value)==null?void 0:m.servers.includes(l.uid)})}),h=()=>b.commandPalette.emit({commandName:"Add Server"}),y=()=>{var e;!((e=r.value)!=null&&e.uid)||!a.value||(p.delete(a.value,r.value.uid),d.hide())},s=e=>{a.value=e,d.show()};return(e,l)=>{var m;return o(),f("div",H,[c("div",Y,[l[3]||(l[3]=L('<div class="flex items-start justify-between gap-2"><div class="flex flex-col"><div class="flex h-8 items-center"><h3 class="font-bold">Servers</h3></div><p class="text-sm"> Add different base URLs for your API. You can use <code class="font-code text-c-2">{variables}</code> for dynamic parts. </p></div></div>',1)),(o(!0),f(D,null,M(x.value,(u,N)=>(o(),f("div",{key:u.uid},[c("div",X,[c("div",J,[u.description?(o(),C(t(I),{key:0,value:u.description},null,8,["value"])):(o(),f("span",K,"Server "+O(N+1),1)),i(t(q),{placement:"bottom-end"},{items:v(()=>[i(t(W),{class:"flex gap-2 font-normal",onClick:Z=>s(u.uid)},{default:v(()=>[i(t(g),{class:"inline-flex",icon:"Delete",size:"sm",thickness:"1.5"}),l[1]||(l[1]=c("span",null,"Delete",-1))]),_:2},1032,["onClick"])]),default:v(()=>[i(t(U),{class:"hover:bg-b-3 h-full max-h-8 gap-1 p-1 text-xs",variant:"ghost"},{default:v(()=>[i(t(g),{class:"text-c-3",icon:"Ellipses",size:"md"})]),_:1})]),_:2},1024)]),t(r)?(o(),C(G,{key:0,collectionId:t(r).uid,serverUid:u.uid},null,8,["collectionId","serverUid"])):w("",!0)])]))),128)),c("div",Q,[i(t(U),{class:"hover:bg-b-2 hover:text-c-1 flex items-center gap-2",size:"sm",variant:"ghost",onClick:h},{default:v(()=>[i(t(g),{class:"inline-flex",icon:"Add",size:"sm",thickness:"1.5"}),l[2]||(l[2]=c("span",null,"Add Server",-1))]),_:1})])]),i(t(B),{size:"xxs",state:t(d),title:`Delete ${a.value?(m=t(n)[a.value])==null?void 0:m.url:"Server"}`},{default:v(()=>[i(F,{variableName:"Server",warningMessage:"Are you sure you want to delete this server? This action cannot be undone.",onClose:l[0]||(l[0]=u=>t(d).hide()),onDelete:y})]),_:1},8,["state","title"])])}}});export{oe as default};
