import { ensurePerformanceMeasurePatched } from "@/lib/performance-measure-polyfill"
import type { Metadata } from "next"
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"

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="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>
  )
}
