"use strict";(globalThis.webpackChunkwp_travel_engine=globalThis.webpackChunkwp_travel_engine||[]).push([[702],{702:(e,t,n)=>{n.d(t,{default:()=>o});const o=class{constructor(e){var t=this;if(e){if(this.applyBtn=e.querySelector(".wp-travel-engine-coupons-apply-btn"),this.resetBtn=e.querySelector(".wte-coupon-response-reset-coupon"),this.tripsField=e.querySelector('input[name="wte_couponse_trip_id"]'),this.dismissButton=e.querySelector(".wte-coupon-remove-trigger"),!this.tripsField)throw new Error("No trips Field.");this.couponCodeField=e.querySelector('input[name="wp_travel_engine_coupon_code_input"]'),this.nonceField=document.getElementById("wte_apply_coupon_nonce"),this.resetNonceField=document.getElementById("wte_reset_coupon_nonce"),this.loader=e.querySelector("#price-loader-coupon"),this.loading=!1,this.summaryTable=document.querySelector(".wpte-bf-summary-table"),this.responseHolder=document.getElementById("coupon-response-holder"),this.dismissButton&&this.dismissButton.addEventListener("click",(function(t){t.preventDefault(),e.remove()})),this.applyBtn&&this.applyBtn.addEventListener("click",function(e){return function(n){n.preventDefault(),t.toggleLoader(!0),function(){var e;if(null!==(e=WTEAjaxData)&&void 0!==e&&e.ajaxurl){var n=new FormData;return n.append("action","wte_session_cart_apply_coupon"),n.append("trip_ids",t.tripsField.value),n.append("CouponCode",t.couponCodeField.value),n.append("trip_id",WTEAjaxData.trip_id),n.append("_nonce",t.nonceField.value),setTimeout((function(){return new Promise((function(e,t){return e(!1)}))}),5e3),fetch(WTEAjaxData.ajaxurl,{method:"POST",body:n})}}().then((function(e){return e.json()})).then((function(n){if(n.success)location.reload();else{var o,r=wp.template("wte-coupon-response");if(wp.template("wte-coupon-response-updated-price"),e.responseHolder)o=n.data.reduce((function(e,t){return"".concat(e).concat(t.message)}),""),e.responseHolder.innerHTML=r({type:"error",message:o});t.toggleLoader(!1)}}))}}(this)),this.resetBtn&&this.resetBtn.addEventListener("click",(function(e){e.preventDefault(),t.toggleLoader(!0),function(){var e;if(null!==(e=WTEAjaxData)&&void 0!==e&&e.ajaxurl){var n=new FormData;return n.append("action","wte_session_cart_reset_coupon"),n.append("_nonce",t.resetNonceField.value),setTimeout((function(){return new Promise((function(e,t){return e(!1)}))}),5e3),fetch(WTEAjaxData.ajaxurl,{method:"POST",body:n})}}().then((function(e){return e.json()})).then((function(e){if(e.success)window.location.reload();else{var n,o=wp.template("wte-coupon-response");if(wp.template("wte-coupon-response-updated-price"),couponInstance.responseHolder)n=e.data.reduce((function(e,t){return"".concat(e).concat(t.message)}),""),couponInstance.responseHolder.innerHTML=o({type:"error",message:n});t.toggleLoader(!1)}}))}))}}toggleLoader(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];e&&!this.loading&&this.loader&&(this.loader.style.removeProperty("display"),this.summaryTable&&(this.summaryTable.style.opacity=".3"),this.loading=!0),!e&&this.loading&&this.loader&&(this.loader.style.display="none",this.summaryTable&&(this.summaryTable.style.opacity="1"),this.loading=!1)}}}}]);