/*! phoscon-app 2023-07-31 */

import*as constants from"./group-switches/constants.js";import{getMachine}from"./group-switches/machine.js";import{getMainView}from"./group-switches/main-view.js";import{getSwitchListView}from"./group-switches/switchList-view.js";import{getResourceListView}from"./group-switches/resourceList-view.js";import{getRlFunctionListView}from"./group-switches/rlFunctionList-view.js";import{getSwitchWizardView}from"./group-switches/wizard-view.js";function initViewAndLogic(){const views={mainView:getMainView(constants),switchListView:getSwitchListView(constants),resourceListView:getResourceListView(constants),rlFunctionListView:getRlFunctionListView(constants),switchWizardView:getSwitchWizardView(constants)};loadLanguage();const router=new(Backbone.Router.extend({routes:{"":"showSwitchList","switch/:swid":"showActiveSwitch","switch/:swid/resource/:rlid/func/:fid":"showActiveResource","*path/wizard/:page":"showWizard"},initialize:function(){this.initCall=!0},showSwitchList:function(){delete app.session.swid,delete app.session.rlid,delete app.session.fid,service.send(constants.States.IDLE)},showActiveSwitch:function(swid){delete app.session.rlid,delete app.session.fid,app.session.swid=swid,service.send(constants.States.ACTIVESW)},showActiveResource:function(swid,rlid,fid){app.session.rlid=rlid,app.session.fid=fid,service.send(constants.States.ACTIVERL)},showWizard:function(path,page){service.send(page),this.initCall&&app.session.swid&&service.send(constants.States.ACTIVESW),this.initCall&&app.session.rlid&&service.send(constants.States.ACTIVERL),delete this.initCall}}));router.on("route",function(route,params){console.log("Different Page: "+route)});let{service:service,machine:machine}=getMachine(constants,views,router);Object.values(views).forEach(view=>{view.service=service,view.subView&&(view.subView.service=service)}),Backbone.history.start();let menuBtn=document.querySelector("#menu-btn");menuBtn.onclick=void 0,menuBtn.addEventListener("click",()=>{if(screenMax(SCREEN_MAX_WIDTH_PHONE_PORTRAIT)){let currentState=service.state.value||"";service.send({type:constants.Events.MENU_BTN_PRESSED,currentState:currentState})}else openNav()})}initApp(),restGetResource(app.resourcelinks).then(()=>restGetResource(app.rules)).then(()=>restGetResource(app.scenes)).then(()=>restGetResource(app.sensors)).then(()=>initViewAndLogic()).catch(console.log);