import { useCallback, useState } from "react";
import { createSimpleContext } from "../simple";
const useStillNoficationsProvider = () => {
    const [notifications, setNotifications] = useState([]);
    const deleteNotification = useCallback((notificationType, options) => {
        const key = options
            ? JSON.stringify({ type: notificationType, options })
            : JSON.stringify({ type: notificationType });
        setNotifications((oldNotifications) => {
            return oldNotifications.filter((props) => JSON.stringify(props) !== key);
        });
    }, []);
    const addNotification = useCallback((newNotification) => {
        const key = JSON.stringify(newNotification);
        setNotifications((prev) => {
            const typeAlreadyExist = prev.find((props) => JSON.stringify(props) === key);
            return typeAlreadyExist ? prev : [...prev, newNotification];
        });
    }, []);
    return {
        notifications,
        showBadge: Boolean(notifications.length),
        addNotification,
        deleteNotification,
    };
};
const Context = createSimpleContext("still-notifications", {
    notifications: [],
    showBadge: false,
    deleteNotification: (notificationType, options) => {
        throw new Error("deleteNotification");
    },
    addNotification: () => {
        throw new Error("addNotification");
    },
}, useStillNoficationsProvider);
export const StillNotificationsProvider = Context.Provider;
export const useStillNotifications = Context.useContext;
//# sourceMappingURL=context.js.map