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