import{H as O,a3 as T,r as z,U}from"./index-C5GbdPxY.js";function A(o){const{t:u}=O(),H=T({...o}),t=z(!1),a=z(Object.keys(o).reduce((s,n)=>(s[n]="",s),{}));function c(){for(const s in a.value)a.value[s]=""}async function I(s,n=!1){var i,f,l,d,g,p,m,v,y,h,_,b,k,x,E;t.value=!0;const r=U();try{const e=await s();if((i=e==null?void 0:e.data)!=null&&i.message&&r.success(e.data.message),c(),n)return e}catch(e){if(c(),(((f=e==null?void 0:e.response)==null?void 0:f.status)===422||(d=(l=e==null?void 0:e.config)==null?void 0:l.url)!=null&&d.includes("/auth/login"))&&((p=(g=e.response)==null?void 0:g.data)!=null&&p.errors)){const j=e.response.data.errors;for(const w in j)a.value[w]=j[w][0]}else(v=(m=e.response)==null?void 0:m.data)!=null&&v.message?(h=(y=e==null?void 0:e.config)==null?void 0:y.url)!=null&&h.includes("/auth/login")?a.value.identifier=(b=(_=e.response)==null?void 0:_.data)==null?void 0:b.message:r.error((x=(k=e.response)==null?void 0:k.data)==null?void 0:x.message):((E=e==null?void 0:e.response)==null?void 0:E.status)===401?r.error(u("core::errors.unauthorized")):r.error(u("core::errors.an_unexpected_error_occurred"));return!1}finally{t.value=!1}return!0}return{state:H,loading:t,errors:a,submit:I}}export{A as u};
