import { AppObjectUC, cubicInOut, getSingletonComponent, } from "@vived/core";
import { scenePixelPick } from "../../Babylon";
import { dispatchStateChange } from "../../Dispatcher";
import { SceneRootEntity } from "../Entities/SceneRootEntity";
export class FocusOnPixelUC extends AppObjectUC {
}
FocusOnPixelUC.type = "FocusOnPixelUC";
FocusOnPixelUC.get = (appObjects) => getSingletonComponent(FocusOnPixelUC.type, appObjects);
export function makeFocusOnPixelUC(appObject) {
    return new FocusOnPixelImp(appObject);
}
class FocusOnPixelImp extends FocusOnPixelUC {
    constructor(appObject) {
        super(appObject, FocusOnPixelUC.type);
        this.durationMS = 500;
        this.easeFn = cubicInOut;
        this.centerOnPixel = (pixel) => {
            if (!this.sceneRoot)
                return;
            const scenePick = scenePixelPick(pixel, this.appObjects);
            if (scenePick?.worldPickPoint) {
                this.sceneRoot.centerOnPoint(scenePick.worldPickPoint, this.durationMS, this.easeFn, () => this.onCenterCompleted());
            }
            else {
                this.sceneRoot.lerpToDefault(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;
        }
    }
}
//# sourceMappingURL=FocusOnPixel.js.map