import { fireEvent, render, screen } from "@testing-library/react";
import { MemoryRouter } from "react-router-dom";
import { describe, expect, it, vi } from "vitest";
import { AdminPanel } from "./AdminPanel";

vi.mock("./AdminUsersTable", () => ({
  AdminUsersTable: () => <h2>Users</h2>
}));

vi.mock("./AdminContentPanel", () => ({
  AdminContentPanel: () => <h2>Content pages</h2>
}));

vi.mock("./AdminSecurityPanel", () => ({
  AdminSecurityPanel: () => <h2>Security panel</h2>
}));

vi.mock("./AdminDiagnosticsPanel", () => ({
  AdminDiagnosticsPanel: () => <h2>Diagnostics panel</h2>
}));

vi.mock("./AdminActivityPanel", () => ({
  AdminActivityPanel: () => <h2>Activity panel</h2>
}));

vi.mock("../api/adminApi", () => ({
  postAdminUiActivity: vi.fn()
}));

vi.mock("@modules/auth", () => ({
  useIsSuperuser: () => true,
  useAuth: () => ({ logout: vi.fn() })
}));

describe("AdminPanel", () => {
  it("switches between admin tabs", () => {
    render(
      <MemoryRouter>
        <AdminPanel />
      </MemoryRouter>
    );
    expect(screen.getByRole("heading", { name: "Users" })).toBeInTheDocument();
    fireEvent.click(screen.getByRole("menuitem", { name: /Content$/ }));
    expect(screen.getByRole("heading", { name: "Content pages" })).toBeInTheDocument();
  });
});
