import { redirect } from "next/navigation"

import { serverClient } from "@/lib/trpc/server"

import SelectedRoom from "@/components/HotelReservation/EnterDetails/SelectedRoom"
import HotelSelectionHeader from "@/components/HotelReservation/HotelSelectionHeader"
import Summary from "@/components/HotelReservation/SelectRate/Summary"

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

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

export default async function StepLayout({
  children,
  params,
}: React.PropsWithChildren<LayoutArgs<LangParams>>) {
  const hotel = await serverClient().hotel.hotelData.get({
    hotelId: "811",
    language: params.lang,
  })

  if (!hotel?.data) {
    redirect(`/${params.lang}`)
  }

  return (
    <main className={styles.layout}>
      <HotelSelectionHeader hotel={hotel.data.attributes} />
      <div className={styles.content}>
        <SelectedRoom />
        {children}
        <aside className={styles.summary}>
          <Summary />
        </aside>
      </div>
    </main>
  )
}
