"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AppIsReadyUC = void 0;
exports.makeAppIsReadyUC = makeAppIsReadyUC;
exports.appIsReady = appIsReady;
const core_1 = require("@vived/core");
const AppDispatcher_1 = require("../Entities/AppDispatcher");
class AppIsReadyUC extends core_1.AppObjectUC {
    constructor() {
        super(...arguments);
        this.requestType = "APP_IS_READY";
    }
}
exports.AppIsReadyUC = AppIsReadyUC;
AppIsReadyUC.type = "AppIsReadyUC";
AppIsReadyUC.get = (appObjects) => (0, core_1.getSingletonComponent)(AppIsReadyUC.type, appObjects);
function makeAppIsReadyUC(appObject) {
    return new AppIsReadyUCImp(appObject);
}
function appIsReady(appObjects) {
    const dispatchUC = AppIsReadyUC.get(appObjects);
    if (dispatchUC) {
        dispatchUC.doDispatch();
    }
    else {
        appObjects.submitWarning("appIsReady", "Can't find AppIsReadyUC");
    }
}
class AppIsReadyUCImp extends AppIsReadyUC {
    constructor(appObject) {
        super(appObject, AppIsReadyUC.type);
        this.requestVersion = 1;
        this.doDispatch = () => {
            if (!this.appDispatcher)
                return;
            this.appDispatcher.formRequestAndDispatch(this.requestType, this.requestVersion);
        };
        this.appDispatcher = appObject.getComponent(AppDispatcher_1.AppDispatcher.type);
        if (!this.appDispatcher) {
            this.warn("AppIsReadyUCImp has been added to an App Object that does not have a AppDispatcher. Add a dispatcher first");
            this.dispose();
        }
    }
}
//# sourceMappingURL=AppIsReadyUC.js.map