import { jsx } from "@emotion/core";
import { has } from "lodash";
import PropTypes from "prop-types";
import MaterialSelect from "@material-ui/core/Select";
import { FormControl, OutlinedInput, MenuItem, FormLabel, FormHelperText } from "@material-ui/core";
import { ThemeProvider } from "@material-ui/styles";
import { MaterialTheme } from "@hackoregon/ui-themes";

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 has(item, "value") && has(item, "label") ? item : {
      value: item,
      label: item
    };
  });
  return jsx(ThemeProvider, {
    theme: MaterialTheme
  }, jsx(FormControl, {
    autoWidth: autoWidth,
    fullWidth: fullWidth,
    displayEmpty: displayEmpty,
    variant: variant,
    disabled: disabled
  }, jsx(FormLabel, {
    style: {
      marginBottom: 8
    }
  }, formLabel), jsx(MaterialSelect, {
    value: value,
    onChange: onChange,
    input: jsx(OutlinedInput, null)
  }, valueLabels.map(function (item) {
    return jsx(MenuItem, {
      value: item.value
    }, item.label);
  })), jsx(FormHelperText, null, formHelperText)));
};

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