import { AppObjectUC, Vector3 } from "@vived/core";
import { SceneRootEntity } from "../../SceneRoot/Entities/SceneRootEntity";
import { CalloutEntity } from "../Entities/CalloutEntity";
export class CalloutScaleHook extends AppObjectUC {
    get sceneRoot() {
        return this.getCachedSingleton(SceneRootEntity.type);
    }
    get callout() {
        return this.getCachedLocalComponent(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 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();
    }
}
CalloutScaleHook.type = "CalloutScaleHook";
//# sourceMappingURL=CalloutScaleHook.js.map