import { DM_Sans, Plus_Jakarta_Sans, JetBrains_Mono } from 'next/font/google';
import './globals.css';
import { Toaster } from '@/components/ui/sonner';
import { ChunkLoadErrorHandler } from '@/components/chunk-load-error-handler';
import { Providers } from './providers';
import { GoogleAnalytics } from '@/components/google-analytics';
import type { Metadata } from 'next';

export const dynamic = 'force-dynamic';

const dmSans = DM_Sans({ subsets: ['latin'], variable: '--font-sans' });
const jakartaSans = Plus_Jakarta_Sans({ subsets: ['latin'], variable: '--font-display' });
const jetbrainsMono = JetBrains_Mono({ subsets: ['latin'], variable: '--font-mono' });

export const metadata: Metadata = {
  title: {
    default: 'Evo Truck Sales | Commercial Trucks & Heavy Equipment Dealer in NJ',
    template: '%s | Evo Truck Sales',
  },
  description: 'Buy quality commercial trucks, dump trucks, trailers, backhoes and heavy equipment at Evo Truck Sales in Hillside, NJ. Financing available. Serving Owner Operators and Fleets. Call (908) 590-9802.',
  metadataBase: new URL(process.env.NEXTAUTH_URL || 'http://localhost:3000'),
  icons: { icon: '/favicon.svg', shortcut: '/favicon.svg' },
  keywords: ['commercial trucks for sale', 'heavy equipment dealer NJ', 'dump trucks', 'trailers for sale', 'used trucks NJ', 'Evo Truck Sales', 'Hillside NJ trucks', 'owner operator trucks', 'fleet trucks', 'backhoe for sale', 'box truck', 'sleeper truck', 'day cab truck'],
  authors: [{ name: 'Evo Truck Sales' }],
  creator: 'Evo Truck Sales',
  publisher: 'Evo Truck Sales',
  openGraph: {
    type: 'website',
    locale: 'en_US',
    siteName: 'Evo Truck Sales',
    title: 'Evo Truck Sales | Commercial Trucks & Heavy Equipment Dealer',
    description: 'Quality commercial trucks and heavy equipment at competitive prices in Hillside, NJ.',
    images: [{ url: '/og-image.png', width: 1200, height: 630, alt: 'Evo Truck Sales - Commercial Trucks & Heavy Equipment' }],
  },
  twitter: {
    card: 'summary_large_image',
    title: 'Evo Truck Sales | Trucks & Heavy Equipment',
    description: 'Quality commercial trucks and heavy equipment at competitive prices.',
    images: ['/og-image.png'],
  },
  alternates: {
    canonical: '/',
  },
  robots: {
    index: true,
    follow: true,
    googleBot: {
      index: true,
      follow: true,
      'max-video-preview': -1,
      'max-image-preview': 'large' as const,
      'max-snippet': -1,
    },
  },
};

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en" suppressHydrationWarning>
      <head>
        <meta httpEquiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
        <meta httpEquiv="Pragma" content="no-cache" />
        <meta httpEquiv="Expires" content="0" />
        <script src="https://apps.abacus.ai/chatllm/appllm-lib.js" />
        <script dangerouslySetInnerHTML={{ __html: `
          if ('caches' in window) {
            caches.keys().then(function(names) {
              for (var i = 0; i < names.length; i++) { caches.delete(names[i]); }
            });
          }
          if ('serviceWorker' in navigator) {
            navigator.serviceWorker.getRegistrations().then(function(regs) {
              for (var i = 0; i < regs.length; i++) { regs[i].unregister(); }
            });
          }
        `}} />
      </head>
      <body className={`${dmSans.variable} ${jakartaSans.variable} ${jetbrainsMono.variable} font-sans`}>
        <Providers>
          {children}
          <Toaster />
          <ChunkLoadErrorHandler />
          <GoogleAnalytics />
        </Providers>
      </body>
    </html>
  );
}
