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