jQuery(document).ready(function($) {
    $('[name="activate_akd_framework"]').wrap('<form id="activate-plugin-form" method="post"></form>');
    
    $('.install-akd-framework').click(function(e) {
        e.preventDefault();
        var $button = $(this);
        var data = {
            action: 'install_plugin',
            plugin_slug: $button.data('slug'),
            plugin_name: $button.data('name'),
            nonce: urls.nonce
        };
        $button.text($button.data('processing')).attr('disabled', 'disabled');
        $.post(urls.ajaxUrl, data, function(response) {
            $button.text('Activating...');
            activatePlugin($button, data.plugin_slug);
        });
    });

    $('.activate-akd-framework').click(function(e) {
        e.preventDefault();
        var $button = $(this);
        $button.text($button.data('processing')).attr('disabled', 'disabled');
        activatePlugin($button, $button.data('slug'));
    });

    function activatePlugin($button, plugin_slug) {
        var data = {
            action: 'activate_plugin',
            plugin_slug: plugin_slug,
            nonce: urls.nonce
        };
        $.post(urls.ajaxUrl, data, function(response) {
            // $button.text('Activate').removeAttr('disabled');
            window.location.href = urls.adminUrl +'admin.php?page=akd-framework';
        });
    }
	
	if (window.location.href.indexOf(urls.themeTemplate) > -1 && window.location.href.indexOf("theme-editor.php") === -1) {
        $('.notice-warning').remove();
        document.body.classList.add('akd-dashboard-card');
    }
});
