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 Textfield from '@atlaskit/textfield';
import messages from '../../common/messages';
export let Errors = /*#__PURE__*/function (Errors) {
  Errors["EMPTY"] = "EMPTY";
  Errors["INVALID_NUMBER"] = "INVALID_NUMBER";
  return Errors;
}({});
export const numberValidate = (isRequired, value) => {
  if (isRequired && !value) {
    return Errors.EMPTY;
  }
  if (value && Number.isNaN(Number(value))) {
    return Errors.INVALID_NUMBER;
  }
  return undefined;
};
const NumberInputPrompt = ({
  userInputPrompt
}) => {
  const {
    variableName,
    required,
    displayName,
    defaultValue
  } = userInputPrompt;
  const generateErrorMessage = error => {
    switch (error) {
      case Errors.EMPTY:
        return /*#__PURE__*/React.createElement(ErrorMessage, null, messages.errorInputMustNotBeEmpty.defaultMessage);
      case Errors.INVALID_NUMBER:
        return /*#__PURE__*/React.createElement(ErrorMessage, null, messages.errorValueIsNotValidNumber.defaultMessage);
      default:
        return null;
    }
  };
  return /*#__PURE__*/React.createElement(Field, {
    key: variableName,
    name: variableName,
    label: displayName,
    defaultValue: defaultValue,
    isRequired: required,
    validate: value => numberValidate(required, value)
  }, ({
    fieldProps,
    error
  }) => /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Textfield, fieldProps), fg('platform_navx_3298_message_wrapper') ? /*#__PURE__*/React.createElement(MessageWrapper, null, generateErrorMessage(error)) : generateErrorMessage(error)));
};
export default NumberInputPrompt;