import { writable } from 'svelte/store';

export interface Toast { id: number; type: 'success' | 'error' | 'info'; title: string; message?: string; }

let _id = 0;
export const toasts = writable<Toast[]>([]);

export function addToast(type: Toast['type'], title: string, message = '') {
  const id = ++_id;
  toasts.update(t => [...t, { id, type, title, message }]);
  setTimeout(() => toasts.update(t => t.filter(x => x.id !== id)), 4000);
}
