g.getValue()!==c[p[1]].getValue()?p[2]:null),()=>{g.setError(null),r&&y(),E?.(c)});return s[u]=g,s},{}),i=Object.values(c),d=()=>{r=!1,n.classList.remove("disabled"),l.disabled=!1,o.style.display="none",i.forEach(s=>s.setValue(""))},m=s=>{o.innerHTML=s,o.style.display="flex"},y=()=>i.map(s=>{for(const u of s.validators)if(s.setError(u()),s.hasError())return!1;return!0}).every(s=>s);return n.addEventListener("submit",async s=>{if(s.preventDefault(),r=!0,!!y()){n.classList.add("disabled"),l.disabled=!0,o.style.display="none";try{await e(c)}catch(u){if(n.classList.remove("disabled"),l.disabled=!1,u.data?.validationErrors)for(const f of u.data.validationErrors)c[f.field.replace("[","").replace("]","")].setError(f.message);else m(u.message||"Произошла ошибка при выполнении запроса")}}}),{...c,element:n,reset:d,setError:m}};L();H("register",{type:["radio",[],t=>{t.shop_name.setValue(""),t.shop_name.element.style.display=t.type.getValue()==="shop"?"flex":"none"}],username:["text",[["required","Введите логин"]]],password:["password",[["required","Введите пароль"],["minLength",8,"Минимум 8 символов"],["equal","confirm_password","Пароли не совпадают"]]],confirm_password:["password",[["required","Введите пароль"],["minLength",8,"Минимум 8 символов"],["equal","password","Пароли не совпадают"]]],shop_name:["text",[["required","Введите название магазина"]]]},async t=>{const a=await S(t.type.getValue(),{username:t.username.getValue(),password:t.password.getValue(),confirm_password:t.confirm_password.getValue(),shop_name:t.shop_name.getValue(),captcha_token:await V()});b(a.data.token),location.assign("/terms")});