
type ToastType = 'success' | 'error' | 'warning' | 'info';

interface ToastHandler {
  showToast: (type: ToastType, message: string, title?: string) => void;
}

let handler: ToastHandler | null = null;

export const registerToastHandler = (h: ToastHandler) => {
  handler = h;
};

export const toast = {
  success: (message: string, title?: string) => {
    if (handler) handler.showToast('success', message, title);
    else console.log(`✅ ${message}`);
  },
  error: (message: string, title?: string) => {
    if (handler) handler.showToast('error', message, title);
    else console.log(`❌ ${message}`);
  },
  info: (message: string, title?: string) => {
    if (handler) handler.showToast('info', message, title);
    else console.log(`ℹ️ ${message}`);
  },
  warning: (message: string, title?: string) => {
    if (handler) handler.showToast('warning', message, title);
    else console.log(`⚠️ ${message}`);
  }
};