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

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

describe("MealPanel", () => {
  it("renders an icon for Economy meal", () => {
    const meals: IMealItem[] = [{ type: "Economy" }];
    render(<MealPanel meals={meals} />);
    expect(screen.getByTestId("meal-icon-Economy")).toBeTruthy();
  });

  it("renders icons for multiple meal types", () => {
    const meals: IMealItem[] = [
      { type: "Economy" }, { type: "Comfort" }, { type: "Business" },
    ];
    render(<MealPanel meals={meals} />);
    expect(screen.getByTestId("meal-icon-Economy")).toBeTruthy();
    expect(screen.getByTestId("meal-icon-Comfort")).toBeTruthy();
    expect(screen.getByTestId("meal-icon-Business")).toBeTruthy();
  });

  it("skips Special type (no link defined)", () => {
    const meals: IMealItem[] = [{ type: "Special" }, { type: "Economy" }];
    render(<MealPanel meals={meals} />);
    expect(screen.queryByTestId("meal-icon-Special")).toBeNull();
    expect(screen.getByTestId("meal-icon-Economy")).toBeTruthy();
  });

  it("meal icon is wrapped in a link to aeroflot.ru", () => {
    const meals: IMealItem[] = [{ type: "Economy" }];
    render(<MealPanel meals={meals} />);
    const link = screen.getByTestId("meal-icon-Economy").closest("a");
    expect(link?.getAttribute("href")).toContain("aeroflot.ru");
    expect(link?.getAttribute("href")).toContain("meal-type_0");
  });

  it("has panel data-testid", () => {
    const meals: IMealItem[] = [{ type: "Economy" }];
    render(<MealPanel meals={meals} />);
    expect(screen.getByTestId("meal-panel")).toBeTruthy();
  });
});
