"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ShowSpinnerUC = void 0;
exports.makeShowSpinnerUC = makeShowSpinnerUC;
const core_1 = require("@vived/core");
const AppDispatcher_1 = require("../Entities/AppDispatcher");
class ShowSpinnerUC extends core_1.AppObjectUC {
    constructor() {
        super(...arguments);
        this.requestType = "SHOW_SPINNER";
    }
}
exports.ShowSpinnerUC = ShowSpinnerUC;
ShowSpinnerUC.type = "ShowSpinnerUC";
ShowSpinnerUC.get = (appObjects) => (0, core_1.getSingletonComponent)(ShowSpinnerUC.type, appObjects);
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_1.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