import { AppObjectUC, getSingletonComponent, } from "@vived/core";
import { AppDispatcher } from "../Entities/AppDispatcher";
export class ShowAlertUC extends AppObjectUC {
    constructor() {
        super(...arguments);
        this.requestType = "SHOW_ALERT";
    }
}
ShowAlertUC.type = "ShowAlertUC";
ShowAlertUC.get = (appObjects) => getSingletonComponent(ShowAlertUC.type, appObjects);
export 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.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