(()=>{"use strict";var e={11535:(e,t,s)=>{e.exports=s.p+"images/cf8cd32effce8f14064b.png"},57100:(e,t,s)=>{e.exports=s.p+"images/e7566180fedbca0ab884.png"},72500:(e,t,s)=>{e.exports=s.p+"images/de8424720353369deee7.png"},37476:(e,t,s)=>{e.exports=s.p+"images/4c951c42399a4da74eb2.png"},44774:(e,t,s)=>{e.exports=s.p+"images/890f12fd1d84b35d3027.png"},88128:(e,t,s)=>{e.exports=s.p+"images/2ebcbbf6c232bb00f2a6.png"},84906:(e,t,s)=>{e.exports=s.p+"images/5bf5ce672a831fe493f0.png"},66120:(e,t,s)=>{e.exports=s.p+"images/f4b9fc927a6cbb785fb7.png"},69331:(e,t,s)=>{e.exports=s.p+"images/a84c2cd630adcb2fb844.png"},93427:(e,t,s)=>{e.exports=s.p+"images/cb601ecb4902055371fa.png"},33298:(e,t,s)=>{e.exports=s.p+"images/0615efa9ac4d4acf62b9.png"},82916:(e,t,s)=>{e.exports=s.p+"images/5a9b103dc314a4c73396.png"},92517:(e,t,s)=>{e.exports=s.p+"images/4cd0bf4f6c3826be20e9.png"},94701:(e,t,s)=>{e.exports=s.p+"images/ca96080890acb13f1452.png"},66735:(e,t,s)=>{e.exports=s.p+"images/b46f607e557fa86ce5de.png"}},t={};function s(r){var o=t[r];if(void 0!==o)return o.exports;var n=t[r]={exports:{}};return e[r](n,n.exports,s),n.exports}s.m=e,s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),s.p="/",s.b=document.baseURI||self.location.href,(()=>{function e(e,t,s,r){t.textContent=e?r:s}new URL(s(66735),s.b),new URL(s(92517),s.b),new URL(s(94701),s.b),new URL(s(11535),s.b),new URL(s(57100),s.b),new URL(s(72500),s.b),new URL(s(37476),s.b),new URL(s(44774),s.b),new URL(s(88128),s.b),new URL(s(84906),s.b),new URL(s(66120),s.b),new URL(s(69331),s.b),new URL(s(93427),s.b),new URL(s(33298),s.b),new URL(s(82916),s.b);class t{constructor(e){this._modal=document.querySelector(e),this._handleEscButton=e=>{"Escape"===e.key&&this.close()},this._handleOverlayClick=e=>{e.target.classList.contains("popup_opened")&&this.close()}}open(){document.querySelector("body").classList.add("body-fixed"),this._modal.classList.add("popup_opened"),document.addEventListener("keydown",this._handleEscButton),this._modal.addEventListener("mousedown",this._handleOverlayClick)}close(){this._modal.classList.remove("popup_opened"),document.removeEventListener("keydown",this._handleEscButton),this._modal.removeEventListener("mousedown",this._handleOverlayClick),document.querySelector("body").classList.remove("body-fixed")}setEventListeners(){this._modal.querySelector(".popup__button-close").addEventListener("mousedown",(()=>{this.close()}))}}class r{constructor(e,t){this._inputSelector=e.inputSelector,this._inputErrorClass=e.inputErrorClass,this._errorClass=e.errorClass,this._submitButtonSelector=e.submitButtonSelector,this._inactiveButtonClass=e.inactiveButtonClass,this._formElement=t,this._inputList=Array.from(this._formElement.querySelectorAll(this._inputSelector)),this._buttonElement=this._formElement.querySelector(this._submitButtonSelector)}_showInputError(e,t){const s=this._formElement.querySelector(`.${e.id}-error`);e.classList.add(this._inputErrorClass),s.textContent=t,s.classList.add(this._errorClass)}_hideInputError(e){const t=this._formElement.querySelector(`.${e.id}-error`);e.classList.remove(this._inputErrorClass),t.classList.remove(this._errorClass),t.textContent=""}_checkInputValidity(e){e.validity.valid?this._hideInputError(e):this._showInputError(e,e.validationMessage)}_hasInvalidInput(e){return e.some((e=>!e.validity.valid))}_toggleButtonState(e,t){this._hasInvalidInput(e)?(t.classList.add(this._inactiveButtonClass),t.setAttribute("disabled",!0)):(t.classList.remove(this._inactiveButtonClass),t.removeAttribute("disabled"))}_showErrors(e,t){e.forEach((s=>{this._checkInputValidity(s),this._toggleButtonState(e,t)}))}toggleButtonState(){this._toggleButtonState(this._inputList,this._buttonElement)}hasInvalidInput(){return this._hasInvalidInput(this._inputList)}disableSaveButton(){this._buttonElement.classList.add(this._inactiveButtonClass),this._buttonElement.setAttribute("disabled",!0)}cleanAllErrors(){this._inputList.forEach((e=>{this._hideInputError(e)}))}showErrors(){this._inputList.forEach((e=>{this._checkInputValidity(e),this.toggleButtonState(this._inputList,this._buttonElement)}))}showErrorsForStep(e){}_setEventListeners(){this._inputList.forEach((e=>{e.addEventListener("input",(()=>{this._checkInputValidity(e),this.toggleButtonState()}))}))}_setStepEventListeners(e){e.forEach((e=>{const t=e.inputs,s=e.button;console.log(`123 ${s}`),t.forEach((e=>{e.addEventListener("input",(()=>{this._checkInputValidity(e),this._toggleButtonState(t,s)}))}))}))}enableValidation(){this._formElement.addEventListener("submit",(e=>{e.preventDefault()})),this._setEventListeners()}checkStep(e){const t=this._sets[e].inputs,s=this._sets[e].button;return!this._hasInvalidInput(t)||(this._showErrors(t,s),this._toggleButtonState(t,s),!1)}enableStepValidation(){this._sets=[];const e=this._formElement.querySelector(".first-step"),t=e.querySelector(".first-step-button"),s=Array.from(e.querySelectorAll(this._inputSelector));this._sets.push({inputs:s,button:t});const r=this._formElement.querySelector(".second-step"),o=r.querySelector(".second-step-button"),n=Array.from(r.querySelectorAll(this._inputSelector));this._sets.push({inputs:n,button:o}),this._setStepEventListeners(this._sets)}}class o{constructor({baseUrl:e,headers:t}){this._baseUrl=e,this._headers=t}_isResponseOk(e){return e.ok?e.json():Promise.reject(`Ошибка: ${e.status}`)}getInitialCards(){return fetch("https://api.termoblok.ru/data/blogCards",{headers:this._headers}).then((e=>this._isResponseOk(e)))}getNews(){return fetch("https://api.termoblok.ru/news",{headers:this._headers}).then((e=>this._isResponseOk(e)))}getInitiatPartners(){return fetch("https://api.termoblok.ru/data/partners",{headers:this._headers}).then((e=>this._isResponseOk(e)))}sendCallForm(e){return fetch(`${this._baseUrl}/forms/small-form`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e),isBase64Encoded:!1}).then((e=>(console.log(e),this._isResponseOk(e))))}sendBigForm(e){return fetch(`${this._baseUrl}/forms/big-form`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then((e=>this._isResponseOk(e)))}}const n=new o({baseUrl:"https://api.termoblok.ru",headers:{Accept:"*/*","Content-Type":"text/plain"}}),i=document.forms.formRaschetPopup,a=i.querySelector(".raschet-bem__submit-button"),l=new r({inputSelector:".raschet-bem__input",submitButtonSelector:".raschet-bem__submit-button",inactiveButtonClass:"raschet-bem__submit-button_disabled",inputErrorClass:"raschet-bem__input_type_error",errorClass:"raschet-bem__input-error_visible"},i);l.enableStepValidation();const c=new class extends t{constructor({formSubmitHandler:e,formCleanError:t,checherValidation:s},r,o,n){super(r),this._formSubmitHandler=e,this._formCleanError=t,this._formElement=this._modal.querySelector(o),this._inputSelector=n,this._absolutePopup=this._modal.querySelector(".popup-absolute"),this._step=0,this._checker=s}increaseStep(){this._step=1}decreaseStep(){this._step=0}_getInputValues(){return this._inputList=this._formElement.querySelectorAll(this._inputSelector),this._formValues={},this._inputList.forEach((e=>{this._formValues[e.name]=e.value})),this._formValues}close(){super.close(),this._formElement.reset(),this._formCleanError(),this._absolutePopup.classList.contains("popup__form-fio_opened")&&(console.log("Открыто!"),this._absolutePopup.classList.remove("popup__form-fio_opened"))}setEventListeners(){super.setEventListeners(),this._formElement.addEventListener("submit",(e=>{e.preventDefault(),this._checker()&&this._formSubmitHandler(this._getInputValues())}))}}({formSubmitHandler:t=>{e(!0,a,"Отправить","Отправка..."),n.sendBigForm(t).then((e=>{console.log(e),c.close()})).catch((e=>console.log(e))).finally((()=>{l.disableSaveButton(),e(!1,a,"Отправить","Отправка...")})),console.log(t)},formCleanError:()=>{l.cleanAllErrors()},checherValidation:e=>!l.hasInvalidInput()||(l.showErrors(),!1)},".popup-raschet",".raschet-bem",".raschet-bem__input");c.setEventListeners();const u=document.querySelector(".form-back-button"),h=document.querySelector(".form-next-step"),p=document.querySelector(".popup-absolute");u.addEventListener("mousedown",(e=>{p.classList.remove("popup__form-fio_opened"),c.decreaseStep(),console.log(c._step)})),h.addEventListener("mousedown",(()=>{l.checkStep(0)&&(p.classList.add("popup__form-fio_opened"),c.increaseStep(),console.log(c._step))}));const _=new o({baseUrl:"https://api.termoblok.ru",headers:{Accept:"*/*","Content-Type":"text/plain"}}),m=document.forms.formCallBack,d=m.querySelector(".button-bem_submit"),b=new r({inputSelector:".raschet-bem__input",submitButtonSelector:".button-bem",inactiveButtonClass:"popup__button-save_disabled",inputErrorClass:"raschet-bem__input_type_error",errorClass:"raschet-bem__input-error_visible"},m),f=new class extends t{constructor({formSubmitHandler:e,formCleanError:t,checherValidation:s},r,o,n){super(r),this._formSubmitHandler=e,this._formCleanError=t,this._formElement=this._modal.querySelector(o),this._heading=this._modal.querySelector(".raschet-bem__title"),this._comment=this._modal.querySelector("#comment-free-input"),this._inputSelector=n,this._checker=s}_getInputValues(){return this._inputList=this._formElement.querySelectorAll(this._inputSelector),this._formValues={},this._inputList.forEach((e=>{this._formValues[e.name]=e.value})),console.log(this._formValues),this._formValues}open(e,t){this._heading.textContent=e||"Заявка в свободной форме",this._comment.textContent=t||"",super.open()}close(){super.close(),this._formElement.reset(),this._formCleanError()}setEventListeners(){super.setEventListeners(),this._formElement.addEventListener("submit",(e=>{e.preventDefault(),this._checker()&&this._formSubmitHandler(this._getInputValues())}))}}({formSubmitHandler:t=>{e(!0,d,"Отправить","Отправка..."),_.sendCallForm(t).then((e=>{console.log(e),f.close()})).catch((e=>console.log(e))).finally((()=>{b.disableSaveButton(),e(!1,d,"Отправить","Отправка...")}))},formCleanError:()=>{b.cleanAllErrors()},checherValidation:e=>!b.hasInvalidInput()||(b.showErrors(),!1)},".popup-callback",".popup__form",".raschet-bem__input");f.setEventListeners(),b.enableValidation(),document.querySelector(".mainmodels__raschet_ti")?.addEventListener("mousedown",(()=>{c.open()})),document.querySelector(".mainmodels__raschet_p")?.addEventListener("mousedown",(()=>{f.open()}))})()})();