"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.actionModal = actionModal;
const app_1 = require("../../app");
const http_1 = require("../../http");
const utils_1 = require("../../utils");
/* --------------------------------
Modal Loader
-------------------------------- */
function actionModal(op = {}) {
    const { element = 'NA', script = '/', payload = {}, title = 'No title provided' } = op;
    /* loading UI */
    $('.modal-body').html(`
        <div class="w-full flex justify-center items-center">
            <img src="${app_1.Config.app_url + app_1.Config.paths.loader}" 
            style="width:20px;height:20px;"> Loading...
        </div>
    `);
    http_1.Http.ajax.make({
        ...op,
        element,
        script,
        payload,
        dataType: 'json',
        type: 'request',
        target: element,
        title,
        noLoaderImg: true,
        success: (op) => {
            const type = typeof op;
            if (app_1.Config.app_env) {
                console.log(op);
            }
            if (type === 'object') {
                const { response, title, modalCallback = undefined, globLoader = true } = op;
                if (response.success) {
                    const { data, view = 'reached' } = response.data;
                    if (globLoader) {
                        utils_1.Sweet.success({ html: data?.alert });
                    }
                    $('.modal-title').html(title);
                    $('.modal-body').html(view);
                    if (modalCallback) {
                        if (window[modalCallback]) {
                            window[modalCallback](response);
                        }
                    }
                }
            }
            else {
                $('#theGlobalLoader').removeClass('activeGlobalLoader').css({ display: 'none' });
            }
        },
    });
}
//# sourceMappingURL=modal.js.map