(function ($) {
    'use strict';

    function runCheck(button) {
        var original = button.text();
        button.prop('disabled', true).text(ultraguardReputationMonitor.i18n.checking);

        $.post(ultraguardReputationMonitor.ajaxUrl, {
            action: 'ultraguard_reputation_check_now',
            nonce: ultraguardReputationMonitor.nonce
        }).done(function () {
            window.location.reload();
        }).fail(function () {
            window.alert(ultraguardReputationMonitor.i18n.failed);
            button.prop('disabled', false).text(original);
        });
    }

    $(document).on('click', '[data-ug-reputation-check]', function (event) {
        event.preventDefault();
        runCheck($(this));
    });
})(jQuery);
