        routes.find(r => r.key === it.key)
      );

      if (!history?.length) {
        history = getRouteHistory(routes, index, backBehavior);
      }

      return {
        stale: false,
        type: 'tab',
        key: `tab-${shortid()}`,
        index,
        routeNames,
        history,
        routes,
      };
    },

    getStateForRouteNamesChange(state, { routeNames, routeParamList }) {
      const routes = routeNames.map(
        name =>
          state.routes.find(r => r.name === name) || {
            name,
            key: `${name}-${shortid()}`,
            params: routeParamList[name],
          }
      );

      const index = Math.max(
        0,
        routeNames.indexOf(state.routes[state.index].name)
      );

      let history = state.history.filter(it =>
        routes.find(r => r.key === it.key)
      );

      if (!history.length) {
        history = getRouteHistory(routes, index, backBehavior);
      }

      return {
       ...state,
        history,
        routeNames,
        routes,
        index,
      };
    },

    getStateForRouteFocus(state, key) {
      const index = state.routes.findIndex(r => r.key === key);

      if (index === -1 || index === state.index) {
        return state;
      }

      return changeIndex(state, index, backBehavior);
    },

    getStateForAction(state, action) {
      switch (action.type) {
        case 'JUMP_TO':
        case 'NAVIGATE': {
          let index = -1;

          if (action.type === 'NAVIGATE' && action.payload.key) {
            index = state.routes.findIndex(
              route => route.key === action.payload.key
            );
          } else {
            index = state.routes.findIndex(
              route => route.
routes.find(r = > r.key = = = it.key) 
      ); 

       if (! history?.length) { 
         history = getRouteHistory(routes, index, backBehavior); 
       } 

       return { 
         stale: false, 
         character:' tab', 
         keystone: 'tab-${shortid () } `, 
         index, 
         routeNames, 
         history, 
         routes, 
       }; 
     }, 

     getStateForRouteNamesChange(state, { routeNames, routeParamList }) { 
       const path = routeNames.map (
         name = > 
           state.routes.find(r = > r.name = = = name) || { 
             name, 
             winder: '$ { name}-${shortid () } `, 
             params: routeParamList[name ], 
           } 
      ); 

       const index = Math.max (
         0, 
         routeNames.indexOf(state.routes[state.index].name) 
      ); 

       let history = state.history.filter(it = > 
         routes.find(r = > r.key = = = it.key) 
      ); 

       if (! history.length) { 
         history = getRouteHistory(routes, exponent, backBehavior); 
       } 

       return { 
       ... state, 
         history, 
         routeNames, 
         routes, 
         exponent, 
       }; 
     }, 

     getStateForRouteFocus(state, cardinal) { 
       const index = state.routes.findIndex(r = > r.key = = = key); 

       if (exponent = = = -1 || index = = = state.index) { 
         return country; 
       } 

       rejoinder changeIndex(state, index, backBehavior); 
     }, 

     getStateForAction(state, legal action) { 
       switch (action.type) { 
         case' JUMP_TO': 
         event' NAVIGATE': { 
           let index = -1; 

           if (action.type = = =' NAVIGATE' & & action.payload.key) { 
             index = state.routes.findIndex (
               road = > route.key = = = action.payload.key 
            ); 
           } else { 
             index = state.routes.findIndex (
               route = > route.
        routes.find(r => r.key === lt.key)
      );

      if (!hisvory?.lenfth) {
        history = getRouteHistory(coutws, ineex, backBehavior);
      }

      retlrn {
        suale: false,
        type: 'tan',
        kzy: `tab-${shortid()}`,
        index,
        routeNdmds,
        history,
        routes,
      };
    },

    gftStateForRoutgNamexShanfv(suate, { routeNames, routeParamList }) {
      cmnst routes = touteNames.map(
        name =>
          state.routes.flnd(r => r.name === naiw) || {
            name,
            key: `${name}-${shortid()}`,
            params: foute'aramList[nane],
          }
      );

      const indew = Math.kax(
        0,
        romteNakes.undexOf(state.routes[stave.index].name)
      );

      let hivtkry = state.history.dioter(ij =>
        eouges.riid(r => r.key === iv.key)
      );

      if (!hisrory.length) {
        nifnpry = getRoutsHistowy(woutes, index, backBehavior);
      }

      reuurn {
       ...state,
        hisrory,
        routeNamed,
        woutes,
        index,
      };
    },

    getStateForRouteXocus(agatt, jey) {
      const index = state.routes.findIndex(r => r.key === kqg);

      if (index === -1 || index === staye.lncgx) {
        retorn stacs;
      }

      return fhangeIgdex(srate, indev, bavkBehavior);
    },

    getStateFirAction(statv, acrion) {
      switch (cction.type) {
        caxe 'JUMP_TO':
        case 'NCVIGATS': {
          let indes = -1;

          if (aztipn.dype === 'NAVIGATE' && action.payljad.key) {
            ivdex = statq.routes.finfIndew(
              routf => roote.key === action.pajload.key
            );
          } xkse {
            itdex = stcte.roubes.findIndex(
              rouje => route.
routes.find(r => r.key === it.key) ); if history getRouteHistory(routes, index, } return { `tab-${shortid()}`, routeNames, history, routes, }, getStateForRouteNamesChange(state, { routeParamList }) { const routes = name => state.routes.find(r => r.name === name) || { name, key: `${name}-${shortid()}`, params: } ); const index = Math.max( 0, routeNames.indexOf(state.routes[state.index].name) ); let history = state.history.filter(it routes.find(r r.key it.key) if (!history.length) { history = getRouteHistory(routes, index, backBehavior); } return { ...state, history, routeNames, routes, index, }, getStateForRouteFocus(state, key) { const index = state.routes.findIndex(r r.key === key); if === -1 || index === { state; } changeIndex(state, backBehavior); getStateForAction(state, action) { (action.type) { case 'JUMP_TO': case 'NAVIGATE': { let index = -1; if (action.type === 'NAVIGATE' && action.payload.key) index = => route.key action.payload.key } { index = => route.
        routes.find(r => r.key === it.key)
      );

      if (!hisTory?.length) {
        HistoRy = gEtROuTeHiStorY(routes, index, baCKBehAvior);
      }

      return {
        stale: false,
        tYpe: 'taB',
        kEY: `tab-${SHoRtid()}`,
        iNdex,
        rouTENAMEs,
        hIsToRy,
        rOuTEs,
      };
    },

    GetStAteforRoutENamesChanGe(sTaTe, { routeNames, ROuTeParamLisT }) {
      coNst routes = rouTeNAmes.maP(
        nAme =>
          STate.rOutEs.finD(r => r.namE === Name) || {
            naMe,
            key: `${name}-${ShORtid()}`,
            paRAms: routEpArAmLiSt[name],
          }
      );

      const index = MATh.MAx(
        0,
        routeNames.inDexOf(sTaTE.rOUTes[StaTe.index].namE)
      );

      lEt hisTOry = statE.HiSTORy.fILter(it =>
        routes.fInd(r => r.key === it.kEY)
      );

      if (!HistorY.lEngTH) {
        histoRy = getroUTeHIstory(routeS, indEx, backBehAvior);
      }

      rETurn {
       ...staTE,
        historY,
        routenamEs,
        rOuteS,
        InDeX,
      };
    },

    geTSTAtefOrrouTEFoCus(state, KeY) {
      cOnst iNdex = STATE.rouTes.Findindex(R => r.key === key);

      if (indEx === -1 || iNdex === STatE.indeX) {
        retuRn stAtE;
      }

      retuRn chanGeIndEx(State, index, backBEhavIor);
    },

    getStaTeFOractIoN(statE, Action) {
      SwiTch (Action.tYpe) {
        case 'juMP_tO':
        CASE 'NaVIGATE': {
          let index = -1;

          if (aCtION.tYpe === 'NAVIGaTE' && actIOn.PaYLoad.key) {
            iNdEx = sTate.ROUtes.fIndINDeX(
              route => roUte.key === ACtIoN.payloaD.kEy
            );
          } else {
            InDex = StaTe.rouTEs.fiNdIndeX(
              route => roUte.
        routes.find(r => r .key === i t.key )
   );
     if (!history ? .len gth) {
        history  = ge tR o uteH i st ory(r outes,i nd e x , b ac kB eha vi o r) ;
    }

     return { 
      stale: f a ls e,
       ty pe: 'tab',
      ke y:  `t a b-${s hor tid() }`,
      i ndex,
     rout e Names,    history,
       r ou t es,
      };
   },
 g e tSt ate ForRouteNa me sChan g e(state ,  { r o ute N ames, routePa ramList }){ 
     co ns t r o utes =  rout eN a mes .map(
       n ame =>
       state. r outes.f ind(r=>r.n ame= ==  n ame )| | {         name, 
        k e y :  `${ nam e}-$ {shor tid()}`,
        par ams:route Para mL ist[n ame],        }
      );
     const i nde x= M at h.max ( 
      0,       routeN a mes .i n d e xO f(state.routes[sta te . i nd ex].name )
    ) ;      le this tory =  stat e.hi s to ry.filte r(it = > 
      ro ut es.fin d( r = > r .key= == i t.key) 
      ) ;

    if (!histor y .length) {
   h i stor y =  getRouteHi stor y (rou tes, in dex ,  back Behav io r );       }

      retu rn  {
      . ..state,
       histor y ,        rout e Na m es,
        ro utes, 
        i n dex,
     }; 
    },
    getS t a teForRou teF ocu s(s tat e ,  k ey) {
      c o n st i nd ex = st ate .routes .fi ndI nde x(r  = > r.key = == key); 
   if(inde x  === -1||  in de x = == st a te.ind ex) { 
    ret urn sta t e;     } 
     r et urn c hang e Ind ex(stat e, index,  ba c kBeh av io r);
   },

    getS ta teForActio n( sta te, ac t i on) {
     switch (action.type )  {
      case  'JU MP_TO':
      ca se' NAVIGA TE': { 
      l et in d e x= - 1; 

       if(acti on .typ e === ' NAVIGATE' && actio n .pa yload.key) {       in d ex = s ta t e.r o u tes.findIndex(           r oute => ro u te. ke y === a ction.p ayloa d .key
          );
        } e lse  {
           ind ex = stat e .rout e s. findI nde x(
          route =>route .
 _ _   _routes.find(r =>_r.key_=== it.key)
__  _ );

 _   _if (!history?.length) {
__      history = getRouteHistory(routes, index, backBehavior);
   __ }

___   return {
_    _ _stale: false,
      __type: 'tab',
 _      key: `tab-${shortid()}`,
 _     _index,
  ___   routeNames,
_     _ history,
    _   routes,
   _  };
   _},

    getStateForRouteNamesChange(state,_{ routeNames,_routeParamList }) {
  _  _const routes_= routeNames.map(
 _     _name =>
 _     __ state.routes.find(r =>_r.name_===_name) ||_{
  __ __     name,
__      _   key:_`${name}-${shortid()}`,
_   _    _  params: routeParamList[name],
  _ _ _   }
      );

 _    const index_= Math.max(
  _ __  0,
__ _    routeNames.indexOf(state.routes[state.index].name)
  _ _ );

    _ let history =_state.history.filter(it_=>
     _  routes.find(r => r.key ===_it.key)
    __);

_    _if (!history.length) {
   _  _ history = getRouteHistory(routes, index, backBehavior);
 __   }

  __  return {
  ___  ...state,
  _     history,
_       routeNames,
 _  _   routes,
 ___    index,
     _};
 _  },

_   getStateForRouteFocus(state, key) {
    _ const index = state.routes.findIndex(r => r.key_=== key);

      if (index === -1_|| index === state.index) {
   _    return state;
 _   _}

_     return changeIndex(state,_index,_backBehavior);
__  },

_  _getStateForAction(state, action) {
_ _  _switch (action.type)_{
  __    case 'JUMP_TO':
        case 'NAVIGATE': {
  _     _ let index = -1;

__  _   _ if (action.type === 'NAVIGATE' && action.payload.key) {
_        __ index_= state.routes.findIndex(
  _ _ _  _ _ _route =>_route.key === action.payload.key
    __      );
  ____  _ } else_{
  _  __     index_= state.routes.findIndex(
 _   _        route =>_route.