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:
		// console.log(eventTags);
		const { name, value } = action.payload;
		const alarmTagList = _.map(_.filter(eventTags, (tag) => {
			return tag.eventType === "alarm";
		}), (ftag) => {
			return ftag.tag;
		});
		if (alarmTagList.includes(name)){
			if(value){
				return _.uniq(_.concat(state, name));
			} else {
				const newActiveState = _.filter(state, (tag) => {
					return tag !== name;
				});
				return newActiveState;
			}
		} else {
			return state;
		}

	default:
		return state;
	}
}