import { NextIntlClientProvider } from 'next-intl';
import { getMessages } from 'next-intl/server';
import { ReactNode } from 'react';
import { Metadata } from 'next';
import { Sora } from 'next/font/google';
import { defaultMeta } from '../../metaData';
import { routing, SupportedLocales } from '@/i18n/routing';
import { notFound } from 'next/navigation';
import { ScrollToTopButton } from '../buttons';
import CookiesScripts from '@/components/CookiesScripts';
import CookiePopup from '../poups/CookiePoup';

const SoraFont = Sora({
    subsets: ['latin'],
    weight: ["100", "200", "300", "400", "500", "600", "700", "800"],
    variable: '--font-sora',
    display: "swap"
});

type BaseLayoutProps = {
    children: ReactNode;
    locale?: string;
    metadata?: Metadata;
};

export const generateMetadata = (): Metadata => defaultMeta;

export default async function BaseLayout({
    children,
    locale = routing.defaultLocale,
}: BaseLayoutProps) {
    const messages = await getMessages();
    if (!routing.locales.includes(locale as SupportedLocales)) {
        notFound();
    }

    return (
        <html className={`${SoraFont.variable} h-full`} lang={locale}>
         <CookiesScripts/>

            <body >
                {/* GTM NoScript Fallback */}
                <noscript>
                    <iframe
                        src="https://www.googletagmanager.com/ns.html?id=GTM-P8JKN8P5"
                        height="0"
                        width="0"
                        style={{ display: 'none', visibility: 'hidden' }}
                    ></iframe>
                </noscript>

                <NextIntlClientProvider messages={messages}>
                    {children}
                    <ScrollToTopButton />
                    <CookiePopup/>
                </NextIntlClientProvider>
            </body>
        </html>
    );
}
