/*! For license information please see utils.js.LICENSE.txt */
(()=>{"use strict";var e={n:t=>{var r=t&&t.__esModule?()=>t.default:()=>t;return e.d(r,{a:r}),r},d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function n(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i=[],a=!0,l=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){l=!0,o=e}finally{try{a||null==r.return||r.return()}finally{if(l)throw o}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function i(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}e.r(t),e.d(t,{SHIPPING_OPTION_REGEX:()=>E,convertCartAddressToPayPal:()=>N,convertPayPalAddressToCart:()=>L,extractFullName:()=>U,extractShippingMethod:()=>G,fieldsToJson:()=>T,getErrorMessage:()=>M,getFieldValue:()=>x,getPage:()=>$,getPayPalQueryParams:()=>I,getRestPath:()=>F,getRestRoute:()=>B,getSetting:()=>k,isPluginConnected:()=>J,isValid:()=>V,isValidAddress:()=>D,isValidFieldValue:()=>H,loadPayPalSdk:()=>A,setFieldValue:()=>q,setSetting:()=>C,submitErrorMessage:()=>R});const a=window.lodash,l=window.jQuery;var c=e.n(l);const u=window.wp.hooks;function s(e,t){void 0===t&&(t={});var r=document.createElement("script");return r.src=e,Object.keys(t).forEach((function(e){r.setAttribute(e,t[e]),"data-csp-nonce"===e&&r.setAttribute("nonce",t["data-csp-nonce"])})),r}function d(e,t){if(void 0===t&&(t=f()),v(e,t),"undefined"==typeof window)return t.resolve(null);var r=function(e){var t="https://www.paypal.com/sdk/js";e.sdkBaseURL&&(t=e.sdkBaseURL,delete e.sdkBaseURL),function(e){var t=e["merchant-id"],r=e["data-merchant-id"],n="",o="";Array.isArray(t)?t.length>1?(n="*",o=t.toString()):n=t.toString():"string"==typeof t&&t.length>0?n=t:"string"==typeof r&&r.length>0&&(n="*",o=r),e["merchant-id"]=n,e["data-merchant-id"]=o}(e);var r,n,o=Object.keys(e).filter((function(t){return void 0!==e[t]&&null!==e[t]&&""!==e[t]})).reduce((function(t,r){var n=e[r].toString();return"data-"===r.substring(0,5)?t.dataAttributes[r]=n:t.queryParams[r]=n,t}),{queryParams:{},dataAttributes:{}}),i=o.queryParams,a=o.dataAttributes;return{url:"".concat(t,"?").concat((r=i,n="",Object.keys(r).forEach((function(e){0!==n.length&&(n+="&"),n+=e+"="+r[e]})),n)),dataAttributes:a}}(e),n=r.url,o=r.dataAttributes,i=o["data-namespace"]||"paypal",a=p(i);return function(e,t){var r=document.querySelector('script[src="'.concat(e,'"]'));if(null===r)return null;var n=s(e,t),o=r.cloneNode();if(delete o.dataset.uidAuto,Object.keys(o.dataset).length!==Object.keys(n.dataset).length)return null;var i=!0;return Object.keys(o.dataset).forEach((function(e){o.dataset[e]!==n.dataset[e]&&(i=!1)})),i?r:null}(n,o)&&a?t.resolve(a):function(e,t){void 0===t&&(t=f()),v(e,t);var r=e.url,n=e.attributes;if("string"!=typeof r||0===r.length)throw new Error("Invalid url.");if(void 0!==n&&"object"!=typeof n)throw new Error("Expected attributes to be an object.");return new t((function(e,t){if("undefined"==typeof window)return e();!function(e){var t=e.onSuccess,r=e.onError,n=s(e.url,e.attributes);n.onerror=r,n.onload=t,document.head.insertBefore(n,document.head.firstElementChild)}({url:r,attributes:n,onSuccess:function(){return e()},onError:function(){var e=new Error('The script "'.concat(r,'" failed to load.'));return window.fetch?fetch(r).then((function(r){return 200===r.status&&t(e),r.text()})).then((function(e){var r=function(e){var t=e.split("/* Original Error:")[1];return t?t.replace(/\n/g,"").replace("*/","").trim():e}(e);t(new Error(r))})).catch((function(e){t(e)})):t(e)}})}))}({url:n,attributes:o},t).then((function(){var e=p(i);if(e)return e;throw new Error("The window.".concat(i," global variable is not available."))}))}function f(){if("undefined"==typeof Promise)throw new Error("Promise is undefined. To resolve the issue, use a Promise polyfill.");return Promise}function p(e){return window[e]}function v(e,t){if("object"!=typeof e||null===e)throw new Error("Expected an options object.");if(void 0!==t&&"function"!=typeof t)throw new Error("Expected PromisePonyfill to be a function.")}var y=["locale"];function g(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return m(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?m(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,l=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){l=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(l)throw i}}}}function m(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function b(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 h(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?b(Object(r),!0).forEach((function(t){i(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):b(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var w={},P=!1,O=new Map,j=null,E=/^([\w]+)\:(.+)$/,S={address_1:"address_line_1|line1",address_2:"address_line_2|line2",state:"admin_area_1|state",city:"admin_area_2|city",postcode:"postal_code",country:"country_code"},_={city:"city",state:"state",postal_code:"postcode",country_code:"country"},A=function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return new Promise((function(r,n){!t||(0,a.isEmpty)(t)||(0,a.isEqual)(t,w)?window.paypal&&!P?r(window.paypal):(u.defaultHooks.addAction("paypalInstanceCreated","wcPPCP",(function(e){r(e)})),u.defaultHooks.addAction("paypalLoadError","wcPPCP",(function(){n()}))):(w=t,window.paypal&&u.defaultHooks.doAction("paypalInstanceCleanup",window.paypal),P=!0,d(h({},t)).then((function(e){r(e),u.defaultHooks.doAction("paypalInstanceCreated",e,w)})).catch((function(i){var a;console.log(i);var l,c=(null==i||null===(a=i.message)||void 0===a?void 0:a.toLowerCase())||null;if(c){if(c.includes("locale")){t.locale;var s=o(t,y);return e(s).then((function(e){r(e)}))}c.includes("client-id not recognized")||c.includes("invalid query value for client-id")?l={code:"invalid_client_id"}:c.includes("invalid query value for currency")}u.defaultHooks.doAction("paypalLoadError"),n(l)})).finally((function(){P=!1})))}))},k=function(e){return void 0!==window.wcPPCPSettings&&window.wcPPCPSettings[e]||{}},C=function(e,t){if(void 0!==window.wcPPCPSettings)return window.wcPPCPSettings[e]=t},I=function(){return k("queryParams")},x=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"billing";return"shipping"!=e.substring(0,"shipping".length)&&"billing"!=e.substring(0,"billing".length)&&(e="".concat(t,"_").concat(e)),c()('[name="'.concat(e,'"]')).length?c()('[name="'.concat(e,'"]')).val():O.get(e)},T=function(){var e={};return O.forEach((function(t,r){e[r]=t})),e},q=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"billing";r&&"shipping"!=e.substring(0,"shipping".length)&&"billing"!=e.substring(0,"billing".length)&&(e="".concat(r,"_").concat(e)),O.set(e,t),c()('[name="'.concat(e,'"]')).length&&c()('[name="'.concat(e,'"]')).val(t)},M=function(e){var t=k("errorMessages");return"string"==typeof e?e:null!=e&&e.code&&null!=t&&t[e.code]?t[e.code]:null!=e&&e.message?e.message:void 0},R=function(e,t){var r,n,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"checkout";if(null==e||null===(r=e.message)||void 0===r||null===(n=r.toLowerCase())||void 0===n||!n.match(/detected popup close|window is closed/)){var i=M(e),a="woocommerce-NoticeGroup",l=c()(t);"checkout"==o&&(a+=" woocommerce-NoticeGroup-checkout"),i=Array.isArray(e)?'<div class="'+a+'"><ul class="woocommerce-error"><li>'+e.join("</li><li>")+"</li></ul></div>":"string"==typeof e&&/<[^>]*>/.test(e)?'<div class="'+a+'">'+e+"</div>":'<div class="'+a+'"><ul class="woocommerce-error"><li>'+i+"</li></ul></div>",c()(".woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message").remove(),l.prepend(i),c().scroll_to_notices?c().scroll_to_notices(l):c()("html, body").animate({scrollTop:l.offset().top-100},1e3)}},D=function(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],o="undefined"==typeof wc_address_i18n_params?k("i18n"):wc_address_i18n_params;if((0,a.isEmpty)(e))return!1;if(j||(j=JSON.parse(o.locale.replace(/&quot;/g,'"'))),!e.country||(0,a.isEmpty)(e))return!1;var i=null!==(t=j)&&void 0!==t&&t[e.country]?j[e.country]:j.default;i=c().extend(!0,{},j.default,i);var l=Object.entries(i).filter((function(e){var t=n(e,2),o=t[0];return t[1],!r.includes(o)}));for(var u in i=Object.fromEntries(l)){var s;if(null!==(s=i[u])&&void 0!==s&&s.required){var d=(null==e?void 0:e[u])||null;if(!d||null==d||!d.trim())return!1}}return!0},N=function(e){var t={};for(var r in e)if(null!=S&&S[r])if(S[r].includes("|")){var o=n(S[r].split("|"),2),i=o[0];o[1],t[i]=e[r]}else t[S[r]]=e[r];return t},L=function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r={};r=t?_:Object.fromEntries(Object.entries(S).map((function(e){var t=n(e,2),r=t[0];return[t[1],r]})));var o={};for(var i in r)if(i.includes("|")){var a,l=i.split("|"),c=g(l);try{for(c.s();!(a=c.n()).done;){var u=a.value;if(e.hasOwnProperty(u)){o[r[i]]=e[u];break}o[r[i]]=""}}catch(e){c.e(e)}finally{c.f()}}else e.hasOwnProperty(i)?o[r[i]]=e[i]:o[r[i]]="";return o},H=function(e){var t;return!!(e=null===(t=e)||void 0===t?void 0:t.trim())},V=function(e){return H(x(e))},G=function(e){var t=e.match(E);return t?i({},t[1],t[2]):null},U=function(e){return[(e=e.trim()).split(" ").slice(0,-1).join(" "),e.split(" ").pop()]},B=function(e){var t,r,n;return(null===(t=k("generalData"))||void 0===t||null===(r=t.restRoutes)||void 0===r||null===(n=r[e])||void 0===n?void 0:n.url)||null},F=function(e){var t,r;return e=e.replace(/^\//,""),null===(t=k("generalData"))||void 0===t||null===(r=t.ajaxRestPath)||void 0===r?void 0:r.replace("%s",e)},$=function(){return k("generalData").page},J=function(){var e,t;return(null===(e=k("generalData"))||void 0===e||null===(t=e.clientId)||void 0===t?void 0:t.length)>0};(this.wcPPCP=this.wcPPCP||{}).utils=t})();
//# sourceMappingURL=utils.js.map