import { create } from "zustand";
import type { ToastLayoutProps } from "../components/toasts/ToastLayout";

interface ToastState {
    toasts: ToastLayoutProps[];
    addToast: (toast: ToastLayoutProps) => void;
    removeToast: (id: ToastLayoutProps["id"]) => void;
    clearToasts: () => void;
}

const useToastsStore = create<ToastState>((set) => ({
    toasts: [],
    addToast: (toast) => 
        set((state) => ({
            toasts: [...state.toasts, toast],
        })),
    removeToast: (id) =>
        set((state) => ({
            toasts: state.toasts.filter((toast) => toast.id !== id),
        })),
    clearToasts: () => set({ toasts: [] }),
}));

export default useToastsStore;