import { notFound } from "next/navigation"

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

import { getBookedHotelRoom } from "@/utils/getBookedHotelRoom"

import Room from "./Room"

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

import type { BookingConfirmationProps } from "@/types/components/hotelReservation/bookingConfirmation/bookingConfirmation"

export default async function Rooms({
  confirmationNumber,
}: BookingConfirmationProps) {
  const { booking, hotel } = await getBookingConfirmation(confirmationNumber)
  const roomAndBed = getBookedHotelRoom(hotel, booking.roomTypeCode ?? "")
  if (!roomAndBed) {
    return notFound()
  }
  return (
    <section className={styles.rooms}>
      <Room
        booking={booking}
        img={roomAndBed.images[0]}
        roomName={roomAndBed.name}
      />
    </section>
  )
}
