import { AppObjectUC } from "@vived/core";
import { dispatchStateChange } from "../../Dispatcher/UC/DispatchStateChangeUC";
import { CalloutEntity } from "../Entities/CalloutEntity";
import { CalloutGlobals } from "../Entities/CalloutGlobals";
import { SetCalloutSizeUndoRedo } from "./SetCalloutSizeUndoRedo";
export class SetCalloutSizeUC extends AppObjectUC {
    static get(appObj) {
        return appObj.getComponent(this.type);
    }
    static getById(id, appObjects) {
        return appObjects.get(id)?.getComponent(this.type);
    }
}
SetCalloutSizeUC.type = "SetCalloutSizeUC";
export function makeSetCalloutSizeUC(appObject) {
    return new SetCalloutSizeUCImp(appObject);
}
class SetCalloutSizeUCImp extends SetCalloutSizeUC {
    get callout() {
        return this.getCachedLocalComponent(CalloutEntity.type);
    }
    get calloutsGlobals() {
        return this.getCachedSingleton(CalloutGlobals.type);
    }
    updateSize(size) {
        if (!this.callout)
            return;
        if (!this.calloutsGlobals)
            return;
        if (this.initialValue === undefined) {
            this.initialValue = this.callout.size;
        }
        this.callout.size = size;
    }
    submitSize(size) {
        if (!this.initialValue)
            return;
        if (!this.callout)
            return;
        if (!this.calloutsGlobals)
            return;
        this.callout.size = size;
        this.calloutsGlobals.lastSize = size;
        if (this.initialValue && this.initialValue !== this.callout.size) {
            new SetCalloutSizeUndoRedo({
                callout: this.callout,
                redoSize: this.callout.size,
                undoSize: this.initialValue,
            }, this.appObjects);
            dispatchStateChange(this.appObjects);
        }
        this.initialValue = undefined;
    }
    constructor(appObject) {
        super(appObject, SetCalloutSizeUC.type);
    }
}
//# sourceMappingURL=SetCalloutSizeUC.js.map