'use client'

import { usePathname } from 'next/navigation'
import { I18nProvider } from '@/i18n'
import { ThemeProvider } from '@/components/providers/theme-provider'
import { AuthProvider } from '@/lib/auth-context'
import { Toaster } from '@/components/ui/sonner'
import { Header } from '@/components/layout/header'
import { Footer } from '@/components/layout/footer'
import { AIAssistant } from '@/components/ai-assistant'
import type { ReactNode } from 'react'

export function RootLayoutClient({ children }: { children: ReactNode }) {
  const pathname = usePathname()
  const isAdminPage = pathname?.startsWith('/admin')

  return (
    <ThemeProvider attribute="class" defaultTheme="system" enableSystem disableTransitionOnChange>
      <AuthProvider>
        <I18nProvider>
          {!isAdminPage && <Header />}
          <main className={isAdminPage ? 'flex-1' : 'flex-1'}>{children}</main>
          {!isAdminPage && <Footer />}
          {!isAdminPage && <AIAssistant />}
          <Toaster richColors closeButton />
        </I18nProvider>
      </AuthProvider>
    </ThemeProvider>
  )
}