/**
 * template js 
 * @since cms:1.4.3.2&1.4.3.3 web:1.0
 */
var TEMPLATE = {};

/** template load header */
TEMPLATE.loadHearder = function(elmentId) {
    $(elmentId).load("../html/common/header.html" , function() {
        I18N.initi18n();
    }); 
}

/**
 * template load dashboard setting 
 * @param {string} elmentId - element to load setting html
 * @param {*} changeCallback - callback when setting changed
 */
TEMPLATE.loadDashboardSetting = function(elmentId, changeCallback) {
    $(elmentId).load("dashboard-setting.html", function() {
        DashboardSetting.init(changeCallback);
        I18N.initi18n();
    }); 
}

/** Template load confirm model */
TEMPLATE.loadConfirmModal = function(elmentId) {
    $(elmentId).load("../html/common/confirm-modal.html", function() {
        I18N.initi18n();
    }); 
}

/** Template load operation select */
TEMPLATE.loadOperationSelect = function(elmentId, selectCallback) {
    $(elmentId).load("operation-select.html", function() {
        OperationSelect.init(selectCallback);
        I18N.initi18n();
    }); 
}

/** Template load display menu */
TEMPLATE.loadDisplaymenu = function(elmentId) {
    $(elmentId).load("display-menu.html", function() {
        I18N.initi18n();
    }); 
}

/**
 * show confirm model
 */
 TEMPLATE.showModalConfirm = function () {
    $("#showConfirm").click(function(){
        $("#confirm-modal").modal();
    });
};

/** Template load notification content*/
TEMPLATE.loadNotificationSelect = function(elmentId, selectCallback) {
    $(elmentId).load("notification-content.html", function() {
        NotificationSelect.init(selectCallback);
        I18N.initi18n();
    }); 
}

/**
 * load main navs title html to a element by id
 * @param {string} elmentId - elementId where contain main title html
 * @param {string} titleLang - lang of title
 * @param {Array} navs - array nav items (titleLang, href)
 */
 TEMPLATE.loadMainNavsTitle = function(elmentId, titleLang, navs, completeCallback) {
    var titleHtmlPath = '../common/main-title.html';
    if (navs) {
        titleHtmlPath = '../common/main-nav-title.html';
    }
    $(elmentId).load(titleHtmlPath , function(data) {
        $(elmentId).replaceWith(data);
        if (titleLang) {
            $('#mainTitleHeader').attr("lang", titleLang);
        }
        if (navs) {
            var olElm = $('#mainTitleNavs ol');
            for (var i = 0; i < navs.length; i++) {
                const nav = navs[i];
                var liElm = $('<li class="breadcrumb-item" />');
                if (nav.href) {
                    var aElm = $('<a class="text-decoration-none text-underline lang" />');
                    aElm.attr('href', nav.href);
                    if (nav.titleLang) {
                        aElm.attr('lang', nav.titleLang);
                    }
                    liElm.append(aElm);
                } else {
                    liElm.addClass('lang');
                    liElm.attr('aria-current', 'page');
                    liElm.append('<span></span>');
                    if (nav.titleLang) {
                        liElm.attr('lang', nav.titleLang);
                    }
                }
                olElm.append(liElm);
            }
        }
        I18N.initi18n();
        if (completeCallback) {
            completeCallback();
        }
    });
}
