import Subtitle from "@/components/TempDesignSystem/Text/Subtitle"
import { getIntl } from "@/i18n"

import { LinkedReservation } from "./LinkedReservation"
import Room from "./Room"

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

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

export default async function Rooms({
  booking,
  checkInTime,
  checkOutTime,
  mainRoom,
  linkedReservations,
}: BookingConfirmationRoomsProps) {
  const intl = await getIntl()

  return (
    <section className={styles.rooms}>
      <div className={styles.room}>
        {linkedReservations.length ? (
          <Subtitle color="mainGrey60" type="two">
            {intl.formatMessage(
              {
                defaultMessage: "Room {roomIndex}",
              },
              { roomIndex: 1 }
            )}
          </Subtitle>
        ) : null}
        <Room
          booking={booking}
          checkInTime={checkInTime}
          checkOutTime={checkOutTime}
          img={mainRoom.images[0]}
          roomName={mainRoom.name}
        />
      </div>

      {linkedReservations.map((reservation, idx) => (
        <div className={styles.room} key={reservation.confirmationNumber}>
          <Subtitle color="mainGrey60" type="two">
            {intl.formatMessage(
              {
                defaultMessage: "Room {roomIndex}",
              },
              { roomIndex: idx + 2 }
            )}
          </Subtitle>
          <LinkedReservation
            checkInTime={checkInTime}
            checkOutTime={checkOutTime}
            confirmationNumber={reservation.confirmationNumber}
            roomIndex={idx + 1}
          />
        </div>
      ))}
    </section>
  )
}
