function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import uuid from 'uuid';
import MarkdownLabel from './MarkdownLabel';

class ToggleButton extends PureComponent {
  constructor(props) {
    super(props);
    this.id = uuid();
  }

  render() {
    const {
      label,
      className,
      input,
      disabled,
      color,
      fieldLabel,
      ...rest
    } = this.props;
    const componentClasses = cx('form-field-togglebutton', `form-field-togglebutton-${color}`, className, {
      'form-field-togglebutton--disabled': disabled
    });
    return /*#__PURE__*/React.createElement("label", {
      className: componentClasses,
      htmlFor: this.id
    }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("input", _extends({
      className: "form-field-togglebutton__input",
      id: this.id,
      checked: !!input.value // eslint-disable-next-line react/jsx-props-no-spreading

    }, input, rest, {
      type: "checkbox"
    })), /*#__PURE__*/React.createElement("div", {
      className: "form-field-togglebutton__checkbox"
    }, /*#__PURE__*/React.createElement(MarkdownLabel, {
      inline: true,
      label: label
    }))));
  }

}

ToggleButton.propTypes = {
  label: PropTypes.string,
  className: PropTypes.string,
  disabled: PropTypes.bool,
  input: PropTypes.object.isRequired,
  color: PropTypes.string,
  fieldLabel: PropTypes.string
};
ToggleButton.defaultProps = {
  className: '',
  label: null,
  disabled: false,
  color: 'cat-color-seq-1',
  fieldLabel: null
};
export default ToggleButton;