import { renderHook } from '@testing-library/react';
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { useGlobalKeyboardShortcuts } from './useGlobalKeyboardShortcuts';

describe('useGlobalKeyboardShortcuts', () => {
  const mockOnHelpOpen = vi.fn();

  beforeEach(() => {
    vi.clearAllMocks();
  });

  afterEach(() => {
    // Cleanup event listeners
    document.removeEventListener('keydown', vi.fn());
  });

  it('should setup global keyboard shortcuts', () => {
    renderHook(() =>
      useGlobalKeyboardShortcuts({
        onHelpOpen: mockOnHelpOpen,
      }),
    );

    // Le hook devrait être défini et fonctionnel
    expect(mockOnHelpOpen).toBeDefined();
  });

  it('should handle keyboard events', () => {
    renderHook(() =>
      useGlobalKeyboardShortcuts({
        onHelpOpen: mockOnHelpOpen,
      }),
    );

    // Simuler une touche de raccourci
    const event = new KeyboardEvent('keydown', {
      key: '?',
      ctrlKey: false,
      shiftKey: false,
      altKey: false,
      metaKey: false,
    });

    document.dispatchEvent(event);

    // Le hook devrait réagir aux événements clavier
    expect(mockOnHelpOpen).toBeDefined();
  });

  it('should handle empty options', () => {
    renderHook(() => useGlobalKeyboardShortcuts({}));

    // Le hook devrait fonctionner même sans options
    expect(true).toBe(true);
  });
});
