import _extends from "@babel/runtime/helpers/extends";
import React from 'react';
import { di } from 'react-magnetic-di';
import { ErrorMessage, Field, MessageWrapper } from '@atlaskit/form';
import { fg } from '@atlaskit/platform-feature-flags';
import Select from '@atlaskit/select';
import messages from '../../common/messages';
var Errors = /*#__PURE__*/function (Errors) {
  Errors["EMPTY"] = "EMPTY";
  return Errors;
}(Errors || {});
const SelectInputPrompt = ({
  userInputPrompt
}) => {
  const {
    variableName,
    required,
    displayName,
    defaultValue
  } = userInputPrompt;
  const validate = value => {
    if (required && !value) {
      return Errors.EMPTY;
    }
    return undefined;
  };
  const selectOptions = defaultValue.map(value => ({
    label: value,
    value
  }));
  return /*#__PURE__*/React.createElement(Field, {
    name: variableName,
    label: displayName,
    isRequired: required,
    validate: validate
  }, ({
    fieldProps,
    error
  }) => /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Select, _extends({
    isClearable: true,
    isSearchable: true,
    options: selectOptions,
    menuPosition: "fixed"
  }, fieldProps)), fg('platform_navx_3298_message_wrapper') ? /*#__PURE__*/React.createElement(MessageWrapper, null, error === Errors.EMPTY && /*#__PURE__*/React.createElement(ErrorMessage, null, messages.errorInputMustNotBeEmpty.defaultMessage)) : error === Errors.EMPTY && /*#__PURE__*/React.createElement(ErrorMessage, null, messages.errorInputMustNotBeEmpty.defaultMessage)));
};
export default SelectInputPrompt;