(()=>{"use strict";function e(e){e.preventDefault();var n=jQuery(this),o=n.find('input[name="shortcode_id"]').val(),i=n.find('input[name="type"]').val(),t=n.find('input[name="password"]').val();n.addClass("loading"),wp.ajax.post("igd_check_module_password",{shortcodeId:o,type:i,password:t,nonce:igd.nonce}).done(function(e){n.parent().replaceWith(e),"table"===i?table.initTable():initShortcode()}).fail(function(e){console.log(e),n.parent().find(".igd-form-error").text(wp.i18n.__("Invalid password.","integrate-google-drive"))}).always(function(){n.removeClass("loading")})}function n(e){return decodeURIComponent(atob(e).split("").map(function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)}).join(""))}var o=jQuery,i=window.initShortcode,t={init:function(){t.onElementReady(".wc-block-components-product-details__igd-wc-uploader",t.renderBlocksUploader)},ready:function(){o(document).on("click",".igd-wc-upload-wrap .upload-button",function(e){e.preventDefault(),o(".igd-wc-upload-wrap").removeClass("active"),o(this).parents(".igd-wc-upload-wrap").addClass("active").find(".browse-files").trigger("click")}),o(document).on("updated_checkout",function(){t.renderClassicUploader()})},renderBlocksUploader:function(){var e=document.querySelectorAll(".wc-block-components-product-details__igd-wc-uploader");e&&0!==e.length&&e.forEach(function(e){var o,t=(null===(o=e.querySelector(".wc-block-components-product-details__value"))||void 0===o?void 0:o.innerText)||"",r=e.closest(".wc-block-components-order-summary-item");r?r.insertAdjacentHTML("beforeend",n(t)):e.outerHTML=n(t),i()})},renderClassicUploader:function(){var e=document.querySelectorAll(".variation-igd_wc_uploader");e&&0!==e.length&&e.forEach(function(e){var o,t=(null===(o=e.querySelector("p"))||void 0===o?void 0:o.innerText)||"";e.closest(".cart_item").insertAdjacentHTML("afterend",'<tr class="cart_item_uploader"><td colspan="3">'.concat(n(t),"</td></tr>")),e.remove(),i()})},onElementReady:function(e,n){var o=document.querySelector(e);if(o)return n(o);var i=new MutationObserver(function(){var o=document.querySelector(e);o&&(i.disconnect(),n(o))});document.body&&i.observe(document.body,{childList:!0,subtree:!0})}};const r=t;!function(n){var o=igd.settings.integrations,i=void 0===o?["classic-editor","gutenberg-editor","elementor"]:o,t={init:function(){i.includes("woocommerce")&&r.init()},ready:function(){n(document).off("submit.igdPass","#igd-password-form").on("submit.igdPass","#igd-password-form",e),n(document).on("submit","#igd-login-form",t.handleModuleLogin),n(document).on("submit","#igd-require-email-form",t.handleEmailRequired),n(document).on("change",".nf-element.upload-file-list",function(){var e=n(this).val(),o=parseInt(n(this).data("min-files")),i=parseInt(n(this).data("field-id")),t="min-files-error";if(o>0){var r=[];try{r=e.split("), ")}catch(e){console.log(e)}if(r.length<o){var d=wp.i18n.sprintf(wp.i18n.__("Please upload at least %s files.","integrate-google-drive"),o);nfRadio.channel("fields").request("add:error",i,t,d)}else nfRadio.channel("fields").request("remove:error",i,t)}}),n(document.body).on("updated_wc_div",function(){initShortcode()}),n(document).on("gform_post_render",function(e,n){initShortcode()}),i.includes("woocommerce")&&r.ready()},handleModuleLogin:function(e){e.preventDefault();var o=n(this),i=o.find(".login-submit"),t=o.parent().data("shortcode_id"),r=n("#igd-user-login").val(),d=n("#igd-user-pass").val(),a=n("#igd-remember-me").is(":checked")?1:0,l=i.find(".igd-spinner");l.length||(l=n('<span class="igd-spinner"></span>'),i.prepend(l)),l.show(),wp.ajax.post("igd_handle_module_login",{username:r,password:d,remember:a,shortcodeId:t,nonce:igd.nonce}).done(function(e){window.location.reload()}).fail(function(e){console.error(e);var n=(null==e?void 0:e.message)||wp.i18n.__("Invalid login credentials.","integrate-google-drive");o.parent().find(".igd-form-error").html(n)}).always(function(){l.hide()})},handleEmailRequired:function(e){e.preventDefault();var o=n(this),i=o.find('input[name="shortcode_id"]').val(),t=o.find('input[name="email"]').val(),r=o.find('input[name="nonce"]').val();if(/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)){var d=o.find("button img");d.show(),wp.ajax.post("igd_email_required",{shortcodeId:i,email:t,nonce:r}).done(function(e){o.parent().replaceWith(e),initShortcode()}).fail(function(e){console.log(e),o.parent().find(".igd-form-error").text(wp.i18n.__("Invalid email.","integrate-google-drive"))}).always(function(){d.hide()})}else o.parent().find(".igd-form-error").text(wp.i18n.__("Please enter a valid email address.","integrate-google-drive"))}};t.init(),n(document).ready(t.ready)}(jQuery)})();