import { describe, it, expect, vi, beforeEach } from 'vitest';
import { screen, waitFor } from '../../../test/utils/test-utils';
import { renderWithRouter } from '../../../test/utils/test-utils';
import DashboardPage from '../DashboardPage';

// Mock useNavigate
const mockNavigate = vi.fn();
vi.mock('react-router-dom', async () => {
  const actual = await vi.importActual('react-router-dom');
  return {
    ...actual,
    useNavigate: () => mockNavigate,
  };
});

describe('Staff DashboardPage', () => {
  beforeEach(() => {
    vi.clearAllMocks();
  });

  it('should render loading state initially', () => {
    renderWithRouter(<DashboardPage />);
    expect(screen.getByText(/Loading/i)).toBeInTheDocument();
  });

  it('should fetch and display dashboard stats', async () => {
    renderWithRouter(<DashboardPage />);

    await waitFor(() => {
      expect(screen.queryByText(/Loading/i)).not.toBeInTheDocument();
    }, { timeout: 5000 });

    // Check if stats are displayed
    await waitFor(() => {
      expect(screen.getByText(/Total Revenue/i)).toBeInTheDocument();
    });
  });

  it('should display recent bookings', async () => {
    renderWithRouter(<DashboardPage />);

    await waitFor(() => {
      expect(screen.queryByText(/Loading/i)).not.toBeInTheDocument();
    }, { timeout: 5000 });

    // Bookings section should be present (might be in a heading or section)
    await waitFor(() => {
      const bookingsHeading = screen.queryByRole('heading', { name: /Recent Bookings/i });
      const bookingsText = screen.queryAllByText(/Recent Bookings/i);
      // Either heading or any text mentioning recent bookings
      expect(bookingsHeading || bookingsText.length > 0).toBeTruthy();
    }, { timeout: 5000 });
  });
});

