import { AppObjectUC, cubicInOut, getSingletonComponent, } from "@vived/core";
import { scenePixelPick } from "../../Babylon";
import { dispatchStateChange } from "../../Dispatcher";
import { SceneRootEntity } from "../Entities/SceneRootEntity";
export class CenterSceneRootOnPixelPickUC extends AppObjectUC {
}
CenterSceneRootOnPixelPickUC.type = "CenterSceneRootOnPixelPickUC";
CenterSceneRootOnPixelPickUC.get = (appObjects) => getSingletonComponent(CenterSceneRootOnPixelPickUC.type, appObjects);
export function makeCenterSceneRootOnPixelPickUC(appObject) {
    return new CenterSceneRootOnPixelPickImp(appObject);
}
class CenterSceneRootOnPixelPickImp extends CenterSceneRootOnPixelPickUC {
    constructor(appObject) {
        super(appObject, CenterSceneRootOnPixelPickUC.type);
        this.durationMS = 500;
        this.easeFn = cubicInOut;
        this.centerOnPixel = (pixel) => {
            if (!this.sceneRoot)
                return;
            const scenePick = scenePixelPick(pixel, this.appObjects);
            if (!scenePick?.worldPickPoint)
                return;
            this.sceneRoot.centerOnPoint(scenePick.worldPickPoint, this.durationMS, this.easeFn, () => this.onCenterCompleted());
        };
        this.onCenterCompleted = () => {
            dispatchStateChange(this.appObjects);
        };
        this.sceneRoot = appObject.getComponent(SceneRootEntity.type);
        if (!this.sceneRoot) {
            this.warn("BumpSceneRootScaleAboutPixelPointImp UC has been added to an App Object that does not have a SceneRoot Entity");
            return;
        }
    }
}
export function centerOnPixel(pixel, appObjects) {
    const uc = CenterSceneRootOnPixelPickUC.get(appObjects);
    if (!uc) {
        appObjects.submitWarning("centerOnPixel", "Unable to find CenterSceneRootOnPixelPickUC");
        return;
    }
    return uc.centerOnPixel(pixel);
}
//# sourceMappingURL=CenterSceneRootOnPixelPick.js.map