(()=>{"use strict";function e(e,t){if(!e||e.dataset.eddModalBound)return;e.dataset.eddModalBound="true";const n=e.querySelector(".edd-modal__close");n&&n.addEventListener("click",(function(e){e.preventDefault(),e.stopPropagation(),t()})),e.addEventListener("click",(function(n){n.target===e&&t()}))}function t(e){return fetch(globalThis.ajaxurl,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},body:new URLSearchParams(e)})}document.addEventListener("DOMContentLoaded",(function(){!function(t){if(t.dialog){const n=t.dialog;if(!n||"function"!=typeof n.showModal)return null;const o=function(){n&&"function"==typeof n.close&&n.close()};return e(n,o),{open:function(){n.showModal(),"function"==typeof t.onOpen&&t.onOpen(n)},close:o,getDialog:function(){return n}}}const n="string"==typeof t.trigger,o=n?document.querySelector(t.trigger):t.trigger,c=t.dialogId||o?.getAttribute("data-dialog-id")||"";let i=c?document.getElementById(c):null;function d(){return!i&&c&&(i=document.getElementById(c)),i}function r(e){const n=e||d();n&&"function"==typeof n.showModal&&(n.showModal(),"function"==typeof t.onOpen&&t.onOpen(n))}n&&t.trigger?document.body.addEventListener("click",(function(n){const o=n.target.closest(t.trigger);if(!o)return;n.preventDefault();const i=o.getAttribute("data-dialog-id")||c,d=i?document.getElementById(i):null;d&&(e(d,(function(){d&&"function"==typeof d.close&&d.close()})),r(d))})):i&&"function"==typeof i.showModal&&(e(i,(function(){const e=d();e&&"function"==typeof e.close&&e.close()})),o&&o.addEventListener("click",(function(e){e.preventDefault(),r()})))}({trigger:"#edit-customer",dialogId:"edd-edit-customer-dialog"}),document.body.addEventListener("click",(function(e){var n,o,c;const i=e.target.closest("#add-customer-email");if(!i)return;e.preventDefault();const d=i.closest(".customer-section"),r=d?.querySelector(".notice-wrap");r&&(r.innerHTML=""),i.disabled=!0,i.classList.add("updating-message"),t({edd_action:"customer-add-email",customer_id:null!==(n=d?.querySelector('input[name="customer-id"]')?.value)&&void 0!==n?n:"",email:null!==(o=d?.querySelector('input[name="additional-email"]')?.value)&&void 0!==o?o:"",primary:d?.querySelector('input[name="make-additional-primary"]')?.checked?"1":"0",_wpnonce:null!==(c=d?.querySelector('input[name="add_email_nonce"]')?.value)&&void 0!==c?c:""}).then((e=>e.json())).then((function(e){setTimeout((function(){!0===e.success?window.location.href=e.redirect:(i.disabled=!1,i.classList.remove("updating-message"),r&&r.insertAdjacentHTML("beforeend",'<div class="notice notice-error inline"><p>'+e.message+"</p></div>"))}),342)})).catch((function(){i.disabled=!1,i.classList.remove("updating-message"),r&&r.insertAdjacentHTML("beforeend",'<div class="notice notice-error inline"><p>'+globalThis.edd_vars?.something_went_wrong+"</p></div>")}))})),document.body.addEventListener("click",(function(e){var n,o;e.target.closest("#disconnect-customer")&&(e.preventDefault(),globalThis.confirm(globalThis.edd_vars?.disconnect_customer)&&t({edd_action:"disconnect-userid",customer_id:null!==(n=document.querySelector('input[name="customerinfo[id]"]')?.value)&&void 0!==n?n:"",_wpnonce:null!==(o=document.querySelector("#edit-customer-info #_wpnonce")?.value)&&void 0!==o?o:""}).then((function(){window.location.reload()})).catch((function(){globalThis.alert(globalThis.edd_vars?.something_went_wrong)})))})),function(){const e=document.getElementById("edd-customer-delete-confirm");e&&e.addEventListener("change",(function(){const e=document.getElementById("edd-customer-delete-records"),t=document.getElementById("edd-delete-customer"),n=this.checked;e&&(e.disabled=!n,n||(e.checked=!1)),t&&(t.disabled=!n)}))}()}))})();