"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MousePan = void 0;
const core_1 = require("@vived/core");
const MouseInput_1 = require("../../MouseInput");
const Tools_1 = require("../../Tools");
const PanSceneRoot_1 = require("../UC/PanSceneRoot");
class MousePan extends core_1.AppObjectController {
    get panRootUC() {
        return this.getCachedLocalComponent(PanSceneRoot_1.PanSceneRootUC.type);
    }
    get toolRepo() {
        return this.getCachedSingleton(Tools_1.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 === Tools_1.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 = MouseInput_1.MouseInputEntity.get(this.appObjects);
        if (mouseInput) {
            mouseInput.registerController(this);
        }
        else {
            this.warn("Unable to find MouseInputEntity");
        }
    }
}
exports.MousePan = MousePan;
MousePan.type = "MousePan";
//# sourceMappingURL=MousePan.js.map