/*! phoscon-app 2024-02-26 */

import{checkLogin,checkAppType}from"./helper-functions.js";import{types}from"./constants.js";import{discoverGateways}from"./discovery-functions.js";export var overviewHandlerFactory=(view,states)=>(ctx,event)=>{let evType=event.type,service=ctx.service;if(evType!=states.GATEWAY){if(evType==states.OVERVIEW)if(app.lastlogin&&""!==app.lastlogin){let gwid=app.lastlogin||void 0,gw=app.gateways.get(gwid)||void 0;gw&&gwid?checkLogin(gwid,gw,service):(view.show(),discoverGateways(service))}else view.show(),discoverGateways(service);else if("GW_PRESSED"==evType){let gwid=event.gwid||void 0,gw=app.gateways.get(gwid)||void 0;checkLogin(gwid,gw,service)}}else view.hide()};export var listHandlerFactory=(view,states)=>(ctx,event)=>{event.type===states.OVERVIEW_LIST?view.show():view.hide()};export var scanHandlerFactory=(view,states)=>(ctx,event)=>{let evType=event.type,service=ctx.service;evType===states.START_SCAN&&(app.probeWorker.postMessage({scan:!0}),searchGateways(),view.showProgress()),evType===states.STOP_SCAN&&(app.probeWorker.postMessage({scan:!1}),stopSearchGateways(),view.hideProgress()),evType===states.DISCOVERY_FAILED&&0===app.gateways.length&&"APP_LOCAL"===checkAppType()&&(view.showProgress(),service.send(states.START_SCAN)),evType===states.DISCOVERY_FAILED&&"APP_SMARTPHONE"===checkAppType()&&(!0===app.smartphoneReady?app.Devicetype.sendMessage("START_SEARCH_GATEWAYS",""):setTimeout(function(){service.send(states.DISCOVERY_FAILED)},1e3))};