import type { Metadata } from "next";
import { cookies } from "next/headers";
import Script from "next/script";
import React, { Suspense } from "react";
import { RefineContext } from "./RefineContext";
import { META_DATA } from "@config/config";

export const metadata: Metadata = META_DATA;

export default async function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  const cookieStore = await cookies();
  const theme = cookieStore.get("theme");
  const defaultMode = theme?.value === "dark" ? "dark" : "light";

  return (
    <html lang="zh-CN">
      <body>
        <Script src="/runtime-config.js" strategy="beforeInteractive" />
        <Suspense>
          <RefineContext defaultMode={defaultMode}>{children}</RefineContext>
        </Suspense>
      </body>
    </html>
  );
}
