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

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

import { FullRouteTimeline } from "./FullRouteTimeline.js";

function makeLeg(i: number): IFlightLeg {
  return {
    arrival: {
      scheduled: {
        airport: "",
        airportCode: "AAA",
        city: `City${i}`,
        cityCode: `C${i}`,
        countryCode: "RU",
      },
      terminal: "",
      times: {
        scheduledArrival: {
          dayChange: { value: 0, title: "" },
          local: `a${i}`,
          localTime: `a${i}`,
          tzOffset: 0,
          utc: `2026-04-17T0${i}:00:00Z`,
        },
      },
    },
    departure: {
      scheduled: {
        airport: "",
        airportCode: "BBB",
        city: `Dep${i}`,
        cityCode: `D${i}`,
        countryCode: "RU",
      },
      terminal: "",
      checkingStatus: "",
      times: {
        scheduledDeparture: {
          dayChange: { value: 0, title: "" },
          local: `d${i}`,
          localTime: `d${i}`,
          tzOffset: 0,
          utc: `2026-04-17T0${i}:00:00Z`,
        },
      },
    },
    dayChange: 0,
    equipment: {},
    flags: { checkinAvailable: false, returnToAirport: false, routeChanged: false },
    flyingTime: `${i}h`,
    index: i,
    operatingBy: {},
    status: "Scheduled",
    updated: "",
  } as IFlightLeg;
}

describe("FullRouteTimeline", () => {
  it("returns null when fewer than 2 legs", () => {
    const { container } = render(<FullRouteTimeline legs={[makeLeg(0)]} viewType="Schedule" />);
    expect(container.firstChild).toBeNull();
  });

  it("renders container with data-testid=full-route-timeline when 2+ legs", () => {
    render(<FullRouteTimeline legs={[makeLeg(0), makeLeg(1)]} viewType="Schedule" />);
    expect(screen.getByTestId("full-route-timeline")).toBeTruthy();
  });

  it("renders inner Timeline content (expect d0 visible when 2 legs)", () => {
    render(<FullRouteTimeline legs={[makeLeg(0), makeLeg(1)]} viewType="Schedule" />);
    expect(screen.getByText("d0")).toBeTruthy();
  });
});
