"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ShowAlertUC = void 0;
exports.makeShowAlertUC = makeShowAlertUC;
const core_1 = require("@vived/core");
const AppDispatcher_1 = require("../Entities/AppDispatcher");
class ShowAlertUC extends core_1.AppObjectUC {
    constructor() {
        super(...arguments);
        this.requestType = "SHOW_ALERT";
    }
}
exports.ShowAlertUC = ShowAlertUC;
ShowAlertUC.type = "ShowAlertUC";
ShowAlertUC.get = (appObjects) => (0, core_1.getSingletonComponent)(ShowAlertUC.type, appObjects);
function makeShowAlertUC(appObject) {
    return new ShowAlertUCImp(appObject);
}
class ShowAlertUCImp extends ShowAlertUC {
    constructor(appObject) {
        super(appObject, ShowAlertUC.type);
        this.requestVersion = 1;
        this.showAlert = (data) => {
            if (!this.appDispatcher)
                return;
            const payload = {
                title: data.title,
                message: data.message,
                closeButtonLabel: data.closeButtonLabel,
                closeCallback: data.closeCallback,
            };
            this.appDispatcher.formRequestAndDispatch(this.requestType, this.requestVersion, payload);
        };
        this.appDispatcher = appObject.getComponent(AppDispatcher_1.AppDispatcher.type);
        if (!this.appDispatcher) {
            this.warn(`${ShowAlertUC.type} has been added to an App Object that does not have a AppDispatcher. Add a dispatcher first`);
            this.dispose();
        }
    }
}
//# sourceMappingURL=ShowAlertUC.js.map