"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PanTransformTC = void 0;
const core_1 = require("@vived/core");
const TouchController_1 = require("../../../TouchController");
const UC_1 = require("../../UC");
class PanTransformTC extends core_1.AppObjectController {
    constructor(appObject) {
        super(appObject, PanTransformTC.type);
        this.isPanning = false;
        this.allow = (e) => {
            return true;
        };
        this.onTouchStart = (e) => {
            if (!this.allow(e)) {
                this.isPanning = false;
                this.panUC?.cancelPan();
                return;
            }
            this.panUC?.initializePixel(e.touchCenter);
            this.isPanning = true;
        };
        this.onTouchMove = (e) => {
            if (!this.isPanning)
                return;
            const pixelPosition = e.touches[0].position;
            this.panUC?.updatePixel(pixelPosition);
        };
        this.onTouchEnd = (e) => {
            this.isPanning = false;
            this.panUC?.finish();
        };
        const appObjects = appObject.appObjectRepo;
        this.panUC = appObject.getComponent(UC_1.PanTransformUC.type);
        if (!this.panUC) {
            this.warn("Controller has been added to an App Object that does not have PanTransformUC. Add one first.");
            return;
        }
        const touchInput = TouchController_1.TouchInputEntity.get(appObjects);
        if (touchInput) {
            touchInput.registerController(this);
        }
        else {
            this.warn("Unable to find TouchInputEntity");
        }
    }
}
exports.PanTransformTC = PanTransformTC;
PanTransformTC.type = "PanTransformTC";
//# sourceMappingURL=PanTransformTC.js.map