import _ from "lodash";
import { IPC_TAGUPDATE } from "../actions/actions_tags";
import {event_tags as eventTags} from "../../../tagList.json";



export default function(state = [], action){
	switch (action.type) {
	case IPC_TAGUPDATE:
		const { name, value } = action.payload;
		const eventTagList = _.map(eventTags, (ftag) => {
			return ftag.tag;
		});
		if (eventTagList.includes(name)){
			if(value){
				const thisEvent = _.find(eventTags, (tag) => {
					return tag.tag === name;
				});
				const newHistory = _.concat([{...thisEvent, timestamp: new Date()}], state);
				return newHistory;
			}
		} 
		return state;

	default:
		return state;
	}
}