"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ModalNotification = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
/**
 * ModalNotification Component
 *
 * A notification that appears in a modal dialog
 */
const react_1 = require("react");
const prop_types_1 = __importDefault(require("prop-types"));
/**
 * ModalNotification component
 * @param {Object} props - Component props
 * @param {string} props.type - Notification type (info, success, warning, error)
 * @param {string} props.title - Notification title
 * @param {React.ReactNode} props.message - Notification message
 * @param {Function} props.onClose - Close handler
 * @param {number} props.autoCloseDelay - Auto-close delay in ms (0 to disable)
 * @param {boolean} props.showCloseButton - Whether to show a close button
 * @param {Array} props.actions - Action buttons configuration
 * @param {string} props.className - Additional CSS classes
 * @param {Object} props.style - Additional inline styles
 * @param {boolean} props.backdrop - Whether to show a backdrop
 * @param {boolean} props.isDismissible - Whether the notification can be dismissed by clicking outside
 * @returns {React.ReactElement|null} ModalNotification component or null if closed
 */
const ModalNotification = ({ type = 'info', title, message, onClose, autoCloseDelay = 0, showCloseButton = true, actions = [], className = '', style = {}, backdrop = true, isDismissible = true, ...rest }) => {
    // State
    const [isVisible, setIsVisible] = (0, react_1.useState)(true);
    // Auto-close effect
    (0, react_1.useEffect)(() => {
        if (autoCloseDelay > 0) {
            const timer = setTimeout(() => {
                handleClose();
            }, autoCloseDelay);
            return () => clearTimeout(timer);
        }
    }, [autoCloseDelay]);
    // Close handler
    const handleClose = () => {
        setIsVisible(false);
        // Wait for animation to complete
        setTimeout(() => {
            if (onClose)
                onClose();
        }, 300);
    };
    // Backdrop click handler
    const handleBackdropClick = (e) => {
        if (e.target === e.currentTarget && isDismissible) {
            handleClose();
        }
    };
    // Don't render if not visible
    if (!isVisible)
        return null;
    // Get icon based on type
    const getIcon = () => {
        switch (type) {
            case 'success':
                return ((0, jsx_runtime_1.jsxs)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [(0, jsx_runtime_1.jsx)("path", { d: "M22 11.08V12a10 10 0 1 1-5.93-9.14" }), (0, jsx_runtime_1.jsx)("polyline", { points: "22 4 12 14.01 9 11.01" })] }));
            case 'error':
                return ((0, jsx_runtime_1.jsxs)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [(0, jsx_runtime_1.jsx)("circle", { cx: "12", cy: "12", r: "10" }), (0, jsx_runtime_1.jsx)("line", { x1: "15", y1: "9", x2: "9", y2: "15" }), (0, jsx_runtime_1.jsx)("line", { x1: "9", y1: "9", x2: "15", y2: "15" })] }));
            case 'warning':
                return ((0, jsx_runtime_1.jsxs)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [(0, jsx_runtime_1.jsx)("path", { d: "M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z" }), (0, jsx_runtime_1.jsx)("line", { x1: "12", y1: "9", x2: "12", y2: "13" }), (0, jsx_runtime_1.jsx)("line", { x1: "12", y1: "17", x2: "12.01", y2: "17" })] }));
            case 'info':
            default:
                return ((0, jsx_runtime_1.jsxs)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [(0, jsx_runtime_1.jsx)("circle", { cx: "12", cy: "12", r: "10" }), (0, jsx_runtime_1.jsx)("line", { x1: "12", y1: "16", x2: "12", y2: "12" }), (0, jsx_runtime_1.jsx)("line", { x1: "12", y1: "8", x2: "12.01", y2: "8" })] }));
        }
    };
    // Classes
    const modalClasses = [
        'bf-modal-notification',
        `bf-modal-notification--${type}`,
        isVisible ? 'bf-modal-notification--visible' : 'bf-modal-notification--hidden',
        className
    ].filter(Boolean).join(' ');
    // Render
    return ((0, jsx_runtime_1.jsxs)("div", { className: "bf-modal-notification__container", onClick: handleBackdropClick, role: "dialog", "aria-modal": "true", "aria-labelledby": "modal-notification-title", "aria-describedby": "modal-notification-message", children: [backdrop && ((0, jsx_runtime_1.jsx)("div", { className: "bf-modal-notification__backdrop" })), (0, jsx_runtime_1.jsxs)("div", { className: modalClasses, style: style, ...rest, children: [(0, jsx_runtime_1.jsxs)("div", { className: "bf-modal-notification__header", children: [(0, jsx_runtime_1.jsx)("div", { className: "bf-modal-notification__icon", children: getIcon() }), title && ((0, jsx_runtime_1.jsx)("h2", { id: "modal-notification-title", className: "bf-modal-notification__title", children: title })), showCloseButton && ((0, jsx_runtime_1.jsx)("button", { className: "bf-modal-notification__close-button", onClick: handleClose, "aria-label": "Close notification", children: (0, jsx_runtime_1.jsxs)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [(0, jsx_runtime_1.jsx)("line", { x1: "18", y1: "6", x2: "6", y2: "18" }), (0, jsx_runtime_1.jsx)("line", { x1: "6", y1: "6", x2: "18", y2: "18" })] }) }))] }), (0, jsx_runtime_1.jsx)("div", { id: "modal-notification-message", className: "bf-modal-notification__body", children: message }), actions.length > 0 && ((0, jsx_runtime_1.jsx)("div", { className: "bf-modal-notification__footer", children: actions.map((action, index) => ((0, jsx_runtime_1.jsx)("button", { className: `bf-modal-notification__action bf-modal-notification__action--${action.type || 'default'}`, onClick: () => {
                                if (action.onClick)
                                    action.onClick();
                                if (action.closeAfter !== false)
                                    handleClose();
                            }, ...action.props, children: action.label }, index))) }))] })] }));
};
exports.ModalNotification = ModalNotification;
exports.ModalNotification.propTypes = {
    type: prop_types_1.default.oneOf(['info', 'success', 'warning', 'error']),
    title: prop_types_1.default.string,
    message: prop_types_1.default.node,
    onClose: prop_types_1.default.func,
    autoCloseDelay: prop_types_1.default.number,
    showCloseButton: prop_types_1.default.bool,
    actions: prop_types_1.default.arrayOf(prop_types_1.default.shape({
        label: prop_types_1.default.string.isRequired,
        onClick: prop_types_1.default.func,
        type: prop_types_1.default.oneOf(['primary', 'secondary', 'danger', 'default']),
        closeAfter: prop_types_1.default.bool,
        props: prop_types_1.default.object
    })),
    className: prop_types_1.default.string,
    style: prop_types_1.default.object,
    backdrop: prop_types_1.default.bool,
    isDismissible: prop_types_1.default.bool
};
exports.default = exports.ModalNotification;
//# sourceMappingURL=ModalNotification.js.map