/*! phoscon-app 2025-10-13 */

import{WifiEvents,GatewayEvents,GeneralStates,UiStates}from"./settings-network/state-constants.js";import{appSetState,createStateHandlerViews,initStateHandlerMap}from"./settings-network/state-handler.js";import{wifiPageActiveIndication}from"./settings-network/network-main-functions.js";function parseWifis(config){const wa=config.wifiavailable||[];return wa.forEach(x=>x.id=x.ssid),wa}function syncWifis(method,model,options){return"patch"===method&&(method="update"),Backbone.sync(method,model,options)}function wifiObserver(){app.stateEventHandler(WifiEvents.CONFIG_CHANGED)}function gwObserver(e){"reachable"===e.status?app.stateEventHandler(GatewayEvents.GW_REACHABLE):"not-reachable"===e.status&&app.stateEventHandler(GatewayEvents.GW_NOT_REACHABLE)}initApp(),app.WifiStation=Backbone.Model.extend({}),app.WifiCollection=Backbone.Collection.extend({name:"wifis",model:app.WifiStation,url:"//"+app.session.gw+"/api/"+app.apikey+"/config/wifi",parse:parseWifis,sync:syncWifis}),app.wifiStations=new app.WifiCollection,restGetResource(app.wifi).then(()=>{setInterval(()=>{!1===document.hidden&&wifiPageActiveIndication()},5e3),setInterval(()=>app.poll.pollOnce(app.wifi),1e3),setInterval(()=>app.poll.pollOnce(app.wifiStations),1e3),app.listenTo(app.wifi,"change:state",wifiObserver),app.listenTo(app.wifi,"change:type change:name",()=>app.stateEventHandler(WifiEvents.USER_CONFIG_CHANGED)),app.listenTo(app.wifi,"change:workingtype change:workingname",()=>app.stateEventHandler(WifiEvents.WORKING_CONFIG_CHANGED)),app.on("gateway-status",gwObserver),app.wifiStations.fetch(),screenMin(SCREEN_MIN_WIDTH_TABLET_PORTRAIT)&&openNav()}).then(()=>createStateHandlerViews()).then(()=>initStateHandlerMap()).then(()=>loadLanguage()).then(()=>appSetState(GeneralStates.INIT_HANDLER)).catch(err=>console.log("%c"+err,ERROR)),app.Router=Backbone.Router.extend({routes:{"//:state":"setState"}}),Backbone.History.started||(app.router=new app.Router,Backbone.history.start());