File: //proc/thread-self/cwd/wp-content/plugins/woocommerce-payments/dist/subscription-edit-page.js
(()=>{var e={5338:(e,t,n)=>{"use strict";var o=n(5795);t.H=o.createRoot,o.hydrateRoot},5795:e=>{"use strict";e.exports=window.ReactDOM}},t={};function n(o){var r=t[o];if(void 0!==r)return r.exports;var a=t[o]={exports:{}};return e[o](a,a.exports,n),a.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e;n.g.importScripts&&(e=n.g.location+"");var t=n.g.document;if(!e&&t&&(t.currentScript&&(e=t.currentScript.src),!e)){var o=t.getElementsByTagName("script");if(o.length)for(var r=o.length-1;r>-1&&(!e||!/^http(s?):/.test(e));)e=o[r--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),n.p=e})(),n.p=window.wcpayAssets.url,(()=>{"use strict";const e=window.React;var t=n.n(e),o=n(5338);const r=window.wp.i18n;var a=function(e,t,n,o){return new(n||(n=Promise))((function(r,a){function c(e){try{s(o.next(e))}catch(e){a(e)}}function i(e){try{s(o.throw(e))}catch(e){a(e)}}function s(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,i)}s((o=o.apply(e,t||[])).next())}))};const c=new Map,i=e=>{const t=c.get(e);if(void 0===t)return 0;const n=t.find((e=>e.isDefault));return void 0!==n?n.tokenId:0},s=({inputName:n,initialValue:o,initialUserId:s,nonce:l,ajaxUrl:u})=>{var d;const[p,m]=(0,e.useState)(o),[f,v]=(0,e.useState)(s),[y,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 n=()=>a(void 0,void 0,void 0,(function*(){var e;e=parseInt(t.value,10)||0,a(void 0,void 0,void 0,(function*(){const t=i(e);if(m(t),v(e),!c.has(e)){w(!0);try{const n=yield((e,t,n)=>a(void 0,void 0,void 0,(function*(){const o=new FormData;o.append("action","wcpay_get_user_payment_tokens"),o.append("nonce",n),o.append("user_id",e.toString());const a=yield fetch(t,{method:"POST",body:o});if(!a.ok)throw new Error((0,r.__)("Failed to fetch user tokens","woocommerce-payments"));const c=(yield a.json()).data;if(void 0===c)throw new Error((0,r.__)("Failed to fetch user tokens. Please reload the page and try again.","woocommerce-payments"));return c.tokens})))(e,u,l);c.set(e,n);const o=i(e);t!==o&&m(o),w(!1),g(null)}catch(e){w(!1),g(e instanceof Error?e.message:(0,r.__)("Unknown error","woocommerce-payments"))}}}))}));return jQuery(t).on("select2:select",n),t.addEventListener("change",n),()=>{jQuery(t).off("select2:select",n),t.removeEventListener("change",n)}})()),[u,l]),f<=0?t().createElement("select",{name:n,defaultValue:0,key:"no-customer"},t().createElement("option",{value:0,key:"no-customer",disabled:!0},(0,r.__)("Please select a customer first","woocommerce-payments"))):y?t().createElement(t().Fragment,null,(0,r.__)("Loading…","woocommerce-payments")):h?t().createElement("strong",null,h):t().createElement("select",{name:n,defaultValue:p,key:f},0===p&&t().createElement("option",{value:0,key:"select",disabled:!0},(0,r.__)("Please select a payment method","woocommerce-payments")),null===(d=c.get(f))||void 0===d?void 0:d.map((e=>t().createElement("option",{value:e.tokenId,key:e.tokenId},e.displayName))))};document.querySelectorAll(".wcpay-subscription-payment-method").forEach((e=>{(e=>{var n,r,a;const i=JSON.parse(e.getAttribute("data-wcpay-pm-selector")||"{}"),l=null!==(n=i.userId)&&void 0!==n?n:0,u=null!==(r=i.value)&&void 0!==r?r:0;l&&c.set(l,null!==(a=i.tokens)&&void 0!==a?a:[]);const d=e.querySelector("select,input");d&&(d instanceof HTMLSelectElement||d instanceof HTMLInputElement)&&(0,o.H)(e).render(t().createElement(s,{inputName:d.name,initialValue:u,initialUserId:l,nonce:i.nonce,ajaxUrl:i.ajaxUrl}))})(e)}))})()})();