(()=>{"use strict";const e=window.wp.i18n;function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t(e)}function r(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function n(e,r,n){return(r=function(e){var r=function(e){if("object"!=t(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=t(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==t(r)?r:r+""}(r))in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}var o=((function(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?r(Object(o),!0).forEach(function(t){n(e,t,o[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):r(Object(o)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))})}return e}({},tripzzy.strings)||{}).messages||{}).required_field;function i(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],r={validated:!0,message:null},n=!1,i=!1,s="",c=document.querySelectorAll("#tripzzy-checkout-form [required]");c.length>0&&c.forEach(function(r){var c=r.value.trim(),a=r.closest(".tripzzy-form-field").getAttribute("title");r.classList.remove("has-error"),c||(i=!0,s+=(0,e.sprintf)(o,a)+"</br />",t||(r.classList.add("has-error"),n||(n=!0,r.focus())))});var a=document.querySelectorAll("#tripzzy-checkout-form input[type=email]");return a.length>0&&a.forEach(function(e){var r=e.value,o=e.closest(".tripzzy-form-field").getAttribute("title");e.classList.remove("has-error"),r&&!r.match(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/)&&(i=!0,s+="* "+o+" is not valid. </br />",t||(e.classList.add("has-error"),n||(n=!0,e.focus())))}),i&&(r.validated=!1,r.message=s),r}function s(e){var t=document.getElementById("tripzzy-checkout-form-response-msg"),r=document.getElementById("tripzzy-checkout-form-response-title"),n=document.getElementById("tripzzy-checkout-form-response");e?(t.classList.add("tripzzy-response-msg","tripzzy-error"),r.innerHTML="Error",n.innerHTML=e):(t.classList.remove("tripzzy-response-msg","tripzzy-error"),r.innerHTML="",n.innerHTML="")}function c(){var e=document.getElementById("tripzzy-checkout-form-response-msg"),t=document.getElementById("tripzzy-checkout-form-response-title"),r=document.getElementById("tripzzy-checkout-form-response"),n=document.getElementById("tripzzy-payment-button");try{n.innerHTML="",n.classList.add("tripzzy-is-processing"),s(),document.getElementById("tripzzy-payment-details");var o=document.getElementById("tripzzy-checkout-form"),c=n.getAttribute("data-total"),a=o.querySelector('input[name="payment_amount"]');a&&(c=a.value),paypal.Buttons({onInit:function(e,t){t.disable(),i(!0).validated&&t.enable(),document.querySelectorAll("#tripzzy-checkout-form [required]").forEach(function(e){e.addEventListener("change",function(e){var r=i();s(r.message),t.disable(),r.validated&&t.enable()})})},onClick:function(){s(i().message)},createOrder:function(e,t){return s(),t.order.create({purchase_units:[{amount:{value:null!=c?c:0},description:tripzzy.payment_description,payment_instruction:{soft_descriptor:"3D_SECURE",secure_payment:{required:!0}}}],application_context:{shipping_preference:"NO_SHIPPING"}})},onApprove:function(e,t){return t.order.capture().then(function(e){var t=new CustomEvent("tripzzyGatewayPaymentSuccess",{detail:{paymentDetails:e}});document.dispatchEvent(t)})},onCancel:function(n){e.classList.add("tripzzy-response-msg","tripzzy-error"),t.innerHTML="Cancelled",r.innerHTML="You have cancelled your payment."},onError:function(o){var i=o.message.match(/{[^]*}/)[0];if(i){var s=JSON.parse(i);e.classList.add("tripzzy-response-msg","tripzzy-error"),t.innerHTML=s.name,r.innerHTML=s.details[0].description}n.classList.remove("tripzzy-is-processing")}}).render("#tripzzy-payment-button").then(function(e){return n.classList.remove("tripzzy-is-processing")})}catch(o){e.classList.add("tripzzy-response-msg","tripzzy-error"),t.innerHTML="Error",r.innerHTML=o.message,setTimeout(function(){n.classList.remove("tripzzy-is-processing")},100)}}c(),document.addEventListener("click",function(e){e.target===document.querySelector("#tripzzy-payment-mode-paypal_payment")&&c()})})();