import { notFound } from "next/navigation"

import { env } from "@/env/server"
import { getHotelPage } from "@/lib/trpc/memoizedRequests"

import HotelMapPage from "@/components/ContentType/HotelMapPage"
import HotelPage from "@/components/ContentType/HotelPage"
import HotelSubpage from "@/components/ContentType/HotelSubpage"

import type { PageArgs } from "@/types/params"

export { generateMetadata } from "@/utils/generateMetadata"

export default async function HotelPagePage(
  props: PageArgs<{}, { subpage?: string; view?: "map" }>
) {
  const searchParams = await props.searchParams
  if (env.NEW_SITE_LIVE_STATUS === "NOT_LIVE") {
    return notFound()
  }

  const hotelPageData = await getHotelPage()

  if (!hotelPageData) {
    return notFound()
  }

  if (searchParams.subpage) {
    return (
      <HotelSubpage
        hotelId={hotelPageData.hotel_page_id}
        subpage={searchParams.subpage}
      />
    )
  }
  if (searchParams.view === "map") {
    return <HotelMapPage hotelId={hotelPageData.hotel_page_id} />
  }
  return <HotelPage hotelId={hotelPageData.hotel_page_id} />
}
