window.afterPageUpdate = function()
{
    setTimeout(function(){
        const dtable = $('#table-repo-browsebranch').zui('dtable');
        if(!dtable) return;
        if(typeof dtable.options == 'undefined') return;
        $.each(dtable.options.data, function(index)
        {
            if(!dtable.options.data[index]) return;
            if(dtable.options.data[index].actions && (dtable.options.data[index].is_default == true || dtable.options.data[index].default == true))
            {
                dtable.options.data[index].actions[0].disabled = true;
                dtable.options.data[index].actions[0].hint = repoLang.deleteDefaultBranch;
            }

            if(dtable.options.data[index].is_default == true)
            {
                dtable.options.data[index].divergence = {html: '<span title="' + repoLang.default + '">' + repoLang.default + '</span>'};
            }
            else
            {
                const divergenceOnBranch = repoLang.divergenceOnBranch.replace('%s', dtable.options.data[index].defaultBranch);
                const aheadHint = repoLang.aheadHint.replace('%s', dtable.options.data[index].ahead);
                const behindHint = repoLang.behindHint.replace('%s', dtable.options.data[index].behind);
                const aheadBehindHint = `${divergenceOnBranch}${behindHint}, ${aheadHint}`;

                dtable.options.data[index].divergence =
                {
                    html: '<span title="' + aheadBehindHint + '">'
                    + repoLang.behind + '<strong class="ml-1">' + dtable.options.data[index].behind + '</strong>'
                    + " | "
                    + repoLang.ahead + '<strong class="ml-1">' + dtable.options.data[index].ahead + '</strong>'
                    + '</span>'
                };

                if(dtable.options.data[index].ahead == 0 && dtable.options.data[index].behind == 0)
                {
                    const noDivergenceHint = repoLang.noDivergenceOnHint.replace('%s', dtable.options.data[index].defaultBranch);
                    dtable.options.data[index].divergence = {html: '<span title="' + noDivergenceHint + '">' + repoLang.noDivergence + '</span>'};
                }
            }
        });

        dtable.render();
    }, 100)
}
