(()=>{"use strict";var t={};// The module cache
var e={};// The require function
function r(o){// Check if module is in cache
var a=e[o];if(a!==undefined){return a.exports}// Create a new module (and put it into the cache)
var n=e[o]={exports:{}};// Execute the module function
t[o](n,n.exports,r);// Return the exports of the module
return n.exports}// webpack/runtime/rspack_version
(()=>{r.rv=()=>"1.6.5"})();// webpack/runtime/rspack_unique_id
(()=>{r.ruid="bundler=rspack@1.6.5"})();// CONCATENATED MODULE: ./node_modules/@swc/helpers/esm/_async_to_generator.js
function o(t,e,r,o,a,n,u){try{var i=t[n](u);var c=i.value}catch(t){r(t);return}if(i.done)e(c);else Promise.resolve(c).then(o,a)}function a(t){return function(){var e=this,r=arguments;return new Promise(function(a,n){var u=t.apply(e,r);function i(t){o(u,a,n,i,c,"next",t)}function c(t){o(u,a,n,i,c,"throw",t)}i(undefined)})}};// CONCATENATED MODULE: ./addons/subscription/assets/react/backend.js
document.addEventListener("DOMContentLoaded",function(){var{__}=wp.i18n;/**
     * Handle subscription status change
     *
     * @since 3.0.0
     *
     */var t=document.querySelector("#tutor-subscription-status-field");var e=document.querySelector("#tutor-subscription-status-change-form");var r=document.querySelector(".tutor-subscription-status-change-modal");var o=document.querySelector("#tutor-backend-filter-subscription-type");if(o){o.addEventListener("change",function(t){var e=new URL(window.location.href);var r=e.searchParams;r.set("subscription-type",t.target.value);window.location=e},{once:true})}if(e&&t){var n=t.value;t.addEventListener("change",function(t){r===null||r===void 0?void 0:r.classList.add("tutor-is-active");e.querySelector("input[name=status]").value=t.target.value;this.value=n});e.addEventListener("submit",function(t){return a(function*(){t.preventDefault();e.querySelector("button[type=submit]").classList.add("is-loading");var r=new FormData(t.target);try{var o=yield fetch(window._tutorobject.ajaxurl,{method:"POST",body:r});var a=yield o.json();if(a.status_code===200){window.location.reload();tutor_toast(__("Success","tutor-pro"),__("Status changed successfully!","tutor-pro"),"success")}else{tutor_toast(__("Failed","tutor-pro"),a.message,"error")}}catch(t){tutor_toast(__("Failed","tutor-pro"),__("Something went wrong!","tutor-pro"),"error")}finally{e.querySelector("button[type=submit]").classList.remove("is-loading")}})()})}/**
     * Handle subscription update
     *
     * @since 3.0.0
     *
     */var u=document.querySelectorAll(".tutor-subscription-update-form");u.forEach(function(t){t.addEventListener("submit",function(e){return a(function*(){e.preventDefault();var r=new FormData(e.target);var o=new FormData;o.append("_tutor_nonce",r.get("_tutor_nonce"));o.append("action",r.get("action"));o.append("subscription_id",r.get("subscription_id"));if(r.get("trial_end_date_gmt")){o.append("trial_end_date_gmt",i(new Date(r.get("trial_end_date_gmt"))))}if(r.get("next_payment_date_gmt")){o.append("next_payment_date_gmt",i(new Date(r.get("next_payment_date_gmt"))))}try{t.querySelector("button[type=submit]").classList.add("is-loading");var a=yield fetch(window._tutorobject.ajaxurl,{method:"POST",body:o});var n=yield a.json();if(n.status_code===200){window.location.reload();tutor_toast(__("Success","tutor-pro"),__("Subscription updated 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{t.querySelector("button[type=submit]").classList.remove("is-loading")}})()})});/**
     * Format date in GMT
     *
     * @since 3.0.0
     *
     */function i(t){var e=t.getUTCFullYear();var r=String(t.getUTCMonth()+1).padStart(2,"0");var o=String(t.getUTCDate()).padStart(2,"0");var a=String(t.getUTCHours()).padStart(2,"0");var n=String(t.getUTCMinutes()).padStart(2,"0");var u=String(t.getUTCSeconds()).padStart(2,"0");var i="".concat(e,"-").concat(r,"-").concat(o," ").concat(a,":").concat(n,":").concat(u);return i}/**
     * Show concent modal on membership only mode enable
     *
     * @since 3.3.0
     */var c=document.querySelector("#field_membership_only_mode .tutor-form-toggle-input");if(c){c.addEventListener("change",t=>{var e=t.target.checked;if(e){t.target.checked=false;t.target.dispatchEvent(new Event("change"));document.querySelector("body").classList.add("tutor-modal-open");document.getElementById("tutor-membership-only-mode-consent-modal").classList.add("tutor-is-active")}});var s=document.querySelector(".tutor-membership-only-mode-consent-confirm");if(s){s.addEventListener("click",t=>{var e=c.previousElementSibling;if(e){c.checked=true;e.value="on"}document.querySelector("body").classList.remove("tutor-modal-open");document.getElementById("tutor-membership-only-mode-consent-modal").classList.remove("tutor-is-active")})}}// Subscription type sorting on the report page
var d=document.querySelectorAll("[tutor-data-filterable]");d.forEach(t=>{t.addEventListener(t.getAttribute("tutor-filter-event-type"),t=>{var e=t.target;var r=e.value;var o=e.getAttribute("tutor-filter-query-param");var a=new URL(window.location.href);var n=a.searchParams;n.set(o,r);window.location=a})})})})();