(()=>{"use strict";function e(e,t,a){e.textContent=t,e.setAttribute("aria-label",a),e.disabled=!1,e.setAttribute("aria-busy","false")}function t(e,t){e&&(e.textContent=t,e.hidden=!1)}document.addEventListener("DOMContentLoaded",()=>{const a=document.querySelector(".acrossai-addons-page");if(!a)return;!function(e){const t=e.querySelector(".acrossai-addons-page__filters"),a=e.querySelector(".acrossai-addons-page__grid");if(!t||!a)return;const n=Array.from(t.querySelectorAll('[role="tab"]')),i=Array.from(a.querySelectorAll(".acrossai-addons-page__card"));function s(e){n.forEach(e=>{e.classList.remove("is-active"),e.setAttribute("aria-selected","false"),e.setAttribute("tabindex","-1")}),e.classList.add("is-active"),e.setAttribute("aria-selected","true"),e.setAttribute("tabindex","0");const t=e.dataset.filter;i.forEach(e=>{const a="all"===t||e.dataset.type===t;e.hidden=!a})}n.forEach(e=>{e.addEventListener("click",()=>s(e)),e.addEventListener("keydown",t=>{const a=n.indexOf(e);if("ArrowRight"===t.key)t.preventDefault(),s(n[(a+1)%n.length]),n[(a+1)%n.length].focus();else if("ArrowLeft"===t.key){t.preventDefault();const e=(a-1+n.length)%n.length;s(n[e]),n[e].focus()}})})}(a);const n="acrossaiAddonsPage_"+(a.dataset.acrossaiAddonsInstance||"").replace(/[^a-zA-Z0-9_]/g,"_"),i=window[n];if(i&&(function(a,n){a.addEventListener("click",a=>{const i=a.target.closest(".acrossai-addons-page__btn");if(!i)return;const s=i.dataset.action;"install"!==s&&"activate"!==s&&"deactivate"!==s||(a.preventDefault(),async function(a,n,i){const s=a.closest(".acrossai-addons-page__card"),o=s?s.querySelector(".acrossai-addons-page__card-error"):null,d=a.dataset.slug,c=a.dataset.source,l=a.dataset.pluginFile||"",r=a.textContent.trim(),u=a.getAttribute("aria-label");a.disabled=!0,a.setAttribute("aria-busy","true"),a.textContent="install"===n?i.i18n.installing:"activate"===n?i.i18n.activating:i.i18n.deactivating,o&&(o.hidden=!0);const p=new FormData;"install"===n?(p.append("action","acrossai_addons_install_free"),p.append("source",c)):"activate"===n?(p.append("action","acrossai_addons_activate"),p.append("plugin_file",l)):(p.append("action","acrossai_addons_deactivate"),p.append("plugin_file",l)),p.append("nonce",i.nonce),p.append("slug",d);try{const s=await fetch(i.ajaxUrl,{method:"POST",body:p}),d=await s.json();if(d.success){const e="install"===n?i.i18n.installed:"activate"===n?i.i18n.activated:i.i18n.deactivated;a.textContent=e,a.classList.add("acrossai-addons-page__btn--confirmed"),a.setAttribute("aria-busy","false"),d.data.plugin_file&&(a.dataset.pluginFile=d.data.plugin_file),setTimeout(()=>{a.classList.remove("acrossai-addons-page__btn--confirmed");const e=d.data.state;a.textContent=e.label,a.setAttribute("aria-label",e.label+" "+(a.dataset.slug||"")),a.dataset.action=e.action,a.disabled=!e.enabled,a.setAttribute("aria-disabled",String(!e.enabled)),a.className="button "+e.css_class+" acrossai-addons-page__btn",e.plugin_file&&(a.dataset.pluginFile=e.plugin_file),a.focus()},1500)}else e(a,r,u),t(o,d.data?.message||i.i18n.installFailed)}catch(n){e(a,r,u),t(o,i.i18n.installFailed)}}(i,s,n))})}(a,i),function(e,t){e.addEventListener("click",e=>{const a=e.target.closest(".acrossai-addons-page__btn");a&&"buy"===a.dataset.action&&(e.preventDefault(),function(e,t){const a=e.dataset.slug,n=t.addons.find(e=>e.slug===a);if(n)if(t.freemius.isRegistered&&t.freemius.checkoutLoaded&&n.checkout_config)!function(e,t){if(void 0===window.FS||void 0===window.FS.Checkout){const a=new URL(t.freemius.connectAgainUrl);return a.searchParams.set("slug",e.slug),void(window.location.href=a.toString())}const a=e.checkout_config;window.FS.Checkout.configure({plugin_id:a.plugin_id,plan_id:a.plan_id,public_key:a.public_key}).open({name:e.name,success:()=>{window.location.reload()}})}(n,t);else{const e=new URL(t.freemius.connectAgainUrl);e.searchParams.set("slug",a),window.location.href=e.toString()}}(a,t))})}(a,i),i.pendingSlug)){const e=a.querySelector(`[data-slug="${i.pendingSlug}"]`);if(e){e.scrollIntoView({behavior:"smooth",block:"center"});const t=e.querySelector(".acrossai-addons-page__btn");t&&t.focus()}}})})();