import { AppObjectUC } from "@vived/core";
import { PixelToSceneRayUC, SceneRayPickUC } from "../../Babylon";
import { PanTransformUC } from "./PanTransformUC";
export class TryPanTransformUC extends AppObjectUC {
}
TryPanTransformUC.type = "TryPanTransformUC";
export function makeTryPanTransformUC(appObject) {
    return new TryPanTransformUCImp(appObject);
}
export class TryPanTransformUCImp extends TryPanTransformUC {
    get pixelToRay() {
        return this.getCachedSingleton(PixelToSceneRayUC.type)
            ?.pixelToSceneRay;
    }
    get rayPickUC() {
        return this.getCachedSingleton(SceneRayPickUC.type);
    }
    constructor(appObject) {
        super(appObject, TryPanTransformUC.type);
        this.allow = () => {
            return true;
        };
        this.tryWithPixel = (pixel) => {
            if (!this.pixelToRay) {
                return false;
            }
            const ray = this.pixelToRay(pixel);
            return this.tryWithRay(ray);
        };
        this.moveWithPixel = (pixel) => {
            if (!this.pixelToRay) {
                return;
            }
            const ray = this.pixelToRay(pixel);
            return this.moveWithRay(ray);
        };
        this.tryWithRay = (pickRay) => {
            this.panUC = undefined;
            if (!this.allow())
                return false;
            const scenePick = this.rayPickUC?.sceneRayPick(pickRay);
            if (!scenePick || !scenePick.worldPickPoint)
                return false;
            const appObjectID = scenePick.appObjectID;
            if (!appObjectID)
                return false;
            this.panUC = PanTransformUC.get(appObjectID, this.appObjects);
            if (this.panUC === undefined) {
                return false;
            }
            this.panUC.initializeRay(pickRay);
            return true;
        };
        this.moveWithRay = (pickRay) => {
            if (!this.panUC)
                return;
            this.panUC.updateRay(pickRay);
        };
        this.stop = () => {
            if (!this.panUC)
                return;
            this.panUC.finish();
            this.panUC = undefined;
        };
        this.cancel = () => {
            if (!this.panUC)
                return;
            this.panUC.cancelPan();
            this.panUC = undefined;
        };
    }
}
//# sourceMappingURL=TryPanTransformUC.js.map