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

import EnterDetailsProvider from "@/components/HotelReservation/EnterDetails/Provider"
import { setLang } from "@/i18n/serverContext"

import { preload } from "./_preload"

import { StepEnum } from "@/types/components/hotelReservation/enterDetails/step"
import type { LangParams, LayoutArgs } from "@/types/params"

export default async function StepLayout({
  summary,
  children,
  hotelHeader,
  params,
}: React.PropsWithChildren<
  LayoutArgs<LangParams & { step: StepEnum }> & {
    hotelHeader: React.ReactNode
    summary: React.ReactNode
  }
>) {
  setLang(params.lang)
  preload()

  const user = await getProfileSafely()

  return (
    <EnterDetailsProvider step={params.step} isMember={!!user}>
      <main className="enter-details-layout__layout">
        {hotelHeader}
        <div className={"enter-details-layout__container"}>
          <div className={"enter-details-layout__content"}>{children}</div>
          <aside className={"enter-details-layout__summaryContainer"}>
            {summary}
          </aside>
        </div>
      </main>
    </EnterDetailsProvider>
  )
}
