import { AppObjectController } from "@vived/core";
import { MouseInputEntity, } from "../../MouseInput";
import { ToolRepository, ToolState } from "../../Tools";
import { PanSceneRootUC } from "../UC/PanSceneRoot";
export class MousePan extends AppObjectController {
    get panRootUC() {
        return this.getCachedLocalComponent(PanSceneRootUC.type);
    }
    get toolRepo() {
        return this.getCachedSingleton(ToolRepository.type);
    }
    constructor(appObject) {
        super(appObject, MousePan.type);
        this.doPan = false;
        this.allow = (e) => {
            const panTool = this.toolRepo?.getTool("PAN");
            if (!panTool)
                return false;
            const panToolIsActive = panTool.state === ToolState.ACTIVE;
            if (e.button === 0 && panToolIsActive) {
                return true;
            }
            else if (e.button === 1) {
                return true;
            }
            return false;
        };
        this.onDown = (e) => {
            this.doPan = false;
            if (!this.allow(e))
                return;
            this.panRootUC?.initializePan(e.position);
            this.doPan = true;
        };
        this.onMove = (e) => {
            if (!this.doPan)
                return;
            this.panRootUC?.doPan(e.position);
        };
        this.onUp = () => {
            this.doPan = false;
            this.panRootUC?.finishPan();
        };
        const mouseInput = MouseInputEntity.get(this.appObjects);
        if (mouseInput) {
            mouseInput.registerController(this);
        }
        else {
            this.warn("Unable to find MouseInputEntity");
        }
    }
}
MousePan.type = "MousePan";
//# sourceMappingURL=MousePan.js.map