import "@/app/globals.css"
import "@scandic-hotels/design-system/style.css"

import Script from "next/script"

import { env } from "@/env/server"
import TrpcProvider from "@/lib/trpc/Provider"

import TokenRefresher from "@/components/Auth/TokenRefresher"
import AdobeSDKScript from "@/components/Current/AdobeSDKScript"
import VwoScript from "@/components/Current/VwoScript"
import { ToastHandler } from "@/components/TempDesignSystem/Toasts"
import { preloadUserTracking } from "@/components/TrackingSDK"
import { getIntl } from "@/i18n"
import ServerIntlProvider from "@/i18n/Provider"
import { setLang } from "@/i18n/serverContext"

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

export default async function RootLayout({
  bookingwidget,
  children,
  footer,
  header,
  sitewidealert,
  params,
}: React.PropsWithChildren<
  LayoutArgs<LangParams> & {
    bookingwidget: React.ReactNode
    footer: React.ReactNode
    header: React.ReactNode
    sitewidealert: React.ReactNode
  }
>) {
  setLang(params.lang)
  preloadUserTracking()
  const { defaultLocale, locale, messages } = await getIntl()

  return (
    <html lang={params.lang}>
      <head>
        <AdobeSDKScript />
        <Script data-cookieconsent="ignore" src="/_static/js/cookie-bot.js" />
        <Script
          strategy="beforeInteractive"
          data-blockingmode="auto"
          data-cbid="6d539de8-3e67-4f0f-a0df-8cef9070f712"
          data-culture="@cultureCode"
          id="Cookiebot"
          src="https://consent.cookiebot.com/uc.js"
        />
        <Script id="ensure-adobeDataLayer">{`
          window.adobeDataLayer = window.adobeDataLayer || []
        `}</Script>
        <VwoScript />
      </head>
      <body>
        <ServerIntlProvider intl={{ defaultLocale, locale, messages }}>
          <TrpcProvider>
            {!env.HIDE_FOR_NEXT_RELEASE && <>{sitewidealert}</>}
            {header}
            {!env.HIDE_FOR_NEXT_RELEASE && <>{bookingwidget}</>}
            {children}
            {footer}
            <ToastHandler />
            <TokenRefresher />
          </TrpcProvider>
        </ServerIntlProvider>
      </body>
    </html>
  )
}
