// 为非组件文件提供全局 snackbar 实例
const getSnackbarInstance = () => {
  if (typeof window !== 'undefined') {
    return (window as any).__snackbarInstance;
  }
  return null;
};

export const snackbar = {
  success: (msg: string, duration?: number) => 
    getSnackbarInstance()?.showMessage.success(msg, duration),
  error: (msg: string, duration?: number) => 
    getSnackbarInstance()?.showMessage.error(msg, duration),
  warning: (msg: string, duration?: number) => 
    getSnackbarInstance()?.showMessage.warning(msg, duration),
  info: (msg: string, duration?: number) => 
    getSnackbarInstance()?.showMessage.info(msg, duration),
};

export const notification = {
  success: (title: string, message?: string, duration?: number) => 
    getSnackbarInstance()?.showNotification.success(title, message, duration),
  error: (title: string, message?: string, duration?: number) => 
    getSnackbarInstance()?.showNotification.error(title, message, duration),
  warning: (title: string, message?: string, duration?: number) => 
    getSnackbarInstance()?.showNotification.warning(title, message, duration),
  info: (title: string, message?: string, duration?: number) => 
    getSnackbarInstance()?.showNotification.info(title, message, duration),
};