import { jsx } from "react/jsx-runtime";
import apollo_core from "@uipath/apollo-core";
import react from "react";
import react_markdown from "react-markdown";
import remark_gfm from "remark-gfm";
import { StatusTypes } from "../../../../../types/statusTypes.js";
import { ApAlertBar } from "../../../ap-alert-bar/index.js";
import { useError } from "../../providers/error-provider.js";
import { Li, Ol, Ul } from "../message/markdown/lists.js";
import { Link } from "../message/markdown/text.js";
function AutopilotChatInputErrorComponent() {
    const { error, clearError } = useError();
    react.useEffect(()=>{
        const listener = ()=>clearError();
        document.addEventListener('cancelAlert', listener);
        return ()=>{
            document.removeEventListener('cancelAlert', listener);
        };
    }, [
        clearError
    ]);
    if (!error) return null;
    return /*#__PURE__*/ jsx(ApAlertBar, {
        sx: {
            marginBottom: apollo_core.Spacing.SpacingBase,
            width: '100%',
            maxHeight: '300px',
            overflowY: 'auto'
        },
        status: 'warn' === error.level ? StatusTypes.WARNING : StatusTypes.ERROR,
        children: /*#__PURE__*/ jsx(react_markdown, {
            remarkPlugins: [
                remark_gfm
            ],
            components: {
                p: ({ children })=>/*#__PURE__*/ jsx("div", {
                        style: {
                            margin: 0,
                            paddingBottom: apollo_core.Spacing.SpacingXs
                        },
                        children: children
                    }),
                a: Link,
                ul: Ul,
                ol: Ol,
                li: Li
            },
            children: error.message
        })
    });
}
const AutopilotChatInputError = /*#__PURE__*/ react.memo(AutopilotChatInputErrorComponent);
export { AutopilotChatInputError };
