"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StopZSpaceUC = void 0;
exports.makeStopZSpaceUC = makeStopZSpaceUC;
const core_1 = require("@vived/core");
const Stylus_1 = require("../../Stylus");
const XR_1 = require("../../XR");
const zSpace_1 = require("../../zSpace");
const Entities_1 = require("../Entities");
class StopZSpaceUC extends core_1.AppObjectUC {
    constructor() {
        super(...arguments);
        this.requestType = "STOP_ZSPACE";
        this.payloadVersion = 1;
    }
}
exports.StopZSpaceUC = StopZSpaceUC;
StopZSpaceUC.type = "StopZSpaceBaseUC";
function makeStopZSpaceUC(appObject) {
    return new StopZSpaceUCImp(appObject);
}
class StopZSpaceUCImp extends StopZSpaceUC {
    constructor(appObject) {
        super(appObject, StopZSpaceUC.type);
        this.action = () => {
            const appObjects = this.appObject.appObjectRepo;
            const zSpaceEntity = zSpace_1.ZSpaceEntity.get(appObjects);
            if (zSpaceEntity) {
                zSpaceEntity.enabled = false;
                zSpaceEntity.emulate = false;
            }
            else {
                appObjects.submitError("stopZSpaceAction", "No zSpace Entity Found");
                return;
            }
            const renderUC = zSpaceEntity.appObject.getComponent(XR_1.RenderToXR.type);
            if (renderUC) {
                renderUC.stopRenderingXR();
            }
            else {
                appObjects.submitError("stopZSpaceAction", "No renderUC found");
                return;
            }
            const emulateStylus = Stylus_1.EmulateStylusUC.get(appObjects);
            if (emulateStylus) {
                emulateStylus.stopEmulating();
            }
            else {
                appObjects.submitWarning("stopZSpaceAction", "EmulateStylusUC not found");
                return;
            }
        };
        this.handleRequest = (version) => {
            if (version === this.payloadVersion) {
                this.action();
            }
            else {
                throw new Entities_1.UnsupportedRequestVersion(this.requestType, version);
            }
        };
        const handler = appObject.getComponent(Entities_1.AppHandlerEntity.type);
        if (!handler) {
            this.warn("StopZSpaceBaseUC has been added to an app object that does not have an AppHandlerEntity. Add one first");
            return;
        }
        handler.registerRequestHandler(this);
    }
}
//# sourceMappingURL=StopZSpaceUC.js.map