(function($){
    'use strict';
   
        $( document ).ready(function() {
            
            $(document).on('click', '.qcld-seo-rss-switch-btn', function (e) {
                //e.preventDefault();

                var $this   = $(this);
                var btntext = $this.text();
                var id      = $this.attr('data-id');

                $.ajax({
                    url: ajaxurl,
                    method: 'POST',
                    data: {
                        'action'    : 'qcld_seohelp_rss_post_status',
                        'id'        : id,
                        'security'  : qcld_seohelp_ajax_nonce
                    },
                    dataType: 'json',
                    beforeSend: function() {
                        $this.closest('.qcld-seo-rss-switch').find('.spinner').addClass('is-active');
                        $this.addClass('spinning');
                        $this.prop("disabled", true);
                    },
                    complete: function() {
        
                    },
                    success: function(response) {
                        $this.prop("disabled", false);
                        $this.removeClass('spinning');
                        $this.closest('.qcld-seo-rss-switch').find('.spinner').removeClass('is-active');
                    },
                    error: function() {
                    	
                        $this.prop("disabled", false);
                        $this.removeClass('spinning');
                        $this.closest('.qcld-seo-rss-switch').find('.spinner').removeClass('is-active');
                        alert( 'Someting went worng' );
                        
                    }
                });
        
            });


            
            $(document).on('click', '.qcld_seohelp_rss_run_now', function (e) {
                e.preventDefault();

                var $this   = $(this);
                var btntext = $this.text();
                var id      = $this.attr('data-id');

                

				var numberRow = $this
					.closest('.column-status')
					.find(".qcld_seohelp-table");
				//numberRow.find("td").hide();

                $.ajax({
                    url: ajaxurl,
                    method: 'POST',
                    data: {
                        'action'    : 'qcld_seohelp_rss_run_now_ajax',
                        'id'        : id,
                        'security'  : qcld_seohelp_ajax_nonce
                       
                    },
                    dataType: 'json',
                    beforeSend: function() {
                        //$this.text('Checking...');
                        $this.closest('.qcld-seo-rss-status-wrap').find('.spinner').addClass('is-active');
                        $this.addClass('spinning');
                        $this.prop("disabled", true);

                    },
                    complete: function() {
        
                    },
                    success: function(response) {

                        //console.log( response );
        
                        $this.prop("disabled", false);
                        $this.removeClass('spinning');
                        $this.closest('.qcld-seo-rss-status-wrap').find('.spinner').removeClass('is-active');

						//numberRow.hide();
						if ( response.data.import_success ) {
							numberRow.addClass('import_success');
						}else{

							numberRow.addClass('import_error');
						}
						numberRow.html(response.data.msg);

        
                      
                    },
                    error: function() {
        
                        $this.prop("disabled", false);
                        $this.removeClass('spinning');
                        $this.closest('.qcld-seo-rss-status-wrap').find('.spinner').removeClass('is-active');

                        alert( 'Someting went worng' );
                        
                    }
                });
        
            });
            
            
            $(document).on('click', '.qcld_seohelp-found-details', function (e) {
                e.preventDefault();
                var currentDom = $(this);
                $('.qcld_seohelp-duplicates-found').hide();
                currentDom.closest('.column-status').find(".qcld_seohelp-items-found").toggle();
            });
            
            $(document).on('click', '.qcld_seohelp-duplicates-details', function (e) {
                e.preventDefault();
                var currentDom = $(this);
                $('.qcld_seohelp-items-found').hide();
                currentDom.closest('.column-status').find(".qcld_seohelp-duplicates-found").toggle();
            });


    });

})(jQuery)