/**
 * Camera + touch controls for the Workshop scene.
 *
 * Uses Three.js OrbitControls with constrained range — the visitor
 * can look around the room but not leave it.
 */

import { OrbitControls } from "https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/controls/OrbitControls.js";

/**
 * Set up camera controls.
 * @param {THREE.PerspectiveCamera} camera
 * @param {HTMLCanvasElement} domElement
 * @returns {OrbitControls}
 */
export function setupControls(camera, domElement) {
    const controls = new OrbitControls(camera, domElement);

    // Smooth damping
    controls.enableDamping = true;
    controls.dampingFactor = 0.08;

    // Limit zoom range
    controls.minDistance = 3;
    controls.maxDistance = 12;

    // Limit vertical angle (don't look below floor or straight up)
    controls.minPolarAngle = Math.PI * 0.2;
    controls.maxPolarAngle = Math.PI * 0.6;

    // Limit horizontal rotation range (stay facing the desk area)
    controls.minAzimuthAngle = -Math.PI * 0.4;
    controls.maxAzimuthAngle = Math.PI * 0.4;

    // Target: roughly the desk area
    controls.target.set(0, 1.2, 0);

    // Touch settings
    controls.touches = {
        ONE: 0, // ROTATE
        TWO: 2, // DOLLY
    };

    // Disable panning (visitor stays in place)
    controls.enablePan = false;

    controls.update();

    return controls;
}
