import { createSelector } from "reselect";
import {
    FETCH_JOBS_SUCCESS,
    FETCH_JOBS_FAILURE,
    FETCH_JOBS_REQUEST,
    TOGGLE_PROMOTED_FILTER_ADS,
} from "../types";

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

    switch (action.type) {
        case FETCH_JOBS_REQUEST:
            return {
                ...state,
               loading:true
            };
        case FETCH_JOBS_SUCCESS:
            return {
                ...state,
                ...action.res,
                loading:false
            };
        case FETCH_JOBS_FAILURE:
            return {
                ...state,
                errors: action.error,
                loading:false
            };
        case TOGGLE_PROMOTED_FILTER_ADS:
            return{
                ...state,
                promotedFilter: !state.promotedFilter
            };
        default:
            return state;
    }
}


export const AdsHashSelector = state => state.ads.data;

export const AdsSelector = createSelector(AdsHashSelector, hash =>
    Object.values(hash)
);
