import{d as w,g,y as h,o as p,e as I,w as K,A as u,f as d,b as x,W as b,u as f,E as O,aw as W,i as R,j as q,c as M,F as z,l as L,k as P}from"./index-D86EVCbM.js";import{F as j,j as A,at as B,D as T,k as Z,E as G,W as H,A as N}from"./ReferenceContentLoader-jQeEHBuo.js";import"./navigation-BK47qCFk.js";import{r as J}from"./EmptyState.vue-D5A1viAm.js";import{m as Q,g as X}from"./SidebarButton.vue-B1NBOg1I.js";import{h as Y,b as y,_ as ee,a as ae}from"./CommandActionInput.vue-jU8qZpBe.js";import{u as oe}from"./ViewLayout.vue-k2dgFArt.js";import{x as le}from"./ViewLayoutContent.vue-BLa-FzmC.js";import{_ as se}from"./ViewLayoutSection.vue-Cvh5w_-L.js";import{q as te}from"./Form.vue-Cl2WzsME.js";import"./__vite-browser-external-D7Ct-6yo.js";import"./ScalarAsciiArt.vue-Bpsm0a0f.js";import"./ScalarHotkey.vue-D1cXZ33d.js";import"./DeleteSidebarListElement.vue-DU9GbhpY.js";const ie=w({__name:"CookieForm",setup(C){const{activeCookieId:m}=j(),{cookies:v,cookieMutators:k}=A(),a=[{label:"Name",key:"name",placeholder:"session_id"},{label:"Value",key:"value",placeholder:"my-cookie-session-id"},{label:"Domain",key:"domain",placeholder:"example.com"}],c=g(()=>v[m.value]||B.parse({name:"",value:"",domain:"",path:""})),_=(i,e)=>{k.edit(m.value,i,e)};return(i,e)=>(p(),h(te,{data:c.value,onUpdate:_,options:a},null,8,["data"]))}}),ue={class:"flex h-8 items-start gap-2 text-sm"},ne={class:"flex h-8 items-start gap-2 text-sm"},de={class:"flex h-8 items-start gap-2 text-sm"},me=w({__name:"CookieModal",props:{state:{}},emits:["cancel","submit"],setup(C,{emit:m}){const v=C,k=m,a=I({name:"",value:"",domain:""}),{toast:c}=Z(),_=()=>{if(!a.value.name||!a.value.value){c("Please fill in all fields before adding a cookie.","error");return}k("submit",a.value),v.state.hide()};return K(()=>v.state.open,i=>{i&&(a.value={name:"",value:"",domain:""})}),(i,e)=>(p(),h(f(T),{size:"xs",state:i.state,title:"Add Cookie"},{default:u(()=>[d(Y,{disabled:!a.value.name||!a.value.value,onCancel:e[3]||(e[3]=n=>k("cancel")),onSubmit:_},{submit:u(()=>e[7]||(e[7]=[b("Add Cookie")])),default:u(()=>[x("div",ue,[e[4]||(e[4]=b(" Name: ")),d(y,{modelValue:a.value.name,"onUpdate:modelValue":e[0]||(e[0]=n=>a.value.name=n),autofocus:"",class:"!p-0",placeholder:"session_id"},null,8,["modelValue"])]),x("div",ne,[e[5]||(e[5]=b(" Value: ")),d(y,{modelValue:a.value.value,"onUpdate:modelValue":e[1]||(e[1]=n=>a.value.value=n),autofocus:"",class:"!p-0",placeholder:"my-cookie-session-id"},null,8,["modelValue"])]),x("div",de,[e[6]||(e[6]=b(" Domain: ")),d(y,{modelValue:a.value.domain,"onUpdate:modelValue":e[2]||(e[2]=n=>a.value.domain=n),autofocus:"",class:"!p-0",placeholder:"example.com"},null,8,["modelValue"])])]),_:1},8,["disabled"])]),_:1},8,["state"]))}}),ce=G(me,[["__scopeId","data-v-694018d6"]]),re={class:"flex-1"},pe={class:"relative mb-[.5px] last:mb-0"},Ne=w({__name:"Cookies",setup(C){const{cookies:m,cookieMutators:v,events:k,workspaceMutators:a}=A(),{activeWorkspace:c,activeCookieId:_}=j(),i=O(),e=W(),n=H(),D=s=>{var l,o;const t=B.parse({name:s.name,value:s.value,domain:s.domain,path:"/"});v.add(t),a.edit((l=c.value)==null?void 0:l.uid,"cookies",[...((o=c.value)==null?void 0:o.cookies)??[],t.uid]),i.push({name:"cookies",params:{cookies:t.uid}})},U=s=>{var l,o;v.delete(s),a.edit((l=c.value)==null?void 0:l.uid,"cookies",[...(((o=c.value)==null?void 0:o.cookies)??[]).filter(r=>r!==s)]);const t=Object.values(m).filter(r=>r.uid!==s);if(t.length>0){const r=t[t.length-1];r&&i.push(r.uid)}else i.push({name:"cookies",params:{[N.Cookies]:"default"}})},V=()=>{n.show()},$=s=>{s!=null&&s.createNew&&e.name==="cookies"&&V()},E=(s,l)=>{var o;const t={name:"cookies",params:{workspace:((o=c.value)==null?void 0:o.uid)??"default",cookies:l}};if(s.metaKey){const r=i.resolve(t).href;window.open(r,"_blank");return}i.push(t)};R(()=>k.hotKeys.on($)),q(()=>k.hotKeys.off($));const F=g(()=>m[_.value]),S=g(()=>Object.keys(m).length>0&&F.value);return(s,l)=>(p(),h(oe,null,{default:u(()=>[d(f(Q),{title:"Cookies"},{content:u(()=>[x("div",re,[d(ee,null,{default:u(()=>[(p(!0),M(z,null,L(Object.values(f(m)),o=>(p(),M("li",{key:o.uid,class:"gap-1/2 flex flex-col"},[x("div",pe,[(p(),h(ae,{key:o.uid,class:"text-xs",isDeletable:"",to:{name:"cookies",params:{[f(N).Cookies]:o.uid}},type:"cookies",variable:{name:o.name,uid:o.uid},warningMessage:"Are you sure you want to delete this cookie?",onClick:P(t=>E(t,o.uid),["prevent"]),onDelete:t=>U(o.uid)},null,8,["to","variable","onClick","onDelete"]))])]))),128))]),_:1})])]),button:u(()=>[d(X,{click:V,hotkey:"N"},{title:u(()=>l[1]||(l[1]=[b(" Add Cookie ")])),_:1})]),_:1}),d(le,{class:"flex-1"},{default:u(()=>[S.value?(p(),h(se,{key:0,class:"*:border-b-0"},{title:u(()=>l[2]||(l[2]=[b("Edit Cookie")])),default:u(()=>[d(ie)]),_:1})):(p(),h(J,{key:1}))]),_:1}),d(ce,{state:f(n),onCancel:l[0]||(l[0]=o=>f(n).hide()),onSubmit:D},null,8,["state"])]),_:1}))}});export{Ne as default};
