(()=>{var e={n:t=>{var s=t&&t.__esModule?()=>t.default:()=>t;return e.d(s,{a:s}),s},d:(t,s)=>{for(var o in s)e.o(s,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:s[o]})}};e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var t;e.g.importScripts&&(t=e.g.location+"");var s=e.g.document;if(!t&&s&&(s.currentScript&&(t=s.currentScript.src),!t)){var o=s.getElementsByTagName("script");o.length&&(t=o[o.length-1].src)}if(!t)throw new Error("Automatic publicPath is not supported in this browser");t=t.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),e.p=t})(),e.p=window.wcpayAssets.url,(()=>{"use strict";window.wp.domReady;const t=e=>"undefined"!=typeof wcpayConfig?wcpayConfig[e]:s(e),s=e=>{let t=null;if("undefined"!=typeof wcpay_upe_config)t=wcpay_upe_config;else{if("object"!=typeof wc||void 0===wc.wcSettings)return null;t=wc.wcSettings.getSetting("woocommerce_payments_data")||{}}return t[e]||null},o=e=>(e=>"object"==typeof wcpayExpressCheckoutParams&&wcpayExpressCheckoutParams.hasOwnProperty(e)?wcpayExpressCheckoutParams[e]:"object"==typeof wcpayPaymentRequestParams&&wcpayPaymentRequestParams.hasOwnProperty(e)?wcpayPaymentRequestParams[e]:null)(e),n=function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"wcpay_";return e.toString().replace("%%endpoint%%",s+t)};const a=()=>{return e=void 0,s=void 0,a=function*(){var e,s,n;let a=(()=>{const e=document.cookie.split(";");for(let t=0;t<e.length;t++){let s=e[t];for(;" "===s.charAt(0);)s=s.substring(1,s.length);if(0===s.indexOf("tk_ai="))return s.substring(6,s.length)}})();if(a){const e={_ut:"anon",_ui:a};return JSON.stringify(e)}const i=null!==(e=t("platformTrackerNonce"))&&void 0!==e?e:null===(s=o("nonce"))||void 0===s?void 0:s.platform_tracker,r=null!==(n=t("ajaxUrl"))&&void 0!==n?n:o("ajax_url"),c=new FormData;c.append("tracksNonce",i),c.append("action","get_identity");try{const e=yield fetch(r,{method:"post",body:c});if(!e.ok)return;const t=yield e.json();return t.success&&t.data&&t.data._ui&&t.data._ut?JSON.stringify(t.data):void 0}catch(e){return}},new((n=void 0)||(n=Promise))((function(t,o){function i(e){try{c(a.next(e))}catch(e){o(e)}}function r(e){try{c(a.throw(e))}catch(e){o(e)}}function c(e){var s;e.done?t(e.value):(s=e.value,s instanceof n?s:new n((function(e){e(s)}))).then(i,r)}c((a=a.apply(e,s||[])).next())}));var e,s,n,a};function i(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",s=arguments.length>2?arguments[2]:void 0;for(const o in e){const n=e[o],a=t?t+"["+o+"]":o;"string"==typeof n||"number"==typeof n?s.append(a,n):"object"==typeof n&&i(n,a,s)}return s}async function r(e,t,s){const o=i(t,"",new FormData),n=await fetch(e,{method:"POST",body:o,...s});return await n.json()}const c=window.wp.element,l=window.React,d=window.wp.i18n;function u(e){window.WooPayConnect||(window.WooPayConnect={}),window.WooPayConnect.iframeInjectedState=e}function h(){return window?.WooPayConnect?.postMessageTimeout||5e3}const y=()=>{const e=(0,l.useRef)(),[s,o]=(0,l.useState)("");return(0,l.useEffect)((()=>{(async()=>{const e=t("testMode"),s=t("woopayHost"),n=t("woopayMerchantId"),i=new URLSearchParams({testMode:e,source_url:window.location.href,blogId:n}),r=await a();r&&i.append("tracksUserIdentity",r),o(`${s}/connect/?${i.toString()}`)})()}),[]),(0,l.useEffect)((()=>{if(!e.current)return;const s=e.current;s.addEventListener("load",(()=>{u(2),window.dispatchEvent(new MessageEvent("message",{source:window,origin:t("woopayHost"),data:{action:"get_iframe_post_message_success",value:e=>s.contentWindow.postMessage(e,t("woopayHost"))}}))}))}),[s]),(0,c.createElement)("iframe",{ref:e,id:"woopay-connect-iframe",src:s,style:{height:0,width:0,border:"none",margin:0,padding:0,overflow:"hidden",display:"block",visibility:"hidden",position:"fixed",pointerEvents:"none",userSelect:"none"},title:(0,d.__)("WooPay Connect Direct Checkout","woocommerce-payments")})},p=window.ReactDOM;var m=e.n(p);const w=class{iframePostMessage=null;listeners={};constructor(){this.listeners={getIframePostMessageCallback:()=>{},getPostMessageTimeoutCallback:()=>{}},this.removeMessageListener=this.attachMessageListener(),this.injectWooPayConnectIframe()}attachMessageListener(){const e=e=>{t("woopayHost").startsWith(e.origin)&&this.callbackFn(e.data)};return window.addEventListener("message",e),()=>{window.removeEventListener("message",e)}}detachMessageListener(){"function"==typeof this.removeMessageListener&&this.removeMessageListener()}injectWooPayConnectIframe(){const e=window?.WooPayConnect?.iframeInjectedState||0;if(2===e){const e=document.querySelector("#woopay-connect-iframe");return void(e&&(this.iframePostMessage=Promise.resolve((s=>{e.contentWindow.postMessage(s,t("woopayHost"))}))))}if(1===e)return void(this.iframePostMessage=new Promise((e=>{this.listeners.getIframePostMessageCallback=e})));u(1);const s=document.createElement("div");s.style.visibility="hidden",s.style.position="fixed",s.style.height="0",s.style.width="0",s.style.bottom="0",s.style.right="0",s.id="woopay-connect-iframe-container",document.body.appendChild(s);const o=this;this.iframePostMessage=new Promise((e=>{o.listeners.getIframePostMessageCallback=e})),m().render((0,c.createElement)(y,null),s)}injectTemporaryWooPayConnectIframe(){let e;const s=new Promise((t=>{e=t})),o=document.createElement("iframe");return o.id="temp-woopay-connect-iframe",o.src=t("woopayHost")+"/connect/",o.height=0,o.width=0,o.border="none",o.margin=0,o.padding=0,o.overflow="hidden",o.display="block",o.visibility="hidden",o.position="fixed",o.pointerEvents="none",o.userSelect="none",o.addEventListener("load",(()=>{e((e=>o.contentWindow.postMessage(e,t("woopayHost"))))})),document.body.appendChild(o),{resolvePostMessagePromise:s,removeTemporaryIframe:()=>{document.body.removeChild(o)}}}async sendMessageAndListenWith(e,t){const s=new Promise(((e,s)=>{let o=!1;const n=setTimeout((()=>{o=!0,s(new Error("WooPayConnectIframe did not respond within the allotted time."))}),h());this.listeners[t]=t=>{o||(n&&clearTimeout(n),e(t))}}));if("function"!=typeof this.iframePostMessage?.then)throw new Error("iframePostMessage is not set");return(await this.iframePostMessage)(e),await s}async getPostMessageTimeout(){try{return await this.sendMessageAndListenWith({action:"getPostMessageTimeout"},"getPostMessageTimeoutCallback")}catch(e){return null}}callbackFn(e){switch(e.action){case"get_iframe_post_message_success":this.listeners.getIframePostMessageCallback(e.value);break;case"get_post_message_timeout_success":this.listeners.getPostMessageTimeoutCallback(e.value)}}},g=class extends w{constructor(){super(),this.listeners={...this.listeners,getIsUserLoggedInCallback:()=>{},getEncryptedDataCallback:()=>{}}}async isUserLoggedIn(){try{return await this.sendMessageAndListenWith({action:"getIsUserLoggedIn"},"getIsUserLoggedInCallback")}catch(e){return!1}}async getEncryptedData(){try{return await this.sendMessageAndListenWith({action:"getEncryptedData"},"getEncryptedDataCallback")}catch(e){return null}}callbackFn(e){switch(super.callbackFn(e),e.action){case"get_is_user_logged_in_success":this.listeners.getIsUserLoggedInCallback(e.value);break;case"get_encrypted_data_success":this.listeners.getEncryptedDataCallback(e.value)}}},_=class extends w{constructor(){super(),this.listeners={...this.listeners,setRedirectSessionDataCallback:()=>{},setTempThirdPartyCookieCallback:()=>{},getIsWooPayReachableCallback:()=>{},getIsThirdPartyCookiesEnabledCallback:()=>{},setPreemptiveSessionDataCallback:()=>{}}}async isWooPayThirdPartyCookiesEnabled(){const{resolvePostMessagePromise:e,removeTemporaryIframe:t}=this.injectTemporaryWooPayConnectIframe(),s=new Promise(((e,t)=>{let s=!1;const o=setTimeout((()=>{s=!0,t(new Error("WooPayConnectIframe did not respond within the allotted time."))}),h());this.listeners.setTempThirdPartyCookieCallback=t=>{s||(o&&clearTimeout(o),e(t))}}));if("function"!=typeof e?.then)return!1;const o=await e;o({action:"setTempThirdPartyCookie"});try{if(!await s)return t(),!1}catch(e){return t(),!1}const n=new Promise(((e,t)=>{let s=!1;const o=setTimeout((()=>{s=!0,t(new Error("WooPayConnectIframe did not respond within the allotted time."))}),h());this.listeners.getIsThirdPartyCookiesEnabledCallback=t=>{s||(o&&clearTimeout(o),e(t))}}));o({action:"getIsThirdPartyCookiesEnabled"});try{return await n}catch(e){return!1}finally{t()}}async sendRedirectSessionDataToWooPay(e){try{return await super.sendMessageAndListenWith({action:"setRedirectSessionData",value:e},"setRedirectSessionDataCallback")}catch(e){return null}}async setPreemptiveSessionData(e){try{return await super.sendMessageAndListenWith({action:"setPreemptiveSessionData",value:e},"setPreemptiveSessionDataCallback")}catch(e){return null}}async isWooPayReachable(){try{return await this.sendMessageAndListenWith({action:"isWooPayReachable"},"getIsWooPayReachableCallback")}catch(e){return!1}}callbackFn(e){switch(super.callbackFn(e),e.action){case"set_redirect_session_data_success":this.listeners.setRedirectSessionDataCallback(e.value);break;case"set_redirect_session_data_error":this.listeners.setRedirectSessionDataCallback({is_error:!0});break;case"set_temp_third_party_cookie_success":this.listeners.setTempThirdPartyCookieCallback(e.value);break;case"get_is_third_party_cookies_enabled_success":this.listeners.getIsThirdPartyCookiesEnabledCallback(e.value);break;case"get_is_woopay_reachable_success":this.listeners.getIsWooPayReachableCallback(e.value);break;case"set_preemptive_session_data_success":this.listeners.setPreemptiveSessionDataCallback(e.value);break;case"set_preemptive_session_data_error":this.listeners.setPreemptiveSessionDataCallback({is_error:!0})}}},f=class{static userConnect;static sessionConnect;static encryptedSessionDataPromise;static redirectElements={CLASSIC_CART_PROCEED_BUTTON:".wc-proceed-to-checkout .checkout-button",BLOCKS_CART_PROCEED_BUTTON:".wp-block-woocommerce-proceed-to-checkout-block",BLOCKS_MINI_CART_PROCEED_BUTTON:"a.wp-block-woocommerce-mini-cart-checkout-button-block",CLASSIC_MINI_CART_PROCEED_BUTTON:".widget_shopping_cart a.button.checkout"};static init(){this.getSessionConnect()}static getUserConnect(){return this.userConnect||(this.userConnect=new g),this.userConnect}static getSessionConnect(){return this.sessionConnect||(this.sessionConnect=new _),this.sessionConnect}static teardown(){this.sessionConnect?.detachMessageListener(),this.userConnect?.detachMessageListener(),this.sessionConnect=null,this.userConnect=null}static isWooPayDirectCheckoutEnabled(){return t("isWooPayDirectCheckoutEnabled")}static async isWooPayReachable(){return this.getSessionConnect().isWooPayReachable()}static async isUserLoggedIn(){return this.getUserConnect().isUserLoggedIn()}static async getEncryptedData(){return this.getUserConnect().getEncryptedData()}static async isWooPayThirdPartyCookiesEnabled(){return this.getSessionConnect().isWooPayThirdPartyCookiesEnabled()}static async initPostMessageTimeout(){const e=await this.getSessionConnect().getPostMessageTimeout();var t;e&&(t=e,window.WooPayConnect||(window.WooPayConnect={}),window.WooPayConnect.postMessageTimeout=t)}static async getWooPayCheckoutUrl(){try{let e;if(e=this.isEncryptedSessionDataPrefetched()?await this.encryptedSessionDataPromise:await this.getEncryptedSessionData(),!this.isValidEncryptedSessionData(e))throw new Error("Could not retrieve encrypted session data from store.");const t=await this.getSessionConnect().sendRedirectSessionDataToWooPay(e);if(!t?.redirect_url)throw new Error("Could not retrieve WooPay checkout URL.");const{redirect_url:s}=t;if(!this.validateRedirectUrl(s,"platform_checkout_key"))throw new Error("Invalid WooPay session URL: "+s);return t.redirect_url}catch(e){throw new Error(e.message)}}static isValidEncryptedSessionData(e){return e&&e?.blog_id&&e?.data?.session&&e?.data?.iv&&e?.data?.hash}static async getWooPayMinimumSessionUrl(){const e=await this.getWooPayMinimumSesssionDataFromMerchant();if(!1===e?.success)throw new Error("Could not retrieve redirect data from merchant.");if(!this.isValidEncryptedSessionData(e))throw new Error("Invalid encrypted session data.");const{blog_id:s,data:{session:o,iv:n,hash:a}}=e,i=new URLSearchParams({checkout_redirect:1,blog_id:s,session:o,iv:n,hash:a});return t("woopayHost")+"/woopay/?"+i.toString()}static getCheckoutButtonElements(){const e=[],t=t=>{const s=document.querySelector(t);s&&e.push(s)};return t(this.redirectElements.CLASSIC_CART_PROCEED_BUTTON),t(this.redirectElements.BLOCKS_CART_PROCEED_BUTTON),t(this.redirectElements.CLASSIC_MINI_CART_PROCEED_BUTTON),e}static getClassicProceedToCheckoutButton(){return document.querySelector(this.redirectElements.CLASSIC_CART_PROCEED_BUTTON)}static getMiniCartProceedToCheckoutButton(){return document.querySelector(this.redirectElements.BLOCKS_MINI_CART_PROCEED_BUTTON)}static addRedirectToWooPayEventListener(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];e.forEach((e=>{const s={is_loading:!1};e.addEventListener("click",(async o=>{if(s.is_loading)return void o.preventDefault();let n;if(s.is_loading=!0,(e=>{if(e.classList.contains("wp-block-woocommerce-mini-cart-checkout-button-block"))return!0;const t=e.classList.contains("checkout-button"),s=e.parentElement?.classList?.contains("wc-proceed-to-checkout");return t&&s})(e)&&(e=>{const t=document.createElement("span");t.classList.add("wc-block-components-spinner"),t.style.position="relative",t.style.fontSize="unset",t.style.display="inline",t.style.lineHeight="0",t.style.margin="0",t.style.border="0",t.style.padding="0",e.innerHTML="&nbsp;",e.classList.remove("wc-forward"),e.appendChild(t)})(e),n="a"===e.tagName.toLowerCase()?e.href:e.querySelector("a")?.href,n){o.preventDefault();try{let e="";if(t)e=await this.getWooPayCheckoutUrl();else{if(!await this.isWooPayReachable())throw new Error("WooPay is currently not available.");e=await this.getWooPayMinimumSessionUrl()}this.teardown(),window.location.href=e}catch(e){console.warn(e),this.teardown(),window.location.href=n}}else this.teardown()}))}))}static async getEncryptedSessionData(){const e=await this.getEncryptedData();return r(n(t("wcAjaxUrl"),"get_woopay_session"),{_ajax_nonce:t("woopaySessionNonce"),...e&&{encrypted_data:e}})}static async getWooPayMinimumSesssionDataFromMerchant(){return t("woopayMinimumSessionData")?t("woopayMinimumSessionData"):r(n(t("wcAjaxUrl"),"get_woopay_minimum_session_data"),{_ajax_nonce:t("woopaySessionNonce")})}static validateRedirectUrl(e,s){try{const o=new URL(e);return!(o.origin!==t("woopayHost")||!o.searchParams.has(s))}catch(e){return!1}}static maybePrefetchEncryptedSessionData(){const e=window?.wcpayWooPayDirectCheckout?.params?.is_product_page;void 0===e||e||(this.encryptedSessionDataPromise=new Promise((e=>{e(this.getEncryptedSessionData())})))}static setEncryptedSessionDataAsNotPrefetched(){this.encryptedSessionDataPromise=null}static isEncryptedSessionDataPrefetched(){return"function"==typeof this.encryptedSessionDataPromise?.then}},C=()=>{const e=document.cookie.split(";").find((e=>e.includes("skip_woopay")));if(!e)return!1;const t=e?.split("=");return"skip_woopay"===t[0].trim()&&"1"===t[1].trim()},P=()=>{!function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};var n,a,i;const r=null!==(n=t("platformTrackerNonce"))&&void 0!==n?n:null===(a=o("nonce"))||void 0===a?void 0:a.platform_tracker,c=null!==(i=t("ajaxUrl"))&&void 0!==i?i:o("ajax_url"),l=new FormData;l.append("tracksNonce",r),l.append("action","platform_tracks"),l.append("tracksEventName",e),l.append("tracksEventProp",JSON.stringify(s)),fetch(c,{method:"post",body:l})}("wcpay_proceed_to_checkout_button_click",{woopay_direct_checkout:Boolean(t("isWooPayDirectCheckoutEnabled"))&&!C()})};window.addEventListener("load",(()=>{Object.values(f.redirectElements).forEach((e=>{const t=document.querySelector(e);t&&t.addEventListener("click",P)})),(()=>{const e=document.querySelector(".cart-collaterals");e&&new MutationObserver((()=>{const e=document.querySelector(f.redirectElements.CLASSIC_CART_PROCEED_BUTTON);e&&e.addEventListener("click",P)})).observe(e,{childList:!0,subtree:!0})})()}))})()})();