import { AppObjectController } from "@vived/core";
import { ToolRepository, ToolState } from "../../Tools";
import { TouchInputEntity, } from "../../TouchController";
import { DragScaleSceneRootUC } from "../UC/DragScaleSceneRoot";
export class TouchScale extends AppObjectController {
    get dragScaleRootUC() {
        return this.getCachedLocalComponent(DragScaleSceneRootUC.type);
    }
    get toolRepo() {
        return this.getCachedSingleton(ToolRepository.type);
    }
    constructor(appObject) {
        super(appObject, TouchScale.type);
        this.isScaling = false;
        this.allow = (e) => {
            const zoomTool = this.toolRepo?.getTool("ZOOM");
            if (!zoomTool)
                return false;
            const zoomToolIsActive = zoomTool.state === ToolState.ACTIVE;
            if (e.touches.length === 1 && zoomToolIsActive) {
                return true;
            }
            return false;
        };
        this.onTouchStart = (e) => {
            this.isScaling = false;
            if (e.touches.length !== 1) {
                return;
            }
            if (!this.allow(e)) {
                return;
            }
            const pixelPosition = e.touches[0].position;
            this.dragScaleRootUC?.initializeScale(pixelPosition);
            this.isScaling = true;
        };
        this.onTouchMove = (e) => {
            if (!this.isScaling)
                return;
            if (e.touches.length !== 1)
                return;
            const pixelPosition = e.touches[0].position;
            this.dragScaleRootUC?.doScale(pixelPosition);
        };
        this.onTouchEnd = () => {
            this.isScaling = false;
            this.dragScaleRootUC?.finishScaling();
        };
        const appObjects = appObject.appObjectRepo;
        const touchInput = TouchInputEntity.get(appObjects);
        if (touchInput) {
            touchInput.registerController(this);
        }
        else {
            this.warn("Unable to find TouchInputEntity");
        }
    }
}
TouchScale.type = "TouchScale";
//# sourceMappingURL=TouchScale.js.map