import { AppObjectController } from "@vived/core";
import { MouseInputEntity, } from "../../MouseInput";
import { ToolRepository, ToolState } from "../../Tools";
import { OrbitSceneRootUC } from "../UC/OrbitSceneRoot";
export class MouseOrbit extends AppObjectController {
    get orbitSceneRoot() {
        return this.getCachedLocalComponent(OrbitSceneRootUC.type);
    }
    get toolRepo() {
        return this.getCachedSingleton(ToolRepository.type);
    }
    constructor(appObject) {
        super(appObject, MouseOrbit.type);
        this.isOrbiting = false;
        this.allow = (e) => {
            const orbitTool = this.toolRepo?.getTool("ORBIT");
            if (!orbitTool)
                return false;
            const orbitToolIsActive = orbitTool.state === ToolState.ACTIVE;
            if (e.button === 0 && orbitToolIsActive) {
                return true;
            }
            else if (e.button === 2) {
                return true;
            }
            return false;
        };
        this.onDown = (e) => {
            this.isOrbiting = false;
            if (!this.orbitSceneRoot)
                return;
            if (!this.allow(e))
                return;
            const pixelPosition = e.position;
            this.orbitSceneRoot.initializeOrbit(pixelPosition);
            this.isOrbiting = true;
        };
        this.onMove = (e) => {
            if (!this.orbitSceneRoot)
                return;
            if (!this.isOrbiting)
                return;
            const currentPixelPos = e.position;
            this.orbitSceneRoot.doOrbit(currentPixelPos);
        };
        this.onUp = () => {
            if (!this.orbitSceneRoot)
                return;
            this.orbitSceneRoot.finishOrbit();
            this.isOrbiting = false;
        };
        const mouseInput = MouseInputEntity.get(this.appObjects);
        if (mouseInput) {
            mouseInput.registerController(this);
        }
        else {
            this.warn("Unable to find MouseInputEntity");
        }
    }
}
MouseOrbit.type = "MouseOrbit";
//# sourceMappingURL=MouseOrbit.js.map