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

import*as constants from"./group-time/constants.js";import*as factorys from"./group-time/factory-functions.js";import{getView}from"./group-time/overview-view.js";import{getEmptyView}from"./group-time/empty-view.js";import{getMachine}from"./group-time/machine.js";async function initLogic(){await loadLanguage(),app.currentSite="NAV_SCHEDULES";let views=getView(constants);views.emptyView=getEmptyView(constants);let{service:service}=getMachine(views,constants,factorys);Object.values(views).forEach(v=>{v.service=service,(v.views||[]).forEach(s=>s.service=service)}),0===views.scheduleListView.views.length?service.send({type:"EMPTY"}):service.send({type:"OVERVIEW"});let deleteBtn=document.querySelector("#deleteBtn"),renameBtn=document.querySelector("#btnRenameSchedule");deleteBtn.addEventListener("click",function(){service.send({type:constants.events.DELETE_CLICKED})}),renameBtn.addEventListener("click",function(){service.send({type:constants.events.RENAME_CLICKED})}),app.schedules.on("add",function(){service.send("OVERVIEW"),Object.values(views.scheduleListView.views).forEach(v=>{null===v.service&&(v.service=service,app.session.sid=v.model.get("id"),service.send({type:constants.events.SCHEDULE_SELECTED,view:v}))})}),app.Router=Backbone.Router.extend({routes:{schedules:"showSchedule","schedules/:sid":"showSchedule"},showSchedule:function(sid){app.session.sid=sid,screenMin(SCREEN_MIN_WIDTH_TABLET_PORTRAIT)&&views.scheduleListView.setActiveSchedule()}}),Backbone.History.started||(app.router=new app.Router,Backbone.history.start(),app.router.navigate("/schedules",{trigger:!0}));let navigation=document.querySelector("#navigation"),mainview=document.querySelector(".main"),menuBtnIcon=document.querySelector("#menu-btn svg use"),menuBtnLabel=document.querySelector("#menu-btn span"),headLeftBtn=document.querySelector(".header #menu-btn");document.querySelector("#ofGroupName").innerText=app.groups.get(app.session.gid).attributes.name,screenMax(SCREEN_MAX_WIDTH_PHONE_LANDSCAPE)&&isThisPortrait()&&(headLeftBtn.onclick=void 0,headLeftBtn.addEventListener("click",function(){"SCHEDULE_SETTINGS"===app.currentSite?(navigation.classList.remove("page-left"),mainview.classList.add("page-right"),menuBtnIcon.setAttribute("xlink:href","#icon-hamburger-sm"),menuBtnLabel.innerText="",app.currentSite="NAV_SCHEDULES"):openNav()}));let emptyStateDivAlarm=$("#first-empty-state-div"),emptyStateDivTimer=$("#second-empty-state-div"),bedroomLamp1=$("#lamp-bedroom-nightstand-left #rect4681"),bedroomLamp2=$("#lamp-bedroom-nightstand-right #path4582"),childroomLamp1=$("#lamp-nursery-top #rect4632"),childroomLamp2=$("#lamp-nursery-top #path4637");document.body.classList.contains("animation")&&screenMin(SCREEN_MIN_WIDTH_TABLET_PORTRAIT)&&setTimeout(()=>{emptyStateDivAlarm.animate({opacity:1},3e3,"swing",function(){setTimeout(()=>{bedroomLamp1.addClass("animate"),bedroomLamp2.addClass("animate")},3e3),setTimeout(()=>{emptyStateDivAlarm.animate({opacity:0},4e3,"swing",function(){setTimeout(()=>{emptyStateDivTimer.animate({opacity:1},2e3,"swing",function(){childroomLamp1.addClass("animate"),childroomLamp2.addClass("animate"),setTimeout(()=>{emptyStateDivTimer.animate({opacity:0},6e3,"swing",function(){})},7e3)})},1e3)})},5e3)})},1e3)}initApp(),restGetResource(app.config).then(()=>restGetResource(app.schedules)).then(()=>restGetResource(app.scenes)).then(()=>restGetResource(app.config)).then(res=>{setTimeout(()=>app.poll.pollRepeated(app.schedules),5e3),setTimeout(()=>app.poll.pollRepeated(app.scenes),5e3),setTimeout(()=>app.poll.pollRepeated(app.config),5e3)}).then(()=>initLogic());