import{aa as b,r as c,ak as C,o as h,g as S,K as T,j as V,u as v,c as $,h as w,i as D,ao as j}from"./app-SC54XQDl.js";import{u as I}from"./app-Ba7ZqSpq.js";const P=["value"],x={__name:"CSRFToken",emits:["update:modelValue"],setup(y,{emit:m}){const p=b("$Tea"),t=c(""),r=c(),u=m,i=function(){p.action("/csrf/token").get().success(function(s){t.value=s.data.token,u("update:modelValue",t.value)})};return C(()=>{i(),r.value.form.addEventListener("submit",function(){i()}),setInterval(function(){i()},10*60*1e3)}),(s,l)=>(h(),S("input",{type:"hidden",name:"csrfToken",value:t.value,ref_key:"tokenInputRe",ref:r},null,8,P))}},E={__name:"PostForm",props:["action","data","method","timeout","refresh","onSuccess","onFail","onProgress","disableCSRF"],emits:["before","progress","success","fail","error","done"],setup(y,{expose:m,emit:p}){const t=y,r=p,u=c(t.disableCSRF);typeof u.value=="string"&&(u.value=!0);let i=!1,s=c(t.data);t.data===void 0&&(i=!0,s.value={csrfToken:""}),T("postFormData",s.value),T("$postForm",j());const l=b("$Tea"),k=I(),d=c(),R=f=>{_()},_=()=>{if(typeof t.method=="string"&&t.method.length>0&&t.method.toLowerCase()!="post"){console.error("'PostForm' says: invalid method: '"+t.method+"'");return}r("before");let f=t.action;typeof f!="string"&&(f="$");const o=l.action(f);if(i){const e=new FormData(d.value);for(const n in s.value){const a=s.value[n];if(a instanceof Array){let g=!1;for(const F of a)F instanceof File&&(e.append(n,F),g=!0);if(g)continue}e.set(n,a)}o.form(e)}else{let e=t.data;(e==null||typeof e!="object")&&(e={}),o.params(e)}if(typeof t.timeout=="number")o.timeout(t.timeout);else if(typeof t.timeout=="string"){const e=parseFloat(t.timeout);isNaN(e)||o.timeout(e)}typeof t.onSuccess=="function"&&o.success(e=>{r("success",e)}),typeof t.onFail=="function"&&o.fail(e=>{r("fail",e)}),typeof t.onProgress=="function"&&o.progress((e,n,a)=>{r("progress",e,n,a)}),o.error(e=>{console.error(e.message),r("error",e)}).done(()=>{r("done")}).alert((e,n,a)=>{typeof e=="string"&&e.length>0&&(a?k.success(e,()=>{typeof n=="function"?n():(t.refresh||t.refresh==="")&&l.reload()}):k.warn(e,()=>{typeof n=="function"?n():(t.refresh||t.refresh==="")&&l.reload()}))}).post()};return m({get rawForm(){return d.value},submit(){setTimeout(_)}}),(f,o)=>(h(),S("form",{onSubmit:D(R,["prevent"]),method:"post",ref_key:"formRef",ref:d},[V(f.$slots,"default"),v(s)!=null&&!u.value?(h(),$(x,{key:0,modelValue:v(s).csrfToken,"onUpdate:modelValue":o[0]||(o[0]=e=>v(s).csrfToken=e)},null,8,["modelValue"])):w("",!0)],544))}};export{E as _};
