/**
 * @vitest-environment jsdom
 */
import { describe, it, expect, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import { IFlyWarning } from "./IFlyWarning.js";

vi.mock("@/i18n/provider.js", () => ({
  useTranslation: () => ({
    t: (key: string) => key,
    i18n: { language: "ru" },
  }),
}));

describe("IFlyWarning", () => {
  it("renders warning for flights in the iFly range (5801-5948)", () => {
    const { container } = render(<IFlyWarning flightNumber="5825" />);
    expect(container.querySelector(".ifly-warning")).toBeTruthy();
    expect(screen.getByText("WARNING.IFLY_HIGHLIGHT")).toBeTruthy();
  });

  it("accepts numeric flight numbers", () => {
    const { container } = render(<IFlyWarning flightNumber={5900} />);
    expect(container.querySelector(".ifly-warning")).toBeTruthy();
  });

  it("does not render for flights below the iFly range", () => {
    const { container } = render(<IFlyWarning flightNumber="5800" />);
    expect(container.querySelector(".ifly-warning")).toBeNull();
  });

  it("does not render for flights above the iFly range", () => {
    const { container } = render(<IFlyWarning flightNumber="5949" />);
    expect(container.querySelector(".ifly-warning")).toBeNull();
  });

  it("does not render for regular flights (SU100)", () => {
    const { container } = render(<IFlyWarning flightNumber="100" />);
    expect(container.querySelector(".ifly-warning")).toBeNull();
  });

  it("does not render for non-numeric input", () => {
    const { container } = render(<IFlyWarning flightNumber="abc" />);
    expect(container.querySelector(".ifly-warning")).toBeNull();
  });
});
