/*!
 * paypal-js v5.0.4 (2022-04-06T22:09:33.042Z)
 * Copyright 2020-present, PayPal, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
function n(n,t){void 0===t&&(t={});var r=document.createElement("script");return r.src=n,Object.keys(t).forEach((function(n){r.setAttribute(n,t[n]),"data-csp-nonce"===n&&r.setAttribute("nonce",t["data-csp-nonce"])})),r}function t(t,i){if(void 0===i&&(i=r()),o(t,i),"undefined"==typeof window)return i.resolve(null);var u=function(n){var t="https://www.paypal.com/sdk/js";n.sdkBaseURL&&(t=n.sdkBaseURL,delete n.sdkBaseURL),function(n){var t=n["merchant-id"],r=n["data-merchant-id"],e="",o="";Array.isArray(t)?t.length>1?(e="*",o=t.toString()):e=t.toString():"string"==typeof t&&t.length>0?e=t:"string"==typeof r&&r.length>0&&(e="*",o=r),n["merchant-id"]=e,n["data-merchant-id"]=o}(n);var r,e,o=Object.keys(n).filter((function(t){return null!=n[t]&&""!==n[t]})).reduce((function(t,r){var e=n[r].toString();return"data-"===r.substring(0,5)?t.dataAttributes[r]=e:t.queryParams[r]=e,t}),{queryParams:{},dataAttributes:{}}),i=o.queryParams,u=o.dataAttributes;return{url:"".concat(t,"?").concat((r=i,e="",Object.keys(r).forEach((function(n){0!==e.length&&(e+="&"),e+=n+"="+r[n]})),e)),dataAttributes:u}}(t),c=u.url,a=u.dataAttributes,f=a["data-namespace"]||"paypal",l=e(f);return function(t,r){var e=document.querySelector('script[src="'.concat(t,'"]'));if(null===e)return null;var o=n(t,r),i=e.cloneNode();if(delete i.dataset.uidAuto,Object.keys(i.dataset).length!==Object.keys(o.dataset).length)return null;var u=!0;return Object.keys(i.dataset).forEach((function(n){i.dataset[n]!==o.dataset[n]&&(u=!1)})),u?e:null}(c,a)&&l?i.resolve(l):function(t,e){void 0===e&&(e=r()),o(t,e);var i=t.url,u=t.attributes;if("string"!=typeof i||0===i.length)throw new Error("Invalid url.");if(void 0!==u&&"object"!=typeof u)throw new Error("Expected attributes to be an object.");return new e((function(t,r){if("undefined"==typeof window)return t();!function(t){var r=t.onSuccess,e=t.onError,o=n(t.url,t.attributes);o.onerror=e,o.onload=r,document.head.insertBefore(o,document.head.firstElementChild)}({url:i,attributes:u,onSuccess:function(){return t()},onError:function(){var n=new Error('The script "'.concat(i,'" failed to load.'));return window.fetch?fetch(i).then((function(t){return 200===t.status&&r(n),t.text()})).then((function(n){var t=function(n){var t=n.split("/* Original Error:")[1];return t?t.replace(/\n/g,"").replace("*/","").trim():n}(n);r(new Error(t))})).catch((function(n){r(n)})):r(n)}})}))}({url:c,attributes:a},i).then((function(){var n=e(f);if(n)return n;throw new Error("The window.".concat(f," global variable is not available."))}))}function r(){if("undefined"==typeof Promise)throw new Error("Promise is undefined. To resolve the issue, use a Promise polyfill.");return Promise}function e(n){return window[n]}function o(n,t){if("object"!=typeof n||null===n)throw new Error("Expected an options object.");if(void 0!==t&&"function"!=typeof t)throw new Error("Expected PromisePonyfill to be a function.")}const i=({clientId:n,reusable:t,merchantId:r,currency:e="usd",merchantInitiated:o})=>({"client-id":n.replace(/ /g,""),...!t||o?{"merchant-id":r.replace(/ /g,"")}:{},commit:!1,intent:t?"tokenize":"capture",vault:!0,currency:e?e.toUpperCase():"USD"});export{i as g,t as l}