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

export const initRouter=params=>{let service=params.service,states=params.states;return Backbone.Router.extend({routes:{OVERVIEW:"showOverview","GATEWAY/:id/:substate":"showGateway"},showOverview:function(){service.send(states.OVERVIEW),app.gateways.length>0&&service.send(states.OVERVIEW_LIST)},showGateway:function(gwid,substate){console.log("%c Router showGateway called: "+gwid,"color: blue"),service.send({type:states.GATEWAY,gwid:gwid});let gw=app.gateways.get(gwid);gw&&localStorage.setItem("app.gw",JSON.stringify(gw.toJSON()));let s=(substate=>{switch(substate){case"login":return states.GATEWAY_INPUT;case"reset":return states.GATEWAY_RESET;case"newpw":return states.GATEWAY_NEWPW;case"install":return states.GATEWAY_INSTALL}})(substate);service.send(s)}})};