import { AppObjectPM } from "@vived/core";
import { LabelEntity } from "../Entities/LabelEntity";
export const defaultLabelVM = {
    customLabel: "",
    defaultLabel: "",
    displayLabel: "",
    hasCustomLabel: false,
    labelValidation: null,
};
export class LabelPM extends AppObjectPM {
    static getForID(appObjID, appObjects) {
        const appObj = appObjects.get(appObjID);
        if (appObj === undefined) {
            return undefined;
        }
        return appObj.getComponent(LabelPM.type);
    }
}
LabelPM.type = "LabelPM";
export function makeLabelPM(appObject) {
    return new LabelPMImp(appObject);
}
class LabelPMImp extends LabelPM {
    vmsAreEqual(a, b) {
        if (a.customLabel !== b.customLabel)
            return false;
        if (a.defaultLabel !== b.defaultLabel)
            return false;
        // Note the rest of the VM is derived from these two values
        return true;
    }
    constructor(appObject) {
        super(appObject, LabelPM.type);
        this.onLabelChange = () => {
            if (!this.label)
                return;
            const { custom: customLabel, display: displayLabel, hasCustomLabel, customLabelValidationMessage: labelValidation, default: defaultLabel, } = this.label;
            const vm = {
                customLabel,
                displayLabel,
                hasCustomLabel,
                labelValidation,
                defaultLabel,
            };
            this.doUpdateView(vm);
        };
        this.dispose = () => {
            super.dispose();
            this.label?.removeChangeObserver(this.onLabelChange);
            this.label?.removeOnDisposeObserver(this.dispose);
        };
        this.label = LabelEntity.get(appObject);
        if (this.label) {
            this.label.addChangeObserver(this.onLabelChange);
            this.label.addOnDisposeObserver(this.dispose);
            this.onLabelChange();
        }
        else {
            this.warn("App Object does not have a Label Entity");
        }
    }
}
//# sourceMappingURL=LabelPM.js.map