import{r as g,o as v,y as r,z as o,B as x,P as q,R as k,_ as B,J as i,D as l,U as c,K as d,S as w,L as m,ab as S,a9 as V}from"./EchoChannel-Bg1-kez_.js";const D=["action"],U=["value"],L={class:"text-3xl col-span-full"},M=["for"],R=["id","name","onUpdate:modelValue"],j={value:"",selected:"",disabled:""},C=["value"],N=["type","id","name","onUpdate:modelValue","placeholder"],X={class:"col-span-full flex justify-end"},P={__name:"DownloadButton",props:{url:{type:String,required:!0}},setup(h){const y=h,t=g({open:!1,url:"",title:"",csrf:"",submitButton:"",fields:[]});v(()=>{_()});const _=async()=>{try{const s=await(await fetch(y.url,{headers:{"X-Requested-With":"XMLHttpRequest"}})).json();t.url=s.url,t.title=s.title,t.csrf=s.csrf,t.submitButton=s.submitButton,t.fields=s.fields}catch(p){console.error(p)}},f=async function(p){const s=t.fields.reduce((a,e)=>{const{name:u,value:n}=e;return{...a,[u]:n}},{});try{await(await fetch(t.url,{method:"POST",headers:{"Content-Type":"application/json","X-Requested-With":"XMLHttpRequest"},body:JSON.stringify(s)})).json(),t.open=!1}catch(a){console.error("Error submitting form:",a)}},b=function(){t.open=!0};return(p,s)=>(l(),r(i,null,[o("button",{onClick:b,class:"text-base py-2 px-4 bg-qorus-purple font-normal text-qorus-grey-light hover:brightness-90"},[x(p.$slots,"default")]),q(B,{popup:t.open,"onUpdate:popup":s[0]||(s[0]=a=>t.open=a)},{default:k(a=>[o("form",{class:"grid grid-cols-2 gap-8 content-center",action:t.url,method:"post"},[o("input",{type:"hidden",name:"_token",value:t.csrf},null,8,U),o("h2",L,c(t.title),1),(l(!0),r(i,null,d(t.fields,(e,u)=>(l(),r("div",{key:u,class:"flex flex-col col-span-full sm:col-span-1"},[o("label",{for:e.name+"_"+u,class:"uppercase text-qorus-grey-dark tracking-widest text-xs mb-2"},[w(c(e.label)+" ",1),s[1]||(s[1]=o("abbr",{class:"no-underline",title:"required"},"*",-1))],8,M),e.type==="select"?m((l(),r("select",{key:0,class:"h-full font-light border py-2 px-4",id:e.name+"_"+u,name:e.name,"onUpdate:modelValue":n=>e.value=n,required:""},[o("option",j,c(e.defaultOptionLabel),1),(l(!0),r(i,null,d(e.options,n=>(l(),r("option",{value:n.value},c(n.name),9,C))),256))],8,R)),[[S,e.value]]):m((l(),r("input",{key:1,class:"font-light border py-2 px-4",type:e.type,id:e.name+"_"+u,name:e.name,"onUpdate:modelValue":n=>e.value=n,required:"",placeholder:e.placeholder},null,8,N)),[[V,e.value]])]))),128)),o("div",X,[o("button",{onClick:f,type:"submit",class:"bg-qorus-purple text-qorus-grey-light hover:brightness-90 py-2 px-4"},c(t.submitButton),1)])],8,D)]),_:1},8,["popup"])],64))}};export{P as default};