"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));

var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));

var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

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

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

var _Checkbox = _interopRequireDefault(require("react-bootstrap/lib/Checkbox"));

var _FormControl = require("./FormControl");

var PureCheckbox =
/*#__PURE__*/
function (_React$Component) {
  (0, _inheritsLoose2.default)(PureCheckbox, _React$Component);

  function PureCheckbox() {
    var _this;

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

    _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "input", {});
    return _this;
  }

  var _proto = PureCheckbox.prototype;

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

    var _this$props = this.props,
        hiddenLabel = _this$props.hiddenLabel,
        children = _this$props.children,
        label = _this$props.label,
        inputRef = _this$props.inputRef,
        props = (0, _objectWithoutPropertiesLoose2.default)(_this$props, ["hiddenLabel", "children", "label", "inputRef"]);

    if (!inputRef) {
      inputRef = function inputRef(ref) {
        return _this2.input = ref;
      };
    }

    this.input.indeterminate = (0, _FormControl.isIndeterminate)(props.checked);
    return _react.default.createElement("div", {
      "data-test-automation-id": "checkbox"
    }, _react.default.createElement(_Checkbox.default, (0, _extends2.default)({}, props, {
      "data-test-automation-id": "input",
      inputRef: inputRef
    }), _react.default.createElement("span", {
      "data-test-automation-id": "label",
      className: !!hiddenLabel ? 'sr-only' : null
    }, children || label)));
  };

  return PureCheckbox;
}(_react.default.Component);

exports.PureCheckbox = PureCheckbox;
(0, _defineProperty2.default)(PureCheckbox, "propTypes", {
  hiddenLabel: _propTypes.default.bool,
  children: _propTypes.default.node,
  inputRef: _propTypes.default.func,
  label: _propTypes.default.string
});
(0, _defineProperty2.default)(PureCheckbox, "defaultProps", {
  hiddenLabel: false,
  children: '',
  inputRef: null,
  label: ''
});