import type {Metadata} from 'next'
import {headers} from 'next/headers'
import {ReactNode} from 'react'

import './globals.css'
import {Toaster} from '@/components/ui/toaster'
import {routing} from '@/i18n/routing'
import {APP_DESCRIPTION, APP_NAME, APP_SLOGAN} from '@/lib/constants'

export const metadata: Metadata = {
	title: {
		template: `%s | ${APP_NAME}`,
		default: `${APP_NAME}. ${APP_SLOGAN}`
	},
	description: APP_DESCRIPTION
}

export default async function RootLayout({
	children
}: Readonly<{children: ReactNode}>) {
	const headersList = await headers()
	const locale = headersList.get('x-site-locale') ?? routing.defaultLocale

	return (
		<html lang={locale} suppressHydrationWarning>
			<body className='min-h-screen antialiased'>
				{children}
				<Toaster />
			</body>
		</html>
	)
}
