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

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

	var _IronMultiSelectable3 = _interopRequireDefault(_IronMultiSelectable2);

	function _interopRequireDefault(obj) {
		return obj && obj.__esModule ? obj : {
			default: obj
		};
	}

	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;
		};
	}();

	function _possibleConstructorReturn(self, call) {
		if (!self) {
			throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
		}

		return call && (typeof call === "object" || typeof call === "function") ? call : self;
	}

	function _inherits(subClass, superClass) {
		if (typeof superClass !== "function" && superClass !== null) {
			throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
		}

		subClass.prototype = Object.create(superClass && superClass.prototype, {
			constructor: {
				value: subClass,
				enumerable: false,
				writable: true,
				configurable: true
			}
		});
		if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
	}

	var IronSelectable = function (_IronMultiSelectable) {
		_inherits(IronSelectable, _IronMultiSelectable);

		function IronSelectable() {
			var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

			_classCallCheck(this, IronSelectable);

			var _this = _possibleConstructorReturn(this, (IronSelectable.__proto__ || Object.getPrototypeOf(IronSelectable)).call(this, props));

			_this.items = props.children || props.items || [];
			_this.attrForSelected = props.attrForSelected || null;
			_this.selectedClassName = props.selectedClassName || "iron-selected";
			_this.selectedItem = props.selectedItem || null;
			_this.selected = props.selected || null;
			_this.selectedAttribute = props.selectedAttribute || null;
			return _this;
		}

		_createClass(IronSelectable, [{
			key: "indexOf",
			value: function indexOf(item) {
				return this.items.indexOf(item);
			}
		}, {
			key: "select",
			value: function select(value) {
				this.selected = value;
				this.selectedItem = value;
			}
		}, {
			key: "selectPrevious",
			value: function selectPrevious() {
				var length = this.items.length;
				var index = (Number(this._valueToIndex(this.selected)) - 1 + length) % length;
				this.select(this._indexToValue(index));
			}
		}, {
			key: "selectNext",
			value: function selectNext() {
				var index = (Number(this._valueToIndex(this.selected)) + 1) % this.items.length;
				this.select(this._indexToValue(index));
			}
		}, {
			key: "selectIndex",
			value: function selectIndex(index) {
				this.select(this._indexToValue(index));
			}
		}, {
			key: "_valueToIndex",
			value: function _valueToIndex(value) {
				if (this.attrForSelected) {
					for (var i = 0, item; item = this.items[i]; i++) {
						if (this._valueForItem(item) == value) {
							return i;
						}
					}
				} else {
					return Number(value);
				}
			}
		}, {
			key: "_indexToValue",
			value: function _indexToValue(index) {
				if (this.attrForSelected) {
					var item = this.items[index];
					if (item) {
						return this._valueForItem(item);
					}
				} else {
					return index;
				}
			}
		}, {
			key: "_valueForItem",
			value: function _valueForItem(item) {
				if (!item) {
					return null;
				}
				var propValue = item.props[this.attrForSelected];
				return propValue != undefined ? propValue : item;
			}
		}, {
			key: "_valueForIndex",
			value: function _valueForIndex(index) {
				if (!index) {
					return null;
				}
				var propValue = this.items[this.attrForSelected];
				return propValue != undefined ? propValue : this.items[index];
			}
		}, {
			key: "_selectionChange",
			value: function _selectionChange() {
				this._setSelectedItem(this._selection.get());
			}
		}]);

		return IronSelectable;
	}(_IronMultiSelectable3.default);

	exports.default = IronSelectable;
});