import type { Metadata } from "next";
import { DM_Sans, Fraunces } from "next/font/google";
import { ClerkProvider } from "@clerk/nextjs";
import { ConvexClientProvider } from "@repo/convex";
import { CartUIProvider } from "../components/cart/CartUIProvider";
import { AnnouncementBar } from "../components/layout/AnnouncementBar";
import { Header } from "../components/layout/header/Header";
import { SessionCartMerge } from "../lib/session/SessionCartMerge";
import { StoreUserSync } from "../lib/session/StoreUserSync";
import { Footer } from "../components/layout/footer/Footer";
import { ToastProvider } from "../components/layout/ToastProvider";
import "./globals.css";

const dmSans = DM_Sans({
  subsets: ["latin"],
  weight: ["300", "400", "500"],
  variable: "--font-dm-sans",
});

const fraunces = Fraunces({
  subsets: ["latin"],
  weight: ["100", "400", "600", "700"],
  variable: "--font-fraunces",
});

export const metadata: Metadata = {
  title: {
    template: "%s | The Pet Loft",
    default: "The Pet Loft — Pet Supplies & More",
  },
  description: "Your one-stop shop for premium pet supplies",
};

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <body
        className={`${dmSans.variable} ${fraunces.variable} font-sans flex min-h-screen max-w-full flex-col overflow-x-hidden`}
      >
        <ClerkProvider>
          <ConvexClientProvider>
            <SessionCartMerge />
            <StoreUserSync />
            <CartUIProvider>
              <AnnouncementBar />
              <Header />
              {children}
              <Footer />
              <ToastProvider />
            </CartUIProvider>
          </ConvexClientProvider>
        </ClerkProvider>
      </body>
    </html>
  );
}
