import {TypedEventNode} from "./_Base";
export class TypedCameraControlsEventNode extends TypedEventNode {
  constructor() {
    super(...arguments);
    this._controls_by_viewer = new Map();
  }
  async apply_controls(camera, viewer) {
    viewer.controlsController?.dispose_controls();
    const canvas = viewer.canvas();
    if (!canvas) {
      return;
    }
    const controls = await this.create_controls_instance(camera, canvas);
    const current_controls = this._controls_by_viewer.get(viewer);
    if (current_controls) {
      current_controls.dispose();
    }
    this._controls_by_viewer.set(viewer, controls);
    const timestamp = performance.now();
    controls.name = `${this.fullPath()}:${camera.name}:${timestamp}:${this.controls_id()}`;
    await this.params.eval_all();
    this.setup_controls(controls);
    return controls;
  }
  controls_id() {
    return JSON.stringify(this.params.all.map((p) => p.value_serialized));
  }
}
