import { useEffect } from "react";
import { useSocketStore } from "../../../store/socket/useSocketStore";
import { useSceneContext } from "../../scene/sceneContext";

function UserResponses() {
    const { builderSocket } = useSocketStore();
    const { collabUsersStore } = useSceneContext();
    const { setCollabUsers, clearCollabUsers } = collabUsersStore();

    //#region Users
    useEffect(() => {
        if (!builderSocket) return;

        builderSocket.on("v1:room:userDatas", (data: any) => {
            if (data?.data?.UsersDetails && data.data.UsersDetails.length > 0) {
                setCollabUsers(data.data.UsersDetails);
            } else {
                clearCollabUsers();
            }
        });

        return () => {
            if (builderSocket) {
                builderSocket.off("v1:room:userDatas");
            }
        };
    }, [builderSocket]);
    //#endregion

    //#region Camera
    useEffect(() => {
        if (!builderSocket) return;

        builderSocket.on("v1:camera:Response:update", (data: any) => {
            if (!data.message) return;
        });

        return () => {
            if (builderSocket) {
                builderSocket.off("v1:camera:Response:update");
            }
        };
    }, [builderSocket]);
    //#endregion

    return null;
}

export default UserResponses;
