/*! For license information please see subscription-edit-page.js.LICENSE.txt */
(()=>{var e={5338(e,t,r){"use strict";var n=r(5795);t.H=n.createRoot,n.hydrateRoot},1020(e,t,r){"use strict";var n=r(1609),o=Symbol.for("react.element"),a=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,c=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};function l(e,t,r){var n,a={},l=null,u=null;for(n in void 0!==r&&(l=""+r),void 0!==t.key&&(l=""+t.key),void 0!==t.ref&&(u=t.ref),t)s.call(t,n)&&!i.hasOwnProperty(n)&&(a[n]=t[n]);if(e&&e.defaultProps)for(n in t=e.defaultProps)void 0===a[n]&&(a[n]=t[n]);return{$$typeof:o,type:e,key:l,ref:u,props:a,_owner:c.current}}t.Fragment=a,t.jsx=l,t.jsxs=l},4848(e,t,r){"use strict";e.exports=r(1020)},1609(e){"use strict";e.exports=window.React},5795(e){"use strict";e.exports=window.ReactDOM}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var a=t[n]={exports:{}};return e[n](a,a.exports,r),a.exports}(()=>{var e;globalThis.importScripts&&(e=globalThis.location+"");var t=globalThis.document;if(!e&&t&&(t.currentScript&&"SCRIPT"===t.currentScript.tagName.toUpperCase()&&(e=t.currentScript.src),!e)){var n=t.getElementsByTagName("script");if(n.length)for(var o=n.length-1;o>-1&&(!e||!/^http(s?):/.test(e));)e=n[o--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),r.p=e})(),r.p=window.wcpayAssets.url,(()=>{"use strict";var e=r(1609),t=r(5338);const n=window.wp.i18n;var o=r(4848);const a=new Map,s=(e,t)=>`${e}-${t}`,c=(e,t)=>{const r=s(e,t),n=a.get(r);if(void 0===n)return 0;const o=n.find(e=>e.isDefault);return void 0!==o?o.tokenId:0},i=({inputName:t,initialValue:r,initialUserId:i,nonce:l,ajaxUrl:u,gatewayId:p})=>{const[d,m]=(0,e.useState)(r),[f,y]=(0,e.useState)(i),[w,_]=(0,e.useState)(!1),[h,g]=(0,e.useState)(null);return(0,e.useEffect)(()=>(()=>{const e=document.getElementById("customer_user"),t=e instanceof HTMLSelectElement?e:null;if(!t)return()=>{};const r=async()=>{(async e=>{const t=s(e,p),r=c(e,p);if(m(r),y(e),!a.has(t)){_(!0);try{const o=await(async(e,t,r,o)=>{const a=new FormData;a.append("action","wcpay_get_user_payment_tokens"),a.append("nonce",r),a.append("user_id",e.toString()),a.append("gateway_id",o);const s=await fetch(t,{method:"POST",body:a});if(!s.ok)throw new Error((0,n.__)("Failed to fetch user tokens","woocommerce-payments"));const c=(await s.json()).data;if(void 0===c)throw new Error((0,n.__)("Failed to fetch user tokens. Please reload the page and try again.","woocommerce-payments"));return c.tokens})(e,u,l,p);a.set(t,o);const s=c(e,p);r!==s&&m(s),_(!1),g(null)}catch(e){_(!1),g(e instanceof Error?e.message:(0,n.__)("Unknown error","woocommerce-payments"))}}})(parseInt(t.value,10)||0)};return jQuery(t).on("select2:select",r),t.addEventListener("change",r),()=>{jQuery(t).off("select2:select",r),t.removeEventListener("change",r)}})(),[u,l,p]),f<=0?(0,o.jsx)("select",{name:t,defaultValue:0,children:(0,o.jsx)("option",{value:0,disabled:!0,children:(0,n.__)("Please select a customer first","woocommerce-payments")},"no-customer")},"no-customer"):w?(0,o.jsx)(o.Fragment,{children:(0,n.__)("Loading…","woocommerce-payments")}):h?(0,o.jsx)("strong",{children:h}):(0,o.jsxs)("select",{name:t,defaultValue:d,children:[0===d&&(0,o.jsx)("option",{value:0,disabled:!0,children:(0,n.__)("Please select a payment method","woocommerce-payments")},"select"),a.get(s(f,p))?.map(e=>(0,o.jsx)("option",{value:e.tokenId,children:e.displayName},e.tokenId))]},f)};document.querySelectorAll(".wcpay-subscription-payment-method").forEach(e=>{(e=>{const r=JSON.parse(e.getAttribute("data-wcpay-pm-selector")||"{}"),n=r.userId??0,c=r.value??0,l=r.gatewayId??"woocommerce_payments";n&&a.set(s(n,l),r.tokens??[]);const u=e.querySelector("select,input");u&&(u instanceof HTMLSelectElement||u instanceof HTMLInputElement)&&(0,t.H)(e).render((0,o.jsx)(i,{inputName:u.name,initialValue:c,initialUserId:n,nonce:r.nonce,ajaxUrl:r.ajaxUrl,gatewayId:l}))})(e)})})()})();