/* eslint-disable no-nested-ternary */ "use client"; import { useRouter } from "next/navigation"; import { useCallback } from "react"; import { useBoolean, useMediaQuery } from "usehooks-ts"; import { Button } from "@/components/ui/button/button"; import Card from "@/components/ui/card/card"; import { Dialog } from "@/components/ui/dialog/dialog"; import LIcon from "@/components/ui/lucid-icon/lucid-icon"; import { Modal } from "@/components/ui/modal/modal"; import { useModal } from "@/components/ui/modal/modal.hook"; import { RezervationSummaryDivider, RezervationSummaryProvider, RezervationSummaryRoomInfo, RezervationSummaryRoomProperty, RezervationSummaryTitle, RezervationSummaryTotalPrice, RezervationSummaryTotalPriceMobile, } from "@/components/widget/rezervation-summary/rezervation-summary"; import { useHotelSummary } from "@/features/modules/hotel/summary/hooks/use-hotel-summary"; import { useHotelTravelPlanner } from "@/features/modules/hotel/travel-planner/hooks/use-hotel-travel-planner"; import AllInstallmentsModalContent from "@/features/payment/credit-card-infos/components/all-installments-modal-content"; import { useApp } from "@/hooks/useApp"; import { useLabels } from "@/hooks/useLabels"; import { useLocale } from "@/hooks/useLocale"; import { DateHelper } from "@/libs/helpers/date-time-helper"; import { localeStorageHelper } from "@/libs/helpers/locale-storage-helper"; import { PriceManager } from "@/libs/price-manager/price-manager"; import { storageManager } from "@/libs/storage-manager"; import { ILoaderKeys } from "@/models/loader.model"; import type { RoomCollectionResult, RoomGroupResult, } from "@/services/eva-display/hotel/hotel-detail/hotel-detail-services.types"; import type { IHotelSearchResultSerializer } from "@/services/eva-display/hotel/hotel-search/hotel-search-services.serializer"; import { useLoaderStore } from "@/store/loader-store/use-loader-store"; import { useRoomCtx } from "../../context/RoomContext"; import useRoomSelect from "../../hooks/use-room-select"; import ReservationSummaryCampaigns from "./reservation-summary-campaigns"; interface IRezervationSummaryProps { isLoading?: boolean; data?: RoomCollectionResult[]; searchData?: IHotelSearchResultSerializer; primaryButtonOnClick?(selectedRoom: any): void; } const RezervationSummary = (props: IRezervationSummaryProps) => { const { state } = useRoomSelect(); const { setDetailData, setSearchData } = useHotelSummary(); const navigate = useRouter(); const isDesktop = useMediaQuery("(min-width: 768px)"); const labels = useLabels(); const { isB2E, isOtel, isB2C } = useApp(); const { data: tpdata } = useHotelTravelPlanner(); const { t } = useLocale(); const roomGroupResultCtx = useRoomCtx(); const { closeModal, openModal, modalOpen } = useModal({ open: false }); const { openLoader } = useLoaderStore(); const allInstallmentsBoolean = useBoolean(); const tpData = storageManager.get("core-travel-planner")?.payload; const hasTpDates = !!tpData?.dates?.checkIn && !!tpData?.dates?.checkOut; function getTotalPrice() { let value: number = 0; let currency: string = ""; if (state?.selectedRooms[0]?.rooms) { state.selectedRooms.forEach((data) => { if (data.rooms && data.rooms[0]?.basePrice) { // eslint-disable-next-line radix value += parseFloat(data.rooms[0]?.totalPrice.slice(3)); currency = data.rooms[0]?.totalPrice.slice(0, 3); } }); } return { currency, value, }; } const totalPrice = getTotalPrice(); const findResult = () => { const roomKeys: string[] = []; const rooms: any[] = []; let result: undefined | RoomGroupResult; state.selectedRooms.forEach((item) => { if (item.rooms?.length > 0 && item.rooms[0]?.key) { rooms.push({ room: item.rooms[0], roomCollection: item, }); roomKeys.push(item.rooms[0].key); } }); if (roomKeys.length > 0 && state.roomGroupResult) { result = state.roomGroupResult.find( (item) => JSON.stringify(item.roomKeys) === JSON.stringify(roomKeys), ); } return { roomKeys, rooms, result, productKey: result?.key, }; }; function getProductKey(navigateSummary: boolean = true) { const { roomKeys, rooms, result } = findResult(); if (roomKeys.length > 0 && state.roomGroupResult) { if (result?.key) { localStorage.setItem( "cart", JSON.stringify({ productKey: result.key, searchId: state.searchId }), ); if (props.primaryButtonOnClick) { props.primaryButtonOnClick({ roomData: props.data, ...state, productKey: result.key, }); } else { openLoader({ key: ILoaderKeys.HotelDetailLoaderKey, open: true }); setDetailData({ roomGroupKey: result.key, rooms, }); if (isOtel) { setSearchData({ searchId: state!.searchId!.toString(), searchItemKey: "", passengersKeys: state!.passengerKeys!, isAbroad: false, }); } return navigateSummary ? navigate.push("/hotel/summary") : result.key; } } return false; } return false; } function getPassengerInformation(index: number) { const localStorageValue = localeStorageHelper.get("travel-planner"); const storagedValue = localStorageValue?.room; const roomsInfo = (tpdata?.payload?.rooms ?? storagedValue) as any; const employeCount = roomsInfo[index].employee?.count ?? 0; const guestCount = roomsInfo[index].guest?.count ?? 0; const childCount = roomsInfo[index].child?.count ?? 0; let passengerInfo = ""; if (employeCount > 0) { passengerInfo += `${employeCount} Kurum çalışanı`; } if (guestCount > 0) { passengerInfo += ` ${guestCount} ${labels.guest.label}`; } if (childCount > 0) { passengerInfo += ` ${childCount} Çocuk`; } return passengerInfo; } const handleOpenModal = useCallback(() => { openModal(); }, [openModal]); const renderModalContent = () => { return (
{state.selectedRooms.map((room, index) => { if (Object.keys(room).length === 0) { return false; } return (
{(props.searchData?.hotelList?.[0]?.name || props.searchData?.hotelList?.[0]?.location) && (
{props.searchData?.hotelList?.[0]?.name && (

{props.searchData?.hotelList?.[0]?.name}

)} {props.searchData?.hotelList?.[0]?.location && (

{props.searchData?.hotelList?.[0]?.location}

)}
)} {index === 0 && ( <>

{t("Check-in")}:

{DateHelper.formatDateToString( roomGroupResultCtx[0].roomGroupResult?.[0] ?.checkInDate as unknown as Date, )}

{t("Check-out")}:

{DateHelper.formatDateToString( roomGroupResultCtx[0].roomGroupResult?.[0] ?.checkOutDate as unknown as Date, )}

)}

{room.title}

{room?.rooms[0]?.mealType?.description && (
{room?.rooms[0]?.mealType.description}
)} {PriceManager({ currency: (room.rooms?.[0]?.totalPrice || "TRY").slice( 0, 3, ), value: +(room.rooms?.[0]?.totalPrice || "").slice(3), })}
{getPassengerInformation(index)}
{room?.rooms[0]?.nightlyRateDescription}
); })}
{`${t("Total")} ${t("Amount")}`} {PriceManager({ currency: totalPrice.currency.slice(0, 3), value: totalPrice.value, })}
); }; const handleClickSelectDate = () => { const dateElement = document.getElementById( "tp-date-range-picker-trigger-button", ); if (dateElement) { dateElement.click(); } }; if (!isDesktop) { return (
1} className="fixed inset-x-0 bottom-0 z-[100] w-full bg-white" >
{state.selectedRooms[0]?.rooms ? (
) : (
{hasTpDates ? t("Select the room you want to make a reservation.") : t("Select a date to see hotel availability and prices")} {!hasTpDates && ( )} {hasTpDates && ( )}
)}
{renderModalContent()}
); } return (
1} className="data-[multiple='true']:mt-2" >
{state.selectedRooms[0]?.rooms ? ( <> ) : (
{hasTpDates ? t("Select the room you want to make a reservation.") : isOtel ? t( "You can change the selected dates to see the prices.", ) : t("Select a date to see hotel availability and prices")} {!hasTpDates && ( )} {hasTpDates && ( )}
)} {!!state.selectedRooms?.[0]?.rooms?.[0]?.key && !!state.searchId && (isOtel || isB2C) && (
{t("12 installments exclusive to Bonus Card")}
)} {(isOtel || isB2C) && ( {allInstallmentsBoolean.value && ( )} )}
{isOtel && (
{t( "Your vacation is safe with Cancellation Assurance Package for up to 72 hours.", )}
)}
{renderModalContent()}
); }; export default RezervationSummary;