import { afterEach, describe, expect, it, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import { BrowserRouter } from "react-router";
import { DraftInfoCard, type DraftInfoCardProps } from "../DraftInfoCard";

function renderWithRouter(ui: React.ReactElement) {
  return render(<BrowserRouter>{ui}</BrowserRouter>);
}

const baseProps: DraftInfoCardProps = {
  draftRounds: 8,
  draftTimerMode: "chess_clock",
  draftInitialTime: 28800,
  draftIncrementTime: 1800,
  sportsCount: 6,
  isDraftOrderSet: true,
  isDraftOrPreDraft: true,
  draftDateTime: new Date("2026-05-21T04:00:00.000Z"),
  draftTimezone: "America/Los_Angeles",
  draftBoardHref: "/leagues/1/draft-board/1",
  draftRoomHref: "/leagues/1/draft/1",
};

describe("DraftInfoCard", () => {
  afterEach(() => {
    vi.useRealTimers();
  });

  it("shows the full draft date and relative timing before the draft", () => {
    vi.useFakeTimers();
    vi.setSystemTime(new Date("2026-05-18T04:00:00.000Z"));

    renderWithRouter(<DraftInfoCard {...baseProps} />);

    expect(screen.getByText("Draft Date & Time")).toBeInTheDocument();
    expect(screen.getByText("May 20, 2026 9:00PM PT")).toBeInTheDocument();
    expect(screen.getByText("In 3 days")).toBeInTheDocument();
  });

  it("describes chess clock bank and increment in human terms", () => {
    renderWithRouter(<DraftInfoCard {...baseProps} />);

    expect(screen.getByText("8 hour time bank")).toBeInTheDocument();
    expect(screen.getByText("+30 minute increment")).toBeInTheDocument();
  });

  it("describes standard timers in human terms", () => {
    renderWithRouter(
      <DraftInfoCard
        {...baseProps}
        draftTimerMode="standard"
        draftInitialTime={30}
        draftIncrementTime={30}
      />
    );

    expect(screen.getByText("30 seconds")).toBeInTheDocument();
    expect(screen.getByText("per pick")).toBeInTheDocument();
  });

  it("formats the draft date in the provided timezone", () => {
    renderWithRouter(
      <DraftInfoCard
        {...baseProps}
        draftTimezone="America/New_York"
      />
    );

    expect(screen.getByText("May 21, 2026 12:00AM ET")).toBeInTheDocument();
  });
});
