import React from "react";
import styles from "./dashboard.module.css";
import Sidebar from "@/components/administrator/Sidebar/sidebar";
import UserProvider from "@/providers/user.provider";
import { decodeAccessToken } from "@/utils/cookie";
import AdminVisitor from "@/providers/admin.visitor";
import { description as defaultDescription } from "@/config/default";
import { getGeneralSettings } from "@/models/settings";
import { EditorProvider } from "@/components/administrator/EditorMD/provider";

const layout = async ({ children }) => {
  const accessToken = await decodeAccessToken();

  let description = await getGeneralSettings();

  if (!description) description = defaultDescription;

  return (
    <>
      <AdminVisitor description={description}>
        <UserProvider userData={accessToken?.data}>
          <EditorProvider>
            <div className={styles.dashboard}>
              <Sidebar user={accessToken?.data} />
              <div className={styles.content}>{children}</div>
            </div>
          </EditorProvider>
        </UserProvider>
      </AdminVisitor>
    </>
  );
};

export default layout;
