"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.showToast = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const ObjectFactory_1 = tslib_1.__importDefault(require("../../../Utilities/ObjectFactory"));
const AdaptablePopupAlert_1 = require("./AdaptablePopupAlert");
const Toastify_1 = require("../../../components/Toastify");
const showToast = (props) => {
    // we're doing this hack and not simply using props.api in order not to have a memory
    // leak where the api is still kept around in memory by the toaster
    let api = props.api;
    const off = api.eventApi.on('AdaptableDestroy', () => {
        Toastify_1.toast.dismiss();
        api = null;
    });
    const adaptableOptions = props.api.optionsApi.getAdaptableOptions();
    const toastProps = ObjectFactory_1.default.CreateToastOptions(adaptableOptions.notificationsOptions, {
        containerId: `Toastify-${adaptableOptions.adaptableId}`,
        onClose: () => {
            off();
        },
    }, {
        duration: props.adaptableAlert.alertDefinition.AlertProperties.NotificationDuration,
    });
    const content = (React.createElement(AdaptablePopupAlert_1.AdaptablePopupAlert, { headless: true, adaptableAlert: props.adaptableAlert, onClose: () => {
            Toastify_1.toast.dismiss(toastId);
        } }));
    let toastId;
    switch (props.adaptableAlert.alertDefinition.MessageType) {
        case 'Info':
            toastId = Toastify_1.toast.info(content, toastProps);
            break;
        case 'Error':
            toastId = Toastify_1.toast.error(content, toastProps);
            break;
        case 'Success':
            toastId = Toastify_1.toast.success(content, toastProps);
            break;
        case 'Warning':
            toastId = Toastify_1.toast.warn(content, toastProps);
            break;
    }
};
exports.showToast = showToast;
