"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.NotifyType = void 0;
const jquery_1 = __importDefault(require("jquery"));
// @ts-ignore
const PNotify_1 = __importDefault(require("pnotify/lib/umd/PNotify"));
require("pnotify/lib/umd/PNotifyButtons");
require("pnotify/lib/umd/PNotifyCallbacks");
//  import 'cci-ui/css/limitless.pnotify.css';
PNotify_1.default.defaults.stack = {
    dir1: 'up',
    dir2: 'right',
    push: 'top'
};
exports.NotifyType = {
    progress: 'progress',
    success: 'success',
    error: 'danger',
    info: 'info'
};
const timeout = 10000;
class Notify {
    static show(text, type, oldNotify, callback) {
        let newNotify;
        if (type === exports.NotifyType.progress) {
            if (oldNotify) {
                oldNotify.close();
            }
            newNotify = PNotify_1.default.alert({
                title: text,
                textTrusted: true,
                text: '<div class="progress progress-striped active" style="margin:0">\
            <div class="progress-bar bg-danger" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0">\
            <span class="sr-only">0%</span>\
            </div>\
            </div>',
                addClass: 'stack-bottom-left bg-primary',
                icon: 'icon-spinner4 spinner',
                hide: false,
                modules: {
                    Buttons: {
                        closer: false,
                        sticker: false
                    },
                    History: {
                        history: false
                    },
                    Callbacks: {
                        beforeOpen: (notice) => {
                            const progress = (0, jquery_1.default)(notice.refs.textContainer)
                                .find('div.progress-bar');
                            let curValue = 1;
                            progress.width(`${curValue}%`)
                                .attr('aria-valuenow', curValue)
                                .find('span')
                                .html(`${curValue}%`);
                            // Pretend to do something.
                            const timer = setInterval(() => {
                                if (curValue >= 90) {
                                    window.clearInterval(timer);
                                    //notice.remove();
                                    return;
                                }
                                curValue += 1;
                                progress.width(`${curValue}%`)
                                    .attr('aria-valuenow', curValue)
                                    .find('span')
                                    .html(`${curValue}%`);
                            }, timeout / 90);
                        }
                    }
                }
            });
        }
        else {
            if (oldNotify) {
                oldNotify.update({
                    title: false,
                    text,
                    addClass: `stack-bottom-left bg-${type}`,
                    icon: false,
                    hide: true,
                    modules: {
                        Buttons: {
                            closer: true
                        }
                    }
                });
                newNotify = oldNotify;
                //  oldNotify.remove();
            }
            else {
                newNotify = PNotify_1.default.alert({
                    text,
                    addClass: `stack-bottom-left bg-${type}`,
                    modules: {
                        Buttons: {
                            closer: true,
                            sticker: false
                        },
                        Callbacks: {
                            afterOpen: () => {
                                if (callback) {
                                    callback();
                                }
                            }
                        }
                    }
                });
            }
        }
        return newNotify;
    }
    static close(notify) {
        try {
            notify.close();
        }
        catch (e) {
        }
    }
}
exports.default = Notify;
