import "core-js/modules/es6.function.name";

function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }

/**
 * @category controls
 * @component toggle-switch
 * @variations collab-ui-react
 */
import React from 'react';
import PropTypes from 'prop-types';

var ToggleSwitch =
/*#__PURE__*/
function (_React$PureComponent) {
  _inheritsLoose(ToggleSwitch, _React$PureComponent);

  function ToggleSwitch() {
    var _this;

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

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

    return _this;
  }

  var _proto = ToggleSwitch.prototype;

  _proto.render = function render() {
    var _this2 = this;

    var _this$props = this.props,
        disabled = _this$props.disabled,
        name = _this$props.name,
        label = _this$props.label,
        value = _this$props.value,
        className = _this$props.className,
        htmlId = _this$props.htmlId,
        onChange = _this$props.onChange;
    return React.createElement("div", {
      className: "cui-input-group cui-toggle-switch" + (" " + className)
    }, React.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);
      }
    }), React.createElement("label", {
      className: "cui-toggle-switch__label",
      htmlFor: htmlId
    }, React.createElement("span", {
      className: "cui-toggle-switch__label__container"
    }), React.createElement("span", {
      className: "cui-toggle-switch__label__text"
    }, label)));
  };

  return ToggleSwitch;
}(React.PureComponent);

ToggleSwitch.propTypes = {
  /** @prop Set the toggle switch to checked | false */
  checked: PropTypes.bool,

  /** @prop Sets the className for the toggle switch | '' */
  className: PropTypes.string,

  /** @prop Set the toggle switch to disabled | false */
  disabled: PropTypes.bool,

  /** @prop Unique HTML ID used for tying label to HTML input for automated testing */
  htmlId: PropTypes.string.isRequired,

  /** @prop Sets the label string for the toggle switch | '' */
  label: PropTypes.string.isRequired,

  /** @prop Sets the name of the toggle switch | '' */
  name: PropTypes.string,

  /** @prop Callback function invoked when state is changed | null */
  onChange: PropTypes.func,

  /** @prop Sets the value of the toggle switch | '' */
  value: PropTypes.string
};
ToggleSwitch.defaultProps = {
  checked: false,
  className: '',
  disabled: false,
  label: '',
  name: '',
  onChange: null,
  value: ''
};
ToggleSwitch.displayName = 'ToggleSwitch';
export default ToggleSwitch;
/**
* @component toggle-switch
* @section default
* @react
import { ToggleSwitch } from '@collab-ui/react';

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

**/

/**
* @component toggle-switch
* @section filled
* @react
import { ToggleSwitch } from '@collab-ui/react';

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

**/