"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = AlertLibrary;
const tslib_1 = require("tslib");
const react_1 = require("react");
const use_event_bus_1 = require("../../hooks/use-event-bus");
const constants_1 = require("./constants");
const __1 = require("../../../..");
const react_2 = tslib_1.__importDefault(require("react"));
function AlertLibrary() {
    const [data, setData] = (0, react_1.useState)({
        message: '',
        isFailure: false,
        show: false,
        type: 'add',
    });
    (0, use_event_bus_1.useMainwrapV4EventBus)(constants_1.KEY_ALERT_LIBRARY, (payload) => {
        const { message, isFailure, show, type } = payload;
        setData({
            type,
            isFailure: isFailure || false,
            message: message || '',
            show,
        });
    });
    (0, react_1.useEffect)(() => {
        if (data.show) {
            const timerId = setTimeout(() => {
                setData((pre) => ({ ...pre, show: false, isFailure: false }));
            }, 10000);
            return () => clearTimeout(timerId);
        }
        return;
    }, [data.show]);
    return (react_2.default.createElement(__1.PHXNotifications, { className: 'z-[9999]', customMessage: data.message, failure: data.isFailure, onHide: () => setData((pre) => ({ ...pre, show: false })), show: data.show, 
        // @ts-ignore
        type: data.type }));
}
//# sourceMappingURL=alert.js.map