"use client"; import dayjs from "dayjs"; import { useHotelSearch } from "@/features/hotel/hooks/use-hotel-search"; import { usePageInfo } from "@/hooks/use-page-info"; import { useApp } from "@/hooks/useApp"; import { useHotelListSearchQuery } from "@/services/eva-display/hotel/hotel-search/hotel-search.services"; import { useLocalizationStore } from "@/store/localization-store/use-localization-store"; import type { IHotelListContext } from "../context/hotel-list-context"; const useHotelListContextValues = (): IHotelListContext | null => { const { info } = usePageInfo(); const { isB2E } = useApp(); const { localizationState } = useLocalizationStore(); const { getVariables, getRoom, getDestionationSubTypeValue, getDestionationTypeValue, } = useHotelSearch(); if ( !info?.queryParams?.destinationId || !info?.queryParams?.destinationTypeName || !info?.queryParams?.destination || !info?.queryParams?.destinationType || !info?.queryParams?.checkinDate || !info?.queryParams?.checkoutDate ) { window.location.href = "/"; } const { rooms, originCode, originId } = getVariables()!; const destinationId = Number(info?.queryParams?.destinationId); const now = dayjs(); let orderBy = isB2E ? "PriceAscending" : "Average"; if (info?.queryParams?.orderBy === "PriceAscending") orderBy = "PriceAscending"; else if (info?.queryParams?.orderBy === "PriceDescending") orderBy = "PriceDescending"; const { data, finalData, requestVariables, isLoading, isIdle, setFilterValue, getMoreData, applyFilter, applyOrderBy, applyPriceFilter, clearFilter, onIsApplicable, } = useHotelListSearchQuery({ variables: { searchId: null, requestKey: null, countryCode: "TR", currency: localizationState.data.currency ?? "TRY", destinationId, destinationType: getDestionationTypeValue( info!.queryParams!.destinationTypeName!, ), // info?.queryParams?.destinationType, destinationName: info?.queryParams?.destination, destinationSubType: getDestionationSubTypeValue( +info!.queryParams!.destinationType!, ), checkInDate: info?.queryParams?.checkinDate || now.format("YYYY-MM-DD"), checkOutDate: info?.queryParams?.checkoutDate || now.format("YYYY-MM-DD"), orderBy, pageSize: 10, pageNumber: 1, rooms: getRoom(rooms), originCode, originId, filter: { hotelName: "", facilities: [], locations: [], mealTypes: [], themes: [], maxPrice: null, minPrice: null, }, }, }); return { hotelList: finalData, hotelListResponse: data, requestData: requestVariables, isLoading, isIdle, setFilterValue, getMoreData, applyFilter, applyOrderBy, applyPriceFilter, clearFilter, onIsApplicable, }; }; export default useHotelListContextValues;