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 TextArea from '@atlaskit/textarea';
import messages from '../../common/messages';
var Errors = /*#__PURE__*/function (Errors) {
  Errors["EMPTY"] = "EMPTY";
  Errors["CHARACTER_LIMIT"] = "CHARACTER_LIMIT";
  return Errors;
}(Errors || {});
var MAX_PARAGRAPH_CHARACTER_LIMIT = 5000;
var ParagraphInputPrompt = function ParagraphInputPrompt(_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;
    }
    if (value && (value === null || value === void 0 ? void 0 : value.trim().length) === 0) {
      return Errors.EMPTY;
    }
    if (value && value.length > MAX_PARAGRAPH_CHARACTER_LIMIT) {
      return Errors.CHARACTER_LIMIT;
    }
    return undefined;
  };
  return /*#__PURE__*/React.createElement(Field, {
    name: variableName,
    label: displayName,
    defaultValue: defaultValue,
    isRequired: required,
    validate: validate
  }, function (_ref2) {
    var fieldProps = _ref2.fieldProps,
      error = _ref2.error;
    return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(TextArea, 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.CHARACTER_LIMIT && /*#__PURE__*/React.createElement(ErrorMessage, null, messages.errorInputCharacterLimitReached.defaultMessage)) : /*#__PURE__*/React.createElement(React.Fragment, null, error === Errors.EMPTY && /*#__PURE__*/React.createElement(ErrorMessage, null, messages.errorInputMustNotBeEmpty.defaultMessage), error === Errors.CHARACTER_LIMIT && /*#__PURE__*/React.createElement(ErrorMessage, null, messages.errorInputCharacterLimitReached.defaultMessage)));
  });
};
export default ParagraphInputPrompt;