import { SelectHotelMapPage as SelectHotelMapPagePrimitive } from "@scandic-hotels/booking-flow/pages/SelectHotelMapPage"
import { toCapitalCase } from "@scandic-hotels/common/utils/toCapitalCase"

import { bookingFlowConfig } from "@/constants/bookingFlowConfig"

import { getLang } from "@/i18n/serverContext"

import type { Metadata } from "next"

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

export async function generateMetadata({
  searchParams,
}: PageArgs<LangParams>): Promise<Metadata> {
  const { city } = await searchParams

  if (!city || Array.isArray(city)) {
    return {}
  }

  return {
    title: `${toCapitalCase(city)}`,
  }
}

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

  return (
    <SelectHotelMapPagePrimitive
      lang={lang}
      searchParams={searchParams}
      config={bookingFlowConfig}
    />
  )
}
