/* Bongoto WooCommerce – Quick Setup helpers (AJAX import + open Home) */ (function ($) { 'use strict'; $(function () { // Safety: make sure localized JS object exists if (typeof window.BongotoWooSetup === 'undefined') { return; } var $btn = $('#bongoto-import-btn'); if (!$btn.length) { return; } var isRequestRunning = false; $btn.on('click', function (e) { e.preventDefault(); // Prevent double clicks if (isRequestRunning) { return; } isRequestRunning = true; var originalText = $btn.text(); var importingLabel = window.BongotoWooSetup.importing_label || 'Importing…'; var resetLabel = window.BongotoWooSetup.reset_label || originalText || 'Import & Set as Front Page'; $btn .prop('disabled', true) .addClass('is-busy') .text(importingLabel); $.post(window.BongotoWooSetup.ajax, { action: 'bongoto_woocommerce_import_home', nonce: window.BongotoWooSetup.nonce }) .done(function (res) { if (res && res.success && res.data) { // Optional admin notice message from PHP if (res.data.message) { alert(res.data.message); } // Open imported Home page in a new tab if permalink is provided if (res.data.permalink) { window.open(res.data.permalink, '_blank'); } // If you need to refresh the admin Setup page, you can uncomment: // location.reload(); } else { var msg = (res && res.data && res.data.message) || 'Import failed. Please try again.'; alert(msg); } }) .fail(function () { alert('Request failed. Please check your connection and try again.'); }) .always(function () { isRequestRunning = false; $btn .prop('disabled', false) .removeClass('is-busy') .text(resetLabel); }); }); }); })(jQuery);