'use strict';

exports.__esModule = true;

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

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

/**
 * @category controls
 * @component toggle-switch
 * @variations collab-ui-react
 */

var _ref = _react2.default.createElement('span', { className: 'cui-toggle-switch__label__container' });

var ToggleSwitch = function (_React$PureComponent) {
  (0, _inherits3.default)(ToggleSwitch, _React$PureComponent);

  function ToggleSwitch() {
    var _temp, _this, _ret;

    (0, _classCallCheck3.default)(this, ToggleSwitch);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, _React$PureComponent.call.apply(_React$PureComponent, [this].concat(args))), _this), _this.state = {
      isToggleOn: _this.props.checked
    }, _this.handleClick = function (event) {
      _this.setState({ isToggleOn: !_this.state.isToggleOn });

      if (_this.props.onChange) {
        _this.props.onChange(event);
      }
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }

  ToggleSwitch.prototype.render = function render() {
    var _this2 = this;

    var _props = this.props,
        disabled = _props.disabled,
        name = _props.name,
        label = _props.label,
        value = _props.value,
        className = _props.className,
        htmlId = _props.htmlId,
        onChange = _props.onChange;


    return _react2.default.createElement(
      'div',
      {
        className: 'cui-input-group cui-toggle-switch' + (' ' + className)
      },
      _react2.default.createElement('input', {
        className: 'cui-input cui-toggle-switch__input',
        type: 'checkbox',
        disabled: disabled,
        'aria-checked': this.state.isToggleOn,
        checked: this.state.isToggleOn,
        name: name,
        value: value,
        id: htmlId,
        onChange: onChange,
        tabIndex: 0,
        onClick: function onClick(event) {
          return _this2.handleClick(event);
        }
      }),
      _react2.default.createElement(
        'label',
        { className: 'cui-toggle-switch__label', htmlFor: htmlId },
        _ref,
        _react2.default.createElement(
          'span',
          { className: 'cui-toggle-switch__label__text' },
          label
        )
      )
    );
  };

  return ToggleSwitch;
}(_react2.default.PureComponent);

ToggleSwitch.displayName = 'ToggleSwitch';
exports.default = ToggleSwitch;


ToggleSwitch.defaultProps = {
  disabled: false,
  checked: false,
  name: '',
  label: '',
  value: '',
  className: '',
  inputRef: null,
  onChange: null
};

/**
* @name Default Toggle Switch
* @description Toggle Switches are useful.
*
* @category controls
* @component toggle-switch
* @section default
*
* @js

export default class Checkbox extends React.PureComponent {
  render() {
    return (
      <ToggleSwitch
        checked={false}
        label='Toggle Switch'
        htmlId='testToggleSwitch1'
      />
    );
  }
}

*/

/**
* @name Disabled Toggle Switch
* @description Toggle Switches are useful.
*
* @category controls
* @component toggle-switch
* @section disabled
*
* @js

export default function ToggleSwitch() {
  return (
    <ToggleSwitch
      disabled
      label='Toggle Switch'
      htmlId='testToggleSwitch2'
    />
  );
}

**/

module.exports = exports['default'];