(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

var _checkable = require('./checkable');

// initialize all elements
var componentsList = document.querySelectorAll(_checkable.Checkable.getSelector()); // Import all components

for (var i = 0; i < componentsList.length; i++) {
	new _checkable.Checkable(componentsList[i]);
}
},{"./checkable":2}],2:[function(require,module,exports){
'use strict';

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

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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

/**
 * checkable.js
 * Sets animation classes for checkable input elements
 */

/**
* Declare constants
*/
var attributeBase = 'data-rs-checkable';

var Checkable = exports.Checkable = function () {
	function Checkable(element) {
		_classCallCheck(this, Checkable);

		this.element = element;
		this.currentState = this.element.dataset.rsCheckable;
		this.input = this.element.querySelector('[' + this.attributes.input + ']');
		this.inputLabel = this.element.querySelector('[' + this.attributes.inputLabel + ']');
		this.icon = this.element.querySelector('[' + this.attributes.icon + ']');
		this.addEventHandlers();
	}

	/**
 * Declare attribute constants
 */


	_createClass(Checkable, [{
		key: 'addEventHandlers',


		/**
   * Add event handlers
   */
		value: function addEventHandlers() {
			var _this = this;

			this.input.addEventListener('change', function () {
				_this.setState(_this.element);
			});
		}

		/**
   * Set state of the input element to 'indeterminate', 'checked' or 'unchecked'
   */

	}, {
		key: 'setState',
		value: function setState(element) {
			var _this2 = this;

			if (this.currentState === this.states.indeterminate) {
				element.classList.remove(this.classes.selectionControlIndeterminate);
				element.classList.add(this.classes.selectionControlIndeterminateAnimate);
				if (this.icon !== null) {
					this.icon.addEventListener('transitionend', function () {
						if (_this2.input.checked) {
							element.dataset.rsCheckable = _this2.states.checked;
						}
					});
				}
				this.currentState = this.states.checked;
			} else if (this.currentState === this.states.checked) {
				element.dataset.rsCheckable = this.states.unchecked;
				this.currentState = this.states.unchecked;
			} else if (this.currentState === this.states.unchecked) {
				element.dataset.rsCheckable = this.states.checked;
				this.currentState = this.states.checked;
			}
		}

		/**
   * Get selector
   */

	}, {
		key: 'attributes',
		get: function get() {
			return {
				input: attributeBase + '-input',
				inputLabel: attributeBase + '-input-label',
				icon: attributeBase + '-icon'
			};
		}

		/**
  * Declare classes
  */

	}, {
		key: 'classes',
		get: function get() {
			return {
				selectionControlIndeterminate: 'selection-control--indeterminate',
				selectionControlIndeterminateAnimate: 'selection-control--indeterminate--animate'
			};
		}

		/**
  * Declare state constants
  */

	}, {
		key: 'states',
		get: function get() {
			return {
				checked: 'checked',
				unchecked: 'unchecked',
				indeterminate: 'indeterminate'
			};
		}
	}], [{
		key: 'getSelector',
		value: function getSelector() {
			return '[' + attributeBase + ']';
		}
	}]);

	return Checkable;
}();
},{}]},{},[1]);
