import type { Metadata } from "next";
import { cookies } from "next/headers";
import "./globals.css";
import { I18nProvider } from "./i18n-provider";
import { directionFor, getDictionary } from "@/lib/i18n";
import { getLocale } from "@/lib/locale";

export const metadata: Metadata = {
  title: "کاپیلا پلاس",
  description: "پنل مدیریت کاپیلا پلاس",
};

export default async function RootLayout({
  children,
}: Readonly<{ children: React.ReactNode }>) {
  const locale = await getLocale();
  const dictionary = getDictionary(locale);
  const themeCookie = (await cookies()).get("capila_theme")?.value;
  const theme = themeCookie === "dark" ? "dark" : "light";
  return (
    <html
      lang={locale}
      dir={directionFor(locale)}
      data-theme={theme}
      suppressHydrationWarning
    >
      <body>
        <I18nProvider locale={locale} dictionary={dictionary}>
          {children}
        </I18nProvider>
      </body>
    </html>
  );
}
