var h=Object.defineProperty;var w=(o,e,t)=>e in o?h(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var r=(o,e,t)=>w(o,typeof e!="symbol"?e+"":e,t);function u(){import.meta.url,import("_").catch(()=>1),async function*(){}().next()}class f{constructor(){r(this,"drawer",null);r(this,"panel",null);r(this,"overlay",null);r(this,"markAllReadButton",null);r(this,"isOpen",!1);this.init()}get $(){return window.jQuery}init(){this.drawer=this.$("#adt-notification-drawer"),!(!this.drawer||this.drawer.length===0)&&(this.overlay=this.drawer.find(".adt-notification-drawer__overlay"),this.panel=this.drawer.find(".adt-notification-drawer__panel"),this.markAllReadButton=this.drawer.find(".adt-notification-drawer__mark-all-read"),this.bindEvents())}bindEvents(){var e,t;(e=this.overlay)==null||e.on("click",()=>this.close()),(t=this.markAllReadButton)==null||t.on("click",a=>{a.preventDefault(),this.markAllAsRead()}),this.$(document).on("keydown",a=>{a.key==="Escape"&&this.isOpen&&this.close()})}open(){var e,t,a,i,s;this.isOpen||((e=this.drawer)==null||e.css("opacity",""),(t=this.panel)==null||t.css("transform",""),(a=this.drawer)==null||a.removeClass("adt-tw-pointer-events-none").addClass("adt-tw-pointer-events-auto"),(i=this.overlay)==null||i.removeClass("adt-tw-opacity-0 adt-tw-pointer-events-none").addClass("adt-tw-opacity-100 adt-tw-pointer-events-auto"),(s=this.panel)==null||s.removeClass("adt-tw-translate-x-full").addClass("adt-tw-translate-x-0"),this.isOpen=!0,this.$("body").css("overflow","hidden"))}close(){var e,t;this.isOpen&&((e=this.overlay)==null||e.removeClass("adt-tw-opacity-100 adt-tw-pointer-events-auto").addClass("adt-tw-opacity-0 adt-tw-pointer-events-none"),(t=this.panel)==null||t.removeClass("adt-tw-translate-x-0").addClass("adt-tw-translate-x-full"),setTimeout(()=>{var a,i,s;(a=this.drawer)==null||a.css("opacity","0"),(i=this.panel)==null||i.css("transform","translateX(100%)"),(s=this.drawer)==null||s.removeClass("adt-tw-pointer-events-auto").addClass("adt-tw-pointer-events-none")},300),this.isOpen=!1,this.$("body").css("overflow","unset"))}toggle(){this.isOpen?this.close():this.open()}markAllAsRead(){var i,s,n;const e=(i=this.drawer)==null?void 0:i.find(".adt-notification-drawer__item"),t=[];if(e==null||e.each((d,c)=>{const l=this.$(c).data("notice-id");l&&t.push(l)}),t.length===0)return;const a=(s=this.markAllReadButton)==null?void 0:s.text();(n=this.markAllReadButton)==null||n.text(window.wp.i18n.__("Marking...","woo-product-feed-pro")).prop("disabled",!0),this.$.ajax({url:window.ajaxurl,type:"POST",data:{action:"adt_pfp_mark_all_read",notice_ids:t,nonce:window.adtNotificationsData.markAllReadNonce},success:d=>{var c,l;d.success?(e==null||e.fadeOut(200,()=>{e.remove(),this.updateBadgeCount(),this.checkIfEmpty()}),(c=this.markAllReadButton)==null||c.hide()):(l=this.markAllReadButton)==null||l.text(a).prop("disabled",!1)},error:()=>{var d;(d=this.markAllReadButton)==null||d.text(a).prop("disabled",!1)}})}updateBadgeCount(){var i,s,n;const e=((i=this.drawer)==null?void 0:i.find(".adt-notification-drawer__item").length)||0,t=this.$(".adt-notification-icon__badge"),a=this.$(".toplevel_page_woo-product-feed .update-plugins .update-count");e>0?(t==null||t.text(e).show(),a==null||a.text(e),(s=this.markAllReadButton)==null||s.show().prop("disabled",!1).text(window.wp.i18n.__("Mark all as read","woo-product-feed-pro"))):(t==null||t.remove(),a==null||a.parent().remove(),(n=this.markAllReadButton)==null||n.hide())}checkIfEmpty(){var i,s,n;const e=((i=this.drawer)==null?void 0:i.find(".adt-notification-drawer__item").length)||0,t=(s=this.drawer)==null?void 0:s.find(".adt-notification-drawer__empty"),a=(n=this.drawer)==null?void 0:n.find(".adt-notification-drawer__list");e===0?(a==null||a.hide(),t==null||t.show()):(t==null||t.hide(),a==null||a.show())}}export{f as N,u as __vite_legacy_guard};
