import { Suspense } from "react"

import { SelectHotelMapContainer } from "@/components/HotelReservation/SelectHotel/SelectHotelMap/SelectHotelMapContainer"
import { SelectHotelMapContainerSkeleton } from "@/components/HotelReservation/SelectHotel/SelectHotelMap/SelectHotelMapContainerSkeleton"
import { MapContainer } from "@/components/MapContainer"
import { setLang } from "@/i18n/serverContext"

import styles from "./page.module.css"

import type { SelectHotelSearchParams } from "@/types/components/hotelReservation/selectHotel/selectHotelSearchParams"
import type { LangParams, PageArgs } from "@/types/params"

export default async function SelectHotelMapPage({
  params,
  searchParams,
}: PageArgs<LangParams, SelectHotelSearchParams>) {
  setLang(params.lang)

  const roomKey = Object.keys(searchParams)
    .filter((key) => key.startsWith("room["))
    .map((key) => searchParams[key])
    .join("-")

  return (
    <div className={styles.main}>
      <MapContainer>
        <Suspense
          key={`${searchParams.city}-${searchParams.fromDate}-${searchParams.toDate}-${roomKey}`}
          fallback={<SelectHotelMapContainerSkeleton />}
        >
          <SelectHotelMapContainer searchParams={searchParams} />
        </Suspense>
      </MapContainer>
    </div>
  )
}
