import { create } from 'zustand';
let toastId = 0;
export const useToastStore = create((set) => ({
    toasts: [],
    addToast: (toast) => {
        const id = `toast-${++toastId}`;
        set((state) => ({
            toasts: [...state.toasts, { ...toast, id }],
        }));
        return id;
    },
    removeToast: (id) => set((state) => ({
        toasts: state.toasts.filter((t) => t.id !== id),
    })),
    updateToast: (id, updates) => set((state) => ({
        toasts: state.toasts.map((t) => (t.id === id ? { ...t, ...updates } : t)),
    })),
    clearToasts: () => set({ toasts: [] }),
}));
export function toast(message, type = 'default', duration = 4000) {
    const id = useToastStore.getState().addToast({ message, type, duration });
    if (duration > 0) {
        setTimeout(() => {
            useToastStore.getState().removeToast(id);
        }, duration);
    }
    return id;
}
toast.success = (message, duration = 4000) => toast(message, 'success', duration);
toast.error = (message, duration = 5000) => toast(message, 'error', duration);
toast.loading = (message) => toast(message, 'loading', 0);
toast.successWithAction = (message, action, duration = 6000) => {
    const id = useToastStore.getState().addToast({
        message,
        type: 'success',
        duration,
        action,
    });
    if (duration > 0) {
        setTimeout(() => {
            useToastStore.getState().removeToast(id);
        }, duration);
    }
    return id;
};
//# sourceMappingURL=toastStore.js.map