import "@scandic-hotels/common/polyfills"

import { env } from "@/env/server"
import { configureTrpc } from "@/lib/trpc"

import { getTitlePrefix } from "@/util/metadata/getTitlePrfiex"

import type { Metadata } from "next"

configureTrpc()

export async function generateMetadata(): Promise<Metadata> {
  return {
    title: {
      template: combineSegments([
        getTitlePrefix(),
        "%s",
        "SAS by Scandic Hotels",
      ]),
      default: combineSegments([getTitlePrefix(), "SAS by Scandic Hotels"]),
    },
    other: {
      "x-release": env.RELEASE_TAG || "-",
    },
  }
}

export default function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return <>{children}</>
}

function combineSegments(
  segments: (string | null | undefined)[],
  delimiter = " | "
) {
  return segments.filter(Boolean).join(delimiter).trim()
}
