"use strict";

var _wp = wp,
  apiFetch = _wp.apiFetch;
jQuery(function ($) {
  var gutenify_alfaRedirectToKitPage = function gutenify_alfaRedirectToKitPage(res) {
    // if( res?.status && 'active' === res.status ) {
    window.location = "".concat(window.gutenify_alfa.gutenify_kit_gallery);
    // }
  };

  // Activate Gutenify.
  $(document).on('click', '.gutenify-alfa-activate-gutenify', function () {
    $(this).html('<span class="dashicons dashicons-update"></span> Loading...').addClass('gutenify-alfa-importing-gutenify');
    apiFetch({
      path: '/wp/v2/plugins/gutenify/gutenify',
      method: 'POST',
      data: {
        "status": "active"
      }
    }).then(function (res) {
      gutenify_alfaRedirectToKitPage(res);
    })["catch"](function () {
      gutenify_alfaRedirectToKitPage({});
    });
  });
  $(document).on('click', '.gutenify-alfa-install-gutenify', function () {
    $(this).html('<span class="dashicons dashicons-update"></span> Loading...').addClass('gutenify-alfa-importing-gutenify');
    apiFetch({
      path: '/wp/v2/plugins',
      method: 'POST',
      data: {
        "slug": "gutenify",
        "status": "active"
      }
    }).then(function (res) {
      gutenify_alfaRedirectToKitPage(res);
    })["catch"](function () {
      gutenify_alfaRedirectToKitPage({});
    });
  });
  $(document).on('click', '.gutenify-alfa-admin-notice .notice-dismiss', function () {
    console.log(ajaxurl + "?action=gutenify_alfa_hide_theme_info_noticebar");
    apiFetch({
      url: ajaxurl + "?action=gutenify_alfa_hide_theme_info_noticebar&gutenify_alfa-nonce-name=".concat(window.gutenify_alfa.gutenify_alfa_nonce),
      method: 'POST'
    }).then(function (res) {
      console.log(res);
    })["catch"](function (res) {
      console.log(res);
    });
  });
});