import { createSelector } from "reselect";
import {
    FETCH_JOBS_ANSWER_REQUEST,
    FETCH_JOBS_ANSWER_SUCCESS,
    FETCH_JOBS_ANSWER_FAILURE,
} from "../types";

export function answers(state = {
}, action = {}) {
    switch (action.type) {
        case FETCH_JOBS_ANSWER_REQUEST:
            return {
                ...state,
                loading: true
            };
        case FETCH_JOBS_ANSWER_SUCCESS:
            return {
                ...state,
                ...action.res,
                loading: false
            };
        case FETCH_JOBS_ANSWER_FAILURE:
            return {
                ...state,
                errors: action.error,
                loading: false
            };
        default:
            return state;
    }
}

export const AnswersHashSelector = state => state.answers.data;

export const AnswersSelector = createSelector(AnswersHashSelector, hash =>
    Object.values(hash)
);
