import { DashboardActionTypes } from "./dashboard-detail.action.types"

const INITIAL_STATE = 
{
    inProgress: false,
    result: [],
    criticalityTrendResult: [],
    apiResponseStatus: -1,
    errorMessages: null,    
}

const dashboardContentReducer = (currentState = INITIAL_STATE, action) => {
    switch(action.type){
        case DashboardActionTypes.DASHBOARD_RESET_STATE:
            return INITIAL_STATE

        case DashboardActionTypes.DASHBOARD_STATUS_CLEAR_ERROR_STATE:        
            return {
                ...currentState,
                errorMessages: null
            }
        
        case DashboardActionTypes.GET_DASHBOARD_START:
            return {
                ...currentState,
                inProgress: true,
                errorMessages: null
            }
        case DashboardActionTypes.GET_DASHBOARD_CRITICALITY_TREND_SUCCESS:{
            return{
                ...currentState,
                inProgress: false,
                errorMessages: null,
                criticalityTrendResult: action.payload
            }
        }
        case DashboardActionTypes.GET_DASHBOARD_SUCCESS:
            return{
                ...currentState,
                inProgress: false,
                errorMessages: null,
                result: action.payload
            }
        case DashboardActionTypes.GET_DASHBOARD_FAILURE:
            return {
                ...currentState,
                errorMessages: action.payload.message,
                inProgress: false
            }    
        default: {
                return currentState
            }        
    }
        
}

export default dashboardContentReducer