(()=>{"use strict";var t={};// The module cache
var i={};// The require function
function n(e){// Check if module is in cache
var r=i[e];if(r!==undefined){return r.exports}// Create a new module (and put it into the cache)
var a=i[e]={exports:{}};// Execute the module function
t[e](a,a.exports,n);// Return the exports of the module
return a.exports}// webpack/runtime/rspack_version
(()=>{n.rv=()=>"1.6.5"})();// webpack/runtime/rspack_unique_id
(()=>{n.ruid="bundler=rspack@1.6.5"})();// CONCATENATED MODULE: ./node_modules/.pnpm/@swc+helpers@0.5.17/node_modules/@swc/helpers/esm/_async_to_generator.js
function e(t,i,n,e,r,a,o){try{var s=t[a](o);var u=s.value}catch(t){n(t);return}if(s.done)i(u);else Promise.resolve(u).then(e,r)}function r(t){return function(){var i=this,n=arguments;return new Promise(function(r,a){var o=t.apply(i,n);function s(t){e(o,r,a,s,u,"next",t)}function u(t){e(o,r,a,s,u,"throw",t)}s(undefined)})}};// CONCATENATED MODULE: ./addons/tutor-notifications/assets/src/js/tutor-notifications.ts
var a="tutor-overflow-hidden";var o="tutor-notifications";var s=3;var u={ENROLLMENTS:"Enrollments",ANNOUNCEMENTS:"Announcements",ASSIGNMENTS:"Assignments",INSTRUCTORSHIP:"Instructorship",QA:"Q&A",QUIZ:"Quiz"};var l={READ:"READ",UNREAD:"UNREAD"};var d={[u.ENROLLMENTS]:"enrolled",[u.ANNOUNCEMENTS]:"announcement",[u.ASSIGNMENTS]:"book-2",[u.INSTRUCTORSHIP]:"instructor",[u.QA]:"qa",[u.QUIZ]:"quiz-2"};var c=t=>{return Object.values(u).includes(t)};var v=function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"";return c(t)?d[t]:"notification"};var A=()=>{var{query:t,toast:i,endpoints:n}=window.TutorCore;var{convertToErrorMessage:e}=window.TutorCore.error;var{wpPost:u}=window.TutorCore.api;return{$watch:null,isOffcanvasOpen:false,getNotificationsQuery:null,markAllAsReadMutation:null,markAllAsUnreadMutation:null,markSingleAsReadMutation:null,allNotifications:[],unreadNotifications:[],unreadCount:0,popoverNotifications:[],popoverUnreadNotifications:[],init(){var n,s,u,l;(n=(s=this).$watch)===null||n===void 0?void 0:n.call(s,"isOffcanvasOpen",t=>{document.documentElement.classList.toggle(a,t);document.body.classList.toggle(a,t)});this.getNotificationsQuery=t.useQuery(o,this.getNotificationsRequest,{staleTime:1e3});this.markAllAsReadMutation=t.useMutation(this.markAllAsReadRequest,{onSuccess:()=>r(function*(){t.invalidateQuery(o)})(),onError:t=>{i.error(e(t))}});this.markAllAsUnreadMutation=t.useMutation(this.markAllAsUnreadRequest,{onSuccess:()=>r(function*(){t.invalidateQuery(o)})(),onError:t=>{i.error(e(t))}});this.markSingleAsReadMutation=t.useMutation(this.markSingleAsReadRequest,{onSuccess:()=>r(function*(){t.invalidateQuery(o)})(),onError:t=>{i.error(e(t))}});(u=(l=this).$watch)===null||u===void 0?void 0:u.call(l,"getNotificationsQuery.data",()=>this._updateDerivedState());this._updateDerivedState()},_updateDerivedState(){var t;var i;var n=(i=(t=this.getNotificationsQuery)===null||t===void 0?void 0:t.data)!==null&&i!==void 0?i:[];this.allNotifications=n;this.unreadNotifications=n.filter(t=>t.status===l.UNREAD);this.unreadCount=this.unreadNotifications.length;this.popoverNotifications=n.slice(0,s);this.popoverUnreadNotifications=this.unreadNotifications.slice(0,s)},getNotificationImage(t){return t.thumbnail_url||""},notificationTypeSelector:v,openOffcanvas(){this.isOffcanvasOpen=true},closeOffcanvas(){this.isOffcanvasOpen=false},getNotificationsRequest(){return r(function*(){return u(n.GET_ALL_NOTIFICATIONS).then(t=>{var i;return(t===null||t===void 0?void 0:(i=t.data)===null||i===void 0?void 0:i.notifications)||[]})})()},markAllAsReadRequest(t){return r(function*(){return u(n.MARK_ALL_NOTIFICATIONS_AS_READ,t)})()},markAllAsUnreadRequest(t){return r(function*(){return u(n.MARK_ALL_NOTIFICATIONS_AS_UNREAD,t)})()},markSingleAsReadRequest(t){return r(function*(){return u(n.MARK_SINGLE_NOTIFICATION_AS_READ,t)})()},markAllAsRead(){return r(function*(){var t;yield(t=this.markAllAsReadMutation)===null||t===void 0?void 0:t.mutateAsync({mark_as_read:true})}).call(this)},markAllAsUnread(){return r(function*(){var t;yield(t=this.markAllAsUnreadMutation)===null||t===void 0?void 0:t.mutateAsync({mark_as_unread:true})}).call(this)},markSingleAsRead(t,i){return r(function*(){var n;if(l.READ===t||!i){return}yield(n=this.markSingleAsReadMutation)===null||n===void 0?void 0:n.mutateAsync({notification_id:i})}).call(this)},handleNotificationClick(t,i,n){return r(function*(){var e=t.currentTarget;var r=(e===null||e===void 0?void 0:e.getAttribute("href"))||"";yield this.markSingleAsRead(i,n);if(r&&"#"!==r){window.location.href=r}}).call(this)}}};var f=()=>{window.TutorComponentRegistry.register({type:"component",meta:{name:"notification",component:A}});window.TutorComponentRegistry.initWithAlpine(window.Alpine)};document.addEventListener("alpine:init",f)})();