"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

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

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

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

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

var _getEventHandlersFromProps = _interopRequireDefault(require("../utils/getEventHandlersFromProps"));

var _Select = _interopRequireDefault(require("../Select"));

var _SuperField = _interopRequireDefault(require("../SuperField"));

var _SuperFieldLabel = _interopRequireDefault(require("../SuperFieldLabel"));

var _SuperFieldHint = _interopRequireDefault(require("../SuperFieldHint"));

/**
 * Convenient component for most of the SelectFields. But with SuperField is
 * simple to compose its own.  It just specified that this is a input field,
 * that can have an error, hint, prefix or suffix.
 */
var SelectField = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
  var id = _ref.id,
      label = _ref.label,
      hasError = _ref.hasError,
      hint = _ref.hint,
      onChange = _ref.onChange,
      value = _ref.value,
      name = _ref.name,
      disabled = _ref.disabled,
      readOnly = _ref.readOnly,
      placeholder = _ref.placeholder,
      inputProps = _ref.inputProps,
      labelAlwaysShrank = _ref.labelAlwaysShrank,
      getLabel = _ref.getLabel,
      getValue = _ref.getValue,
      items = _ref.items,
      rest = (0, _objectWithoutProperties2["default"])(_ref, ["id", "label", "hasError", "hint", "onChange", "value", "name", "disabled", "readOnly", "placeholder", "inputProps", "labelAlwaysShrank", "getLabel", "getValue", "items"]);
  return /*#__PURE__*/_react["default"].createElement(_SuperField["default"], (0, _extends2["default"])({
    ref: ref
  }, rest, {
    disabled: disabled,
    readOnly: readOnly,
    hasError: hasError,
    id: id
  }), /*#__PURE__*/_react["default"].createElement(_SuperFieldLabel["default"], {
    alwaysShrank: !!(labelAlwaysShrank || placeholder)
  }, label), /*#__PURE__*/_react["default"].createElement(_Select["default"], (0, _extends2["default"])({
    placeholder: placeholder,
    value: value,
    name: name,
    onChange: onChange,
    disabled: disabled,
    readOnly: readOnly,
    items: items,
    getLabel: getLabel,
    getValue: getValue
  }, (0, _getEventHandlersFromProps["default"])(rest), inputProps)), /*#__PURE__*/_react["default"].createElement(_SuperFieldHint["default"], null, hint));
});
SelectField.displayName = 'SelectField';
SelectField.propTypes = {
  disabled: _propTypes["default"].bool,
  getLabel: _propTypes["default"].func,
  getValue: _propTypes["default"].func,
  hasError: _propTypes["default"].bool,
  hint: _propTypes["default"].node,
  id: _propTypes["default"].string,
  inputProps: _propTypes["default"].object,
  items: _propTypes["default"].array,
  label: _propTypes["default"].node,
  labelAlwaysShrank: _propTypes["default"].bool,
  name: _propTypes["default"].string,
  onChange: _propTypes["default"].func,
  placeholder: _propTypes["default"].string,
  readOnly: _propTypes["default"].bool,
  value: _propTypes["default"].any
};
var _default = SelectField;
exports["default"] = _default;