'use strict';

import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import React from 'react';
import PropTypes from 'prop-types';
import { FormControl } from './FormControl';
import Radio from 'react-bootstrap/lib/Radio';
export var RadioControl =
/*#__PURE__*/
function (_FormControl) {
  _inheritsLoose(RadioControl, _FormControl);

  function RadioControl() {
    return _FormControl.apply(this, arguments) || this;
  }

  var _proto = RadioControl.prototype;

  _proto.inputConverter = function inputConverter(value) {
    return {
      checked: this.props.value == value,
      // eslint-disable-line
      value: value
    };
  };

  _proto.componentDidMount = function componentDidMount() {
    this.testAutomationIdHandler();
  };

  _proto.componentDidUpdate = function componentDidUpdate() {
    this.testAutomationIdHandler();
  };

  _proto.testAutomationIdHandler = function testAutomationIdHandler() {
    if (this.input && !this.props.hasFormGroupContainer) {
      this.input.parentNode.setAttribute('data-test-automation-id', this.props.testAutomationId);
    }
  };

  _proto.getInputDOMNode = function getInputDOMNode() {
    return this.input;
  };

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

    var _this$getPropsFromCon = this.getPropsFromContext(),
        children = _this$getPropsFromCon.children,
        hiddenLabel = _this$getPropsFromCon.hiddenLabel,
        removeName = _this$getPropsFromCon.removeName,
        props = _objectWithoutPropertiesLoose(_this$getPropsFromCon, ["children", "hiddenLabel", "removeName"]);

    return React.createElement(Radio, _extends({}, this.getSafeProps(props), {
      ref: "input",
      type: "radio",
      "data-test-automation-id": "input",
      name: removeName ? null : props.name,
      inputRef: function inputRef(ref) {
        return _this.input = ref;
      }
    }), React.createElement("span", {
      "data-test-automation-id": "label",
      className: !!hiddenLabel ? 'sr-only' : null
    }, children));
  };

  return RadioControl;
}(FormControl);

_defineProperty(RadioControl, "propTypes", Object.assign({}, FormControl.propTypes, {
  removeName: PropTypes.bool
}));

_defineProperty(RadioControl, "defaultProps", Object.assign({}, FormControl.defaultProps, {
  testAutomationId: 'radio',
  removeName: false
}));