"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SetLandmarkSizeUC = void 0;
exports.makeSetLandmarkSizeUC = makeSetLandmarkSizeUC;
const core_1 = require("@vived/core");
const Dispatcher_1 = require("../../Dispatcher");
const LandmarkEntity_1 = require("../Entities/LandmarkEntity");
const LandmarkGlobals_1 = require("../Entities/LandmarkGlobals");
const SetLandmarkSizeUndoRedo_1 = require("./SetLandmarkSizeUndoRedo");
class SetLandmarkSizeUC extends core_1.AppObjectUC {
    static get(appObj) {
        return appObj.getComponent(this.type);
    }
    static getById(id, appObjects) {
        return appObjects.get(id)?.getComponent(this.type);
    }
}
exports.SetLandmarkSizeUC = SetLandmarkSizeUC;
SetLandmarkSizeUC.type = "SetLandmarkSizeUC";
function makeSetLandmarkSizeUC(appObject) {
    return new SetLandmarkSizeUCImp(appObject);
}
class SetLandmarkSizeUCImp extends SetLandmarkSizeUC {
    get landmark() {
        return this.getCachedLocalComponent(LandmarkEntity_1.LandmarkEntity.type);
    }
    get landmarkGlobals() {
        return this.getCachedSingleton(LandmarkGlobals_1.LandmarkGlobals.type);
    }
    updateSize(size) {
        if (!this.landmark)
            return;
        if (!this.landmarkGlobals)
            return;
        if (this.initialValue === undefined) {
            this.initialValue = this.landmark.size;
        }
        this.landmark.size = size;
    }
    submitSize(size) {
        if (this.initialValue === undefined)
            return;
        if (!this.landmark)
            return;
        if (!this.landmarkGlobals)
            return;
        this.landmark.size = size;
        this.landmarkGlobals.lastSize = size;
        if (this.initialValue !== undefined &&
            this.initialValue !== this.landmark.size) {
            new SetLandmarkSizeUndoRedo_1.SetLandmarkSizeUndoRedo({
                landmark: this.landmark,
                redoSize: this.landmark.size,
                undoSize: this.initialValue,
            }, this.appObjects);
            (0, Dispatcher_1.dispatchStateChange)(this.appObjects);
        }
        this.initialValue = undefined;
    }
    constructor(appObject) {
        super(appObject, SetLandmarkSizeUC.type);
    }
}
//# sourceMappingURL=SetLandmarkSizeUC.js.map