import { AppObjectController } from "@vived/core";
import { pixelToSceneRay } from "../../Babylon";
import { MouseInputEntity, } from "../../MouseInput";
import { TryAddNewLandmarkUC } from "../UseCases/TryAddNewLandmarkUC";
import { TryPreviewLandmarkUC } from "../UseCases/TryPreviewLandmarkUC";
export class MouseLandmark extends AppObjectController {
    constructor() {
        super(...arguments);
        this.addingLandmark = false;
        this.pressed = false;
    }
}
MouseLandmark.type = "Mouse_Landmark_Controller";
export function makeMouseLandmark(appObject) {
    return new MouseLandmarkImp(appObject);
}
class MouseLandmarkImp extends MouseLandmark {
    get tryPreviewLandmarkUc() {
        return this.getCachedSingleton(TryPreviewLandmarkUC.type);
    }
    get tryAddLandmarkUc() {
        return this.getCachedSingleton(TryAddNewLandmarkUC.type);
    }
    constructor(appObject) {
        super(appObject, MouseLandmark.type);
        this.addingLandmark = false;
        this.pressed = false;
        this.allow = (e) => {
            return true;
        };
        this.onMove = (e) => {
            if (!this.allow(e))
                return;
            if (!this.tryPreviewLandmarkUc) {
                return;
            }
            const ray = pixelToSceneRay(e.position, this.appObjects);
            this.tryPreviewLandmarkUc.tryPreviewLandmark(ray, this.pressed);
        };
        this.onDown = (e) => {
            this.addingLandmark = false;
            if (e.button !== 0)
                return;
            if (!this.allow(e))
                return;
            if (!this.tryPreviewLandmarkUc) {
                return;
            }
            const ray = pixelToSceneRay(e.position, this.appObjects);
            const pressed = true;
            this.tryPreviewLandmarkUc.tryPreviewLandmark(ray, pressed);
            this.addingLandmark = true;
            this.pressed = true;
        };
        this.onUp = (e) => {
            if (!this.allow(e))
                return;
            if (!this.addingLandmark)
                return;
            if (!this.tryAddLandmarkUc)
                return;
            if (!this.tryPreviewLandmarkUc)
                return;
            const ray = pixelToSceneRay(e.position, this.appObjects);
            this.tryAddLandmarkUc.addFromRay(ray);
            this.tryPreviewLandmarkUc.hidePreview();
            this.addingLandmark = false;
            this.pressed = false;
        };
        const mouseInput = MouseInputEntity.get(this.appObjects);
        if (mouseInput) {
            mouseInput.registerController(this);
        }
        else {
            this.warn("Unable to find MouseInputEntity");
        }
    }
}
//# sourceMappingURL=MouseLandmark.js.map