import {TypedEventNode} from "./_Base";
import {EventConnectionPoint, EventConnectionPointType} from "../utils/io/connections/Event";
import {NodeParamsConfig, ParamConfig} from "../utils/params/ParamsConfig";
class ViewerParamsConfig extends NodeParamsConfig {
  constructor() {
    super(...arguments);
    this.className = ParamConfig.STRING("active");
  }
}
const ParamsConfig2 = new ViewerParamsConfig();
export class ViewerEventNode extends TypedEventNode {
  constructor() {
    super(...arguments);
    this.params_config = ParamsConfig2;
  }
  static type() {
    return "viewer";
  }
  initializeNode() {
    this.io.inputs.setNamedInputConnectionPoints([
      new EventConnectionPoint("set", EventConnectionPointType.BASE, this._process_trigger_setClass.bind(this)),
      new EventConnectionPoint("unset", EventConnectionPointType.BASE, this._process_trigger_unsetClass.bind(this)),
      new EventConnectionPoint("createControls", EventConnectionPointType.BASE, this._process_trigger_createControls.bind(this)),
      new EventConnectionPoint("disposeControls", EventConnectionPointType.BASE, this._process_trigger_disposeControls.bind(this))
    ]);
  }
  _process_trigger_setClass(context) {
    const canvas = context.viewer?.canvas();
    if (canvas) {
      canvas.classList.add(this.pv.className);
    }
  }
  _process_trigger_unsetClass(context) {
    const canvas = context.viewer?.canvas();
    if (canvas) {
      canvas.classList.remove(this.pv.className);
    }
  }
  _process_trigger_createControls(context) {
    this.scene().viewersRegister.traverseViewers((v) => {
      v.controlsController?.create_controls();
    });
  }
  _process_trigger_disposeControls(context) {
    this.scene().viewersRegister.traverseViewers((v) => {
      v.controlsController?.dispose_controls();
    });
  }
}
