import { AppObjectUC } from "@vived/core";
import { SceneRayPickUC } from "../../Babylon";
import { StylusEntity } from "../../Stylus";
import { Transform3D } from "../Entities";
import { MoveTransformUC } from "./MoveTransformUC";
export class TryMoveTransformUC extends AppObjectUC {
}
TryMoveTransformUC.type = "TryMoveTransformUC";
export function makeTryMoveTransformUC(appObject) {
    return new TryMoveTransformUCImp(appObject);
}
export class TryMoveTransformUCImp extends TryMoveTransformUC {
    get rayPickUC() {
        return this.getCachedSingleton(SceneRayPickUC.type);
    }
    constructor(appObject) {
        super(appObject, TryMoveTransformUC.type);
        this.allow = () => {
            return true;
        };
        this.tryWithRay = (pickRay) => {
            this.moveUC = undefined;
            if (!this.allow())
                return false;
            const appObjectID = this.rayPickUC?.sceneRayPick(pickRay)?.appObjectID;
            if (!appObjectID)
                return false;
            this.moveUC = MoveTransformUC.get(appObjectID, this.appObjects);
            if (this.moveUC === undefined) {
                return false;
            }
            this.moveUC.initialize(this.helperTransform);
            return true;
        };
        this.moveWithRay = (pickRay) => {
            if (!this.moveUC)
                return;
            this.moveUC.update(this.helperTransform, pickRay);
        };
        this.stop = () => {
            if (!this.moveUC)
                return;
            this.moveUC.finish();
            this.moveUC = undefined;
        };
        this.cancel = () => {
            if (!this.moveUC)
                return;
            this.moveUC.cancel();
            this.moveUC = undefined;
        };
        const helperAO = this.appObjects.getOrCreate(this.appObject.id + "_helper");
        this.helperTransform = Transform3D.addIfMissing(helperAO);
        const stylus = StylusEntity.get(this.appObjects);
        if (!stylus) {
            this.error("Unable to find stylus");
        }
        else {
            this.helperTransform.parent = stylus.transform;
        }
    }
}
//# sourceMappingURL=TryMoveTransformUC.js.map