"use strict";

require("core-js/modules/web.dom-collections.iterator.js");

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

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

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

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

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

var _FormControl = _interopRequireDefault(require("@material-ui/core/FormControl"));

var _MenuItem = _interopRequireDefault(require("@material-ui/core/MenuItem"));

var _CredentialsContext = require("subfirelib/hooks/contexts/CredentialsContext");

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

const useStyles = (0, _styles.makeStyles)(theme => ({
  formControl: {
    margin: 0
  },
  notConnected: {
    fontStyle: 'italic'
  }
}));

const ServerSelect = props => {
  const {
    native,
    labelId,
    fullWidth,
    isLoggedIn
  } = props;
  const classes = useStyles();
  const value = (0, _CredentialsContext.useCredentials)();
  const [current = 'unconfigured...', // eslint-disable-line
  creds = [{
    name: 'unconfigured...'
  }], currentKey, setNewCurrent] = value;
  const className = isLoggedIn ? classes.connected : classes.notConnected;

  const handleServerChange = evt => {
    setNewCurrent(evt.target.value);
  };

  return /*#__PURE__*/_react.default.createElement(_FormControl.default, {
    className: classes.formControl,
    fullWidth: fullWidth
  }, /*#__PURE__*/_react.default.createElement(_Select.default, {
    native: native,
    id: "current-server",
    labelId: labelId,
    SelectDisplayProps: {
      id: 'select-server'
    },
    MenuProps: {
      id: 'menu-server'
    },
    value: currentKey,
    onChange: handleServerChange,
    className: className
  }, Object.entries(creds).map(o => {
    if (native) return /*#__PURE__*/_react.default.createElement("option", {
      key: o[0],
      value: o[0]
    }, o[1].name);
    return /*#__PURE__*/_react.default.createElement(_MenuItem.default, {
      key: o[0],
      value: o[0]
    }, o[1].name);
  })));
};

ServerSelect.propTypes = {
  native: _propTypes.default.bool,
  handleClose: _propTypes.default.func,
  labelId: _propTypes.default.string,
  fullWidth: _propTypes.default.bool,
  isLoggedIn: _propTypes.default.bool
};
ServerSelect.defaultProps = {
  fullWidth: true
};
var _default = ServerSelect;
exports.default = _default;