"use strict";

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 _react = _interopRequireDefault(require("react"));
var _reactMagneticDi = require("react-magnetic-di");
var _form = require("@atlaskit/form");
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
var _select = _interopRequireDefault(require("@atlaskit/select"));
var _messages = _interopRequireDefault(require("../../common/messages"));
var Errors = /*#__PURE__*/function (Errors) {
  Errors["EMPTY"] = "EMPTY";
  return Errors;
}(Errors || {});
var SelectInputPrompt = function SelectInputPrompt(_ref) {
  var userInputPrompt = _ref.userInputPrompt;
  var variableName = userInputPrompt.variableName,
    required = userInputPrompt.required,
    displayName = userInputPrompt.displayName,
    defaultValue = userInputPrompt.defaultValue;
  var validate = function validate(value) {
    if (required && !value) {
      return Errors.EMPTY;
    }
    return undefined;
  };
  var selectOptions = defaultValue.map(function (value) {
    return {
      label: value,
      value: value
    };
  });
  return /*#__PURE__*/_react.default.createElement(_form.Field, {
    name: variableName,
    label: displayName,
    isRequired: required,
    validate: validate
  }, function (_ref2) {
    var fieldProps = _ref2.fieldProps,
      error = _ref2.error;
    return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_select.default, (0, _extends2.default)({
      isClearable: true,
      isSearchable: true,
      options: selectOptions,
      menuPosition: "fixed"
    }, fieldProps)), (0, _platformFeatureFlags.fg)('platform_navx_3298_message_wrapper') ? /*#__PURE__*/_react.default.createElement(_form.MessageWrapper, null, error === Errors.EMPTY && /*#__PURE__*/_react.default.createElement(_form.ErrorMessage, null, _messages.default.errorInputMustNotBeEmpty.defaultMessage)) : error === Errors.EMPTY && /*#__PURE__*/_react.default.createElement(_form.ErrorMessage, null, _messages.default.errorInputMustNotBeEmpty.defaultMessage));
  });
};
var _default = exports.default = SelectInputPrompt;