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