/*! phoscon-app 2024-10-07 */

import*as constants from"./devices-plugs/constants.js";import*as factorys from"./devices-plugs/factory-functions.js";import{getView}from"./devices-plugs/overview-view.js";import{getDetailsView}from"./devices-plugs/details-view.js";import{getMachine}from"./devices-plugs/machine.js";function initLogic(){let views=getView(constants);views.detailsView=getDetailsView(constants);let{service:service}=getMachine(views,constants,factorys);Object.values(views).forEach(v=>{v.service=service,(v.views||[]).forEach(s=>s.service=service)}),app.plugs.on("add",function(){service.send("OVERVIEW"),Object.values(views.tableView.views).forEach(v=>{null===v.service&&(v.service=service)})}),loadLanguage(),app.navItem=document.querySelector("#dPlug").parentElement,app.navItem.addEventListener("click",()=>{app.router.navigate("table",{trigger:!0})}),app.headLeftBtn=document.querySelector(".header #menu-btn"),app.headLeftSvg=app.headLeftBtn.querySelector("use"),app.headLeftLabel=app.headLeftBtn.querySelector("span"),app.headLeftBtn.onclick=void 0,app.headLeftBtn.addEventListener("click",function(){screenMax(SCREEN_MAX_WIDTH_PHONE_LANDSCAPE)&&isThisPortrait()&&document.location.hash.indexOf("plug/")>0?app.router.navigate("table",{trigger:!0}):openNav()});var Router=Backbone.Router.extend({routes:{"plug/:id":"showPlugDetails",table:"showPlugTable"},showPlugDetails:function(id){app.navItem.classList.add("sub-item"),app.session.pid=id;let p=app.plugs.get(id);p&&service.send({type:"DETAILS",model:p}),screenMax(SCREEN_MAX_WIDTH_PHONE_LANDSCAPE)&&isThisPortrait()&&(app.headLeftSvg.setAttribute("xlink:href","#back-icon-sm"),app.headLeftLabel.textContent=translate("link_plugs"))},showPlugTable:function(url){app.session.pid=void 0,app.navItem.classList.remove("sub-item"),app.headLeftSvg.setAttribute("xlink:href","#icon-hamburger-sm"),app.headLeftLabel.textContent="",app.plugs.length>0?service.send("OVERVIEW"):service.send("EMPTY")}});app.router=new Router,Backbone.history.start(),setTimeout(pollDone,1e3);let route=window.location.href.split("#")[1];void 0!==route&&-1!==route.indexOf("plug")||app.router.navigate("table",{trigger:!0})}initApp(),restGetResource(app.config).then(()=>restGetResource(app.lights)).then(()=>restGetResource(app.sensors)).then(()=>restGetResource(app.groups)).then(res=>{setTimeout(()=>app.poll.pollRepeated(app.config),5e3),setTimeout(()=>app.poll.pollRepeated(app.lights),5e3),setTimeout(()=>app.poll.pollRepeated(app.sensors),5e3)}).then(()=>initLogic());