jQuery(document).ready(function($) {
	"use strict";

	$('#dollah-welcome-msg .notice-dismiss').on('click',function(e){
		e.preventDefault();
		if( 'undefined' != typeof dollah_admin_notice && 'undefined' != typeof dollah_admin_notice.nonce && 'undefined' != typeof dollah_admin_notice.dismiss_action ) {
			jQuery.ajax({
				url : ajaxurl, // dollah_admin_notice.ajax_url
				type : 'post',
				data : {
					'action': dollah_admin_notice.dismiss_action,
					'nonce': dollah_admin_notice.nonce
				},
				success : function( response ) {}
			}); //$.post(ajaxurl, data);
		}
	});

	$( '.dollah-btn-processplugin' ).click( function ( e ) {
		e.preventDefault();
		if ($(this).hasClass('disabled')) {
			return;
		}

		if( 'undefined' != typeof dollah_admin_notice && 'undefined' != typeof dollah_admin_notice.nonce && 'undefined' != typeof dollah_admin_notice.dollah_processplugin_action ) {

			var $this = $( this );
			var origText = $this.text();
			var activeText = $this.hasClass( 'dollah-btn-smallmsg' ) ? 'Processing...' : dollah_admin_notice.dollah_processplugin_btntext;
			var pluginName = $(this).attr('data-plugin');
			$this.nextAll('.error').remove();
			$this.addClass( 'updating-message disabled' ).text( activeText );
			jQuery.ajax({
				url : ajaxurl, // dollah_admin_notice.ajax_url
				type : 'post',
				data : {
					'action': dollah_admin_notice.dollah_processplugin_action,
					'nonce': dollah_admin_notice.nonce,
					'plugin': pluginName ? pluginName : 'hoot-import',
				},
				success : function( response ) {
					console.log(response);
					if ( response.redirect ) {
						window.location.href = response.redirect;
					} else {
						$this.removeClass( 'updating-message disabled' ).text( origText );
						if ( response.errorInstall ) {
							var $errorDiv = $('<div class="error">' + response.errorInstall + '</div>');
							$this.after( $errorDiv );
							$errorDiv.delay(5000).fadeOut( 400, function() { $(this).remove(); } );
						} else if ( response.errorMessage ) {
							var $errorDiv = $('<div class="error">' + response.errorMessage + '</div>');
							$this.after( $errorDiv );
							$errorDiv.delay(5000).fadeOut( 400, function() { $(this).remove(); } );
						}
					}
				},
				error   : function( xhr, ajaxOptions, thrownError ){
					$this.removeClass( 'updating-message disabled' ).text( origText );
					console.log(thrownError);
				}
			}); //$.post(ajaxurl, data);

		}

	} );

});