"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CalloutScaleHook = void 0;
const core_1 = require("@vived/core");
const SceneRootEntity_1 = require("../../SceneRoot/Entities/SceneRootEntity");
const CalloutEntity_1 = require("../Entities/CalloutEntity");
class CalloutScaleHook extends core_1.AppObjectUC {
    get sceneRoot() {
        return this.getCachedSingleton(SceneRootEntity_1.SceneRootEntity.type);
    }
    get callout() {
        return this.getCachedLocalComponent(CalloutEntity_1.CalloutEntity.type);
    }
    constructor(appObject) {
        super(appObject, CalloutScaleHook.type);
        this.onEntityChange = () => {
            if (!this.callout || !this.sceneRoot) {
                this.error("Missing Components");
                return;
            }
            const rootScale = this.sceneRoot.scale ?? 1;
            const calloutSize = this.callout.size;
            if (rootScale === this.lastRootScale &&
                calloutSize === this.lastCalloutSize) {
                return;
            }
            const scaler = calloutSize / rootScale;
            const labelScale = new core_1.Vector3(scaler, scaler, scaler);
            this.callout.labelTransform.localScale = labelScale;
            this.lastCalloutSize = calloutSize;
            this.lastRootScale = rootScale;
        };
        this.dispose = () => {
            this.sceneRoot?.removeChangeObserver(this.onEntityChange);
            this.callout?.removeChangeObserver(this.onEntityChange);
            super.dispose();
        };
        this.sceneRoot?.addChangeObserver(this.onEntityChange);
        this.callout?.addChangeObserver(this.onEntityChange);
        this.onEntityChange();
    }
}
exports.CalloutScaleHook = CalloutScaleHook;
CalloutScaleHook.type = "CalloutScaleHook";
//# sourceMappingURL=CalloutScaleHook.js.map