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

const{Machine:Machine,actions:actions}=XState,{interpret:interpret}=XStateInterpreter,{choose:choose}=actions;export const getMachine=(view,{states:states,noOptStates:noOptStates,events:events},factorys)=>{const reqFactoryFunc=factorys.requestHandlerFactory(view,{states:states,noOptStates:noOptStates,events:events}),wsFactoryFunc=factorys.websocketHandlerFactory(view,{states:states,noOptStates:noOptStates,events:events});let onList={[states.NOTHING]:"noFilter",[states.CONFIG]:"config",[states.LIGHTS]:"lights",[states.PLUGS]:"plugs",[states.SWITCHES]:"switches",[states.SENSORS]:"sensors",[states.BLINDS]:"blinds",[states.THERMOSTATS]:"thermostats",[states.GROUPS]:"groups",[states.RULES]:"rules",[states.DEVICES]:"devices",[events.RADIOBTN_PRESSED]:{actions:"chooseApiEvents"},[events.WS_CHANGED]:{actions:"chooseApiEvents"},[events.TAB_PRESSED]:{actions:"chooseApiEvents"},[events.COPY_PRESSED]:{actions:["chooseApiEvents","showCopyFeedback"]},[events.RELOAD_PRESSED]:{actions:["chooseApiEvents","showReloadFeedback"]},[events.CLEAR_PRESSED]:{actions:["chooseApiEvents","showClearFeedback"]}},machine=Machine({id:"api",initial:"noFilter",context:{wsLog:{},activeLog:!1,activeState:"nothing",activeDevice:"all"},states:{noFilter:{on:{...onList},onEntry:"chooseApiEvents"},config:{on:{...onList},onEntry:"chooseApiEvents"},sensors:{on:{...onList,[events.CHECKBOX_PRESSED]:{actions:"chooseApiEvents"},[events.SELECTITEM_PRESSED]:{actions:"chooseApiEvents"}},onEntry:"chooseApiEvents"},switches:{on:{...onList,[events.SELECTITEM_PRESSED]:{actions:"chooseApiEvents"}},onEntry:"chooseApiEvents"},groups:{on:{...onList,[events.CHECKBOX_PRESSED]:{actions:"chooseApiEvents"},[events.SELECTITEM_PRESSED]:{actions:"chooseApiEvents"}},onEntry:"chooseApiEvents"},lights:{on:{...onList,[events.SELECTITEM_PRESSED]:{actions:"chooseApiEvents"}},onEntry:"chooseApiEvents"},plugs:{on:{...onList,[events.SELECTITEM_PRESSED]:{actions:"chooseApiEvents"}},onEntry:"chooseApiEvents"},blinds:{on:{...onList,[events.SELECTITEM_PRESSED]:{actions:"chooseApiEvents"}},onEntry:"chooseApiEvents"},thermostats:{on:{...onList,[events.SELECTITEM_PRESSED]:{actions:"chooseApiEvents"}},onEntry:"chooseApiEvents"},rules:{on:{...onList,[events.SELECTITEM_PRESSED]:{actions:"chooseApiEvents"}},onEntry:"chooseApiEvents"},devices:{on:{...onList,[events.SELECTITEM_PRESSED]:{actions:"chooseApiEvents"}},onEntry:"chooseApiEvents"}}},{actions:{showReloadFeedback:(ctx,event,{action:action})=>{view.showReloadFeedback()},showClearFeedback:(ctx,event,{action:action})=>{view.showClearFeedback()},showCopyFeedback:(ctx,event,{action:action})=>{view.showCopyFeedback()},chooseApiEvents:choose([{cond:(ctx,ev)=>(ev.tabId&&(ctx.activeLog="events"===ev.tabId),!!ctx.activeLog),actions:["callWsHandlerFactory"]},{cond:(ctx,ev)=>!ctx.activeLog,actions:["callReqHandlerFactory"]}]),callReqHandlerFactory:reqFactoryFunc,callWsHandlerFactory:wsFactoryFunc}}),service=interpret(machine).onTransition(state=>{console.log("machine event: "+state.event.type)});return service.start(),{machine:machine,service:service}};