"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 _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));

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

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

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

// Style

/* istanbul ignore next */
if (typeof window !== 'undefined') {}

var Select = function Select(_ref) {
  var options = _ref.options,
      props = (0, _objectWithoutProperties2["default"])(_ref, ["options"]);

  var _useState = (0, _react.useState)(''),
      _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
      selectedOption = _useState2[0],
      setSelectedOption = _useState2[1];

  var className = props.className,
      isInvalid = props.isInvalid,
      onChange = props.onChange,
      size = props.size,
      attrs = (0, _objectWithoutProperties2["default"])(props, ["className", "isInvalid", "onChange", "size"]);

  var changeHandler = function changeHandler(e) {
    setSelectedOption(e.target.value);
    /* istanbul ignore else */

    if (typeof onChange === 'function') onChange(e);
  };

  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "Select ".concat(className || '')
  }, /*#__PURE__*/_react["default"].createElement("select", (0, _extends2["default"])({
    className: "Select-Input ".concat(size && "Select-Input_".concat(size, " ").concat(isInvalid && "Select-Input_invalid")),
    onChange: changeHandler,
    value: selectedOption
  }, attrs), options.map(function (o) {
    return /*#__PURE__*/_react["default"].createElement("option", {
      key: o.label,
      disabled: o.disabled,
      value: o.value
    }, o.label);
  })));
};

var Options = _propTypes["default"].shape({
  disabled: _propTypes["default"].bool,
  label: _propTypes["default"].string,
  value: _propTypes["default"].oneOfType([_propTypes["default"].number, _propTypes["default"].string])
});

Select.propTypes = {
  className: _propTypes["default"].string,
  isInvalid: _propTypes["default"].bool,
  onChange: _propTypes["default"].func,
  options: _propTypes["default"].arrayOf(Options),
  size: _propTypes["default"].oneOf(['lg', 'md', 'sm']),
  value: _propTypes["default"].oneOfType([_propTypes["default"].number, _propTypes["default"].string])
};
Select.defaultProps = {
  size: 'md'
};
var _default = Select;
exports["default"] = _default;