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