"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _reactMagneticDi = require("react-magnetic-di");
var _form = require("@atlaskit/form");
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
var _textarea = _interopRequireDefault(require("@atlaskit/textarea"));
var _messages = _interopRequireDefault(require("../../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.default.createElement(_form.Field, {
    name: variableName,
    label: displayName,
    defaultValue: defaultValue,
    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(_textarea.default, 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.CHARACTER_LIMIT && /*#__PURE__*/_react.default.createElement(_form.ErrorMessage, null, _messages.default.errorInputCharacterLimitReached.defaultMessage)) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, error === Errors.EMPTY && /*#__PURE__*/_react.default.createElement(_form.ErrorMessage, null, _messages.default.errorInputMustNotBeEmpty.defaultMessage), error === Errors.CHARACTER_LIMIT && /*#__PURE__*/_react.default.createElement(_form.ErrorMessage, null, _messages.default.errorInputCharacterLimitReached.defaultMessage)));
  });
};
var _default = exports.default = ParagraphInputPrompt;