import { injectService, SERVICE_TOKENS } from '@/core/di-container'
import type { ToastService } from '@/core/services/ToastService'

/**
 * Composable for accessing centralized toast notifications
 * Provides consistent toast patterns across the application
 */
export function useToast() {
  const toastService = injectService(SERVICE_TOKENS.TOAST_SERVICE) as ToastService

  if (!toastService) {
    console.error('ToastService not available - make sure base module is installed')
    // Return a fallback that does nothing to prevent runtime errors
    return {
      success: () => {},
      error: () => {},
      info: () => {},
      warning: () => {},
      loading: () => '',
      dismiss: () => {},
      auth: {
        loginSuccess: () => {},
        loginError: () => {},
        logoutSuccess: () => {},
        registrationSuccess: () => {},
        registrationError: () => {}
      },
      payment: {
        processing: () => '',
        success: () => {},
        failed: () => {},
        copied: () => {},
        copyFailed: () => {}
      },
      clipboard: {
        copied: () => {},
        copyFailed: () => {}
      },
      operation: {
        success: () => {},
        failed: () => {},
        loading: () => ''
      },
      asyncOperation: async <T>(operation: Promise<T>) => operation
    }
  }

  return {
    // Basic toast methods
    success: toastService.success.bind(toastService),
    error: toastService.error.bind(toastService),
    info: toastService.info.bind(toastService),
    warning: toastService.warning.bind(toastService),
    loading: toastService.loading.bind(toastService),
    dismiss: toastService.dismiss.bind(toastService),

    // Context-specific methods
    auth: toastService.auth,
    payment: toastService.payment,
    clipboard: toastService.clipboard,
    operation: toastService.operation,

    // Advanced method
    asyncOperation: toastService.asyncOperation.bind(toastService)
  }
}