import { AppObjectUC } from "@vived/core";
import { dispatchStateChange } from "../../Dispatcher";
import { LabelEntity } from "../Entities";
import { SetCustomLabelUndoRedo } from "./SetCustomLabelUndoRedo";
export class SetCustomLabelUC extends AppObjectUC {
    get label() {
        return this.getCachedLocalComponent(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;
            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(prevLabel, this.label.custom, this.appObject);
                this.localCustomLabel = this.label.display;
            }
        };
        this.localCustomLabel = this.label?.display;
    }
    static get(appObj) {
        return appObj.getComponent(this.type);
    }
}
SetCustomLabelUC.type = "SetCustomLabelUC";
//# sourceMappingURL=SetCustomLabelUC.js.map