import { createReducer, on } from '@ngrx/store';

import { LoaderStore } from '../../interfaces/store/loader.interface';
import { initialState } from './loader.store';
import { loaderActions } from './loader.actions';

export const loaderReducers = createReducer<LoaderStore>(
  initialState,

  on(
    loaderActions.set_loader,
    (state, action): LoaderStore => ({ ...state, ...action }),
  ),

  on(loaderActions.show_loader, () => ({ isLoading: true })),

  on(loaderActions.hide_loader, () => ({ isLoading: false })),
);
