/* eslint-disable import-x/order */
import { render, screen, waitFor } from '@testing-library/react';
import { beforeEach, describe, expect, it, vi } from 'vitest';

vi.mock('lucide-react', () => ({
  Users: () => <span data-testid="icon-users" />,
  Home: () => <span data-testid="icon-home" />,
  ClipboardCheck: () => <span data-testid="icon-clipboard" />,
  Clock: () => <span data-testid="icon-clock" />,
  UserCheck: () => <span data-testid="icon-usercheck" />,
  ShieldCheck: () => <span data-testid="icon-shieldcheck" />,
  ArrowUpRight: () => <span data-testid="icon-arrowup" />,
  ArrowDownRight: () => <span data-testid="icon-arrowdown" />,
  TrendingUp: () => <span data-testid="icon-trending" />,
  RefreshCw: () => <span data-testid="icon-refresh" />,
}));

vi.mock('@/lib/admin-api', () => ({
  adminApi: {
    getDashboardStats: vi.fn().mockResolvedValue({
      totalUsers: 5000,
      totalListings: 1200,
      activeListings: 800,
      pendingModerationCount: 15,
      totalAgents: 300,
      verifiedAgents: 150,
      totalTransactions: 4500,
      newUsersLast30Days: 200,
      newListingsLast30Days: 50,
    }),
    getRevenueStats: vi.fn().mockResolvedValue([
      { period: '2025-11', totalRevenue: 50000000, subscriptionRevenue: 30000000, listingFeeRevenue: 20000000, transactionCount: 100 },
      { period: '2025-12', totalRevenue: 65000000, subscriptionRevenue: 40000000, listingFeeRevenue: 25000000, transactionCount: 130 },
    ]),
  },
}));

import AdminDashboardPage from '../page';

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

  it('renders admin dashboard heading', async () => {
    render(<AdminDashboardPage />);

    await waitFor(() => {
      expect(screen.getByText('Dashboard')).toBeInTheDocument();
    });
  });

  it('renders stat cards with data', async () => {
    render(<AdminDashboardPage />);

    await waitFor(() => {
      expect(screen.getByText('Tổng người dùng')).toBeInTheDocument();
      expect(screen.getByText('Tổng tin đăng')).toBeInTheDocument();
      expect(screen.getByText('Tin đang hoạt động')).toBeInTheDocument();
      expect(screen.getByText('Chờ kiểm duyệt')).toBeInTheDocument();
    });
  });

  it('renders revenue chart section', async () => {
    render(<AdminDashboardPage />);

    await waitFor(() => {
      expect(screen.getByText('Doanh thu 6 tháng gần nhất')).toBeInTheDocument();
    });
  });

  it('renders refresh button', async () => {
    render(<AdminDashboardPage />);

    await waitFor(() => {
      expect(screen.getByRole('button', { name: /làm mới/i })).toBeInTheDocument();
    });
  });
});
