export const API_ERROR_TOAST_EVENT = 'liqa:api-error-toast'; export interface ApiErrorToastDetail { message: string; } export function emitApiErrorToast(message: string): void { if (typeof window === 'undefined') return; window.dispatchEvent( new CustomEvent(API_ERROR_TOAST_EVENT, { detail: { message }, }), ); } export function subscribeApiErrorToasts(handler: (message: string) => void): () => void { if (typeof window === 'undefined') return () => {}; const listener = (event: Event) => { const custom = event as CustomEvent; const message = custom.detail?.message; if (message) handler(message); }; window.addEventListener(API_ERROR_TOAST_EVENT, listener); return () => { window.removeEventListener(API_ERROR_TOAST_EVENT, listener); }; }