import { redirect } from "next/navigation"

import { getHotelData } from "@/lib/trpc/memoizedRequests"

import HotelSelectionHeader from "@/components/HotelReservation/HotelSelectionHeader"

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

export default async function HotelHeader({
  params,
  searchParams,
}: PageArgs<LangParams, { hotel: string }>) {
  const home = `/${params.lang}`
  if (!searchParams.hotel) {
    redirect(home)
  }
  const hotel = await getHotelData({
    hotelId: searchParams.hotel,
    language: params.lang,
  })
  if (!hotel?.data) {
    redirect(home)
  }
  return <HotelSelectionHeader hotel={hotel.data.attributes} />
}
