"use server"

import Board from "@/components/Board";
import { liveblocksClient } from "@/lib/liveblocksClient";
import { getUserEmail } from "@/lib/userClient";


type PageProps ={
    params: {
        boardId: string;
    };
};


const BoardPage = async (props: PageProps) => {
    const boardId = props.params.boardId
    const userEmail = await getUserEmail();
    const boardInfo = await liveblocksClient.getRoom(boardId)
    const userAcess = boardInfo.usersAccesses?.[userEmail];
    const hasAccess = userAcess && [...userAcess].includes('room:write');
    
    if(!hasAccess){
        return(
            <div>Access denied</div>
        )
    }


  return (
    <div>  
        <Board name={boardInfo.metadata.boardName.toString()} id={boardId}/>
    </div>
  )
}

export default BoardPage