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

import { setLang } from "@/i18n/serverContext"
import DetailsProvider from "@/providers/DetailsProvider"

import { preload } from "./_preload"

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

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

  const user = await getProfileSafely()

  return (
    <DetailsProvider 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>
    </DetailsProvider>
  )
}
