import {
	PELAPORAN_LIST_REQUEST,
	PELAPORAN_LIST_SUCCESS,
	PELAPORAN_LIST_FAIL,
	PELAPORAN_DETAILS_REQUEST,
	PELAPORAN_DETAILS_SUCCESS,
	PELAPORAN_DETAILS_FAIL,
	PELAPORAN_CREATE_REQUEST,
	PELAPORAN_CREATE_SUCCESS,
	PELAPORAN_CREATE_FAIL,
	PELAPORAN_CREATE_RESET,
} from "../actions/pelaporan";

export const pelaporanListReducer = (state = { data: [] }, action) => {
	switch (action.type) {
		case PELAPORAN_LIST_REQUEST:
			return { loading: true, data: [] };
		case PELAPORAN_LIST_SUCCESS:
			return { loading: false, data: action.payload };
		case PELAPORAN_LIST_FAIL:
			return { loading: false, error: action.payload };
		default:
			return state;
	}
};

export const pelaporanDetailsReducer = (state = { pelaporan: {} }, action) => {
	switch (action.type) {
		case PELAPORAN_DETAILS_REQUEST:
			return { loading: true, ...state };
		case PELAPORAN_DETAILS_SUCCESS:
			return { loading: false, data: action.payload };
		case PELAPORAN_DETAILS_FAIL:
			return { loading: false, error: action.payload };
		default:
			return state;
	}
};

export const pelaporanCreateReducer = (state = {}, action) => {
	switch (action.type) {
		case PELAPORAN_CREATE_REQUEST:
			return { loading: true };
		case PELAPORAN_CREATE_SUCCESS:
			return { loading: false, success: true, data: action.payload };
		case PELAPORAN_CREATE_FAIL:
			return { loading: false, error: action.payload };
		case PELAPORAN_CREATE_RESET:
			return {};
		default:
			return state;
	}
};
