"use client"

import { ReactNode, useEffect } from "react";
import "../../assets/css/admin.css"
import Sidebar from "../../components/admin/sidebar";
import Header from "../../components/admin/adminHeader";
import { signOutFunc } from "#/lib/function";
import { usePathname } from "next/navigation";
import { useSession } from "next-auth/react";

export default function Dashboard({ children }: { children: ReactNode }) {
  const { status, data } = useSession();
  const path = usePathname();

  useEffect(() => {
    if (status !== "loading") {
      if (status === "unauthenticated" || (data && !data.user.access_token)) {
        signOutFunc();
      }
    }
  }, [data, status, path]);

  return (

    <div className="r-flex-between">
      <Sidebar />
      <main className="flex-grow-1 min-w-0 pt-md-1 pt-sm-5">
        <Header/>
        <div className="main px-[44px] py-[64px] ">
          {children}
        </div>
      </main>
    </div >
  )
}
