import { render, screen } from "@testing-library/react";
import { afterEach, expect, test, vi } from "vitest";
import { RegistrationRewardPage } from "./RegistrationRewardPage.jsx";
import { useRegistrationRewardPage } from "@/features/registration-reward/hooks/useRegistrationRewardPage.js";

vi.mock("@/features/registration-reward/hooks/useRegistrationRewardPage.js", () => ({
    useRegistrationRewardPage: vi.fn(),
}));

afterEach(() => {
    vi.clearAllMocks();
});

test("registration reward list shows receive filter today count and compact row fields", () => {
    vi.mocked(useRegistrationRewardPage).mockReturnValue(pageFixture());

    render(<RegistrationRewardPage />);

    expect(screen.getByText("今日已领")).toBeInTheDocument();
    expect(screen.getByText("7 份")).toBeInTheDocument();
    expect(
        screen.getAllByRole("button", { name: /领取时间/ }).some((node) => node.textContent.includes("领取时间")),
    ).toBe(true);
    expect(screen.getByText("jayCiE")).toBeInTheDocument();
    expect(screen.getByText("165121")).toBeInTheDocument();
    expect(screen.getAllByText("1,000 金币").length).toBeGreaterThanOrEqual(1);
    expect(screen.queryByText(/^注册奖励$/)).not.toBeInTheDocument();
    expect(screen.getByText("rclaim_1780684209628_899e9717839e0109")).toBeInTheDocument();
    expect(screen.queryByText(/^2026-06-05$/)).not.toBeInTheDocument();
});

function pageFixture() {
    return {
        abilities: { canUpdate: true, canView: true },
        changeQuery: vi.fn(),
        changeStatus: vi.fn(),
        changeTimeRange: vi.fn(),
        claims: {
            items: [
                {
                    claimId: "rclaim_1780684209628_899e9717839e0109",
                    claimedAtMs: 1780684209000,
                    coinAmount: 1000,
                    createdAtMs: 1780684209000,
                    rewardDay: "2026-06-05",
                    rewardType: "coin",
                    status: "granted",
                    user: {
                        avatar: "",
                        displayUserId: "165121",
                        username: "jayCiE",
                    },
                    userId: 3201,
                },
            ],
            page: 1,
            pageSize: 50,
            todayClaimedCount: 7,
            total: 1,
        },
        claimsError: null,
        claimsLoading: false,
        closeConfigDrawer: vi.fn(),
        config: {
            coinAmount: 1000,
            dailyLimit: 500,
            enabled: true,
            rewardType: "coin",
        },
        configDrawerOpen: false,
        configLoading: false,
        configSaving: false,
        form: {},
        openConfigDrawer: vi.fn(),
        page: 1,
        query: "",
        reloadClaims: vi.fn(),
        reloadConfig: vi.fn(),
        resetFilters: vi.fn(),
        resourceGroups: [],
        setForm: vi.fn(),
        setPage: vi.fn(),
        status: "",
        submitConfig: vi.fn(),
        timeRange: { endMs: "", startMs: "" },
    };
}
