!function(){"use strict";var e={n:function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,{a:n}),n},d:function(t,n){if(Array.isArray(n))for(var r=0;r<n.length;){var a=n[r++],o=n[r++];e.o(t,a)?0===o&&r++:0===o?Object.defineProperty(t,a,{enumerable:!0,value:n[r++]}):Object.defineProperty(t,a,{enumerable:!0,get:o})}else for(var a in n)e.o(n,a)&&!e.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:n[a]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}},t=window.wp.i18n,n=window.wp.apiFetch,r=e.n(n);function a(e){const t=document.createElement("span");return t.className="hyve-add-post-error",t.style.color="red",t.style.marginLeft="8px",t.textContent=e,t}document.addEventListener("DOMContentLoaded",(function(){document.querySelectorAll(".hyve-row-action-btn").forEach((e=>function(e){if(!e.dataset.postId)return;let n=null;e.addEventListener("click",(async o=>{o.preventDefault();const d=e.parentElement;d&&n&&n?.parentNode&&(n?.remove(),n=null),e.disabled=!0,e.style.cursor="wait";const i=e.dataset.action,s=e.innerText;try{let o;e.innerText=(0,t.__)("Hyve is processing the post","hyve-lite"),o="delete"===i?await r()({path:`${window.hyveAddons.api}/data?id=${e.dataset.postId}`,method:"DELETE"}):await r()({path:`${window.hyveAddons.api}/data`,method:"POST",data:{action:"add",data:{ID:e.dataset.postId}}}),e.style.cursor="pointer",o&&o.error&&d?(n=a(o.error),d.appendChild(n),e.innerHTML=s,e.disabled=!1):o&&("delete"===i?(e.innerHTML=(0,t.__)("Add to Hyve","hyve-lite"),e.dataset.action="add",e.classList.remove("button-link-delete")):(e.innerHTML=(0,t.__)("Remove from Hyve","hyve-lite"),e.dataset.action="delete",e.classList.add("button-link-delete")),e.disabled=!1)}catch(r){d&&(n=a(r.message||(0,t.__)("An unknown error occurred. Please try again.","hyve-lite")),d.appendChild(n)),e.innerHTML=s,e.disabled=!1,e.style.cursor="pointer"}}))}(e)))}))}();