"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const DOMPurify = require("dompurify");
const React = require("react");
const index = require("../../icons/index.cjs");
;/* empty css                                                                                                                                                                                        */
;/* empty css                                                                                                                                                                                         */
;/* empty css                                                                                                                                                                                                 */
;/* empty css                                                                                                                                                                                            */
;/* empty css                                                                                                                                                                                            */
const Alert = require("../../node_modules/.pnpm/@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/components/Alert/Alert.cjs");
const FormErrorMessage = ({
  message,
  onDismiss,
  autoScroll,
  closable = false,
  ...rest
}) => {
  const bottomRef = React.useRef(null);
  const [show, setShow] = React.useState(true);
  React.useEffect(() => {
    var _a;
    if (!autoScroll) return;
    (_a = bottomRef.current) == null ? void 0 : _a.scrollIntoView({ behavior: "smooth" });
  }, [autoScroll, message]);
  React.useEffect(() => {
    setShow(true);
  }, [message]);
  if (!message || !show) {
    return null;
  }
  return /* @__PURE__ */ jsxRuntime.jsxs(
    Alert.Alert,
    {
      withCloseButton: Boolean(onDismiss) || closable,
      color: "red",
      icon: /* @__PURE__ */ jsxRuntime.jsx(index.IconAlertCircle, {}),
      onClose: () => {
        setShow(false);
        onDismiss == null ? void 0 : onDismiss();
      },
      ...rest,
      children: [
        /* @__PURE__ */ jsxRuntime.jsx("div", { dangerouslySetInnerHTML: { __html: DOMPurify.sanitize(message) } }),
        /* @__PURE__ */ jsxRuntime.jsx("div", { ref: bottomRef })
      ]
    }
  );
};
FormErrorMessage.displayName = "HookFormErrorMessage";
exports.FormErrorMessage = FormErrorMessage;
