"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const React = require("react");
const classNames = require("../../utils/classNames.cjs");
const config_context = require("../config/config.context.cjs");
require("./validationErrors.theme.css.cjs");
function _interopNamespaceDefault(e) {
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
  if (e) {
    for (const k in e) {
      if (k !== "default") {
        const d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: () => e[k]
        });
      }
    }
  }
  n.default = e;
  return Object.freeze(n);
}
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
const ValidationErrors = React__namespace.forwardRef(({ validationErrors, className, scrollIntoView, validationMode, ...nativeProps }, ref) => {
  const globals = config_context.useArmstrongConfig({
    validationMode,
    scrollValidationErrorsIntoView: scrollIntoView
  });
  const internalRef = React__namespace.useRef(null);
  React__namespace.useImperativeHandle(ref, () => internalRef.current, [internalRef]);
  React__namespace.useEffect(() => {
    var _a;
    if (validationErrors.length > 0 && globals.scrollValidationErrorsIntoView) {
      (_a = internalRef.current) == null ? void 0 : _a.scrollIntoView({
        block: "center",
        behavior: "smooth"
      });
    }
  }, [validationErrors.length, globals.scrollValidationErrorsIntoView]);
  const getKey = React__namespace.useCallback((error, index) => {
    if (typeof error === "string") {
      return error + index;
    }
    return (error == null ? void 0 : error.key) ?? index;
  }, []);
  const shouldShowErrorMessage = globals.validationMode === "both" || globals.validationMode === "message";
  return jsxRuntime.jsx("div", { ref: internalRef, className: classNames.concat("arm-validation-errors", className), ...nativeProps, children: validationErrors.map((error, i) => jsxRuntime.jsx("div", { className: "arm-validation-error-message", "aria-errormessage": typeof error === "string" ? error : "", children: shouldShowErrorMessage && jsxRuntime.jsx("span", { children: error }) }, getKey(error, i))) });
});
ValidationErrors.displayName = "ValidationErrors";
exports.ValidationErrors = ValidationErrors;
//# sourceMappingURL=validationErrors.component.cjs.map
