/*! phoscon-app 2025-08-29 */

import{StateEvents,WifiEvents,ButtonEvents,UiStates,Types}from"./state-constants.js";const subStateHandlerMap={};let stateNotConfiguredHandler=()=>{};function appSetNotConfiguredState(state){if(!state)throw new Error("state is missing");if(stateNotConfiguredHandler(StateEvents.LEAVE_STATE),!(state in subStateHandlerMap))throw new Error("state not found: "+state);(stateNotConfiguredHandler=subStateHandlerMap[state])(StateEvents.ENTER_STATE),app.router.navigate("//"+state,{trigger:!0})}export const clientNotConfiguredHandlerFactory=(view,setState,wifi,setSubState=appSetNotConfiguredState)=>(event,args)=>{if(event===StateEvents.ENTER_STATE)subStateHandlerMap[UiStates.CLIENT_NOT_CONFIGURED_CONNECTED]=clientConnectedHandlerFactory(view,setSubState,wifi),subStateHandlerMap[UiStates.CLIENT_NOT_CONFIGURED_NOT_CONNECTED_LIST]=clientNotConnectedListHandlerFactory(view,setSubState,wifi),subStateHandlerMap[UiStates.CLIENT_NOT_CONFIGURED_NOT_CONNECTED_EMPTY]=clientNotConnectedEmptyHandlerFactory(view,setSubState,wifi),wifi.get("workingtype")===Types.CLIENT?setSubState(UiStates.CLIENT_NOT_CONFIGURED_CONNECTED):wifi.get("wifiavailable").length>=1?setSubState(UiStates.CLIENT_NOT_CONFIGURED_NOT_CONNECTED_LIST):setSubState(UiStates.CLIENT_NOT_CONFIGURED_NOT_CONNECTED_EMPTY);else if(event===StateEvents.LEAVE_STATE)view.hide();else if(event===WifiEvents.USER_CONFIG_CHANGED||event===WifiEvents.WORKING_CONFIG_CHANGED)stateNotConfiguredHandler(StateEvents.LEAVE_STATE),setState(UiStates.CLIENT);else if(event===WifiEvents.CONFIG_CHANGED)wifi.get("wifiavailable").length>=1?setSubState(UiStates.CLIENT_NOT_CONFIGURED_NOT_CONNECTED_LIST):setSubState(UiStates.CLIENT_NOT_CONFIGURED_NOT_CONNECTED_EMPTY);else if(stateNotConfiguredHandler(event)===StateEvents.NOT_HANDLED)if(event===ButtonEvents.TAB_AP_PRESSED)stateNotConfiguredHandler(StateEvents.LEAVE_STATE),setState(UiStates.AP);else{if(event!==ButtonEvents.CONNECT_TO_CLIENT_PRESSED||!wifi.get("eth0"))return StateEvents.NOT_HANDLED;setState(UiStates.CASE_1_PAGE_1,args)}};const clientConnectedHandlerFactory=(view,setState,wifi)=>event=>{if(event===StateEvents.ENTER_STATE)view.show(),view.showList();else{if(event!==StateEvents.LEAVE_STATE)return StateEvents.NOT_HANDLED;view.hide()}},clientNotConnectedListHandlerFactory=(view,setState,wifi)=>event=>{if(event===StateEvents.ENTER_STATE)view.show(),view.showList();else{if(event!==StateEvents.LEAVE_STATE)return StateEvents.NOT_HANDLED;view.hide()}},clientNotConnectedEmptyHandlerFactory=(view,setState,wifi)=>event=>{if(event===StateEvents.ENTER_STATE)view.show(),view.showEmpty();else{if(event!==StateEvents.LEAVE_STATE)return StateEvents.NOT_HANDLED;view.hide()}};