import { AppObjectUC, getSingletonComponent, } from "@vived/core";
import { AppDispatcher } from "../Entities/AppDispatcher";
export class ShowSpinnerUC extends AppObjectUC {
    constructor() {
        super(...arguments);
        this.requestType = "SHOW_SPINNER";
    }
}
ShowSpinnerUC.type = "ShowSpinnerUC";
ShowSpinnerUC.get = (appObjects) => getSingletonComponent(ShowSpinnerUC.type, appObjects);
export function makeShowSpinnerUC(appObject) {
    return new ShowSpinnerUCImp(appObject);
}
class ShowSpinnerUCImp extends ShowSpinnerUC {
    constructor(appObject) {
        super(appObject, ShowSpinnerUC.type);
        this.requestVersion = 1;
        this.showSpinner = (title, message) => {
            return new Promise((resolve, reject) => {
                const closeCallback = (closeSpinner) => {
                    resolve(closeSpinner);
                };
                const payload = {
                    message,
                    title,
                    closeCallback,
                };
                if (!this.appDispatcher) {
                    reject(new Error("No App Dispatcher"));
                }
                else {
                    this.appDispatcher.formRequestAndDispatch(this.requestType, this.requestVersion, payload);
                }
            });
        };
        this.appDispatcher = appObject.getComponent(AppDispatcher.type);
        if (!this.appDispatcher) {
            this.warn(`${ShowSpinnerUC.type} has been added to an App Object that does not have a AppDispatcher. Add a dispatcher first`);
            this.dispose();
        }
    }
}
//# sourceMappingURL=ShowSpinnerUC.js.map