"use client" import { APIProvider } from "@vis.gl/react-google-maps" import { useRouter, useSearchParams } from "next/navigation" import { useEffect, useRef, useState } from "react" import { useIntl } from "react-intl" import { useMediaQuery } from "usehooks-ts" import { selectHotel } from "@/constants/routes/hotelReservation" import { CloseIcon, CloseLargeIcon } from "@/components/Icons" import InteractiveMap from "@/components/Maps/InteractiveMap" import { BackToTopButton } from "@/components/TempDesignSystem/BackToTopButton" import Button from "@/components/TempDesignSystem/Button" import useLang from "@/hooks/useLang" import FilterAndSortModal from "../FilterAndSortModal" import HotelListing from "./HotelListing" import styles from "./selectHotelMap.module.css" import { SelectHotelMapProps } from "@/types/components/hotelReservation/selectHotel/map" export default function SelectHotelMap({ apiKey, hotelPins, mapId, hotels, filterList, cityCoordinates, }: SelectHotelMapProps) { const searchParams = useSearchParams() const router = useRouter() const lang = useLang() const intl = useIntl() const isAboveMobile = useMediaQuery("(min-width: 768px)") const [activeHotelPin, setActiveHotelPin] = useState(null) const [showBackToTop, setShowBackToTop] = useState(false) const listingContainerRef = useRef(null) const selectHotelParams = new URLSearchParams(searchParams.toString()) const selectedHotel = selectHotelParams.get("selectedHotel") const coordinates = isAboveMobile ? cityCoordinates : { ...cityCoordinates, lat: cityCoordinates.lat - 0.006 } useEffect(() => { if (listingContainerRef.current) { const activeElement = listingContainerRef.current.querySelector(`[data-active="true"]`) if (activeElement) { activeElement.scrollIntoView({ behavior: "smooth", block: "nearest" }) } } }, [activeHotelPin]) useEffect(() => { if (selectedHotel) { setActiveHotelPin(selectedHotel) } }, [selectedHotel]) useEffect(() => { const hotelListingElement = document.querySelector( `.${styles.listingContainer}` ) if (!hotelListingElement) return const handleScroll = () => { const hasScrolledPast = hotelListingElement.scrollTop > 490 setShowBackToTop(hasScrolledPast) } hotelListingElement.addEventListener("scroll", handleScroll) return () => hotelListingElement.removeEventListener("scroll", handleScroll) }, []) function scrollToTop() { const hotelListingElement = document.querySelector( `.${styles.listingContainer}` ) hotelListingElement?.scrollTo({ top: 0, behavior: "smooth" }) } function handlePageRedirect() { const newUrl = `${selectHotel(lang)}?${searchParams.toString()}` if (window.history.length > 1) { router.back() } else { router.push(newUrl) } } const closeButton = ( ) return (
{showBackToTop && }
) }