import { useEffect, useState } from 'react';
import { useMainwrapV4EventBus } from '../../hooks/use-event-bus';
import { KEY_ALERT_LIBRARY } from './constants';
import { PHXNotifications } from '../../../..';
import React from 'react';
export default function AlertLibrary() {
    const [data, setData] = useState({
        message: '',
        isFailure: false,
        show: false,
        type: 'add',
    });
    useMainwrapV4EventBus(KEY_ALERT_LIBRARY, (payload) => {
        const { message, isFailure, show, type } = payload;
        setData({
            type,
            isFailure: isFailure || false,
            message: message || '',
            show,
        });
    });
    useEffect(() => {
        if (data.show) {
            const timerId = setTimeout(() => {
                setData((pre) => ({ ...pre, show: false, isFailure: false }));
            }, 10000);
            return () => clearTimeout(timerId);
        }
        return;
    }, [data.show]);
    return (React.createElement(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