/* eslint-disable jsx-a11y/no-static-element-interactions */ /* eslint-disable jsx-a11y/click-events-have-key-events */ /* eslint-disable no-console */ /* eslint-disable @next/next/no-img-element */ import dayjs from "dayjs"; import { useState } from "react"; import { useMediaQuery } from "usehooks-ts"; import { Button } from "@/components/ui/button/button"; import Card from "@/components/ui/card/card"; import LIcon from "@/components/ui/lucid-icon/lucid-icon"; import { Modal } from "@/components/ui/modal/modal"; import { Undefined } from "@/components/widget/booking-request-card-detail/booking-request-card-detail"; import { DateHelper, getFormatedFlightTime, } from "@/libs/helpers/date-time-helper"; import { getAirportCode, getCityName, getWaitingTime, } from "@/libs/helpers/flight-helper"; import type { IPlaneReservationData } from "@/services/eva-display/demand/flight-reservation-data/flight-reservation-data"; import FlightInformationModal from "../../flight-information-modal/flight-information-modal"; interface PlaneOneWayCardProps { reservationData: IPlaneReservationData; totalPrice?: string | number; } const FlightMultipleWayCard = ({ totalPrice, reservationData, }: PlaneOneWayCardProps) => { const isDesktop = useMediaQuery("(min-width: 768px)"); const [detailModals, setDetailModals] = useState([]); if (!reservationData?.DetailResponse?.PricingCombinations) return null; const pricingCombinations = reservationData.DetailResponse.PricingCombinations .length ? reservationData.DetailResponse.PricingCombinations : [reservationData.DetailResponse.PricingCombinations[0]]; if (pricingCombinations.length === 0) { console.log("pricingCombinations", pricingCombinations); return null; } const combinationGroups = pricingCombinations?.flatMap((item) => item?.CombinationGroups?.sort((a, b) => a.GroupId - b.GroupId), ); const tripLength = combinationGroups && combinationGroups.length; return (
{combinationGroups && combinationGroups.map((combination) => { if ( !combination?.FlightSegments || combination?.FlightSegments?.length === 0 ) { return null; } const flightSegments = combination.FlightSegments.sort( (a, b) => dayjs(a.DepartureTime).valueOf() - dayjs(b.DepartureTime).valueOf(), ); if ( !flightSegments || !Array.isArray(flightSegments) || flightSegments.length === 0 || !flightSegments[0] ) return null; const departureSegment = flightSegments[0]; const arrivalSegment = flightSegments[flightSegments.length - 1]!; const direct = combination.GroupId === 0 ? "Gidiş" : "Dönüş"; return (
{totalPrice && (
{`${getCityName( departureSegment?.Origin || "", )} - ${getCityName(departureSegment?.Destination || "")}`} {DateHelper.dayjs(departureSegment.DepartureTime).format( "DD MMMM YYYY dddd", )}
{isDesktop && ( )}
)}
{tripLength === 2 && (

{direct}

)}
{departureSegment?.OperatingAirlineCode

{departureSegment?.MarketingAirline || Undefined()}

{departureSegment?.FlightNumber || Undefined()}

{getFormatedFlightTime(combination?.TravelTime || "") || Undefined()}

{DateHelper.dateToTime( departureSegment.DepartureTime, )}

{getAirportCode(departureSegment?.Origin || "")! || Undefined()}

{DateHelper.dateToTime(arrivalSegment.ArrivalTime)}

{getAirportCode(arrivalSegment?.Destination || "")! || Undefined()}

{`${ combination.FlightSegments.length >= 2 ? `${ combination.FlightSegments.length - 1 } Aktarmalı ( ${[ ...new Set( flightSegments .filter((_, i) => i !== 0) .map((x) => getAirportCode(x.Origin)), ), ].join(", ")} )` : "Aktarmasız" }`} {`, ${ combination.CabinClassTitle?.toLowerCase() ?? "" }`}

{totalPrice && (
{!isDesktop && ( )} {tripLength === 1 && (

Toplam Tutar

{totalPrice}

)}
)}
{ setDetailModals((prev) => prev.filter((x) => x !== combination.Key), ); }} title="Detaylı Bilgi" footer >
{flightSegments.map((flightSegmentItem, key) => ( ))}
Varış Tarihi {DateHelper.dayjs( flightSegments[flightSegments.length - 1] ?.ArrivalTime as unknown as Date, ).format("DD MMMM YYYY ddd HH:mm")}
Seyahat Süresi {getFormatedFlightTime(combination.TravelTime)}
); })}
); }; export default FlightMultipleWayCard;