"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CheckZSpaceDisplaySizeImp = exports.CheckZSpaceDisplaySizeUC = void 0;
exports.makeCheckZSpaceDisplaySizeUC = makeCheckZSpaceDisplaySizeUC;
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const Transform3D_1 = require("../../Transform3D");
const Entities_1 = require("../Entities");
const DisplaySizeExtractor_1 = require("./DisplaySizeExtractor");
class CheckZSpaceDisplaySizeUC extends core_1.AppObjectUC {
}
exports.CheckZSpaceDisplaySizeUC = CheckZSpaceDisplaySizeUC;
CheckZSpaceDisplaySizeUC.type = "CheckZSpaceDisplaySizeUC";
function makeCheckZSpaceDisplaySizeUC(appObject) {
    return new CheckZSpaceDisplaySizeImp(appObject);
}
class CheckZSpaceDisplaySizeImp extends CheckZSpaceDisplaySizeUC {
    constructor(appObject) {
        super(appObject, CheckZSpaceDisplaySizeUC.type);
        this.checkDisplayFromXRSession = (xrSession) => {
            this.getDisplaySize(xrSession);
        };
        this.getDisplaySize = async (xrSession) => {
            const dse = new DisplaySizeExtractor_1.DisplaySizeExtractor(xrSession);
            const displaySize = await dse.QueryDisplaySize();
            this.checkDisplayFromSize(displaySize);
        };
        this.checkDisplayFromSize = (displaySize) => {
            const displayWidth = Math.round(displaySize.width * 1000) / 1000;
            if (displayWidth !== Entities_1.INSPIRE_WIDTH && this.zSpaceEntity) {
                const viewerScale = Entities_1.INSPIRE_WIDTH / displaySize.width;
                this.zSpaceEntity.viewerScale = viewerScale;
                this.zSpaceEntity.display.setForSize(displaySize.width, displaySize.height);
                const zSpaceTransform = Transform3D_1.Transform3D.get(this.zSpaceEntity.appObject);
                if (zSpaceTransform) {
                    zSpaceTransform.localScale = new core_2.Vector3(viewerScale, viewerScale, viewerScale);
                }
            }
        };
        this.zSpaceEntity = Entities_1.ZSpaceEntity.get(appObject.appObjectRepo);
        if (!this.zSpaceEntity) {
            console.warn("[EmulateDisplaySizeHook] Unable to find the zSpace Entity");
            return;
        }
    }
}
exports.CheckZSpaceDisplaySizeImp = CheckZSpaceDisplaySizeImp;
//# sourceMappingURL=CheckZSpaceDisplaySizeUC.js.map