import React, { ReactNode } from 'react';
import { Metadata } from 'next';
import { unstable_setRequestLocale } from 'next-intl/server';
import { notFound } from 'next/navigation';
import { ConfigProvider } from 'antd';
import theme from '../../constants/theme';
import { ALLOWED_LOCALES } from '../../constants/locale';
import StyledComponentsRegistry from '../../lib/AntdRegistry';
import StyledRegistry from '../../lib/StyleRegistry';
import { Header, Footer } from '../../components/Page';

type LayoutProps = {
    children: ReactNode;
    params: { locale: string };
};

export function generateStaticParams() {
    return ALLOWED_LOCALES.map((locale) => ({ locale }));
}

export const metadata: Metadata = {
    title: 'Bbuddy'
};

export default function LocaleLayout({ children, params: { locale } }: LayoutProps) {
    if (!ALLOWED_LOCALES.includes(locale as any)) notFound();

    unstable_setRequestLocale(locale);

    return (
        <StyledRegistry>
            <StyledComponentsRegistry>
                <ConfigProvider theme={theme}>
                    <div className="b-wrapper">
                        <div className="b-content">
                            <Header locale={locale} />
                            {children}
                        </div>
                        <Footer />
                    </div>
                </ConfigProvider>
            </StyledComponentsRegistry>
        </StyledRegistry>
    );
};
