@movmo_app/payments 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var Jt=Object.defineProperty;var Zt=(t,r,n)=>r in t?Jt(t,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[r]=n;var at=(t,r,n)=>Zt(t,typeof r!="symbol"?r+"":r,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react");var ct={exports:{}},Ve={};/**
1
+ "use strict";var Jt=Object.defineProperty;var Zt=(t,r,s)=>r in t?Jt(t,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[r]=s;var lt=(t,r,s)=>Zt(t,typeof r!="symbol"?r+"":r,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react");var pt={exports:{}},qe={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.min.js
4
4
  *
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var gt;function Xt(){if(gt)return Ve;gt=1;var t=s,r=Symbol.for("react.element"),n=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,l=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,c={key:!0,ref:!0,__self:!0,__source:!0};function f(g,m,S){var v,w={},p=null,j=null;S!==void 0&&(p=""+S),m.key!==void 0&&(p=""+m.key),m.ref!==void 0&&(j=m.ref);for(v in m)o.call(m,v)&&!c.hasOwnProperty(v)&&(w[v]=m[v]);if(g&&g.defaultProps)for(v in m=g.defaultProps,m)w[v]===void 0&&(w[v]=m[v]);return{$$typeof:r,type:g,key:p,ref:j,props:w,_owner:l.current}}return Ve.Fragment=n,Ve.jsx=f,Ve.jsxs=f,Ve}var qe={};/**
9
+ */var wt;function Xt(){if(wt)return qe;wt=1;var t=n,r=Symbol.for("react.element"),s=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,l=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,c={key:!0,ref:!0,__self:!0,__source:!0};function f(x,m,R){var w,p={},v=null,E=null;R!==void 0&&(v=""+R),m.key!==void 0&&(v=""+m.key),m.ref!==void 0&&(E=m.ref);for(w in m)o.call(m,w)&&!c.hasOwnProperty(w)&&(p[w]=m[w]);if(x&&x.defaultProps)for(w in m=x.defaultProps,m)p[w]===void 0&&(p[w]=m[w]);return{$$typeof:r,type:x,key:v,ref:E,props:p,_owner:l.current}}return qe.Fragment=s,qe.jsx=f,qe.jsxs=f,qe}var Ke={};/**
10
10
  * @license React
11
11
  * react-jsx-runtime.development.js
12
12
  *
@@ -14,18 +14,18 @@
14
14
  *
15
15
  * This source code is licensed under the MIT license found in the
16
16
  * LICENSE file in the root directory of this source tree.
17
- */var bt;function Qt(){return bt||(bt=1,process.env.NODE_ENV!=="production"&&function(){var t=s,r=Symbol.for("react.element"),n=Symbol.for("react.portal"),o=Symbol.for("react.fragment"),l=Symbol.for("react.strict_mode"),c=Symbol.for("react.profiler"),f=Symbol.for("react.provider"),g=Symbol.for("react.context"),m=Symbol.for("react.forward_ref"),S=Symbol.for("react.suspense"),v=Symbol.for("react.suspense_list"),w=Symbol.for("react.memo"),p=Symbol.for("react.lazy"),j=Symbol.for("react.offscreen"),W=Symbol.iterator,ee="@@iterator";function C(e){if(e===null||typeof e!="object")return null;var i=W&&e[W]||e[ee];return typeof i=="function"?i:null}var P=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function E(e){{for(var i=arguments.length,d=new Array(i>1?i-1:0),y=1;y<i;y++)d[y-1]=arguments[y];ae("error",e,d)}}function ae(e,i,d){{var y=P.ReactDebugCurrentFrame,F=y.getStackAddendum();F!==""&&(i+="%s",d=d.concat([F]));var M=d.map(function(R){return String(R)});M.unshift("Warning: "+i),Function.prototype.apply.call(console[e],console,M)}}var X=!1,de=!1,ye=!1,q=!1,ne=!1,x;x=Symbol.for("react.module.reference");function se(e){return!!(typeof e=="string"||typeof e=="function"||e===o||e===c||ne||e===l||e===S||e===v||q||e===j||X||de||ye||typeof e=="object"&&e!==null&&(e.$$typeof===p||e.$$typeof===w||e.$$typeof===f||e.$$typeof===g||e.$$typeof===m||e.$$typeof===x||e.getModuleId!==void 0))}function Ce(e,i,d){var y=e.displayName;if(y)return y;var F=i.displayName||i.name||"";return F!==""?d+"("+F+")":d}function ve(e){return e.displayName||"Context"}function T(e){if(e==null)return null;if(typeof e.tag=="number"&&E("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case o:return"Fragment";case n:return"Portal";case c:return"Profiler";case l:return"StrictMode";case S:return"Suspense";case v:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case g:var i=e;return ve(i)+".Consumer";case f:var d=e;return ve(d._context)+".Provider";case m:return Ce(e,e.render,"ForwardRef");case w:var y=e.displayName||null;return y!==null?y:T(e.type)||"Memo";case p:{var F=e,M=F._payload,R=F._init;try{return T(R(M))}catch{return null}}}return null}var b=Object.assign,h=0,k,A,Z,ue,K,Y,I;function O(){}O.__reactDisabledLog=!0;function L(){{if(h===0){k=console.log,A=console.info,Z=console.warn,ue=console.error,K=console.group,Y=console.groupCollapsed,I=console.groupEnd;var e={configurable:!0,enumerable:!0,value:O,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}h++}}function fe(){{if(h--,h===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:b({},e,{value:k}),info:b({},e,{value:A}),warn:b({},e,{value:Z}),error:b({},e,{value:ue}),group:b({},e,{value:K}),groupCollapsed:b({},e,{value:Y}),groupEnd:b({},e,{value:I})})}h<0&&E("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ce=P.ReactCurrentDispatcher,Q;function je(e,i,d){{if(Q===void 0)try{throw Error()}catch(F){var y=F.stack.trim().match(/\n( *(at )?)/);Q=y&&y[1]||""}return`
18
- `+Q+e}}var ke=!1,me;{var oe=typeof WeakMap=="function"?WeakMap:Map;me=new oe}function xe(e,i){if(!e||ke)return"";{var d=me.get(e);if(d!==void 0)return d}var y;ke=!0;var F=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var M;M=ce.current,ce.current=null,L();try{if(i){var R=function(){throw Error()};if(Object.defineProperty(R.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(R,[])}catch(le){y=le}Reflect.construct(e,[],R)}else{try{R.call()}catch(le){y=le}e.call(R.prototype)}}else{try{throw Error()}catch(le){y=le}e()}}catch(le){if(le&&y&&typeof le.stack=="string"){for(var _=le.stack.split(`
19
- `),re=y.stack.split(`
20
- `),U=_.length-1,B=re.length-1;U>=1&&B>=0&&_[U]!==re[B];)B--;for(;U>=1&&B>=0;U--,B--)if(_[U]!==re[B]){if(U!==1||B!==1)do if(U--,B--,B<0||_[U]!==re[B]){var he=`
21
- `+_[U].replace(" at new "," at ");return e.displayName&&he.includes("<anonymous>")&&(he=he.replace("<anonymous>",e.displayName)),typeof e=="function"&&me.set(e,he),he}while(U>=1&&B>=0);break}}}finally{ke=!1,ce.current=M,fe(),Error.prepareStackTrace=F}var Oe=e?e.displayName||e.name:"",Pe=Oe?je(Oe):"";return typeof e=="function"&&me.set(e,Pe),Pe}function ge(e,i,d){return xe(e,!1)}function _e(e){var i=e.prototype;return!!(i&&i.isReactComponent)}function G(e,i,d){if(e==null)return"";if(typeof e=="function")return xe(e,_e(e));if(typeof e=="string")return je(e);switch(e){case S:return je("Suspense");case v:return je("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case m:return ge(e.render);case w:return G(e.type,i,d);case p:{var y=e,F=y._payload,M=y._init;try{return G(M(F),i,d)}catch{}}}return""}var be=Object.prototype.hasOwnProperty,Re={},pe=P.ReactDebugCurrentFrame;function we(e){if(e){var i=e._owner,d=G(e.type,e._source,i?i.type:null);pe.setExtraStackFrame(d)}else pe.setExtraStackFrame(null)}function N(e,i,d,y,F){{var M=Function.call.bind(be);for(var R in e)if(M(e,R)){var _=void 0;try{if(typeof e[R]!="function"){var re=Error((y||"React class")+": "+d+" type `"+R+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[R]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw re.name="Invariant Violation",re}_=e[R](i,R,y,d,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(U){_=U}_&&!(_ instanceof Error)&&(we(F),E("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",y||"React class",d,R,typeof _),we(null)),_ instanceof Error&&!(_.message in Re)&&(Re[_.message]=!0,we(F),E("Failed %s type: %s",d,_.message),we(null))}}}var D=Array.isArray;function V(e){return D(e)}function ie(e){{var i=typeof Symbol=="function"&&Symbol.toStringTag,d=i&&e[Symbol.toStringTag]||e.constructor.name||"Object";return d}}function He(e){try{return Je(e),!1}catch{return!0}}function Je(e){return""+e}function Fe(e){if(He(e))return E("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",ie(e)),Je(e)}var Le=P.ReactCurrentOwner,Ze={key:!0,ref:!0,__self:!0,__source:!0},ze,Se;function Be(e){if(be.call(e,"ref")){var i=Object.getOwnPropertyDescriptor(e,"ref").get;if(i&&i.isReactWarning)return!1}return e.ref!==void 0}function Ye(e){if(be.call(e,"key")){var i=Object.getOwnPropertyDescriptor(e,"key").get;if(i&&i.isReactWarning)return!1}return e.key!==void 0}function We(e,i){typeof e.ref=="string"&&Le.current}function et(e,i){{var d=function(){ze||(ze=!0,E("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",i))};d.isReactWarning=!0,Object.defineProperty(e,"key",{get:d,configurable:!0})}}function tt(e,i){{var d=function(){Se||(Se=!0,E("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",i))};d.isReactWarning=!0,Object.defineProperty(e,"ref",{get:d,configurable:!0})}}var u=function(e,i,d,y,F,M,R){var _={$$typeof:r,type:e,key:i,ref:d,props:R,_owner:M};return _._store={},Object.defineProperty(_._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(_,"_self",{configurable:!1,enumerable:!1,writable:!1,value:y}),Object.defineProperty(_,"_source",{configurable:!1,enumerable:!1,writable:!1,value:F}),Object.freeze&&(Object.freeze(_.props),Object.freeze(_)),_};function H(e,i,d,y,F){{var M,R={},_=null,re=null;d!==void 0&&(Fe(d),_=""+d),Ye(i)&&(Fe(i.key),_=""+i.key),Be(i)&&(re=i.ref,We(i,F));for(M in i)be.call(i,M)&&!Ze.hasOwnProperty(M)&&(R[M]=i[M]);if(e&&e.defaultProps){var U=e.defaultProps;for(M in U)R[M]===void 0&&(R[M]=U[M])}if(_||re){var B=typeof e=="function"?e.displayName||e.name||"Unknown":e;_&&et(R,B),re&&tt(R,B)}return u(e,_,re,F,y,Le.current,R)}}var z=P.ReactCurrentOwner,$=P.ReactDebugCurrentFrame;function te(e){if(e){var i=e._owner,d=G(e.type,e._source,i?i.type:null);$.setExtraStackFrame(d)}else $.setExtraStackFrame(null)}var Ee;Ee=!1;function Me(e){return typeof e=="object"&&e!==null&&e.$$typeof===r}function mt(){{if(z.current){var e=T(z.current.type);if(e)return`
17
+ */var Et;function Qt(){return Et||(Et=1,process.env.NODE_ENV!=="production"&&function(){var t=n,r=Symbol.for("react.element"),s=Symbol.for("react.portal"),o=Symbol.for("react.fragment"),l=Symbol.for("react.strict_mode"),c=Symbol.for("react.profiler"),f=Symbol.for("react.provider"),x=Symbol.for("react.context"),m=Symbol.for("react.forward_ref"),R=Symbol.for("react.suspense"),w=Symbol.for("react.suspense_list"),p=Symbol.for("react.memo"),v=Symbol.for("react.lazy"),E=Symbol.for("react.offscreen"),T=Symbol.iterator,se="@@iterator";function M(e){if(e===null||typeof e!="object")return null;var i=T&&e[T]||e[se];return typeof i=="function"?i:null}var C=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(e){{for(var i=arguments.length,d=new Array(i>1?i-1:0),y=1;y<i;y++)d[y-1]=arguments[y];Y("error",e,d)}}function Y(e,i,d){{var y=C.ReactDebugCurrentFrame,F=y.getStackAddendum();F!==""&&(i+="%s",d=d.concat([F]));var O=d.map(function(k){return String(k)});O.unshift("Warning: "+i),Function.prototype.apply.call(console[e],console,O)}}var ee=!1,ve=!1,ue=!1,te=!1,oe=!1,D;D=Symbol.for("react.module.reference");function j(e){return!!(typeof e=="string"||typeof e=="function"||e===o||e===c||oe||e===l||e===R||e===w||te||e===E||ee||ve||ue||typeof e=="object"&&e!==null&&(e.$$typeof===v||e.$$typeof===p||e.$$typeof===f||e.$$typeof===x||e.$$typeof===m||e.$$typeof===D||e.getModuleId!==void 0))}function fe(e,i,d){var y=e.displayName;if(y)return y;var F=i.displayName||i.name||"";return F!==""?d+"("+F+")":d}function Ee(e){return e.displayName||"Context"}function S(e){if(e==null)return null;if(typeof e.tag=="number"&&b("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case o:return"Fragment";case s:return"Portal";case c:return"Profiler";case l:return"StrictMode";case R:return"Suspense";case w:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case x:var i=e;return Ee(i)+".Consumer";case f:var d=e;return Ee(d._context)+".Provider";case m:return fe(e,e.render,"ForwardRef");case p:var y=e.displayName||null;return y!==null?y:S(e.type)||"Memo";case v:{var F=e,O=F._payload,k=F._init;try{return S(k(O))}catch{return null}}}return null}var g=Object.assign,h=0,N,U,K,me,G,re,H;function W(){}W.__reactDisabledLog=!0;function Z(){{if(h===0){N=console.log,U=console.info,K=console.warn,me=console.error,G=console.group,re=console.groupCollapsed,H=console.groupEnd;var e={configurable:!0,enumerable:!0,value:W,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}h++}}function je(){{if(h--,h===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:g({},e,{value:N}),info:g({},e,{value:U}),warn:g({},e,{value:K}),error:g({},e,{value:me}),group:g({},e,{value:G}),groupCollapsed:g({},e,{value:re}),groupEnd:g({},e,{value:H})})}h<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var pe=C.ReactCurrentDispatcher,he;function ie(e,i,d){{if(he===void 0)try{throw Error()}catch(F){var y=F.stack.trim().match(/\n( *(at )?)/);he=y&&y[1]||""}return`
18
+ `+he+e}}var ae=!1,_e;{var Fe=typeof WeakMap=="function"?WeakMap:Map;_e=new Fe}function le(e,i){if(!e||ae)return"";{var d=_e.get(e);if(d!==void 0)return d}var y;ae=!0;var F=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var O;O=pe.current,pe.current=null,Z();try{if(i){var k=function(){throw Error()};if(Object.defineProperty(k.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(k,[])}catch(ce){y=ce}Reflect.construct(e,[],k)}else{try{k.call()}catch(ce){y=ce}e.call(k.prototype)}}else{try{throw Error()}catch(ce){y=ce}e()}}catch(ce){if(ce&&y&&typeof ce.stack=="string"){for(var _=ce.stack.split(`
19
+ `),ne=y.stack.split(`
20
+ `),V=_.length-1,q=ne.length-1;V>=1&&q>=0&&_[V]!==ne[q];)q--;for(;V>=1&&q>=0;V--,q--)if(_[V]!==ne[q]){if(V!==1||q!==1)do if(V--,q--,q<0||_[V]!==ne[q]){var ye=`
21
+ `+_[V].replace(" at new "," at ");return e.displayName&&ye.includes("<anonymous>")&&(ye=ye.replace("<anonymous>",e.displayName)),typeof e=="function"&&_e.set(e,ye),ye}while(V>=1&&q>=0);break}}}finally{ae=!1,pe.current=O,je(),Error.prepareStackTrace=F}var Oe=e?e.displayName||e.name:"",Pe=Oe?ie(Oe):"";return typeof e=="function"&&_e.set(e,Pe),Pe}function J(e,i,d){return le(e,!1)}function ge(e){var i=e.prototype;return!!(i&&i.isReactComponent)}function z(e,i,d){if(e==null)return"";if(typeof e=="function")return le(e,ge(e));if(typeof e=="string")return ie(e);switch(e){case R:return ie("Suspense");case w:return ie("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case m:return J(e.render);case p:return z(e.type,i,d);case v:{var y=e,F=y._payload,O=y._init;try{return z(O(F),i,d)}catch{}}}return""}var xe=Object.prototype.hasOwnProperty,Se={},we=C.ReactDebugCurrentFrame;function X(e){if(e){var i=e._owner,d=z(e.type,e._source,i?i.type:null);we.setExtraStackFrame(d)}else we.setExtraStackFrame(null)}function P(e,i,d,y,F){{var O=Function.call.bind(xe);for(var k in e)if(O(e,k)){var _=void 0;try{if(typeof e[k]!="function"){var ne=Error((y||"React class")+": "+d+" type `"+k+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[k]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw ne.name="Invariant Violation",ne}_=e[k](i,k,y,d,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(V){_=V}_&&!(_ instanceof Error)&&(X(F),b("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",y||"React class",d,k,typeof _),X(null)),_ instanceof Error&&!(_.message in Se)&&(Se[_.message]=!0,X(F),b("Failed %s type: %s",d,_.message),X(null))}}}var $=Array.isArray;function A(e){return $(e)}function de(e){{var i=typeof Symbol=="function"&&Symbol.toStringTag,d=i&&e[Symbol.toStringTag]||e.constructor.name||"Object";return d}}function ot(e){try{return Je(e),!1}catch{return!0}}function Je(e){return""+e}function We(e){if(ot(e))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",de(e)),Je(e)}var Ze=C.ReactCurrentOwner,Xe={key:!0,ref:!0,__self:!0,__source:!0},Le,Qe;function ze(e){if(xe.call(e,"ref")){var i=Object.getOwnPropertyDescriptor(e,"ref").get;if(i&&i.isReactWarning)return!1}return e.ref!==void 0}function et(e){if(xe.call(e,"key")){var i=Object.getOwnPropertyDescriptor(e,"key").get;if(i&&i.isReactWarning)return!1}return e.key!==void 0}function tt(e,i){typeof e.ref=="string"&&Ze.current}function rt(e,i){{var d=function(){Le||(Le=!0,b("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",i))};d.isReactWarning=!0,Object.defineProperty(e,"key",{get:d,configurable:!0})}}function Me(e,i){{var d=function(){Qe||(Qe=!0,b("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",i))};d.isReactWarning=!0,Object.defineProperty(e,"ref",{get:d,configurable:!0})}}var Be=function(e,i,d,y,F,O,k){var _={$$typeof:r,type:e,key:i,ref:d,props:k,_owner:O};return _._store={},Object.defineProperty(_._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(_,"_self",{configurable:!1,enumerable:!1,writable:!1,value:y}),Object.defineProperty(_,"_source",{configurable:!1,enumerable:!1,writable:!1,value:F}),Object.freeze&&(Object.freeze(_.props),Object.freeze(_)),_};function Ye(e,i,d,y,F){{var O,k={},_=null,ne=null;d!==void 0&&(We(d),_=""+d),et(i)&&(We(i.key),_=""+i.key),ze(i)&&(ne=i.ref,tt(i,F));for(O in i)xe.call(i,O)&&!Xe.hasOwnProperty(O)&&(k[O]=i[O]);if(e&&e.defaultProps){var V=e.defaultProps;for(O in V)k[O]===void 0&&(k[O]=V[O])}if(_||ne){var q=typeof e=="function"?e.displayName||e.name||"Unknown":e;_&&rt(k,q),ne&&Me(k,q)}return Be(e,_,ne,F,y,Ze.current,k)}}var ke=C.ReactCurrentOwner,at=C.ReactDebugCurrentFrame;function Re(e){if(e){var i=e._owner,d=z(e.type,e._source,i?i.type:null);at.setExtraStackFrame(d)}else at.setExtraStackFrame(null)}var u;u=!1;function B(e){return typeof e=="object"&&e!==null&&e.$$typeof===r}function I(){{if(ke.current){var e=S(ke.current.type);if(e)return`
22
22
 
23
- Check the render method of \``+e+"`."}return""}}function It(e){return""}var pt={};function Lt(e){{var i=mt();if(!i){var d=typeof e=="string"?e:e.displayName||e.name;d&&(i=`
23
+ Check the render method of \``+e+"`."}return""}}function L(e){return""}var be={};function Ce(e){{var i=I();if(!i){var d=typeof e=="string"?e:e.displayName||e.name;d&&(i=`
24
24
 
25
- Check the top-level render call using <`+d+">.")}return i}}function ht(e,i){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var d=Lt(i);if(pt[d])return;pt[d]=!0;var y="";e&&e._owner&&e._owner!==z.current&&(y=" It was passed a child from "+T(e._owner.type)+"."),te(e),E('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',d,y),te(null)}}function yt(e,i){{if(typeof e!="object")return;if(V(e))for(var d=0;d<e.length;d++){var y=e[d];Me(y)&&ht(y,i)}else if(Me(e))e._store&&(e._store.validated=!0);else if(e){var F=C(e);if(typeof F=="function"&&F!==e.entries)for(var M=F.call(e),R;!(R=M.next()).done;)Me(R.value)&&ht(R.value,i)}}}function zt(e){{var i=e.type;if(i==null||typeof i=="string")return;var d;if(typeof i=="function")d=i.propTypes;else if(typeof i=="object"&&(i.$$typeof===m||i.$$typeof===w))d=i.propTypes;else return;if(d){var y=T(i);N(d,e.props,"prop",y,e)}else if(i.PropTypes!==void 0&&!Ee){Ee=!0;var F=T(i);E("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",F||"Unknown")}typeof i.getDefaultProps=="function"&&!i.getDefaultProps.isReactClassApproved&&E("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Bt(e){{for(var i=Object.keys(e.props),d=0;d<i.length;d++){var y=i[d];if(y!=="children"&&y!=="key"){te(e),E("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",y),te(null);break}}e.ref!==null&&(te(e),E("Invalid attribute `ref` supplied to `React.Fragment`."),te(null))}}var vt={};function xt(e,i,d,y,F,M){{var R=se(e);if(!R){var _="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(_+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var re=It();re?_+=re:_+=mt();var U;e===null?U="null":V(e)?U="array":e!==void 0&&e.$$typeof===r?(U="<"+(T(e.type)||"Unknown")+" />",_=" Did you accidentally export a JSX literal instead of a component?"):U=typeof e,E("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",U,_)}var B=H(e,i,d,F,M);if(B==null)return B;if(R){var he=i.children;if(he!==void 0)if(y)if(V(he)){for(var Oe=0;Oe<he.length;Oe++)yt(he[Oe],e);Object.freeze&&Object.freeze(he)}else E("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else yt(he,e)}if(be.call(i,"key")){var Pe=T(e),le=Object.keys(i).filter(function(Ht){return Ht!=="key"}),rt=le.length>0?"{key: someKey, "+le.join(": ..., ")+": ...}":"{key: someKey}";if(!vt[Pe+rt]){var Gt=le.length>0?"{"+le.join(": ..., ")+": ...}":"{}";E(`A props object containing a "key" prop is being spread into JSX:
25
+ Check the top-level render call using <`+d+">.")}return i}}function Ve(e,i){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var d=Ce(i);if(be[d])return;be[d]=!0;var y="";e&&e._owner&&e._owner!==ke.current&&(y=" It was passed a child from "+S(e._owner.type)+"."),Re(e),b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',d,y),Re(null)}}function gt(e,i){{if(typeof e!="object")return;if(A(e))for(var d=0;d<e.length;d++){var y=e[d];B(y)&&Ve(y,i)}else if(B(e))e._store&&(e._store.validated=!0);else if(e){var F=M(e);if(typeof F=="function"&&F!==e.entries)for(var O=F.call(e),k;!(k=O.next()).done;)B(k.value)&&Ve(k.value,i)}}}function zt(e){{var i=e.type;if(i==null||typeof i=="string")return;var d;if(typeof i=="function")d=i.propTypes;else if(typeof i=="object"&&(i.$$typeof===m||i.$$typeof===p))d=i.propTypes;else return;if(d){var y=S(i);P(d,e.props,"prop",y,e)}else if(i.PropTypes!==void 0&&!u){u=!0;var F=S(i);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",F||"Unknown")}typeof i.getDefaultProps=="function"&&!i.getDefaultProps.isReactClassApproved&&b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Bt(e){{for(var i=Object.keys(e.props),d=0;d<i.length;d++){var y=i[d];if(y!=="children"&&y!=="key"){Re(e),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",y),Re(null);break}}e.ref!==null&&(Re(e),b("Invalid attribute `ref` supplied to `React.Fragment`."),Re(null))}}var xt={};function bt(e,i,d,y,F,O){{var k=j(e);if(!k){var _="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(_+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var ne=L();ne?_+=ne:_+=I();var V;e===null?V="null":A(e)?V="array":e!==void 0&&e.$$typeof===r?(V="<"+(S(e.type)||"Unknown")+" />",_=" Did you accidentally export a JSX literal instead of a component?"):V=typeof e,b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",V,_)}var q=Ye(e,i,d,F,O);if(q==null)return q;if(k){var ye=i.children;if(ye!==void 0)if(y)if(A(ye)){for(var Oe=0;Oe<ye.length;Oe++)gt(ye[Oe],e);Object.freeze&&Object.freeze(ye)}else b("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else gt(ye,e)}if(xe.call(i,"key")){var Pe=S(e),ce=Object.keys(i).filter(function(Ht){return Ht!=="key"}),it=ce.length>0?"{key: someKey, "+ce.join(": ..., ")+": ...}":"{key: someKey}";if(!xt[Pe+it]){var Gt=ce.length>0?"{"+ce.join(": ..., ")+": ...}":"{}";b(`A props object containing a "key" prop is being spread into JSX:
26
26
  let props = %s;
27
27
  <%s {...props} />
28
28
  React keys must be passed directly to JSX without using spread:
29
29
  let props = %s;
30
- <%s key={someKey} {...props} />`,rt,Pe,Gt,Pe),vt[Pe+rt]=!0}}return e===o?Bt(B):zt(B),B}}function Yt(e,i,d){return xt(e,i,d,!0)}function Vt(e,i,d){return xt(e,i,d,!1)}var qt=Vt,Kt=Yt;qe.Fragment=o,qe.jsx=qt,qe.jsxs=Kt}()),qe}process.env.NODE_ENV==="production"?ct.exports=Xt():ct.exports=Qt();var a=ct.exports;function St(t){var r,n,o="";if(typeof t=="string"||typeof t=="number")o+=t;else if(typeof t=="object")if(Array.isArray(t)){var l=t.length;for(r=0;r<l;r++)t[r]&&(n=St(t[r]))&&(o&&(o+=" "),o+=n)}else for(n in t)t[n]&&(o&&(o+=" "),o+=n);return o}function J(){for(var t,r,n=0,o="",l=arguments.length;n<l;n++)(t=arguments[n])&&(r=St(t))&&(o&&(o+=" "),o+=r);return o}const er="https://core.spreedly.com/iframe/iframe-v1.min.js",tr="https://cdn.e2e.movmo.io";let De={};const rr=t=>{De={...De,...t}},nt=t=>{var n;const r=globalThis.process;return(n=r==null?void 0:r.env)==null?void 0:n[t]},Te=()=>({baseUrl:De.baseUrl??nt("REACT_APP_MOVMO_API_URL")??"",spreedlyScriptUrl:De.spreedlyScriptUrl??nt("REACT_APP_SPREEDLY_SCRIPT_URL")??er,iconCdnBaseUrl:De.iconCdnBaseUrl??nt("REACT_APP_MOVMO_ICON_CDN_URL")??tr,fetch:De.fetch??(typeof globalThis<"u"&&typeof globalThis.fetch=="function"?globalThis.fetch.bind(globalThis):(()=>{throw new Error("@movmo_app/payments: no fetch available")})())}),dt=t=>({id:t.id,last4:t.last4,brand:t.brand,expMonth:t.expMonth,expYear:t.expYear,isDefault:t.isDefault,vault:t.vault,cardholderName:t.cardholderName,zip:t.zip}),$e={Accept:"application/json","Content-Type":"application/json"},Ae=t=>{const{baseUrl:r}=Te();if(!r)throw new Error("@movmo_app/payments: baseUrl is not configured. Call setPaymentsConfig({ baseUrl }) at app boot, or set REACT_APP_MOVMO_API_URL.");return`${r}${t}`},Ue=(t,r)=>{const{fetch:n}=Te();return n(t,r)},Ie=async(t,r)=>{try{return(await t.json()).message||r}catch{return r}};let Ke=null;const ut=()=>{if(Ke)return Ke;const t=(async()=>{const r=await Ue(Ae("/v1/payments/tokenization-session"),{method:"GET",headers:$e,credentials:"include"});if(!r.ok)throw new Error(await Ie(r,`Failed to fetch tokenization session (${r.status})`));return await r.json()})();return Ke=t,t.finally(()=>{Ke===t&&(Ke=null)}).catch(()=>{}),t},ar=t=>typeof t.brand=="string"&&typeof t.last4=="string"&&typeof t.expMonth=="number"&&typeof t.expYear=="number",nr=async(t,r,n)=>{const o=await Ue(Ae(`/v1/users/${encodeURIComponent(t)}/payment-methods/from-token`),{method:"POST",headers:$e,credentials:"include",body:JSON.stringify({tokenizedPaymentMethodId:r,isDefault:n})});if(!o.ok)throw new Error(await Ie(o,`Failed to save payment method (${o.status})`));const l=await o.json();if(ar(l))return dt(l);const c=await Ue(Ae(`/v1/users/${encodeURIComponent(t)}/payment-methods/${encodeURIComponent(l.id)}`),{method:"GET",headers:$e,credentials:"include"});if(!c.ok)throw new Error(await Ie(c,`Failed to fetch saved payment method (${c.status})`));const f=await c.json();return dt(f)},sr=async(t,r)=>{if(!t)return[];const n=await Ue(Ae(`/v1/users/${encodeURIComponent(t)}/payment-methods`),{method:"GET",headers:$e,credentials:"include",signal:r});if(!n.ok)throw new Error(await Ie(n,`Failed to fetch payment methods (${n.status})`));return(await n.json()??[]).map(dt)},or=async(t,r)=>{const n=await Ue(Ae(`/v1/users/${encodeURIComponent(t)}/payment-methods/${encodeURIComponent(r)}`),{method:"DELETE",headers:$e,credentials:"include"});if(!n.ok)throw new Error(await Ie(n,`Failed to delete payment method (${n.status})`))},Pt=async(t,r,n)=>{const o=await Ue(Ae(`/v1/users/${encodeURIComponent(t)}/payment-methods/${encodeURIComponent(r)}`),{method:"PUT",headers:$e,credentials:"include",body:JSON.stringify(n)});if(!o.ok)throw new Error(await Ie(o,`Failed to update payment method (${o.status})`))},ir={visa:"visa",master:"mastercard",mastercard:"mastercard",american_express:"amex",amex:"amex",discover:"discover"},lr=28,Ne=({brand:t,className:r,width:n=46})=>{const o=t?ir[t.toLowerCase()]??"credit-card":"credit-card",l=Math.max(n,lr),c=Math.round(l*24/34),{iconCdnBaseUrl:f}=Te();return a.jsx("img",{src:`${f}/website/assets/icons/payments/${o}.svg`,alt:o==="credit-card"?"card":`${o} card`,"data-testid":`card-brand-${t.toLowerCase()}`,className:r,width:l,height:c,loading:"lazy"})};let Ge=null;const cr=()=>{if(typeof window>"u")return Promise.reject(new Error("Spreedly can only be loaded in a browser environment."));if(window.Spreedly)return Promise.resolve(window.Spreedly);if(Ge)return Ge;const{spreedlyScriptUrl:t}=Te();return Ge=new Promise((r,n)=>{const o=document.querySelector(`script[src="${t}"]`),l=()=>{window.Spreedly?r(window.Spreedly):n(new Error("Spreedly script loaded but window.Spreedly is undefined."))};if(o){if(window.Spreedly){l();return}o.addEventListener("load",l,{once:!0}),o.addEventListener("error",()=>{o.remove(),n(new Error("Failed to load Spreedly iframe script."))},{once:!0});return}const c=document.createElement("script");c.src=t,c.async=!0,c.onload=l,c.onerror=()=>{c.remove(),n(new Error("Failed to load Spreedly iframe script."))},document.head.appendChild(c)}).catch(r=>{throw Ge=null,r}),Ge};class Xe extends Error{constructor(n,o){super(o instanceof Error?o.message:"Failed to initialize card form.");at(this,"source");at(this,"cause");this.name="InitError",this.source=n,this.cause=o}}const dr="movmo-card-number",ur="movmo-card-cvv",fr=t=>({first_name:t.firstName,last_name:t.lastName,month:t.month,year:t.year,...t.email?{email:t.email}:{},...t.zip?{zip:t.zip}:{}}),Tt=(t={})=>{const{numberEl:r=dr,cvvEl:n=ur,onCardTokenized:o,onFieldErrors:l,onValidityChange:c,onBrandChange:f}=t,[g,m]=s.useState("idle"),[S,v]=s.useState(null),[w,p]=s.useState(null),[j,W]=s.useState(null),[ee,C]=s.useState({number:!1,cvv:!1}),[P,E]=s.useState(null),[ae,X]=s.useState({number:!1,cvv:!1}),de=s.useRef(null),ye=s.useRef(o),q=s.useRef(l),ne=s.useRef(c),x=s.useRef(f);s.useEffect(()=>{ye.current=o},[o]),s.useEffect(()=>{q.current=l},[l]),s.useEffect(()=>{ne.current=c},[c]),s.useEffect(()=>{x.current=f},[f]);const se=s.useRef({number:!1,cvv:!1});s.useEffect(()=>{let T=!1;return m("loading"),v(null),p(null),W(null),C({number:!1,cvv:!1}),E(null),se.current={number:!1,cvv:!1},(async()=>{try{const[b,h]=await Promise.all([ut().catch(k=>{throw new Xe("tokenization-session",k)}),cr().catch(k=>{throw new Xe("spreedly-script",k)})]);if(T)return;de.current=h,h.on("ready",()=>{var k,A,Z,ue,K,Y;if(!T){m("ready");try{(k=h.setFieldType)==null||k.call(h,"number","tel"),(A=h.setFieldType)==null||A.call(h,"cvv","tel")}catch(I){console.warn("@movmo_app/payments: setFieldType failed",I)}try{typeof h.setNumberFormat=="function"?h.setNumberFormat("prettyFormat"):console.warn("@movmo_app/payments: Spreedly.setNumberFormat is missing — card-number digits will not be space-grouped.")}catch(I){console.warn("@movmo_app/payments: setNumberFormat failed",I)}try{(Z=h.setPlaceholder)==null||Z.call(h,"number","Card number"),(ue=h.setPlaceholder)==null||ue.call(h,"cvv","CVV");const I='box-sizing: border-box;width: 100%;height: 100%;margin: 0;padding: 0;border: 0;background: transparent;outline: none;font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;font-size: 14px;font-weight: 400;line-height: 20px;color: rgb(28 25 23);letter-spacing: 0;vertical-align: middle;';(K=h.setStyle)==null||K.call(h,"number",I),(Y=h.setStyle)==null||Y.call(h,"cvv",I)}catch(I){console.warn("@movmo_app/payments: setPlaceholder/setStyle failed",I)}}}),h.on("paymentMethod",k=>{var A;(A=ye.current)==null||A.call(ye,k)}),h.on("errors",k=>{var A;(A=q.current)==null||A.call(q,k)}),h.on("fieldEvent",(k,A,Z,ue)=>{var I;if(T)return;if(A==="focus"){X(O=>O[k]?O:{...O,[k]:!0});return}if(A==="blur"){X(O=>O[k]?{...O,[k]:!1}:O);return}if(A!=="input")return;const K=ue??{};if(k==="number"){if(K.numberLength===0)E(O=>{var L;return O!==null&&((L=x.current)==null||L.call(x,null)),null});else if(K.cardType!==void 0){const O=K.cardType||null;E(L=>{var fe;return L!==O&&((fe=x.current)==null||fe.call(x,O)),O})}}const Y=k==="number"?typeof K.validNumber=="boolean"?K.validNumber:void 0:typeof K.validCvv=="boolean"?K.validCvv:void 0;if(typeof Y=="boolean"){const O=se.current,L=k==="number"?{...O,number:Y}:{...O,cvv:Y};(L.number!==O.number||L.cvv!==O.cvv)&&(se.current=L,C(L),(I=ne.current)==null||I.call(ne,L))}}),h.on("consoleError",k=>{var Z;const A=k instanceof Error?k.message:"An unexpected error occurred while securing your card.";(Z=q.current)==null||Z.call(q,[{message:A}])}),h.init(b.environmentKey,{numberEl:r,cvvEl:n,nonce:b.nonce,timestamp:String(b.timestamp),certificateToken:b.certificateToken,signature:b.signature})}catch(b){if(T)return;const h=b instanceof Error?b.message:"Failed to initialize card form.";v(h),p(b instanceof Xe?b.source:"spreedly-script"),W(b instanceof Xe?b.cause:b),m("error")}})(),()=>{var b,h;T=!0;try{(h=(b=de.current)==null?void 0:b.removeHandlers)==null||h.call(b)}catch(k){console.warn("@movmo_app/payments: removeHandlers failed during cleanup",k)}de.current=null}},[r,n]);const Ce=s.useCallback(T=>{var b;(b=de.current)==null||b.tokenizeCreditCard(fr(T))},[]),ve=s.useCallback(T=>{var b,h;(h=(b=de.current)==null?void 0:b.transferFocus)==null||h.call(b,T)},[]);return{status:g,error:S,errorSource:w,errorCause:j,tokenize:Ce,validity:ee,brand:P,focused:ae,focusField:ve}},st="h-11 w-full rounded-md border border-grayWarm-300 bg-white px-3 py-2 text-sm text-grayWarm-900 placeholder:text-grayWarm-400 outline-none focus:border-grayWarm-950 focus:shadow-[0_0_0_1px_#1c1917]",wt="flex h-11 w-full items-center gap-2 rounded-md border bg-white px-3 py-2 transition-shadow",Et="border-grayWarm-950 shadow-[0_0_0_1px_#1c1917]",jt="border-grayWarm-300",mr=t=>{const r=t.trim();if(!r)return{firstName:"",lastName:""};const n=r.lastIndexOf(" ");return n===-1?{firstName:r,lastName:""}:{firstName:r.slice(0,n).trim(),lastName:r.slice(n+1).trim()}},Ft=t=>{const r=t.replace(/\D/g,"");if(r.length<4)return{month:"",year:""};const n=r.slice(0,2),o=r.slice(2),l=o.length===2?`20${o}`:o.slice(0,4);return{month:n,year:l}},pr=t=>{const r=t.replace(/\D/g,"").slice(0,4);return r.length<=2?r:`${r.slice(0,2)} / ${r.slice(2)}`},ot=t=>{const{month:r,year:n}=Ft(t);if(!r||!n)return!1;const o=parseInt(r,10),l=parseInt(n,10);if(isNaN(o)||o<1||o>12)return!1;const c=new Date;return!(l<c.getFullYear()||l>c.getFullYear()+20||l===c.getFullYear()&&o<c.getMonth()+1)},it=t=>/^\d{5}(-\d{4})?$/.test(t.trim()),hr=t=>{const r=t.replace(/[^\d]/g,"").slice(0,9);return r.length<=5?r:`${r.slice(0,5)}-${r.slice(5)}`},ft=({userId:t,onSuccess:r,onError:n,onErrorDetail:o,isDefault:l=!1,className:c,defaultCardholderName:f,defaultCardholderFirstName:g="",defaultCardholderLastName:m="",autoSave:S=!1,formId:v="movmo-card-form",hideInternalSaveButton:w=!1,onCanSubmitChange:p,onSavingChange:j,autoFocus:W})=>{const ee=f??[g,m].filter(Boolean).join(" "),[C,P]=s.useState(ee),[E,ae]=s.useState(""),[X,de]=s.useState(""),[ye,q]=s.useState("idle"),ne=s.useRef(!1),x=s.useRef(o);s.useEffect(()=>{x.current=o},[o]);const se=s.useCallback(async N=>{var D;q("saving");try{const V=await nr(t,N,l);q("ready"),r(V)}catch(V){const ie=V instanceof Error?V.message:"Failed to save payment method.";q("ready"),ne.current=!1,n(ie),(D=x.current)==null||D.call(x,{source:"save-from-token",message:ie,cause:V})}},[t,l,r,n]),Ce=s.useCallback(N=>{var V;const D=N.map(ie=>ie.message).filter(Boolean).join("; ")||"Card validation failed.";q(ie=>ie==="tokenizing"?"ready":ie),ne.current=!1,n(D),(V=x.current)==null||V.call(x,{source:"card-tokenize",message:D})},[n]),ve=s.useMemo(()=>({onCardTokenized:se,onFieldErrors:Ce}),[se,Ce]),{status:T,error:b,errorSource:h,errorCause:k,tokenize:A,validity:Z,brand:ue,focused:K,focusField:Y}=Tt(ve),I=s.useRef(!1);s.useEffect(()=>{!W||T!=="ready"||I.current||(I.current=!0,Y(W))},[W,T,Y]);const O=C.trim().split(/\s+/).length>=2,L=ot(E),fe=it(X),ce=s.useRef(!1),Q=s.useRef(!1),je=s.useRef(!1),ke=s.useRef(null),me=s.useRef(null);s.useEffect(()=>{var N;Z.cvv?Q.current||(Q.current=!0,(N=ke.current)==null||N.focus()):Q.current=!1},[Z.cvv]);const oe=!O||!L||!fe||!Z.number||!Z.cvv,xe=ye==="tokenizing"||ye==="saving",ge=T==="ready"&&!xe&&!oe,_e=s.useRef(p);s.useEffect(()=>{_e.current=p},[p]),s.useEffect(()=>{var N;(N=_e.current)==null||N.call(_e,ge)},[ge]);const G=s.useRef(j);s.useEffect(()=>{G.current=j},[j]),s.useEffect(()=>{var N;(N=G.current)==null||N.call(G,xe)},[xe]);const be=s.useCallback(()=>{const{firstName:N,lastName:D}=mr(C),{month:V,year:ie}=Ft(E);q("tokenizing"),A({firstName:N,lastName:D,month:V,year:ie,zip:X.trim()})},[C,E,X,A]);s.useEffect(()=>{if(!S||!ge||ne.current)return;const N=setTimeout(()=>{ne.current=!0,be()},1200);return()=>clearTimeout(N)},[S,ge,be]);const Re=N=>{N.preventDefault(),ge&&be()},pe=T!=="ready"||xe,we=s.useRef(n);return s.useEffect(()=>{we.current=n},[n]),s.useEffect(()=>{var N,D;b&&((N=we.current)==null||N.call(we,b),(D=x.current)==null||D.call(x,{source:h??"spreedly-script",message:b,cause:k}))},[b,h,k]),a.jsxs("form",{id:v,onSubmit:Re,className:J("flex w-full flex-col gap-3",c),"data-testid":"movmo-card-form",children:[a.jsxs("div",{children:[a.jsx("span",{id:"movmo-card-number-label",className:"sr-only",children:"Card number"}),a.jsxs("div",{className:J(wt,K.number?Et:jt),children:[a.jsx(Ne,{brand:ue??"",width:32,className:"flex-shrink-0"}),a.jsxs("div",{className:"relative h-full flex-1",children:[a.jsx("div",{id:"movmo-card-number","aria-labelledby":"movmo-card-number-label","aria-busy":T!=="ready",className:"absolute inset-0","data-testid":"movmo-card-number-mount"}),T!=="ready"?a.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-y-2 left-0 right-2 animate-pulse rounded bg-grayWarm-200"}):null]})]})]}),a.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{htmlFor:"movmo-card-expiry",className:"sr-only",children:"Expiry MM / YY"}),a.jsx("input",{id:"movmo-card-expiry",type:"text",inputMode:"numeric",autoComplete:"cc-exp",placeholder:"MM / YY",value:E,onChange:N=>{const D=pr(N.target.value);ae(D),ot(D)&&!ce.current?(ce.current=!0,Y("cvv")):ot(D)||(ce.current=!1)},className:J(st,E&&!L&&"border-error-500"),disabled:pe,required:!0,"data-testid":"movmo-card-expiry-input"})]}),a.jsxs("div",{className:"relative",children:[a.jsx("span",{id:"movmo-card-cvv-label",className:"sr-only",children:"CVV"}),a.jsxs("div",{className:J(wt,K.cvv?Et:jt),children:[a.jsxs("div",{className:"relative h-full flex-1",children:[a.jsx("div",{id:"movmo-card-cvv","aria-labelledby":"movmo-card-cvv-label","aria-busy":T!=="ready",className:"absolute inset-0","data-testid":"movmo-card-cvv-mount"}),T!=="ready"?a.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-y-2 left-0 right-2 animate-pulse rounded bg-grayWarm-200"}):null]}),a.jsx("button",{type:"button","aria-label":"CVV help",tabIndex:-1,className:"flex h-5 w-5 flex-shrink-0 items-center justify-center rounded-full border border-grayWarm-300 text-xs text-grayWarm-500",title:ue==="american_express"?"The 4 numbers on the front of your card.":"The 3 numbers on the back of your card.","data-testid":"movmo-cvv-help",children:"?"})]})]}),a.jsxs("div",{children:[a.jsx("label",{htmlFor:"movmo-card-zip",className:"sr-only",children:"ZIP code"}),a.jsx("input",{id:"movmo-card-zip",ref:ke,type:"text",inputMode:"numeric",autoComplete:"postal-code",placeholder:"ZIP code",value:X,onChange:N=>{var V;const D=hr(N.target.value);de(D),it(D)&&!je.current?(je.current=!0,(V=me.current)==null||V.focus()):it(D)||(je.current=!1)},className:J(st,X&&!fe&&"border-error-500"),disabled:pe,required:!0,"data-testid":"movmo-card-zip-input"})]})]}),a.jsxs("div",{children:[a.jsx("label",{htmlFor:"movmo-card-cardholder-name",className:"sr-only",children:"Cardholder name"}),a.jsx("input",{id:"movmo-card-cardholder-name",ref:me,type:"text",autoComplete:"cc-name",placeholder:"Cardholder name",value:C,onChange:N=>P(N.target.value),className:st,disabled:pe,required:!0,"data-testid":"movmo-card-cardholder-name-input"})]}),!S&&!w?a.jsx("button",{type:"submit",disabled:!ge,className:J("inline-flex h-11 items-center justify-center rounded-md bg-brand-500 px-4 text-sm font-semibold text-white transition-colors hover:bg-brand-600","disabled:cursor-not-allowed disabled:bg-grayWarm-300 disabled:text-grayWarm-500"),"data-testid":"movmo-card-save",children:xe?"Saving…":T==="loading"?"Loading…":"Save card"}):xe&&S?a.jsx("p",{className:"text-center text-sm text-grayWarm-500","aria-live":"polite","data-testid":"movmo-card-autosaving",children:"Saving card…"}):null]})};ft.displayName="MovmoCardForm";const Wt=t=>{const[r,n]=s.useState("idle"),[o,l]=s.useState(null);return{deletePaymentMethod:s.useCallback(async f=>{n("pending"),l(null);try{await or(t,f),n("idle")}catch(g){const m=g instanceof Error?g.message:"Failed to delete payment method.";throw l(m),n("error"),g}},[t]),status:r,error:o}},Mt=t=>{const[r,n]=s.useState("idle"),[o,l]=s.useState(null);return{setDefault:s.useCallback(async f=>{n("pending"),l(null);try{await Pt(t,f,{isDefault:!0}),n("idle")}catch(g){const m=g instanceof Error?g.message:"Failed to set default payment method.";throw l(m),n("error"),g}},[t]),status:r,error:o}},Ot=t=>{const[r,n]=s.useState("idle"),[o,l]=s.useState(null);return{updatePaymentMethod:s.useCallback(async(f,g)=>{n("pending"),l(null);try{await Pt(t,f,g),n("idle")}catch(m){const S=m instanceof Error?m.message:"Failed to update payment method.";throw l(S),n("error"),m}},[t]),status:r,error:o}},Dt=t=>{const[r,n]=s.useState([]),[o,l]=s.useState("idle"),[c,f]=s.useState(null),[g,m]=s.useState(0),S=s.useRef(null);s.useEffect(()=>{var p;if((p=S.current)==null||p.abort(),!t){S.current=null,n([]),f(null),l("ready");return}const w=new AbortController;return S.current=w,l("loading"),f(null),sr(t,w.signal).then(j=>{w.signal.aborted||(n(j),l("ready"))}).catch(j=>{if(w.signal.aborted||j instanceof DOMException&&j.name==="AbortError")return;const W=j instanceof Error?j.message:"Failed to fetch payment methods.";f(W),l("error")}),()=>{w.abort()}},[t,g]);const v=s.useCallback(()=>{m(w=>w+1)},[]);return{items:r,status:o,error:c,refetch:v}},$t=({open:t,onClose:r,title:n,titleId:o,formId:l,saveDisabled:c,saveLabel:f="Save",isSaving:g=!1,testIdPrefix:m="payment-method",children:S})=>(s.useEffect(()=>{if(!t)return;const v=w=>{w.key==="Escape"&&r()};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[t,r]),s.useEffect(()=>{if(!t)return;const v=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=v}},[t]),t?a.jsx("div",{role:"dialog","aria-modal":"true","aria-labelledby":o,className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",onClick:v=>{v.target===v.currentTarget&&r()},"data-testid":`${m}-modal`,children:a.jsxs("div",{className:"flex max-h-full w-full max-w-md flex-col rounded-xl bg-white shadow-2xl",children:[a.jsxs("div",{className:"flex items-center gap-3 border-b border-grayWarm-200 px-4 py-3",children:[a.jsx("button",{type:"button",onClick:r,"aria-label":`Close ${n.toLowerCase()} dialog`,className:"flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg bg-grayWarm-100 p-2 text-grayWarm-950 transition-colors hover:bg-grayWarm-200","data-testid":`${m}-close`,children:a.jsx("svg",{viewBox:"0 0 20 20",width:"20",height:"20","aria-hidden":"true",children:a.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"currentColor",strokeWidth:"1.67",strokeLinecap:"round",strokeLinejoin:"round"})})}),a.jsx("h2",{id:o,className:"flex-1 text-center text-base font-semibold text-grayWarm-900",children:n}),a.jsx("span",{"aria-hidden":"true",className:"h-9 w-9 flex-shrink-0"})]}),a.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:S}),a.jsxs("div",{className:"flex gap-3 border-t border-grayWarm-200 p-4",children:[a.jsx("button",{type:"button",onClick:r,className:"inline-flex h-11 flex-1 items-center justify-center rounded-lg border border-grayWarm-300 px-4 text-sm font-semibold text-grayWarm-900 transition-colors hover:border-grayWarm-900 hover:shadow-[0_0_0_1px_#1c1917]","data-testid":`${m}-cancel`,children:"Cancel"}),a.jsx("button",{type:"submit",form:l,disabled:g?!1:c,"aria-disabled":g||c,"aria-busy":g,className:J("inline-flex h-11 flex-1 items-center justify-center rounded-lg bg-brand-500 px-4 text-sm font-semibold text-white transition-colors",g?"cursor-not-allowed opacity-90 pointer-events-none":"hover:bg-brand-600 disabled:cursor-not-allowed disabled:bg-grayWarm-300 disabled:text-grayWarm-500"),"data-testid":`${m}-save`,children:g?a.jsxs(a.Fragment,{children:[a.jsxs("svg",{className:"h-[18px] w-[18px] animate-spin",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[a.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3",strokeOpacity:"0.25"}),a.jsx("path",{d:"M22 12a10 10 0 0 1-10 10",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round"})]}),a.jsx("span",{className:"sr-only",children:"Saving"})]}):f})]})]})}):null),yr=({open:t,onClose:r,formId:n,saveDisabled:o,saveLabel:l="Save",isSaving:c=!1,children:f})=>a.jsx($t,{open:t,onClose:r,title:"Add payment method",titleId:"movmo-add-payment-title",formId:n,saveDisabled:o,saveLabel:l,isSaving:c,testIdPrefix:"add-payment-method",children:f}),vr=(t,r)=>`${String(t).padStart(2,"0")}/${r}`,xr=t=>{if(!t)return"Card";const r=t.toLowerCase();return r==="amex"?"Amex":r.charAt(0).toUpperCase()+r.slice(1)},gr=({open:t,method:r,onClose:n,onSave:o,isSaving:l=!1,error:c=null})=>{const f=s.useId(),[g,m]=s.useState(""),[S,v]=s.useState("");if(s.useEffect(()=>{t&&r&&(m(r.cardholderName??""),v(r.zip??""))},[t,r]),!r)return null;const w=g.trim(),p=S.trim(),j=w!==(r.cardholderName??"").trim(),W=p!==(r.zip??"").trim(),ee=j||W,C=(!j||w.length>0)&&(!W||/^[A-Za-z0-9 -]{3,20}$/.test(p)),P=!ee||!C,E=ae=>{if(ae.preventDefault(),P||l)return;const X={};j&&(X.cardholderName=w),W&&(X.zip=p),o(X).catch(()=>{})};return a.jsxs($t,{open:t,onClose:n,title:"Edit payment method",titleId:"movmo-edit-payment-title",formId:f,saveDisabled:P,isSaving:l,testIdPrefix:"edit-payment-method",children:[a.jsxs("div",{className:"mb-4 flex items-start gap-3 rounded-lg bg-grayWarm-50 p-3","data-testid":"edit-payment-method-context",children:[a.jsx(Ne,{brand:r.brand,className:"flex-shrink-0"}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsxs("div",{className:"text-lg font-semibold text-grayWarm-950",children:[xr(r.brand)," •••• ",r.last4]}),a.jsxs("div",{className:"text-sm text-grayWarm-600",children:["Exp. ",vr(r.expMonth,r.expYear)]})]})]}),a.jsxs("form",{id:f,onSubmit:E,className:"flex flex-col gap-4",noValidate:!0,children:[a.jsxs("label",{className:"flex flex-col gap-1.5 text-sm font-medium text-grayWarm-700",children:["Cardholder name",a.jsx("input",{type:"text",autoComplete:"cc-name",value:g,onChange:ae=>m(ae.target.value),disabled:l,maxLength:255,"data-testid":"edit-payment-method-cardholder",className:"h-11 rounded-lg border border-grayWarm-300 px-3 text-base font-normal text-grayWarm-950 focus:border-grayWarm-950 focus:outline-none focus:ring-1 focus:ring-grayWarm-950"})]}),a.jsxs("label",{className:"flex flex-col gap-1.5 text-sm font-medium text-grayWarm-700",children:["Billing ZIP",a.jsx("input",{type:"text",inputMode:"numeric",autoComplete:"postal-code",value:S,onChange:ae=>v(ae.target.value),disabled:l,maxLength:20,"data-testid":"edit-payment-method-zip",className:"h-11 rounded-lg border border-grayWarm-300 px-3 text-base font-normal text-grayWarm-950 focus:border-grayWarm-950 focus:outline-none focus:ring-1 focus:ring-grayWarm-950"})]}),c?a.jsx("p",{role:"alert",className:"text-sm text-error-700","data-testid":"edit-payment-method-error",children:c}):null]})]})},br=t=>{if(!t)return"Card";const r=t.toLowerCase();return r==="amex"?"Amex":r.charAt(0).toUpperCase()+r.slice(1)},At=({method:t,trailing:r,onClick:n,cardLabelFormat:o="branded",className:l})=>a.jsxs("div",{className:J("flex items-center gap-3",n&&"cursor-pointer",l),onClick:n,role:n?"button":void 0,tabIndex:n?0:void 0,onKeyDown:n?c=>{(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),n())}:void 0,"data-testid":`payment-method-preview-${t.id}`,children:[a.jsx(Ne,{brand:t.brand,width:34,className:"flex-shrink-0"}),a.jsx("span",{className:"flex-1 text-lg font-semibold text-grayWarm-950",children:o==="masked"?`•••• ${t.last4}`:`${br(t.brand)} ${t.last4}`}),r]}),wr=(t,r,n=new Date)=>r<n.getFullYear()||r===n.getFullYear()&&t<n.getMonth()+1,_t=t=>{if(!t)return"Card";const r=t.toLowerCase();return r==="amex"?"Amex":r.charAt(0).toUpperCase()+r.slice(1)},Er=(t,r)=>`${String(t).padStart(2,"0")}/${r}`,jr=({method:t,selectable:r,selected:n,onSelect:o,onSetDefault:l,onRemove:c,onEdit:f,disabled:g,showDefaultBadge:m,hideSetDefaultMenuItem:S,cardLabelFormat:v="branded"})=>{const[w,p]=s.useState(!1),j=s.useRef(null),W=wr(t.expMonth,t.expYear);s.useEffect(()=>{if(!w)return;const C=P=>{var E;(E=j.current)!=null&&E.contains(P.target)||p(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[w]);const ee=()=>{r&&o&&!g&&o(t)};return a.jsxs("div",{className:J("flex items-start gap-3 transition-colors",r?"rounded-lg border px-3 py-3":"py-4",r&&!g&&"cursor-pointer",r&&(n?"border-grayWarm-950 shadow-[0_0_0_1px_#1c1917]":"border-grayWarm-200 hover:border-grayWarm-300")),onClick:ee,"data-testid":`payment-method-row-${t.id}`,children:[r?a.jsx("input",{type:"radio",name:"movmo-payment-method",checked:n,onChange:()=>o==null?void 0:o(t),onClick:C=>C.stopPropagation(),"aria-label":`Select ${_t(t.brand)} ending ${t.last4}`,className:"mr-1 h-4 w-4 mt-2 cursor-pointer appearance-none rounded-full border-2 border-grayWarm-300 checked:border-[5px] checked:border-grayWarm-950 bg-white checked:bg-white focus:ring-0 focus:ring-offset-0",disabled:g}):null,a.jsx(Ne,{brand:t.brand,className:"flex-shrink-0"}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[a.jsx("span",{className:"text-lg font-semibold text-grayWarm-950",children:v==="masked"?`•••• ${t.last4}`:`${_t(t.brand)} ${t.last4}`}),m&&t.isDefault?a.jsx("span",{className:"inline-flex items-center rounded-full bg-success-50 px-2 py-0.5 text-xs font-semibold text-success-700","data-testid":`badge-default-${t.id}`,children:"Default"}):null,W?a.jsx("span",{className:"inline-flex items-center rounded-full bg-error-50 px-2 py-0.5 text-xs font-semibold text-error-700","data-testid":`badge-expired-${t.id}`,children:"Expired"}):null]}),a.jsxs("div",{className:J("text-base",W?"text-grayWarm-400":"text-grayWarm-600"),children:["Exp. ",Er(t.expMonth,t.expYear)]})]}),a.jsxs("div",{className:"relative flex-shrink-0",ref:j,children:[a.jsx("button",{type:"button","aria-label":`Open actions for card ending ${t.last4}`,"aria-haspopup":"menu","aria-expanded":w,className:"rounded-lg p-2 text-grayWarm-600 transition-colors hover:bg-grayWarm-100 disabled:cursor-not-allowed disabled:opacity-50",disabled:g,onClick:C=>{C.stopPropagation(),p(P=>!P)},"data-testid":`menu-trigger-${t.id}`,children:a.jsx("svg",{viewBox:"0 0 24 24",width:"20",height:"20",fill:"currentColor","aria-hidden":"true",children:a.jsx("path",{d:"M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"})})}),w?a.jsxs("div",{role:"menu",className:J("absolute z-10 whitespace-nowrap rounded-lg border border-grayWarm-200 bg-white py-1 shadow-lg",r?"bottom-full left-1/2 mb-2 -translate-x-1/2":"right-0 top-full mt-1"),onClick:C=>C.stopPropagation(),"data-testid":`menu-${t.id}`,children:[r?a.jsx("span",{"aria-hidden":"true",className:"absolute -bottom-1.5 left-1/2 h-3 w-3 -translate-x-1/2 rotate-45 border-b border-r border-grayWarm-200 bg-white"}):null,!t.isDefault&&!S?a.jsx("button",{type:"button",role:"menuitem",className:"block w-full px-4 py-1 text-left text-md font-semibold text-grayWarm-950 hover:text-grayWarm-700",onClick:()=>{p(!1),l(t)},"data-testid":`menu-set-default-${t.id}`,children:"Set as default"}):null,f&&t.vault==="spreedly"?a.jsx("button",{type:"button",role:"menuitem",className:"block w-full px-4 py-1 text-left text-md font-semibold text-grayWarm-950 hover:text-grayWarm-700",onClick:()=>{p(!1),f(t)},"data-testid":`menu-edit-${t.id}`,children:"Edit"}):null,a.jsx("button",{type:"button",role:"menuitem",className:"block w-full px-4 py-1 text-left text-md font-semibold text-error-700 hover:text-error-500",onClick:()=>{p(!1),c(t)},"data-testid":`menu-remove-${t.id}`,children:"Delete"})]}):null]})]})},_r=t=>`${Te().iconCdnBaseUrl}/website/assets/icons/payments/${t}.svg`,lt=({slug:t,alt:r})=>a.jsx("img",{src:_r(t),alt:r,height:20,loading:"lazy",style:{height:20,width:"auto"}}),Qe=({type:t,label:r,iconNode:n,disabled:o=!1})=>a.jsxs("label",{className:"flex cursor-pointer items-center gap-3 rounded-lg border border-grayWarm-200 px-4 py-3 transition-colors hover:border-grayWarm-300","data-testid":`payment-type-${t}`,children:[a.jsx("input",{type:"radio",name:"movmo-payment-type",value:t,disabled:o,onChange:()=>{},className:J("h-4 w-4 accent-grayWarm-900",o?"cursor-not-allowed":"cursor-pointer"),"aria-label":r}),a.jsxs("span",{className:"flex flex-1 items-center gap-2 text-sm font-semibold text-grayWarm-900",children:[r,n]})]}),Ct=({selected:t,onSelect:r,creditCardBody:n,disabled:o=!1,className:l})=>{const c=t==="credit_card";return a.jsxs("div",{className:J("flex w-full flex-col gap-3",l),children:[a.jsxs("label",{className:J("flex cursor-pointer flex-col gap-3 rounded-lg border px-4 py-3 transition-colors",c?"border-grayWarm-900 shadow-[0_0_0_1px_#1c1917]":"border-grayWarm-200"),"data-testid":"payment-type-credit_card",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("input",{type:"radio",name:"movmo-payment-type",value:"credit_card",checked:c,disabled:o,onChange:()=>{o||r("credit_card")},className:J("h-4 w-4 accent-grayWarm-900",o?"cursor-not-allowed":"cursor-pointer"),"aria-label":"Credit card"}),a.jsx("span",{className:"flex-1 text-sm font-semibold text-grayWarm-900",children:"Credit card"}),a.jsxs("div",{className:"flex items-center gap-1.5",children:[a.jsx(Ne,{brand:"mastercard",width:28}),a.jsx(Ne,{brand:"visa",width:28}),a.jsx(Ne,{brand:"amex",width:28}),a.jsx(Ne,{brand:"discover",width:28})]})]}),c?a.jsx("div",{"data-testid":"payment-type-credit_card-body",children:n}):null]}),c?a.jsx("p",{className:"mt-2 text-sm font-semibold text-grayWarm-900","data-testid":"payment-type-other-options-header",children:"Other options"}):null,a.jsx(Qe,{type:"paypal",label:"PayPal",iconNode:a.jsx(lt,{slug:"paypal",alt:"PayPal"}),disabled:o}),a.jsx(Qe,{type:"googlepay",label:"GooglePay",iconNode:a.jsx(lt,{slug:"google-pay",alt:"GooglePay"}),disabled:o}),a.jsx(Qe,{type:"klarna",label:"Klarna",iconNode:a.jsx(lt,{slug:"klarna",alt:"Klarna"}),disabled:o}),a.jsx(Qe,{type:"ach",label:"Bank account (ACH)",iconNode:a.jsx("span",{className:"text-xs font-medium text-grayWarm-500",children:"Direct debit"}),disabled:o})]})},kt="movmo-add-payment-form",Cr=t=>{console.error("@movmo_app/payments: failed to update payment method",t);const r=t instanceof Error?t.message.trim():"";return/spreedly-backed cards/i.test(r)?"This card's details can't be edited.":r||"Failed to update payment method."},Rt=t=>{const r=t.filter(o=>o.isDefault),n=t.filter(o=>!o.isDefault);return[...r,...n]},Nt=({withDefaultBadge:t=!1})=>a.jsxs("div",{className:"flex items-start justify-between py-4","data-testid":"payment-method-skeleton",children:[a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"h-8 w-[46px] flex-shrink-0 animate-pulse rounded bg-grayWarm-200"}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("div",{className:"h-5 w-[120px] animate-pulse rounded bg-grayWarm-200"}),t?a.jsx("div",{className:"h-5 w-[56px] animate-pulse rounded-full bg-grayWarm-200"}):null]}),a.jsx("div",{className:"h-4 w-[100px] animate-pulse rounded bg-grayWarm-200"})]})]}),a.jsx("div",{className:"h-5 w-5 flex-shrink-0 animate-pulse rounded-full bg-grayWarm-200"})]}),Ut=({userId:t,defaultCardholderName:r,defaultCardholderFirstName:n,defaultCardholderLastName:o,selectedId:l,onSelect:c,onChange:f,onError:g,paymentTypeSelector:m=!0,autoSaveFirstCard:S=!0,selectionSetsDefault:v=!1,showDefaultBadge:w=!0,collapsible:p=!1,cardLabelFormat:j="branded",className:W})=>{const{items:ee,status:C,error:P,refetch:E}=Dt(t),{deletePaymentMethod:ae,status:X}=Wt(t),{setDefault:de,status:ye}=Mt(t),{updatePaymentMethod:q,status:ne}=Ot(t),[x,se]=s.useState([]),[Ce,ve]=s.useState(null),[T,b]=s.useState(!1),[h,k]=s.useState(null),[A,Z]=s.useState(!1),[ue,K]=s.useState(!1),[Y,I]=s.useState(null),[O,L]=s.useState(null),[fe,ce]=s.useState(null),[Q,je]=s.useState(!1),ke=s.useRef(!1),me=s.useRef(g);s.useEffect(()=>{me.current=g},[g]);const oe=s.useCallback(u=>{var H;(H=me.current)==null||H.call(me,u)},[]),xe=s.useCallback(()=>{b(!1),k(null),ce(null)},[]),ge=r??([n,o].filter(Boolean).join(" ")||void 0);s.useEffect(()=>{C==="ready"&&se(Rt(ee))},[ee,C]);const _e=s.useRef(null);s.useEffect(()=>{if(C==="error"&&P){if(_e.current===P)return;_e.current=P,oe({source:"list",message:P})}else C!=="error"&&(_e.current=null)},[C,P,oe]),s.useEffect(()=>{if(!c||ke.current||C!=="ready"||x.length===0||l)return;ke.current=!0;const u=x.find(H=>H.isDefault)??x[0];c(u)},[c,C,x,l]);const G=s.useCallback(u=>{se(H=>{const z=typeof u=="function"?u(H):u,$=Rt(z);return queueMicrotask(()=>f==null?void 0:f($)),$})},[f]),be=X==="pending"||ye==="pending"||ne==="pending",Re=s.useCallback(async u=>{const H=x;ve(null),G(z=>z.map($=>({...$,isDefault:$.id===u.id})));try{await de(u.id),E()}catch(z){se(H),f==null||f(H);const $=z instanceof Error?z.message:"Failed to set default payment method.";ve($),oe({source:"set-default",message:$,cause:z})}},[x,G,de,E,f,oe]),pe=s.useCallback(u=>{c==null||c(u),v&&(u.isDefault||Re(u))},[c,v,Re]),we=s.useCallback(async u=>{const H=x;ve(null);const z=x.filter(Ee=>Ee.id!==u.id);G(()=>z);const $=u.id===l&&c?z.find(Ee=>Ee.isDefault)??z[0]??null:null;$&&pe($);const te=!!$&&v&&$!==null&&!$.isDefault;try{await ae(u.id),te||E()}catch(Ee){se(H),f==null||f(H);const Me=Ee instanceof Error?Ee.message:"Failed to delete payment method.";ve(Me),oe({source:"delete",message:Me,cause:Ee})}},[x,G,ae,E,f,l,c,pe,v,oe]),N=s.useCallback(u=>{L(null),I(u)},[]),D=s.useCallback(()=>{I(null),L(null)},[]),V=s.useCallback(async u=>{if(!Y)return;const H=Y,z=x;L(null),G($=>$.map(te=>te.id===H.id?{...te,...u.cardholderName!==void 0?{cardholderName:u.cardholderName}:{},...u.zip!==void 0?{zip:u.zip}:{}}:te));try{await q(H.id,u),D(),E()}catch($){se(z),f==null||f(z);const te=Cr($);L(te),oe({source:"update",message:te,cause:$})}},[Y,x,G,q,E,f,D,oe]),ie=s.useCallback(u=>{k(null),b(!1),ce(null),G(z=>[u,...z.filter($=>$.id!==u.id)]),pe(u),!!c&&v&&!u.isDefault||E()},[G,E,pe,c,v]),He=s.useCallback(u=>{k(u)},[]),Je=C==="ready"&&x.length===0,Fe=typeof c=="function",Le=!Fe&&!p,Ze=x.length===0,ze=S&&x.length===0,Se=s.useCallback(u=>a.jsx(ft,{userId:t,isDefault:Ze,defaultCardholderName:ge,autoSave:!u&&ze,hideInternalSaveButton:u,formId:u?kt:void 0,onCanSubmitChange:u?Z:void 0,onSavingChange:u?K:void 0,autoFocus:u?"number":void 0,onSuccess:ie,onError:He,onErrorDetail:oe}),[t,Ze,ge,ze,ie,He,oe]),Be=s.useMemo(()=>Se(!1),[Se]),Ye=s.useMemo(()=>Se(!0),[Se]),We=!t,et=s.useMemo(()=>m?a.jsx(Ct,{selected:fe,onSelect:u=>ce(u),creditCardBody:Be,disabled:We}):Be,[m,fe,Be,We]),tt=s.useMemo(()=>m?a.jsx(Ct,{selected:fe,onSelect:u=>ce(u),creditCardBody:Ye,disabled:We}):Ye,[m,fe,Ye,We]);return a.jsxs("div",{className:J("flex w-full flex-col gap-4",W),"data-testid":"payment-methods-manager",children:[C==="loading"&&x.length===0?a.jsxs("div",{className:J(Le?"flex flex-col divide-y divide-grayWarm-200 rounded-xl border border-grayWarm-200 px-4 md:px-6":"flex flex-col gap-2"),"data-testid":"payment-methods-loading",children:[a.jsx(Nt,{withDefaultBadge:!0}),a.jsx(Nt,{})]}):null,C==="error"?a.jsxs("div",{role:"alert","aria-live":"polite",className:"flex items-center justify-between gap-3 rounded-md bg-error-50 p-3 text-sm text-error-700","data-testid":"payment-methods-list-error",children:[a.jsx("span",{children:P??"Failed to load payment methods."}),a.jsx("button",{type:"button",onClick:E,className:"rounded-md border border-error-700 px-3 py-1 text-xs font-semibold text-error-700 hover:bg-error-50",children:"Retry"})]}):null,Ce?a.jsx("div",{role:"alert","aria-live":"polite",className:"rounded-md bg-error-50 p-3 text-sm text-error-700","data-testid":"payment-methods-mutation-error",children:Ce}):null,p&&x.length>0?a.jsx("div",{className:"border-t border-grayWarm-200 pt-4",children:a.jsxs("div",{className:"flex items-center justify-between","data-testid":Q?"payment-methods-drawer-header":"payment-methods-collapsed-preview",children:[Q?a.jsx("h3",{className:"text-md font-semibold text-grayWarm-950",children:"Payment methods"}):a.jsx(At,{method:x.find(u=>u.id===l)??x.find(u=>u.isDefault)??x[0],cardLabelFormat:j,className:"flex-1"}),a.jsx("button",{type:"button","aria-label":Q?"Collapse payment methods":"Expand payment methods","aria-expanded":Q,className:"bg-grayWarm-100 p-2 rounded-lg hover:bg-grayWarm-200 transition-colors",onClick:()=>je(u=>!u),"data-testid":Q?"payment-methods-drawer-close":"payment-methods-drawer-open",children:a.jsx("img",{src:`${Te().iconCdnBaseUrl}/website/assets/icons/chevron-${Q?"up":"down"}-double.svg`,alt:"",className:"w-5 h-5"})})]})}):null,x.length>0&&(!p||Q)?a.jsx("div",{className:J("flex flex-col",Le?"rounded-xl border border-grayWarm-200 px-4 md:px-6 divide-y divide-grayWarm-200":"space-y-3"),children:x.map(u=>a.jsx(jr,{method:u,selectable:Fe,selected:Fe&&u.id===l,onSelect:pe,onSetDefault:Re,onRemove:we,onEdit:N,disabled:be,showDefaultBadge:w,hideSetDefaultMenuItem:v,cardLabelFormat:j},u.id))}):null,Je?a.jsx("div",{"data-testid":"payment-methods-empty",children:et}):x.length>0&&(!p||Q)?a.jsx("button",{type:"button",onClick:()=>{k(null),ce(null),Z(!1),b(!0)},onMouseEnter:()=>{ut().catch(()=>{})},onFocus:()=>{ut().catch(()=>{})},className:"self-start rounded-lg bg-brand-50 px-6 py-3 text-md font-semibold text-brand-600 transition-colors hover:bg-brand-100","data-testid":"payment-methods-add-trigger",children:"Add payment method"}):null,a.jsxs(yr,{open:T,onClose:xe,formId:kt,saveDisabled:!A,isSaving:ue,children:[tt,h?a.jsx("p",{role:"alert","aria-live":"polite",className:"mt-3 rounded-md bg-error-50 px-3 py-2 text-sm text-error-700","data-testid":"payment-methods-modal-error",children:h}):null]}),a.jsx(gr,{open:Y!==null,method:Y,onClose:D,onSave:V,isSaving:ne==="pending",error:O})]})};Ut.displayName="PaymentMethodsManager";const kr="/v1/auth/",Rr="movmo_csrf_token",Nr=t=>{if(typeof document>"u")return null;const r=document.cookie?document.cookie.split(";"):[];for(const n of r){const o=n.trim();if(o.startsWith(t+"="))return decodeURIComponent(o.substring(t.length+1))}return null},Sr=t=>typeof t=="string"?t:t instanceof URL?t.href:t.url,Pr=()=>{if(typeof globalThis<"u"&&typeof globalThis.fetch=="function")return globalThis.fetch.bind(globalThis);throw new Error("@movmo_app/payments: no global fetch available in this environment")},Tr=t=>{const{refreshSession:r,onRefreshFailed:n,csrfCookieName:o=Rr,extraHeaders:l,authPathFragment:c=kr,baseFetch:f=Pr(),readCookie:g=Nr}=t;let m=null;const S=()=>{if(m)return m;const w=(async()=>{await r()})();return m=w,w.finally(()=>{m===w&&(m=null)}).catch(()=>{}),w},v=(w,p)=>{const j=new Headers(p==null?void 0:p.headers),W=g(o);if(W&&!j.has("X-CSRF-Token")&&j.set("X-CSRF-Token",W),l){const ee=l(w,p);for(const[C,P]of Object.entries(ee))j.has(C)||j.set(C,P)}return{...p,headers:j,credentials:(p==null?void 0:p.credentials)??"include"}};return async function(p,j){const W=await f(p,v(p,j));if(Sr(p).includes(c)||W.status!==401&&W.status!==403)return W;try{await S()}catch(P){try{n(P)}catch(E){console.error("@movmo_app/payments: onRefreshFailed callback threw — auth retry path is misconfigured",E)}return W}try{return await f(p,v(p,j))}catch(P){return console.error("@movmo_app/payments: retry after token refresh failed — returning original response",P),W}}};exports.MovmoCardForm=ft;exports.PaymentMethodPreview=At;exports.PaymentMethodsManager=Ut;exports.createMovmoAuthFetch=Tr;exports.getPaymentsConfig=Te;exports.setPaymentsConfig=rr;exports.useDeletePaymentMethod=Wt;exports.useMovmoCardFields=Tt;exports.useSetDefaultPaymentMethod=Mt;exports.useUpdatePaymentMethod=Ot;exports.useUserPaymentMethods=Dt;
30
+ <%s key={someKey} {...props} />`,it,Pe,Gt,Pe),xt[Pe+it]=!0}}return e===o?Bt(q):zt(q),q}}function Yt(e,i,d){return bt(e,i,d,!0)}function Vt(e,i,d){return bt(e,i,d,!1)}var qt=Vt,Kt=Yt;Ke.Fragment=o,Ke.jsx=qt,Ke.jsxs=Kt}()),Ke}process.env.NODE_ENV==="production"?pt.exports=Xt():pt.exports=Qt();var a=pt.exports;function Tt(t){var r,s,o="";if(typeof t=="string"||typeof t=="number")o+=t;else if(typeof t=="object")if(Array.isArray(t)){var l=t.length;for(r=0;r<l;r++)t[r]&&(s=Tt(t[r]))&&(o&&(o+=" "),o+=s)}else for(s in t)t[s]&&(o&&(o+=" "),o+=s);return o}function Q(){for(var t,r,s=0,o="",l=arguments.length;s<l;s++)(t=arguments[s])&&(r=Tt(t))&&(o&&(o+=" "),o+=r);return o}const er="https://core.spreedly.com/iframe/iframe-v1.min.js",tr="https://cdn.e2e.movmo.io";let De={};const rr=t=>{De={...De,...t}},ct=t=>{var s;const r=globalThis.process;return(s=r==null?void 0:r.env)==null?void 0:s[t]},Te=()=>({baseUrl:De.baseUrl??ct("REACT_APP_MOVMO_API_URL")??"",spreedlyScriptUrl:De.spreedlyScriptUrl??ct("REACT_APP_SPREEDLY_SCRIPT_URL")??er,iconCdnBaseUrl:De.iconCdnBaseUrl??ct("REACT_APP_MOVMO_ICON_CDN_URL")??tr,fetch:De.fetch??(typeof globalThis<"u"&&typeof globalThis.fetch=="function"?globalThis.fetch.bind(globalThis):(()=>{throw new Error("@movmo_app/payments: no fetch available")})())}),ht=t=>({id:t.id,last4:t.last4,brand:t.brand,expMonth:t.expMonth,expYear:t.expYear,isDefault:t.isDefault,vault:t.vault,cardholderName:t.cardholderName,zip:t.zip}),$e={Accept:"application/json","Content-Type":"application/json"},Ae=t=>{const{baseUrl:r}=Te();if(!r)throw new Error("@movmo_app/payments: baseUrl is not configured. Call setPaymentsConfig({ baseUrl }) at app boot, or set REACT_APP_MOVMO_API_URL.");return`${r}${t}`},Ue=(t,r)=>{const{fetch:s}=Te();return s(t,r)},Ie=async(t,r)=>{try{return(await t.json()).message||r}catch{return r}};let Ge=null;const yt=()=>{if(Ge)return Ge;const t=(async()=>{const r=await Ue(Ae("/v1/payments/tokenization-session"),{method:"GET",headers:$e,credentials:"include"});if(!r.ok)throw new Error(await Ie(r,`Failed to fetch tokenization session (${r.status})`));return await r.json()})();return Ge=t,t.finally(()=>{Ge===t&&(Ge=null)}).catch(()=>{}),t},ar=t=>typeof t.brand=="string"&&typeof t.last4=="string"&&typeof t.expMonth=="number"&&typeof t.expYear=="number",nr=async(t,r,s)=>{const o=await Ue(Ae(`/v1/users/${encodeURIComponent(t)}/payment-methods/from-token`),{method:"POST",headers:$e,credentials:"include",body:JSON.stringify({tokenizedPaymentMethodId:r,isDefault:s})});if(!o.ok)throw new Error(await Ie(o,`Failed to save payment method (${o.status})`));const l=await o.json();if(ar(l))return ht(l);const c=await Ue(Ae(`/v1/users/${encodeURIComponent(t)}/payment-methods/${encodeURIComponent(l.id)}`),{method:"GET",headers:$e,credentials:"include"});if(!c.ok)throw new Error(await Ie(c,`Failed to fetch saved payment method (${c.status})`));const f=await c.json();return ht(f)},sr=async(t,r)=>{if(!t)return[];const s=await Ue(Ae(`/v1/users/${encodeURIComponent(t)}/payment-methods`),{method:"GET",headers:$e,credentials:"include",signal:r});if(!s.ok)throw new Error(await Ie(s,`Failed to fetch payment methods (${s.status})`));return(await s.json()??[]).map(ht)},or=async(t,r)=>{const s=await Ue(Ae(`/v1/users/${encodeURIComponent(t)}/payment-methods/${encodeURIComponent(r)}`),{method:"DELETE",headers:$e,credentials:"include"});if(!s.ok)throw new Error(await Ie(s,`Failed to delete payment method (${s.status})`))},Ft=async(t,r,s)=>{const o=await Ue(Ae(`/v1/users/${encodeURIComponent(t)}/payment-methods/${encodeURIComponent(r)}`),{method:"PUT",headers:$e,credentials:"include",body:JSON.stringify(s)});if(!o.ok)throw new Error(await Ie(o,`Failed to update payment method (${o.status})`))},ir={visa:"visa",master:"mastercard",mastercard:"mastercard",american_express:"amex",amex:"amex",discover:"discover"},lr=28,Ne=({brand:t,className:r,width:s=46})=>{const o=t?ir[t.toLowerCase()]??"credit-card":"credit-card",l=Math.max(s,lr),c=Math.round(l*24/34),{iconCdnBaseUrl:f}=Te();return a.jsx("img",{src:`${f}/website/assets/icons/payments/${o}.svg`,alt:o==="credit-card"?"card":`${o} card`,"data-testid":`card-brand-${t.toLowerCase()}`,className:r,width:l,height:c,loading:"lazy"})};let He=null;const cr=()=>{if(typeof window>"u")return Promise.reject(new Error("Spreedly can only be loaded in a browser environment."));if(window.Spreedly)return Promise.resolve(window.Spreedly);if(He)return He;const{spreedlyScriptUrl:t}=Te();return He=new Promise((r,s)=>{const o=document.querySelector(`script[src="${t}"]`),l=()=>{window.Spreedly?r(window.Spreedly):s(new Error("Spreedly script loaded but window.Spreedly is undefined."))};if(o){if(window.Spreedly){l();return}o.addEventListener("load",l,{once:!0}),o.addEventListener("error",()=>{o.remove(),s(new Error("Failed to load Spreedly iframe script."))},{once:!0});return}const c=document.createElement("script");c.src=t,c.async=!0,c.onload=l,c.onerror=()=>{c.remove(),s(new Error("Failed to load Spreedly iframe script."))},document.head.appendChild(c)}).catch(r=>{throw He=null,r}),He};class nt extends Error{constructor(s,o){super(o instanceof Error?o.message:"Failed to initialize card form.");lt(this,"source");lt(this,"cause");this.name="InitError",this.source=s,this.cause=o}}const dr="movmo-card-number",ur="movmo-card-cvv",fr=t=>({first_name:t.firstName,last_name:t.lastName,month:t.month,year:t.year,...t.email?{email:t.email}:{},...t.zip?{zip:t.zip}:{}}),Wt=(t={})=>{const{numberEl:r=dr,cvvEl:s=ur,onCardTokenized:o,onFieldErrors:l,onValidityChange:c,onBrandChange:f}=t,[x,m]=n.useState("idle"),[R,w]=n.useState(null),[p,v]=n.useState(null),[E,T]=n.useState(null),[se,M]=n.useState({number:!1,cvv:!1}),[C,b]=n.useState(null),[Y,ee]=n.useState({number:!1,cvv:!1}),ve=n.useRef(null),ue=n.useRef(o),te=n.useRef(l),oe=n.useRef(c),D=n.useRef(f);n.useEffect(()=>{ue.current=o},[o]),n.useEffect(()=>{te.current=l},[l]),n.useEffect(()=>{oe.current=c},[c]),n.useEffect(()=>{D.current=f},[f]);const j=n.useRef({number:!1,cvv:!1});n.useEffect(()=>{let S=!1;return m("loading"),w(null),v(null),T(null),M({number:!1,cvv:!1}),b(null),j.current={number:!1,cvv:!1},(async()=>{try{const[g,h]=await Promise.all([yt().catch(N=>{throw new nt("tokenization-session",N)}),cr().catch(N=>{throw new nt("spreedly-script",N)})]);if(S)return;ve.current=h,h.on("ready",()=>{var N,U,K,me,G,re;if(!S){m("ready");try{(N=h.setFieldType)==null||N.call(h,"number","tel"),(U=h.setFieldType)==null||U.call(h,"cvv","tel")}catch(H){console.warn("@movmo_app/payments: setFieldType failed",H)}try{typeof h.setNumberFormat=="function"?h.setNumberFormat("prettyFormat"):console.warn("@movmo_app/payments: Spreedly.setNumberFormat is missing — card-number digits will not be space-grouped.")}catch(H){console.warn("@movmo_app/payments: setNumberFormat failed",H)}try{(K=h.setPlaceholder)==null||K.call(h,"number","Card number"),(me=h.setPlaceholder)==null||me.call(h,"cvv","CVV");const H='box-sizing: border-box;width: 100%;height: 100%;margin: 0;padding: 0;border: 0;background: transparent;outline: none;font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;font-size: 14px;font-weight: 400;line-height: 20px;color: rgb(28 25 23);letter-spacing: 0;vertical-align: middle;';(G=h.setStyle)==null||G.call(h,"number",H),(re=h.setStyle)==null||re.call(h,"cvv",H)}catch(H){console.warn("@movmo_app/payments: setPlaceholder/setStyle failed",H)}}}),h.on("paymentMethod",N=>{var U;(U=ue.current)==null||U.call(ue,N)}),h.on("errors",N=>{var U;(U=te.current)==null||U.call(te,N)}),h.on("fieldEvent",(N,U,K,me)=>{var H;if(S)return;if(U==="focus"){ee(W=>W[N]?W:{...W,[N]:!0});return}if(U==="blur"){ee(W=>W[N]?{...W,[N]:!1}:W);return}if(U!=="input")return;const G=me??{};if(N==="number"){if(G.numberLength===0)b(W=>{var Z;return W!==null&&((Z=D.current)==null||Z.call(D,null)),null});else if(G.cardType!==void 0){const W=G.cardType||null;b(Z=>{var je;return Z!==W&&((je=D.current)==null||je.call(D,W)),W})}}const re=N==="number"?typeof G.validNumber=="boolean"?G.validNumber:void 0:typeof G.validCvv=="boolean"?G.validCvv:void 0;if(typeof re=="boolean"){const W=j.current,Z=N==="number"?{...W,number:re}:{...W,cvv:re};(Z.number!==W.number||Z.cvv!==W.cvv)&&(j.current=Z,M(Z),(H=oe.current)==null||H.call(oe,Z))}}),h.on("consoleError",N=>{var K;const U=N instanceof Error?N.message:"An unexpected error occurred while securing your card.";(K=te.current)==null||K.call(te,[{message:U}])}),h.init(g.environmentKey,{numberEl:r,cvvEl:s,nonce:g.nonce,timestamp:String(g.timestamp),certificateToken:g.certificateToken,signature:g.signature})}catch(g){if(S)return;const h=g instanceof Error?g.message:"Failed to initialize card form.";w(h),v(g instanceof nt?g.source:"spreedly-script"),T(g instanceof nt?g.cause:g),m("error")}})(),()=>{var g,h;S=!0;try{(h=(g=ve.current)==null?void 0:g.removeHandlers)==null||h.call(g)}catch(N){console.warn("@movmo_app/payments: removeHandlers failed during cleanup",N)}ve.current=null}},[r,s]);const fe=n.useCallback(S=>{var g;(g=ve.current)==null||g.tokenizeCreditCard(fr(S))},[]),Ee=n.useCallback(S=>{var g,h;(h=(g=ve.current)==null?void 0:g.transferFocus)==null||h.call(g,S)},[]);return{status:x,error:R,errorSource:p,errorCause:E,tokenize:fe,validity:se,brand:C,focused:Y,focusField:Ee}},dt="h-11 w-full rounded-md border border-grayWarm-300 bg-white px-3 py-2 text-sm text-grayWarm-900 placeholder:text-grayWarm-400 outline-none focus:border-grayWarm-950 focus:shadow-[0_0_0_1px_#1c1917]",jt="flex h-11 w-full items-center gap-2 rounded-md border bg-white px-3 py-2 transition-shadow",_t="border-grayWarm-950 shadow-[0_0_0_1px_#1c1917]",Ct="border-grayWarm-300",mr=t=>{const r=t.trim();if(!r)return{firstName:"",lastName:""};const s=r.lastIndexOf(" ");return s===-1?{firstName:r,lastName:""}:{firstName:r.slice(0,s).trim(),lastName:r.slice(s+1).trim()}},Mt=t=>{const r=t.replace(/\D/g,"");if(r.length<4)return{month:"",year:""};const s=r.slice(0,2),o=r.slice(2),l=o.length===2?`20${o}`:o.slice(0,4);return{month:s,year:l}},pr=t=>{const r=t.replace(/\D/g,"").slice(0,4);return r.length<=2?r:`${r.slice(0,2)} / ${r.slice(2)}`},ut=t=>{const{month:r,year:s}=Mt(t);if(!r||!s)return!1;const o=parseInt(r,10),l=parseInt(s,10);if(isNaN(o)||o<1||o>12)return!1;const c=new Date;return!(l<c.getFullYear()||l>c.getFullYear()+20||l===c.getFullYear()&&o<c.getMonth()+1)},ft=t=>/^\d{5}(-\d{4})?$/.test(t.trim()),hr=t=>{const r=t.replace(/[^\d]/g,"").slice(0,9);return r.length<=5?r:`${r.slice(0,5)}-${r.slice(5)}`},vt=({userId:t,onSuccess:r,onError:s,onErrorDetail:o,isDefault:l=!1,className:c,defaultCardholderName:f,defaultCardholderFirstName:x="",defaultCardholderLastName:m="",autoSave:R=!1,formId:w="movmo-card-form",hideInternalSaveButton:p=!1,onCanSubmitChange:v,onSavingChange:E,autoFocus:T})=>{const se=f??[x,m].filter(Boolean).join(" "),[M,C]=n.useState(se),[b,Y]=n.useState(""),[ee,ve]=n.useState(""),[ue,te]=n.useState("idle"),oe=n.useRef(!1),D=n.useRef(o);n.useEffect(()=>{D.current=o},[o]);const j=n.useCallback(async P=>{var $;te("saving");try{const A=await nr(t,P,l);te("ready"),r(A)}catch(A){const de=A instanceof Error?A.message:"Failed to save payment method.";te("ready"),oe.current=!1,s(de),($=D.current)==null||$.call(D,{source:"save-from-token",message:de,cause:A})}},[t,l,r,s]),fe=n.useCallback(P=>{var A;const $=P.map(de=>de.message).filter(Boolean).join("; ")||"Card validation failed.";te(de=>de==="tokenizing"?"ready":de),oe.current=!1,s($),(A=D.current)==null||A.call(D,{source:"card-tokenize",message:$})},[s]),Ee=n.useMemo(()=>({onCardTokenized:j,onFieldErrors:fe}),[j,fe]),{status:S,error:g,errorSource:h,errorCause:N,tokenize:U,validity:K,brand:me,focused:G,focusField:re}=Wt(Ee),H=n.useRef(!1);n.useEffect(()=>{!T||S!=="ready"||H.current||(H.current=!0,re(T))},[T,S,re]);const W=M.trim().split(/\s+/).length>=2,Z=ut(b),je=ft(ee),pe=n.useRef(!1),he=n.useRef(!1),ie=n.useRef(!1),ae=n.useRef(null),_e=n.useRef(null);n.useEffect(()=>{var P;K.cvv?he.current||(he.current=!0,(P=ae.current)==null||P.focus()):he.current=!1},[K.cvv]);const Fe=!W||!Z||!je||!K.number||!K.cvv,le=ue==="tokenizing"||ue==="saving",J=S==="ready"&&!le&&!Fe,ge=n.useRef(v);n.useEffect(()=>{ge.current=v},[v]),n.useEffect(()=>{var P;(P=ge.current)==null||P.call(ge,J)},[J]);const z=n.useRef(E);n.useEffect(()=>{z.current=E},[E]),n.useEffect(()=>{var P;(P=z.current)==null||P.call(z,le)},[le]);const xe=n.useCallback(()=>{const{firstName:P,lastName:$}=mr(M),{month:A,year:de}=Mt(b);te("tokenizing"),U({firstName:P,lastName:$,month:A,year:de,zip:ee.trim()})},[M,b,ee,U]);n.useEffect(()=>{if(!R||!J||oe.current)return;const P=setTimeout(()=>{oe.current=!0,xe()},1200);return()=>clearTimeout(P)},[R,J,xe]);const Se=P=>{P.preventDefault(),J&&xe()},we=S!=="ready"||le,X=n.useRef(s);return n.useEffect(()=>{X.current=s},[s]),n.useEffect(()=>{var P,$;g&&((P=X.current)==null||P.call(X,g),($=D.current)==null||$.call(D,{source:h??"spreedly-script",message:g,cause:N}))},[g,h,N]),a.jsxs("form",{id:w,onSubmit:Se,className:Q("flex w-full flex-col gap-3",c),"data-testid":"movmo-card-form",children:[a.jsxs("div",{children:[a.jsx("span",{id:"movmo-card-number-label",className:"sr-only",children:"Card number"}),a.jsxs("div",{className:Q(jt,G.number?_t:Ct),children:[a.jsx(Ne,{brand:me??"",width:32,className:"flex-shrink-0"}),a.jsxs("div",{className:"relative h-full flex-1",children:[a.jsx("div",{id:"movmo-card-number","aria-labelledby":"movmo-card-number-label","aria-busy":S!=="ready",className:"absolute inset-0","data-testid":"movmo-card-number-mount"}),S!=="ready"?a.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-y-2 left-0 right-2 animate-pulse rounded bg-grayWarm-200"}):null]})]})]}),a.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{htmlFor:"movmo-card-expiry",className:"sr-only",children:"Expiry MM / YY"}),a.jsx("input",{id:"movmo-card-expiry",type:"text",inputMode:"numeric",autoComplete:"cc-exp",placeholder:"MM / YY",value:b,onChange:P=>{const $=pr(P.target.value);Y($),ut($)&&!pe.current?(pe.current=!0,re("cvv")):ut($)||(pe.current=!1)},className:Q(dt,b&&!Z&&"border-error-500"),disabled:we,required:!0,"data-testid":"movmo-card-expiry-input"})]}),a.jsxs("div",{className:"relative",children:[a.jsx("span",{id:"movmo-card-cvv-label",className:"sr-only",children:"CVV"}),a.jsxs("div",{className:Q(jt,G.cvv?_t:Ct),children:[a.jsxs("div",{className:"relative h-full flex-1",children:[a.jsx("div",{id:"movmo-card-cvv","aria-labelledby":"movmo-card-cvv-label","aria-busy":S!=="ready",className:"absolute inset-0","data-testid":"movmo-card-cvv-mount"}),S!=="ready"?a.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-y-2 left-0 right-2 animate-pulse rounded bg-grayWarm-200"}):null]}),a.jsx("button",{type:"button","aria-label":"CVV help",tabIndex:-1,className:"flex h-5 w-5 flex-shrink-0 items-center justify-center rounded-full border border-grayWarm-300 text-xs text-grayWarm-500",title:me==="american_express"?"The 4 numbers on the front of your card.":"The 3 numbers on the back of your card.","data-testid":"movmo-cvv-help",children:"?"})]})]}),a.jsxs("div",{children:[a.jsx("label",{htmlFor:"movmo-card-zip",className:"sr-only",children:"ZIP code"}),a.jsx("input",{id:"movmo-card-zip",ref:ae,type:"text",inputMode:"numeric",autoComplete:"postal-code",placeholder:"ZIP code",value:ee,onChange:P=>{var A;const $=hr(P.target.value);ve($),ft($)&&!ie.current?(ie.current=!0,(A=_e.current)==null||A.focus()):ft($)||(ie.current=!1)},className:Q(dt,ee&&!je&&"border-error-500"),disabled:we,required:!0,"data-testid":"movmo-card-zip-input"})]})]}),a.jsxs("div",{children:[a.jsx("label",{htmlFor:"movmo-card-cardholder-name",className:"sr-only",children:"Cardholder name"}),a.jsx("input",{id:"movmo-card-cardholder-name",ref:_e,type:"text",autoComplete:"cc-name",placeholder:"Cardholder name",value:M,onChange:P=>C(P.target.value),className:dt,disabled:we,required:!0,"data-testid":"movmo-card-cardholder-name-input"})]}),!R&&!p?a.jsx("button",{type:"submit",disabled:!J,className:Q("inline-flex h-11 items-center justify-center rounded-md bg-brand-500 px-4 text-sm font-semibold text-white transition-colors hover:bg-brand-600","disabled:cursor-not-allowed disabled:bg-grayWarm-300 disabled:text-grayWarm-500"),"data-testid":"movmo-card-save",children:le?"Saving…":S==="loading"?"Loading…":"Save card"}):le&&R?a.jsx("p",{className:"text-center text-sm text-grayWarm-500","aria-live":"polite","data-testid":"movmo-card-autosaving",children:"Saving card…"}):null]})};vt.displayName="MovmoCardForm";const Ot=t=>{const[r,s]=n.useState("idle"),[o,l]=n.useState(null);return{deletePaymentMethod:n.useCallback(async f=>{s("pending"),l(null);try{await or(t,f),s("idle")}catch(x){const m=x instanceof Error?x.message:"Failed to delete payment method.";throw l(m),s("error"),x}},[t]),status:r,error:o}},Dt=t=>{const[r,s]=n.useState("idle"),[o,l]=n.useState(null);return{setDefault:n.useCallback(async f=>{s("pending"),l(null);try{await Ft(t,f,{isDefault:!0}),s("idle")}catch(x){const m=x instanceof Error?x.message:"Failed to set default payment method.";throw l(m),s("error"),x}},[t]),status:r,error:o}},$t=t=>{const[r,s]=n.useState("idle"),[o,l]=n.useState(null);return{updatePaymentMethod:n.useCallback(async(f,x)=>{s("pending"),l(null);try{await Ft(t,f,x),s("idle")}catch(m){const R=m instanceof Error?m.message:"Failed to update payment method.";throw l(R),s("error"),m}},[t]),status:r,error:o}},At=t=>{const[r,s]=n.useState([]),[o,l]=n.useState("idle"),[c,f]=n.useState(null),[x,m]=n.useState(0),R=n.useRef(null);n.useEffect(()=>{var v;if((v=R.current)==null||v.abort(),!t){R.current=null,s([]),f(null),l("ready");return}const p=new AbortController;return R.current=p,l("loading"),f(null),sr(t,p.signal).then(E=>{p.signal.aborted||(s(E),l("ready"))}).catch(E=>{if(p.signal.aborted||E instanceof DOMException&&E.name==="AbortError")return;const T=E instanceof Error?E.message:"Failed to fetch payment methods.";f(T),l("error")}),()=>{p.abort()}},[t,x]);const w=n.useCallback(()=>{m(p=>p+1)},[]);return{items:r,status:o,error:c,refetch:w}},Ut=({open:t,onClose:r,title:s,titleId:o,formId:l,saveDisabled:c,saveLabel:f="Save",isSaving:x=!1,testIdPrefix:m="payment-method",children:R})=>(n.useEffect(()=>{if(!t)return;const w=p=>{p.key==="Escape"&&r()};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[t,r]),n.useEffect(()=>{if(!t)return;const w=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=w}},[t]),t?a.jsx("div",{role:"dialog","aria-modal":"true","aria-labelledby":o,className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",onClick:w=>{w.target===w.currentTarget&&r()},"data-testid":`${m}-modal`,children:a.jsxs("div",{className:"flex max-h-full w-full max-w-md flex-col rounded-xl bg-white shadow-2xl",children:[a.jsxs("div",{className:"flex items-center gap-3 border-b border-grayWarm-200 px-4 py-3",children:[a.jsx("button",{type:"button",onClick:r,"aria-label":`Close ${s.toLowerCase()} dialog`,className:"flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg bg-grayWarm-100 p-2 text-grayWarm-950 transition-colors hover:bg-grayWarm-200","data-testid":`${m}-close`,children:a.jsx("svg",{viewBox:"0 0 20 20",width:"20",height:"20","aria-hidden":"true",children:a.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"currentColor",strokeWidth:"1.67",strokeLinecap:"round",strokeLinejoin:"round"})})}),a.jsx("h2",{id:o,className:"flex-1 text-center text-base font-semibold text-grayWarm-900",children:s}),a.jsx("span",{"aria-hidden":"true",className:"h-9 w-9 flex-shrink-0"})]}),a.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:R}),a.jsxs("div",{className:"flex gap-3 border-t border-grayWarm-200 p-4",children:[a.jsx("button",{type:"button",onClick:r,className:"inline-flex h-11 flex-1 items-center justify-center rounded-lg border border-grayWarm-300 px-4 text-sm font-semibold text-grayWarm-900 transition-colors hover:border-grayWarm-900 hover:shadow-[0_0_0_1px_#1c1917]","data-testid":`${m}-cancel`,children:"Cancel"}),a.jsx("button",{type:"submit",form:l,disabled:x?!1:c,"aria-disabled":x||c,"aria-busy":x,className:Q("inline-flex h-11 flex-1 items-center justify-center rounded-lg bg-brand-500 px-4 text-sm font-semibold text-white transition-colors",x?"cursor-not-allowed opacity-90 pointer-events-none":"hover:bg-brand-600 disabled:cursor-not-allowed disabled:bg-grayWarm-300 disabled:text-grayWarm-500"),"data-testid":`${m}-save`,children:x?a.jsxs(a.Fragment,{children:[a.jsxs("svg",{className:"h-[18px] w-[18px] animate-spin",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[a.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3",strokeOpacity:"0.25"}),a.jsx("path",{d:"M22 12a10 10 0 0 1-10 10",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round"})]}),a.jsx("span",{className:"sr-only",children:"Saving"})]}):f})]})]})}):null),yr=({open:t,onClose:r,formId:s,saveDisabled:o,saveLabel:l="Save",isSaving:c=!1,children:f})=>a.jsx(Ut,{open:t,onClose:r,title:"Add payment method",titleId:"movmo-add-payment-title",formId:s,saveDisabled:o,saveLabel:l,isSaving:c,testIdPrefix:"add-payment-method",children:f}),vr=(t,r)=>`${String(t).padStart(2,"0")}/${r}`,gr=t=>{if(!t)return"Card";const r=t.toLowerCase();return r==="amex"?"Amex":r.charAt(0).toUpperCase()+r.slice(1)},xr=({open:t,method:r,onClose:s,onSave:o,isSaving:l=!1,error:c=null})=>{const f=n.useId(),[x,m]=n.useState(""),[R,w]=n.useState("");if(n.useEffect(()=>{t&&r&&(m(r.cardholderName??""),w(r.zip??""))},[t,r]),!r)return null;const p=x.trim(),v=R.trim(),E=p!==(r.cardholderName??"").trim(),T=v!==(r.zip??"").trim(),se=E||T,M=(!E||p.length>0)&&(!T||/^[A-Za-z0-9 -]{3,20}$/.test(v)),C=!se||!M,b=Y=>{if(Y.preventDefault(),C||l)return;const ee={};E&&(ee.cardholderName=p),T&&(ee.zip=v),o(ee).catch(()=>{})};return a.jsxs(Ut,{open:t,onClose:s,title:"Edit payment method",titleId:"movmo-edit-payment-title",formId:f,saveDisabled:C,isSaving:l,testIdPrefix:"edit-payment-method",children:[a.jsxs("div",{className:"mb-4 flex items-start gap-3 rounded-lg bg-grayWarm-50 p-3","data-testid":"edit-payment-method-context",children:[a.jsx(Ne,{brand:r.brand,className:"flex-shrink-0"}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsxs("div",{className:"text-lg font-semibold text-grayWarm-950",children:[gr(r.brand)," •••• ",r.last4]}),a.jsxs("div",{className:"text-sm text-grayWarm-600",children:["Exp. ",vr(r.expMonth,r.expYear)]})]})]}),a.jsxs("form",{id:f,onSubmit:b,className:"flex flex-col gap-4",noValidate:!0,children:[a.jsxs("label",{className:"flex flex-col gap-1.5 text-sm font-medium text-grayWarm-700",children:["Cardholder name",a.jsx("input",{type:"text",autoComplete:"cc-name",value:x,onChange:Y=>m(Y.target.value),disabled:l,maxLength:255,"data-testid":"edit-payment-method-cardholder",className:"h-11 rounded-lg border border-grayWarm-300 px-3 text-base font-normal text-grayWarm-950 focus:border-grayWarm-950 focus:outline-none focus:ring-1 focus:ring-grayWarm-950"})]}),a.jsxs("label",{className:"flex flex-col gap-1.5 text-sm font-medium text-grayWarm-700",children:["Billing ZIP",a.jsx("input",{type:"text",inputMode:"numeric",autoComplete:"postal-code",value:R,onChange:Y=>w(Y.target.value),disabled:l,maxLength:20,"data-testid":"edit-payment-method-zip",className:"h-11 rounded-lg border border-grayWarm-300 px-3 text-base font-normal text-grayWarm-950 focus:border-grayWarm-950 focus:outline-none focus:ring-1 focus:ring-grayWarm-950"})]}),c?a.jsx("p",{role:"alert",className:"text-sm text-error-700","data-testid":"edit-payment-method-error",children:c}):null]})]})},br=t=>{if(!t)return"Card";const r=t.toLowerCase();return r==="amex"?"Amex":r.charAt(0).toUpperCase()+r.slice(1)},It=({method:t,trailing:r,onClick:s,cardLabelFormat:o="branded",className:l})=>a.jsxs("div",{className:Q("flex items-center gap-3",s&&"cursor-pointer",l),onClick:s,role:s?"button":void 0,tabIndex:s?0:void 0,onKeyDown:s?c=>{(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),s())}:void 0,"data-testid":`payment-method-preview-${t.id}`,children:[a.jsx(Ne,{brand:t.brand,width:34,className:"flex-shrink-0"}),a.jsx("span",{className:"flex-1 text-lg font-semibold text-grayWarm-950",children:o==="masked"?`•••• ${t.last4}`:`${br(t.brand)} ${t.last4}`}),r]}),wr=(t,r,s=new Date)=>r<s.getFullYear()||r===s.getFullYear()&&t<s.getMonth()+1,kt=t=>{if(!t)return"Card";const r=t.toLowerCase();return r==="amex"?"Amex":r.charAt(0).toUpperCase()+r.slice(1)},Er=(t,r)=>`${String(t).padStart(2,"0")}/${r}`,jr=({method:t,selectable:r,selected:s,onSelect:o,onSetDefault:l,onRemove:c,onEdit:f,disabled:x,showDefaultBadge:m,hideSetDefaultMenuItem:R,cardLabelFormat:w="branded"})=>{const[p,v]=n.useState(!1),E=n.useRef(null),T=wr(t.expMonth,t.expYear);n.useEffect(()=>{if(!p)return;const M=C=>{var b;(b=E.current)!=null&&b.contains(C.target)||v(!1)};return document.addEventListener("mousedown",M),()=>document.removeEventListener("mousedown",M)},[p]);const se=()=>{r&&o&&!x&&o(t)};return a.jsxs("div",{className:Q("flex items-start gap-3 transition-colors",r?"rounded-lg border px-3 py-3":"py-4",r&&!x&&"cursor-pointer",r&&(s?"border-grayWarm-950 shadow-[0_0_0_1px_#1c1917]":"border-grayWarm-200 hover:border-grayWarm-300")),onClick:se,"data-testid":`payment-method-row-${t.id}`,children:[r?a.jsx("input",{type:"radio",name:"movmo-payment-method",checked:s,onChange:()=>o==null?void 0:o(t),onClick:M=>M.stopPropagation(),"aria-label":`Select ${kt(t.brand)} ending ${t.last4}`,className:"mr-1 h-4 w-4 mt-2 cursor-pointer appearance-none rounded-full border-2 border-grayWarm-300 checked:border-[5px] checked:border-grayWarm-950 bg-white checked:bg-white focus:ring-0 focus:ring-offset-0",disabled:x}):null,a.jsx(Ne,{brand:t.brand,className:"flex-shrink-0"}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[a.jsx("span",{className:"text-lg font-semibold text-grayWarm-950",children:w==="masked"?`•••• ${t.last4}`:`${kt(t.brand)} ${t.last4}`}),m&&t.isDefault?a.jsx("span",{className:"inline-flex items-center rounded-full bg-success-50 px-2 py-0.5 text-xs font-semibold text-success-700","data-testid":`badge-default-${t.id}`,children:"Default"}):null,T?a.jsx("span",{className:"inline-flex items-center rounded-full bg-error-50 px-2 py-0.5 text-xs font-semibold text-error-700","data-testid":`badge-expired-${t.id}`,children:"Expired"}):null]}),a.jsxs("div",{className:Q("text-base",T?"text-grayWarm-400":"text-grayWarm-600"),children:["Exp. ",Er(t.expMonth,t.expYear)]})]}),a.jsxs("div",{className:"relative flex-shrink-0",ref:E,children:[a.jsx("button",{type:"button","aria-label":`Open actions for card ending ${t.last4}`,"aria-haspopup":"menu","aria-expanded":p,className:"rounded-lg p-2 text-grayWarm-600 transition-colors hover:bg-grayWarm-100 disabled:cursor-not-allowed disabled:opacity-50",disabled:x,onClick:M=>{M.stopPropagation(),v(C=>!C)},"data-testid":`menu-trigger-${t.id}`,children:a.jsx("svg",{viewBox:"0 0 24 24",width:"20",height:"20",fill:"currentColor","aria-hidden":"true",children:a.jsx("path",{d:"M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"})})}),p?a.jsxs("div",{role:"menu",className:Q("absolute z-10 whitespace-nowrap rounded-lg border border-grayWarm-200 bg-white py-1 shadow-lg",r?"bottom-full left-1/2 mb-2 -translate-x-1/2":"right-0 top-full mt-1"),onClick:M=>M.stopPropagation(),"data-testid":`menu-${t.id}`,children:[r?a.jsx("span",{"aria-hidden":"true",className:"absolute -bottom-1.5 left-1/2 h-3 w-3 -translate-x-1/2 rotate-45 border-b border-r border-grayWarm-200 bg-white"}):null,!t.isDefault&&!R?a.jsx("button",{type:"button",role:"menuitem",className:"block w-full px-4 py-1 text-left text-md font-semibold text-grayWarm-950 hover:text-grayWarm-700",onClick:()=>{v(!1),l(t)},"data-testid":`menu-set-default-${t.id}`,children:"Set as default"}):null,f&&t.vault==="spreedly"?a.jsx("button",{type:"button",role:"menuitem",className:"block w-full px-4 py-1 text-left text-md font-semibold text-grayWarm-950 hover:text-grayWarm-700",onClick:()=>{v(!1),f(t)},"data-testid":`menu-edit-${t.id}`,children:"Edit"}):null,a.jsx("button",{type:"button",role:"menuitem",className:"block w-full px-4 py-1 text-left text-md font-semibold text-error-700 hover:text-error-500",onClick:()=>{v(!1),c(t)},"data-testid":`menu-remove-${t.id}`,children:"Delete"})]}):null]})]})},_r=t=>`${Te().iconCdnBaseUrl}/website/assets/icons/payments/${t}.svg`,mt=({slug:t,alt:r})=>a.jsx("img",{src:_r(t),alt:r,height:20,loading:"lazy",style:{height:20,width:"auto"}}),st=({type:t,label:r,iconNode:s,disabled:o=!1})=>a.jsxs("label",{className:"flex cursor-pointer items-center gap-3 rounded-lg border border-grayWarm-200 px-4 py-3 transition-colors hover:border-grayWarm-300","data-testid":`payment-type-${t}`,children:[a.jsx("input",{type:"radio",name:"movmo-payment-type",value:t,disabled:o,onChange:()=>{},className:Q("h-4 w-4 accent-grayWarm-900",o?"cursor-not-allowed":"cursor-pointer"),"aria-label":r}),a.jsxs("span",{className:"flex flex-1 items-center gap-2 text-sm font-semibold text-grayWarm-900",children:[r,s]})]}),Rt=({selected:t,onSelect:r,creditCardBody:s,disabled:o=!1,className:l})=>{const c=t==="credit_card";return a.jsxs("div",{className:Q("flex w-full flex-col gap-3",l),children:[a.jsxs("label",{className:Q("flex cursor-pointer flex-col gap-3 rounded-lg border px-4 py-3 transition-colors",c?"border-grayWarm-900 shadow-[0_0_0_1px_#1c1917]":"border-grayWarm-200"),"data-testid":"payment-type-credit_card",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("input",{type:"radio",name:"movmo-payment-type",value:"credit_card",checked:c,disabled:o,onChange:()=>{o||r("credit_card")},className:Q("h-4 w-4 accent-grayWarm-900",o?"cursor-not-allowed":"cursor-pointer"),"aria-label":"Credit card"}),a.jsx("span",{className:"flex-1 text-sm font-semibold text-grayWarm-900",children:"Credit card"}),a.jsxs("div",{className:"flex items-center gap-1.5",children:[a.jsx(Ne,{brand:"mastercard",width:28}),a.jsx(Ne,{brand:"visa",width:28}),a.jsx(Ne,{brand:"amex",width:28}),a.jsx(Ne,{brand:"discover",width:28})]})]}),c?a.jsx("div",{"data-testid":"payment-type-credit_card-body",children:s}):null]}),c?a.jsx("p",{className:"mt-2 text-sm font-semibold text-grayWarm-900","data-testid":"payment-type-other-options-header",children:"Other options"}):null,a.jsx(st,{type:"paypal",label:"PayPal",iconNode:a.jsx(mt,{slug:"paypal",alt:"PayPal"}),disabled:o}),a.jsx(st,{type:"googlepay",label:"GooglePay",iconNode:a.jsx(mt,{slug:"google-pay",alt:"GooglePay"}),disabled:o}),a.jsx(st,{type:"klarna",label:"Klarna",iconNode:a.jsx(mt,{slug:"klarna",alt:"Klarna"}),disabled:o}),a.jsx(st,{type:"ach",label:"Bank account (ACH)",iconNode:a.jsx("span",{className:"text-xs font-medium text-grayWarm-500",children:"Direct debit"}),disabled:o})]})},Nt="movmo-add-payment-form",Cr=t=>{console.error("@movmo_app/payments: failed to update payment method",t);const r=t instanceof Error?t.message.trim():"";return/spreedly-backed cards/i.test(r)?"This card's details can't be edited.":r||"Failed to update payment method."},St=t=>{const r=t.filter(o=>o.isDefault),s=t.filter(o=>!o.isDefault);return[...r,...s]},Pt=({withDefaultBadge:t=!1})=>a.jsxs("div",{className:"flex items-start justify-between py-4","data-testid":"payment-method-skeleton",children:[a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"h-8 w-[46px] flex-shrink-0 animate-pulse rounded bg-grayWarm-200"}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("div",{className:"h-5 w-[120px] animate-pulse rounded bg-grayWarm-200"}),t?a.jsx("div",{className:"h-5 w-[56px] animate-pulse rounded-full bg-grayWarm-200"}):null]}),a.jsx("div",{className:"h-4 w-[100px] animate-pulse rounded bg-grayWarm-200"})]})]}),a.jsx("div",{className:"h-5 w-5 flex-shrink-0 animate-pulse rounded-full bg-grayWarm-200"})]}),Lt=({userId:t,defaultCardholderName:r,defaultCardholderFirstName:s,defaultCardholderLastName:o,selectedId:l,onSelect:c,onChange:f,onError:x,onEvent:m,paymentTypeSelector:R=!0,autoSaveFirstCard:w=!0,selectionSetsDefault:p=!1,showDefaultBadge:v=!0,collapsible:E=!1,cardLabelFormat:T="branded",className:se})=>{const{items:M,status:C,error:b,refetch:Y}=At(t),{deletePaymentMethod:ee,status:ve}=Ot(t),{setDefault:ue,status:te}=Dt(t),{updatePaymentMethod:oe,status:D}=$t(t),[j,fe]=n.useState([]),Ee=n.useRef(j);n.useEffect(()=>{Ee.current=j},[j]);const[S,g]=n.useState(null),[h,N]=n.useState(!1),[U,K]=n.useState(null),[me,G]=n.useState(!1),[re,H]=n.useState(!1),[W,Z]=n.useState(null),[je,pe]=n.useState(null),[he,ie]=n.useState(null),[ae,_e]=n.useState(!1),Fe=n.useRef(!1),le=n.useRef(x);n.useEffect(()=>{le.current=x},[x]);const J=n.useCallback(u=>{var B;(B=le.current)==null||B.call(le,u)},[]),ge=n.useRef(m);n.useEffect(()=>{ge.current=m},[m]);const z=n.useCallback((u,B)=>{var I;(I=ge.current)==null||I.call(ge,u,B)},[]),xe=n.useCallback(()=>{N(!1),K(null),ie(null)},[]),Se=r??([s,o].filter(Boolean).join(" ")||void 0);n.useEffect(()=>{C==="ready"&&fe(St(M))},[M,C]);const we=n.useRef(null);n.useEffect(()=>{if(C==="error"&&b){if(we.current===b)return;we.current=b,J({source:"list",message:b})}else C!=="error"&&(we.current=null)},[C,b,J]),n.useEffect(()=>{if(!c||Fe.current||C!=="ready"||j.length===0||l)return;Fe.current=!0,z("autoselected",{had_saved_methods:!0});const u=j.find(B=>B.isDefault)??j[0];c(u)},[c,C,j,l,z]);const X=n.useCallback(u=>{fe(B=>{const I=typeof u=="function"?u(B):u,L=St(I);return queueMicrotask(()=>f==null?void 0:f(L)),L})},[f]),P=ve==="pending"||te==="pending"||D==="pending",$=n.useCallback(async u=>{const B=j;g(null),X(I=>I.map(L=>({...L,isDefault:L.id===u.id})));try{await ue(u.id),Y(),z("set_default")}catch(I){fe(B),f==null||f(B);const L=I instanceof Error?I.message:"Failed to set default payment method.";g(L),J({source:"set-default",message:L,cause:I})}},[j,X,ue,Y,f,J,z]),A=n.useCallback(u=>{c==null||c(u),p&&(u.isDefault||$(u))},[c,p,$]),de=n.useCallback(u=>{z("selected",{method_count:j.length}),A(u)},[z,j,A]),ot=n.useCallback(async u=>{const B=j;g(null);const I=j.filter(Ce=>Ce.id!==u.id);X(()=>I);const L=u.id===l&&c?I.find(Ce=>Ce.isDefault)??I[0]??null:null;L&&A(L);const be=!!L&&p&&L!==null&&!L.isDefault;try{await ee(u.id),be||Y(),z("deleted",{remaining_count:I.length})}catch(Ce){fe(B),f==null||f(B);const Ve=Ce instanceof Error?Ce.message:"Failed to delete payment method.";g(Ve),J({source:"delete",message:Ve,cause:Ce})}},[j,X,ee,Y,f,l,c,A,p,J,z]),Je=n.useCallback(u=>{pe(null),Z(u)},[]),We=n.useCallback(()=>{Z(null),pe(null)},[]),Ze=n.useCallback(async u=>{if(!W)return;const B=W,I=j;pe(null),X(L=>L.map(be=>be.id===B.id?{...be,...u.cardholderName!==void 0?{cardholderName:u.cardholderName}:{},...u.zip!==void 0?{zip:u.zip}:{}}:be));try{await oe(B.id,u),We(),Y(),z("edited",{fields:Object.keys(u)})}catch(L){fe(I),f==null||f(I);const be=Cr(L);pe(be),J({source:"update",message:be,cause:L})}},[W,j,X,oe,Y,f,We,J,z]),Xe=n.useCallback(u=>{K(null),N(!1),ie(null),X(I=>[u,...I.filter(L=>L.id!==u.id)]),A(u),!!c&&p&&!u.isDefault||Y(),z("added",{method_count:Ee.current.length+1})},[X,Y,A,c,p,z]),Le=n.useCallback(u=>{K(u)},[]),Qe=C==="ready"&&j.length===0,ze=typeof c=="function",et=!ze&&!E,tt=j.length===0,rt=w&&j.length===0,Me=n.useCallback(u=>a.jsx(vt,{userId:t,isDefault:tt,defaultCardholderName:Se,autoSave:!u&&rt,hideInternalSaveButton:u,formId:u?Nt:void 0,onCanSubmitChange:u?G:void 0,onSavingChange:u?H:void 0,autoFocus:u?"number":void 0,onSuccess:Xe,onError:Le,onErrorDetail:J}),[t,tt,Se,rt,Xe,Le,J]),Be=n.useMemo(()=>Me(!1),[Me]),Ye=n.useMemo(()=>Me(!0),[Me]),ke=!t,at=n.useMemo(()=>R?a.jsx(Rt,{selected:he,onSelect:u=>ie(u),creditCardBody:Be,disabled:ke}):Be,[R,he,Be,ke]),Re=n.useMemo(()=>R?a.jsx(Rt,{selected:he,onSelect:u=>ie(u),creditCardBody:Ye,disabled:ke}):Ye,[R,he,Ye,ke]);return a.jsxs("div",{className:Q("flex w-full flex-col gap-4",se),"data-testid":"payment-methods-manager",children:[C==="loading"&&j.length===0?a.jsxs("div",{className:Q(et?"flex flex-col divide-y divide-grayWarm-200 rounded-xl border border-grayWarm-200 px-4 md:px-6":"flex flex-col gap-2"),"data-testid":"payment-methods-loading",children:[a.jsx(Pt,{withDefaultBadge:!0}),a.jsx(Pt,{})]}):null,C==="error"?a.jsxs("div",{role:"alert","aria-live":"polite",className:"flex items-center justify-between gap-3 rounded-md bg-error-50 p-3 text-sm text-error-700","data-testid":"payment-methods-list-error",children:[a.jsx("span",{children:b??"Failed to load payment methods."}),a.jsx("button",{type:"button",onClick:Y,className:"rounded-md border border-error-700 px-3 py-1 text-xs font-semibold text-error-700 hover:bg-error-50",children:"Retry"})]}):null,S?a.jsx("div",{role:"alert","aria-live":"polite",className:"rounded-md bg-error-50 p-3 text-sm text-error-700","data-testid":"payment-methods-mutation-error",children:S}):null,E&&j.length>0?a.jsx("div",{className:"border-t border-grayWarm-200 pt-4",children:a.jsxs("div",{className:"flex items-center justify-between","data-testid":ae?"payment-methods-drawer-header":"payment-methods-collapsed-preview",children:[ae?a.jsx("h3",{className:"text-md font-semibold text-grayWarm-950",children:"Payment methods"}):a.jsx(It,{method:j.find(u=>u.id===l)??j.find(u=>u.isDefault)??j[0],cardLabelFormat:T,className:"flex-1"}),a.jsx("button",{type:"button","aria-label":ae?"Collapse payment methods":"Expand payment methods","aria-expanded":ae,className:"bg-grayWarm-100 p-2 rounded-lg hover:bg-grayWarm-200 transition-colors",onClick:()=>_e(u=>!u),"data-testid":ae?"payment-methods-drawer-close":"payment-methods-drawer-open",children:a.jsx("img",{src:`${Te().iconCdnBaseUrl}/website/assets/icons/chevron-${ae?"up":"down"}-double.svg`,alt:"",className:"w-5 h-5"})})]})}):null,j.length>0&&(!E||ae)?a.jsx("div",{className:Q("flex flex-col",et?"rounded-xl border border-grayWarm-200 px-4 md:px-6 divide-y divide-grayWarm-200":"space-y-3"),children:j.map(u=>a.jsx(jr,{method:u,selectable:ze,selected:ze&&u.id===l,onSelect:de,onSetDefault:$,onRemove:ot,onEdit:Je,disabled:P,showDefaultBadge:v,hideSetDefaultMenuItem:p,cardLabelFormat:T},u.id))}):null,Qe?a.jsx("div",{"data-testid":"payment-methods-empty",children:at}):j.length>0&&(!E||ae)?a.jsx("button",{type:"button",onClick:()=>{K(null),ie(null),G(!1),N(!0)},onMouseEnter:()=>{yt().catch(()=>{})},onFocus:()=>{yt().catch(()=>{})},className:"self-start rounded-lg bg-brand-50 px-6 py-3 text-md font-semibold text-brand-600 transition-colors hover:bg-brand-100","data-testid":"payment-methods-add-trigger",children:"Add payment method"}):null,a.jsxs(yr,{open:h,onClose:xe,formId:Nt,saveDisabled:!me,isSaving:re,children:[Re,U?a.jsx("p",{role:"alert","aria-live":"polite",className:"mt-3 rounded-md bg-error-50 px-3 py-2 text-sm text-error-700","data-testid":"payment-methods-modal-error",children:U}):null]}),a.jsx(xr,{open:W!==null,method:W,onClose:We,onSave:Ze,isSaving:D==="pending",error:je})]})};Lt.displayName="PaymentMethodsManager";const kr="/v1/auth/",Rr="movmo_csrf_token",Nr=t=>{if(typeof document>"u")return null;const r=document.cookie?document.cookie.split(";"):[];for(const s of r){const o=s.trim();if(o.startsWith(t+"="))return decodeURIComponent(o.substring(t.length+1))}return null},Sr=t=>typeof t=="string"?t:t instanceof URL?t.href:t.url,Pr=()=>{if(typeof globalThis<"u"&&typeof globalThis.fetch=="function")return globalThis.fetch.bind(globalThis);throw new Error("@movmo_app/payments: no global fetch available in this environment")},Tr=t=>{const{refreshSession:r,onRefreshFailed:s,csrfCookieName:o=Rr,extraHeaders:l,authPathFragment:c=kr,baseFetch:f=Pr(),readCookie:x=Nr}=t;let m=null;const R=()=>{if(m)return m;const p=(async()=>{await r()})();return m=p,p.finally(()=>{m===p&&(m=null)}).catch(()=>{}),p},w=(p,v)=>{const E=new Headers(v==null?void 0:v.headers),T=x(o);if(T&&!E.has("X-CSRF-Token")&&E.set("X-CSRF-Token",T),l){const se=l(p,v);for(const[M,C]of Object.entries(se))E.has(M)||E.set(M,C)}return{...v,headers:E,credentials:(v==null?void 0:v.credentials)??"include"}};return async function(v,E){const T=await f(v,w(v,E));if(Sr(v).includes(c)||T.status!==401&&T.status!==403)return T;try{await R()}catch(C){try{s(C)}catch(b){console.error("@movmo_app/payments: onRefreshFailed callback threw — auth retry path is misconfigured",b)}return T}try{return await f(v,w(v,E))}catch(C){return console.error("@movmo_app/payments: retry after token refresh failed — returning original response",C),T}}};exports.MovmoCardForm=vt;exports.PaymentMethodPreview=It;exports.PaymentMethodsManager=Lt;exports.createMovmoAuthFetch=Tr;exports.getPaymentsConfig=Te;exports.setPaymentsConfig=rr;exports.useDeletePaymentMethod=Ot;exports.useMovmoCardFields=Wt;exports.useSetDefaultPaymentMethod=Dt;exports.useUpdatePaymentMethod=$t;exports.useUserPaymentMethods=At;
31
31
  //# sourceMappingURL=index.cjs.js.map