1var g=Object.defineProperty;var y=(s,t,o)=>t in s?g(s,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):s[t]=o;var e=(s,t,o)=>(y(s,typeof t!="symbol"?t+"":t,o),o);import{I as v}from"./InputController.js";import"./index.js";const f="[data-js-code-confirmation-modal]";class w{constructor(t){e(this,"rootElement");e(this,"elementInput");e(this,"timerElement");e(this,"modalRoot");e(this,"codeInput");e(this,"selectors",{root:f,input:"[data-js-code-input]",timer:"[data-js-code-timer]"});e(this,"phoneElement",null);e(this,"codeLength",4);e(this,"isLoading",!1);e(this,"timerInterval",null);e(this,"timeLeft",30);e(this,"canResend",!1);e(this,"handleInput",()=>{this.codeInput.getValue().length===this.codeLength&&this.codeInput.isValid()&&!this.isLoading&&this.sendRequest()});e(this,"handleResendClick",()=>{!this.canResend||this.isLoading||this.resendCode()});e(this,"resendCode",async()=>{const t=this.rootElement.getAttribute("data-flow"),o=t==="registration"?"data-js-resend-code-registration-url":t==="recovery"?"data-js-resend-code-recovery-url":"data-js-resend-code-change-url",n=this.timerElement.getAttribute(o)||"",r=this.rootElement.querySelector('input[name="_token"]'),a=(r==null?void 0:r.value)??"";this.isLoading=!0,this.timerElement.textContent="ÐÑпÑавка...",this.timerElement.style.cursor="default";const c=this.rootElement.getAttribute("data-current-phone");try{const h=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({_token:a,phone:c})}),d=await h.json();if(!h.ok||d.success===!1){this.timerElement.textContent="ÐопÑобоваÑÑ Ñнова",this.canResend=!0;return}this.startTimer()}catch{this.canResend=!0}finally{this.isLoading=!1}});e(this,"sendRequest",async()=>{var d;const t=this.getApiUrlByFlow(),o=this.codeInput.getValue().trim(),n=this.rootElement.querySelector('input[name="_token"]'),r=(n==null?void 0:n.value)??"",a=this.rootElement.getAttribute("data-flow");this.isLoading=!0;const c=this.elementInput.querySelector("[data-js-input-control]");c.disabled=!0,this.codeInput.hideError();const h=this.rootElement.getAttribute("data-current-phone");try{const p=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({code:o,_token:r,phone:h})}),i=await p.json();if(!p.ok||i.success===!1){i.message&&this.codeInput.showError(i.message),(d=i.errors)!=null&&d.code&&this.codeInput.showError(i.errors.code[0]);return}if(a==="recovery"){const l=i.token,E=this.rootElement.getAttribute("data-current-phone")||"",m=document.querySelector("[data-js-password-change-modal]");m&&(m.setAttribute("data-recovery-token",l),m.setAttribute("data-recovery-phone",E));const u=document.querySelector('[data-js-modal-open="password-change"]');u==null||u.click()}if(a==="registration"){const l=document.querySelector('[data-js-modal-open="registration-success"]');l==null||l.click()}a==="change"&&window.location.reload()}catch{this.codeInput.showError("ÐÑибка ÑоединениÑ")}finally{this.isLoading=!1,c.disabled=!1}});this.rootElement=t,this.elementInput=this.rootElement.querySelector(this.selectors.input),this.timerElement=this.rootElement.querySelector(this.selectors.timer),this.modalRoot=this.rootElement.closest("[data-js-modal]"),this.codeInput=v(this.elementInput),this.phoneElement=this.rootElement.querySelector("[data-js-current-phone]"),this.init()}init(){this.bindEvents(),this.observeOpenState()}bindEvents(){this.elementInput.addEventListener("input",this.handleInput),this.timerElement.addEventListener("click",this.handleResendClick)}getApiUrlByFlow(){const t=this.rootElement.getAttribute("data-flow");return t==="recovery"?this.rootElement.getAttribute("data-js-api-url-recovery")||"":t==="registration"?this.rootElement.getAttribute("data-js-api-url-register")||"":t==="change"&&this.rootElement.getAttribute("data-js-api-url-change")||""}observeOpenState(){if(!this.modalRoot)return;new MutationObserver(o=>{o.forEach(n=>{n.attributeName==="open"&&(this.modalRoot.hasAttribute("open")?(this.updatePhone(),this.startTimer()):this.stopTimer())})}).observe(this.modalRoot,{attributes:!0})}updatePhone(){if(!this.phoneElement)return;const t=this.rootElement.getAttribute("data-current-phone");if(!t)return;this.phoneElement.textContent="+"+t;const o=this.rootElement.getAttribute("data-flow")==="registration",n=this.rootElement.querySelector("[data-js-phone-title]");
1n&&(n.textContent=o?"ÐÐ»Ñ Ð¿Ð¾Ð´ÑвеÑÐ¶Ð´ÐµÐ½Ð¸Ñ ÑегиÑÑÑаÑии введиÑе код, оÑпÑавленнÑй Ð½Ð°Â Ð½Ð¾Ð¼ÐµÑ ÑелеÑона":"ÐведиÑе код, оÑпÑавленнÑй Ð½Ð°Â Ð½Ð¾Ð¼ÐµÑ ÑелеÑона")}startTimer(){this.stopTimer(),this.canResend=!1,this.timerElement.style.cursor="default",this.timeLeft=30,this.updateTimer(),this.timerInterval=window.setInterval(()=>{if(this.timeLeft--,this.timeLeft<=0){this.stopTimer();return}this.updateTimer()},1e3)}updateTimer(){if(!this.timerElement)return;const t=this.timeLeft<10?`0${this.timeLeft}`:this.timeLeft;this.timerElement.textContent=`00:${t}`}stopTimer(){this.timerInterval&&(clearInterval(this.timerInterval),this.timerInterval=null),this.timerElement&&(this.timerElement.textContent="ÐÑпÑавиÑÑ ÐºÐ¾Ð´ еÑÑ Ñаз",this.timerElement.style.cursor="pointer",this.canResend=!0)}destroy(){this.stopTimer()}}class A{constructor(){e(this,"modal");this.init()}init(){const t=document.querySelector(f);if(t instanceof HTMLElement)this.modal=new w(t);else throw new Error("Code modal not found")}}export{A as CodeConfirmationController};
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.