(()=>{var t={985:(t,e,s)=>{"use strict";s.r(e),s.d(e,{createForm:()=>l});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}: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(t=>t.classList.add(...this._showErrorsAnimationClasses,...this._showErrorsTransitionsClasses))}_animateErrMessage(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)})})}_setStepEventListeners(t){t.forEach(t=>{const e=t.inputs,s=t.button;console.log(`123 ${s}`),e.forEach(t=>{t.addEventListener("input",()=>{this._checkInputValidity(t),this._toggleButtonState(e,s)})})})}checkStep(t){const e=this._sets[t].inputs,s=this._sets[t].button;return!this._hasInvalidInput(e)||(this._showErrors(e,s),this._toggleButtonState(e,s),!1)}enableStepValidation(){this._sets=[];const t=this._formElement.querySelector(".first-step"),e=t.querySelector(".first-step-button"),s=Array.from(t.querySelectorAll(this._inputSelector));this._sets.push({inputs:s,button:e});const r=this._formElement.querySelector(".second-step"),i=r.querySelector(".second-step-button"),o=Array.from(r.querySelectorAll(this._inputSelector));this._sets.push({inputs:o,button:i}),this._setStepEventListeners(this._sets)}enableValidation(){this._formElement.addEventListener("submit",t=>{t.preventDefault()}),this._setEventListeners()}}class i{constructor({baseUrl:t,headers:e}){this._baseUrl=t,this._headers=e}_isResponseOk(t){return t.ok?t.json():Promise.reject(`Ошибка: ${t.status}`)}getDataRequest(t){return fetch(`https://${this._baseUrl}/data/${t}`,{headers:this._headers}).then(t=>this._isResponseOk(t))}getCustomRequest(t){return fetch(`https://${this._baseUrl}/custom/${t}`,{headers:this._headers}).then(t=>this._isResponseOk(t))}getSharedTable(t){return fetch(`https://${this._baseUrl}/${t}`,{headers:this._headers}).then(t=>this._isResponseOk(t))}getReviewRequest(t){return fetch(`https://${this._baseUrl}/reviews/${t}`,{headers:this._headers}).then(t=>this._isResponseOk(t))}sendForm(t,e){return fetch(`https://${this._baseUrl}/forms/${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e),isBase64Encoded:!1}).then(t=>(console.log(t),this._isResponseOk(t)))}}class o{constructor({formSubmitHandler:t,formCleanError:e,checherValidation:s},r,i){this._formSubmitHandler=t,this._formCleanError=e,this._formElement=r,this._inputSelector=i,this._checker=s}_getInputValues(){return this._inputList=this._formElement.querySelectorAll(this._inputSelector),this._formValues={},this._inputList.forEach(t=>{"checkbox"===t.type?(this._formValues[t.name]||(this._formValues[t.name]=[]),t.checked&&this._formValues[t.name].push(t.value)):"radio"===t.type?t.checked&&(this._formValues[t.name]=t.value):this._formValues[t.name]=t.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",t=>{t.preventDefault(),this._checker()&&this._formSubmitHandler(this._getInputValues())})}}function n(t,e,s,r,i){switch(t){case"default":default:e.textContent=s;break;case"loading":e.textContent=r;break;case"sended":e.textContent=i}}const a={inputSelector:".form__input",submitButtonSelector:".form__submit-button",inactiveButtonClass:"form__submit-button_disabled",inputErrorClass:"form__input_type_error",errorClass:"form__input-error_visible"};function l(t){const{formSelector:e,formId:s,handleCloseCallback:l,handleSuccessSendedCallback:h,buttonText:u="Оставить заявку",loadingText:c="Отправляем...",successText:_="Отправлено успешно!",newFormConfig:d,isStepValidation:m=!1,dataTransformCallback:p}=t,f=d||a;console.log("configForm",f);const E=document.querySelector(e);if(!E)return void console.warn(`Форма ${e} не найдена`);const b=E.querySelector(f.submitButtonSelector),S=new i({baseUrl:"api.dromotron.ru",headers:{Accept:"application/json","Content-Type":"application/json;charset=utf-8"}}),v=new r(f,E);m?v.enableStepValidation():v.enableValidation();const y=new o({formSubmitHandler:t=>{let e=t;p&&(e=p(t)),n("loading",b,u,c,_),S.sendForm(s,e).then(e=>{n("sended",b,u,c,_),h?.(e,t)}).catch(t=>console.log(t)).finally(()=>{E.reset(),setTimeout(()=>{n("default",b,u,c,_)},900),l&&l()})},formCleanError:()=>{},checherValidation:t=>!v.hasInvalidInput()||(v.showErrors(),!1)},E,f.inputSelector);return y.setEventListeners(),{form:E,formValidator:v,formStatic:y}}}},e={};function s(r){var i=e[r];if(void 0!==i)return i.exports;var o=e[r]={exports:{}};return t[r](o,o.exports,s),o.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.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};const{createForm:r}=s(985);r({formSelector:"#formFreePopup",formId:"base-form",loadingText:"Отправляем в Дромотрон..."})})();