1var S=Object.defineProperty;var b=(r,t,o)=>t in r?S(r,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):r[t]=o;var s=(r,t,o)=>(b(r,typeof t!="symbol"?t+"":t,o),o);import{I as E}from"./InputController.js";import"./index.js";const I="[data-js-registration-modal]";class f{constructor(t){s(this,"rootElement");s(this,"elementClose");s(this,"elementLoginInput");s(this,"elementPasswordInput");s(this,"elementConsent");s(this,"submitBtn");s(this,"loginInput");s(this,"passwordInput");s(this,"isLoading",!1);s(this,"selectors",{root:I,close:"[data-js-registration-modal-close]",login:"[data-js-reg-login-email-input]",password:"[data-js-reg-password-input]",consent:"[data-js-reg-consent]",button:"[data-js-reg-btn]"});s(this,"stateClasses",{isHidden:"js-hidden"});s(this,"updateButtonState",()=>{const t=this.loginInput.getValue().trim(),o=this.passwordInput.getValue().trim(),e=this.rootElement.querySelector("[data-js-reg-consent]"),i=e==null?void 0:e.querySelector('input[type="checkbox"]'),l=(i==null?void 0:i.checked)??!1,a=t.length>0&&o.length>0&&l,d=this.loginInput.isValid()&&this.passwordInput.isValid(),h=a&&d&&!this.isLoading;this.submitBtn.disabled=!h});s(this,"onSubmit",async t=>{t.preventDefault(),!this.submitBtn.disabled&&await this.sendRequest()});s(this,"sendRequest",async()=>{var u,m,p,g;this.isLoading=!0,this.submitBtn.disabled=!0,this.submitBtn.innerHTML=` 2 <div class="loader"> 3 <div></div> 4 <div></div> 5 <div></div> 6 </div> 7 `;const t=this.loginInput.getValue().trim(),o=this.passwordInput.getValue().trim(),e=this.rootElement.querySelector("[data-js-reg-consent]"),i=e==null?void 0:e.querySelector('input[type="checkbox"]'),l=(i==null?void 0:i.checked)??!1,a=this.rootElement.querySelector('input[name="_token"]'),d=(a==null?void 0:a.value)??"",h=this.rootElement.dataset.jsApiUrl??"/api/registration";try{const w=await fetch(h,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({login:t,password:o,consent:l,_token:d})}),n=await w.json();if(this.loginInput.hideError(),this.passwordInput.hideError(),!w.ok){const c=((u=n.errors)==null?void 0:u.login)||((m=n.errors)==null?void 0:m.password);throw!c&&n.message&&(this.loginInput.showError(n.message),this.passwordInput.showError(n.message)),c&&((p=n.errors)!=null&&p.login)&&this.loginInput.showError(n.errors.login[0]),c&&((g=n.errors)!=null&&g.password)&&this.passwordInput.showError(n.errors.password[0]),new Error("Reg failed")}this.openNextModal(t.includes("@")?"email":"phone")}finally{this.isLoading=!1,this.submitBtn.textContent="ÐаÑегиÑÑÑиÑоваÑÑÑÑ",this.updateButtonState()}});s(this,"onClose",()=>{this.hide()});this.rootElement=t,this.elementClose=this.rootElement.querySelector(this.selectors.close),this.elementLoginInput=this.rootElement.querySelector(this.selectors.login),this.elementPasswordInput=this.rootElement.querySelector(this.selectors.password),this.elementConsent=this.rootElement.querySelector(this.selectors.consent),this.submitBtn=this.rootElement.querySelector(this.selectors.button),this.loginInput=E(this.elementLoginInput),this.passwordInput=E(this.elementPasswordInput),this.init()}init(){this.bindEvents(),this.updateButtonState()}bindEvents(){var t;(t=this.elementClose)==null||t.addEventListener("click",this.onClose),this.elementLoginInput.addEventListener("input",this.updateButtonState),this.elementPasswordInput.addEventListener("input",this.updateButtonState),this.elementConsent.addEventListener("change",this.updateButtonState),this.submitBtn.addEventListener("click",this.onSubmit)}openNextModal(t){const o=t==="phone"?"code-confirmation":"email-confirmation",e=document.querySelector(`[data-js-${o}-modal]`);e==null||e.setAttribute("data-flow","registration"),t==="email"&&(e==null||e.setAttribute("data-current-email",this.loginInput.getValue())),t==="phone"&&(e==null||e.setAttribute("data-current-phone",this.loginInput.getValue()));const i=document.querySelector(`[data-js-modal-open="${o}"]`);i==null||i.click()}show(){this.rootElement.classList.remove(this.stateClasses.isHidden)}hide(){this.rootElement.classList.add(this.stateClasses.isHidden)}}class C{constructor(){s(this,"modal");this.init()}init(){const t=document.querySelector(I);if(t instanceof HTMLElement)this.modal=new f(t);else throw new Error("Registration modal not found")}open(){this.modal.show()}close(){this.modal.hide()}}export{C as RegistrationController};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.