import { AppObjectUC, getSingletonComponent, } from "@vived/core";
import { AppDispatcher } from "../Entities/AppDispatcher";
export class HasPreviousStateUC extends AppObjectUC {
    constructor() {
        super(...arguments);
        this.requestType = "HAS_PREVIOUS_STATE";
    }
}
HasPreviousStateUC.type = "HasPreviousStateUC";
HasPreviousStateUC.get = (appObjects) => getSingletonComponent(HasPreviousStateUC.type, appObjects);
export function makeHasPreviousStateUC(appObject) {
    return new DispatchStateChangeUCImp(appObject);
}
class DispatchStateChangeUCImp extends HasPreviousStateUC {
    constructor(appObject) {
        super(appObject, HasPreviousStateUC.type);
        this.requestVersion = 1;
        this.doDispatch = () => {
            return new Promise((resolve, reject) => {
                const callback = (hasNextState) => {
                    resolve(hasNextState);
                };
                const payload = {
                    callback,
                };
                if (!this.appDispatcher)
                    return reject(new Error("No host handler has been registered"));
                else {
                    this.appDispatcher.formRequestAndDispatch(this.requestType, this.requestVersion, payload);
                }
            });
        };
        this.appDispatcher = appObject.getComponent(AppDispatcher.type);
        if (!this.appDispatcher) {
            console.warn("HasPreviousStateUC has been added to an App Object that does not have a AppDispatcher. Add a dispatcher first");
            this.dispose();
        }
    }
}
//# sourceMappingURL=HasPreviousStateUC.js.map