import { jsxs, jsx } from 'react/jsx-runtime';
import { forwardRef } from 'react';
import { c as cx } from './index-De1g9FRV.js';
import { S as StatusIcon } from './StatusIcon-BwULopyH.js';

import './FieldMessage.css';const messages = "_messages_1jce7_1";
const styles = {
	messages: messages,
	"error-container": "_error-container_1jce7_24",
	"warning-container": "_warning-container_1jce7_31",
	"status-icon": "_status-icon_1jce7_38"
};

function normalizeMessages(val) {
  if (val === void 0) return [];
  if (Array.isArray(val)) return val;
  return [val];
}
const FieldMessage = forwardRef(
  (props, ref) => {
    const {
      id,
      hint,
      description,
      error,
      warning,
      errorAriaLive: _errorAriaLive,
      errorMessage,
      className,
      ...rest
    } = props;
    const errorMessages = normalizeMessages(error);
    const warningMessages = normalizeMessages(warning);
    const allErrors = errorMessages.length === 0 && errorMessage ? [errorMessage] : errorMessages;
    return /* @__PURE__ */ jsxs(
      "div",
      {
        ...rest,
        className: cx(styles["messages"], className),
        ref,
        id,
        children: [
          hint ?? null,
          description ? /* @__PURE__ */ jsx("span", { children: description }) : null,
          allErrors.map((msg, index) => /* @__PURE__ */ jsxs("div", { className: styles["error-container"], children: [
            /* @__PURE__ */ jsx(
              StatusIcon,
              {
                size: "small",
                variant: "error",
                rootProps: {
                  "aria-hidden": true,
                  className: styles["status-icon"]
                }
              }
            ),
            /* @__PURE__ */ jsx("span", { className: styles["error-message"], "aria-live": "assertive", children: msg })
          ] }, index)),
          warningMessages.map((msg, index) => /* @__PURE__ */ jsxs("div", { className: styles["warning-container"], children: [
            /* @__PURE__ */ jsx(
              StatusIcon,
              {
                size: "small",
                variant: "warning",
                rootProps: {
                  "aria-hidden": true,
                  className: styles["status-icon"]
                }
              }
            ),
            /* @__PURE__ */ jsx("span", { className: styles["warning-message"], "aria-live": "polite", children: msg })
          ] }, index))
        ]
      }
    );
  }
);
FieldMessage.displayName = "FieldMessage";

export { FieldMessage as F };
//# sourceMappingURL=FieldMessage-DzxfodaI.js.map
