"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HoverLabelEntity = exports.HoverLabelMode = void 0;
exports.makeHoverLabelEntity = makeHoverLabelEntity;
const core_1 = require("@vived/core");
const Transform3D_1 = require("../../Transform3D");
var HoverLabelMode;
(function (HoverLabelMode) {
    HoverLabelMode[HoverLabelMode["NONE"] = 0] = "NONE";
    HoverLabelMode[HoverLabelMode["SCREEN"] = 1] = "SCREEN";
    HoverLabelMode[HoverLabelMode["WORLD"] = 2] = "WORLD";
})(HoverLabelMode || (exports.HoverLabelMode = HoverLabelMode = {}));
class HoverLabelEntity extends core_1.AppObjectEntity {
    static get(appObjects) {
        return (0, core_1.getSingletonComponent)(HoverLabelEntity.type, appObjects);
    }
}
exports.HoverLabelEntity = HoverLabelEntity;
HoverLabelEntity.type = "HoverLabelEntity";
function makeHoverLabelEntity(appObject) {
    Transform3D_1.Transform3D.addIfMissing(appObject);
    return new HoverLabelEntityImp(appObject);
}
class HoverLabelEntityImp extends HoverLabelEntity {
    get mode() {
        return this._mode;
    }
    get pixelPosition() {
        return this._pixelPosition;
    }
    get show() {
        return this._show;
    }
    get label() {
        return this._label;
    }
    get allowHoverLabel() {
        return this.memoizedAllow.val;
    }
    set allowHoverLabel(allow) {
        if (allow === this.memoizedAllow.val) {
            return;
        }
        this.memoizedAllow.val = allow;
        if (allow === false) {
            this.hideHoverLabel();
        }
    }
    constructor(appObject) {
        super(appObject, HoverLabelEntity.type);
        this._mode = HoverLabelMode.NONE;
        this._pixelPosition = core_1.Vector2.Zero();
        this._show = false;
        this._label = "";
        this.memoizedAllow = new core_1.MemoizedBoolean(true, this.notifyOnChange);
        this.showScreenHoverLabel = (label, pixelPosition) => {
            if (!this.allowHoverLabel) {
                return;
            }
            if (this.mode === HoverLabelMode.SCREEN &&
                label === this._label &&
                core_1.Vector2.Equal(pixelPosition, this._pixelPosition) &&
                this.show) {
                return;
            }
            this._label = label;
            this._pixelPosition = pixelPosition;
            this._show = true;
            this._mode = HoverLabelMode.SCREEN;
            this.notifyOnChange();
        };
        this.showWorldHoverLabel = (label, worldPosition) => {
            if (!this.allowHoverLabel) {
                return;
            }
            if (this.mode === HoverLabelMode.WORLD &&
                label === this._label &&
                core_1.Vector3.Equal(worldPosition, this.transform.worldPosition) &&
                this.show) {
                return;
            }
            this._label = label;
            this.transform.worldPosition = worldPosition;
            this._show = true;
            this._mode = HoverLabelMode.WORLD;
            this.notifyOnChange();
        };
        this.hideHoverLabel = () => {
            if (!this._show)
                return;
            this._show = false;
            this._label = "";
            this._pixelPosition = core_1.Vector2.Zero();
            this.transform.localPosition = core_1.Vector3.Zero();
            this._mode = HoverLabelMode.NONE;
            this.notifyOnChange();
        };
        this.transform = Transform3D_1.Transform3D.addIfMissing(appObject);
    }
}
//# sourceMappingURL=HoverLabelEntity.js.map