import { AppObjectController } from "@vived/core";
import { TouchInputEntity } from "../../../TouchController";
import { TryPanTransformUC } from "../../UC/TryPanTransformUC";
export class TouchPanTransformTC extends AppObjectController {
    get tryScreenDragUC() {
        return this.getCachedLocalComponent(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 = TouchInputEntity.get(this.appObjects);
        touchInput?.registerController(this);
    }
}
TouchPanTransformTC.type = "TouchPanTransformTC";
//# sourceMappingURL=TouchPanTransformTC.js.map