'use client';

import { SessionProvider } from 'next-auth/react';
import { CsrfProvider } from '@/context/CsrfContext';
import { NextIntlClientProvider } from 'next-intl';
import { EstablishmentProvider } from '@/context/EstablishmentContext';
import { DndProvider } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';

export default function Providers({ children, messages, locale, session }) {
  if (!locale) {
    console.error('Locale non définie dans Providers');
    locale = 'fr'; // Valeur par défaut
  }
  return (
    <SessionProvider session={session}>
      <DndProvider backend={HTML5Backend}>
        <CsrfProvider>
          <EstablishmentProvider>
            <NextIntlClientProvider messages={messages} locale={locale}>
              {children}
            </NextIntlClientProvider>
          </EstablishmentProvider>
        </CsrfProvider>
      </DndProvider>
    </SessionProvider>
  );
}
