diff --git a/src/features/schedule/components/ScheduleDetailsPage.tsx b/src/features/schedule/components/ScheduleDetailsPage.tsx index 33947be2..df9a6c7a 100644 --- a/src/features/schedule/components/ScheduleDetailsPage.tsx +++ b/src/features/schedule/components/ScheduleDetailsPage.tsx @@ -9,8 +9,10 @@ */ import type { FC } from "react"; +import { useCallback } from "react"; import { Link } from "@modern-js/runtime/router"; import { useTranslation } from "@/i18n/provider.js"; +import { localeToLanguage, normalizeLocaleParam, DEFAULT_LANGUAGE } from "@/i18n/resolver.js"; import { FlightCard } from "@/ui/flights/FlightCard.js"; import { FlightListSkeleton } from "@/ui/flights/FlightListSkeleton.js"; import { SeoHead } from "@/ui/seo/SeoHead.js"; @@ -78,6 +80,31 @@ export const ScheduleDetailsPage: FC = ({ const pageTabs = ; const scheduleHref = `/${locale}/schedule`; + + // `Купить` button — opens Aeroflot's booking flow in a new tab. + // Mirrors BoardDetailsHeader's BuyTicketButton / Schedule search page. + const language = + localeToLanguage(normalizeLocaleParam(locale) ?? "ru-ru") ?? DEFAULT_LANGUAGE; + const handleBuy = useCallback( + (flight: ISimpleFlight) => { + const legs = flight.routeType === "Direct" ? [flight.leg] : flight.legs; + const firstLeg = legs[0]; + const lastLeg = legs[legs.length - 1]; + if (!firstLeg || !lastLeg) return; + const dep = firstLeg.departure.scheduled.airportCode; + const arr = lastLeg.arrival.scheduled.airportCode; + const depUtc = firstLeg.departure.times.scheduledDeparture.utc; + const depDate = new Date(depUtc); + const yyyy = depDate.getFullYear().toString(); + const mm = (depDate.getMonth() + 1).toString().padStart(2, "0"); + const dd = depDate.getDate().toString().padStart(2, "0"); + const url = `https://www.aeroflot.ru/sb/app/${language}-${language}#/search?adults=1&cabin=economy&children=0&infants=0&routes=${dep}.${yyyy}${mm}${dd}.${arr}&autosearch=Y`; + if (typeof window !== "undefined") { + window.open(url, "_blank", "noopener,noreferrer"); + } + }, + [language], + ); const backLink = ( = ({ // body for each, separated by a transit caption — close to Angular's // `schedule-flight-details-view` for the connecting case. const renderBody = (flight: typeof flights[number]) => ( - + handleBuy(flight as unknown as ISimpleFlight)} + /> ); return (