// src/services/notificationService.ts
import toast, { ToastOptions } from '../lib/toast';

const commonToastOptions: ToastOptions = {
  style: {
    borderRadius: '8px',
    background: 'var(--toast-bg, #333)', // Uses CSS variables for theming
    color: 'var(--toast-color, #fff)',
    boxShadow: '0 4px 12px rgba(0, 0, 0, 0.15)',
  },
};

// Define a minimal interface for the toaster to allow mocking
export interface Toaster {
    success: (message: string, options?: ToastOptions) => string;
    error: (message: string, options?: ToastOptions) => string;
}

/**
 * Displays a success toast notification.
 * @param message The message to display.
 * @param toaster Optional toaster instance (for testing). Defaults to the imported toast library.
 */
export const notifySuccess = (message: string, toaster: Toaster = toast) => {
  // Defensive check: Ensure the toaster instance is valid
  if (!toaster || typeof toaster.success !== 'function') {
      console.warn('[NotificationService] toast.success is not available. Message:', message);
      return;
  }

  toaster.success(message, {
    ...commonToastOptions,
    iconTheme: {
      primary: '#10B981', // Emerald-500
      secondary: '#fff',
    },
  });
};

/**
 * Displays an error toast notification.
 * @param message The message to display.
 * @param toaster Optional toaster instance (for testing). Defaults to the imported toast library.
 */
export const notifyError = (message: string, toaster: Toaster = toast) => {
  // Defensive check
  if (!toaster || typeof toaster.error !== 'function') {
    console.warn('[NotificationService] toast.error is not available. Message:', message);
    return;
  }

  toaster.error(message, {
    ...commonToastOptions,
    iconTheme: {
      primary: '#EF4444', // Red-500
      secondary: '#fff',
    },
  });
};