"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SetCalloutSizeUC = void 0;
exports.makeSetCalloutSizeUC = makeSetCalloutSizeUC;
const core_1 = require("@vived/core");
const DispatchStateChangeUC_1 = require("../../Dispatcher/UC/DispatchStateChangeUC");
const CalloutEntity_1 = require("../Entities/CalloutEntity");
const CalloutGlobals_1 = require("../Entities/CalloutGlobals");
const SetCalloutSizeUndoRedo_1 = require("./SetCalloutSizeUndoRedo");
class SetCalloutSizeUC extends core_1.AppObjectUC {
    static get(appObj) {
        return appObj.getComponent(this.type);
    }
    static getById(id, appObjects) {
        return appObjects.get(id)?.getComponent(this.type);
    }
}
exports.SetCalloutSizeUC = SetCalloutSizeUC;
SetCalloutSizeUC.type = "SetCalloutSizeUC";
function makeSetCalloutSizeUC(appObject) {
    return new SetCalloutSizeUCImp(appObject);
}
class SetCalloutSizeUCImp extends SetCalloutSizeUC {
    get callout() {
        return this.getCachedLocalComponent(CalloutEntity_1.CalloutEntity.type);
    }
    get calloutsGlobals() {
        return this.getCachedSingleton(CalloutGlobals_1.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_1.SetCalloutSizeUndoRedo({
                callout: this.callout,
                redoSize: this.callout.size,
                undoSize: this.initialValue,
            }, this.appObjects);
            (0, DispatchStateChangeUC_1.dispatchStateChange)(this.appObjects);
        }
        this.initialValue = undefined;
    }
    constructor(appObject) {
        super(appObject, SetCalloutSizeUC.type);
    }
}
//# sourceMappingURL=SetCalloutSizeUC.js.map