(()=>{"use strict";var t={446:(t,e,s)=>{s.d(e,{aL:()=>r});const r="Escape"},634:(t,e,s)=>{s.d(e,{A:()=>r});class r{constructor(t,e){this._inputSelector=t.inputSelector,this._inputErrorClass=t.inputErrorClass,this._errorClass=t.errorClass,this._submitButtonSelector=t.submitButtonSelector,this._inactiveButtonClass=t.inactiveButtonClass,this._formElement=e,this._inputList=Array.from(this._formElement.querySelectorAll(this._inputSelector)),this._buttonElement=this._formElement.querySelector(this._submitButtonSelector),this._showErrorsAnimationClasses=["translate-x-5","opacity-0"],this._showErrorsTransitionsClasses=["transition-all","duration-300"],Array.from(this._formElement.querySelectorAll(".form__input-error")).map((t=>t.classList.add(...this._showErrorsAnimationClasses,...this._showErrorsTransitionsClasses)))}_animateErrMessage(t){console.log("пытаемся анимировать",t),t.classList.add(...this._showErrorsAnimationClasses),requestAnimationFrame((()=>{t.classList.add(...this._showErrorsTransitionsClasses),t.classList.remove(...this._showErrorsAnimationClasses);const e=()=>{t.removeEventListener("transitionend",e),t.classList.remove(...this._showErrorsTransitionsClasses)};t.addEventListener("transitionend",e),setTimeout(e,350)}))}_showInputError(t,e){const s=this._formElement.querySelector(`.${t.id}-error`);t.classList.add(this._inputErrorClass),s.textContent=e,s.classList.add(this._errorClass),this._animateErrMessage(s)}_hideInputError(t){const e=this._formElement.querySelector(`.${t.id}-error`);t.classList.remove(this._inputErrorClass),e.classList.remove(this._errorClass),e.classList.add(...this._showErrorsAnimationClasses),e.textContent=""}_checkInputValidity(t){t.validity.valid?this._hideInputError(t):this._showInputError(t,t.validationMessage)}_hasInvalidInput(t){return t.some((t=>!t.validity.valid))}_toggleButtonState(t,e){this._hasInvalidInput(t)?(e.classList.add(this._inactiveButtonClass),e.setAttribute("disabled",!0)):(e.classList.remove(this._inactiveButtonClass),e.removeAttribute("disabled"))}_showErrors(t,e){t.forEach((t=>{this._checkInputValidity(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((t=>{this._hideInputError(t)}))}showErrors(){this._inputList.forEach((t=>{this._checkInputValidity(t)}))}_setEventListeners(){this._inputList.forEach((t=>{let e=null;t.addEventListener("input",(()=>{e&&clearTimeout(e),e=setTimeout((()=>{this._checkInputValidity(t)}),400)}))}))}enableValidation(){this._formElement.addEventListener("submit",(t=>{t.preventDefault()})),this._setEventListeners()}}},810:(t,e,s)=>{s.d(e,{A:()=>r});class r{constructor({baseUrl:t,headers:e}){this._baseUrl=t,this._headers=e}_isResponseOk(t){return t.ok?t.json():Promise.reject(`Ошибка: ${t.status}`)}getInitialCards(){return fetch("https://api.termoblok.ru/blogcards",{headers:this._headers}).then((t=>this._isResponseOk(t)))}getInitiatPartners(){return fetch("https://api.termoblok.ru/partners",{headers:this._headers}).then((t=>this._isResponseOk(t)))}sendCartForm(t){return fetch(`${this._baseUrl}/forms/cart-form`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}).then((t=>this._isResponseOk(t)))}sendCallForm(t){return fetch(`${this._baseUrl}/forms/call-form`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}).then((t=>this._isResponseOk(t)))}sendBigForm(t){return fetch(`${this._baseUrl}/forms/base-form`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}).then((t=>this._isResponseOk(t)))}}},966:(t,e,s)=>{function r(t,e,s,r,o){switch(t){case"default":default:e.textContent=s;break;case"loading":e.textContent=r;break;case"sended":e.textContent=o}}s.d(e,{renderLoading:()=>r})}},e={};function s(r){var o=e[r];if(void 0!==o)return o.exports;var i=e[r]={exports:{}};return t[r](i,i.exports,s),i.exports}s.d=(t,e)=>{for(var r in e)s.o(e,r)&&!s.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},s.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),s.p="/",s.p;var r=s(810),o=s(446);class i{constructor(t){this._modal=document.querySelector(t),this._handleEscButton=t=>{t.key===o.aL&&this.close()},this._handleOverlayClick=t=>{t.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()}))}}var n=s(966),a=s(634);const l={inputSelector:".raschet-bem__input",submitButtonSelector:".button-bem_submit",inactiveButtonClass:"ui-button_disabled",inputErrorClass:"ui-button__type_error",errorClass:"raschet-bem__input-error_visible"},h=new r.A({baseUrl:"https://api.dromotron.ru",headers:{Accept:"application/json","Content-Type":"application/json;charset=utf-8"}}),u=document.forms.formCallBack,c=u.querySelector(l.submitButtonSelector),d=document.querySelector(".popup-callback-button"),m=new a.A(l,u);m.enableValidation();const _=new class extends i{constructor({formSubmitHandler:t,formCleanError:e,checherValidation:s},r,o,i){super(r),this._formSubmitHandler=t,this._formCleanError=e,this._formElement=this._modal.querySelector(o),this._heading=this._modal.querySelector(".popup-form__title"),this._inputSelector=i,this._checker=s}_getInputValues(){return this._inputList=this._formElement.querySelectorAll(this._inputSelector),this._formValues={},this._inputList.forEach((t=>{this._formValues[t.name]=t.value})),console.log(this._formValues),this._formValues}open(t,e){this._heading.textContent=t||"",super.open()}close(){super.close(),this._formElement.reset(),this._formCleanError()}setEventListeners(){super.setEventListeners(),this._formElement.addEventListener("submit",(t=>{t.preventDefault(),this._checker()&&this._formSubmitHandler(this._getInputValues())}))}}({formSubmitHandler:t=>{(0,n.renderLoading)("loading",c,"Оставить заявку","Отправляем...","Отправлено успешно!"),h.sendCallForm(t).then((t=>{console.log(t),(0,n.renderLoading)("sended",c,"Оставить заявку","Отправляем...","Отправлено успешно!")})).catch((t=>console.log(t))).finally((()=>{setTimeout((()=>{_.close(),m.disableSaveButton(),(0,n.renderLoading)("default",c,"Оставить заявку","Отправляем...","Отправлено успешно!")}),900)}))},formCleanError:()=>{m.cleanAllErrors()},checherValidation:t=>!m.hasInvalidInput()||(m.showErrors(),!1)},".popup-callback",".popup__form",".raschet-bem__input");_.setEventListeners(),d.addEventListener("mousedown",(()=>{_.open()}));const p=new i(".popup-menu");p.setEventListeners(),document.querySelector(".nav__mobile-icon").addEventListener("click",(()=>{p.open(),console.log("111")}));const v=new class{constructor(){this.state=this.loadFromStorage()}loadFromStorage(){const t=localStorage.getItem("cart");return t?JSON.parse(t):{}}saveToStorage(){localStorage.setItem("cart",JSON.stringify(this.state))}addItem(t,e={}){return this.state[t]?this.state[t].quantity+=1:this.state[t]={...e,quantity:1},this.saveToStorage(),this.state[t]}removeItem(t){return this.state[t]?(this.state[t].quantity>1?this.state[t].quantity-=1:delete this.state[t],this.saveToStorage(),this.state[t]):null}removeItemCompletely(t){return this.state[t]?(delete this.state[t],this.saveToStorage(),null):null}getItemQuantity(t){return this.state[t]?.quantity||0}getTotalQuantity(){return Object.values(this.state).reduce(((t,e)=>t+e.quantity),0)}getTotalPrice(t){const e=Object.keys(this.state).reduce(((e,s)=>{const{price:r}=t[s];return e[s]={...this.state[s],...void 0!==r&&{price:r}},e}),{});return Object.values(e).reduce(((t,e)=>(console.log("Object.values(this.state).reduce((total, item)",e),t+e.price*e.quantity)),0)}clear(){this.state={},this.saveToStorage()}getItem(t){return this.state[t]}getItems(){return{...this.state}}getItemsForSend(t){const e=Object.keys(this.state).reduce(((e,s)=>{const{price:r,title:o}=t[s];return e[s]={...this.state[s],...void 0!==r&&{price:r},...void 0!==o&&{title:o}},e}),{});return Object.values(e)}},E=document.querySelector(".header-cart-link");!function(){const t=v.getTotalQuantity();t>0?(E.querySelector(".header-cart-link-count").textContent=`(${t})`,E.style.display="flex"):E.querySelector(".header-cart-link-count").textContent=""}()})();