/**
 * Notification context — provides a `push()` helper that surfaces
 * toast-style notifications via `react-native-toast-message`.
 *
 * Mount `<NotificationProvider>` somewhere above the components that
 * consume `useNotificationContext()`. The `<Toast />` component itself
 * must be rendered separately in the app root (see
 * `react-native-toast-message` docs).
 *
 * The vault notification provider also bridged a WebSocket service into
 * this context to dispatch server-pushed toasts; that piece is
 * app-specific and not included here. Consumers that need it can build
 * a thin wrapper around this provider.
 */
import React, { createContext, useCallback, useContext, useMemo } from "react";
import Toast from "react-native-toast-message";
const NotificationContext = createContext(null);
const LEVEL_TO_TOAST_TYPE = {
    success: "success",
    error: "error",
    // react-native-toast-message only ships success/error/info — warnings
    // map onto error so they show with the warning-coloured icon.
    warning: "error",
    info: "info",
};
export function NotificationProvider({ children }) {
    const push = useCallback((options) => {
        Toast.show({
            type: LEVEL_TO_TOAST_TYPE[options.level],
            text1: options.title,
            text2: options.message,
            visibilityTime: options.ttl_ms ?? 4000,
        });
    }, []);
    // Memoize the context value so an inline-object identity churn
    // doesn't re-render every consumer on each NotificationProvider
    // render. `push` is already `useCallback`-stable, so the memo
    // effectively pins the value across the provider's lifetime.
    const value = useMemo(() => ({ push }), [push]);
    return <NotificationContext.Provider value={value}>{children}</NotificationContext.Provider>;
}
export function useNotificationContext() {
    const ctx = useContext(NotificationContext);
    if (!ctx) {
        throw new Error("useNotificationContext must be used inside <NotificationProvider>");
    }
    return ctx;
}
//# sourceMappingURL=NotificationContext.jsx.map