import { createSelector } from "reselect";
import {
    FETCH_EMPHASIS_COMPANIES_REQUEST,
    FETCH_EMPHASIS_COMPANIES_SUCCESS,
    FETCH_EMPHASIS_COMPANIES_FAILURE
} from "../types";

export function emphasisCompanies(state = {
}, action = {}) {

    switch (action.type) {
        case FETCH_EMPHASIS_COMPANIES_REQUEST:
            return {
                ...state,
                loading:true
            };
        case FETCH_EMPHASIS_COMPANIES_SUCCESS:
            return {
                ...action.res,
                loading:false
            };
        case FETCH_EMPHASIS_COMPANIES_FAILURE:
            return {
                ...state,
                errors: action.error,
                loading:false
            };
        default:
            return state;
    }
}

export const emphasisCompaniesHashSelector = state => state.emphasisCompanies.data;

export const emphasisCompaniesSelector = createSelector(emphasisCompaniesHashSelector, hash =>
    Object.values(hash)
);
