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

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

const baseItem: IFlightTransitionItem = {
  start: {
    dayChange: { value: 0, title: "" },
    local: "13:00",
    localTime: "13:00",
    tzOffset: 3,
    utc: "10:00",
  },
  end: {
    dayChange: { value: 0, title: "" },
    local: "13:30",
    localTime: "13:30",
    tzOffset: 3,
    utc: "10:30",
  },
  status: "InProgress",
  isActual: true,
};

const arrival: IFlightLegArrivalStation = {
  scheduled: { airport: "SVO", airportCode: "SVO", city: "Moscow", cityCode: "MOW", countryCode: "RU" },
  latest: { airport: "SVO", airportCode: "SVO", city: "Moscow", cityCode: "MOW", countryCode: "RU" },
  dispatch: "Terminal D",
  gate: "B23",
  terminal: "D",
  bagBelt: "5",
  times: {
    scheduledArrival: { dayChange: { value: 0, title: "" }, local: "", localTime: "", tzOffset: 0, utc: "" },
  },
};

describe("DeboardingPanel", () => {
  it("renders transition times and status", () => {
    render(<DeboardingPanel item={baseItem} arrival={arrival} />);
    expect(screen.getByText("13:00")).toBeTruthy();
    expect(screen.getByText("DETAILS.STATUS_IN_PROGRESS")).toBeTruthy();
  });

  it("renders terminal, gate, baggage belt from arrival", () => {
    render(<DeboardingPanel item={baseItem} arrival={arrival} />);
    expect(screen.getByText("D")).toBeTruthy();
    expect(screen.getByText("5")).toBeTruthy();
  });

  it("omits terminal row when arrival has no terminal", () => {
    const { terminal, ...noTerminal } = arrival;
    void terminal;
    render(<DeboardingPanel item={baseItem} arrival={noTerminal} />);
    expect(screen.queryByText("DETAILS.TERMINAL")).toBeNull();
  });

  it("omits bag belt row when arrival has no bagBelt", () => {
    const { bagBelt, ...noBelt } = arrival;
    void bagBelt;
    render(<DeboardingPanel item={baseItem} arrival={noBelt} />);
    expect(screen.queryByText("DETAILS.BAG_BELT")).toBeNull();
  });

  it("has data-testid", () => {
    render(<DeboardingPanel item={baseItem} arrival={arrival} />);
    expect(screen.getByTestId("deboarding-panel")).toBeTruthy();
  });
});
