import{c as x,g as G,a as d,u as M,k as h,i as t,b as i,h as R,t as z}from"./web.4OCuPnM3.js";import{a as B,g as n}from"./errors.BxTAJicR.js";import{T as N,F as o}from"./toast.BAoR90zK.js";var H=z('<form class="grid gap-5 md:gap-10"><input name=id hidden><input name=self hidden><div class=form-grid><!$><!/><!$><!/><!$><!/><div class=sm:col-span-2></div><!$><!/><div class=sm:col-span-2></div></div><div class="flex flex-wrap justify-center mt-5"><button type=submit class="bg-blue-950 rounded-lg text-white p-2 w-[10rem]">');const O=(a,S,y)=>{const[E,c]=x(!1),[l,u]=x();let f;const F=async s=>{s.preventDefault(),c(!0),u();try{const r=new FormData(f),{data:m,error:e}=await B.updateProfile(r);c(!1),u(e),await N.fire({icon:e?"error":"success",title:e?"Failed":"Successful",text:m?.message??e?.fields?"":e?.message})}catch(r){console.log({error:r}),await N.fire({icon:"error",title:"Error",text:r.message})}finally{c(!1)}};return(()=>{var s=G(H),r=s.firstChild,m=r.nextSibling,e=m.nextSibling,w=e.firstChild,[p,P]=d(w.nextSibling),C=p.nextSibling,[$,L]=d(C.nextSibling),q=$.nextSibling,[b,D]=d(q.nextSibling),_=b.nextSibling,k=_.nextSibling,[v,A]=d(k.nextSibling),T=v.nextSibling,U=e.nextSibling,j=U.firstChild;return M(g=>f=g,s),s.addEventListener("submit",g=>F(g)),h(m,"value",S),t(e,i(o,{name:"firstName",required:!0,get value(){return a?.first_name??a?.firstName},label:"First Name",placeholder:"First Name",error:()=>n(["firstName"],l()),className:""}),p,P),t(e,i(o,{name:"lastName",get value(){return a?.last_name??a?.lastName},required:!0,label:"Last Name",placeholder:"Last Name",error:()=>n(["lastName"],l()),className:""}),$,L),t(e,i(o,{name:"username",get value(){return a?.username},label:"Username",placeholder:"Username",error:()=>n(["username"],l()),className:""}),b,D),t(_,i(o,{name:"email",required:!0,get value(){return a?.email},label:"Email",type:"email",placeholder:"Email",error:()=>n(["email"],l())})),t(e,i(o,{name:"phone",get value(){return a?.phone},label:"Phone",type:"tel",placeholder:"Phone",error:()=>n(["phone"],l()),className:""}),v,A),t(T,i(o,{name:"address",get value(){return a?.address},label:"Address",placeholder:"Address",error:()=>n(["address"],l())})),t(j,()=>E()?"...loading":"Save"),R(()=>h(r,"value",a.id)),s})()};export{O as ProfileForm};
