var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import * as React from "react";
import { useState, useCallback, useEffect } from "react";
import { cn } from "@utils";
import { toastVariants, toastIconVariants, toastContentWrapperVariants, toastContentVariants, toastCloseButtonVariants } from "./toastVariants";
import { ADPIcon, iconList } from "../adpIcon";
import { Button } from "../button";
const variantMapping = {
    info: iconList.infoFilled,
    success: iconList.checkCircleFilled,
    warning: iconList.alertFilled,
    error: iconList.timesCircleFilled
};
/**
 * Toast component for displaying notifications or alerts.
 */
export const Toast = React.forwardRef((_a, ref) => {
    var { variant = "info", display = true, children, autoHideDelay, hideCloseButton = false, onClose, condensed = true, className } = _a, props = __rest(_a, ["variant", "display", "children", "autoHideDelay", "hideCloseButton", "onClose", "condensed", "className"]);
    const [show, setShow] = useState(display);
    const hideToast = useCallback(() => {
        onClose === null || onClose === void 0 ? void 0 : onClose();
        setShow(false);
    }, [onClose]);
    useEffect(() => {
        setShow(display);
    }, [display]);
    useEffect(() => {
        let autoHide;
        if (typeof autoHideDelay === "number") {
            autoHide = setTimeout(hideToast, Math.round(autoHideDelay));
        }
        return () => {
            if (autoHide) {
                clearTimeout(autoHide);
            }
        };
    }, [autoHideDelay, hideToast]);
    return show ? (_jsxs("div", Object.assign({ ref: ref, className: cn(toastVariants({ variant }), className), role: "alert", "aria-live": "assertive", "aria-atomic": "true" }, props, { children: [_jsx("div", { className: cn(toastIconVariants({ variant, condensed })), children: condensed && _jsx(ADPIcon, { icon: variantMapping[variant], size: "md" }) }), _jsxs("div", { className: cn(toastContentWrapperVariants()), children: [children && _jsx("div", { className: cn(toastContentVariants()), children: children }), !hideCloseButton && (_jsx(Button, { prefixIcon: "cross", onClick: hideToast, variant: "text", color: "secondary", className: cn(toastCloseButtonVariants()), size: "xl" }))] })] }))) : null;
});
Toast.displayName = "Toast";
//# sourceMappingURL=toast.js.map