"use strict";

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

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

var _react = _interopRequireWildcard(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 }; }

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

const ServerSelect = props => {
  const {
    classes,
    native,
    labelId,
    fullWidth,
    isLoggedIn
  } = props;
  const value = (0, _react.useContext)(_CredentialsContext.CredentialsContext);
  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);
  })));
};

const styles = theme => ({
  formControl: {
    margin: 0
  },
  notConnected: {
    fontStyle: 'italic'
  }
});

ServerSelect.propTypes = {
  classes: _propTypes.default.any,
  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 = (0, _styles.withStyles)(styles)(ServerSelect);

exports.default = _default;