(function (global, factory) {
	if (typeof define === "function" && define.amd) {
		define(["exports"], factory);
	} else if (typeof exports !== "undefined") {
		factory(exports);
	} else {
		var mod = {
			exports: {}
		};
		factory(mod.exports);
		global.IronSelection = mod.exports;
	}
})(this, function (exports) {
	"use strict";

	Object.defineProperty(exports, "__esModule", {
		value: true
	});

	function _classCallCheck(instance, Constructor) {
		if (!(instance instanceof Constructor)) {
			throw new TypeError("Cannot call a class as a function");
		}
	}

	var _createClass = function () {
		function defineProperties(target, props) {
			for (var i = 0; i < props.length; i++) {
				var descriptor = props[i];
				descriptor.enumerable = descriptor.enumerable || false;
				descriptor.configurable = true;
				if ("value" in descriptor) descriptor.writable = true;
				Object.defineProperty(target, descriptor.key, descriptor);
			}
		}

		return function (Constructor, protoProps, staticProps) {
			if (protoProps) defineProperties(Constructor.prototype, protoProps);
			if (staticProps) defineProperties(Constructor, staticProps);
			return Constructor;
		};
	}();

	var IronSelection = function () {
		function IronSelection(props) {
			_classCallCheck(this, IronSelection);

			this.selection = [];
			this.selectCallback = props && props.selectCallback;
		}

		_createClass(IronSelection, [{
			key: "get",
			value: function get() {
				return this.multi ? this.selection.slice() : this.selection[0];
			}
		}, {
			key: "clear",
			value: function clear(excludes) {
				this.selection.slice().forEach(function (item) {
					if (!excludes || excludes.indexOf(item) < 0) {
						this.setItemSelected(item, false);
					}
				}, this);
			}
		}, {
			key: "isSelected",
			value: function isSelected(item) {
				return this.selection.indexOf(item) >= 0;
			}
		}, {
			key: "setItemSelected",
			value: function setItemSelected(item, isSelected) {
				if (item != null) {
					if (isSelected !== this.isSelected(item)) {
						if (isSelected) {
							this.selection.push(item);
						} else {
							var i = this.selection.indexOf(item);
							if (i >= 0) {
								this.selection.splice(i, 1);
							}
						}
						if (this.selectCallback) {
							this.selectCallback(item, isSelected);
						}
					}
				}
			}
		}, {
			key: "select",
			value: function select(item) {
				if (this.multi) {
					this.toggle(item);
				} else if (this.get() !== item) {
					this.setItemSelected(this.get(), false);
					this.setItemSelected(item, true);
				}
			}
		}, {
			key: "toggle",
			value: function toggle(item) {
				this.setItemSelected(item, !this.isSelected(item));
			}
		}]);

		return IronSelection;
	}();

	exports.default = IronSelection;
});