"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = ValidityMessages;
var _react = _interopRequireDefault(require("react"));
var _get = _interopRequireDefault(require("lodash-es/get"));
var _message = require("../message");
var _constants = require("./constants");
var _utilities = require("./utilities");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
// eslint-disable-next-line you-dont-need-lodash-underscore/get

function ValidityMessages({
  fieldId,
  validity,
  validationTestId,
  validationValues: validationValuesParams
}) {
  const defaultValidationValues = (0, _constants.useDefaultValidationValues)();
  const validationValues = validationValuesParams ?? defaultValidationValues;
  const validityType = (0, _get.default)(validity, 'type');
  const validatedValidityMessages = (0, _utilities.getValidityMessages)({
    validity,
    validationValues
  });
  if (!validatedValidityMessages.length) {
    return null;
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
    className: "dr-validity-messages",
    "test-id": "dr-validity-messages",
    children: validatedValidityMessages.map((message, i) => {
      const extraProps = fieldId ? {
        id: (0, _utilities.buildValidityMessageId)({
          fieldId,
          type: validityType,
          position: i + 1
        })
      } : {};
      return /*#__PURE__*/(0, _jsxRuntime.jsx)(_message.Message, {
        className: "validation-message",
        type: validityType,
        testId: validationTestId,
        ...extraProps,
        children: message
      }, `key-${validityType}-${message}`);
    })
  });
}