/**
 * Standard toast message patterns for RankWiz AI.
 * Ensures consistent user feedback across the application.
 *
 * Usage:
 *   const { successToast, errorToast } = useToastMessages();
 *   successToast('Changes saved!');
 *   errorToast('Failed to save. Try again.');
 */

import { toast } from 'sonner';

import { useCallback } from 'react';

/**
 * Toast message variants with standardized text patterns.
 * Helps users understand success, errors, and other outcomes consistently.
 */
export const TOAST_MESSAGES = {
  /* Success messages - brief, action-oriented */
  success: {
    saved: 'Changes saved!',
    created: 'Created successfully!',
    deleted: 'Deleted successfully!',
    updated: 'Updated successfully!',
    published: 'Published successfully!',
    copied: 'Copied to clipboard!',
    connected: 'Connected successfully!',
  },

  /* Error messages - brief, non-alarming, suggest action */
  error: {
    generic: 'Something went wrong. Try again.',
    network: 'Network error. Check your connection and try again.',
    unauthorized: 'You do not have permission to perform this action.',
    notFound: 'Item not found. It may have been deleted.',
    validation: 'Check your input and try again.',
    timeout: 'Request timed out. Try again.',
    limits: 'You have reached your usage limit. Upgrade your plan.',
  },

  /* Info/warning messages - helpful context */
  info: {
    loading: 'Loading...',
    processing: 'Processing...',
    saving: 'Saving...',
  },
};

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

export interface ToastMessage {
  type: ToastType;
  title: string;
  description?: string;
  duration?: number;
}

/**
 * Hook for standardized toast notifications via Sonner.
 * Returns helper functions for consistent user feedback across the app.
 */
export function useToastMessages() {
  const successToast = useCallback((message: string) => {
    toast.success(message, { duration: 4000 });
  }, []);

  const errorToast = useCallback((message: string) => {
    toast.error(message, { duration: 7000 });
  }, []);

  const warningToast = useCallback((message: string) => {
    toast.warning(message, { duration: 5000 });
  }, []);

  const infoToast = useCallback((message: string) => {
    toast.info(message, { duration: 4000 });
  }, []);

  return {
    successToast,
    errorToast,
    warningToast,
    infoToast,
    TOAST_MESSAGES,
  };
}
