import { ensurePerformanceMeasurePatched } from "@/lib/performance-measure-polyfill"
import type { Metadata } from "next"
import { Inter, JetBrains_Mono } from "next/font/google"
import "./globals.css"
import { ConvexClientProvider } from "./ConvexClientProvider"
import { AuthProvider } from "@/lib/auth-client"
import { Toaster } from "@/components/ui/sonner"
import { ChatWidgetProvider } from "@/components/chat/chat-widget-provider"

const inter = Inter({
  subsets: ["latin"],
  display: "swap",
  variable: "--font-inter",
})

const jetbrainsMono = JetBrains_Mono({
  subsets: ["latin"],
  display: "swap",
  variable: "--font-mono",
})

export const metadata: Metadata = {
  title: "Raven - Sistema de chamados",
  description: "Plataforma Raven da Rever",
  icons: {
    icon: [
      { url: "/favicon.ico", rel: "icon" },
      { url: "/icon.png", rel: "icon", type: "image/png" },
    ],
    shortcut: "/favicon.ico",
    apple: "/icon.png",
  },
}

// Força renderização dinâmica em todo o app para evitar páginas estáticas
// cacheadas sem passar pelo middleware de autenticação.
export const dynamic = "force-dynamic"

ensurePerformanceMeasurePatched()

export default async function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode
}>) {
  return (
    <html lang="pt-BR" className={`${inter.variable} ${jetbrainsMono.variable} h-full`} suppressHydrationWarning>
      <body className="min-h-screen bg-background text-foreground antialiased">
        <ConvexClientProvider>
          <AuthProvider>
            {children}
            <ChatWidgetProvider />
            <Toaster position="bottom-center" richColors />
          </AuthProvider>
        </ConvexClientProvider>
      </body>
    </html>
  )
}
