import type { Metadata } from "next";
import Providers from '@/app/providers/getQueryServer'
import { NextIntlClientProvider, hasLocale } from 'next-intl';
import { notFound } from 'next/navigation';
import { getQueryClient } from '@/app/providers/getQueryClient';
import { HydrationBoundary, dehydrate } from '@tanstack/react-query';
import { prefetchLayoutQueries } from '@/app/lib/prefetch-queries';
import { routing } from '@/i18n/routing';
import AdminLayoutWrapper from '@/app/components/admin-layout-wrapper';

export const metadata: Metadata = {
	title: "Admin panel no copy",
	description: "Admin panel no copy",
};

export async function generateStaticParams() {
	return routing.locales.map((locale: any) => ({ locale }));
}

export default async function RootLayout({
	children,
	params
}: Readonly<{
	children: React.ReactNode;
	params: Promise<{ locale: string }>;
}>) {
	const { locale } = await params;

	if (!hasLocale(routing.locales, locale)) {
		notFound();
	}

	const queryClient = getQueryClient();

	await prefetchLayoutQueries(queryClient);

	return (
		<HydrationBoundary state={dehydrate(queryClient)}>
			<div className="admin-panel">
				<AdminLayoutWrapper>
					{children}
				</AdminLayoutWrapper>
			</div>
		</HydrationBoundary>
	);
}