document.addEventListener("alpine:init",(()=>{Alpine.store("eddNotifications",{isPanelOpen:!1,notificationsLoaded:!1,numberActiveNotifications:0,activeNotifications:[],inactiveNotifications:[],init:function(){const i=this,t=document.querySelector("#edd-notification-button .edd-number");t&&t.classList.remove("edd-hidden"),document.addEventListener("keydown",(function(t){"Escape"===t.key&&i.closePanel()}));const e=new URLSearchParams(window.location.search);e.has("notifications")&&"true"===e.get("notifications")&&i.openPanel()},openPanel:function(){const i=document.getElementById("edd-notifications-header");if(this.notificationsLoaded)return this.isPanelOpen=!0,void(i&&setTimeout((function(){i.focus()})));this.isPanelOpen=!0,this.apiRequest("/notifications","GET").then((t=>{this.activeNotifications=t.active,this.inactiveNotifications=t.dismissed,this.notificationsLoaded=!0,i&&i.focus()})).catch((i=>{console.log("Notification error",i)}))},closePanel:function(){if(!this.isPanelOpen)return;this.isPanelOpen=!1;const i=document.getElementById("edd-notification-button");i&&i.focus()},apiRequest:function(i,t){return fetch(edd_vars.restBase+i,{method:t,credentials:"same-origin",headers:{"Content-Type":"application/json","X-WP-Nonce":edd_vars.restNonce}}).then((i=>i.ok?i.text():Promise.reject(i))).then((i=>i?JSON.parse(i):null))},dismiss:function(i,t){if(void 0===this.activeNotifications[t])return;i.target.disabled=!0;const e=this.activeNotifications[t];this.apiRequest("/notifications/"+e.id,"DELETE").then((i=>{this.activeNotifications.splice(t,1),this.numberActiveNotifications=this.activeNotifications.length})).catch((i=>{console.log("Dismiss error",i)}))}})}));