import { AppObjectUC } from "@vived/core";
import { dispatchStateChange } from "../../Dispatcher";
import { LandmarkEntity } from "../Entities/LandmarkEntity";
import { LandmarkGlobals } from "../Entities/LandmarkGlobals";
import { SetLandmarkSizeUndoRedo } from "./SetLandmarkSizeUndoRedo";
export class SetLandmarkSizeUC extends AppObjectUC {
    static get(appObj) {
        return appObj.getComponent(this.type);
    }
    static getById(id, appObjects) {
        return appObjects.get(id)?.getComponent(this.type);
    }
}
SetLandmarkSizeUC.type = "SetLandmarkSizeUC";
export function makeSetLandmarkSizeUC(appObject) {
    return new SetLandmarkSizeUCImp(appObject);
}
class SetLandmarkSizeUCImp extends SetLandmarkSizeUC {
    get landmark() {
        return this.getCachedLocalComponent(LandmarkEntity.type);
    }
    get landmarkGlobals() {
        return this.getCachedSingleton(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({
                landmark: this.landmark,
                redoSize: this.landmark.size,
                undoSize: this.initialValue,
            }, this.appObjects);
            dispatchStateChange(this.appObjects);
        }
        this.initialValue = undefined;
    }
    constructor(appObject) {
        super(appObject, SetLandmarkSizeUC.type);
    }
}
//# sourceMappingURL=SetLandmarkSizeUC.js.map