import _ from 'lodash';
import Mixpanel from 'react-native-mixpanel';
import {
	// RESET_ALL_PHOTOS,
	ADD_PHOTO_BENEFICIARY,
	ADD_PHOTO_HOUSEHOLD,
	// GET_PHOTO_BENEFICIARY,
	// GET_PHOTO_HOUSEHOLD,
	PHOTO_UPDATE_SYNC_DATA,
} from '~/store/actionTypes';

const photosInit = {
	beneficiaryPhotos: [], // list of users photo
	householdPhotos: [], // list of users photo
	meta: {
		loading: false,
		error: '',
	},
	lastSyncDateTime: '',
	lastUpdate: '',
};

export const photos = (state = photosInit, { type, payload }) => {
	switch (type) {
		case ADD_PHOTO_BENEFICIARY: {
			Mixpanel.track('add_bene_photo');
			const { beneficiaryPhotos } = state;
			const arrValues = (_.has(beneficiaryPhotos, payload.memberRefId)) ? beneficiaryPhotos[`${payload.memberRefId}`] : [];
			beneficiaryPhotos[`${payload.memberRefId}`] = _.compact([payload, ...arrValues]);
			return {
				...state,
				beneficiaryPhotos: { ...beneficiaryPhotos },
				lastUpdate: Math.floor(new Date().getTime() / 1000.0),
			};
		}
		case ADD_PHOTO_HOUSEHOLD: {
			Mixpanel.track('add_household_photo');
			const { householdPhotos } = state;
			const arrValues = (_.has(householdPhotos, payload.memberRefId)) ? householdPhotos[`${payload.memberRefId}`] : [];
			householdPhotos[`${payload.memberId}`] = _.compact([payload, ...arrValues]);
			return {
				...state,
				householdPhotos: { ...householdPhotos },
				lastUpdate: Math.floor(new Date().getTime() / 1000.0),
			};
		}
		// case GET_PHOTO_BENEFICIARY:
		// 	return filterPhotosForBeneficiary(state.beneficiaryPhotos, payload);
		// case GET_PHOTO_HOUSEHOLD:
		// 	return filterPhotosForHousehold(state, payload);
		case PHOTO_UPDATE_SYNC_DATA:
			return state;
		default:
			return state;
	}
};
