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

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

describe("AircraftPanel", () => {
  it("renders actual title when present", () => {
    const eq: IEquipmentFull = { aircraft: { actual: { title: "Airbus A321" } } };
    render(<AircraftPanel equipment={eq} />);
    expect(screen.getByText("Airbus A321")).toBeTruthy();
  });

  it("falls back to scheduled when actual.title is empty", () => {
    const eq: IEquipmentFull = {
      aircraft: { actual: { title: "" }, scheduled: { title: "Boeing 737" } },
    };
    render(<AircraftPanel equipment={eq} />);
    expect(screen.getByText("Boeing 737")).toBeTruthy();
  });

  it("renders both actual and scheduled when they differ", () => {
    const eq: IEquipmentFull = {
      aircraft: {
        actual: { title: "Airbus A321" },
        scheduled: { title: "Airbus A320" },
      },
    };
    render(<AircraftPanel equipment={eq} />);
    expect(screen.getByText("Airbus A321")).toBeTruthy();
    expect(screen.getByText("Airbus A320")).toBeTruthy();
  });

  it("renders configuration when present", () => {
    const eq: IEquipmentFull = {
      aircraft: { actual: { title: "A320" }, configuration: "C12Y138" },
    };
    render(<AircraftPanel equipment={eq} />);
    expect(screen.getByText("C12Y138")).toBeTruthy();
  });

  it("has data-testid", () => {
    const eq: IEquipmentFull = { aircraft: { actual: { title: "A320" } } };
    render(<AircraftPanel equipment={eq} />);
    expect(screen.getByTestId("aircraft-panel")).toBeTruthy();
  });
});
