import "@scandic-hotels/design-system/fonts.css"
import "@/app/globals.css"
import "@/public/_static/css/design-system-new-deprecated.css"
import "@scandic-hotels/design-system/style.css"

import { ReactQueryDevtools } from "@tanstack/react-query-devtools"
import Script from "next/script"
import { SessionProvider } from "next-auth/react"

import TrpcProvider from "@/lib/trpc/Provider"

import { SessionRefresher } from "@/components/Auth/TokenRefresher"
import CookieBotConsent from "@/components/CookieBot"
import Footer from "@/components/Footer"
import Header from "@/components/Header"
import StorageCleaner from "@/components/HotelReservation/EnterDetails/StorageCleaner"
import SitewideAlert from "@/components/SitewideAlert"
import { ToastHandler } from "@/components/TempDesignSystem/Toasts"
import AdobeSDKScript from "@/components/TrackingSDK/AdobeSDKScript"
import GTMScript from "@/components/TrackingSDK/GTMScript"
import RouterTracking from "@/components/TrackingSDK/RouterTracking"
import { getIntl } from "@/i18n"
import ServerIntlProvider from "@/i18n/Provider"

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

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

  return (
    <>
      <head>
        <AdobeSDKScript />
        <GTMScript />
        <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>
      </head>
      <body className="scandic">
        <SessionProvider basePath="/api/web/auth">
          <ServerIntlProvider intl={{ defaultLocale, locale, messages }}>
            <TrpcProvider>
              <RouterTracking />
              <SitewideAlert />
              <Header />
              {bookingwidget}
              {children}
              <Footer />
              <ToastHandler />
              <SessionRefresher />
              <StorageCleaner />
              <CookieBotConsent />
              <ReactQueryDevtools initialIsOpen={false} />
            </TrpcProvider>
          </ServerIntlProvider>
        </SessionProvider>
      </body>
    </>
  )
}
