import { useContext, useEffect, useState } from 'react';
import { useStableCallback } from './useStableCallback';
import { createTimeout } from '../utils/pauseableTimeout';
import { ToastContext } from '../../Toast/ToastContext';
const noop = () => { };
export const useToastTimeout = (delay, callback = noop) => {
    const paused = useContext(ToastContext)?.hidden ?? false;
    const stableCallback = useStableCallback(callback);
    const [timeoutState, setTimeoutState] = useState();
    useEffect(() => {
        if (delay === undefined) {
            return;
        }
        const timeout = createTimeout(stableCallback, delay);
        setTimeoutState(timeout);
        return timeout.clear;
    }, [delay, stableCallback]);
    useEffect(() => {
        if (paused) {
            timeoutState?.pause();
        }
        else {
            timeoutState?.resume();
        }
    }, [timeoutState, paused]);
};
//# sourceMappingURL=useToastTimeout.js.map