window.mtAddons = window.mtAddons || {};
(function( window, document, $, app ) {
	'use strict';

	app.cache = function() {
		app.$ = {};
	};

	app.init = function() {
		app.cache();
		var $checkbox = $( '.check-column' ).find( 'input' );

		// Loop through checkboxes.
		$checkbox.each(function( index, value ){
			var id = $( value ).attr( 'id' );

			// Bail early if no ID exists.
			if ( ! id ) {
				return;
			}

			id = id.slice( 0, -6 );

			$( value ).on( 'click', function(){
				$.post( ajaxurl,
					{
						'action': 'mt_activate_addon',
						'addon_id': id,
						'mt-nonce': mt_extension.ajax_nonce,
					},
					function( response ){
							$( value ).parent().find( '.dashicons' ).remove();
							$( value ).after( '<span class="dashicons dashicons-yes"></span>' );
							$( value ).parent().find( '.dashicons' ).delay( 500 ).fadeOut( 400 );
					}
				);
			});
		});
	};

	$( document ).ready( app.init );
	return app;
})( window, document, jQuery, window.mtAddons );
