(function ($) {
    $(document).on('click', '#ezhp-test-connection', function () {
        $('#ezhp-test-result').html('Testing connection...');
        $.post(ezhpVoiceAjax.ajaxurl, { action: 'ezhp_test_brilyi_connection' }, function (response) {
            if (response && response.success) {
                let msg = response.data ? response.data : 'Connected successfully.';
                $('#ezhp-test-result').html('<span style="color:green;">✅ ' + msg + '</span>');
            } else {
                let msg = (response && response.data) ? response.data : 'Unknown error';
                $('#ezhp-test-result').html('<span style="color:red;">❌ ' + msg + '</span>');
            }
        }).fail(function () {
            $('#ezhp-test-result').html('<span style="color:red;">❌ Request failed</span>');
        });
    });
})(jQuery);