(()=>{"use strict";class e{constructor({cardTemplateSelector:e,cardSelector:t,animateClass:s}){this._cardSelector=t,this._cardTemplateSelector=e,this._animateClass=s}_getTemplate(){return document.querySelector(this._cardTemplateSelector).content.querySelector(this._cardSelector).cloneNode(!0)}generateCard(){return this._element=this._getTemplate(),this._element}}class t extends e{constructor({title:e,equipment:t,location:s,region:r,handleProjectClick:n,...i}){super(i),this._title=e,this._equipment=t,this._location=s,s||console.log(" Undefined?",s),this._region=r,this._handleProjectClick=n}generateCard(){return this._element=super._getTemplate(),this._cardTitleEl=this._element.querySelector(".card-title"),this._cardTitleEl.textContent=this._title,this._cardEquipmentEl=this._element.querySelector(".card-equipment"),this._cardEquipmentEl.textContent=this._equipment,this._cardTitleEl=this._element.querySelector(".card-reg-and-location"),this._cardTitleEl.textContent=`${this._region}${this._location?` (${this._location})`:""}`,this._setEventListeners(),this._element}_setEventListeners(){this._element.addEventListener("mousedown",(()=>{this._handleProjectClick(this._title,this._equipment)}))}}const s=new class{constructor({baseUrl:e,headers:t}){this._baseUrl=e,this._headers=t}_isResponseOk(e){return e.ok?e.json():Promise.reject(`Ошибка: ${e.status}`)}getSskObjects(){return fetch("https://api.ssk22.ru/data/objects",{headers:this._headers}).then((e=>this._isResponseOk(e)))}getInitialNews(){return fetch("https://api.ssk22.ru/news",{headers:this._headers}).then((e=>this._isResponseOk(e)))}sendCallForm(e){return fetch(`${this._baseUrl}`,{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}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then((e=>this._isResponseOk(e)))}}({baseUrl:"https://api.ssk22.ru",headers:{"Content-Type":"application/json"}}),r=document.querySelector(".object-section"),n=new class{constructor({data:e,renderer:t},s,r=200){this._renderedItems=e||[],this._container=document.querySelector(s),this._renderer=t,this._delay=0,this._delayTime=r}setData(e){this._renderedItems=e}setItem(e){this._container.prepend(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.innerHTML='
Тепловой пункт в пути или проходит пуско-наладку :) Скоро опубликуем!
')}renderItems(){this._renderedItems.forEach((e=>{e["data-wow-delay"]=this._delay/1e3+"s",setTimeout((()=>{this._renderer(e)}),this._delay),this._delay+=this._delayTime}))}}({data:null,renderer:e=>{const s=new t({...e,handleProjectClick:(e,t)=>{console.log("Это коллбэк из объекта",e,t)},cardTemplateSelector:"#card-object-template",cardSelector:".card"}).generateCard();n.appendItem(s)}},".object-list"),i=document.querySelector(".objects-more-button");i.addEventListener("click",(async e=>{i.classList.add("hidden"),await async function(){const e=document.createElement("div");e.classList.add("p-4","font-medium"),e.textContent="Загружаем...",n.appendItem(e);const t=await s.getSskObjects();r.scrollIntoView({behavior:"smooth"}),n.clear(),n.setData(t),n.renderItems()}()}))})();