import { AppObjectController } from "@vived/core";
import { pixelToSceneRay } from "../../Babylon";
import { MouseInputEntity, } from "../../MouseInput";
import { ZSpaceEntity } from "../../zSpace/Entities/ZSpaceEntity";
import { SelectAppObjectUC } from "../UC/SelectAppObjectUC";
export class MouseSelectAppObject extends AppObjectController {
    constructor(appObject) {
        super(appObject, MouseSelectAppObject.type);
        this.zSpaceEntity = undefined;
        this.allow = (e) => {
            return true;
        };
        this.onClick = (e) => {
            if (!this.selectUC) {
                return;
            }
            if (e.button !== 0) {
                return;
            }
            if (this.zSpaceEntity && this.zSpaceEntity.emulate)
                return;
            if (!this.allow(e))
                return;
            const ray = pixelToSceneRay(e.position, this.appObjects);
            this.selectUC.trySelectAppObject(ray);
        };
        this.zSpaceEntity = ZSpaceEntity.get(this.appObjects);
        this.selectUC = appObject.getComponent(SelectAppObjectUC.type);
        if (!this.selectUC) {
            console.warn("MouseSelect has been added to an App Object that does not have a SelectAppObjectUC. Add a SelectAppObjectUC before adding the Controller.");
            return;
        }
        const mouseInput = MouseInputEntity.get(this.appObjects);
        if (mouseInput) {
            mouseInput.registerController(this);
        }
        else {
            this.warn("Unable to find MouseInputEntity");
        }
    }
}
MouseSelectAppObject.type = "MouseSelectAppObject";
//# sourceMappingURL=MouseSelectAppObject.js.map