import { AppObjectUC, getSingletonComponent, } from "@vived/core";
import { BabylonRenderingUC } from "../../Babylon";
import { KeyboardInputEntity } from "../../KeyboardInput";
import { TouchInputEntity } from "../../TouchController";
import { MouseInputEntity } from "../../MouseInput";
export class RenderCanvasUC extends AppObjectUC {
}
RenderCanvasUC.type = "RenderCanvasUC";
RenderCanvasUC.get = (appObjects) => getSingletonComponent(RenderCanvasUC.type, appObjects);
export function makeRenderCanvasUC(appObject) {
    return new RenderCanvasUCImp(appObject);
}
class RenderCanvasUCImp extends RenderCanvasUC {
    submitCanvas(canvas) {
        const appObjects = this.appObject.appObjectRepo;
        const keyboardInput = KeyboardInputEntity.get(appObjects);
        if (keyboardInput) {
            keyboardInput.setEventElement(canvas);
        }
        else {
            this.warn("Unable to find KeyboardInputEntity");
        }
        const touchInput = TouchInputEntity.get(appObjects);
        if (touchInput) {
            touchInput.setEventElement(canvas);
        }
        else {
            this.warn("Unable to find TouchInputEntity");
        }
        const mouseInput = MouseInputEntity.get(appObjects);
        if (mouseInput) {
            mouseInput.setEventElement(canvas);
        }
        else {
            this.warn("Unable to find MouseInputEntity");
        }
        const babylonRendering = BabylonRenderingUC.get(appObjects);
        if (babylonRendering) {
            babylonRendering.submitRenderCanvas(canvas);
        }
        else {
            this.warn("Unable to find BabylonRenderingUC");
        }
        canvas.addEventListener("contextmenu", (e) => {
            e.preventDefault();
        }, false);
    }
    clearCanvas() {
        const appObjects = this.appObject.appObjectRepo;
        const keyboardInput = KeyboardInputEntity.get(appObjects);
        if (keyboardInput) {
            keyboardInput.clearInputElement();
        }
        else {
            this.warn("Unable to find KeyboardInputEntity");
        }
        const touchInput = TouchInputEntity.get(appObjects);
        if (touchInput) {
            touchInput.clearInputElement();
        }
        else {
            this.warn("Unable to find TouchInputEntity");
        }
        const mouseInput = MouseInputEntity.get(appObjects);
        if (mouseInput) {
            mouseInput.clearInputElement();
        }
        else {
            this.warn("Unable to find MouseInputEntity");
        }
        const babylonRendering = BabylonRenderingUC.get(appObjects);
        if (babylonRendering) {
            babylonRendering.clearRenderCanvas();
        }
        else {
            this.warn("Unable to find BabylonRenderingUC");
        }
    }
    constructor(appObject) {
        super(appObject, RenderCanvasUC.type);
    }
}
//# sourceMappingURL=RenderCanvasUC.js.map