"use strict";

jQuery( function ($) {

	var wpss_redirect = function wpss_redirect(result) {
		location = acai_vars.acai_starter_sites_page;
	};

	$( document ).on('click', '.acai-admin-notice .notice-dismiss', function () {
		$.ajax({
			url: ajaxurl,
			type: 'POST',
			data: {
				action: 'acai_admin_notice_dismiss',
				'acai-nonce-name': acai_vars.acai_nonce
			}
		});
	});

	$( document ).on('click', '.acai-activate-wpss', function () {
		$( this ).html('<span class="dashicons dashicons-update"></span> ' + acai_text_strings.acai_string_activating).addClass('button-loading');
		wp.apiFetch( {
			path: '/wp/v2/plugins/starter-sites/starter-sites',
			method: 'POST',
			data: {
				'status': 'active'
			}
		}).then( function (result) {
			wpss_redirect(result);
		})["catch"]( function () {
			wpss_redirect({});
		});
	});

	$( document ).on('click', '.acai-install-wpss', function () {
		$( this ).html('<span class="dashicons dashicons-update"></span> ' + acai_text_strings.acai_string_installing).addClass('button-loading');
		wp.apiFetch( {
			path: '/wp/v2/plugins',
			method: 'POST',
			data: {
				'slug': 'starter-sites',
				'status': 'active'
			}
		}).then( function (result) {
			wpss_redirect(result);
		})["catch"]( function () {
			wpss_redirect({});
		});
	});

});