"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultScreenHoverLabelVM = exports.ScreenHoverLabelPM = void 0;
exports.makeScreenHoverLabelPM = makeScreenHoverLabelPM;
const core_1 = require("@vived/core");
const HoverLabelEntity_1 = require("../Entities/HoverLabelEntity");
class ScreenHoverLabelPM extends core_1.AppObjectPM {
    static get(appObjects) {
        return (0, core_1.getSingletonComponent)(ScreenHoverLabelPM.type, appObjects);
    }
}
exports.ScreenHoverLabelPM = ScreenHoverLabelPM;
ScreenHoverLabelPM.type = "ScreenHoverLabelPM";
function makeScreenHoverLabelPM(appObject) {
    return new ScreenHoverLabelPMImp(appObject);
}
class ScreenHoverLabelPMImp extends ScreenHoverLabelPM {
    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;
        if (a.screenPosition.x !== b.screenPosition.x ||
            a.screenPosition.y !== b.screenPosition.y)
            return false;
        return true;
    }
    constructor(appObject) {
        super(appObject, ScreenHoverLabelPM.type);
        this.onEntityChange = () => {
            if (!this.hoverLabelEntity)
                return;
            const vm = {
                show: false,
                text: "",
                screenPosition: { x: 0, y: 0 },
            };
            if (this.hoverLabelEntity.mode === HoverLabelEntity_1.HoverLabelMode.SCREEN &&
                this.hoverLabelEntity.show) {
                vm.show = true;
                vm.text = this.hoverLabelEntity.label;
                vm.screenPosition.x = this.hoverLabelEntity.pixelPosition.x;
                vm.screenPosition.y = this.hoverLabelEntity.pixelPosition.y;
            }
            this.doUpdateView(vm);
        };
        this.hoverLabelEntity?.addChangeObserver(this.onEntityChange);
        this.onEntityChange();
        this.appObjects.registerSingleton(this);
    }
}
exports.defaultScreenHoverLabelVM = {
    show: false,
    text: "",
    screenPosition: { x: 0, y: 0 },
};
//# sourceMappingURL=ScreenHoverLabelPM.js.map