type ToastListener = (message: string, severity: 'error' | 'success' | 'info') => void;

const listeners = new Set<ToastListener>();

export function subscribeToast(listener: ToastListener): () => void {
  listeners.add(listener);
  return () => {
    listeners.delete(listener);
  };
}

export function showToast(
  message: string,
  severity: 'error' | 'success' | 'info' = 'info',
): void {
  listeners.forEach((listener) => listener(message, severity));
}
