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

import Script from "next/script"

import TokenRefresher from "@/components/Auth/TokenRefresher"
import BookingWidget from "@/components/BookingWidget"
import AdobeScript from "@/components/Current/AdobeScript"
import Footer from "@/components/Current/Footer"
import LangPopup from "@/components/Current/LangPopup"
import SkipToMainContent from "@/components/SkipToMainContent"
import { getIntl } from "@/i18n"
import ServerIntlProvider from "@/i18n/Provider"
import { setLang } from "@/i18n/serverContext"

import type { Metadata } from "next"

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

export const fetchCache = "default-no-store"

export const metadata: Metadata = {
  title: "Scandic Hotels",
}

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

  return (
    <html lang={params.lang}>
      <head>
        {/* eslint-disable-next-line @next/next/no-css-tags */}
        <link rel="stylesheet" href="/_static/css/core.css" />
        {/* eslint-disable-next-line @next/next/no-css-tags */}
        <link rel="stylesheet" href="/_static/css/scandic.css" />
        <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={params.lang}
          id="Cookiebot"
          src="https://consent.cookiebot.com/uc.js"
        />
        <Script id="ensure-datalayer">{`
          window.datalayer = window.datalayer || {}
        `}</Script>
        <AdobeScript />
        <link rel="preconnect" href="https://dev.visualwebsiteoptimizer.com" />
        <Script
          id="vwoCode"
          src="/_static/dist/js/vwo.js?1714979036301"
          strategy="beforeInteractive"
        />
      </head>
      <body className="theme-00Corecolours theme-X0Oldcorecolours">
        <LangPopup />
        <SkipToMainContent />
        <ServerIntlProvider intl={{ defaultLocale, locale, messages }}>
          {header}
          {children}
          <Footer />
          <TokenRefresher />
        </ServerIntlProvider>
        <Script id="page-tracking">{`
          typeof _satellite !== "undefined" && _satellite.pageBottom();
        `}</Script>
      </body>
    </html>
  )
}
