"use client";
import { jsx as _jsx } from "react/jsx-runtime";
import { createContext, useContext, useMemo, useSyncExternalStore } from "react";
import { toastManager } from "./ToastManager.js";
const context = /*#__PURE__*/ createContext(toastManager);
context.displayName = "ToastManager";
const { Provider } = context;
/**
 * This is mostly an internal hook to implement the toast functionality but can
 * be used externally as well for custom toast behavior if the other hooks do
 * not support your needs.
 *
 * @see {@link useAddToast}
 * @see {@link useToastQueue}
 * @see {@link useRemoveToast}
 *
 * @returns The current `ToastManager` set in the `ToastManagerProvider`.
 * Defaults to {@link toastManager} if there are no parent providers.
 * @since 6.0.0
 */ export function useToastManager() {
    return useContext(context);
}
/**
 * @see {@link ToastManager.addToast}
 * @since 6.0.0
 */ export function useAddToast() {
    return useToastManager().addToast;
}
/**
 * @see {@link ToastManager.removeToast}
 * @since 6.0.0
 */ export function useRemoveToast() {
    return useToastManager().removeToast;
}
/**
 * @param limit - the total number of toasts that can be visible at once.
 * @since 6.0.0
 */ export function useToastQueue(limit) {
    const toastManager = useToastManager();
    const queue = useSyncExternalStore(toastManager.subscribe, toastManager.getQueue, toastManager.getQueue);
    return useMemo(()=>{
        if (!limit) {
            return queue;
        }
        return queue.slice(0, limit);
    }, [
        limit,
        queue
    ]);
}
/**
 * **Client Component**
 *
 * This component can be used to implement separate instances of toasts if
 * required in your app. This probably shouldn't be required for most apps with
 * the default {@link addToast}, {@link removeToast}, and {@link clearToasts}
 * implementation.
 *
 * @see {@link https://react-md.dev/components/snackbar | Snackbar Demos}
 * @see {@link ToastManager} for example usage.
 * @since 6.0.0
 */ export function ToastManagerProvider(props) {
    const { children, manager = toastManager } = props;
    return /*#__PURE__*/ _jsx(Provider, {
        value: manager,
        children: children
    });
}

//# sourceMappingURL=ToastManagerProvider.js.map