(()=>{"use strict";function t(t,e,s,r){e.textContent=t?r:s}const e={inputSelector:".formx__input",submitButtonSelector:".formx__submit-button",inactiveButtonClass:"formx__submit-button_disabled",inputErrorClass:"formx__inputt_type_error",errorClass:"formx__input-error_visible"},s=document.forms.vacancyForm,r=s.querySelector(e.submitButtonSelector),o=new class{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}_showInputError(t,e){const s=this._formElement.querySelector(`.${t.id}-error`);t.classList.add(this._inputErrorClass),s.textContent=e,s.classList.add(this._errorClass)}_hideInputError(t){const e=this._formElement.querySelector(`.${t.id}-error`);t.classList.remove(this._inputErrorClass),e.classList.remove(this._errorClass),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"))}disableSaveButton(){const t=this._formElement.querySelector(this._submitButtonSelector);t.classList.add(this._inactiveButtonClass),t.setAttribute("disabled",!0)}cleanAllErrors(){Array.from(this._formElement.querySelectorAll(this._inputSelector)).forEach((t=>{this._hideInputError(t)}))}_setEventListeners(){const t=Array.from(this._formElement.querySelectorAll(this._inputSelector)),e=this._formElement.querySelector(this._submitButtonSelector);this._toggleButtonState(t,e),t.forEach((s=>{s.addEventListener("input",(()=>{this._checkInputValidity(s),this._toggleButtonState(t,e)}))}))}enableValidation(){this._formElement.addEventListener("submit",(t=>{t.preventDefault()})),this._setEventListeners()}}(e,s);o.enableValidation();const i=new class{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/data/blogCards",{headers:this._headers}).then((t=>this._isResponseOk(t)))}getNews(){return fetch("https://api.termoblok.ru/news",{headers:this._headers}).then((t=>this._isResponseOk(t)))}getInitiatPartners(){return fetch("https://api.termoblok.ru/data/partners",{headers:this._headers}).then((t=>this._isResponseOk(t)))}sendCallForm(t){return fetch(`${this._baseUrl}/forms/small-form`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),isBase64Encoded:!1}).then((t=>(console.log(t),this._isResponseOk(t))))}sendBigForm(t){return fetch(`${this._baseUrl}/forms/big-form`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}).then((t=>this._isResponseOk(t)))}}({baseUrl:"https://api.termoblok.ru",headers:{Accept:"application/json","Content-Type":"application/json;charset=utf-8"}}),n=new class{constructor({formSubmitHandler:t,formCleanError:e},s,r){this._formSubmitHandler=t,this._formCleanError=e,this._formElement=s,this._inputSelector=r,this._absolutePopup=this._formElement.querySelector(".popup-absolute")}_getInputValues(){return this._inputList=this._formElement.querySelectorAll(this._inputSelector),this._formValues={},this._inputList.forEach((t=>{if(t.dataset.alias){if("moshnost"===t.name)return this._formValues[t.dataset.alias]=t.value+" "+this._formElement.t_typesr1.value;if("rashod"===t.name)return this._formValues[t.dataset.alias]=t.value+" "+this._formElement.t_typesr2.value;this._formValues[t.dataset.alias]=t.value}else 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(),this._absolutePopup.classList.contains("popup__form-fio_opened")&&(console.log("Открыто!"),this._absolutePopup.classList.remove("popup__form-fio_opened"))}setEventListeners(){this._formElement.addEventListener("submit",(t=>{t.preventDefault(),this._formSubmitHandler(this._getInputValues())}))}}({formSubmitHandler:e=>{t(!0,r,"Откликнуться","Отправляем..."),i.sendBigForm(e).then((t=>{console.log(t),n.cleanAll()})).catch((t=>console.log(t))).finally((()=>{o.disableSaveButton(),s.reset(),t(!1,r,"Откликнуться","Отправляем...")})),console.log(e)},formCleanError:()=>{}},s,e.inputSelector);n.setEventListeners()})();