import type {
  FlightStatus,
  IEquipmentFull,
  IFlightTransitionItem,
  MealType,
} from "../../types.js";

export type DetailsViewType = "Onlineboard" | "Schedule";

/**
 * Matches Angular's `showBoardProperty` in flight-details-wrapper.component.ts.
 * Transition panels are hidden for Schedule mode, Cancelled flights,
 * missing data, or when the transition hasn't started.
 */
export function shouldShowTransition(
  item: IFlightTransitionItem | undefined,
  legStatus: FlightStatus,
  viewType: DetailsViewType,
): boolean {
  if (viewType === "Schedule") return false;
  if (legStatus === "Cancelled") return false;
  if (!item) return false;
  if (item.status === "Scheduled") return false;
  return true;
}

/**
 * Matches Angular's `showAircraft` getter. Shows when actual or scheduled
 * title exists, or when configuration string is present.
 */
export function shouldShowAircraft(equipment: Pick<IEquipmentFull, "aircraft">): boolean {
  const aircraft = equipment.aircraft;
  if (!aircraft) return false;
  const title = aircraft.actual?.title || aircraft.scheduled?.title;
  if (title) return true;
  if (aircraft.configuration) return true;
  return false;
}

/**
 * Service ID → icon filename mapping.
 * From Angular flight-details-services.component.ts.
 * IDs 6 and 7 both use the entertaintment icon (typo in original is preserved
 * because that's how Angular ships the filename).
 */
export const SERVICE_ICON_MAP: Record<number, string> = {
  1: "shopping",
  2: "space",
  3: "taxi",
  4: "wifi",
  5: "gsm",
  6: "entertaintment",
  7: "entertaintment",
  8: "seat_reservation",
};

/** Fallback icon for unknown service IDs. */
export const SERVICE_ICON_FALLBACK = "comfort-plus";

/**
 * Meal type → aeroflot.ru info page link.
 * From Angular flight-details-meal.component.ts.
 */
export const MEAL_LINKS: Record<Exclude<MealType, "Special">, string> = {
  Economy: "https://www.aeroflot.ru/ru-ru/information/onboard/dining?0000#meal-type_0",
  Comfort: "https://www.aeroflot.ru/ru-ru/information/onboard/dining?0000#meal-type_1",
  Business: "https://www.aeroflot.ru/ru-ru/information/onboard/dining?0000#meal-type_2",
};
