(function($) {
    'use strict';

    $(document).ready(function() {
        $('.salesloo-update-order-access').each(function() {
            $(this).on('click', function() {
                let id = $(this).attr('data-order-id');
                let nonce = $(this).attr('data-nonce');
                let c = confirm('Are you sure?');
                let ini = this;
                if (c) {
                    $(this).text('Process');
                    $.ajax({
                        url: ajaxurl,
                        method: 'POST',
                        data: {
                            order_id: id,
                            action: 'update-order-access',
                            nonce: nonce
                        }
                    }).done(function(msg) {
                        alert(msg);
                        $(ini).text('Update Access');
                    })
                }
            });
        });

        $('.salesloo-delete-access-license-host').each(function() {
            $(this).on('click', function() {
                let access_id = $(this).attr('data-access-id');
                let nonce = $(this).attr('data-nonce');
                let host = $(this).attr('data-host');

                let c = confirm('Are you sure?');
                let $this = this;
                if (c) {
                    $(this).removeClass().text('Processing');
                    $.ajax({
                        url: ajaxurl,
                        method: 'POST',
                        data: {
                            access_id: access_id,
                            host: host,
                            action: 'delete-access-license-host',
                            nonce: nonce
                        }
                    }).done(function(res) {
                        if (res == 1 || res == '1') {
                            console.log($($this).parent().parent().remove());
                        } else {
                            alert(res);
                        }
                    })
                }
            });
        });
    });

})(jQuery);