import { AppObjectController } from "@vived/core";
import { Vector2 } from "@vived/core";
import { TouchInputEntity, } from "../../TouchController";
import { PinchSceneRootUC } from "../UC/PinchSceneRoot";
export class TouchPinch extends AppObjectController {
    get pinchRootUC() {
        return this.getCachedLocalComponent(PinchSceneRootUC.type);
    }
    constructor(appObject) {
        super(appObject, TouchPinch.type);
        this.isPinching = false;
        this.PAN_FINGER_DISTANCE_PX = 80;
        this.allow = (e) => {
            if (e.touches.length === 2) {
                const dist = Vector2.Subtract(e.touches[0].position, e.touches[1].position).magnitued;
                if (dist > this.PAN_FINGER_DISTANCE_PX) {
                    return true;
                }
            }
            return false;
        };
        this.onTouchStart = (e) => {
            this.isPinching = false;
            if (e.touches.length !== 2) {
                return;
            }
            if (!this.allow(e)) {
                return;
            }
            this.pinchRootUC?.initializePinch(e.touches[0].position, e.touches[1].position);
            this.isPinching = true;
        };
        this.onTouchMove = (e) => {
            if (!this.isPinching)
                return;
            if (e.touches.length !== 2)
                return;
            this.pinchRootUC?.doPinch(e.touches[0].position, e.touches[1].position);
        };
        this.onTouchEnd = () => {
            this.isPinching = false;
            this.pinchRootUC?.finishPinch();
        };
        const appObjects = appObject.appObjectRepo;
        const touchInput = TouchInputEntity.get(appObjects);
        if (touchInput) {
            touchInput.registerController(this);
        }
        else {
            this.warn("Unable to find TouchInputEntity");
        }
    }
}
TouchPinch.type = "TouchPinch";
//# sourceMappingURL=TouchPinch.js.map