(()=>{"use strict";var e={824:(e,t,s)=>{s.d(t,{N:()=>o,k:()=>c}),s.p;var n=s(985);class r{constructor(e,t){this._modal=document.querySelector(e),this._buttonClose=this._modal.querySelector(".popup-button-close"),this._closeButtonSelector=".popup-button-close",this._openedClass="popup_opened",this._handleEscButton=e=>{"Escape"===e.key&&this.close()},this._handleOverlayClick=e=>{e.target.classList.contains("popup_opened")&&this.close()},this._isOpened=!1}open(){this._modal.classList.add(this._openedClass),this._isOpened=!0,this._isEscHandleEnabled&&document.addEventListener("keydown",this._handleEscButton),this._isOverlayEnabled&&this._modal.addEventListener("mousedown",this._handleOverlayClick),this._isBodyFixWhenOpen&&document.querySelector("body").classList.add("body-fixed")}close(){this._modal.classList.remove(this._openedClass),this._isOpened=!1,this._isEscHandleEnabled&&document.removeEventListener("keydown",this._handleEscButton),this._isOverlayEnabled&&this._modal.removeEventListener("mousedown",this._handleOverlayClick),this._isBodyFixWhenOpen&&document.querySelector("body").classList.remove("body-fixed")}setEventListeners({overlay:e=!0,esc:t=!0,bodyfix:s=!0}={}){this._isOverlayEnabled=e,this._isEscHandleEnabled=t,this._isBodyFixWhenOpen=s,this._buttonClose.addEventListener("mousedown",()=>{this.close()})}}class a extends r{constructor({handleClose:e,formConfig:t,headingSelector:s,commentSelector:r,buttonCloseSelector:a},i){super(i),a&&(this._buttonClose=this._modal.querySelector(a)),this._formInstance=(0,n.createForm)({...t,formSelector:`${i} form`,handleCloseCallback:()=>{this.close()}}),this._formElement=this._formInstance.form,this._formValidator=this._formInstance.formValidator,this._heading=this._modal.querySelector(s),this._comment=this._modal.querySelector(r),e&&(this._handleCloseFunc=e),this._step=0}increaseStep(){this._step=1}decreaseStep(){this._step=0}open(e,t){this._heading&&(this._heading.textContent=e||"Отправить заявку"),this._comment&&(this._comment.textContent=t||""),super.open()}close(){super.close(),this._handleCloseFunc&&this._handleCloseFunc(),this._formElement.reset(),this._formValidator.cleanAllErrors()}setEventListeners(e){super.setEventListeners(e)}setSubmitHandler(e){this._formInstance.formStatic.setSubmitHandler(e)}validate(){return this._formValidator.hasInvalidInput()}}class i extends r{constructor(e,t){super(e);const{containerSelector:s,animateClasses:n,buttonCloseSelector:r}=t;this._animateClasses=n||[],this._container=this._modal.querySelector(s||".popup-menu-container"),this._container.classList.add(...n,"transition-all","duration-200"),r&&(this._buttonClose=this._modal.querySelector(r))}open(){super.open(),this._container.classList.remove(...this._animateClasses)}close(){super.close(),this._container.classList.add(...this._animateClasses)}}!function(e){const{popupSelector:t,buttonOpenSelector:s,formConfig:n,popupConfig:r={}}=e,i=new a({...r,formConfig:{...n,formSelector:`${t} form`}},t),o=document.querySelector(s);o?(o.addEventListener("click",e=>{e.preventDefault(),i.open(r.heading,r.comment)}),i.setEventListeners({overlay:!1,esc:!1})):(console.warn(`Кнопка ${s} не найдена`),i.setEventListeners({overlay:!1,esc:!1}))}({popupSelector:".popup-callback",buttonOpenSelector:".popup-callback-button",formConfig:{formId:"call-form",loadingText:"Отправляем заявку в дромотрон 2...",newFormConfig:{inputSelector:".raschet-bem__input",submitButtonSelector:".button-bem_submit",inactiveButtonClass:"ui-button_disabled",inputErrorClass:"ui-button__type_error",errorClass:"raschet-bem__input-error_visible"}},popupConfig:{buttonCloseSelector:".popup__button-close",heading:"Оставьте свой номер и мы Вам перезвоним2",headingSelector:".title-form",handleClose:()=>{console.log('Попап "Перезвоните мне" закрыт')}}}),function(e={}){const t={containerSelector:".popup-menu-container",animateClasses:["translate-x-20"],buttonCloseSelector:".popup-button-close"},{popupSelector:s=".popup-menu",buttonOpenSelector:n=".nav__mobile-icon",menuConfig:r={}}=e,a={...t,...r,animateClasses:[...t.animateClasses,...r.animateClasses||[]]},o=new i(s,a),l=document.querySelector(n);l?(l.addEventListener("click",e=>{e.preventDefault(),o.open()}),o.setEventListeners()):(console.warn(`Кнопка ${n} не найдена`),o.setEventListeners())}({menuConfig:{containerSelector:".popup__container_menu",buttonCloseSelector:".popup__button-close"}});const o=new class{constructor(){this.state=this.loadFromStorage()}loadFromStorage(){const e=localStorage.getItem("cart");return e?JSON.parse(e):{}}saveToStorage(){localStorage.setItem("cart",JSON.stringify(this.state))}addItem(e,t={}){return this.state[e]?this.state[e].quantity+=1:this.state[e]={...t,quantity:1},this.saveToStorage(),this.state[e]}removeItem(e){return this.state[e]?(this.state[e].quantity>1?this.state[e].quantity-=1:delete this.state[e],this.saveToStorage(),this.state[e]):null}removeItemCompletely(e){return this.state[e]?(delete this.state[e],this.saveToStorage(),null):null}getItemQuantity(e){return this.state[e]?.quantity||0}getTotalQuantity(){return Object.values(this.state).reduce((e,t)=>e+t.quantity,0)}getTotalPrice(e){const t=Object.keys(this.state).reduce((t,s)=>{const{price:n}=e[s];return t[s]={...this.state[s],...void 0!==n&&{price:n}},t},{});return Object.values(t).reduce((e,t)=>(console.log("Object.values(this.state).reduce((total, item)",t),e+t.price*t.quantity),0)}clear(){this.state={},this.saveToStorage()}getItem(e){return this.state[e]}getItems(){return{...this.state}}getItemsForSend(e){const t=Object.keys(this.state).reduce((t,s)=>{const{price:n,title:r}=e[s];return t[s]={...this.state[s],...void 0!==n&&{price:n},...void 0!==r&&{title:r}},t},{});return Object.values(t)}},l=document.querySelector(".header-cart-link");function c(){const e=o.getTotalQuantity();e>0?(l.querySelector(".header-cart-link-count").textContent=`(${e})`,l.style.display="flex"):l.querySelector(".header-cart-link-count").textContent=""}c()},985:(e,t,s)=>{s.d(t,{createForm:()=>l});class n{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}:not([type="radio"])`)),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(e=>e.classList.add(...this._showErrorsAnimationClasses,...this._showErrorsTransitionsClasses))}_animateErrMessage(e){e.classList.add(...this._showErrorsAnimationClasses),requestAnimationFrame(()=>{e.classList.add(...this._showErrorsTransitionsClasses),e.classList.remove(...this._showErrorsAnimationClasses);const t=()=>{e.removeEventListener("transitionend",t),e.classList.remove(...this._showErrorsTransitionsClasses)};e.addEventListener("transitionend",t),setTimeout(t,350)})}_showInputError(e,t){const s=this._formElement.querySelector(`.${e.id}-error`);e.classList.add(this._inputErrorClass),s.textContent=t,s.classList.add(this._errorClass),this._animateErrMessage(s)}_hideInputError(e){const t=this._formElement.querySelector(`.${e.id}-error`);e.classList.remove(this._inputErrorClass),t.classList.remove(this._errorClass),t.classList.add(...this._showErrorsAnimationClasses),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(e=>{this._checkInputValidity(e)})}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)})}_setEventListeners(){this._inputList.forEach(e=>{let t=null;e.addEventListener("input",()=>{t&&clearTimeout(t),t=setTimeout(()=>{this._checkInputValidity(e)},400)})})}_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)})})})}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 n=this._formElement.querySelector(".second-step"),r=n.querySelector(".second-step-button"),a=Array.from(n.querySelectorAll(this._inputSelector));this._sets.push({inputs:a,button:r}),this._setStepEventListeners(this._sets)}enableValidation(){this._formElement.addEventListener("submit",e=>{e.preventDefault()}),this._setEventListeners()}}class r{constructor({baseUrl:e,headers:t}){this._baseUrl=e,this._headers=t}_isResponseOk(e){return e.ok?e.json():Promise.reject(`Ошибка: ${e.status}`)}getDataRequest(e){return fetch(`https://${this._baseUrl}/data/${e}`,{headers:this._headers}).then(e=>this._isResponseOk(e))}getCustomRequest(e){return fetch(`https://${this._baseUrl}/custom/${e}`,{headers:this._headers}).then(e=>this._isResponseOk(e))}getSharedTable(e){return fetch(`https://${this._baseUrl}/${e}`,{headers:this._headers}).then(e=>this._isResponseOk(e))}getReviewRequest(e){return fetch(`https://${this._baseUrl}/reviews/${e}`,{headers:this._headers}).then(e=>this._isResponseOk(e))}sendForm(e,t){return fetch(`https://${this._baseUrl}/forms/${e}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),isBase64Encoded:!1}).then(e=>(console.log(e),this._isResponseOk(e)))}}class a{constructor({formSubmitHandler:e,formCleanError:t,checherValidation:s},n,r){this._formSubmitHandler=e,this._formCleanError=t,this._formElement=n,this._inputSelector=r,this._checker=s}_getInputValues(){return this._inputList=this._formElement.querySelectorAll(this._inputSelector),this._formValues={},this._inputList.forEach(e=>{"checkbox"===e.type?(this._formValues[e.name]||(this._formValues[e.name]=[]),e.checked&&this._formValues[e.name].push(e.value)):"radio"===e.type?e.checked&&(this._formValues[e.name]=e.value):this._formValues[e.name]=e.value}),localStorage.getItem("clientId")&&(this._formValues.clientId=localStorage.getItem("clientId")),this._formValues.page=window.location.pathname,console.log("Поля формы на отправку",this._formValues),this._formValues}cleanAll(){this._formElement.reset(),this._formCleanError()}setEventListeners(){this._formElement.addEventListener("submit",e=>{e.preventDefault(),this._checker()&&this._formSubmitHandler(this._getInputValues())})}}function i(e,t,s,n,r){switch(e){case"default":default:t.textContent=s;break;case"loading":t.textContent=n;break;case"sended":t.textContent=r}}const o={inputSelector:".form__input",submitButtonSelector:".form__submit-button",inactiveButtonClass:"form__submit-button_disabled",inputErrorClass:"form__input_type_error",errorClass:"form__input-error_visible"};function l(e){const{formSelector:t,formId:s,handleCloseCallback:l,handleSuccessSendedCallback:c,buttonText:h="Оставить заявку",loadingText:d="Отправляем...",successText:u="Отправлено успешно!",newFormConfig:_,isStepValidation:m=!1,dataTransformCallback:p}=e,y=_||o;console.log("configForm",y);const f=document.querySelector(t);if(!f)return void console.warn(`Форма ${t} не найдена`);const b=f.querySelector(y.submitButtonSelector),g=new r({baseUrl:"api.dromotron.ru",headers:{Accept:"application/json","Content-Type":"application/json;charset=utf-8"}}),C=new n(y,f);m?C.enableStepValidation():C.enableValidation();const S=new a({formSubmitHandler:e=>{let t=e;p&&(t=p(e)),i("loading",b,h,d,u),g.sendForm(s,t).then(t=>{i("sended",b,h,d,u),c?.(t,e)}).catch(e=>console.log(e)).finally(()=>{f.reset(),setTimeout(()=>{i("default",b,h,d,u)},900),l&&l()})},formCleanError:()=>{},checherValidation:e=>!C.hasInvalidInput()||(C.showErrors(),!1)},f,y.inputSelector);return S.setEventListeners(),{form:f,formValidator:C,formStatic:S}}}},t={};function s(n){var r=t[n];if(void 0!==r)return r.exports;var a=t[n]={exports:{}};return e[n](a,a.exports,s),a.exports}s.d=(e,t)=>{for(var n in t)s.o(t,n)&&!s.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),s.p="/";class n{constructor({cardTemplateSelector:e,cardSelector:t,configFields:s,cardObj:n,handleCardClick:r},i=null){this._handleCardClick=r,this._cardTemplateSelector=e,this._cardSelector=t,this._dynamicRenderer=i||new a(s),this._cardObj=n}_getTemplate(){return document.querySelector(this._cardTemplateSelector).content.querySelector(this._cardSelector).cloneNode(!0)}generateCard(){return this._element=this._getTemplate(),console.log(this._configBySelector),this._dynamicRenderer._configElementsMap(this._element),console.log(this._elementsMap),this._dynamicRenderer._renderObj(this._cardObj),this._setEventListeners(),this._element}_setEventListeners(){this._handleCardClick&&this._element.addEventListener("mousedown",()=>{this._handleCardClick(this._cardObj,this._element)})}}class r{constructor({data:e,renderer:t,el:s},n,r=0){this._renderedItems=e,this._container=s?s.querySelector(n):document.querySelector(n),this._renderer=t,this._delay=0,this._delayTime=r}hideParentEl(){this._container.closest(".parent-sect").style.display="none"}setItem(e){this._container.prepend(e)}setData(e){this._renderedItems=e}setItems(e){this._renderedItems=e}appendItem(e){this._container.append(e)}clear(){this._container.innerHTML="",this._delay=0}renderFiltered(e){this.clear(),this._renderedItems=e,this._renderedItems.forEach(e=>{this._renderer(e)}),0===e.length&&(this._container.textContent="По Вашему условию поиска статей пока нет.")}renderItems(){this._renderedItems.forEach(e=>{e["data-wow-delay"]=this._delay/1e3+"s",setTimeout(()=>{this._renderer(e)},this._delay),this._delay+=this._delayTime})}renderItem(e){this._renderer(e)}renderItemsSlice(e,t){this.clear(),this._renderedItems.slice(e,t).forEach(e=>{this._renderer(e)})}renderItemsFilteredByKey(e,t){this.clear(),this._renderedItems.filter(s=>s[e]===t).forEach(e=>{this._renderer(e)})}}class a{constructor(e){this._configFields=e,this._elementsMap=new Map,this._sectionsMap=new Map;const t={};e.forEach(e=>{t[e.selector]||(t[e.selector]=[]),t[e.selector].push(e)}),this._configBySelector=t}_configElementsMap(e){Object.keys(this._configBySelector).forEach(t=>{const s=e.querySelector(t);s?this._configBySelector[t].forEach(a=>{if(this[a.privateVarname]=s,"array"!==a.whatChange)this._elementsMap.set(a.privateVarname,{element:s,whatChange:a.whatChange,keyInData:a.key_in_dataobj,formatter:a.formatter||!1,type:"property"});else{this._elementsMap.set(a.privateVarname,{element:s,whatChange:a.whatChange,keyInData:a.key_in_dataobj,type:"array"});const i=a.configForInnerSection,o=new r({items:[],el:e,renderer:e=>{const t=new n({cardTemplateSelector:i.cardTemplateSelector,cardSelector:i.cardSelector,configFields:i.configFields,cardObj:e}).generateCard();o.appendItem(t)}},t);this._sectionsMap.set(a.privateVarname,o)}}):console.warn(`Элемент с селектором ${t} не найден в карточке`)})}_setProperty(e,t){const s=e.element,n=e.whatChange,r=e.keyInData,a=e.formatter||!1;null===t[r]&&(s.closest(".parent-sect")&&(s.closest(".parent-sect").style.display="none"),console.log("element.closest('.parent-sect')",s.closest(".parent-sect"))),s&&void 0!==t[r]&&null!==t[r]&&("textContent"===n?s.textContent=a?a(t[r]):t[r]:"innerHTML"===n?s.innerHTML=a?a(t[r]):t[r]:"src"===n?s.src=a?a(t[r]):t[r]:"alt"===n?s.alt=a?a(t[r]):t[r]:n in s&&(s[n]=a?a(t[r]):t[r]))}_renderArray(e,t,s){const n=e.keyInData,r=this._sectionsMap.get(t);console.log("Пытаемся отрендерить массивчик тегов data[dataKey]=",s[n],Array.isArray(s[n])),console.log(this._sectionsMap),console.log("config.",e),r&&Array.isArray(s[n])&&(r._container.closest(".parent-sect")&&!s[n].length&&(console.log("YOOOO section._container.closest"),r._container.closest(".parent-sect").style.display="none"),console.log("element.closest('.parent-sect')",r),e.element.innerHTML="",r.setItems(s[n]),r.renderItems())}_renderObj(e){this._elementsMap.forEach((t,s)=>{"property"===t.type&&this._setProperty(t,e)}),this._elementsMap.forEach((t,s)=>{"array"===t.type&&this._renderArray(t,s,e)})}_clearObj(){this._sectionsMap.forEach((e,t)=>{const s=this._elementsMap.get(t);s&&s.element&&(s.element.innerHTML="")}),this._elementsMap.forEach((e,t)=>{const s=e.element,n=e.whatChange;s&&("textContent"===n||"innerHTML"===n?s[n]="":"src"===n?s.src="":"alt"===n?s.alt="":"value"===n&&(s.value=""))})}updateField(e,t){const s=this._elementsMap.get(e);s&&s.element&&(s.element[s.whatChange]=t)}}const i={cardTemplateSelector:"#product-card-template",cardSelector:".product-card",configFields:[{selector:".card__image",whatChange:"src",privateVarname:"_imageEl",key_in_dataobj:"image_name"},{selector:".card__image",whatChange:"alt",privateVarname:"_imageAlt",key_in_dataobj:"title"},{selector:".card__title",whatChange:"textContent",privateVarname:"_titleEl",key_in_dataobj:"title"},{selector:".card__price",whatChange:"textContent",privateVarname:"_priceEl",key_in_dataobj:"price",formatter:e=>`${e} руб.`},{selector:".card__weight",whatChange:"textContent",privateVarname:"_weightEl",key_in_dataobj:"weight",formatter:e=>`Вес: ${e} кг`},{selector:".cart-quantity",whatChange:"value",privateVarname:"_quantityInput",key_in_dataobj:"count",defaultValue:"1"},{selector:".cart-btn-minus",whatChange:"dataset.action",privateVarname:"_minusBtn",key_in_dataobj:"id",defaultValue:"decrease"},{selector:".cart-btn-plus",whatChange:"dataset.action",privateVarname:"_plusBtn",key_in_dataobj:"id",defaultValue:"increase"},{selector:".card__link",whatChange:"href",privateVarname:"_linkEl",key_in_dataobj:"linkPath",formatter:e=>`/${e}`}],dataobj_test:{image_name:"plast-ti025-1234-L.png",linkPath:"komplektuyushchie-dlya-teploobmennikov/plates/ti025/ti025-aisi316-l-1234-0_4-mm.html",price:"316",title:"Пластина ТИ025 1.4401/AISI316 0.4mm L 1234",weight:"0.136",id:"product-12345",initial_quantity:"1"}};class o extends n{constructor({handleIncreaseInCart:e,handleDecreaceInCart:t,handleRemoveFromCart:s,handleSomeElementNull:n,...r},i,o){super(r,i),this._handleIncreaseInCart=e,this._handleDecreaceInCart=t,this._handleRemoveFromCart=s,this._handleSomeElementNull=n,this._cart=o,this._dynamicRenderer=new a(r.configFields)}generateCard(){return this._element=super.generateCard(),this._element}updateCard(){const e=this._cart.getItems(),t=e[this._cardObj.linkPath]?.quantity||0;0===t?this._handleSomeElementNull():this._dynamicRenderer.updateField("_quantityInput",t)}_setEventListeners(){super._setEventListeners(),this._dynamicRenderer._elementsMap.get("_plusBtn").element.addEventListener("click",()=>{this._handleIncreaseInCart(this._cardObj)}),this._dynamicRenderer._elementsMap.get("_minusBtn").element.addEventListener("click",()=>{this._handleDecreaceInCart(this._cardObj)})}}var l=s(824);const c=new a(i.configFields),h=document.querySelector("#item-data"),d=JSON.parse(h.textContent),u=document.querySelector(".product-page-main").dataset.uniqueid,_=(l.N.getItem(u),document.querySelector(".cart-button")),m=document.querySelector(".cart-link"),p=new r({data:[],renderer:e=>{const t=new o({...i,cardObj:e,handleIncreaseInCart:e=>{console.log(u,e.linkPath),l.N.addItem(e.linkPath),t.updateCard(),(0,l.k)()},handleDecreaceInCart:e=>{l.N.removeItem(e.linkPath),t.updateCard(),(0,l.k)()},handleSomeElementNull:()=>{_.textContent="В корзину",_.disabled=!1,y()}},c,l.N),s=t.generateCard();p.appendItem(s)}},".cart-main-control");function y(){const e=l.N.getItem(u);p.setItems(e?[{...d,count:e.quantity}]:[]),e?(_.textContent="В корзине",_.disabled=!0,m.style.visibility="visible",p.renderItems()):(_.textContent="В корзину",_.disabled=!1,m.style.visibility="hidden",p.clear())}y(),_.addEventListener("click",()=>{l.N.addItem(d.linkPath),y(),(0,l.k)()})})();