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

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

// Mock Zustand store
vi.mock('../../stores/health', () => ({
  useHealthStore: () => ({
    batchResolvePatientNames: vi.fn(),
    getPatientName: (id: string) => `患者-${id}`,
  }),
}));

const mockOrders = createFixtureList(createPointsOrderFixture, 8, [
  { id: 'order-00000001-abcd', product_name: '体检套餐兑换券', status: 'pending', points_cost: 100 },
  { id: 'order-00000002-abcd', product_name: '健康手环', status: 'verified', points_cost: 200 },
]);

createListPageTests({
  Component: PointsOrderList,
  apiPath: '/api/v1/health/points/orders',
  columns: ['订单号', '商品', '积分', '状态'],
  firstRowTexts: ['体检套餐兑换券'],
  totalItems: 8,
  hasCreateButton: true,
  createButtonText: '核销订单',
  hasSearch: true,
  hasPagination: true,
  mockItems: mockOrders as Record<string, unknown>[],
});

describe('PointsOrderList extra tests', () => {
  it('renders the page title', async () => {
    vi.setConfig({ testTimeout: 15000 });
    renderWithProviders(<PointsOrderList />);
    await waitFor(() => {
      expect(screen.getByText('积分订单')).toBeInTheDocument();
    });
  });
});
