import * as types from "../actionTypes/actionTypes"
import initialState from "../state/addEventInitialValue";

export default (state = initialState, action) => {

    switch (action.type) {
        
        // GET ALL EVENTS
		case types.GET_EVENTS_REQUEST: {
			return state;
		}
		case types.GET_EVENTS_REQUEST_SUCCESS: {
			const { data } = action.payload;
			const eventList = data.events
			return { ...state, eventList };
		}
		case types.GET_EVENTS_REQUEST_FAIL: {
			return state;
        }

        // GET PHOTOGAARY
		case types.GET_PHOTOGALARY_REQUEST: {
			return state;
		}
		case types.GET_PHOTOGALARY_REQUEST_SUCCESS: {
            console.log('GET_PHOTOGALARY reducer data', action.payload.data.gallery)
			//const { data } = action.payload;
			//const gallery = data.data.gallery;
            return { ...state, gallery: action.payload.data.gallery  };
		}
		case types.GET_PHOTOGALARY_REQUEST_FAIL: {
			return state;
        }
        
        //POST PHOTOGAARY
		case types.POST_PHOTOGALARY_REQUEST_SUCCESS: {
			console.log('reducer post photogalary success', action.payload)
			return state
		}
		case types.POST_PHOTOGALARY_REQUEST_FAIL: {
			console.log('reducer post photogalary fail', action.payload)
			return { ...state, error: action.payload }
		}

		//PUT PHOTOGAARY
		case types.PUT_PHOTOGALARY_REQUEST_SUCCESS: {
			console.log('reducer PUT photogalary success', action.payload)
			return state
			
		}
		case types.PUT_PHOTOGALARY_REQUEST_FAIL: {
			console.log('reducer PUT photogalary fail', action.payload)
			return { ...state, error: action.payload }
		}

		// // REMOVE
		// case types.REMOVE_EVENT_REQUEST: {
		// 	return state;
		// }
		// case types.REMOVE_EVENT_REQUEST_SUCCESS: {
		// 	const { _id } = action.payload;
		// 	return {
		// 		...state,
		// 		eventList: state.eventList.filter(el => el._id !== _id)
		// 	};
		// }

		// case types.REMOVE_EVENT_REQUEST_FAIL: {
		// 	return state;
		// }

        default:
			return state; 
    }
}