{# @copyright   Copyright (C) 2010-2026 Combodo SARL #}
{# @license     http://opensource.org/licenses/AGPL-3.0 #}

function ajax_run_audit(sTransactionId) {
    $('#ajax_run_audit_in_progress_msg').removeClass('ibo-is-hidden');
    $.post(
        '{{ sAjaxURL|raw }}',
        { operation: 'ajax_run_audit', transaction_id: sTransactionId },
        function (data) {
            $('#ajax_run_audit_in_progress_msg').addClass('ibo-is-hidden');

            if (data.error_message) {
                $('#ajax_run_audit_error_msg .ibo-alert--title').html(data.error_message);
                $('#ajax_run_audit_error_msg').removeClass('ibo-is-hidden');
            } else {
                $('#ajax_run_audit_success_msg').removeClass('ibo-is-hidden');
                $('#ajax_run_audit').html(data);
            }
        }
    )
    .fail(function() {
        $('#ajax_run_audit_in_progress_msg').addClass('ibo-is-hidden');
        $('#ajax_run_audit_error_msg .ibo-alert--title').html('{{ 'DataFeatureRemoval:RunAudit:Error'|dict_s }}');
        $('#ajax_run_audit_error_msg').removeClass('ibo-is-hidden');
    });
}

function ajax_compile() {
    $('#ajax_compile_in_progress_msg').removeClass('ibo-is-hidden');

    $.post(
        '{{ sAjaxURL|raw }}',
        { operation: 'ajax_compile', transaction_id: '{{ sTransactionId }}' },
        function (data) {
            $('#ajax_compile_in_progress_msg').addClass('ibo-is-hidden');

            if (data.error_message) {
                $('#ajax_compile_error_msg .ibo-alert--title').html(data.error_message);
                $('#ajax_compile_error_msg').removeClass('ibo-is-hidden');
            } else {
                $('#ajax_compile_success_msg .ibo-alert--title').html(data.success_message);
                $('#ajax_compile_success_msg').removeClass('ibo-is-hidden');

                ajax_run_audit(data.transaction_id);
            }
        },
        'json'
    )
    .fail(function() {
        $('#ajax_compile_in_progress_msg').addClass('ibo-is-hidden');
        $('#ajax_compile_error_msg .ibo-alert--title').html('{{ 'DataFeatureRemoval:Compile:Error'|dict_s }}');
        $('#ajax_compile_error_msg').removeClass('ibo-is-hidden');
    });
}

ajax_compile();
