/* 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', () => ({
  Search: () => <span data-testid="icon-search" />,
  RefreshCw: () => <span data-testid="icon-refresh" />,
  ChevronLeft: () => <span data-testid="icon-left" />,
  ChevronRight: () => <span data-testid="icon-right" />,
  UserX: () => <span data-testid="icon-userx" />,
  UserCheck: () => <span data-testid="icon-usercheck" />,
  Eye: () => <span data-testid="icon-eye" />,
  X: () => <span data-testid="icon-x" />,
}));

vi.mock('@/lib/admin-api', () => ({
  adminApi: {
    getUsers: vi.fn().mockResolvedValue({
      data: [
        {
          id: 'u1',
          fullName: 'Nguyen Van A',
          phone: '0912345678',
          email: 'a@test.com',
          role: 'BUYER',
          kycStatus: 'NONE',
          isActive: true,
          createdAt: '2024-01-01T00:00:00.000Z',
        },
        {
          id: 'u2',
          fullName: 'Tran Thi B',
          phone: '0987654321',
          email: null,
          role: 'AGENT',
          kycStatus: 'VERIFIED',
          isActive: true,
          createdAt: '2024-02-01T00:00:00.000Z',
        },
      ],
      total: 2,
      page: 1,
      totalPages: 1,
    }),
    getUserDetail: vi.fn(),
    banUser: vi.fn(),
  },
}));

import AdminUsersPage from '../users/page';

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

  it('renders user management heading', async () => {
    render(<AdminUsersPage />);

    await waitFor(() => {
      expect(screen.getByText('Quản lý người dùng')).toBeInTheDocument();
    });
  });

  it('renders user list', async () => {
    render(<AdminUsersPage />);

    await waitFor(() => {
      expect(screen.getByText('Nguyen Van A')).toBeInTheDocument();
      expect(screen.getByText('Tran Thi B')).toBeInTheDocument();
    });
  });

  it('renders search input', async () => {
    render(<AdminUsersPage />);

    await waitFor(() => {
      expect(screen.getByPlaceholderText(/tìm theo tên/i)).toBeInTheDocument();
    });
  });

  it('renders role filter', async () => {
    render(<AdminUsersPage />);

    await waitFor(() => {
      expect(screen.getByText('Tất cả vai trò')).toBeInTheDocument();
    });
  });

  it('renders empty detail panel placeholder', async () => {
    render(<AdminUsersPage />);

    await waitFor(() => {
      expect(screen.getByText(/chọn người dùng để xem chi tiết/i)).toBeInTheDocument();
    });
  });
});
