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

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

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

describe("BoardingPanel", () => {
  it("renders start and end times", () => {
    render(<BoardingPanel item={baseItem} />);
    expect(screen.getByText("11:00")).toBeTruthy();
    expect(screen.getByText("11:30")).toBeTruthy();
  });

  it("renders status label", () => {
    render(<BoardingPanel item={baseItem} />);
    expect(screen.getByText("DETAILS.STATUS_FINISHED")).toBeTruthy();
  });

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

  // §4.1.15.4: departure gate + transfer type in boarding panel (Angular parity)
  it("4.1.15.4-Boarding-Gate: renders gate row when departure.gate is present", () => {
    render(<BoardingPanel item={baseItem} departure={{ gate: "D5" }} />);
    expect(screen.getByTestId("boarding-gate")).toBeTruthy();
    expect(screen.getByText("D5")).toBeTruthy();
    expect(screen.getByText("SHARED.NUMBER-EXIT")).toBeTruthy();
  });

  it("4.1.15.4-Boarding-Dispatch: renders dispatch type row when departure.dispatch is present", () => {
    render(<BoardingPanel item={baseItem} departure={{ dispatch: "Bus" }} />);
    expect(screen.getByTestId("boarding-dispatch")).toBeTruthy();
    // t mock returns key — dispatch key is "DISPATCH.Bus"
    expect(screen.getByText("DISPATCH.Bus")).toBeTruthy();
    expect(screen.getByText("SHARED.LANDING-TRANSFER")).toBeTruthy();
  });

  it("4.1.15.4-Boarding-NoGate: omits gate row when departure.gate is absent", () => {
    render(<BoardingPanel item={baseItem} departure={{}} />);
    expect(screen.queryByTestId("boarding-gate")).toBeNull();
  });

  it("4.1.15.4-Boarding-NoDeparture: omits gate/dispatch rows when departure prop is not passed", () => {
    render(<BoardingPanel item={baseItem} />);
    expect(screen.queryByTestId("boarding-gate")).toBeNull();
    expect(screen.queryByTestId("boarding-dispatch")).toBeNull();
  });
});
