import { describe, it, expect, vi } from 'vitest';
import { screen, waitFor } from '@testing-library/react';
import { renderWithProviders } from '../../test/utils/renderWithProviders';

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

// Mock the sub-dashboard components to simplify testing
vi.mock('./StatisticsDashboard/DoctorDashboard', () => ({
  DoctorDashboard: () => <div data-testid="doctor-dashboard">医生仪表盘</div>,
}));
vi.mock('./StatisticsDashboard/NurseDashboard', () => ({
  NurseDashboard: () => <div data-testid="nurse-dashboard">护士仪表盘</div>,
}));
vi.mock('./StatisticsDashboard/AdminDashboard', () => ({
  AdminDashboard: () => <div data-testid="admin-dashboard">管理仪表盘</div>,
}));
vi.mock('./StatisticsDashboard/OperatorDashboard', () => ({
  OperatorDashboard: () => <div data-testid="operator-dashboard">运营仪表盘</div>,
}));

import StatisticsDashboard from './StatisticsDashboard';

describe('StatisticsDashboard', () => {
  it('renders a dashboard component based on role', async () => {
    vi.setConfig({ testTimeout: 15000 });
    renderWithProviders(<StatisticsDashboard />);

    await waitFor(() => {
      // Default role is 'admin' when no user roles are set
      const adminDashboard = screen.queryByTestId('admin-dashboard');
      const doctorDashboard = screen.queryByTestId('doctor-dashboard');
      // One of these should render (depends on default role)
      expect(adminDashboard || doctorDashboard).toBeTruthy();
    });
  });

  it('does not render 403 when user has permission', async () => {
    renderWithProviders(<StatisticsDashboard />);
    await waitFor(() => {
      expect(screen.queryByText('权限不足')).not.toBeInTheDocument();
    });
  });
});
