"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SetCustomLabelUC = void 0;
const core_1 = require("@vived/core");
const Dispatcher_1 = require("../../Dispatcher");
const Entities_1 = require("../Entities");
const SetCustomLabelUndoRedo_1 = require("./SetCustomLabelUndoRedo");
class SetCustomLabelUC extends core_1.AppObjectUC {
    get label() {
        return this.getCachedLocalComponent(Entities_1.LabelEntity.type);
    }
    constructor(appObject) {
        super(appObject, SetCustomLabelUC.type);
        this.update = (customLabel) => {
            if (!this.label) {
                this.warn("[SetCustomLabelUC] Unable to get Entity");
                return;
            }
            this.label.custom = customLabel;
            (0, Dispatcher_1.dispatchStateChange)(this.appObjects);
        };
        this.submit = () => {
            if (!this.label) {
                this.warn("[SetCustomLabelUC] Unable to get Entity");
                return;
            }
            if (this.localCustomLabel !== undefined) {
                const prevLabel = this.localCustomLabel;
                new SetCustomLabelUndoRedo_1.SetCustomLabelUndoRedo(prevLabel, this.label.custom, this.appObject);
                this.localCustomLabel = this.label.display;
            }
        };
        this.localCustomLabel = this.label?.display;
    }
    static get(appObj) {
        return appObj.getComponent(this.type);
    }
}
exports.SetCustomLabelUC = SetCustomLabelUC;
SetCustomLabelUC.type = "SetCustomLabelUC";
//# sourceMappingURL=SetCustomLabelUC.js.map