'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 _ from 'lodash';
import { FormControl } from './FormControl';
import BSFormControl from 'react-bootstrap/lib/FormControl';
import { Static } from './Static';
export var SelectControl =
/*#__PURE__*/
function (_FormControl) {
  _inheritsLoose(SelectControl, _FormControl);

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

  var _proto = SelectControl.prototype;

  _proto.render = function render() {
    var _this$getPropsFromCon = this.getPropsFromContext(),
        children = _this$getPropsFromCon.children,
        props = _objectWithoutPropertiesLoose(_this$getPropsFromCon, ["children"]);

    if (props.readOnly) {
      var valueStaticText = '';

      var options = _.compact(_.flatten(children));

      if (options.length > 0) {
        var option = options.find(function (child) {
          return child.props.value == props.value; // eslint-disable-line
        }) || options[0];
        valueStaticText = option.props.children;
      }

      return React.createElement(Static, _extends({
        ref: "input"
      }, this.getSafeProps(props), {
        "data-test-automation-id": "select",
        value: valueStaticText,
        hasFeedbackBlock: false
      }));
    } else {
      return React.createElement("span", {
        className: "rc-select",
        "data-test-automation-id": this.props.hasFormGroupContainer ? undefined : this.props.testAutomationId
      }, React.createElement(BSFormControl, _extends({
        ref: "input",
        "data-test-automation-id": "select",
        componentClass: "select"
      }, this.getSafeProps(props)), children));
    }
  };

  return SelectControl;
}(FormControl);

_defineProperty(SelectControl, "propTypes", Object.assign({}, FormControl.propTypes));

_defineProperty(SelectControl, "defaultProps", Object.assign({}, FormControl.defaultProps, {
  testAutomationId: 'select'
}));