'use client'

import { Toaster } from "@nice/ui/components/sonner";
import { ReactNode, useEffect } from "react";
import AuthProvider from "./auth-provider";
import QueryProvider from "./query-provider";
import { TokenProvider } from "./token-provider";
import { I18N_CONFIG, preloadLocale } from "@nice/i18n";

export default function AppProvider({ children }: { children: ReactNode }) {
    useEffect(() => {
        const preload = async () => {
            await preloadLocale(I18N_CONFIG.defaultLocale);
        };
        preload()
    }, []);

    return <>
        <TokenProvider>
            <QueryProvider>
                <AuthProvider>
                    {children}
                </AuthProvider>
            </QueryProvider>
        </TokenProvider>
        <Toaster position="top-center" />
    </>
}