// @vitest-environment jsdom

import { cleanup, render, screen } from "@testing-library/react";
import { afterEach, describe, expect, it } from "vitest";
import { PlayersAdminStats } from "@/components/players-admin-stats";
import type { BallboxStoreAdminPlayer, BallboxStoreClubListItem } from "@/lib/ballbox-store";

const players: BallboxStoreAdminPlayer[] = [
  {
    id: "player_1",
    name: "Player One",
    whatsappPhone: null,
    telegramHandle: null,
    gender: null,
    birthYear: null,
    coachCategory: null,
    memberships: [{ id: "membership_1", clubId: "club_1", clubName: "Club One" }],
  },
  {
    id: "player_2",
    name: "Player Two",
    whatsappPhone: null,
    telegramHandle: null,
    gender: null,
    birthYear: null,
    coachCategory: null,
    memberships: [{ id: "membership_2", clubId: "club_2", clubName: "Club Two" }],
  },
];

const clubs: BallboxStoreClubListItem[] = [
  { id: "club_1", atcSportclubId: "106", name: "Club One", locationName: null, venues: 1, machines: 1, screens: 1 },
  { id: "club_2", atcSportclubId: "107", name: "Club Two", locationName: null, venues: 1, machines: 1, screens: 1 },
  { id: "club_3", atcSportclubId: "108", name: "Club Three", locationName: null, venues: 1, machines: 1, screens: 1 },
];

describe("PlayersAdminStats", () => {
  afterEach(() => {
    cleanup();
  });

  it("renders the derived player and membership totals", () => {
    render(<PlayersAdminStats players={players} clubs={clubs} cardClassName="stat-card" />);

    expect(screen.getByText("Players")).toBeTruthy();
    expect(screen.getByText("Memberships")).toBeTruthy();
    expect(screen.getByText("Clubs linked")).toBeTruthy();
    expect(screen.getByText("Network clubs")).toBeTruthy();
    expect(screen.getAllByText("2")).toHaveLength(3);
    expect(screen.getByText("3")).toBeTruthy();
  });
});
