import type { Metadata } from 'next';
import './globals.css';
import { Providers } from './providers';
import AppHeader from '@/components/AppHeader';
import { Footer } from '@/components/Footer';
import { LoadingIndicator } from '@/components/LoadingIndicator';

export const metadata: Metadata = {
  title: 'EDR Passenger Portal - Book your train journey',
  description: 'Book train tickets on the Ethio-Djibouti Railway',
};

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en" suppressHydrationWarning>
      <body className="font-sans antialiased flex flex-col min-h-screen">
        <script
          dangerouslySetInnerHTML={{
            __html: `
              (function() {
                try {
                  var theme = localStorage.getItem('theme');
                  var effectiveTheme = 'light';
                  
                  if (theme === 'dark') {
                    effectiveTheme = 'dark';
                  } else if (theme === 'light') {
                    effectiveTheme = 'light';
                  } else if (theme === 'system' || !theme) {
                    effectiveTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
                  }
                  
                  document.documentElement.classList.add(effectiveTheme);
                } catch (e) {}
              })();
            `,
          }}
        />
        <Providers>
          <LoadingIndicator />
          <AppHeader />
          <main className="flex-1">
            {children}
          </main>
          <Footer />
        </Providers>
      </body>
    </html>
  );
}
