"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MousePanTransformMC = void 0;
const core_1 = require("@vived/core");
const MouseInput_1 = require("../../../MouseInput");
const TryPanTransformUC_1 = require("../../UC/TryPanTransformUC");
class MousePanTransformMC extends core_1.AppObjectController {
    get mouseInput() {
        return this.getCachedSingleton(MouseInput_1.MouseInputEntity.type);
    }
    get tryScreenDragUC() {
        return this.getCachedLocalComponent(TryPanTransformUC_1.TryPanTransformUC.type);
    }
    constructor(appObject) {
        super(appObject, MousePanTransformMC.type);
        this.allow = (e) => {
            if (e.button !== 0)
                return false;
            return true;
        };
        this.isDragging = false;
        this.onDown = (e) => {
            if (this.isDragging) {
                this.tryScreenDragUC?.cancel();
                this.isDragging = false;
            }
            if (!this.allow(e)) {
                return;
            }
            this.isDragging = this.tryScreenDragUC?.tryWithPixel(e.position) ?? false;
        };
        this.onMove = (e) => {
            if (!this.isDragging)
                return;
            this.tryScreenDragUC?.moveWithPixel(e.position);
        };
        this.onUp = () => {
            if (!this.isDragging)
                return;
            this.tryScreenDragUC?.stop();
            this.isDragging = false;
        };
        this.mouseInput?.registerController(this);
    }
}
exports.MousePanTransformMC = MousePanTransformMC;
MousePanTransformMC.type = "MousePanTransformMC";
//# sourceMappingURL=MousePanTransformMC.js.map