import { Type } from '@angular/core';
import {
  ActionReducer,
  ActionReducerMap,
  MetaReducer,
  createSelector
} from '@ngrx/store';

import * as fromRouter from '@ngrx/router-store';

import { environment } from '../../environments/environment';

export const EFFECTS: Type<any>[] = [];

export const REDUCERS: ActionReducerMap<any> = {
  router: fromRouter.routerReducer
};

// console.log all actions
export function logger(reducer: ActionReducer<State>): ActionReducer<State> {
  return function(state: State, action: any): State {
    const result = reducer(state, action);
    console.groupCollapsed(action.type);
    console.log('prev state', state);
    console.log('action', action);
    console.log('next state', result);
    console.groupEnd();

    return result;
  };
}

export const META_REDUCERS: MetaReducer<State>[] = !environment.production
  ? [logger]
  : [];

export interface State {
  router: fromRouter.RouterReducerState;
}
