import "@scandic-hotels/common/polyfills"

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"]),
    },
  }
}

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

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