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