import { describe, it, expect, vi } from 'vitest';
import { screen, waitFor } from '@testing-library/react';
import { createListPageTests } from '../../test/factories/listPageTests';
import { createFixtureList, createAnalysisFixture } from '../../test/fixtures';
import { renderWithProviders } from '../../test/utils/renderWithProviders';
import AiAnalysisList from './AiAnalysisList';

// Mock useThemeMode
vi.mock('../../hooks/useThemeMode', () => ({
  useThemeMode: () => false,
}));

// Mock suggestion API (used by sub-component)
vi.mock('../../api/ai/suggestions', () => ({
  suggestionApi: {
    list: vi.fn().mockResolvedValue({ data: [], total: 0 }),
    approve: vi.fn(),
  },
}));

const mockAnalyses = createFixtureList(createAnalysisFixture, 6, [
  { id: 'analysis-1', analysis_type: 'lab_report_interpretation', status: 'completed', patient_name: '张三' },
  { id: 'analysis-2', analysis_type: 'health_trend_analysis', status: 'streaming', patient_name: '李四' },
]);

createListPageTests({
  Component: AiAnalysisList,
  apiPath: '/api/v1/ai/analysis/history',
  columns: ['分析类型', '患者', '模型', '状态'],
  firstRowTexts: ['化验单解读'],
  totalItems: 6,
  hasCreateButton: false,
  hasSearch: true,
  hasPagination: true,
  mockItems: mockAnalyses as Record<string, unknown>[],
});

describe('AiAnalysisList extra tests', () => {
  it('renders page header with title', async () => {
    vi.setConfig({ testTimeout: 15000 });
    renderWithProviders(<AiAnalysisList />);
    await waitFor(() => {
      expect(screen.getByText('AI 分析历史')).toBeInTheDocument();
    });
  });

  it('shows analysis type filter dropdown', async () => {
    renderWithProviders(<AiAnalysisList />);
    await waitFor(() => {
      const selects = document.querySelectorAll('.ant-select');
      expect(selects.length).toBeGreaterThan(0);
    });
  });
});
