"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TouchScale = void 0;
const core_1 = require("@vived/core");
const Tools_1 = require("../../Tools");
const TouchController_1 = require("../../TouchController");
const DragScaleSceneRoot_1 = require("../UC/DragScaleSceneRoot");
class TouchScale extends core_1.AppObjectController {
    get dragScaleRootUC() {
        return this.getCachedLocalComponent(DragScaleSceneRoot_1.DragScaleSceneRootUC.type);
    }
    get toolRepo() {
        return this.getCachedSingleton(Tools_1.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 === Tools_1.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 = TouchController_1.TouchInputEntity.get(appObjects);
        if (touchInput) {
            touchInput.registerController(this);
        }
        else {
            this.warn("Unable to find TouchInputEntity");
        }
    }
}
exports.TouchScale = TouchScale;
TouchScale.type = "TouchScale";
//# sourceMappingURL=TouchScale.js.map