"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Alert = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const CrossOutlineMd_1 = require("../../icons/CrossOutlineMd");
const ErrorFillMd_1 = require("../../icons/ErrorFillMd");
const InfoFillMd_1 = require("../../icons/InfoFillMd");
const SuccessFillMd_1 = require("../../icons/SuccessFillMd");
const WarningFillMd_1 = require("../../icons/WarningFillMd");
const Collapse_1 = require("../Collapse");
const classNames_1 = require("../utils/classNames");
const cva_1 = require("../utils/cva");
const constants_1 = require("./constants");
const styles_1 = require("./styles");
const useLogic_1 = require("./useLogic");
const alertCva = (0, cva_1.cva)(constants_1.alertClassnames.root, {
    variants: {
        hasTitle: {
            true: constants_1.alertClassnames.hasTitle,
        },
        hasCloseButton: {
            true: constants_1.alertClassnames.hasCloseButton,
        },
        hasActions: {
            true: constants_1.alertClassnames.hasActions,
        },
        severity: {
            info: constants_1.alertClassnames.severityInfo,
            error: constants_1.alertClassnames.severityError,
            success: constants_1.alertClassnames.severitySuccess,
            warning: constants_1.alertClassnames.severityWarning,
        },
    },
});
exports.Alert = (0, react_1.forwardRef)(({ children, title, closeText = 'Скрыть', display = true, actions, onClose, severity = 'info', style, className, icon, unmountOnExit, }, ref) => {
    const { shouldRenderParagraph } = (0, useLogic_1.useLogic)({ children });
    const renderCloseButton = () => {
        return ((0, jsx_runtime_1.jsx)(styles_1.StyledIconButton, { variant: "text", color: "grey", onClick: onClose, "aria-label": closeText, title: closeText, className: constants_1.alertClassnames.closeButton, children: (0, jsx_runtime_1.jsx)(CrossOutlineMd_1.CrossOutlineMd, {}) }));
    };
    const renderIcon = () => {
        const iconMapping = {
            info: (0, jsx_runtime_1.jsx)(InfoFillMd_1.InfoFillMd, {}),
            error: (0, jsx_runtime_1.jsx)(ErrorFillMd_1.ErrorFillMd, {}),
            success: (0, jsx_runtime_1.jsx)(SuccessFillMd_1.SuccessFillMd, {}),
            warning: (0, jsx_runtime_1.jsx)(WarningFillMd_1.WarningFillMd, {}),
        };
        return ((0, jsx_runtime_1.jsx)(styles_1.IconWrapper, { className: constants_1.alertClassnames.iconWrapper, children: icon ?? iconMapping[severity] }));
    };
    return ((0, jsx_runtime_1.jsx)(Collapse_1.Collapse, { in: display, unmountOnExit: unmountOnExit, children: (0, jsx_runtime_1.jsxs)(styles_1.Wrapper, { style: style, className: (0, classNames_1.classNames)(alertCva({
                hasTitle: Boolean(title),
                hasCloseButton: Boolean(onClose),
                hasActions: Boolean(actions),
                severity,
            }), className), role: "alert", ref: ref, children: [(0, jsx_runtime_1.jsxs)(styles_1.Content, { className: constants_1.alertClassnames.contentWrapper, children: [renderIcon(), title && ((0, jsx_runtime_1.jsx)(styles_1.Title, { variant: "h5", className: constants_1.alertClassnames.title, children: title })), onClose && renderCloseButton(), (0, jsx_runtime_1.jsx)(styles_1.StyledTypography, { component: shouldRenderParagraph ? 'p' : 'div', className: constants_1.alertClassnames.content, children: children })] }), actions && ((0, jsx_runtime_1.jsx)(styles_1.StyledGrid, { container: true, spacing: 4, children: actions }))] }) }));
});
