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

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

describe("FlightEvents", () => {
  it("renders null when both flags are false", () => {
    const { container } = render(<FlightEvents changeRoute={false} reroute={false} />);
    expect(container.firstChild).toBeNull();
  });

  it("renders change-route event when changeRoute=true with description", () => {
    render(<FlightEvents changeRoute reroute={false} showDescription />);
    expect(screen.getByTestId("flight-event-change-route")).toBeTruthy();
    expect(screen.getByText("SHARED.ROUTE-CHANGE")).toBeTruthy();
  });

  it("renders reroute event when reroute=true", () => {
    render(<FlightEvents changeRoute={false} reroute showDescription />);
    expect(screen.getByTestId("flight-event-reroute")).toBeTruthy();
    expect(screen.getByText("SHARED.RETURN")).toBeTruthy();
  });

  it("renders both events when both flags true", () => {
    render(<FlightEvents changeRoute reroute showDescription />);
    expect(screen.getByTestId("flight-event-change-route")).toBeTruthy();
    expect(screen.getByTestId("flight-event-reroute")).toBeTruthy();
  });

  it("hides descriptions when showDescription=false", () => {
    render(<FlightEvents changeRoute reroute />);
    expect(screen.getByTestId("flight-event-change-route")).toBeTruthy();
    expect(screen.getByTestId("flight-event-reroute")).toBeTruthy();
    expect(screen.queryByText("SHARED.ROUTE-CHANGE")).toBeNull();
    expect(screen.queryByText("SHARED.RETURN")).toBeNull();
  });
});
