import type { PropsWithChildren } from "react"; import { createContext, useContext } from "react"; import type { RangeValue } from "@/components/ui/range-slider/range-slider"; import type { IHotelSearchResultSerializer } from "@/services/eva-display/hotel/hotel-search/hotel-search-services.serializer"; import type { IHotelListItem, IHotelSearchRequest, IHotelSearchRequestFilter, } from "@/services/eva-display/hotel/hotel-search/hotel-search-services.types"; import useHotelListContextValues from "../hooks/use-hotel-list-context"; type ApplyFilterType = < K extends keyof Omit, >( key: keyof Omit, value: Omit[K], ) => void; export interface IHotelListContext { requestData: IHotelSearchRequest; hotelList: (IHotelListItem | { key: string })[] | undefined; hotelListResponse: IHotelSearchResultSerializer | undefined; isLoading: boolean; isIdle: boolean; setFilterValue: ( key: keyof IHotelSearchRequest, value: unknown, requestParams: Pick, ) => void; getMoreData: ( requestParams: Pick, ) => void; applyFilter: ApplyFilterType; applyPriceFilter: (price: RangeValue) => void; applyOrderBy: (orderBy: string) => void; clearFilter: (withoutPrice?: boolean) => void; onIsApplicable: ( filterParameters: | { filterKey: keyof IHotelSearchRequestFilter; filterValue: string; } | boolean, ) => void; } const initialValue: Partial = {}; export const HotelListContext = createContext>(initialValue); interface HotelListContextProviderProps extends PropsWithChildren {} export const HotelListContextProvider = ({ children, }: HotelListContextProviderProps) => { const value = useHotelListContextValues(); if (value === null) return <>There is no any filter; return ( {children} ); }; export const useHotelListContext = () => useContext(HotelListContext);