import { describe, it, expect, vi, beforeEach } from 'vitest';
import { renderHook } from '@testing-library/react';
import { useToast } from './useToast';
import { useToastContext } from '@/components/feedback/ToastProvider';

// Mock ToastProvider
vi.mock('@/components/feedback/ToastProvider', () => ({
  useToastContext: vi.fn(),
}));

const mockAddToast = vi.fn();

describe('useToast', () => {
  beforeEach(() => {
    vi.clearAllMocks();
    vi.mocked(useToastContext).mockReturnValue({
      addToast: mockAddToast,
    } as any);
  });

  it('should return toast functions', () => {
    const { result } = renderHook(() => useToast());

    expect(result.current.success).toBeDefined();
    expect(result.current.error).toBeDefined();
    expect(result.current.warning).toBeDefined();
    expect(result.current.info).toBeDefined();
    expect(result.current.toast).toBeDefined();
  });

  it('should call addToast with success type', () => {
    const { result } = renderHook(() => useToast());

    result.current.success('Success message');

    expect(mockAddToast).toHaveBeenCalledWith({
      message: 'Success message',
      type: 'success',
      duration: undefined,
    });
  });

  it('should call addToast with success type and duration', () => {
    const { result } = renderHook(() => useToast());

    result.current.success('Success message', 5000);

    expect(mockAddToast).toHaveBeenCalledWith({
      message: 'Success message',
      type: 'success',
      duration: 5000,
    });
  });

  it('should call addToast with error type', () => {
    const { result } = renderHook(() => useToast());

    result.current.error('Error message');

    expect(mockAddToast).toHaveBeenCalledWith({
      message: 'Error message',
      type: 'error',
      duration: undefined,
    });
  });

  it('should call addToast with warning type', () => {
    const { result } = renderHook(() => useToast());

    result.current.warning('Warning message');

    expect(mockAddToast).toHaveBeenCalledWith({
      message: 'Warning message',
      type: 'warning',
      duration: undefined,
    });
  });

  it('should call addToast with info type', () => {
    const { result } = renderHook(() => useToast());

    result.current.info('Info message');

    expect(mockAddToast).toHaveBeenCalledWith({
      message: 'Info message',
      type: 'info',
      duration: undefined,
    });
  });

  it('should call addToast with custom toast object', () => {
    const { result } = renderHook(() => useToast());

    result.current.toast({
      message: 'Custom message',
      type: 'success',
      duration: 3000,
    });

    expect(mockAddToast).toHaveBeenCalledWith({
      message: 'Custom message',
      type: 'success',
      duration: 3000,
    });
  });
});
