(()=>{"use strict";var t={};// The module cache
var o={};// The require function
function e(r){// Check if module is in cache
var n=o[r];if(n!==undefined){return n.exports}// Create a new module (and put it into the cache)
var u=o[r]={exports:{}};// Execute the module function
t[r](u,u.exports,e);// Return the exports of the module
return u.exports}// webpack/runtime/rspack_version
(()=>{e.rv=()=>"1.6.5"})();// webpack/runtime/rspack_unique_id
(()=>{e.ruid="bundler=rspack@1.6.5"})();// CONCATENATED MODULE: ./node_modules/@swc/helpers/esm/_async_to_generator.js
function r(t,o,e,r,n,u,i){try{var s=t[u](i);var d=s.value}catch(t){e(t);return}if(s.done)o(d);else Promise.resolve(d).then(r,n)}function n(t){return function(){var o=this,e=arguments;return new Promise(function(n,u){var i=t.apply(o,e);function s(t){r(i,n,u,s,d,"next",t)}function d(t){r(i,n,u,s,d,"throw",t)}s(undefined)})}};// CONCATENATED MODULE: ./addons/subscription/assets/react/frontend.js
document.addEventListener("DOMContentLoaded",function(){var{__}=wp.i18n;/**
     * Handle cancel plan in frontend dashboard
     *
     * @since 3.0.0
     *
     */var t=document.querySelector("#tutor-subscription-cancel-plan-button");var o=document.querySelector("#tutor-subscription-cancel-plan-modal");var e=document.querySelector("#tutor-subscription-cancel-plan-submit");if(t&&o){t.addEventListener("click",function(t){o.classList.add("tutor-is-active")});e.addEventListener("click",function(t){return n(function*(){e.classList.add("is-loading");var o=new FormData;o.append("_tutor_nonce",_tutorobject._tutor_nonce);o.append("action","tutor_subscription_status_update");o.append("context","frontend_dashboard");o.append("subscription_id",t.target.dataset.subscriptionId);o.append("status","cancelled");try{var r=yield fetch(window._tutorobject.ajaxurl,{method:"POST",body:o});var n=yield r.json();if(n.status_code===200){window.location.reload();tutor_toast(__("Success","tutor-pro"),__("Subscription cancelled successfully!","tutor-pro"),"success")}else{tutor_toast(__("Failed","tutor-pro"),n.message,"error")}}catch(t){tutor_toast(__("Failed","tutor-pro"),__("Something went wrong!","tutor-pro"),"error")}finally{e.classList.remove("is-loading")}})()})}/**
     * Handle resume plan in frontend dashboard
     * 
     * @since 3.7.1 
     */var r=document.querySelector("#resume_plan");if(r){r.addEventListener("click",function(t){return n(function*(){var o=t.target;var e=window._tutorobject.ajaxurl;var r=t.target.dataset.subscriptionId;var n=new FormData;n.append("_tutor_nonce",_tutorobject._tutor_nonce);n.append("action","tutor_subscription_resume");n.append("subscription_id",r);try{o.classList.add("is-loading");var u=yield fetch(e,{method:"POST",body:n});var i=yield u.json();if(i.status_code===200){tutor_toast(__("Success","tutor-pro"),i.message,"success");window.location.reload(true)}else{tutor_toast(__("Failed","tutor-pro"),i.message,"error")}}catch(t){tutor_toast(__("Failed","tutor-pro"),__("Something went wrong!","tutor-pro"),"error")}finally{o.classList.remove("is-loading")}})()})}/**
     * Handle early renewal in frontend dashboard
     *
     * @since 3.0.0
     *
     */var u=document.querySelector("#tutor-subscription-early-renewal-submit");if(u){u.addEventListener("click",function(t){return n(function*(){u.classList.add("is-loading");u.disabled=true;var o=new FormData;o.append("_tutor_nonce",_tutorobject._tutor_nonce);o.append("action","tutor_subscription_early_renew");o.append("subscription_id",t.target.dataset.subscriptionId);try{var e=yield fetch(window._tutorobject.ajaxurl,{method:"POST",body:o});var r=yield e.json();if(r.status_code===200){window.location.reload();tutor_toast(__("Success","tutor-pro"),r.message,"success")}else{tutor_toast(__("Failed","tutor-pro"),r.message,"error")}}catch(t){tutor_toast(__("Failed","tutor-pro"),__("Something went wrong!","tutor-pro"),"error")}finally{u.classList.remove("is-loading");u.disabled=false}})()})}/**
     * Handle subscription option change in single course 
     *
     * @since 3.0.0
     *
     */var i=document.querySelectorAll(".tutor-course-subscription-options input[name=selling_option]");i.forEach(t=>{t.addEventListener("change",function(t){var o=t.target.value;if(o==="subscription"){var e,r,n,u,i,s,d,a,c;(e=document.querySelector(".tutor-subscription-plan-wrapper"))===null||e===void 0?void 0:e.classList.remove("tutor-d-none");(r=document.querySelector(".tutor-subscription-buy-now"))===null||r===void 0?void 0:r.classList.remove("tutor-d-none","tutor-native-add-to-cart");(n=document.querySelector(".tutor-subscription-add-to-cart-wrap"))===null||n===void 0?void 0:n.classList.add("tutor-d-none");(u=document.querySelector(".tutor-single-course-sidebar .tutor-btn-gift"))===null||u===void 0?void 0:u.classList.add("tutor-d-none");(i=document.querySelector("#tutor-membership-view-pricing"))===null||i===void 0?void 0:i.classList.add("tutor-d-none");(s=document.querySelector(".tutor-plan-feature-list"))===null||s===void 0?void 0:s.classList.remove("tutor-d-none");(d=document.querySelector("#tutor-subscription-start-from"))===null||d===void 0?void 0:d.classList.add("tutor-d-none");(a=document.querySelector(".tutor-course-certificate-meta"))===null||a===void 0?void 0:a.classList.add("tutor-d-none");(c=document.querySelector(".tutor-course-enrollment-meta"))===null||c===void 0?void 0:c.classList.add("tutor-d-none")}else if(o==="membership"){var l,v,p,m,_,b,y,f,S;(l=document.querySelector(".tutor-subscription-plan-wrapper"))===null||l===void 0?void 0:l.classList.add("tutor-d-none");(v=document.querySelector(".tutor-subscription-buy-now"))===null||v===void 0?void 0:v.classList.add("tutor-d-none");(p=document.querySelector("#tutor-subscription-start-from"))===null||p===void 0?void 0:p.classList.remove("tutor-d-none");(m=document.querySelector(".tutor-subscription-add-to-cart-wrap"))===null||m===void 0?void 0:m.classList.add("tutor-d-none");(_=document.querySelector("#tutor-membership-view-pricing"))===null||_===void 0?void 0:_.classList.remove("tutor-d-none");(b=document.querySelector(".tutor-single-course-sidebar .tutor-btn-gift"))===null||b===void 0?void 0:b.classList.add("tutor-d-none");(y=document.querySelector(".tutor-plan-feature-list"))===null||y===void 0?void 0:y.classList.add("tutor-d-none");(f=document.querySelector(".tutor-course-certificate-meta"))===null||f===void 0?void 0:f.classList.add("tutor-d-none");(S=document.querySelector(".tutor-course-enrollment-meta"))===null||S===void 0?void 0:S.classList.add("tutor-d-none")}else{var L,w,q,g,h,j,E,k,x;(L=document.querySelector(".tutor-subscription-plan-wrapper"))===null||L===void 0?void 0:L.classList.add("tutor-d-none");(w=document.querySelector(".tutor-subscription-buy-now"))===null||w===void 0?void 0:w.classList.add("tutor-d-none");(q=document.querySelector("#tutor-subscription-start-from"))===null||q===void 0?void 0:q.classList.remove("tutor-d-none");(g=document.querySelector(".tutor-subscription-add-to-cart-wrap"))===null||g===void 0?void 0:g.classList.remove("tutor-d-none");(h=document.querySelector("#tutor-membership-view-pricing"))===null||h===void 0?void 0:h.classList.add("tutor-d-none");(j=document.querySelector(".tutor-single-course-sidebar .tutor-btn-gift"))===null||j===void 0?void 0:j.classList.remove("tutor-d-none");(E=document.querySelector(".tutor-plan-feature-list"))===null||E===void 0?void 0:E.classList.add("tutor-d-none");(k=document.querySelector(".tutor-course-certificate-meta"))===null||k===void 0?void 0:k.classList.remove("tutor-d-none");(x=document.querySelector(".tutor-course-enrollment-meta"))===null||x===void 0?void 0:x.classList.remove("tutor-d-none")}})});/**
     * Handle subscription plan change in single course 
     *
     * @since 3.0.0
     *
     */var s=document.querySelectorAll(".tutor-course-subscription-plan input[name=plan_id]");s.forEach(t=>{t.addEventListener("change",function(o){var e;var r=t.closest(".tutor-course-subscription-plan");var n=r.dataset.checkoutLink;(e=document.querySelector(".tutor-subscription-buy-now"))===null||e===void 0?void 0:e.setAttribute("href",n);var u=r.dataset.features;if(u){var i=JSON.parse(u);var s=i.map(t=>'\n                    <div class="tutor-plan-feature-item">\n                        <i class="tutor-icon-mark-light"></i>\n                        '.concat(t,"\n                    </div>\n                ")).join("");document.querySelector(".tutor-plan-feature-list").innerHTML=s}})});/**
     * Select first subscription plan by default
     *
     * @since 3.0.0
     */if(s.length>0){s[0].checked=true;s[0].dispatchEvent(new Event("change"))}/**
     * Hide enrollment and certificate meta for membership and subscription only mode.
     * 
     * @since 3.0.0
     * 
     * @since 3.6.0 Membership only added
     */if(document.querySelector(".tutor-subscription-plans.subscriptions-only, .tutor-subscription-plans.membership-only")){var d,a;(d=document.querySelector(".tutor-course-enrollment-meta"))===null||d===void 0?void 0:d.classList.add("tutor-d-none");(a=document.querySelector(".tutor-course-certificate-meta"))===null||a===void 0?void 0:a.classList.add("tutor-d-none")}})})();