$(document).on('click', '.test-inserve-connection-btn', function (e) {
    e.preventDefault();

    const url = "/api/v1/sources/inserve/";
    const params = {action: "auth/me"};
    const rootStyles = getComputedStyle(document.documentElement);
    const background = rootStyles.getPropertyValue('--swal-bg')?.trim();
    const color = rootStyles.getPropertyValue('--swal-text-color')?.trim();

    $.get(url, params)
        .done(function (response, status, jqXHR) {
            // Check if HTTP code is 200
            if (jqXHR.status === 200) {
                Swal.fire({
                    background: background,
                    color: color,
                    icon: "success",
                    title: __('connection_success_title'),
                    text: __('connection_success_text'),
                    confirmButtonText: __('close'),
                    customClass: {confirmButton: "btn btn-success"},
                    buttonsStyling: true
                });
            }
        })
        .fail(function (jqXHR) {
            let response = jqXHR.responseJSON || {};

            Swal.fire({
                background: background,
                color: color,
                icon: "error",
                title: __('connection_error_title'),
                text: response.message || __('connection_error_text') + jqXHR.status,
                confirmButtonText: __('close'),
                customClass: {confirmButton: "btn btn-danger"},
                buttonsStyling: false
            });
        });
});