import React from 'react';
import { describe, it, expect, vi } from 'vitest';
import { render, screen, fireEvent } from '@testing-library/react';
import { BulkActions } from '@/components/dms/BulkActions';
import type { DmsFolder } from '@/api/dms';

vi.mock('@/api/dms', () => ({
  bulkMoveFiles: vi.fn().mockResolvedValue(undefined),
  bulkDeleteFiles: vi.fn().mockResolvedValue(undefined),
}));

vi.mock('@/components/ui/Toast', () => ({
  useToast: () => ({ success: vi.fn(), error: vi.fn(), info: vi.fn() }),
}));

const mockFolders: DmsFolder[] = [
  { id: 'folder1', name: 'Documents', parent_id: null, created_by: 'user1', created_at: '2024-01-01T00:00:00Z' },
  { id: 'folder2', name: 'Images', parent_id: null, created_by: 'user1', created_at: '2024-01-01T00:00:00Z' },
];

const defaultProps = {
  selectedFileIds: new Set(['f1', 'f2', 'f3']),
  folders: mockFolders,
  onClear: vi.fn(),
  onActionComplete: vi.fn(),
};

describe('BulkActions', () => {
  it('renders bulk actions bar when files are selected', () => {
    render(<BulkActions {...defaultProps} />);
    expect(screen.getByTestId('bulk-actions-bar')).toBeInTheDocument();
  });

  it('does not render when no files selected', () => {
    render(<BulkActions {...defaultProps} selectedFileIds={new Set()} />);
    expect(screen.queryByTestId('bulk-actions-bar')).not.toBeInTheDocument();
  });

  it('renders selected file count', () => {
    render(<BulkActions {...defaultProps} />);
    expect(screen.getByText(/3/)).toBeInTheDocument();
  });

  it('renders move button', () => {
    render(<BulkActions {...defaultProps} />);
    expect(screen.getByText(/move|verschieben/i)).toBeInTheDocument();
  });

  it('renders delete button', () => {
    render(<BulkActions {...defaultProps} />);
    expect(screen.getByText(/delete|löschen/i)).toBeInTheDocument();
  });

  it('renders cancel/clear button', () => {
    render(<BulkActions {...defaultProps} />);
    expect(screen.getByText(/cancel|abbrechen/i)).toBeInTheDocument();
  });

  it('calls onClear when cancel button clicked', () => {
    render(<BulkActions {...defaultProps} />);
    fireEvent.click(screen.getByText(/cancel|abbrechen/i));
    expect(defaultProps.onClear).toHaveBeenCalled();
  });
});
