(()=>{var l=Object.defineProperty;var a=Object.getOwnPropertySymbols;var S=Object.prototype.hasOwnProperty,f=Object.prototype.propertyIsEnumerable;var d=(r,t,e)=>t in r?l(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,h=(r,t)=>{for(var e in t||(t={}))S.call(t,e)&&d(r,e,t[e]);if(a)for(var e of a(t))f.call(t,e)&&d(r,e,t[e]);return r};var n,o;function m(){n.dataset.navState="displayed",n.classList.remove("state-off"),n.classList.add("state-on"),o.classList.add("a-show")}function c(){n.dataset.navState="hidden",n.classList.remove("state-on"),n.classList.add("state-off"),o.classList.add("a-hide"),o.classList.remove("a-show"),setTimeout(()=>{o.classList.remove("a-hide")},300)}function u(){console.log("HUD init"),n=document.querySelector(".hud .nav-toggle"),o=document.querySelector(".hud .navigation"),n.addEventListener("click",r=>{r.currentTarget.dataset.navState!="displayed"?m():c()})}var i=class{constructor(t,e,s){this.screens={},this.routesMap={},this.currentScreen=null,this.eventsHandlers={switch:[]},this.screensContainer=document.querySelector(t),this.loader=document.querySelector(e),this.errorScreen=document.querySelector(s),console.log("Screens Init")}add(t,e){if(typeof e!="object")return console.error("Screens: screens must be object");if(typeof(e==null?void 0:e.alias)=="undefined")return console.error("Screens: undefined alias");if(typeof(e==null?void 0:e.renderer)!="function")return console.error("Screens: renderer must be function");this.screens[e.alias]=h({route:t},e),this.routesMap[t]=e.alias}switch(t){var s;if(this.runSwitchHandlers(t),this.showLoader(),(s=this.currentScreen)==null||s.DOMObject.remove(),typeof this.screens[t]=="undefined"){console.error(`Screens: "${t}" not found`);return}this.currentScreen=this.screens[t];let e=document.createElement("div");e.classList.add("screen"),e.id=t,e.dataset.alias=t,e.innerHTML=this.currentScreen.renderer(),this.currentScreen.DOMObject=e,this.screensContainer.append(this.currentScreen.DOMObject),this.currentScreen.initer(this)}routing(){setInterval(()=>{let t=document.location.hash.split("#!")[1];if(typeof t=="undefined"||t=="")return;let e=typeof this.routesMap[t]=="undefined"?"not-found-screen":this.routesMap[t];(!this.currentScreen||this.currentScreen.alias!=e)&&this.switch(e)},50)}ready(){this.currentScreen!=null&&(this.currentScreen.DOMObject||(this.currentScreen.DOMObject=document.getElementsById(this.currentScreen.alias)),this.hideLoader(),this.currentScreen.DOMObject.classList.add("a-show"))}error(t,e){var s;(s=this.currentScreen)==null||s.DOMObject.remove(),this.errorScreen.querySelector(".error-title").innerHTML=t,this.errorScreen.querySelector(".error-text").innerHTML=e,this.showErrorScreen()}hideLoader(){this.loader.classList.remove("a-show")}showLoader(){this.loader.classList.add("a-show")}showErrorScreen(){this.errorScreen.classList.add("a-show")}hideErrorScreen(){this.errorScreen.classList.remove("a-show")}getScreens(){return this.screens}getRoutesMap(){return this.routesMap}onSwitch(t){this.eventsHandlers.switch.push(t)}runSwitchHandlers(t){for(let e of this.eventsHandlers.switch)e(this,t)}};document.addEventListener("DOMContentLoaded",r=>{console.log("App init"),u();let t=new i(".screens",".load-screen",".error-screen");t.add("/",{alias:"home",renderer:()=>'<h2 class="mt-4">Hello world</h2>',initer:e=>{setTimeout(()=>e.ready(),1e3),setTimeout(()=>e.error("Error","Just testing"),2e3)}}),t.add("-",{alias:"not-found-screen",renderer:()=>'<h2 class="mt-4">404 NOT FOUND</h2>',initer:e=>{e.ready()}}),console.log(t.getScreens()),t.onSwitch((e,s)=>{c()}),t.routing()});})();
//# sourceMappingURL=main.js.map