import { AppObjectUC, getSingletonComponent, } from "@vived/core";
import { DispatchStateChangeUC } from "../../Dispatcher";
import { UndoRedoEntity } from "../../UndoRedo";
import { EnvironmentEntity } from "../Entities/Environment";
export class SetTexturalEnvironmentUC extends AppObjectUC {
    static get(appObjects) {
        return getSingletonComponent(SetTexturalEnvironmentUC.type, appObjects);
    }
}
SetTexturalEnvironmentUC.type = "SetTexturalEnvironmentUC";
export function makeSetTexturalEnvironmentUC(appObject) {
    return new SetTexturalEnvironmentUCImp(appObject);
}
class SetTexturalEnvironmentUCImp extends SetTexturalEnvironmentUC {
    get environment() {
        return this.getCachedSingleton(EnvironmentEntity.type);
    }
    get undo() {
        return this.getCachedSingleton(UndoRedoEntity.type);
    }
    get dispatchStateChange() {
        return this.getCachedSingleton(DispatchStateChangeUC.type)?.doDispatch;
    }
    constructor(appObject) {
        super(appObject, SetTexturalEnvironmentUC.type);
        this.setEnvironment = (env) => {
            const dispatchStateChange = this.dispatchStateChange;
            const environment = this.environment;
            if (!environment || !dispatchStateChange) {
                this.error("Missing component");
                return;
            }
            if (environment.currentEnvironment === env)
                return;
            const previousEnv = environment.currentEnvironment;
            environment.currentEnvironment = env;
            this.undo?.submitAction({
                undoAction: () => {
                    environment.currentEnvironment = previousEnv;
                    dispatchStateChange();
                },
                redoAction: () => {
                    environment.currentEnvironment = env;
                    dispatchStateChange();
                },
            });
            dispatchStateChange();
        };
        this.appObjects.registerSingleton(this);
    }
}
//# sourceMappingURL=SetTexturalEnvironmentUC.js.map