// @vitest-environment jsdom
import { describe, it, expect, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import { RegistrationPanel } from "./RegistrationPanel.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: "10:00",
    localTime: "10:00",
    tzOffset: 3,
    utc: "07:00",
  },
  end: {
    dayChange: { value: 0, title: "" },
    local: "10:30",
    localTime: "10:30",
    tzOffset: 3,
    utc: "07:30",
  },
  status: "InProgress",
  isActual: true,
};

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

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

  it("renders only start time when end is missing", () => {
    const noEnd: IFlightTransitionItem = {
      ...baseItem,
      end: {
        dayChange: { value: 0, title: "" },
        local: "",
        localTime: "",
        tzOffset: 0,
        utc: "",
      },
    };
    render(<RegistrationPanel item={noEnd} />);
    expect(screen.getByText("10:00")).toBeTruthy();
    expect(screen.queryByText("10:30")).toBeNull();
  });

  it("has data-testid for targeting in integration tests", () => {
    render(<RegistrationPanel item={baseItem} />);
    expect(screen.getByTestId("registration-panel")).toBeTruthy();
  });
});
