"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.ToastContainer = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = __importStar(require("react"));
const acui_1 = require("@Acme Corporation/acui");
const react_dom_1 = require("react-dom");
const ToastContainer = ({ position = 'bottom-right', className = '', children }) => {
    const containerId = react_1.default.useId();
    const [mounted, setMounted] = (0, react_1.useState)(false);
    (0, react_1.useEffect)(() => {
        setMounted(true);
        return () => setMounted(false);
    }, []);
    if (!mounted)
        return null;
    return (0, react_dom_1.createPortal)((0, jsx_runtime_1.jsx)("div", { id: containerId, role: "region", "aria-label": "Notifications", className: `bf-toast-container bf-toast-container-${position} ${className}`, children: children }), document.body);
};
exports.ToastContainer = ToastContainer;
const Toast = (0, react_1.forwardRef)(({ id, title, description, status = 'info', variant = 'subtle', duration = 5000, isClosable = true, onClose, onCloseComplete, position = 'bottom-right', icon, className = '', wrapperClassName = '', titleClassName = '', descriptionClassName = '', iconClassName = '', closeButtonClassName = '', progressClassName = '', children, ...props }, ref) => {
    const theme = (0, acui_1.useTheme)();
    const [isVisible, setIsVisible] = (0, react_1.useState)(true);
    const [progress, setProgress] = (0, react_1.useState)(100);
    const toastId = react_1.default.useId();
    const titleId = react_1.default.useId();
    const descriptionId = react_1.default.useId();
    const handleClose = (0, react_1.useCallback)((event) => {
        if (event) {
            event.preventDefault();
        }
        setIsVisible(false);
        onClose?.();
    }, [onClose]);
    const handleAnimationEnd = (0, react_1.useCallback)(() => {
        if (!isVisible) {
            onCloseComplete?.();
        }
    }, [isVisible, onCloseComplete]);
    (0, react_1.useEffect)(() => {
        if (duration === null)
            return;
        const startTime = Date.now();
        const endTime = startTime + duration;
        const updateProgress = () => {
            const now = Date.now();
            const remaining = endTime - now;
            const newProgress = (remaining / duration) * 100;
            if (remaining <= 0) {
                setProgress(0);
                handleClose();
                return;
            }
            setProgress(newProgress);
            requestAnimationFrame(updateProgress);
        };
        const animationFrame = requestAnimationFrame(updateProgress);
        return () => {
            cancelAnimationFrame(animationFrame);
        };
    }, [duration, handleClose]);
    const ariaProps = {
        role: 'alert',
        'aria-live': 'assertive',
        'aria-atomic': 'true',
        'aria-labelledby': title ? titleId : undefined,
        'aria-describedby': description ? descriptionId : undefined
    };
    const progressAriaProps = {
        role: 'progressbar',
        'aria-valuenow': Math.round(progress),
        'aria-valuemin': 0,
        'aria-valuemax': 100
    };
    const defaultIcons = {
        info: ((0, jsx_runtime_1.jsxs)("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [(0, jsx_runtime_1.jsx)("circle", { cx: "12", cy: "12", r: "10" }), (0, jsx_runtime_1.jsx)("path", { d: "M12 16v-4M12 8h.01" })] })),
        success: ((0, jsx_runtime_1.jsxs)("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", 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" })] })),
        warning: ((0, jsx_runtime_1.jsxs)("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", 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" })] })),
        error: ((0, jsx_runtime_1.jsxs)("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", 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" })] }))
    };
    const renderIcon = () => {
        if (icon) {
            return ((0, jsx_runtime_1.jsx)("span", { className: `bf-toast-icon ${iconClassName}`, "aria-hidden": "true", children: icon }));
        }
        return ((0, jsx_runtime_1.jsx)("span", { className: `bf-toast-icon ${iconClassName}`, "aria-hidden": "true", children: defaultIcons[status] }));
    };
    return ((0, jsx_runtime_1.jsx)("div", { ref: ref, id: id || toastId, ...ariaProps, className: `bf-toast-wrapper ${wrapperClassName}`, "data-status": status, "data-variant": variant, "data-position": position, "data-visible": isVisible, onAnimationEnd: handleAnimationEnd, children: (0, jsx_runtime_1.jsxs)("div", { className: `bf-toast ${className}`, children: [renderIcon(), (0, jsx_runtime_1.jsxs)("div", { className: "bf-toast-content", children: [title && ((0, jsx_runtime_1.jsx)("div", { id: titleId, className: `bf-toast-title ${titleClassName}`, children: title })), description && ((0, jsx_runtime_1.jsx)("div", { id: descriptionId, className: `bf-toast-description ${descriptionClassName}`, children: description })), children] }), isClosable && ((0, jsx_runtime_1.jsx)("button", { type: "button", className: `bf-toast-close-button ${closeButtonClassName}`, onClick: handleClose, "aria-label": "Close notification", children: (0, jsx_runtime_1.jsxs)("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", "aria-hidden": "true", 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" })] }) })), duration !== null && ((0, jsx_runtime_1.jsx)("div", { className: `bf-toast-progress ${progressClassName}`, style: { width: `${progress}%` }, ...progressAriaProps }))] }) }));
});
Toast.displayName = 'Toast';
exports.default = (0, react_1.memo)(Toast);
//# sourceMappingURL=Toast.js.map