import { Params, RouterStateSnapshot } from '@angular/router';
import { ActionReducerMap, createFeatureSelector, MetaReducer } from '@ngrx/store';
import * as fromRouter from '@ngrx/router-store';
import { environment } from '../../environments/environment';
import { ActivatedRouteSnapshot } from '@angular/router/src/router_state';
import { storeFreeze } from 'ngrx-store-freeze';


export interface RouterStateUrl {
  url: string;
  queryParams: Params;
  params: Params;
}

export interface State {
  router: fromRouter.RouterReducerState<RouterStateUrl>;
}

export const reducers: ActionReducerMap<State> = {
  router: fromRouter.routerReducer
};

export const getRouterState = createFeatureSelector<fromRouter.RouterReducerState<RouterStateUrl>>('router');

export class CustomSerializer implements fromRouter.RouterStateSerializer<RouterStateUrl> {
  serialize(routerState: RouterStateSnapshot): RouterStateUrl {
    const { url } = routerState;
    const { queryParams } = routerState.root;

    let state: ActivatedRouteSnapshot = routerState.root;
    while (state.firstChild) {
      state = state.firstChild;
    }
    const { params } = state;

    return { url, queryParams, params };
  }
}

export const metaReducers: MetaReducer<any>[] = !environment.production
  ? [storeFreeze]
  : [];

{'avg_line_length': 30.325581395348838, 'max_line_length': 109, 'alphanum_fraction': 0.7446319018404908, 'licenses': ['MIT'], 'repository_name': 'm0nkeylabs/assiste-ai', 'path': 'src/app/reducer/index.ts', 'size': 1304, 'lang': 'TypeScript'}