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