import { writable } from 'svelte/store';
export const toasts = writable([]);
export const addToast = (toast) => {
    // Create a unique ID so we can easily find/remove it
    // if it is dismissible/has a timeout.
    const id = Math.floor(Math.random() * 10000);
    const defaultToast = {
        id,
        autoDismissAfter: 6000
    };
    // Push the toast to the top of the list of toasts
    toasts.update((all) => [{ ...defaultToast, ...toast }, ...all]);
    // If toast is dismissible, dismiss it after "timeout" milliseconds.
    if (toast.autoDismissAfter)
        setTimeout(() => dismissToast(id), toast.autoDismissAfter);
    // Return the generated ID
    return id;
};
export const dismissToast = (id) => {
    toasts.update((all) => all.filter((t) => t.id !== id));
};
