import { AppObjectController } from "@vived/core";
import { TouchInputEntity } from "../../../TouchController";
import { PanTransformUC } from "../../UC";
export class PanTransformTC extends 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(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 = TouchInputEntity.get(appObjects);
        if (touchInput) {
            touchInput.registerController(this);
        }
        else {
            this.warn("Unable to find TouchInputEntity");
        }
    }
}
PanTransformTC.type = "PanTransformTC";
//# sourceMappingURL=PanTransformTC.js.map