import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useMemo, useState } from 'react';
import { ChevronDown, ChevronUp, CircleExclamationFill, CircleInfoFill, TriangleExclamationFill, } from '@gravity-ui/icons';
import { Button, Icon, Text } from '@gravity-ui/uikit';
import { block } from "../../../utils/cn.js";
import "./Alert.css";
const b = block('alert');
const statusIcons = {
    info: CircleInfoFill,
    warning: TriangleExclamationFill,
    error: CircleExclamationFill,
};
export function Alert({ text, icon, button, content, initialExpanded = false, variant = 'default', className, qa, }) {
    const [isExpanded, setIsExpanded] = useState(initialExpanded);
    const statusIcon = useMemo(() => {
        if (icon) {
            return _jsx("div", { className: b('icon'), children: icon });
        }
        const iconData = variant ? statusIcons[variant] : null;
        if (iconData) {
            return _jsx(Icon, { data: iconData, size: 14, className: b('icon', { variant }) });
        }
        return null;
    }, [icon, variant]);
    const toggleExpanded = () => {
        setIsExpanded((prev) => !prev);
    };
    return (_jsxs("div", { className: b(null, className), "data-qa": qa, children: [_jsxs("div", { className: b('header'), children: [_jsxs("div", { className: b('icon-with-text-wrapper'), children: [_jsx("div", { className: b('icon-wrapper'), children: statusIcon }), _jsx(Text, { variant: "body-1", className: b('text'), children: text })] }), content && (_jsx(Button, { onClick: toggleExpanded, size: "s", view: "flat", className: b('collapse-button'), children: _jsx(Icon, { data: isExpanded ? ChevronUp : ChevronDown, size: 16 }) })), button ? (_jsx(Button, { onClick: button.onClick, size: "s", view: "outlined", className: b('action'), children: button.content })) : null] }), content && isExpanded && _jsx("div", { className: b('content'), children: content })] }));
}
//# sourceMappingURL=index.js.map
