1var r=Object.defineProperty;var l=(n,e,t)=>e in n?r(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var s=(n,e,t)=>(l(n,typeof e!="symbol"?e+"":e,t),t);const o="[data-js-promocode]";class a{constructor(e){s(this,"rootElement");s(this,"elementInput");s(this,"elementButton");s(this,"elementMessage");s(this,"apiUrl");s(this,"isApplied",!1);s(this,"isLoading",!1);s(this,"selectors",{root:o,input:"[data-js-input-control]",button:"[data-js-promocode-button]",message:"[data-js-promocode-message]"});s(this,"onInputChange",()=>{this.isApplied||(this.updateButtonState(),this.clearMessage())});s(this,"onInputKeyDown",e=>{e.key==="Enter"&&(e.preventDefault(),this.elementButton.click())});s(this,"onButtonClick",async()=>{if(this.isApplied||this.isLoading||this.elementButton.disabled)return;const e=this.elementInput.value.trim();e.length<=3||await this.sendRequest(e)});this.rootElement=e,this.elementInput=this.rootElement.querySelector(this.selectors.input),this.elementButton=this.rootElement.querySelector(this.selectors.button),this.elementMessage=this.rootElement.querySelector(this.selectors.message),this.apiUrl=this.rootElement.getAttribute("data-js-api-url")||"",this.init()}init(){!this.elementInput||!this.elementButton||!this.elementMessage||(this.bindEvents(),this.updateButtonState())}bindEvents(){this.elementInput.addEventListener("input",this.onInputChange),this.elementInput.addEventListener("keydown",this.onInputKeyDown),this.elementButton.addEventListener("click",this.onButtonClick)}updateButtonState(){if(this.isApplied||this.isLoading)return;this.elementInput.value.trim().length>3?this.elementButton.removeAttribute("disabled"):this.elementButton.setAttribute("disabled","")}async sendRequest(e){this.isLoading=!0,this.elementButton.setAttribute("disabled",""),this.clearMessage();try{const i=await(await fetch(this.apiUrl,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({code:e})})).json();i.success?this.handleSuccess(i.message):this.handleError(i.message)}catch(t){this.handleError("ÐÑоизоÑла оÑибка. ÐопÑобÑйÑе позже."),console.error("PromoCode error:",t)}finally{this.isLoading=!1}}handleSuccess(e){this.isApplied=!0,this.showMessage(e);const t=this.elementButton.querySelector(".button__label");t&&(t.textContent="ÐÑименен"),this.elementInput.setAttribute("readonly","")}handleError(e){this.showMessage(e),this.updateButtonState()}showMessage(e){this.clearMessage(),this.elementMessage.innerHTML=e}clearMessage(){this.elementMessage.innerHTML=""}}class u{constructor(){this.init()}init(){document.querySelectorAll(o).forEach(t=>{t instanceof HTMLElement&&new a(t)})}}export{u as PromoCodeController};
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.