(()=>{"use strict";var t={};// The module cache
var e={};// The require function
function n(r){// Check if module is in cache
var o=e[r];if(o!==undefined){return o.exports}// Create a new module (and put it into the cache)
var i=e[r]={exports:{}};// Execute the module function
t[r](i,i.exports,n);// Return the exports of the module
return i.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 r(t,e,n,r,o,i,a){try{var u=t[i](a);var c=u.value}catch(t){n(t);return}if(u.done)e(c);else Promise.resolve(c).then(r,o)}function o(t){return function(){var e=this,n=arguments;return new Promise(function(o,i){var a=t.apply(e,n);function u(t){r(a,o,i,u,c,"next",t)}function c(t){r(a,o,i,u,c,"throw",t)}u(undefined)})}};// CONCATENATED MODULE: ./addons/tutor-notifications/assets/src/js/register.js
document.addEventListener("DOMContentLoaded",function(){var{__}=wp.i18n;if(!("serviceWorker"in navigator)){console.warn("Service Worker not supported");return}function t(t,e,n){var r=new Date;r.setTime(r.getTime()+n*24*60*60*1e3);var o="expires="+r.toUTCString();document.cookie=t+"="+e+";"+o+";path="+window._tutorobject.base_path}function e(t){var e=t+"=";var n=document.cookie.split(";");for(var r=0;r<n.length;r++){var o=n[r];while(o.charAt(0)==" "){o=o.substring(1)}if(o.indexOf(e)==0){return o.substring(e.length,o.length)}}return""}function n(t){var e="=".repeat((4-t.length%4)%4);// eslint-disable-next-line
var n=(t+e).replace(/\-/g,"+").replace(/_/g,"/");var r=window.atob(n);var o=new Uint8Array(r.length);for(var i=0;i<r.length;++i){o[i]=r.charCodeAt(i)}return o}function r(e,n,r){navigator.serviceWorker.ready.then(function(o){// Check if supports PN.
if(!o.pushManager){t("tutor_pn_dont_ask","yes",365);alert(__("This browser does not support push notification","tutor-pro"));return}// Try to get existing subscription.
o.pushManager.getSubscription().then(function(t){if(t===null){// Create new subscription
o.pushManager.subscribe({applicationServerKey:e,userVisibleOnly:true}).then(function(t){setTimeout(function(){if(navigator.userAgent.indexOf("Mac OS X")&&n){alert(__("Thanks! Please make sure browser notification is enabled in notification settings.","tutor-pro"))}},1);r(t,o,true)}).catch(function(){console.warn(Notification.permission!=="granted"?"PN Permission denied":"PN subscription error")})}else{// Use existing subscription
r(t,o)}})}).catch(function(t){console.error("Service Worker error",t)})}function i(t){// Request push notification permission
r(n(window._tutorobject.tutor_pn_vapid_key),t,function(t,n,r){// Set the current user id for this browser
n.active.postMessage(JSON.stringify({client_id:window._tutorobject.tutor_pn_client_id,browser_key:e("tutor_pn_browser_key")}));if(window._tutorobject.tutor_pn_client_id==0||!r&&window._tutorobject.tutor_pn_subscription_saved=="yes"){return}var o=new FormData;o.append("action","tutor_pn_save_subscription");o.append("subscription",JSON.stringify(t));fetch(window._tutorobject.ajaxurl,{method:"POST",body:o})})}// Register service worker
navigator.serviceWorker.register(window._tutorobject.home_url+"/tutor-push-notification.js").then(function(n){if(Notification.permission=="denied"){return}if(!window._tutorobject.tutor_pn_vapid_key){console.warn("Vapid key could not be generated.");return}if(Notification.permission=="granted"){i();return}var r=document.getElementById("tutor-pn-permission");if(r&&window._tutorobject.tutor_pn_client_id>0&&!e("tutor_pn_dont_ask")){// Show the toast with CSS transition animation
r.style.display="block";r.style.bottom="-100px";// Force reflow to enable transition
r.offsetHeight;r.style.transition="bottom 1s ease";r.style.bottom="0px";// Enable handler
r.querySelector("#tutor-pn-enable").addEventListener("click",function(){i(true)});// Don't ask handler
r.querySelector("#tutor-pn-dont-ask").addEventListener("click",function(){t("tutor_pn_dont_ask","yes",365)});// Hide toast on all actions ultimately
["#tutor-pn-enable","#tutor-pn-close","#tutor-pn-dont-ask"].forEach(function(t){var e=r.querySelector(t);if(e){e.addEventListener("click",function(){r.style.display="none"})}})}}).catch(function(t){console.warn("Tutor PN Service Worker registration failed",t)});/**
     * Listen for push notifications while browsing and show in-app drawer inside dashboard
     * 
     * @since 4.0.0
     */if("serviceWorker"in navigator){navigator.serviceWorker.addEventListener("message",function(t){return o(function*(){if(t.data&&t.data.type==="tutor_push_notification_received"){v(t.data.payload)}})()})}function a(){return o(function*(){try{var t=new FormData;t.append(_tutorobject.nonce_key,_tutorobject._tutor_nonce);t.append("action","tutor_get_latest_notification");var e=yield fetch(window._tutorobject.ajaxurl,{method:"POST",body:t});return yield e.json()}catch(t){console.error("Failed to fetch latest notification",t);return null}})()}function u(t){return o(function*(){try{var e=new FormData;e.append(_tutorobject.nonce_key,_tutorobject._tutor_nonce);e.append("action","toggle_single_notification_status_as_read");e.append("notification_id",t);var n=yield fetch(window._tutorobject.ajaxurl,{method:"POST",body:e});return yield n.json()}catch(t){console.error("Failed to mark notification as read",t)}})()}// Clone template and append it to our clean HTML container
function c(){var t=document.getElementById("tutor-pn-drawer-template");var e=document.querySelector(".tutor-pn-drawer-stack");if(!t||!e){return null}var n=t.content.firstElementChild.cloneNode(true);e.appendChild(n);return n}function s(t){var e=new DOMParser().parseFromString(t,"text/html");return e.body.textContent||""}function d(t,e){var n=t.querySelector(".tutor-pn-drawer-title");if(n){n.textContent=e.title||__("New Notification","tutor-pro")}var r=t.querySelector(".tutor-pn-drawer-description");if(r){r.textContent=s(e.body||"")}var o=t.querySelector("a.tutor-pn-drawer-link");if(o){var i;if((i=e.data)===null||i===void 0?void 0:i.url){o.href=e.data.url;o.textContent=__("View Details","tutor-pro");o.style.display="inline-block"}else{o.style.display="none"}}}function l(t){var e=t.style.display;if(!t.classList.contains("tutor-active")&&!t.classList.contains("tutor-closing")){t.style.display="flex"}t.style.setProperty("--tutor-pn-drawer-height",t.offsetHeight+"px");t.style.display=e}function f(t){l(t);t.classList.remove("tutor-closing");t.classList.add("tutor-active")}function p(t,e){if(!t.classList.contains("tutor-active")){return}l(t);t.classList.remove("tutor-active");t.classList.add("tutor-closing");t.addEventListener("animationend",function e(n){if(n.target!==t){return}t.removeEventListener("animationend",e);t.remove()});if(e.id){u(e.id)}}function v(t){return o(function*(){var e=c();if(!e){return}d(e,t);f(e);var n=e.querySelector("button.tutor-pn-drawer-close");if(n){n.addEventListener("click",function(){p(e,t)})}var r=e.querySelector("a.tutor-pn-drawer-link");if(r&&t.id){r.addEventListener("click",function(e){return o(function*(){e.preventDefault();r.classList.add("tutor-btn-loading");yield u(t.id);r.classList.remove("tutor-btn-loading");var n=this.getAttribute("href")||"";if(n){window.location.href=n}}).call(this)})}})()}function _(){return o(function*(){if(_tutorobject.is_dashboard_page!=="1"){return}var t=yield a();var e=t===null||t===void 0?void 0:t.data;if(e&&e.status==="UNREAD"){var n={id:e.ID,title:e.title,body:e.content,data:{url:e.topic_url}};v(n)}})()}_()})})();