'use client'
import { useHookstate } from "@hookstate/core";
import { useShallowEffect } from "@mantine/hooks";
import { useParams } from "next/navigation";
import { funGetUserByCookies } from "@/module/auth";
import { globalIsMemberProject } from "../lib/val_project";
import { funGetOneProjectById } from "../lib/api_project";

export default function WrapLayoutProject({ children }: { children: React.ReactNode }) {
   const isMember = useHookstate(globalIsMemberProject)
   const param = useParams<{ id: string }>()

   const getData = async () => {
      const res = await funGetOneProjectById(param.id, 'member');
      const login = await funGetUserByCookies()
      const cekMember = res.data.some((i: any) => i.idUser == login.id)
      isMember.set(cekMember)
   }

   useShallowEffect(() => {
      getData()
   }, [])
   return (
      <>
         {children}
      </>
   );
}