"use strict";

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

var _core = require("@emotion/core");

var _lodash = require("lodash");

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

var _Select = _interopRequireDefault(require("@material-ui/core/Select"));

var _core2 = require("@material-ui/core");

var _styles = require("@material-ui/styles");

var _uiThemes = require("@hackoregon/ui-themes");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

var Select = function Select(_ref) {
  var autoWidth = _ref.autoWidth,
      fullWidth = _ref.fullWidth,
      displayEmpty = _ref.displayEmpty,
      onChange = _ref.onChange,
      value = _ref.value,
      variant = _ref.variant,
      formLabel = _ref.formLabel,
      formHelperText = _ref.formHelperText,
      disabled = _ref.disabled,
      options = _ref.options;
  var valueLabels = options.map(function (item) {
    return (0, _lodash.has)(item, "value") && (0, _lodash.has)(item, "label") ? item : {
      value: item,
      label: item
    };
  });
  return (0, _core.jsx)(_styles.ThemeProvider, {
    theme: _uiThemes.MaterialTheme
  }, (0, _core.jsx)(_core2.FormControl, {
    autoWidth: autoWidth,
    fullWidth: fullWidth,
    displayEmpty: displayEmpty,
    variant: variant,
    disabled: disabled
  }, (0, _core.jsx)(_core2.FormLabel, {
    style: {
      marginBottom: 8
    }
  }, formLabel), (0, _core.jsx)(_Select["default"], {
    value: value,
    onChange: onChange,
    input: (0, _core.jsx)(_core2.OutlinedInput, null)
  }, valueLabels.map(function (item) {
    return (0, _core.jsx)(_core2.MenuItem, {
      value: item.value
    }, item.label);
  })), (0, _core.jsx)(_core2.FormHelperText, null, formHelperText)));
};

Select.displayName = "Select";
Select.propTypes = {
  autoWidth: _propTypes["default"].bool,
  fullWidth: _propTypes["default"].bool,
  displayEmpty: _propTypes["default"].bool,
  onChange: _propTypes["default"].func,
  value: _propTypes["default"].string,
  variant: _propTypes["default"].string,
  formLabel: _propTypes["default"].string,
  formHelperText: _propTypes["default"].string,
  disabled: _propTypes["default"].bool,
  options: _propTypes["default"].oneOf([_propTypes["default"].arrayOf(_propTypes["default"].string), _propTypes["default"].arrayOf(_propTypes["default"].shape({
    value: _propTypes["default"].any,
    label: _propTypes["default"].string
  }))]).isRequired
};
Select.defaultProps = {
  autoWidth: true,
  fullWidth: false,
  displayEmpty: true,
  value: "List item",
  variant: "outlined",
  formLabel: "Label",
  formHelperText: "",
  disabled: false
};
var _default = Select;
exports["default"] = _default;