import type { ToastMessageOptions } from 'primevue/toast'; import toasteventbus from 'primevue/toasteventbus'; function add (toast: ToastMessageOptions): string { const id = 'toast-' + Date.now() + Math.random().toString(36); toasteventbus.emit('add', { ...toast, id }); return id; } function success (toast: Omit) { return add({ summary: 'Success', life: 4000, ...toast, severity: 'success' }); } function info (toast: Omit) { return add({ summary: 'Info', life: 4000, ...toast, severity: 'info' }); } function warn (toast: Omit) { return add({ summary: 'Warning', ...toast, severity: 'warn' }); } function error (toast: Omit) { return add({ summary: 'Error', ...toast, severity: 'error' }); } function secondary (toast: Omit) { return add({ life: 4000, ...toast, severity: 'secondary' }); } function contrast (toast: Omit) { return add({ life: 4000, ...toast, severity: 'contrast' }); } function remove (id: string) { toasteventbus.emit('remove', { id }); } function removeGroup (group: string) { toasteventbus.emit('remove-group', group); } function removeAllGroups () { toasteventbus.emit('remove-all-groups'); } export default { add, success, info, warn, error, secondary, contrast, remove, removeGroup, removeAllGroups, };