"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TouchPanTransformTC = void 0;
const core_1 = require("@vived/core");
const TouchController_1 = require("../../../TouchController");
const TryPanTransformUC_1 = require("../../UC/TryPanTransformUC");
class TouchPanTransformTC extends core_1.AppObjectController {
    get tryScreenDragUC() {
        return this.getCachedLocalComponent(TryPanTransformUC_1.TryPanTransformUC.type);
    }
    constructor(appObject) {
        super(appObject, TouchPanTransformTC.type);
        this.allow = (e) => {
            if (e.touches.length !== 1)
                return false;
            return true;
        };
        this.isDragging = false;
        this.onTouchStart = (e) => {
            if (this.isDragging) {
                this.tryScreenDragUC?.cancel();
                this.isDragging = false;
            }
            if (!this.tryScreenDragUC)
                return;
            if (!this.allow(e))
                return;
            const position = e.touches[0].position;
            this.isDragging = this.tryScreenDragUC.tryWithPixel(position);
        };
        this.onTouchMove = (e) => {
            if (!this.tryScreenDragUC)
                return;
            if (!this.isDragging)
                return;
            const position = e.touches[0].position;
            this.tryScreenDragUC.moveWithPixel(position);
        };
        this.onTouchEnd = () => {
            if (!this.tryScreenDragUC)
                return;
            if (!this.isDragging)
                return;
            this.tryScreenDragUC.stop();
            this.isDragging = false;
        };
        const touchInput = TouchController_1.TouchInputEntity.get(this.appObjects);
        touchInput?.registerController(this);
    }
}
exports.TouchPanTransformTC = TouchPanTransformTC;
TouchPanTransformTC.type = "TouchPanTransformTC";
//# sourceMappingURL=TouchPanTransformTC.js.map