import { AppObjectUC } from "@vived/core";
import { Vector3 } from "@vived/core";
import { Transform3D } from "../../Transform3D";
import { INSPIRE_WIDTH, ZSpaceEntity } from "../Entities";
import { DisplaySizeExtractor } from "./DisplaySizeExtractor";
export class CheckZSpaceDisplaySizeUC extends AppObjectUC {
}
CheckZSpaceDisplaySizeUC.type = "CheckZSpaceDisplaySizeUC";
export function makeCheckZSpaceDisplaySizeUC(appObject) {
    return new CheckZSpaceDisplaySizeImp(appObject);
}
export class CheckZSpaceDisplaySizeImp extends CheckZSpaceDisplaySizeUC {
    constructor(appObject) {
        super(appObject, CheckZSpaceDisplaySizeUC.type);
        this.checkDisplayFromXRSession = (xrSession) => {
            this.getDisplaySize(xrSession);
        };
        this.getDisplaySize = async (xrSession) => {
            const dse = new DisplaySizeExtractor(xrSession);
            const displaySize = await dse.QueryDisplaySize();
            this.checkDisplayFromSize(displaySize);
        };
        this.checkDisplayFromSize = (displaySize) => {
            const displayWidth = Math.round(displaySize.width * 1000) / 1000;
            if (displayWidth !== INSPIRE_WIDTH && this.zSpaceEntity) {
                const viewerScale = INSPIRE_WIDTH / displaySize.width;
                this.zSpaceEntity.viewerScale = viewerScale;
                this.zSpaceEntity.display.setForSize(displaySize.width, displaySize.height);
                const zSpaceTransform = Transform3D.get(this.zSpaceEntity.appObject);
                if (zSpaceTransform) {
                    zSpaceTransform.localScale = new Vector3(viewerScale, viewerScale, viewerScale);
                }
            }
        };
        this.zSpaceEntity = ZSpaceEntity.get(appObject.appObjectRepo);
        if (!this.zSpaceEntity) {
            console.warn("[EmulateDisplaySizeHook] Unable to find the zSpace Entity");
            return;
        }
    }
}
//# sourceMappingURL=CheckZSpaceDisplaySizeUC.js.map