import { useSelectedUserStore } from "../../../store/collaboration/useCollabStore";
import { useFrame } from "@react-three/fiber";
import { CameraControls } from "@react-three/drei";

function CollabCamFollow() {
    const { selectedUser } = useSelectedUserStore();

    useFrame((state) => {
        if (!selectedUser || !state.controls || !selectedUser.location) return;
        const controls = state.controls as CameraControls;

        controls.setLookAt(
            selectedUser.location.position.x,
            selectedUser.location.position.y,
            selectedUser.location.position.z,
            selectedUser.location.target.x,
            selectedUser.location.target.y,
            selectedUser.location.target.z,
            true
        );
    });

    return null;
}

export default CollabCamFollow;
