let t=!1;function a(t,a){a?(t.classList.add("notifal-loading"),t.disabled=!0):(t.classList.remove("notifal-loading"),t.disabled=!1)}function n(t){window.NotifalUtils&&"function"==typeof window.NotifalUtils.showMessage&&window.NotifalUtils.showMessage(t,"error")}async function e(t){const e=t.dataset.campaignId;if(e&&!t.classList.contains("notifal-loading"))try{a(t,!0);const o=await async function(t){const a=window.NotifalCampaignToggleAjax||{},n=a.ajax_actions&&a.ajax_actions.toggle_campaign_status?a.ajax_actions.toggle_campaign_status:"notifal_toggle_campaign_status",e=a.nonce&&a.nonce.toggle_campaign_status?a.nonce.toggle_campaign_status:"",o=new FormData;o.append("action",n),o.append("nonce",e),o.append("campaign_id",t);const i=await fetch(a.ajax_url||"",{method:"POST",body:o,credentials:"same-origin"});if(!i.ok)throw new Error("HTTP "+String(i.status));return i.json()}(e);if(o&&o.success&&o.data)return void window.setTimeout(()=>{window.location.reload()},400);let i=window.NotifalCampaignStrings&&window.NotifalCampaignStrings.unexpected_error||"An unexpected error occurred. Please try again.";o&&o.data&&("string"==typeof o.data?i=o.data:o.data.message&&(i=o.data.message)),n(i)}catch(o){n(window.NotifalCampaignStrings&&window.NotifalCampaignStrings.unexpected_error||"An unexpected error occurred. Please try again.")}finally{a(t,!1)}}function o(t){const a=t.target,n=a instanceof Element?a:a&&a.parentElement?a.parentElement:null;if(!n||"function"!=typeof n.closest)return;const o=n.closest(".notifal-campaign-status-toggle");o&&o instanceof HTMLButtonElement&&(t.preventDefault(),e(o))}function i(){t||(t=!0,document.addEventListener("click",o))}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",i):i();
