import { AppObjectPM, getSingletonComponent, } from "@vived/core";
import { HoverLabelEntity, HoverLabelMode } from "../Entities/HoverLabelEntity";
export class ScreenHoverLabelPM extends AppObjectPM {
    static get(appObjects) {
        return getSingletonComponent(ScreenHoverLabelPM.type, appObjects);
    }
}
ScreenHoverLabelPM.type = "ScreenHoverLabelPM";
export function makeScreenHoverLabelPM(appObject) {
    return new ScreenHoverLabelPMImp(appObject);
}
class ScreenHoverLabelPMImp extends ScreenHoverLabelPM {
    get hoverLabelEntity() {
        return this.getCachedSingleton(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 === 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);
    }
}
export const defaultScreenHoverLabelVM = {
    show: false,
    text: "",
    screenPosition: { x: 0, y: 0 },
};
//# sourceMappingURL=ScreenHoverLabelPM.js.map