import { Socket } from "socket.io-client";
import * as THREE from "three";
import { getUserData } from "../../../functions/getUserData";

export default function updateCamPosition(
  controls: any,
  socket: Socket,
  position: THREE.Vector3,
  rotation: THREE.Euler,
  projectId?: string
) {
  const { userId, organization } = getUserData();
  if (!controls.current) return;
  const target = controls.current.getTarget(new THREE.Vector3());

  const camData = {
    organization,
    userId: userId,
    position: position,
    target: new THREE.Vector3(target.x, 0, target.z),
    rotation: new THREE.Vector3(rotation.x, rotation.y, rotation.z),
    socketId: socket.id,
    projectId,
  };
  socket.emit("v1:Camera:set", camData);
}
