"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultWorldHoverLabelVM = exports.WorldHoverLabelPM = void 0;
exports.makeWorldHoverLabelPM = makeWorldHoverLabelPM;
const core_1 = require("@vived/core");
const HoverLabelEntity_1 = require("../Entities/HoverLabelEntity");
class WorldHoverLabelPM extends core_1.AppObjectPM {
    static get(appObjects) {
        return (0, core_1.getSingletonComponent)(WorldHoverLabelPM.type, appObjects);
    }
}
exports.WorldHoverLabelPM = WorldHoverLabelPM;
WorldHoverLabelPM.type = "WorldHoverLabelPM";
function makeWorldHoverLabelPM(appObject) {
    return new WorldHoverLabelPMImp(appObject);
}
class WorldHoverLabelPMImp extends WorldHoverLabelPM {
    get hoverLabelEntity() {
        return this.getCachedSingleton(HoverLabelEntity_1.HoverLabelEntity.type);
    }
    vmsAreEqual(a, b) {
        if (a.show !== b.show)
            return false;
        if (a.text !== b.text)
            return false;
        return true;
    }
    constructor(appObject) {
        super(appObject, WorldHoverLabelPM.type);
        this.onEntityChange = () => {
            if (!this.hoverLabelEntity)
                return;
            const vm = {
                show: false,
                text: "",
            };
            if (this.hoverLabelEntity.mode === HoverLabelEntity_1.HoverLabelMode.WORLD &&
                this.hoverLabelEntity.show) {
                vm.show = true;
                vm.text = this.hoverLabelEntity.label;
            }
            this.doUpdateView(vm);
        };
        this.hoverLabelEntity?.addChangeObserver(this.onEntityChange);
        this.onEntityChange();
        this.appObjects.registerSingleton(this);
    }
}
exports.defaultWorldHoverLabelVM = {
    show: false,
    text: "",
};
//# sourceMappingURL=WorldHoverLabelPM.js.map