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