import { notFound } from "next/navigation"
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 { parseSelectHotelSearchParams } from "@/utils/url"

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

import type { LangParams, NextSearchParams, PageArgs } from "@/types/params"

export default async function SelectHotelMapPage(
  props: PageArgs<LangParams, NextSearchParams>
) {
  const searchParams = await props.searchParams

  const booking = parseSelectHotelSearchParams(searchParams)

  if (!booking) return notFound()

  return (
    <div className={styles.main}>
      <MapContainer>
        <Suspense
          key={searchParams.hotel}
          fallback={<SelectHotelMapContainerSkeleton />}
        >
          <SelectHotelMapContainer booking={booking} isAlternativeHotels />
        </Suspense>
      </MapContainer>
    </div>
  )
}
