"use strict";

exports.__esModule = true;
exports.default = void 0;

var _react = _interopRequireDefault(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

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

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

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.default.createElement("div", {
      className: "cui-input-group cui-toggle-switch" + (" " + className)
    }, _react.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);
      }
    }), _react.default.createElement("label", {
      className: "cui-toggle-switch__label",
      htmlFor: htmlId
    }, _react.default.createElement("span", {
      className: "cui-toggle-switch__label__container"
    }), _react.default.createElement("span", {
      className: "cui-toggle-switch__label__text"
    }, label)));
  };

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

ToggleSwitch.displayName = 'ToggleSwitch';
ToggleSwitch.propTypes = {
  /**
   * @prop disabled | Set the toggle switch to disabled | false
   */
  disabled: _propTypes.default.bool,

  /**
   * @prop checked | Set the toggle switch to checked | false
   */
  checked: _propTypes.default.bool,

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

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

  /**
   * @prop value | Sets the value of the toggle switch | ''
   */
  value: _propTypes.default.string,

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

  /**
   * @prop htmlId | Unique HTML ID. Used for tying label to HTML input. Handy hook for automated testing.
   */
  htmlId: _propTypes.default.string.isRequired,

  /**
   * @prop onChange | Sets the callback function to call when state is changed | null
   */
  onChange: _propTypes.default.func
};
ToggleSwitch.defaultProps = {
  disabled: false,
  checked: false,
  name: '',
  label: '',
  value: '',
  className: '',
  inputRef: null,
  onChange: null
};
var _default = ToggleSwitch;
/**
* @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'
    />
  );
}

**/

exports.default = _default;