'use strict';

angular.module('app')
	.filter('excludeTagsThatAreBothPositiveAndNegative', function() {
		return function(tagsToSuggest, alreadySelectedTags) {
			var alreadySelectedTagNames;

			if (!tagsToSuggest) {
				return [];
			}
			if (!alreadySelectedTags) {
				return tagsToSuggest;
			}
			alreadySelectedTagNames = alreadySelectedTags.map(function(alreadySelectedTag) {
				return alreadySelectedTag.name;
			});


			return tagsToSuggest.filter(function(tag) {
				var firstIndex;

				firstIndex = alreadySelectedTagNames.indexOf(tag.name);


				return firstIndex < 0 || alreadySelectedTagNames.indexOf(tag.name, firstIndex + 1) < 0;
			});
		};
	});