import type { Metadata } from 'next';
import '@/styles/tailwind.css';
import { Toaster } from 'sonner';
import { AuthProvider } from '@client/contexts/AuthContext';
import { LanguageProvider } from '@client/contexts/LanguageContext';

export const metadata: Metadata = {
  title: 'RestroAgent — AI Voice & Chat for Restaurants',
  description: 'AI-powered voice and chat agents for restaurant orders and table bookings',
  icons: { icon: '/favicon.ico' },
};

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en" dir="ltr" suppressHydrationWarning>
      <head>
        <link rel="preconnect" href="https://fonts.googleapis.com" />
        <link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="anonymous" />
        {/* Bootstrap lang/dir from localStorage before React hydrates to avoid FOUC */}
        <script
          suppressHydrationWarning
          dangerouslySetInnerHTML={{
            __html: `(function(){try{var l=localStorage.getItem('rra_lang');if(l){var RTL=['ar','he','fa','ur','yi','ku'];var d=RTL.indexOf(l)>=0?'rtl':'ltr';document.documentElement.setAttribute('lang',l);document.documentElement.setAttribute('dir',d);}}catch(e){}})();`,
          }}
        />
</head>
      <body className="antialiased">
        <LanguageProvider>
          <AuthProvider>
            {children}
          </AuthProvider>
        </LanguageProvider>
        <Toaster
          position="top-right"
          toastOptions={{
            duration: 3500,
            style: {
              fontFamily: 'DM Sans, system-ui, sans-serif',
              fontSize: '14px',
              borderRadius: '10px',
              border: '1px solid hsl(220, 13%, 91%)',
              boxShadow: '0 10px 24px -4px rgb(0 0 0 / 0.10)',
            },
          }}
        />
      </body>
    </html>
  );
}