import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js'
const _changeEvent = { type: 'change' }
class DmtControl extends OrbitControls {
  constructor(object, domElement) {
    super(object, domElement)
    const scope = this
    const STATE = {
      NONE: -1,
      ROTATE: 0,
      DOLLY: 1,
      PAN: 2,
      TOUCH_ROTATE: 3,
      TOUCH_PAN: 4,
      TOUCH_DOLLY_PAN: 5,
      TOUCH_DOLLY_ROTATE: 6
    }

    // eslint-disable-next-line no-unused-vars
    let state = STATE.NONE
    this.resetState = function(target0, position0, zoom0) {
      scope.target.copy(target0)
      scope.object.position.copy(position0)
      scope.object.zoom = zoom0

      scope.object.updateProjectionMatrix()
      scope.dispatchEvent(_changeEvent)

      scope.update()

      state = STATE.NONE
    }
    this.setLookAt = function(position0, target0, zoom0) {
      scope.target.copy(target0)
      scope.object.position.copy(position0)
      scope.object.zoom = zoom0

      scope.object.updateProjectionMatrix()
      scope.dispatchEvent(_changeEvent)

      scope.update()

      state = STATE.NONE
    }
    this.moveTo = function(x, y, z) {
      // scope.target.set(x, y, z)
    }
    this.getState = function() {
      return {
        target: scope.target.clone(),
        position: scope.object.position.clone(),
        zoom: parseFloat(scope.object.zoom.toString())
      }
    }
  }
}
export {
  DmtControl
}
