@1interface/chat-shell 0.9.9 → 0.10.0-dev.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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("react"),n=require("@1interface/chat-core"),r=require("@1interface/shared-core"),o=e=>{const t=(e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,t,n)=>n?n.toUpperCase():t.toLowerCase()))(e);return t.charAt(0).toUpperCase()+t.slice(1)},a=(...e)=>e.filter((e,t,n)=>Boolean(e)&&""!==e.trim()&&n.indexOf(e)===t).join(" ").trim(),i=e=>{for(const t in e)if(t.startsWith("aria-")||"role"===t||"title"===t)return!0};var s={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};const c=t.forwardRef(({color:e="currentColor",size:n=24,strokeWidth:r=2,absoluteStrokeWidth:o,className:c="",children:l,iconNode:u,...d},p)=>t.createElement("svg",{ref:p,...s,width:n,height:n,stroke:e,strokeWidth:o?24*Number(r)/Number(n):r,className:a("lucide",c),...!l&&!i(d)&&{"aria-hidden":"true"},...d},[...u.map(([e,n])=>t.createElement(e,n)),...Array.isArray(l)?l:[l]])),l=((e,n)=>{const r=t.forwardRef(({className:r,...i},s)=>{return t.createElement(c,{ref:s,iconNode:n,className:a(`lucide-${l=o(e),l.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}`,`lucide-${e}`,r),...i});var l});return r.displayName=o(e),r})("loader-circle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]);function u(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var d,p,f,m,y,h,g,b,v,x,w,S,E,C,j,k,P={exports:{}},_={exports:{}},O={},A={};function T(){return f||(f=1,_.exports="production"===process.env.NODE_ENV?function(){if(d)return O;d=1;var e="function"==typeof Symbol&&Symbol.for,t=e?Symbol.for("react.element"):60103,n=e?Symbol.for("react.portal"):60106,r=e?Symbol.for("react.fragment"):60107,o=e?Symbol.for("react.strict_mode"):60108,a=e?Symbol.for("react.profiler"):60114,i=e?Symbol.for("react.provider"):60109,s=e?Symbol.for("react.context"):60110,c=e?Symbol.for("react.async_mode"):60111,l=e?Symbol.for("react.concurrent_mode"):60111,u=e?Symbol.for("react.forward_ref"):60112,p=e?Symbol.for("react.suspense"):60113,f=e?Symbol.for("react.suspense_list"):60120,m=e?Symbol.for("react.memo"):60115,y=e?Symbol.for("react.lazy"):60116,h=e?Symbol.for("react.block"):60121,g=e?Symbol.for("react.fundamental"):60117,b=e?Symbol.for("react.responder"):60118,v=e?Symbol.for("react.scope"):60119;function x(e){if("object"==typeof e&&null!==e){var d=e.$$typeof;switch(d){case t:switch(e=e.type){case c:case l:case r:case a:case o:case p:return e;default:switch(e=e&&e.$$typeof){case s:case u:case y:case m:case i:return e;default:return d}}case n:return d}}}function w(e){return x(e)===l}return O.AsyncMode=c,O.ConcurrentMode=l,O.ContextConsumer=s,O.ContextProvider=i,O.Element=t,O.ForwardRef=u,O.Fragment=r,O.Lazy=y,O.Memo=m,O.Portal=n,O.Profiler=a,O.StrictMode=o,O.Suspense=p,O.isAsyncMode=function(e){return w(e)||x(e)===c},O.isConcurrentMode=w,O.isContextConsumer=function(e){return x(e)===s},O.isContextProvider=function(e){return x(e)===i},O.isElement=function(e){return"object"==typeof e&&null!==e&&e.$$typeof===t},O.isForwardRef=function(e){return x(e)===u},O.isFragment=function(e){return x(e)===r},O.isLazy=function(e){return x(e)===y},O.isMemo=function(e){return x(e)===m},O.isPortal=function(e){return x(e)===n},O.isProfiler=function(e){return x(e)===a},O.isStrictMode=function(e){return x(e)===o},O.isSuspense=function(e){return x(e)===p},O.isValidElementType=function(e){return"string"==typeof e||"function"==typeof e||e===r||e===l||e===a||e===o||e===p||e===f||"object"==typeof e&&null!==e&&(e.$$typeof===y||e.$$typeof===m||e.$$typeof===i||e.$$typeof===s||e.$$typeof===u||e.$$typeof===g||e.$$typeof===b||e.$$typeof===v||e.$$typeof===h)},O.typeOf=x,O}():(p||(p=1,"production"!==process.env.NODE_ENV&&function(){var e="function"==typeof Symbol&&Symbol.for,t=e?Symbol.for("react.element"):60103,n=e?Symbol.for("react.portal"):60106,r=e?Symbol.for("react.fragment"):60107,o=e?Symbol.for("react.strict_mode"):60108,a=e?Symbol.for("react.profiler"):60114,i=e?Symbol.for("react.provider"):60109,s=e?Symbol.for("react.context"):60110,c=e?Symbol.for("react.async_mode"):60111,l=e?Symbol.for("react.concurrent_mode"):60111,u=e?Symbol.for("react.forward_ref"):60112,d=e?Symbol.for("react.suspense"):60113,p=e?Symbol.for("react.suspense_list"):60120,f=e?Symbol.for("react.memo"):60115,m=e?Symbol.for("react.lazy"):60116,y=e?Symbol.for("react.block"):60121,h=e?Symbol.for("react.fundamental"):60117,g=e?Symbol.for("react.responder"):60118,b=e?Symbol.for("react.scope"):60119;function v(e){if("object"==typeof e&&null!==e){var p=e.$$typeof;switch(p){case t:var y=e.type;switch(y){case c:case l:case r:case a:case o:case d:return y;default:var h=y&&y.$$typeof;switch(h){case s:case u:case m:case f:case i:return h;default:return p}}case n:return p}}}var x=l,w=s,S=i,E=t,C=u,j=r,k=m,P=f,_=n,O=a,T=o,N=d,I=!1;function M(e){return v(e)===l}A.AsyncMode=c,A.ConcurrentMode=x,A.ContextConsumer=w,A.ContextProvider=S,A.Element=E,A.ForwardRef=C,A.Fragment=j,A.Lazy=k,A.Memo=P,A.Portal=_,A.Profiler=O,A.StrictMode=T,A.Suspense=N,A.isAsyncMode=function(e){return I||(I=!0,console.warn("The ReactIs.isAsyncMode() alias has been deprecated, and will be removed in React 17+. Update your code to use ReactIs.isConcurrentMode() instead. It has the exact same API.")),M(e)||v(e)===c},A.isConcurrentMode=M,A.isContextConsumer=function(e){return v(e)===s},A.isContextProvider=function(e){return v(e)===i},A.isElement=function(e){return"object"==typeof e&&null!==e&&e.$$typeof===t},A.isForwardRef=function(e){return v(e)===u},A.isFragment=function(e){return v(e)===r},A.isLazy=function(e){return v(e)===m},A.isMemo=function(e){return v(e)===f},A.isPortal=function(e){return v(e)===n},A.isProfiler=function(e){return v(e)===a},A.isStrictMode=function(e){return v(e)===o},A.isSuspense=function(e){return v(e)===d},A.isValidElementType=function(e){return"string"==typeof e||"function"==typeof e||e===r||e===l||e===a||e===o||e===d||e===p||"object"==typeof e&&null!==e&&(e.$$typeof===m||e.$$typeof===f||e.$$typeof===i||e.$$typeof===s||e.$$typeof===u||e.$$typeof===h||e.$$typeof===g||e.$$typeof===b||e.$$typeof===y)},A.typeOf=v}()),A)),_.exports}function N(){return g?h:(g=1,h="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}function I(){return v?b:(v=1,b=Function.call.bind(Object.prototype.hasOwnProperty))}function M(){if(w)return x;w=1;var e=function(){};if("production"!==process.env.NODE_ENV){var t=N(),n={},r=I();e=function(e){var t="Warning: "+e;"undefined"!=typeof console&&console.error(t);try{throw new Error(t)}catch(e){}}}function o(o,a,i,s,c){if("production"!==process.env.NODE_ENV)for(var l in o)if(r(o,l)){var u;try{if("function"!=typeof o[l]){var d=Error((s||"React class")+": "+i+" type `"+l+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof o[l]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw d.name="Invariant Violation",d}u=o[l](a,l,s,i,null,t)}catch(e){u=e}if(!u||u instanceof Error||e((s||"React class")+": type specification of "+i+" `"+l+"` is invalid; the type checker function must return `null` or an `Error` but returned a "+typeof u+". You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument)."),u instanceof Error&&!(u.message in n)){n[u.message]=!0;var p=c?c():"";e("Failed "+i+" type: "+u.message+(null!=p?p:""))}}}return o.resetWarningCache=function(){"production"!==process.env.NODE_ENV&&(n={})},x=o}function R(){if(E)return S;E=1;var e=T(),t=function(){if(y)return m;y=1;var e=Object.getOwnPropertySymbols,t=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable;return m=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},n=0;n<10;n++)t["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(t).map(function(e){return t[e]}).join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach(function(e){r[e]=e}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(e){return!1}}()?Object.assign:function(r,o){for(var a,i,s=function(e){if(null==e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}(r),c=1;c<arguments.length;c++){for(var l in a=Object(arguments[c]))t.call(a,l)&&(s[l]=a[l]);if(e){i=e(a);for(var u=0;u<i.length;u++)n.call(a,i[u])&&(s[i[u]]=a[i[u]])}}return s},m}(),n=N(),r=I(),o=M(),a=function(){};function i(){return null}return"production"!==process.env.NODE_ENV&&(a=function(e){var t="Warning: "+e;"undefined"!=typeof console&&console.error(t);try{throw new Error(t)}catch(e){}}),S=function(s,c){var l="function"==typeof Symbol&&Symbol.iterator,u="<<anonymous>>",d={array:y("array"),bigint:y("bigint"),bool:y("boolean"),func:y("function"),number:y("number"),object:y("object"),string:y("string"),symbol:y("symbol"),any:m(i),arrayOf:function(e){return m(function(t,r,o,a,i){if("function"!=typeof e)return new f("Property `"+i+"` of component `"+o+"` has invalid PropType notation inside arrayOf.");var s=t[r];if(!Array.isArray(s))return new f("Invalid "+a+" `"+i+"` of type `"+b(s)+"` supplied to `"+o+"`, expected an array.");for(var c=0;c<s.length;c++){var l=e(s,c,o,a,i+"["+c+"]",n);if(l instanceof Error)return l}return null})},element:m(function(e,t,n,r,o){var a=e[t];return s(a)?null:new f("Invalid "+r+" `"+o+"` of type `"+b(a)+"` supplied to `"+n+"`, expected a single ReactElement.")}),elementType:m(function(t,n,r,o,a){var i=t[n];return e.isValidElementType(i)?null:new f("Invalid "+o+" `"+a+"` of type `"+b(i)+"` supplied to `"+r+"`, expected a single ReactElement type.")}),instanceOf:function(e){return m(function(t,n,r,o,a){return t[n]instanceof e?null:new f("Invalid "+o+" `"+a+"` of type `"+((i=t[n]).constructor&&i.constructor.name?i.constructor.name:u)+"` supplied to `"+r+"`, expected instance of `"+(e.name||u)+"`.");var i})},node:m(function(e,t,n,r,o){return g(e[t])?null:new f("Invalid "+r+" `"+o+"` supplied to `"+n+"`, expected a ReactNode.")}),objectOf:function(e){return m(function(t,o,a,i,s){if("function"!=typeof e)return new f("Property `"+s+"` of component `"+a+"` has invalid PropType notation inside objectOf.");var c=t[o],l=b(c);if("object"!==l)return new f("Invalid "+i+" `"+s+"` of type `"+l+"` supplied to `"+a+"`, expected an object.");for(var u in c)if(r(c,u)){var d=e(c,u,a,i,s+"."+u,n);if(d instanceof Error)return d}return null})},oneOf:function(e){return Array.isArray(e)?m(function(t,n,r,o,a){for(var i=t[n],s=0;s<e.length;s++)if(p(i,e[s]))return null;var c=JSON.stringify(e,function(e,t){return"symbol"===v(t)?String(t):t});return new f("Invalid "+o+" `"+a+"` of value `"+String(i)+"` supplied to `"+r+"`, expected one of "+c+".")}):("production"!==process.env.NODE_ENV&&a(arguments.length>1?"Invalid arguments supplied to oneOf, expected an array, got "+arguments.length+" arguments. A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z]).":"Invalid argument supplied to oneOf, expected an array."),i)},oneOfType:function(e){if(!Array.isArray(e))return"production"!==process.env.NODE_ENV&&a("Invalid argument supplied to oneOfType, expected an instance of array."),i;for(var t=0;t<e.length;t++){var o=e[t];if("function"!=typeof o)return a("Invalid argument supplied to oneOfType. Expected an array of check functions, but received "+x(o)+" at index "+t+"."),i}return m(function(t,o,a,i,s){for(var c=[],l=0;l<e.length;l++){var u=(0,e[l])(t,o,a,i,s,n);if(null==u)return null;u.data&&r(u.data,"expectedType")&&c.push(u.data.expectedType)}return new f("Invalid "+i+" `"+s+"` supplied to `"+a+"`"+(c.length>0?", expected one of type ["+c.join(", ")+"]":"")+".")})},shape:function(e){return m(function(t,r,o,a,i){var s=t[r],c=b(s);if("object"!==c)return new f("Invalid "+a+" `"+i+"` of type `"+c+"` supplied to `"+o+"`, expected `object`.");for(var l in e){var u=e[l];if("function"!=typeof u)return h(o,a,i,l,v(u));var d=u(s,l,o,a,i+"."+l,n);if(d)return d}return null})},exact:function(e){return m(function(o,a,i,s,c){var l=o[a],u=b(l);if("object"!==u)return new f("Invalid "+s+" `"+c+"` of type `"+u+"` supplied to `"+i+"`, expected `object`.");var d=t({},o[a],e);for(var p in d){var m=e[p];if(r(e,p)&&"function"!=typeof m)return h(i,s,c,p,v(m));if(!m)return new f("Invalid "+s+" `"+c+"` key `"+p+"` supplied to `"+i+"`.\nBad object: "+JSON.stringify(o[a],null," ")+"\nValid keys: "+JSON.stringify(Object.keys(e),null," "));var y=m(l,p,i,s,c+"."+p,n);if(y)return y}return null})}};function p(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t}function f(e,t){this.message=e,this.data=t&&"object"==typeof t?t:{},this.stack=""}function m(e){if("production"!==process.env.NODE_ENV)var t={},r=0;function o(o,i,s,l,d,p,m){if(l=l||u,p=p||s,m!==n){if(c){var y=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use `PropTypes.checkPropTypes()` to call them. Read more at http://fb.me/use-check-prop-types");throw y.name="Invariant Violation",y}if("production"!==process.env.NODE_ENV&&"undefined"!=typeof console){var h=l+":"+s;!t[h]&&r<3&&(a("You are manually calling a React.PropTypes validation function for the `"+p+"` prop on `"+l+"`. This is deprecated and will throw in the standalone `prop-types` package. You may be seeing this warning due to a third-party PropTypes library. See https://fb.me/react-warning-dont-call-proptypes for details."),t[h]=!0,r++)}}return null==i[s]?o?new f(null===i[s]?"The "+d+" `"+p+"` is marked as required in `"+l+"`, but its value is `null`.":"The "+d+" `"+p+"` is marked as required in `"+l+"`, but its value is `undefined`."):null:e(i,s,l,d,p)}var i=o.bind(null,!1);return i.isRequired=o.bind(null,!0),i}function y(e){return m(function(t,n,r,o,a,i){var s=t[n];return b(s)!==e?new f("Invalid "+o+" `"+a+"` of type `"+v(s)+"` supplied to `"+r+"`, expected `"+e+"`.",{expectedType:e}):null})}function h(e,t,n,r,o){return new f((e||"React class")+": "+t+" type `"+n+"."+r+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+o+"`.")}function g(e){switch(typeof e){case"number":case"string":case"undefined":return!0;case"boolean":return!e;case"object":if(Array.isArray(e))return e.every(g);if(null===e||s(e))return!0;var t=function(e){var t=e&&(l&&e[l]||e["@@iterator"]);if("function"==typeof t)return t}(e);if(!t)return!1;var n,r=t.call(e);if(t!==e.entries){for(;!(n=r.next()).done;)if(!g(n.value))return!1}else for(;!(n=r.next()).done;){var o=n.value;if(o&&!g(o[1]))return!1}return!0;default:return!1}}function b(e){var t=typeof e;return Array.isArray(e)?"array":e instanceof RegExp?"object":function(e,t){return"symbol"===e||!!t&&("Symbol"===t["@@toStringTag"]||"function"==typeof Symbol&&t instanceof Symbol)}(t,e)?"symbol":t}function v(e){if(null==e)return""+e;var t=b(e);if("object"===t){if(e instanceof Date)return"date";if(e instanceof RegExp)return"regexp"}return t}function x(e){var t=v(e);switch(t){case"array":case"object":return"an "+t;case"boolean":case"date":case"regexp":return"a "+t;default:return t}}return f.prototype=Error.prototype,d.checkPropTypes=o,d.resetWarningCache=o.resetWarningCache,d.PropTypes=d,d},S}function F(){if(j)return C;j=1;var e=N();function t(){}function n(){}return n.resetWarningCache=t,C=function(){function r(t,n,r,o,a,i){if(i!==e){var s=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw s.name="Invariant Violation",s}}function o(){return r}r.isRequired=r;var a={array:r,bigint:r,bool:r,func:r,number:r,object:r,string:r,symbol:r,any:r,arrayOf:o,element:r,elementType:r,instanceOf:o,node:r,objectOf:o,oneOf:o,oneOfType:o,shape:o,exact:o,checkPropTypes:n,resetWarningCache:t};return a.PropTypes=a,a}}function $(){if(k)return P.exports;if(k=1,"production"!==process.env.NODE_ENV){var e=T();P.exports=R()(e.isElement,!0)}else P.exports=F()();return P.exports}const D=u($());function V(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function L(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?V(Object(n),!0).forEach(function(t){U(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):V(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function B(e){return(B="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function U(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function z(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=e&&("undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"]);if(null!=n){var r,o,a=[],i=!0,s=!1;try{for(n=n.call(e);!(i=(r=n.next()).done)&&(a.push(r.value),!t||a.length!==t);i=!0);}catch(e){s=!0,o=e}finally{try{i||null==n.return||n.return()}finally{if(s)throw o}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return q(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?q(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function q(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var Y=function(e,n,r){var o=!!r,a=t.useRef(r);t.useEffect(function(){a.current=r},[r]),t.useEffect(function(){if(!o||!e)return function(){};var t=function(){a.current&&a.current.apply(a,arguments)};return e.on(n,t),function(){e.off(n,t)}},[o,n,e,a])},W=function(e){var n=t.useRef(e);return t.useEffect(function(){n.current=e},[e]),n.current},H=function(e){return null!==e&&"object"===B(e)},J="[object Object]",K=function e(t,n){if(!H(t)||!H(n))return t===n;var r=Array.isArray(t);if(r!==Array.isArray(n))return!1;var o=Object.prototype.toString.call(t)===J;if(o!==(Object.prototype.toString.call(n)===J))return!1;if(!o&&!r)return t===n;var a=Object.keys(t),i=Object.keys(n);if(a.length!==i.length)return!1;for(var s={},c=0;c<a.length;c+=1)s[a[c]]=!0;for(var l=0;l<i.length;l+=1)s[i[l]]=!0;var u=Object.keys(s);if(u.length!==a.length)return!1;var d=t,p=n;return u.every(function(t){return e(d[t],p[t])})},G=function(e,t,n){return H(e)?Object.keys(e).reduce(function(r,o){var a=!H(t)||!K(e[o],t[o]);return n.includes(o)?(a&&console.warn("Unsupported prop change: options.".concat(o," is not a mutable property.")),r):a?L(L({},r||{}),{},U({},o,e[o])):r},null):null},X="Invalid prop `stripe` supplied to `Elements`. We recommend using the `loadStripe` utility from `@stripe/stripe-js`. See https://stripe.com/docs/stripe-js/react#elements-props-stripe for details.",Z=function(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:X;if(null===e||H(t=e)&&"function"==typeof t.elements&&"function"==typeof t.createToken&&"function"==typeof t.createPaymentMethod&&"function"==typeof t.confirmCardPayment)return e;throw new Error(n)},Q=t.createContext(null);Q.displayName="ElementsContext";var ee=function(e,t){if(!e)throw new Error("Could not find Elements context; You need to wrap the part of your app that ".concat(t," in an <Elements> provider."));return e},te=function(e){var n=e.stripe,r=e.options,o=e.children,a=t.useMemo(function(){return function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:X;if(function(e){return H(e)&&"function"==typeof e.then}(e))return{tag:"async",stripePromise:Promise.resolve(e).then(function(e){return Z(e,t)})};var n=Z(e,t);return null===n?{tag:"empty"}:{tag:"sync",stripe:n}}(n)},[n]),i=z(t.useState(function(){return{stripe:"sync"===a.tag?a.stripe:null,elements:"sync"===a.tag?a.stripe.elements(r):null}}),2),s=i[0],c=i[1];t.useEffect(function(){var e=!0,t=function(e){c(function(t){return t.stripe?t:{stripe:e,elements:e.elements(r)}})};return"async"!==a.tag||s.stripe?"sync"!==a.tag||s.stripe||t(a.stripe):a.stripePromise.then(function(n){n&&e&&t(n)}),function(){e=!1}},[a,s,r]);var l=W(n);t.useEffect(function(){null!==l&&l!==n&&console.warn("Unsupported prop change on Elements: You cannot change the `stripe` prop after setting it.")},[l,n]);var u=W(r);return t.useEffect(function(){if(s.elements){var e=G(r,u,["clientSecret","fonts"]);e&&s.elements.update(e)}},[r,u,s.elements]),t.useEffect(function(){var e;(e=s.stripe)&&e._registerWrapper&&e.registerAppInfo&&(e._registerWrapper({name:"react-stripe-js",version:"3.10.0"}),e.registerAppInfo({name:"react-stripe-js",version:"3.10.0",url:"https://stripe.com/docs/stripe-js/react"}))},[s.stripe]),t.createElement(Q.Provider,{value:s},o)};te.propTypes={stripe:D.any,options:D.object};var ne=t.createContext(null);ne.displayName="CheckoutSdkContext",t.createContext(null).displayName="CheckoutContext",D.shape({fetchClientSecret:D.func.isRequired,elementsOptions:D.object});var re=function(e){var n=t.useContext(ne),r=t.useContext(Q);if(n&&r)throw new Error("You cannot wrap the part of your app that ".concat(e," in both <CheckoutProvider> and <Elements> providers."));return n?function(e,t){if(!e)throw new Error("Could not find CheckoutProvider context; You need to wrap the part of your app that ".concat(t," in an <CheckoutProvider> provider."));return e}(n,e):ee(r,e)},oe=["mode"],ae=function(e,n){var r,o="".concat((r=e).charAt(0).toUpperCase()+r.slice(1),"Element"),a=n?function(e){return re("mounts <".concat(o,">")),t.createElement("div",{id:e.id,className:e.className})}:function(n){var r,a=n.id,i=n.className,s=n.options,c=void 0===s?{}:s,l=n.onBlur,u=n.onFocus,d=n.onReady,p=n.onChange,f=n.onEscape,m=n.onClick,y=n.onLoadError,h=n.onLoaderStart,g=n.onNetworksChange,b=n.onConfirm,v=n.onCancel,x=n.onShippingAddressChange,w=n.onShippingRateChange,S=n.onSavedPaymentMethodRemove,E=n.onSavedPaymentMethodUpdate,C=re("mounts <".concat(o,">")),j="elements"in C?C.elements:null,k="checkoutSdk"in C?C.checkoutSdk:null,P=z(t.useState(null),2),_=P[0],O=P[1],A=t.useRef(null),T=t.useRef(null);Y(_,"blur",l),Y(_,"focus",u),Y(_,"escape",f),Y(_,"click",m),Y(_,"loaderror",y),Y(_,"loaderstart",h),Y(_,"networkschange",g),Y(_,"confirm",b),Y(_,"cancel",v),Y(_,"shippingaddresschange",x),Y(_,"shippingratechange",w),Y(_,"savedpaymentmethodremove",S),Y(_,"savedpaymentmethodupdate",E),Y(_,"change",p),d&&(r="expressCheckout"===e?d:function(){d(_)}),Y(_,"ready",r),t.useLayoutEffect(function(){if(null===A.current&&null!==T.current&&(j||k)){var t=null;if(k)switch(e){case"payment":t=k.createPaymentElement(c);break;case"address":if(!("mode"in c))throw new Error("You must supply options.mode. mode must be 'billing' or 'shipping'.");var n=c.mode,r=function(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},a=Object.keys(e);for(r=0;r<a.length;r++)t.indexOf(n=a[r])>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)t.indexOf(n=a[r])>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}(c,oe);if("shipping"===n)t=k.createShippingAddressElement(r);else{if("billing"!==n)throw new Error("Invalid options.mode. mode must be 'billing' or 'shipping'.");t=k.createBillingAddressElement(r)}break;case"expressCheckout":t=k.createExpressCheckoutElement(c);break;case"currencySelector":t=k.createCurrencySelectorElement();break;case"taxId":t=k.createTaxIdElement(c);break;default:throw new Error("Invalid Element type ".concat(o,". You must use either the <PaymentElement />, <AddressElement options={{mode: 'shipping'}} />, <AddressElement options={{mode: 'billing'}} />, or <ExpressCheckoutElement />."))}else j&&(t=j.create(e,c));A.current=t,O(t),t&&t.mount(T.current)}},[j,k,c]);var N=W(c);return t.useEffect(function(){if(A.current){var e=G(c,N,["paymentRequest"]);e&&"update"in A.current&&A.current.update(e)}},[c,N]),t.useLayoutEffect(function(){return function(){if(A.current&&"function"==typeof A.current.destroy)try{A.current.destroy(),A.current=null}catch(e){}}},[]),t.createElement("div",{id:a,className:i,ref:T})};return a.propTypes={id:D.string,className:D.string,onChange:D.func,onBlur:D.func,onFocus:D.func,onReady:D.func,onEscape:D.func,onClick:D.func,onLoadError:D.func,onLoaderStart:D.func,onNetworksChange:D.func,onConfirm:D.func,onCancel:D.func,onShippingAddressChange:D.func,onShippingRateChange:D.func,onSavedPaymentMethodRemove:D.func,onSavedPaymentMethodUpdate:D.func,options:D.object},a.displayName=o,a.__elementType=e,a},ie="undefined"==typeof window;t.createContext(null).displayName="EmbeddedCheckoutProviderContext",ae("auBankAccount",ie),ae("card",ie),ae("cardNumber",ie),ae("cardExpiry",ie),ae("cardCvc",ie),ae("fpxBank",ie),ae("iban",ie),ae("idealBank",ie),ae("p24Bank",ie),ae("epsBank",ie);var se=ae("payment",ie);ae("expressCheckout",ie),ae("currencySelector",ie),ae("paymentRequestButton",ie),ae("linkAuthentication",ie),ae("address",ie),ae("shippingAddress",ie),ae("paymentMethodMessaging",ie),ae("affirmMessage",ie),ae("afterpayClearpayMessage",ie),ae("taxId",ie);const ce=t.createContext(null),le=({onResult:n,children:r})=>{const[o,a]=t.useState(null),[i,s]=t.useState(null),c=t.useRef(n);c.current=n;const l=t.useCallback(e=>{c.current(e)},[]),u=t.useCallback(e=>{a(e)},[]),d=t.useCallback(e=>{s(e)},[]),p=t.useMemo(()=>({emitResult:l,registerConfirm:u,confirmHandle:o,reportSummary:d,summary:i}),[l,u,o,d,i]);return e.jsx(ce.Provider,{value:p,children:r})},ue=()=>{const e=t.useContext(ce);if(!e)throw new Error("Payment result channel hooks must be used inside PaymentResultChannelProvider");return e},de=()=>ue().emitResult,pe=()=>ue().registerConfirm,fe=()=>ue().reportSummary;function me(e){return(me="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var ye,he="https://js.stripe.com/v3",ge=/^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/,be="loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used",ve=function(e){var t=e&&!e.advancedFraudSignals?"?advancedFraudSignals=false":"",n=document.createElement("script");n.src="".concat(he).concat(t);var r=document.head||document.body;if(!r)throw new Error("Expected document.body not to be null. Stripe.js requires a <body> element.");return r.appendChild(n),n},xe=null,we=null,Se=null,Ee=function(e){var t="invalid load parameters; expected object of shape\n\n {advancedFraudSignals: boolean}\n\nbut received\n\n ".concat(JSON.stringify(e),"\n");if(null===e||"object"!==me(e))throw new Error(t);if(1===Object.keys(e).length&&"boolean"==typeof e.advancedFraudSignals)return e;throw new Error(t)},Ce=!1,je=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];Ce=!0;var r,o=Date.now();return(r=ye,null!==xe?xe:(xe=new Promise(function(e,t){if("undefined"!=typeof window&&"undefined"!=typeof document)if(window.Stripe&&r&&console.warn(be),window.Stripe)e(window.Stripe);else try{var n=function(){for(var e=document.querySelectorAll('script[src^="'.concat(he,'"]')),t=0;t<e.length;t++){var n=e[t];if(ge.test(n.src))return n}return null}();if(n&&r)console.warn(be);else if(n){if(n&&null!==Se&&null!==we){var o;n.removeEventListener("load",Se),n.removeEventListener("error",we),null===(o=n.parentNode)||void 0===o||o.removeChild(n),n=ve(r)}}else n=ve(r);Se=function(e,t){return function(){window.Stripe?e(window.Stripe):t(new Error("Stripe.js not available"))}}(e,t),we=function(e){return function(){e(new Error("Failed to load Stripe.js"))}}(t),n.addEventListener("load",Se),n.addEventListener("error",we)}catch(e){return void t(e)}else e(null)})).catch(function(e){return xe=null,Promise.reject(e)})).then(function(e){return function(e,t,n){if(null===e)return null;var r=e.apply(void 0,t);return function(e,t){e&&e._registerWrapper&&e._registerWrapper({name:"stripe-js",version:"4.6.0",startTime:t})}(r,n),r}(e,t,o)})};je.setLoadParameters=function(e){if(Ce&&ye){var t=Ee(e);if(Object.keys(t).reduce(function(t,n){var r;return t&&e[n]===(null===(r=ye)||void 0===r?void 0:r[n])},!0))return}if(Ce)throw new Error("You cannot change load parameters after calling loadStripe");ye=Ee(e)};const ke=t.createContext(null),Pe=({onReady:n})=>{const r=re("calls useStripe()").stripe,o=(p=t.useContext(Q),ee(p,"calls useElements()")).elements,{paymentInit:a}=on(),i=de(),s=pe(),c=fe(),[l,u]=t.useState(!1),d="stripe"===a?.provider?a.config.client_secret:null;var p;t.useEffect(()=>{if(!r||!d)return;let e=!1;return r.retrievePaymentIntent(d).then(t=>{if(e)return;const n=t.paymentIntent;n&&"number"==typeof n.amount&&n.currency&&c({amount:n.amount,currency:n.currency})}),()=>{e=!0}},[r,d,c]);const f=t.useCallback(async()=>{if(!r||!o||!d)return;u(!0);const{error:e}=await o.submit();if(e)return void u(!1);const{error:t,paymentIntent:n}=await r.confirmPayment({elements:o,clientSecret:d,confirmParams:{return_url:window.location.href},redirect:"if_required"});u(!1),t||!n||"succeeded"!==n.status&&"requires_capture"!==n.status||i({status:"success",provider:"stripe",paymentId:n.id,amount:n.amount,currency:n.currency})},[r,o,d,i]);return t.useEffect(()=>(s({confirm:f,isConfirming:l}),()=>s(null)),[f,l,s]),e.jsx(se,{options:{layout:"tabs",wallets:{applePay:"auto",googlePay:"auto"}},onReady:n})},_e={type:"stripe",label:"Stripe",ProviderWrapper:({children:n})=>{const{paymentInit:r}=on(),[o,a]=t.useState(null),i="stripe"===r?.provider?r.config.publishable_key:null;t.useEffect(()=>{i&&i.startsWith("pk_")&&a(je(i))},[i]);const s=t.useMemo(()=>({stripePromise:o}),[o]);return e.jsx(ke.Provider,{value:s,children:n})},FormComponent:({onReady:o})=>{const{themeStyles:a,theme:i}=r.useBranding(),{stripePromise:s}=(()=>{const e=t.useContext(ke);if(!e)throw new Error("Stripe adapter components must be used inside StripeProviderWrapper");return e})(),{paymentInit:c}=on(),l=t.useMemo(()=>n.buildBrandSkin(a,i),[a,i]),u=t.useMemo(()=>function(e,t,n){return{theme:"dark"===t?"night":"stripe",variables:{colorPrimary:e.statusDiscovery.solid,colorBackground:n.cardBg,colorText:n.text,colorDanger:"#df1b41",fontFamily:n.fontFamily,borderRadius:`${n.radius}px`,spacingUnit:"3px",fontSizeBase:"16px"}}}(a,i,l),[a,i,l]),d="stripe"===c?.provider?c.config.client_secret:null,p=t.useMemo(()=>d?{clientSecret:d,appearance:u}:null,[d,u]);return s&&p?e.jsx(te,{stripe:s,options:p,children:e.jsx(Pe,{onReady:o})},d):null}};function Oe(e){const t={};if(e.config.metadata)for(const[n,r]of Object.entries(e.config.metadata))null!=r&&(t[n]=String(r));if(e.config.customer){const{name:n,email:r,phone:o,reference_id:a}=e.config.customer;n&&(t.customer_name=n),r&&(t.customer_email=r),o&&(t.customer_phone=o),a&&(t.customer_reference_id=a)}return t}class Ae extends Error{constructor(e,t,n){super(e),this.status=t,this.body=n,this.name="MoyasarApiError"}}async function Te(e){const t=await Ne("https://api.moyasar.com/v1/payments",e);if(!t.ok)throw new Ae(Ie(t.body)??`Payment creation failed (${t.status})`,t.status,t.body);const n=t.body;if(!n||"string"!=typeof n.id||"string"!=typeof n.status)throw new Ae("Payment creation returned no id/status",t.status,n);return n}async function Ne(e,t){const n=new AbortController,r=setTimeout(()=>n.abort(new DOMException("Request timed out","TimeoutError")),3e4);let o;try{o=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),signal:n.signal})}catch(e){const t=e instanceof DOMException&&"TimeoutError"===e.name?"Payment request timed out — please try again.":e instanceof Error?e.message:"Network request failed";throw new Ae(t)}finally{clearTimeout(r)}let a=null;try{a=await o.json()}catch{a=null}return{ok:o.ok,status:o.status,body:a}}function Ie(e){if(!e||"object"!=typeof e)return null;if("string"==typeof e.message&&e.message.length>0)return e.message;if(e.errors&&"object"==typeof e.errors){const t=e.errors;for(const[e,n]of Object.entries(t)){if(Array.isArray(n)&&"string"==typeof n[0])return`${Me(e)}: ${n[0]}`;if("string"==typeof n)return`${Me(e)}: ${n}`}}return null}function Me(e){return e.replace(/_/g," ")}const Re=({url:r,onResult:o,skin:a})=>{const i=t.useRef(o);i.current=o;const s=t.useRef(!1),[c,l]=t.useState(!1),u=t.useRef(!1),d=t.useCallback(e=>{s.current||(s.current=!0,i.current({status:"failure",provider:"moyasar",message:e}))},[]);return t.useEffect(()=>{const e=window.location.origin,t=t=>{if(t.origin!==e)return;if(s.current)return;if(!(r=t.data)||"object"!=typeof r||"moyasar-iframe-callback"!==r.type||"string"!=typeof r.search)return;var r;const o=n.parseMoyasarCallbackFromUrl(t.data.search);o&&(s.current=!0,i.current(o.result))};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[]),t.useEffect(()=>{const e=setTimeout(()=>{u.current||d("3D Secure challenge failed to load")},6e4);return()=>clearTimeout(e)},[d]),e.jsxs("div",{className:"absolute inset-0 z-[105]",style:{background:a.cardBg},role:"dialog","aria-label":"3D Secure authentication",children:[!c&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center text-sm",style:{color:a.muted,fontFamily:a.fontFamily},children:"Loading…"}),e.jsx("iframe",{src:r,title:"3D Secure",className:"w-full h-full",style:{border:0,background:"white"},onLoad:()=>{u.current=!0,l(!0)},onError:()=>{d("3D Secure challenge failed to load")},allow:"payment *",sandbox:"allow-scripts allow-forms allow-same-origin allow-popups allow-top-navigation-by-user-activation",referrerPolicy:"no-referrer"})]})},Fe=["mada","visa","masterCard"],$e="data-aiatcore-apple-pay",De=({skin:o})=>{const{paymentInit:a}=on(),i=a&&"moyasar"===a.provider?a:null,s=de(),[c,l]=t.useState(null),u=t.useRef(s);u.current=s,t.useEffect(()=>{!function(){if("undefined"==typeof document)return;if(document.querySelector(`style[${$e}]`))return;const e=document.createElement("style");e.setAttribute($e,"true"),e.textContent="\n .aiatcore-apple-pay-button {\n -webkit-appearance: -apple-pay-button;\n -apple-pay-button-type: pay;\n -apple-pay-button-style: black;\n width: 100%;\n cursor: pointer;\n border: none;\n padding: 0;\n margin: 0;\n }\n ",document.head.appendChild(e)}()},[]);const d=t.useCallback(()=>{if(!i)return;const e=window.ApplePaySession;if(!e)return void r.showErrorToast("Apple Pay is not available on this device.");const t=i.config.apple_pay?.label??i.config.description??"Payment",o=i.config.apple_pay?.country??"SA",a=i.config.currency.toUpperCase(),c=(i.config.amount/100).toFixed(2),u={countryCode:o,currencyCode:a,supportedNetworks:Fe,merchantCapabilities:["supports3DS","supportsDebit","supportsCredit"],total:{label:t,amount:c}};let d;try{d=new e(5,u)}catch(e){return void r.showErrorToast(e instanceof Error?e.message:"Failed to start Apple Pay")}d.onvalidatemerchant=async e=>{try{const n=await async function(e){const t={validation_url:e.validationUrl,display_name:e.displayName,domain_name:e.domainName??window.location.hostname,publishable_api_key:e.publishableApiKey},n=new AbortController,r=setTimeout(()=>n.abort(new DOMException("Request timed out","TimeoutError")),3e4);let o;try{o=await fetch("https://api.moyasar.com/v1/applepay/initiate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),signal:n.signal})}catch(e){const t=e instanceof DOMException&&"TimeoutError"===e.name?"Apple Pay merchant validation timed out — please try again.":e instanceof Error?e.message:"Network request failed";throw new Ae(t)}finally{clearTimeout(r)}let a=null;try{a=await o.json()}catch{a=null}if(!o.ok)throw new Ae(function(e){return e&&"object"==typeof e&&"string"==typeof e.message&&e.message.length>0?e.message:null}(a)??`Apple Pay merchant validation failed (${o.status})`,o.status,a);return a}({validationUrl:e.validationURL,displayName:t,publishableApiKey:i.config.publishable_key});d.completeMerchantValidation(n)}catch(e){const t=e instanceof Error?e.message:"Merchant validation failed";d.abort(),s({status:"failure",provider:"moyasar",message:t,paymentId:i.config.given_id})}},d.onpaymentauthorized=async t=>{try{const r=Oe(i),o=await Te({publishable_api_key:i.config.publishable_key,given_id:i.config.given_id,amount:i.config.amount,currency:a,description:i.config.description,callback_url:n.buildCallbackUrl(i.config.given_id),source:{type:"applepay",token:t.payment.token},...Object.keys(r).length>0?{metadata:r}:{}}),c=o.source?.transaction_url??o.transaction_url;if(c)return d.completePayment({status:e.STATUS_SUCCESS}),void l(c);const u=o.status;if("paid"===u||"authorized"===u||"captured"===u)d.completePayment({status:e.STATUS_SUCCESS}),s({status:"success",provider:"moyasar",paymentId:o.id,amount:o.amount,currency:o.currency});else if("failed"===u){const t=o.source?.message??"Payment failed";d.completePayment({status:e.STATUS_FAILURE}),s({status:"failure",provider:"moyasar",code:"failed",message:t,paymentId:o.id})}else{const t=`Unexpected payment status: ${u}`;d.completePayment({status:e.STATUS_FAILURE}),s({status:"failure",provider:"moyasar",code:u,message:t,paymentId:o.id})}}catch(t){const n=t instanceof Ae||t instanceof Error?t.message:"Payment failed";d.completePayment({status:e.STATUS_FAILURE}),s({status:"failure",provider:"moyasar",message:n,paymentId:i.config.given_id})}},d.oncancel=()=>{};try{d.begin()}catch(e){r.showErrorToast(e instanceof Error?e.message:"Failed to start Apple Pay")}},[i,s]);return i?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:d,className:"aiatcore-apple-pay-button",style:{borderRadius:o.radius,height:44},"aria-label":"Pay with Apple Pay"}),c&&e.jsx(Re,{url:c,skin:o,onResult:e=>{l(null),u.current(e)}})]}):null};var Ve,Le,Be,Ue={},ze={};function qe(){return Be||(Be=1,Object.defineProperty(ze,"__esModule",{value:!0}),ze.clone=function(e){return e?JSON.parse(JSON.stringify(e)):null}),ze}var Ye,We,He,Je,Ke,Ge,Xe={},Ze={},Qe={};function et(){if(Ge)return Ke;Ge=1;var e=Ke&&Ke.__assign||function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)},t=Le?Ve:(Le=1,Ve={visa:{niceType:"Visa",type:"visa",patterns:[4],gaps:[4,8,12],lengths:[16,18,19],code:{name:"CVV",size:3}},mastercard:{niceType:"Mastercard",type:"mastercard",patterns:[[51,55],[2221,2229],[223,229],[23,26],[270,271],2720],gaps:[4,8,12],lengths:[16],code:{name:"CVC",size:3}},"american-express":{niceType:"American Express",type:"american-express",patterns:[34,37],gaps:[4,10],lengths:[15],code:{name:"CID",size:4}},"diners-club":{niceType:"Diners Club",type:"diners-club",patterns:[[300,305],36,38,39],gaps:[4,10],lengths:[14,16,19],code:{name:"CVV",size:3}},discover:{niceType:"Discover",type:"discover",patterns:[6011,[644,649],65],gaps:[4,8,12],lengths:[16,19],code:{name:"CID",size:3}},jcb:{niceType:"JCB",type:"jcb",patterns:[2131,1800,[3528,3589]],gaps:[4,8,12],lengths:[16,17,18,19],code:{name:"CVV",size:3}},unionpay:{niceType:"UnionPay",type:"unionpay",patterns:[620,[62100,62182],[62184,62187],[62185,62197],[62200,62205],[622010,622999],622018,[62207,62209],[623,626],6270,6272,6276,[627700,627779],[627781,627799],[6282,6289],6291,6292,810,[8110,8131],[8132,8151],[8152,8163],[8164,8171]],gaps:[4,8,12],lengths:[14,15,16,17,18,19],code:{name:"CVN",size:3}},maestro:{niceType:"Maestro",type:"maestro",patterns:[493698,[5e5,504174],[504176,506698],[506779,508999],[56,59],63,67,6],gaps:[4,8,12],lengths:[12,13,14,15,16,17,18,19],code:{name:"CVC",size:3}},elo:{niceType:"Elo",type:"elo",patterns:[401178,401179,438935,457631,457632,431274,451416,457393,504175,[506699,506778],[509e3,509999],627780,636297,636368,[650031,650033],[650035,650051],[650405,650439],[650485,650538],[650541,650598],[650700,650718],[650720,650727],[650901,650978],[651652,651679],[655e3,655019],[655021,655058]],gaps:[4,8,12],lengths:[16],code:{name:"CVE",size:3}},mir:{niceType:"Mir",type:"mir",patterns:[[2200,2204]],gaps:[4,8,12],lengths:[16,17,18,19],code:{name:"CVP2",size:3}},hiper:{niceType:"Hiper",type:"hiper",patterns:[637095,63737423,63743358,637568,637599,637609,637612],gaps:[4,8,12],lengths:[16],code:{name:"CVC",size:3}},hipercard:{niceType:"Hipercard",type:"hipercard",patterns:[606282],gaps:[4,8,12],lengths:[16],code:{name:"CVC",size:3}},verve:{niceType:"Verve",type:"verve",patterns:[[506099,506127],506129,[506133,506150],[506158,506163],506166,506168,506170,506173,[506176,506180],506184,[506187,506188],506191,506195,506197,507865,507866,[507868,507877],[507880,507888],507900,507941],gaps:[4,8,12],lengths:[16,18,19],code:{name:"CVV",size:3}}}),n=function(){if(We)return Ue;We=1,Object.defineProperty(Ue,"__esModule",{value:!0}),Ue.addMatchingCardsToResults=function(n,r,o){var a,i;for(a=0;a<r.patterns.length;a++){var s=r.patterns[a];if((0,t.matches)(n,s)){var c=(0,e.clone)(r);i=Array.isArray(s)?String(s[0]).length:String(s).length,n.length>=i&&(c.matchStrength=i),o.push(c);break}}};var e=qe(),t=(Ye||(Ye=1,Object.defineProperty(Xe,"__esModule",{value:!0}),Xe.matches=function(e,t){return Array.isArray(t)?function(e,t,n){var r=String(t).length,o=e.substr(0,r),a=parseInt(o,10);return t=parseInt(String(t).substr(0,o.length),10),n=parseInt(String(n).substr(0,o.length),10),a>=t&&a<=n}(e,t[0],t[1]):function(e,t){return(t=String(t)).substring(0,e.length)===e.substring(0,t.length)}(e,t)}),Xe);return Ue}(),r=(He||(He=1,Object.defineProperty(Ze,"__esModule",{value:!0}),Ze.isValidInputType=function(e){return"string"==typeof e||e instanceof String}),Ze),o=(Je||(Je=1,Object.defineProperty(Qe,"__esModule",{value:!0}),Qe.findBestMatch=function(e){return function(e){var t=e.filter(function(e){return e.matchStrength}).length;return t>0&&t===e.length}(e)?e.reduce(function(e,t){return e?Number(e.matchStrength)<Number(t.matchStrength)?t:e:t}):null}),Qe),a=qe(),i={},s={VISA:"visa",MASTERCARD:"mastercard",AMERICAN_EXPRESS:"american-express",DINERS_CLUB:"diners-club",DISCOVER:"discover",JCB:"jcb",UNIONPAY:"unionpay",VERVE:"verve",MAESTRO:"maestro",ELO:"elo",MIR:"mir",HIPER:"hiper",HIPERCARD:"hipercard"},c=[s.VISA,s.MASTERCARD,s.AMERICAN_EXPRESS,s.DINERS_CLUB,s.DISCOVER,s.JCB,s.UNIONPAY,s.VERVE,s.MAESTRO,s.ELO,s.MIR,s.HIPER,s.HIPERCARD],l=(0,a.clone)(c);function u(e){return i[e]||t[e]}function d(e,t){void 0===t&&(t=!1);var n=l.indexOf(e);if(!t&&-1===n)throw new Error('"'+e+'" is not a supported card type.');return n}function p(e){var t=[];if(!(0,r.isValidInputType)(e))return t;if(0===e.length)return l.map(function(e){return(0,a.clone)(u(e))});l.forEach(function(r){var o=u(r);(0,n.addMatchingCardsToResults)(e,o,t)});var i=(0,o.findBestMatch)(t);return i?[i]:t}return p.getTypeInfo=function(e){return(0,a.clone)(u(e))},p.removeCard=function(e){var t=d(e);l.splice(t,1)},p.addCard=function(e){var t=d(e.type,!0);i[e.type]=e,-1===t&&l.push(e.type)},p.updateCard=function(n,r){var o=i[n]||t[n];if(!o)throw new Error('"'.concat(n,"\" is not a recognized type. Use `addCard` instead.'"));if(r.type&&o.type!==r.type)throw new Error("Cannot overwrite type parameter.");var s=(0,a.clone)(o);s=e(e({},s),r),i[s.type]=s},p.changeOrder=function(e,t){var n=d(e);l.splice(n,1),l.splice(t,0,e)},p.resetModifications=function(){l=(0,a.clone)(c),i={}},p.types=s,Ke=p}var tt,nt,rt,ot,at,it={},st={},ct={},lt={},ut={};function dt(){if(at)return ut;at=1,Object.defineProperty(ut,"__esModule",{value:!0}),ut.expirationYear=function(n,r){var o;if(void 0===r&&(r=e),"string"!=typeof n)return t(!1,!1);if(""===n.replace(/\s/g,""))return t(!1,!0);if(!/^\d*$/.test(n))return t(!1,!1);var a=n.length;if(a<2)return t(!1,!0);var i=(new Date).getFullYear();if(3===a)return t(!1,n.slice(0,2)===String(i).slice(0,2));if(a>4)return t(!1,!1);var s=parseInt(n,10),c=Number(String(i).substr(2,2)),l=!1;if(2===a){if(String(i).substr(0,2)===n)return t(!1,!0);o=c===s,l=s>=c&&s<=c+r}else 4===a&&(o=i===s,l=s>=i&&s<=i+r);return t(l,l,o)};var e=19;function t(e,t,n){return{isValid:e,isPotentiallyValid:t,isCurrentYear:n||!1}}return ut}var pt,ft,mt,yt,ht={},gt={};function bt(){if(mt)return gt;function e(e,t,n){return{isValid:e,isPotentiallyValid:t,isValidForThisYear:n||!1}}return mt=1,Object.defineProperty(gt,"__esModule",{value:!0}),gt.expirationMonth=function(t){var n=(new Date).getMonth()+1;if("string"!=typeof t)return e(!1,!1);if(""===t.replace(/\s/g,"")||"0"===t)return e(!1,!0);if(!/^\d*$/.test(t))return e(!1,!1);var r=parseInt(t,10);if(isNaN(Number(t)))return e(!1,!1);var o=r>0&&r<13;return e(o,o,o&&r>=n)},gt}var vt,xt,wt,St,Et={},Ct={};const jt=u(function(){if(St)return wt;St=1;var e=wt&&wt.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),t=wt&&wt.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),n=(wt&&wt.__importStar||function(){var n=function(e){return(n=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n);return t})(e)};return function(r){if(r&&r.__esModule)return r;var o={};if(null!=r)for(var a=n(r),i=0;i<a.length;i++)"default"!==a[i]&&e(o,r,a[i]);return t(o,r),o}}())(et()),r=function(){if(tt)return it;tt=1,Object.defineProperty(it,"__esModule",{value:!0}),it.cardholderName=function(r){return"string"!=typeof r?n(!1,!1):0===r.length?n(!1,!0):r.length>t?n(!1,!1):e.test(r)?n(!1,!0):n(!0,!0)};var e=/^[\d\s-]*$/,t=255;function n(e,t){return{isValid:e,isPotentiallyValid:t}}return it}(),o=function(){if(ot)return st;ot=1,Object.defineProperty(st,"__esModule",{value:!0}),st.cardNumber=function(r,o){var a,i;if(void 0===o&&(o={}),"string"!=typeof r&&"number"!=typeof r)return n(null,!1,!1);var s=String(r).replace(/-|\s/g,"");if(!/^\d*$/.test(s))return n(null,!1,!1);var c=t(s);if(0===c.length)return n(null,!1,!1);if(1!==c.length)return n(null,!0,!1);var l=c[0];if(o.maxLength&&s.length>o.maxLength)return n(l,!1,!1);a=!0===o.skipLuhnValidation||l.type===t.types.UNIONPAY&&!0!==o.luhnValidateUnionPay||e(s),i=Math.max.apply(null,l.lengths),o.maxLength&&(i=Math.min(o.maxLength,i));for(var u=0;u<l.lengths.length;u++)if(l.lengths[u]===s.length)return n(l,s.length<i||a,a);return n(l,s.length<i,!1)};var e=rt?nt:(rt=1,nt=function(e){for(var t,n=0,r=!1,o=e.length-1;o>=0;)t=parseInt(e.charAt(o),10),r&&(t*=2)>9&&(t=t%10+1),r=!r,n+=t,o--;return n%10==0}),t=et();function n(e,t,n){return{card:e,isPotentiallyValid:t,isValid:n}}return st}(),a=function(){if(yt)return ct;yt=1;var e=ct&&ct.__assign||function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)};Object.defineProperty(ct,"__esModule",{value:!0}),ct.expirationDate=function(a,i){var s;if("string"==typeof a)a=a.replace(/^(\d\d) (\d\d(\d\d)?)$/,"$1/$2"),s=(0,t.parseDate)(String(a));else{if(null===a||"object"!=typeof a)return o(!1,!1,null,null);var c=e({},a);s={month:String(c.month),year:String(c.year)}}var l=(0,n.expirationMonth)(s.month),u=(0,r.expirationYear)(s.year,i);if(l.isValid){if(u.isCurrentYear){var d=l.isValidForThisYear;return o(d,d,s.month,s.year)}if(u.isValid)return o(!0,!0,s.month,s.year)}return o(!1,!(!l.isPotentiallyValid||!u.isPotentiallyValid),null,null)};var t=function(){if(ft)return lt;ft=1,Object.defineProperty(lt,"__esModule",{value:!0}),lt.parseDate=function(n){var r;if(/^\d{4}-\d{1,2}$/.test(n)?r=n.split("-").reverse():/\//.test(n)?r=n.split(/\s*\/\s*/g):/\s/.test(n)&&(r=n.split(/ +/g)),(0,t.isArray)(r))return{month:r[0]||"",year:r.slice(1).join()};var o,a,i,s=(o=n,0===(i=Number(o[0]))?2:i>1||1===i&&Number(o[1])>2?1:1===i?(a=o.substr(1),(0,e.expirationYear)(a).isPotentiallyValid?1:2):5===o.length?1:o.length>5?2:1),c=n.substr(0,s);return{month:c,year:n.substr(c.length)}};var e=dt(),t=(pt||(pt=1,Object.defineProperty(ht,"__esModule",{value:!0}),ht.isArray=void 0,ht.isArray=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)}),ht);return lt}(),n=bt(),r=dt();function o(e,t,n,r){return{isValid:e,isPotentiallyValid:t,month:n,year:r}}return ct}(),i=bt(),s=dt(),c=function(){if(vt)return Et;vt=1,Object.defineProperty(Et,"__esModule",{value:!0}),Et.cvv=function(n,r){return void 0===r&&(r=e),r=r instanceof Array?r:[r],"string"!=typeof n?t(!1,!1):/^\d*$/.test(n)?function(e,t){for(var n=0;n<e.length;n++)if(t===e[n])return!0;return!1}(r,n.length)?t(!0,!0):n.length<Math.min.apply(null,r)?t(!1,!0):n.length>function(t){for(var n=e,r=0;r<t.length;r++)n=t[r]>n?t[r]:n;return n}(r)?t(!1,!1):t(!0,!0):t(!1,!1)};var e=3;function t(e,t){return{isValid:e,isPotentiallyValid:t}}return Et}(),l=function(){if(xt)return Ct;xt=1,Object.defineProperty(Ct,"__esModule",{value:!0}),Ct.postalCode=function(r,o){void 0===o&&(o={});var a=o.minLength||e;return"string"!=typeof r?n(!1,!1):r.length<a?n(!1,!0):t.test(r.trim().slice(0,a))?n(!0,!0):n(!1,!0)};var e=2,t=new RegExp(/^[a-z0-9]+$/i);function n(e,t){return{isValid:e,isPotentiallyValid:t}}return Ct}();return wt={creditCardType:n,cardholderName:r.cardholderName,number:o.cardNumber,expirationDate:a.expirationDate,expirationMonth:i.expirationMonth,expirationYear:s.expirationYear,cvv:c.cvv,postalCode:l.postalCode}}()),kt=u(et());let Pt=!1;Pt||(Pt=!0,kt.addCard({niceType:"Mada",type:"mada",patterns:[440647,440795,446404,446672,419593,428331,428671,432328,440533,446393,457865,458456,462220,484783,484800,493428,504300,521076,529415,535825,536023,537767,543357,557606,558848,588845,589206],gaps:[4,8,12],lengths:[16,18,19],code:{name:"CVV",size:3}}));const _t=({brand:t,fallbackColor:n,height:r=22})=>{if(!t)return null;switch(t){case"Visa":return e.jsx(Ot,{height:r});case"Mastercard":return e.jsx(At,{height:r});case"American Express":return e.jsx(Tt,{height:r});case"Mada":return e.jsx(Nt,{height:r});case"Discover":return e.jsx(It,{height:r});case"JCB":return e.jsx(Mt,{height:r});default:return e.jsx("span",{className:"text-xs font-medium",style:{color:n},"aria-label":`Card brand: ${t}`,children:t})}},Ot=({height:t})=>e.jsxs("svg",{role:"img","aria-label":"Visa",viewBox:"0 0 48 16",height:t,width:48*t/16,style:{display:"block"},children:[e.jsx("rect",{width:"48",height:"16",rx:"2",fill:"#1A1F71"}),e.jsx("text",{x:"24",y:"12",textAnchor:"middle",fontFamily:"Helvetica, Arial, sans-serif",fontWeight:"900",fontSize:"11",fill:"#FFFFFF",letterSpacing:"1.4",children:"VISA"})]}),At=({height:t})=>e.jsxs("svg",{role:"img","aria-label":"Mastercard",viewBox:"0 0 32 20",height:t,width:32*t/20,style:{display:"block"},children:[e.jsx("circle",{cx:"12",cy:"10",r:"7",fill:"#EB001B"}),e.jsx("circle",{cx:"20",cy:"10",r:"7",fill:"#F79E1B"}),e.jsx("path",{d:"M16 4.5a7 7 0 0 1 0 11 7 7 0 0 1 0-11Z",fill:"#FF5F00","aria-hidden":"true"})]}),Tt=({height:t})=>e.jsxs("svg",{role:"img","aria-label":"American Express",viewBox:"0 0 48 16",height:t,width:48*t/16,style:{display:"block"},children:[e.jsx("rect",{width:"48",height:"16",rx:"2",fill:"#2E77BB"}),e.jsx("text",{x:"24",y:"11.5",textAnchor:"middle",fontFamily:"Helvetica, Arial, sans-serif",fontWeight:"700",fontSize:"9",fill:"#FFFFFF",letterSpacing:"0.4",children:"AMEX"})]}),Nt=({height:t})=>e.jsxs("svg",{role:"img","aria-label":"Mada",viewBox:"0 0 48 16",height:t,width:48*t/16,style:{display:"block"},children:[e.jsx("rect",{width:"48",height:"16",rx:"2",fill:"#84B740"}),e.jsx("text",{x:"24",y:"11.5",textAnchor:"middle",fontFamily:"Helvetica, Arial, sans-serif",fontWeight:"700",fontSize:"9",fill:"#FFFFFF",letterSpacing:"0.6",children:"mada"})]}),It=({height:t})=>e.jsxs("svg",{role:"img","aria-label":"Discover",viewBox:"0 0 56 16",height:t,width:56*t/16,style:{display:"block"},children:[e.jsx("rect",{width:"56",height:"16",rx:"2",fill:"#FFFFFF",stroke:"#E5E7EB"}),e.jsx("text",{x:"20",y:"11.5",textAnchor:"middle",fontFamily:"Helvetica, Arial, sans-serif",fontWeight:"700",fontSize:"8",fill:"#231F20",letterSpacing:"0.2",children:"DISCOVER"}),e.jsx("circle",{cx:"44",cy:"8",r:"4",fill:"#FF6000"})]}),Mt=({height:t})=>e.jsxs("svg",{role:"img","aria-label":"JCB",viewBox:"0 0 32 16",height:t,width:32*t/16,style:{display:"block"},children:[e.jsx("rect",{x:"0",y:"0",width:"10.66",height:"16",rx:"2",fill:"#0E4C96"}),e.jsx("rect",{x:"10.66",y:"0",width:"10.66",height:"16",fill:"#B41E25"}),e.jsx("rect",{x:"21.33",y:"0",width:"10.66",height:"16",rx:"2",fill:"#1B8A3A"}),e.jsx("text",{x:"16",y:"11",textAnchor:"middle",fontFamily:"Helvetica, Arial, sans-serif",fontWeight:"900",fontSize:"9",fill:"#FFFFFF",children:"JCB"})]}),Rt=({skin:r})=>{const{paymentInit:o}=on(),a=o&&"moyasar"===o.provider?o:null,i=de(),s=pe(),c=fe(),[l,u]=t.useState(""),[d,p]=t.useState(""),[f,m]=t.useState(""),[y,h]=t.useState(""),[g,b]=t.useState(!1),[v,x]=t.useState({}),[w,S]=t.useState(null),E=t.useRef({number:l,expiry:d,cvc:f,name:y});E.current={number:l,expiry:d,cvc:f,name:y};const C=t.useRef(i);C.current=i,t.useEffect(()=>{a&&c({amount:a.config.amount,currency:a.config.currency.toUpperCase()})},[a,c]);const j=t.useCallback(async()=>{if(!a)return;const e=function(e,t=new Date){const n=[],r=jt.number(e.number),o=e.number.replace(/\D/g,"");o?r.isValid||n.push({field:"number",message:"Invalid card number"}):n.push({field:"number",message:"Card number is required"});const a=jt.expirationDate(e.expiry);let i=null,s=null;const c=e.expiry.trim();if(c)if(a.isValid){i=Number.parseInt(a.month??"",10);const e=Number.parseInt(a.year??"",10);s=2===(a.year??"").length?e+2e3:e}else{const e=function(e){let t="",n="";if(e.includes("/")){const[r,o]=e.split("/");t=(r??"").replace(/\D/g,""),n=(o??"").replace(/\D/g,"")}else{const r=e.replace(/\D/g,"");t=r.slice(0,2),n=r.slice(2)}const r=Number.parseInt(t,10),o=Number.parseInt(n,10);return Number.isNaN(r)||Number.isNaN(o)?null:{month:r,year:2===n.length?o+2e3:o}}(c);e&&function(e,t,n){const r=n.getFullYear(),o=n.getMonth()+1;return t<r||t===r&&e<o}(e.month,e.year,t)?n.push({field:"expiry",message:"Card expired"}):n.push({field:"expiry",message:"Invalid expiry"})}else n.push({field:"expiry",message:"Expiry is required"});const l=jt.cvv(e.cvc,r.card?.code.size??[3,4]),u=e.cvc.replace(/\D/g,"");u?l.isValid||n.push({field:"cvc",message:"Invalid CVC"}):n.push({field:"cvc",message:"CVC is required"});const d=jt.cardholderName(e.name),p=e.name.trim();return p?d.isValid||n.push({field:"name",message:"Invalid cardholder name"}):n.push({field:"name",message:"Cardholder name is required"}),n.length>0||null==i||null==s?{ok:!1,errors:n}:{ok:!0,card:{number:o,month:String(i).padStart(2,"0"),year:String(s),cvc:u,name:p}}}(E.current);if(!1===e.ok){const t={};for(const n of e.errors)t[n.field]||(t[n.field]=n.message);return void x(t)}x({}),b(!0);try{const t=await async function(e){const t=await Ne("https://api.moyasar.com/v1/tokens",{...e,save_only:!0});if(!t.ok)throw new Ae(Ie(t.body)??`Tokenization failed (${t.status})`,t.status,t.body);const n=t.body;if(!n||"string"!=typeof n.id)throw new Ae("Tokenization returned no token id",t.status,n);return{id:n.id}}({publishable_api_key:a.config.publishable_key,name:e.card.name,number:e.card.number,month:e.card.month,year:e.card.year,cvc:e.card.cvc}),r=Oe(a),o=await Te({publishable_api_key:a.config.publishable_key,given_id:a.config.given_id,amount:a.config.amount,currency:a.config.currency.toUpperCase(),description:a.config.description,callback_url:n.buildCallbackUrl(a.config.given_id),source:{type:"token",token:t.id},...Object.keys(r).length>0?{metadata:r}:{}}),i=o.source?.transaction_url??o.transaction_url;if(i)return void S(i);const s=o.status;C.current("paid"===s||"authorized"===s||"captured"===s?{status:"success",provider:"moyasar",paymentId:o.id,amount:o.amount,currency:o.currency}:"failed"===s?{status:"failure",provider:"moyasar",code:"failed",message:o.source?.message??"Payment failed",paymentId:o.id}:{status:"failure",provider:"moyasar",code:s,message:`Unexpected payment status: ${s}`,paymentId:o.id})}catch(e){const t=e instanceof Ae||e instanceof Error?e.message:"Payment failed";C.current({status:"failure",provider:"moyasar",message:t,paymentId:a.config.given_id})}finally{b(!1)}},[a]);t.useEffect(()=>(s({confirm:j,isConfirming:g}),()=>s(null)),[j,g,s]);const k=t.useMemo(()=>Math.max(r.radius-4,4),[r.radius]),P=t.useMemo(()=>function(e){const t=e.replace(/\D/g,"");if(t.length<2)return null;const n=kt(t);return n[0]?.niceType??null}(l),[l]);return a?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-3",style:{fontFamily:r.fontFamily},children:[e.jsx($t,{label:"Card number",value:l,onChange:e=>u(e.replace(/\D/g,"").slice(0,19).replace(/(\d{4})(?=\d)/g,"$1 ")),autoComplete:"cc-number",inputMode:"numeric",placeholder:"1234 5678 9012 3456",error:v.number,skin:r,radius:k,endAdornment:P?e.jsx(_t,{brand:P,fallbackColor:r.muted}):null}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx($t,{label:"Expiry",value:d,onChange:e=>p(function(e){const t=e.replace(/\D/g,"").slice(0,4);return t.length<=2?t:`${t.slice(0,2)}/${t.slice(2)}`}(e)),autoComplete:"cc-exp",inputMode:"numeric",placeholder:"MM / YY",error:v.expiry,skin:r,radius:k}),e.jsx($t,{label:"CVC",value:f,onChange:e=>m(e.replace(/\D/g,"").slice(0,4)),autoComplete:"cc-csc",inputMode:"numeric",placeholder:"123",error:v.cvc,skin:r,radius:k})]}),e.jsx($t,{label:"Name on card",value:y,onChange:h,autoComplete:"cc-name",inputMode:"text",placeholder:"Full name",error:v.name,skin:r,radius:k})]}),w&&e.jsx(Re,{url:w,skin:r,onResult:e=>{S(null),C.current(e)}})]}):null};function Ft(e){let t=0;for(let n=0;n<e.length;n++){const r=e.charCodeAt(n);r>=48&&r<=57&&t++}return t}const $t=({label:n,value:r,onChange:o,placeholder:a,autoComplete:i,inputMode:s,error:c,skin:l,radius:u,endAdornment:d})=>{const p=c?"#dc2626":l.divider,f=t.useRef(null),m=t.useRef(null),y="numeric"===s;return t.useLayoutEffect(()=>{const e=m.current;if(null===e||!f.current)return;m.current=null;const t=f.current.value;let n=0,r=0;for(;r<t.length&&!(n>=e);)/\d/.test(t[r])&&n++,r++;f.current.setSelectionRange(r,r)},[r]),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"block text-xs mb-1",style:{color:l.muted},children:n}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{ref:f,type:"text",value:r,onChange:e=>{y&&(m.current=Ft(e.target.value.slice(0,e.target.selectionStart??e.target.value.length))),o(e.target.value)},onKeyDown:e=>{if(!y||"Backspace"!==e.key)return;const t=e.currentTarget,n=t.selectionStart??0;if(n!==(t.selectionEnd??0)||n<2)return;const r=t.value[n-1];if(!r||/\d/.test(r))return;e.preventDefault();const a=t.value.slice(0,n-2)+t.value.slice(n);m.current=Ft(a.slice(0,n-2)),o(a)},placeholder:a,autoComplete:i,inputMode:s,spellCheck:!1,className:"w-full py-3 px-3 outline-none text-sm transition-colors",style:{background:l.pillBg,color:l.text,border:`1px solid ${p}`,borderRadius:u,paddingRight:d?96:void 0}}),d&&e.jsx("span",{className:"absolute right-3 top-1/2 -translate-y-1/2 text-xs font-medium pointer-events-none",style:{color:l.muted},"aria-label":"Card brand",children:d})]}),c&&e.jsx("span",{className:"block mt-1 text-xs",style:{color:"#dc2626"},children:c})]})},Dt=["creditcard","applepay"],Vt=({skin:t})=>e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-x-0 top-1/2",style:{borderTop:`1px solid ${t.divider}`}}),e.jsx("div",{className:"relative flex justify-center",children:e.jsx("span",{className:"px-2 text-xs uppercase tracking-wide",style:{background:t.cardBg,color:t.muted,fontFamily:t.fontFamily},children:"or"})})]}),Lt={type:"moyasar",label:"Moyasar",FormComponent:({skin:n,onReady:r})=>{const{paymentInit:o}=on(),a=o&&"moyasar"===o.provider?o:null,i=function(){const[e,n]=t.useState(!1);return t.useEffect(()=>{if("undefined"==typeof window)return;const e=window.ApplePaySession;if(e&&"function"==typeof e.canMakePayments)try{n(!0===e.canMakePayments())}catch{n(!1)}},[]),e}(),s=t.useRef(r);if(s.current=r,t.useEffect(()=>{s.current?.()},[]),!a)return null;const c=a.config.methods??Dt,l=c.includes("creditcard"),u=c.includes("applepay")&&i;return e.jsxs("div",{className:"space-y-4",children:[l&&e.jsx(Rt,{skin:n}),l&&u&&e.jsx(Vt,{skin:n}),u&&e.jsx(De,{skin:n})]})}},Bt="5vh",Ut="5vw",zt="aiatcore-chargebee-modal-style",qt="aiatcore-chargebee-close-button",Yt="aiatcore-chargebee-loader",Wt="aiatcore-cb-spin",Ht='#cb-container, .cb-container, [id^="cb-modal"], [class*="cb-modal"], [class*="cb-checkout"], div[class*="cb-"][class*="overlay"]',Jt="aiatcore-chargebee-open";function Kt(){document.getElementById(qt)?.remove()}function Gt(){document.getElementById(Yt)?.remove()}const Xt={type:"chargebee",label:"Chargebee",FormComponent:({amount:e,currency:n,onReady:r})=>{const{paymentInit:o}=on(),a=de(),i=fe(),s=pe(),c=t.useRef(!1);return t.useEffect(()=>(s(null),()=>s(null)),[s]),t.useEffect(()=>{if("chargebee"!==o?.provider)return;const{site:t,hosted_page_url:s,amount:l,currency:u,expires_at:d}=o.config,p=l??e,f=u??n;null!=p&&f&&i({amount:p,currency:f}),c.current=!1;let m=!1,y=null,h=null;const g=e=>{c.current||(c.current=!0,a(e))};return r?.(),null!=d&&Date.now()>=1e3*d?(g({status:"failure",provider:"chargebee",message:"Payment link has expired. Please request a new one."}),()=>{m=!0}):(function(){const e=document.getElementById(zt)??document.createElement("style");e.id=zt,e.textContent=`\n /* Prevent horizontal page scroll only while Chargebee's overlay is mounted */\n html.${Jt}, body.${Jt} {\n overflow-x: hidden !important;\n }\n\n /* Outer Chargebee overlay container — broad selector net so we catch\n whatever wrapper Chargebee actually uses */\n #cb-container,\n .cb-container,\n [id^="cb-modal"],\n [class*="cb-modal"],\n [class*="cb-checkout"],\n div[class*="cb-"][class*="overlay"] {\n position: fixed !important;\n inset: ${Bt} max(${Ut}, calc((100vw - 1500px) / 2)) !important;\n width: auto !important;\n height: auto !important;\n max-width: none !important;\n max-height: none !important;\n margin: 0 !important;\n border-radius: 12px !important;\n box-shadow: 0 20px 60px rgba(0,0,0,0.35) !important;\n overflow: hidden !important;\n z-index: 2147483646 !important;\n pointer-events: all !important;\n }\n\n /* Inner iframe — fill the container fully and ensure it receives clicks */\n [id^="cb-frame"] {\n width: 100% !important;\n height: 100% !important;\n border: none !important;\n display: block !important;\n z-index: 2147483646 !important;\n pointer-events: all !important;\n outline: none !important;\n box-shadow: none !important;\n }\n\n @keyframes ${Wt} {\n to { transform: rotate(360deg); }\n }\n `,e.parentElement||document.head.appendChild(e),document.documentElement.classList.add(Jt),document.body.classList.add(Jt)}(),function(e){if(window.Chargebee)return Promise.resolve();const t=document.querySelector('script[src*="js.chargebee.com"]');return t?"1"===t.dataset.cbLoaded?Promise.resolve():new Promise((e,n)=>{t.addEventListener("load",()=>e()),t.addEventListener("error",()=>n(new Error("Chargebee.js failed to load")))}):new Promise((t,n)=>{const r=document.createElement("script");r.src="https://js.chargebee.com/v2/chargebee.js",r.setAttribute("data-cb-site",e),r.onload=()=>{r.dataset.cbLoaded="1",t()},r.onerror=()=>n(new Error("Chargebee.js failed to load")),document.head.appendChild(r)})}(t).then(()=>{if(m)return;let e;try{e=window.Chargebee.getInstance()??window.Chargebee.init({site:t})}catch{e=window.Chargebee.init({site:t})}e.openCheckout({hostedPage:()=>Promise.resolve({id:o.payment_id,url:s,type:"checkout_one_time",state:"created"}),success:e=>{Kt(),Gt(),g({status:"success",provider:"chargebee",paymentId:e,amount:p??void 0,currency:f??void 0})},close:()=>{Kt(),Gt(),g({status:"cancel",provider:"chargebee"})},error:e=>{Kt(),Gt(),g({status:"failure",provider:"chargebee",message:e?.message??"Payment failed"})}}),h=function(){let e=0,t=0,n=0,r=null,o=null;const a=Date.now()+5e3,i=()=>{if(m||c.current)return;const t=document.querySelector(Ht);if(t instanceof HTMLElement){const e=t.getBoundingClientRect();if(e.width>0&&e.height>0){!function(){Gt();const e=document.createElement("div");e.id=Yt,e.setAttribute("aria-live","polite"),e.setAttribute("aria-busy","true"),e.style.cssText=`\n position: fixed;\n inset: ${Bt} max(${Ut}, calc((100vw - 1500px) / 2));\n z-index: 2147483646;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n gap: 14px;\n background: #f8f8f8;\n border-radius: 12px;\n color: #6b7280;\n font: 500 14px/1.4 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;\n pointer-events: none;\n `;const t=document.createElement("div");t.style.cssText=`\n width: 32px;\n height: 32px;\n border: 2.5px solid rgba(17, 24, 39, 0.08);\n border-top-color: #6366f1;\n border-radius: 50%;\n animation: ${Wt} 0.8s linear infinite;\n `;const n=document.createElement("p");n.textContent="Loading payment…",n.style.cssText="margin: 0;",e.appendChild(t),e.appendChild(n),document.body.appendChild(e)}();const e=document.querySelector('[id^="cb-frame"]');return void(e instanceof HTMLIFrameElement&&(r=e,o=()=>{n=window.setTimeout(Gt,400)},r.addEventListener("load",o)))}}Date.now()>=a||(e=window.requestAnimationFrame(i))};return t=window.setTimeout(i,100),()=>{window.clearTimeout(t),window.clearTimeout(n),e&&window.cancelAnimationFrame(e),r&&o&&r.removeEventListener("load",o),Gt()}}(),y=function(e){let t=0,n=0;const r=Date.now()+5e3,o=()=>{if(m||c.current)return;const n=document.querySelector(Ht);if(n instanceof HTMLElement){const t=n.getBoundingClientRect();if(t.width>0&&t.height>0)return void function(e){Kt();const t=document.createElement("button");t.id=qt,t.type="button",t.setAttribute("aria-label","Close payment"),t.textContent="×",t.style.cssText=`\n position: fixed;\n top: calc(${Bt} + 12px);\n right: calc(max(${Ut}, calc((100vw - 1500px) / 2)) + 12px);\n z-index: 2147483647;\n width: 32px;\n height: 32px;\n border: 0;\n border-radius: 9999px;\n background: rgba(17, 24, 39, 0.72);\n color: #ffffff;\n font: 600 16px/1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;\n cursor: pointer;\n pointer-events: auto;\n display: flex;\n align-items: center;\n justify-content: center;\n box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);\n `,t.addEventListener("click",e),document.body.appendChild(t)}(e)}Date.now()>=r||(t=window.requestAnimationFrame(o))};return n=window.setTimeout(o,100),()=>{window.clearTimeout(n),t&&window.cancelAnimationFrame(t)}}(()=>{Kt(),Gt(),document.querySelectorAll(Ht).forEach(e=>{e instanceof HTMLElement&&(e.style.display="none")}),g({status:"cancel",provider:"chargebee"});try{e.closeAll()}catch{}})}).catch(e=>{g({status:"failure",provider:"chargebee",message:e?.message??"Failed to load payment form"})}),()=>{m=!0,y?.(),h?.(),Kt(),Gt(),document.documentElement.classList.remove(Jt),document.body.classList.remove(Jt),document.getElementById(zt)?.remove();try{window.Chargebee?.getInstance?.()?.closeAll?.()}catch{}})},[o,e,n,i,r,a]),null},hideShellSubmit:!0};function Zt(){const e=document.createElement("div");e.style.cssText="position:absolute;top:-9999px;width:100px;height:100px;overflow:scroll;",document.body.appendChild(e);const t=e.offsetWidth-e.clientWidth;return e.remove(),Math.max(0,t)}function Qt(e,t,r){e?.contentWindow?.postMessage(n.buildHostedPaymentPageThemeMessage(t),r)}const en=({init:o,onResult:a,skin:i})=>{const s=t.useRef(null),c=t.useRef(a);t.useLayoutEffect(()=>{c.current=a},[a]);const l=t.useRef(i),u=t.useRef(!1),d=t.useRef(null);t.useLayoutEffect(()=>{l.current=i,u.current&&Qt(s.current,i,d.current??"*")},[i]);const p=t.useRef(!1),f=t.useRef(!1),m=t.useRef(!1),[y,h]=t.useState(!1),[g]=t.useState(Zt),b=t.useCallback(e=>{f.current||p.current||(f.current=!0,c.current({status:"failure",provider:"hosted_payment_page",message:e,paymentId:o.payment_id}))},[o.payment_id]);return t.useEffect(()=>{const e=e=>{if(e.source!==s.current?.contentWindow)return;if(!n.isHostedPaymentPageCallbackMessage(e.data))return;if(d.current=e.origin,e.data.action===n.HOSTED_PAYMENT_PAGE_CALLBACK_ACTIONS.LOADED&&(u.current=!0,Qt(s.current,l.current,e.origin)),f.current)return;const t=n.parseHostedPaymentPageCallback(e.data.search);if(!t)return r.logger.warn({message:"Hosted payment callback arrived without a paymentId or a known paymentStatus",api_name:"hosted-payment-page-callback"}),void b("Payment confirmation was incomplete. Please try again.");const a=e.data.action===n.HOSTED_PAYMENT_PAGE_CALLBACK_ACTIONS.DONE;if(p.current=!0,t.paymentStatus===n.HOSTED_PAYMENT_PAGE_STATUSES.CANCELED){if(!a)return;return f.current=!0,void c.current({status:"cancel",provider:"hosted_payment_page"})}a&&(f.current=!0),c.current(t.paymentStatus===n.HOSTED_PAYMENT_PAGE_STATUSES.SUCCEEDED?{status:"success",provider:"hosted_payment_page",paymentId:t.paymentId,...t.amount&&t.currency?{amount:t.amount,currency:t.currency}:{amount:o.config.amount,currency:o.config.currency},dismissed:a}:{status:"failure",provider:"hosted_payment_page",code:t.paymentStatus,message:t.message??"The payment was not completed.",paymentId:t.paymentId,dismissed:a})};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[b,o]),t.useEffect(()=>{const e=setTimeout(()=>{m.current||b("The payment page failed to load.")},6e4);return()=>clearTimeout(e)},[b]),e.jsxs("div",{className:"absolute inset-0 z-[105] overflow-hidden",style:{background:i.cardBg},role:"region","aria-label":"Payment",children:[!y&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center text-sm",style:{color:i.muted,fontFamily:i.fontFamily},children:"Loading…"}),e.jsx("iframe",{ref:s,src:o.config.url,title:"Payment",className:"h-full",style:{border:0,background:"white",width:`calc(100% + ${g}px)`},onLoad:()=>{m.current=!0,h(!0)},onError:()=>b("The payment page failed to load."),allow:"payment",referrerPolicy:"no-referrer"})]})},tn={type:"hosted_payment_page",label:"Secure checkout",hideShellSubmit:!0,hideShellFooter:!0,FormComponent:({skin:n,onReady:r})=>{const{paymentInit:o}=on(),a=o&&"hosted_payment_page"===o.provider?o:null,i=de(),s=t.useRef(!1);t.useEffect(()=>{r?.()},[r]);const c=a?.config.expires_at,[l]=t.useState(()=>null!=c&&Date.now()>=1e3*c);return t.useEffect(()=>{a&&l&&!s.current&&(s.current=!0,i({status:"failure",provider:"hosted_payment_page",message:"Payment link has expired. Please request a new one.",paymentId:a.payment_id}))},[a,l,i]),!a||l?null:e.jsx(en,{init:a,onResult:i,skin:n})}},nn=t.createContext(void 0),rn=({children:r,paymentProvider:o,paymentInit:a=null,conversationId:i=null})=>{const s=a?.provider||o||n.DEFAULT_PAYMENT_PROVIDER,c=t.useMemo(()=>function(e){switch(e){case"stripe":return _e;case"moyasar":return Lt;case"chargebee":return Xt;case"hosted_payment_page":return tn;default:throw new Error(`Unknown payment provider: "${e}". Supported providers: stripe, moyasar, chargebee, hosted_payment_page`)}}(s),[s]),l=t.useMemo(()=>({adapter:c,paymentProvider:s,paymentInit:a,conversationId:i}),[c,s,a,i]),u=c.ProviderWrapper;return e.jsx(nn.Provider,{value:l,children:u?e.jsx(u,{children:r}):r})},on=()=>{const e=t.useContext(nn);if(!e)throw new Error("usePaymentAdapter must be used within a PaymentProvider");return e},an=({provider:o,paymentInit:a})=>{const{themeStyles:i,theme:s}=r.useBranding(),{adapter:c}=on(),l=ue().summary,[u,d]=t.useState(!1),p=t.useCallback(()=>d(!0),[]),f=t.useMemo(()=>n.buildBrandSkin(i,s),[i,s]),m="moyasar"===a?.provider?a.config:null,y="chargebee"===a?.provider?a.config:null,h=l?.amount??m?.amount??y?.amount??0,g=l?.currency??m?.currency??y?.currency??"usd",b=null!=l?.amount||null!=m?.amount||null!=y?.amount,v=((e,t)=>n.formatAmount(e,t)??"")(h,g),x=o??c.label,w=c.FormComponent;return e.jsxs("div",{className:"w-full flex-1 min-h-0 overflow-y-auto [&::-webkit-scrollbar]:hidden [scrollbar-width:none] relative",style:{background:f.pageBg,color:f.text,fontFamily:f.fontFamily,colorScheme:f.colorScheme},children:[!u&&e.jsx(sn,{skin:f}),e.jsx("div",{className:"min-h-full flex items-center justify-center p-4",style:{visibility:u?"visible":"hidden"},children:e.jsxs("div",{className:"w-full max-w-lg p-6",style:{background:f.cardBg,borderRadius:f.radius,boxShadow:f.cardShadow,color:f.text},children:[e.jsx("h1",{className:"text-base font-semibold text-center mb-3.5",style:{color:f.heading},children:"Payment Options"}),e.jsx("div",{className:"mb-3.5",children:e.jsx(w,{amount:h,currency:g,skin:f,onReady:p})}),!c.hideShellSubmit&&b&&e.jsx(cn,{label:`Pay ${v}`,background:i.statusDiscovery.solid,color:i.statusDiscovery.text,radius:f.radius}),!c.hideShellFooter&&e.jsxs("p",{className:"text-xs text-center mt-2.5",style:{color:f.muted},children:["Powered by ",x]})]})})]})},sn=({skin:t})=>e.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-3",style:{background:t.pageBg,color:t.text},"aria-live":"polite","aria-busy":"true",children:[e.jsx(l,{className:"h-8 w-8 animate-spin",style:{color:t.accent}}),e.jsx("p",{className:"text-sm",style:{color:t.muted},children:"Loading payment…"})]}),cn=({label:t,background:n,color:r,radius:o})=>{const a=ue().confirmHandle;return e.jsx("button",{type:"button",onClick:()=>a?.confirm(),disabled:!a||a.isConfirming,className:"w-full p-3 text-sm font-semibold border-0 cursor-pointer disabled:cursor-not-allowed disabled:opacity-70",style:{background:n,color:r,borderRadius:o},children:a?.isConfirming?"Processing…":t})};exports.default=({provider:t,paymentInit:n=null,onResult:o,conversationId:a=null})=>e.jsx(rn,{paymentInit:n,conversationId:a,paymentProvider:r.getPaymentProviderHint(),children:e.jsx(le,{onResult:e=>{o?.(e)},children:e.jsx(an,{provider:t,paymentInit:n})})},n?.provider??"default");
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("react"),n=require("@1interface/chat-core"),r=require("@1interface/shared-core"),o=e=>{const t=(e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,t,n)=>n?n.toUpperCase():t.toLowerCase()))(e);return t.charAt(0).toUpperCase()+t.slice(1)},a=(...e)=>e.filter((e,t,n)=>Boolean(e)&&""!==e.trim()&&n.indexOf(e)===t).join(" ").trim(),i=e=>{for(const t in e)if(t.startsWith("aria-")||"role"===t||"title"===t)return!0};var s={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};const c=t.forwardRef(({color:e="currentColor",size:n=24,strokeWidth:r=2,absoluteStrokeWidth:o,className:c="",children:l,iconNode:u,...d},p)=>t.createElement("svg",{ref:p,...s,width:n,height:n,stroke:e,strokeWidth:o?24*Number(r)/Number(n):r,className:a("lucide",c),...!l&&!i(d)&&{"aria-hidden":"true"},...d},[...u.map(([e,n])=>t.createElement(e,n)),...Array.isArray(l)?l:[l]])),l=((e,n)=>{const r=t.forwardRef(({className:r,...i},s)=>{return t.createElement(c,{ref:s,iconNode:n,className:a(`lucide-${l=o(e),l.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}`,`lucide-${e}`,r),...i});var l});return r.displayName=o(e),r})("loader-circle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]);function u(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var d,p,f,m,y,h,g,b,v,x,w,S,E,C,j,k,P={exports:{}},_={exports:{}},A={},O={};function T(){return f||(f=1,_.exports="production"===process.env.NODE_ENV?function(){if(d)return A;d=1;var e="function"==typeof Symbol&&Symbol.for,t=e?Symbol.for("react.element"):60103,n=e?Symbol.for("react.portal"):60106,r=e?Symbol.for("react.fragment"):60107,o=e?Symbol.for("react.strict_mode"):60108,a=e?Symbol.for("react.profiler"):60114,i=e?Symbol.for("react.provider"):60109,s=e?Symbol.for("react.context"):60110,c=e?Symbol.for("react.async_mode"):60111,l=e?Symbol.for("react.concurrent_mode"):60111,u=e?Symbol.for("react.forward_ref"):60112,p=e?Symbol.for("react.suspense"):60113,f=e?Symbol.for("react.suspense_list"):60120,m=e?Symbol.for("react.memo"):60115,y=e?Symbol.for("react.lazy"):60116,h=e?Symbol.for("react.block"):60121,g=e?Symbol.for("react.fundamental"):60117,b=e?Symbol.for("react.responder"):60118,v=e?Symbol.for("react.scope"):60119;function x(e){if("object"==typeof e&&null!==e){var d=e.$$typeof;switch(d){case t:switch(e=e.type){case c:case l:case r:case a:case o:case p:return e;default:switch(e=e&&e.$$typeof){case s:case u:case y:case m:case i:return e;default:return d}}case n:return d}}}function w(e){return x(e)===l}return A.AsyncMode=c,A.ConcurrentMode=l,A.ContextConsumer=s,A.ContextProvider=i,A.Element=t,A.ForwardRef=u,A.Fragment=r,A.Lazy=y,A.Memo=m,A.Portal=n,A.Profiler=a,A.StrictMode=o,A.Suspense=p,A.isAsyncMode=function(e){return w(e)||x(e)===c},A.isConcurrentMode=w,A.isContextConsumer=function(e){return x(e)===s},A.isContextProvider=function(e){return x(e)===i},A.isElement=function(e){return"object"==typeof e&&null!==e&&e.$$typeof===t},A.isForwardRef=function(e){return x(e)===u},A.isFragment=function(e){return x(e)===r},A.isLazy=function(e){return x(e)===y},A.isMemo=function(e){return x(e)===m},A.isPortal=function(e){return x(e)===n},A.isProfiler=function(e){return x(e)===a},A.isStrictMode=function(e){return x(e)===o},A.isSuspense=function(e){return x(e)===p},A.isValidElementType=function(e){return"string"==typeof e||"function"==typeof e||e===r||e===l||e===a||e===o||e===p||e===f||"object"==typeof e&&null!==e&&(e.$$typeof===y||e.$$typeof===m||e.$$typeof===i||e.$$typeof===s||e.$$typeof===u||e.$$typeof===g||e.$$typeof===b||e.$$typeof===v||e.$$typeof===h)},A.typeOf=x,A}():(p||(p=1,"production"!==process.env.NODE_ENV&&function(){var e="function"==typeof Symbol&&Symbol.for,t=e?Symbol.for("react.element"):60103,n=e?Symbol.for("react.portal"):60106,r=e?Symbol.for("react.fragment"):60107,o=e?Symbol.for("react.strict_mode"):60108,a=e?Symbol.for("react.profiler"):60114,i=e?Symbol.for("react.provider"):60109,s=e?Symbol.for("react.context"):60110,c=e?Symbol.for("react.async_mode"):60111,l=e?Symbol.for("react.concurrent_mode"):60111,u=e?Symbol.for("react.forward_ref"):60112,d=e?Symbol.for("react.suspense"):60113,p=e?Symbol.for("react.suspense_list"):60120,f=e?Symbol.for("react.memo"):60115,m=e?Symbol.for("react.lazy"):60116,y=e?Symbol.for("react.block"):60121,h=e?Symbol.for("react.fundamental"):60117,g=e?Symbol.for("react.responder"):60118,b=e?Symbol.for("react.scope"):60119;function v(e){if("object"==typeof e&&null!==e){var p=e.$$typeof;switch(p){case t:var y=e.type;switch(y){case c:case l:case r:case a:case o:case d:return y;default:var h=y&&y.$$typeof;switch(h){case s:case u:case m:case f:case i:return h;default:return p}}case n:return p}}}var x=l,w=s,S=i,E=t,C=u,j=r,k=m,P=f,_=n,A=a,T=o,I=d,N=!1;function M(e){return v(e)===l}O.AsyncMode=c,O.ConcurrentMode=x,O.ContextConsumer=w,O.ContextProvider=S,O.Element=E,O.ForwardRef=C,O.Fragment=j,O.Lazy=k,O.Memo=P,O.Portal=_,O.Profiler=A,O.StrictMode=T,O.Suspense=I,O.isAsyncMode=function(e){return N||(N=!0,console.warn("The ReactIs.isAsyncMode() alias has been deprecated, and will be removed in React 17+. Update your code to use ReactIs.isConcurrentMode() instead. It has the exact same API.")),M(e)||v(e)===c},O.isConcurrentMode=M,O.isContextConsumer=function(e){return v(e)===s},O.isContextProvider=function(e){return v(e)===i},O.isElement=function(e){return"object"==typeof e&&null!==e&&e.$$typeof===t},O.isForwardRef=function(e){return v(e)===u},O.isFragment=function(e){return v(e)===r},O.isLazy=function(e){return v(e)===m},O.isMemo=function(e){return v(e)===f},O.isPortal=function(e){return v(e)===n},O.isProfiler=function(e){return v(e)===a},O.isStrictMode=function(e){return v(e)===o},O.isSuspense=function(e){return v(e)===d},O.isValidElementType=function(e){return"string"==typeof e||"function"==typeof e||e===r||e===l||e===a||e===o||e===d||e===p||"object"==typeof e&&null!==e&&(e.$$typeof===m||e.$$typeof===f||e.$$typeof===i||e.$$typeof===s||e.$$typeof===u||e.$$typeof===h||e.$$typeof===g||e.$$typeof===b||e.$$typeof===y)},O.typeOf=v}()),O)),_.exports}function I(){return g?h:(g=1,h="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}function N(){return v?b:(v=1,b=Function.call.bind(Object.prototype.hasOwnProperty))}function M(){if(w)return x;w=1;var e=function(){};if("production"!==process.env.NODE_ENV){var t=I(),n={},r=N();e=function(e){var t="Warning: "+e;"undefined"!=typeof console&&console.error(t);try{throw new Error(t)}catch(e){}}}function o(o,a,i,s,c){if("production"!==process.env.NODE_ENV)for(var l in o)if(r(o,l)){var u;try{if("function"!=typeof o[l]){var d=Error((s||"React class")+": "+i+" type `"+l+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof o[l]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw d.name="Invariant Violation",d}u=o[l](a,l,s,i,null,t)}catch(e){u=e}if(!u||u instanceof Error||e((s||"React class")+": type specification of "+i+" `"+l+"` is invalid; the type checker function must return `null` or an `Error` but returned a "+typeof u+". You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument)."),u instanceof Error&&!(u.message in n)){n[u.message]=!0;var p=c?c():"";e("Failed "+i+" type: "+u.message+(null!=p?p:""))}}}return o.resetWarningCache=function(){"production"!==process.env.NODE_ENV&&(n={})},x=o}function R(){if(E)return S;E=1;var e=T(),t=function(){if(y)return m;y=1;var e=Object.getOwnPropertySymbols,t=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable;return m=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},n=0;n<10;n++)t["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(t).map(function(e){return t[e]}).join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach(function(e){r[e]=e}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(e){return!1}}()?Object.assign:function(r,o){for(var a,i,s=function(e){if(null==e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}(r),c=1;c<arguments.length;c++){for(var l in a=Object(arguments[c]))t.call(a,l)&&(s[l]=a[l]);if(e){i=e(a);for(var u=0;u<i.length;u++)n.call(a,i[u])&&(s[i[u]]=a[i[u]])}}return s},m}(),n=I(),r=N(),o=M(),a=function(){};function i(){return null}return"production"!==process.env.NODE_ENV&&(a=function(e){var t="Warning: "+e;"undefined"!=typeof console&&console.error(t);try{throw new Error(t)}catch(e){}}),S=function(s,c){var l="function"==typeof Symbol&&Symbol.iterator,u="<<anonymous>>",d={array:y("array"),bigint:y("bigint"),bool:y("boolean"),func:y("function"),number:y("number"),object:y("object"),string:y("string"),symbol:y("symbol"),any:m(i),arrayOf:function(e){return m(function(t,r,o,a,i){if("function"!=typeof e)return new f("Property `"+i+"` of component `"+o+"` has invalid PropType notation inside arrayOf.");var s=t[r];if(!Array.isArray(s))return new f("Invalid "+a+" `"+i+"` of type `"+b(s)+"` supplied to `"+o+"`, expected an array.");for(var c=0;c<s.length;c++){var l=e(s,c,o,a,i+"["+c+"]",n);if(l instanceof Error)return l}return null})},element:m(function(e,t,n,r,o){var a=e[t];return s(a)?null:new f("Invalid "+r+" `"+o+"` of type `"+b(a)+"` supplied to `"+n+"`, expected a single ReactElement.")}),elementType:m(function(t,n,r,o,a){var i=t[n];return e.isValidElementType(i)?null:new f("Invalid "+o+" `"+a+"` of type `"+b(i)+"` supplied to `"+r+"`, expected a single ReactElement type.")}),instanceOf:function(e){return m(function(t,n,r,o,a){return t[n]instanceof e?null:new f("Invalid "+o+" `"+a+"` of type `"+((i=t[n]).constructor&&i.constructor.name?i.constructor.name:u)+"` supplied to `"+r+"`, expected instance of `"+(e.name||u)+"`.");var i})},node:m(function(e,t,n,r,o){return g(e[t])?null:new f("Invalid "+r+" `"+o+"` supplied to `"+n+"`, expected a ReactNode.")}),objectOf:function(e){return m(function(t,o,a,i,s){if("function"!=typeof e)return new f("Property `"+s+"` of component `"+a+"` has invalid PropType notation inside objectOf.");var c=t[o],l=b(c);if("object"!==l)return new f("Invalid "+i+" `"+s+"` of type `"+l+"` supplied to `"+a+"`, expected an object.");for(var u in c)if(r(c,u)){var d=e(c,u,a,i,s+"."+u,n);if(d instanceof Error)return d}return null})},oneOf:function(e){return Array.isArray(e)?m(function(t,n,r,o,a){for(var i=t[n],s=0;s<e.length;s++)if(p(i,e[s]))return null;var c=JSON.stringify(e,function(e,t){return"symbol"===v(t)?String(t):t});return new f("Invalid "+o+" `"+a+"` of value `"+String(i)+"` supplied to `"+r+"`, expected one of "+c+".")}):("production"!==process.env.NODE_ENV&&a(arguments.length>1?"Invalid arguments supplied to oneOf, expected an array, got "+arguments.length+" arguments. A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z]).":"Invalid argument supplied to oneOf, expected an array."),i)},oneOfType:function(e){if(!Array.isArray(e))return"production"!==process.env.NODE_ENV&&a("Invalid argument supplied to oneOfType, expected an instance of array."),i;for(var t=0;t<e.length;t++){var o=e[t];if("function"!=typeof o)return a("Invalid argument supplied to oneOfType. Expected an array of check functions, but received "+x(o)+" at index "+t+"."),i}return m(function(t,o,a,i,s){for(var c=[],l=0;l<e.length;l++){var u=(0,e[l])(t,o,a,i,s,n);if(null==u)return null;u.data&&r(u.data,"expectedType")&&c.push(u.data.expectedType)}return new f("Invalid "+i+" `"+s+"` supplied to `"+a+"`"+(c.length>0?", expected one of type ["+c.join(", ")+"]":"")+".")})},shape:function(e){return m(function(t,r,o,a,i){var s=t[r],c=b(s);if("object"!==c)return new f("Invalid "+a+" `"+i+"` of type `"+c+"` supplied to `"+o+"`, expected `object`.");for(var l in e){var u=e[l];if("function"!=typeof u)return h(o,a,i,l,v(u));var d=u(s,l,o,a,i+"."+l,n);if(d)return d}return null})},exact:function(e){return m(function(o,a,i,s,c){var l=o[a],u=b(l);if("object"!==u)return new f("Invalid "+s+" `"+c+"` of type `"+u+"` supplied to `"+i+"`, expected `object`.");var d=t({},o[a],e);for(var p in d){var m=e[p];if(r(e,p)&&"function"!=typeof m)return h(i,s,c,p,v(m));if(!m)return new f("Invalid "+s+" `"+c+"` key `"+p+"` supplied to `"+i+"`.\nBad object: "+JSON.stringify(o[a],null," ")+"\nValid keys: "+JSON.stringify(Object.keys(e),null," "));var y=m(l,p,i,s,c+"."+p,n);if(y)return y}return null})}};function p(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t}function f(e,t){this.message=e,this.data=t&&"object"==typeof t?t:{},this.stack=""}function m(e){if("production"!==process.env.NODE_ENV)var t={},r=0;function o(o,i,s,l,d,p,m){if(l=l||u,p=p||s,m!==n){if(c){var y=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use `PropTypes.checkPropTypes()` to call them. Read more at http://fb.me/use-check-prop-types");throw y.name="Invariant Violation",y}if("production"!==process.env.NODE_ENV&&"undefined"!=typeof console){var h=l+":"+s;!t[h]&&r<3&&(a("You are manually calling a React.PropTypes validation function for the `"+p+"` prop on `"+l+"`. This is deprecated and will throw in the standalone `prop-types` package. You may be seeing this warning due to a third-party PropTypes library. See https://fb.me/react-warning-dont-call-proptypes for details."),t[h]=!0,r++)}}return null==i[s]?o?new f(null===i[s]?"The "+d+" `"+p+"` is marked as required in `"+l+"`, but its value is `null`.":"The "+d+" `"+p+"` is marked as required in `"+l+"`, but its value is `undefined`."):null:e(i,s,l,d,p)}var i=o.bind(null,!1);return i.isRequired=o.bind(null,!0),i}function y(e){return m(function(t,n,r,o,a,i){var s=t[n];return b(s)!==e?new f("Invalid "+o+" `"+a+"` of type `"+v(s)+"` supplied to `"+r+"`, expected `"+e+"`.",{expectedType:e}):null})}function h(e,t,n,r,o){return new f((e||"React class")+": "+t+" type `"+n+"."+r+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+o+"`.")}function g(e){switch(typeof e){case"number":case"string":case"undefined":return!0;case"boolean":return!e;case"object":if(Array.isArray(e))return e.every(g);if(null===e||s(e))return!0;var t=function(e){var t=e&&(l&&e[l]||e["@@iterator"]);if("function"==typeof t)return t}(e);if(!t)return!1;var n,r=t.call(e);if(t!==e.entries){for(;!(n=r.next()).done;)if(!g(n.value))return!1}else for(;!(n=r.next()).done;){var o=n.value;if(o&&!g(o[1]))return!1}return!0;default:return!1}}function b(e){var t=typeof e;return Array.isArray(e)?"array":e instanceof RegExp?"object":function(e,t){return"symbol"===e||!!t&&("Symbol"===t["@@toStringTag"]||"function"==typeof Symbol&&t instanceof Symbol)}(t,e)?"symbol":t}function v(e){if(null==e)return""+e;var t=b(e);if("object"===t){if(e instanceof Date)return"date";if(e instanceof RegExp)return"regexp"}return t}function x(e){var t=v(e);switch(t){case"array":case"object":return"an "+t;case"boolean":case"date":case"regexp":return"a "+t;default:return t}}return f.prototype=Error.prototype,d.checkPropTypes=o,d.resetWarningCache=o.resetWarningCache,d.PropTypes=d,d},S}function F(){if(j)return C;j=1;var e=I();function t(){}function n(){}return n.resetWarningCache=t,C=function(){function r(t,n,r,o,a,i){if(i!==e){var s=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw s.name="Invariant Violation",s}}function o(){return r}r.isRequired=r;var a={array:r,bigint:r,bool:r,func:r,number:r,object:r,string:r,symbol:r,any:r,arrayOf:o,element:r,elementType:r,instanceOf:o,node:r,objectOf:o,oneOf:o,oneOfType:o,shape:o,exact:o,checkPropTypes:n,resetWarningCache:t};return a.PropTypes=a,a}}function D(){if(k)return P.exports;if(k=1,"production"!==process.env.NODE_ENV){var e=T();P.exports=R()(e.isElement,!0)}else P.exports=F()();return P.exports}const $=u(D());function V(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function L(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?V(Object(n),!0).forEach(function(t){U(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):V(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function B(e){return(B="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function U(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function z(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=e&&("undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"]);if(null!=n){var r,o,a=[],i=!0,s=!1;try{for(n=n.call(e);!(i=(r=n.next()).done)&&(a.push(r.value),!t||a.length!==t);i=!0);}catch(e){s=!0,o=e}finally{try{i||null==n.return||n.return()}finally{if(s)throw o}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return q(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?q(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function q(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var Y=function(e,n,r){var o=!!r,a=t.useRef(r);t.useEffect(function(){a.current=r},[r]),t.useEffect(function(){if(!o||!e)return function(){};var t=function(){a.current&&a.current.apply(a,arguments)};return e.on(n,t),function(){e.off(n,t)}},[o,n,e,a])},W=function(e){var n=t.useRef(e);return t.useEffect(function(){n.current=e},[e]),n.current},H=function(e){return null!==e&&"object"===B(e)},J="[object Object]",G=function e(t,n){if(!H(t)||!H(n))return t===n;var r=Array.isArray(t);if(r!==Array.isArray(n))return!1;var o=Object.prototype.toString.call(t)===J;if(o!==(Object.prototype.toString.call(n)===J))return!1;if(!o&&!r)return t===n;var a=Object.keys(t),i=Object.keys(n);if(a.length!==i.length)return!1;for(var s={},c=0;c<a.length;c+=1)s[a[c]]=!0;for(var l=0;l<i.length;l+=1)s[i[l]]=!0;var u=Object.keys(s);if(u.length!==a.length)return!1;var d=t,p=n;return u.every(function(t){return e(d[t],p[t])})},K=function(e,t,n){return H(e)?Object.keys(e).reduce(function(r,o){var a=!H(t)||!G(e[o],t[o]);return n.includes(o)?(a&&console.warn("Unsupported prop change: options.".concat(o," is not a mutable property.")),r):a?L(L({},r||{}),{},U({},o,e[o])):r},null):null},X="Invalid prop `stripe` supplied to `Elements`. We recommend using the `loadStripe` utility from `@stripe/stripe-js`. See https://stripe.com/docs/stripe-js/react#elements-props-stripe for details.",Z=function(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:X;if(null===e||H(t=e)&&"function"==typeof t.elements&&"function"==typeof t.createToken&&"function"==typeof t.createPaymentMethod&&"function"==typeof t.confirmCardPayment)return e;throw new Error(n)},Q=t.createContext(null);Q.displayName="ElementsContext";var ee=function(e,t){if(!e)throw new Error("Could not find Elements context; You need to wrap the part of your app that ".concat(t," in an <Elements> provider."));return e},te=function(e){var n=e.stripe,r=e.options,o=e.children,a=t.useMemo(function(){return function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:X;if(function(e){return H(e)&&"function"==typeof e.then}(e))return{tag:"async",stripePromise:Promise.resolve(e).then(function(e){return Z(e,t)})};var n=Z(e,t);return null===n?{tag:"empty"}:{tag:"sync",stripe:n}}(n)},[n]),i=z(t.useState(function(){return{stripe:"sync"===a.tag?a.stripe:null,elements:"sync"===a.tag?a.stripe.elements(r):null}}),2),s=i[0],c=i[1];t.useEffect(function(){var e=!0,t=function(e){c(function(t){return t.stripe?t:{stripe:e,elements:e.elements(r)}})};return"async"!==a.tag||s.stripe?"sync"!==a.tag||s.stripe||t(a.stripe):a.stripePromise.then(function(n){n&&e&&t(n)}),function(){e=!1}},[a,s,r]);var l=W(n);t.useEffect(function(){null!==l&&l!==n&&console.warn("Unsupported prop change on Elements: You cannot change the `stripe` prop after setting it.")},[l,n]);var u=W(r);return t.useEffect(function(){if(s.elements){var e=K(r,u,["clientSecret","fonts"]);e&&s.elements.update(e)}},[r,u,s.elements]),t.useEffect(function(){var e;(e=s.stripe)&&e._registerWrapper&&e.registerAppInfo&&(e._registerWrapper({name:"react-stripe-js",version:"3.10.0"}),e.registerAppInfo({name:"react-stripe-js",version:"3.10.0",url:"https://stripe.com/docs/stripe-js/react"}))},[s.stripe]),t.createElement(Q.Provider,{value:s},o)};te.propTypes={stripe:$.any,options:$.object};var ne=t.createContext(null);ne.displayName="CheckoutSdkContext",t.createContext(null).displayName="CheckoutContext",$.shape({fetchClientSecret:$.func.isRequired,elementsOptions:$.object});var re=function(e){var n=t.useContext(ne),r=t.useContext(Q);if(n&&r)throw new Error("You cannot wrap the part of your app that ".concat(e," in both <CheckoutProvider> and <Elements> providers."));return n?function(e,t){if(!e)throw new Error("Could not find CheckoutProvider context; You need to wrap the part of your app that ".concat(t," in an <CheckoutProvider> provider."));return e}(n,e):ee(r,e)},oe=["mode"],ae=function(e,n){var r,o="".concat((r=e).charAt(0).toUpperCase()+r.slice(1),"Element"),a=n?function(e){return re("mounts <".concat(o,">")),t.createElement("div",{id:e.id,className:e.className})}:function(n){var r,a=n.id,i=n.className,s=n.options,c=void 0===s?{}:s,l=n.onBlur,u=n.onFocus,d=n.onReady,p=n.onChange,f=n.onEscape,m=n.onClick,y=n.onLoadError,h=n.onLoaderStart,g=n.onNetworksChange,b=n.onConfirm,v=n.onCancel,x=n.onShippingAddressChange,w=n.onShippingRateChange,S=n.onSavedPaymentMethodRemove,E=n.onSavedPaymentMethodUpdate,C=re("mounts <".concat(o,">")),j="elements"in C?C.elements:null,k="checkoutSdk"in C?C.checkoutSdk:null,P=z(t.useState(null),2),_=P[0],A=P[1],O=t.useRef(null),T=t.useRef(null);Y(_,"blur",l),Y(_,"focus",u),Y(_,"escape",f),Y(_,"click",m),Y(_,"loaderror",y),Y(_,"loaderstart",h),Y(_,"networkschange",g),Y(_,"confirm",b),Y(_,"cancel",v),Y(_,"shippingaddresschange",x),Y(_,"shippingratechange",w),Y(_,"savedpaymentmethodremove",S),Y(_,"savedpaymentmethodupdate",E),Y(_,"change",p),d&&(r="expressCheckout"===e?d:function(){d(_)}),Y(_,"ready",r),t.useLayoutEffect(function(){if(null===O.current&&null!==T.current&&(j||k)){var t=null;if(k)switch(e){case"payment":t=k.createPaymentElement(c);break;case"address":if(!("mode"in c))throw new Error("You must supply options.mode. mode must be 'billing' or 'shipping'.");var n=c.mode,r=function(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},a=Object.keys(e);for(r=0;r<a.length;r++)t.indexOf(n=a[r])>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)t.indexOf(n=a[r])>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}(c,oe);if("shipping"===n)t=k.createShippingAddressElement(r);else{if("billing"!==n)throw new Error("Invalid options.mode. mode must be 'billing' or 'shipping'.");t=k.createBillingAddressElement(r)}break;case"expressCheckout":t=k.createExpressCheckoutElement(c);break;case"currencySelector":t=k.createCurrencySelectorElement();break;case"taxId":t=k.createTaxIdElement(c);break;default:throw new Error("Invalid Element type ".concat(o,". You must use either the <PaymentElement />, <AddressElement options={{mode: 'shipping'}} />, <AddressElement options={{mode: 'billing'}} />, or <ExpressCheckoutElement />."))}else j&&(t=j.create(e,c));O.current=t,A(t),t&&t.mount(T.current)}},[j,k,c]);var I=W(c);return t.useEffect(function(){if(O.current){var e=K(c,I,["paymentRequest"]);e&&"update"in O.current&&O.current.update(e)}},[c,I]),t.useLayoutEffect(function(){return function(){if(O.current&&"function"==typeof O.current.destroy)try{O.current.destroy(),O.current=null}catch(e){}}},[]),t.createElement("div",{id:a,className:i,ref:T})};return a.propTypes={id:$.string,className:$.string,onChange:$.func,onBlur:$.func,onFocus:$.func,onReady:$.func,onEscape:$.func,onClick:$.func,onLoadError:$.func,onLoaderStart:$.func,onNetworksChange:$.func,onConfirm:$.func,onCancel:$.func,onShippingAddressChange:$.func,onShippingRateChange:$.func,onSavedPaymentMethodRemove:$.func,onSavedPaymentMethodUpdate:$.func,options:$.object},a.displayName=o,a.__elementType=e,a},ie="undefined"==typeof window;t.createContext(null).displayName="EmbeddedCheckoutProviderContext",ae("auBankAccount",ie),ae("card",ie),ae("cardNumber",ie),ae("cardExpiry",ie),ae("cardCvc",ie),ae("fpxBank",ie),ae("iban",ie),ae("idealBank",ie),ae("p24Bank",ie),ae("epsBank",ie);var se=ae("payment",ie);ae("expressCheckout",ie),ae("currencySelector",ie),ae("paymentRequestButton",ie),ae("linkAuthentication",ie),ae("address",ie),ae("shippingAddress",ie),ae("paymentMethodMessaging",ie),ae("affirmMessage",ie),ae("afterpayClearpayMessage",ie),ae("taxId",ie);const ce=t.createContext(null),le=({onResult:n,children:r})=>{const[o,a]=t.useState(null),[i,s]=t.useState(null),c=t.useRef(n);c.current=n;const l=t.useCallback(e=>{c.current(e)},[]),u=t.useCallback(e=>{a(e)},[]),d=t.useCallback(e=>{s(e)},[]),p=t.useMemo(()=>({emitResult:l,registerConfirm:u,confirmHandle:o,reportSummary:d,summary:i}),[l,u,o,d,i]);return e.jsx(ce.Provider,{value:p,children:r})},ue=()=>{const e=t.useContext(ce);if(!e)throw new Error("Payment result channel hooks must be used inside PaymentResultChannelProvider");return e},de=()=>ue().emitResult,pe=()=>ue().registerConfirm,fe=()=>ue().reportSummary;function me(e){return(me="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var ye,he="https://js.stripe.com/v3",ge=/^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/,be="loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used",ve=function(e){var t=e&&!e.advancedFraudSignals?"?advancedFraudSignals=false":"",n=document.createElement("script");n.src="".concat(he).concat(t);var r=document.head||document.body;if(!r)throw new Error("Expected document.body not to be null. Stripe.js requires a <body> element.");return r.appendChild(n),n},xe=null,we=null,Se=null,Ee=function(e){var t="invalid load parameters; expected object of shape\n\n {advancedFraudSignals: boolean}\n\nbut received\n\n ".concat(JSON.stringify(e),"\n");if(null===e||"object"!==me(e))throw new Error(t);if(1===Object.keys(e).length&&"boolean"==typeof e.advancedFraudSignals)return e;throw new Error(t)},Ce=!1,je=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];Ce=!0;var r,o=Date.now();return(r=ye,null!==xe?xe:(xe=new Promise(function(e,t){if("undefined"!=typeof window&&"undefined"!=typeof document)if(window.Stripe&&r&&console.warn(be),window.Stripe)e(window.Stripe);else try{var n=function(){for(var e=document.querySelectorAll('script[src^="'.concat(he,'"]')),t=0;t<e.length;t++){var n=e[t];if(ge.test(n.src))return n}return null}();if(n&&r)console.warn(be);else if(n){if(n&&null!==Se&&null!==we){var o;n.removeEventListener("load",Se),n.removeEventListener("error",we),null===(o=n.parentNode)||void 0===o||o.removeChild(n),n=ve(r)}}else n=ve(r);Se=function(e,t){return function(){window.Stripe?e(window.Stripe):t(new Error("Stripe.js not available"))}}(e,t),we=function(e){return function(){e(new Error("Failed to load Stripe.js"))}}(t),n.addEventListener("load",Se),n.addEventListener("error",we)}catch(e){return void t(e)}else e(null)})).catch(function(e){return xe=null,Promise.reject(e)})).then(function(e){return function(e,t,n){if(null===e)return null;var r=e.apply(void 0,t);return function(e,t){e&&e._registerWrapper&&e._registerWrapper({name:"stripe-js",version:"4.6.0",startTime:t})}(r,n),r}(e,t,o)})};je.setLoadParameters=function(e){if(Ce&&ye){var t=Ee(e);if(Object.keys(t).reduce(function(t,n){var r;return t&&e[n]===(null===(r=ye)||void 0===r?void 0:r[n])},!0))return}if(Ce)throw new Error("You cannot change load parameters after calling loadStripe");ye=Ee(e)};const ke=t.createContext(null),Pe=({onReady:n})=>{const r=re("calls useStripe()").stripe,o=(p=t.useContext(Q),ee(p,"calls useElements()")).elements,{paymentInit:a}=an(),i=de(),s=pe(),c=fe(),[l,u]=t.useState(!1),d="stripe"===a?.provider?a.config.client_secret:null;var p;t.useEffect(()=>{if(!r||!d)return;let e=!1;return r.retrievePaymentIntent(d).then(t=>{if(e)return;const n=t.paymentIntent;n&&"number"==typeof n.amount&&n.currency&&c({amount:n.amount,currency:n.currency})}),()=>{e=!0}},[r,d,c]);const f=t.useCallback(async()=>{if(!r||!o||!d)return;u(!0);const{error:e}=await o.submit();if(e)return void u(!1);const{error:t,paymentIntent:n}=await r.confirmPayment({elements:o,clientSecret:d,confirmParams:{return_url:window.location.href},redirect:"if_required"});u(!1),t||!n||"succeeded"!==n.status&&"requires_capture"!==n.status||i({status:"success",provider:"stripe",paymentId:n.id,amount:n.amount,currency:n.currency})},[r,o,d,i]);return t.useEffect(()=>(s({confirm:f,isConfirming:l}),()=>s(null)),[f,l,s]),e.jsx(se,{options:{layout:"tabs",wallets:{applePay:"auto",googlePay:"auto"}},onReady:n})},_e={type:"stripe",label:"Stripe",ProviderWrapper:({children:n})=>{const{paymentInit:r}=an(),[o,a]=t.useState(null),i="stripe"===r?.provider?r.config.publishable_key:null;t.useEffect(()=>{i&&i.startsWith("pk_")&&a(je(i))},[i]);const s=t.useMemo(()=>({stripePromise:o}),[o]);return e.jsx(ke.Provider,{value:s,children:n})},FormComponent:({onReady:o})=>{const{themeStyles:a,theme:i}=r.useBranding(),{stripePromise:s}=(()=>{const e=t.useContext(ke);if(!e)throw new Error("Stripe adapter components must be used inside StripeProviderWrapper");return e})(),{paymentInit:c}=an(),l=t.useMemo(()=>n.buildBrandSkin(a,i),[a,i]),u=t.useMemo(()=>function(e,t,n){return{theme:"dark"===t?"night":"stripe",variables:{colorPrimary:e.statusDiscovery.solid,colorBackground:n.cardBg,colorText:n.text,colorDanger:"#df1b41",fontFamily:n.fontFamily,borderRadius:`${n.radius}px`,spacingUnit:"3px",fontSizeBase:"16px"}}}(a,i,l),[a,i,l]),d="stripe"===c?.provider?c.config.client_secret:null,p=t.useMemo(()=>d?{clientSecret:d,appearance:u}:null,[d,u]);return s&&p?e.jsx(te,{stripe:s,options:p,children:e.jsx(Pe,{onReady:o})},d):null}};function Ae(e){const t={};if(e.config.metadata)for(const[n,r]of Object.entries(e.config.metadata))null!=r&&(t[n]=String(r));if(e.config.customer){const{name:n,email:r,phone:o,reference_id:a}=e.config.customer;n&&(t.customer_name=n),r&&(t.customer_email=r),o&&(t.customer_phone=o),a&&(t.customer_reference_id=a)}return t}class Oe extends Error{constructor(e,t,n){super(e),this.status=t,this.body=n,this.name="MoyasarApiError"}}async function Te(e){const t=await Ie("https://api.moyasar.com/v1/payments",e);if(!t.ok)throw new Oe(Ne(t.body)??`Payment creation failed (${t.status})`,t.status,t.body);const n=t.body;if(!n||"string"!=typeof n.id||"string"!=typeof n.status)throw new Oe("Payment creation returned no id/status",t.status,n);return n}async function Ie(e,t){const n=new AbortController,r=setTimeout(()=>n.abort(new DOMException("Request timed out","TimeoutError")),3e4);let o;try{o=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),signal:n.signal})}catch(e){const t=e instanceof DOMException&&"TimeoutError"===e.name?"Payment request timed out — please try again.":e instanceof Error?e.message:"Network request failed";throw new Oe(t)}finally{clearTimeout(r)}let a=null;try{a=await o.json()}catch{a=null}return{ok:o.ok,status:o.status,body:a}}function Ne(e){if(!e||"object"!=typeof e)return null;if("string"==typeof e.message&&e.message.length>0)return e.message;if(e.errors&&"object"==typeof e.errors){const t=e.errors;for(const[e,n]of Object.entries(t)){if(Array.isArray(n)&&"string"==typeof n[0])return`${Me(e)}: ${n[0]}`;if("string"==typeof n)return`${Me(e)}: ${n}`}}return null}function Me(e){return e.replace(/_/g," ")}const Re=({url:r,onResult:o,skin:a})=>{const i=t.useRef(o);i.current=o;const s=t.useRef(!1),[c,l]=t.useState(!1),u=t.useRef(!1),d=t.useCallback(e=>{s.current||(s.current=!0,i.current({status:"failure",provider:"moyasar",message:e}))},[]);return t.useEffect(()=>{const e=window.location.origin,t=t=>{if(t.origin!==e)return;if(s.current)return;if(!(r=t.data)||"object"!=typeof r||"moyasar-iframe-callback"!==r.type||"string"!=typeof r.search)return;var r;const o=n.parseMoyasarCallbackFromUrl(t.data.search);o&&(s.current=!0,i.current(o.result))};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[]),t.useEffect(()=>{const e=setTimeout(()=>{u.current||d("3D Secure challenge failed to load")},6e4);return()=>clearTimeout(e)},[d]),e.jsxs("div",{className:"absolute inset-0 z-[105]",style:{background:a.cardBg},role:"dialog","aria-label":"3D Secure authentication",children:[!c&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center text-sm",style:{color:a.muted,fontFamily:a.fontFamily},children:"Loading…"}),e.jsx("iframe",{src:r,title:"3D Secure",className:"w-full h-full",style:{border:0,background:"white"},onLoad:()=>{u.current=!0,l(!0)},onError:()=>{d("3D Secure challenge failed to load")},allow:"payment *",sandbox:"allow-scripts allow-forms allow-same-origin allow-popups allow-top-navigation-by-user-activation",referrerPolicy:"no-referrer"})]})},Fe=["mada","visa","masterCard"],De="data-aiatcore-apple-pay",$e=({skin:o})=>{const{paymentInit:a}=an(),i=a&&"moyasar"===a.provider?a:null,s=de(),[c,l]=t.useState(null),u=t.useRef(s);u.current=s,t.useEffect(()=>{!function(){if("undefined"==typeof document)return;if(document.querySelector(`style[${De}]`))return;const e=document.createElement("style");e.setAttribute(De,"true"),e.textContent="\n .aiatcore-apple-pay-button {\n -webkit-appearance: -apple-pay-button;\n -apple-pay-button-type: pay;\n -apple-pay-button-style: black;\n width: 100%;\n cursor: pointer;\n border: none;\n padding: 0;\n margin: 0;\n }\n ",document.head.appendChild(e)}()},[]);const d=t.useCallback(()=>{if(!i)return;const e=window.ApplePaySession;if(!e)return void r.showErrorToast("Apple Pay is not available on this device.");const t=i.config.apple_pay?.label??i.config.description??"Payment",o=i.config.apple_pay?.country??"SA",a=i.config.currency.toUpperCase(),c=(i.config.amount/100).toFixed(2),u={countryCode:o,currencyCode:a,supportedNetworks:Fe,merchantCapabilities:["supports3DS","supportsDebit","supportsCredit"],total:{label:t,amount:c}};let d;try{d=new e(5,u)}catch(e){return void r.showErrorToast(e instanceof Error?e.message:"Failed to start Apple Pay")}d.onvalidatemerchant=async e=>{try{const n=await async function(e){const t={validation_url:e.validationUrl,display_name:e.displayName,domain_name:e.domainName??window.location.hostname,publishable_api_key:e.publishableApiKey},n=new AbortController,r=setTimeout(()=>n.abort(new DOMException("Request timed out","TimeoutError")),3e4);let o;try{o=await fetch("https://api.moyasar.com/v1/applepay/initiate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),signal:n.signal})}catch(e){const t=e instanceof DOMException&&"TimeoutError"===e.name?"Apple Pay merchant validation timed out — please try again.":e instanceof Error?e.message:"Network request failed";throw new Oe(t)}finally{clearTimeout(r)}let a=null;try{a=await o.json()}catch{a=null}if(!o.ok)throw new Oe(function(e){return e&&"object"==typeof e&&"string"==typeof e.message&&e.message.length>0?e.message:null}(a)??`Apple Pay merchant validation failed (${o.status})`,o.status,a);return a}({validationUrl:e.validationURL,displayName:t,publishableApiKey:i.config.publishable_key});d.completeMerchantValidation(n)}catch(e){const t=e instanceof Error?e.message:"Merchant validation failed";d.abort(),s({status:"failure",provider:"moyasar",message:t,paymentId:i.config.given_id})}},d.onpaymentauthorized=async t=>{try{const r=Ae(i),o=await Te({publishable_api_key:i.config.publishable_key,given_id:i.config.given_id,amount:i.config.amount,currency:a,description:i.config.description,callback_url:n.buildCallbackUrl(i.config.given_id),source:{type:"applepay",token:t.payment.token},...Object.keys(r).length>0?{metadata:r}:{}}),c=o.source?.transaction_url??o.transaction_url;if(c)return d.completePayment({status:e.STATUS_SUCCESS}),void l(c);const u=o.status;if("paid"===u||"authorized"===u||"captured"===u)d.completePayment({status:e.STATUS_SUCCESS}),s({status:"success",provider:"moyasar",paymentId:o.id,amount:o.amount,currency:o.currency});else if("failed"===u){const t=o.source?.message??"Payment failed";d.completePayment({status:e.STATUS_FAILURE}),s({status:"failure",provider:"moyasar",code:"failed",message:t,paymentId:o.id})}else{const t=`Unexpected payment status: ${u}`;d.completePayment({status:e.STATUS_FAILURE}),s({status:"failure",provider:"moyasar",code:u,message:t,paymentId:o.id})}}catch(t){const n=t instanceof Oe||t instanceof Error?t.message:"Payment failed";d.completePayment({status:e.STATUS_FAILURE}),s({status:"failure",provider:"moyasar",message:n,paymentId:i.config.given_id})}},d.oncancel=()=>{};try{d.begin()}catch(e){r.showErrorToast(e instanceof Error?e.message:"Failed to start Apple Pay")}},[i,s]);return i?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:d,className:"aiatcore-apple-pay-button",style:{borderRadius:o.radius,height:44},"aria-label":"Pay with Apple Pay"}),c&&e.jsx(Re,{url:c,skin:o,onResult:e=>{l(null),u.current(e)}})]}):null};var Ve,Le,Be,Ue={},ze={};function qe(){return Be||(Be=1,Object.defineProperty(ze,"__esModule",{value:!0}),ze.clone=function(e){return e?JSON.parse(JSON.stringify(e)):null}),ze}var Ye,We,He,Je,Ge,Ke,Xe={},Ze={},Qe={};function et(){if(Ke)return Ge;Ke=1;var e=Ge&&Ge.__assign||function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)},t=Le?Ve:(Le=1,Ve={visa:{niceType:"Visa",type:"visa",patterns:[4],gaps:[4,8,12],lengths:[16,18,19],code:{name:"CVV",size:3}},mastercard:{niceType:"Mastercard",type:"mastercard",patterns:[[51,55],[2221,2229],[223,229],[23,26],[270,271],2720],gaps:[4,8,12],lengths:[16],code:{name:"CVC",size:3}},"american-express":{niceType:"American Express",type:"american-express",patterns:[34,37],gaps:[4,10],lengths:[15],code:{name:"CID",size:4}},"diners-club":{niceType:"Diners Club",type:"diners-club",patterns:[[300,305],36,38,39],gaps:[4,10],lengths:[14,16,19],code:{name:"CVV",size:3}},discover:{niceType:"Discover",type:"discover",patterns:[6011,[644,649],65],gaps:[4,8,12],lengths:[16,19],code:{name:"CID",size:3}},jcb:{niceType:"JCB",type:"jcb",patterns:[2131,1800,[3528,3589]],gaps:[4,8,12],lengths:[16,17,18,19],code:{name:"CVV",size:3}},unionpay:{niceType:"UnionPay",type:"unionpay",patterns:[620,[62100,62182],[62184,62187],[62185,62197],[62200,62205],[622010,622999],622018,[62207,62209],[623,626],6270,6272,6276,[627700,627779],[627781,627799],[6282,6289],6291,6292,810,[8110,8131],[8132,8151],[8152,8163],[8164,8171]],gaps:[4,8,12],lengths:[14,15,16,17,18,19],code:{name:"CVN",size:3}},maestro:{niceType:"Maestro",type:"maestro",patterns:[493698,[5e5,504174],[504176,506698],[506779,508999],[56,59],63,67,6],gaps:[4,8,12],lengths:[12,13,14,15,16,17,18,19],code:{name:"CVC",size:3}},elo:{niceType:"Elo",type:"elo",patterns:[401178,401179,438935,457631,457632,431274,451416,457393,504175,[506699,506778],[509e3,509999],627780,636297,636368,[650031,650033],[650035,650051],[650405,650439],[650485,650538],[650541,650598],[650700,650718],[650720,650727],[650901,650978],[651652,651679],[655e3,655019],[655021,655058]],gaps:[4,8,12],lengths:[16],code:{name:"CVE",size:3}},mir:{niceType:"Mir",type:"mir",patterns:[[2200,2204]],gaps:[4,8,12],lengths:[16,17,18,19],code:{name:"CVP2",size:3}},hiper:{niceType:"Hiper",type:"hiper",patterns:[637095,63737423,63743358,637568,637599,637609,637612],gaps:[4,8,12],lengths:[16],code:{name:"CVC",size:3}},hipercard:{niceType:"Hipercard",type:"hipercard",patterns:[606282],gaps:[4,8,12],lengths:[16],code:{name:"CVC",size:3}},verve:{niceType:"Verve",type:"verve",patterns:[[506099,506127],506129,[506133,506150],[506158,506163],506166,506168,506170,506173,[506176,506180],506184,[506187,506188],506191,506195,506197,507865,507866,[507868,507877],[507880,507888],507900,507941],gaps:[4,8,12],lengths:[16,18,19],code:{name:"CVV",size:3}}}),n=function(){if(We)return Ue;We=1,Object.defineProperty(Ue,"__esModule",{value:!0}),Ue.addMatchingCardsToResults=function(n,r,o){var a,i;for(a=0;a<r.patterns.length;a++){var s=r.patterns[a];if((0,t.matches)(n,s)){var c=(0,e.clone)(r);i=Array.isArray(s)?String(s[0]).length:String(s).length,n.length>=i&&(c.matchStrength=i),o.push(c);break}}};var e=qe(),t=(Ye||(Ye=1,Object.defineProperty(Xe,"__esModule",{value:!0}),Xe.matches=function(e,t){return Array.isArray(t)?function(e,t,n){var r=String(t).length,o=e.substr(0,r),a=parseInt(o,10);return t=parseInt(String(t).substr(0,o.length),10),n=parseInt(String(n).substr(0,o.length),10),a>=t&&a<=n}(e,t[0],t[1]):function(e,t){return(t=String(t)).substring(0,e.length)===e.substring(0,t.length)}(e,t)}),Xe);return Ue}(),r=(He||(He=1,Object.defineProperty(Ze,"__esModule",{value:!0}),Ze.isValidInputType=function(e){return"string"==typeof e||e instanceof String}),Ze),o=(Je||(Je=1,Object.defineProperty(Qe,"__esModule",{value:!0}),Qe.findBestMatch=function(e){return function(e){var t=e.filter(function(e){return e.matchStrength}).length;return t>0&&t===e.length}(e)?e.reduce(function(e,t){return e?Number(e.matchStrength)<Number(t.matchStrength)?t:e:t}):null}),Qe),a=qe(),i={},s={VISA:"visa",MASTERCARD:"mastercard",AMERICAN_EXPRESS:"american-express",DINERS_CLUB:"diners-club",DISCOVER:"discover",JCB:"jcb",UNIONPAY:"unionpay",VERVE:"verve",MAESTRO:"maestro",ELO:"elo",MIR:"mir",HIPER:"hiper",HIPERCARD:"hipercard"},c=[s.VISA,s.MASTERCARD,s.AMERICAN_EXPRESS,s.DINERS_CLUB,s.DISCOVER,s.JCB,s.UNIONPAY,s.VERVE,s.MAESTRO,s.ELO,s.MIR,s.HIPER,s.HIPERCARD],l=(0,a.clone)(c);function u(e){return i[e]||t[e]}function d(e,t){void 0===t&&(t=!1);var n=l.indexOf(e);if(!t&&-1===n)throw new Error('"'+e+'" is not a supported card type.');return n}function p(e){var t=[];if(!(0,r.isValidInputType)(e))return t;if(0===e.length)return l.map(function(e){return(0,a.clone)(u(e))});l.forEach(function(r){var o=u(r);(0,n.addMatchingCardsToResults)(e,o,t)});var i=(0,o.findBestMatch)(t);return i?[i]:t}return p.getTypeInfo=function(e){return(0,a.clone)(u(e))},p.removeCard=function(e){var t=d(e);l.splice(t,1)},p.addCard=function(e){var t=d(e.type,!0);i[e.type]=e,-1===t&&l.push(e.type)},p.updateCard=function(n,r){var o=i[n]||t[n];if(!o)throw new Error('"'.concat(n,"\" is not a recognized type. Use `addCard` instead.'"));if(r.type&&o.type!==r.type)throw new Error("Cannot overwrite type parameter.");var s=(0,a.clone)(o);s=e(e({},s),r),i[s.type]=s},p.changeOrder=function(e,t){var n=d(e);l.splice(n,1),l.splice(t,0,e)},p.resetModifications=function(){l=(0,a.clone)(c),i={}},p.types=s,Ge=p}var tt,nt,rt,ot,at,it={},st={},ct={},lt={},ut={};function dt(){if(at)return ut;at=1,Object.defineProperty(ut,"__esModule",{value:!0}),ut.expirationYear=function(n,r){var o;if(void 0===r&&(r=e),"string"!=typeof n)return t(!1,!1);if(""===n.replace(/\s/g,""))return t(!1,!0);if(!/^\d*$/.test(n))return t(!1,!1);var a=n.length;if(a<2)return t(!1,!0);var i=(new Date).getFullYear();if(3===a)return t(!1,n.slice(0,2)===String(i).slice(0,2));if(a>4)return t(!1,!1);var s=parseInt(n,10),c=Number(String(i).substr(2,2)),l=!1;if(2===a){if(String(i).substr(0,2)===n)return t(!1,!0);o=c===s,l=s>=c&&s<=c+r}else 4===a&&(o=i===s,l=s>=i&&s<=i+r);return t(l,l,o)};var e=19;function t(e,t,n){return{isValid:e,isPotentiallyValid:t,isCurrentYear:n||!1}}return ut}var pt,ft,mt,yt,ht={},gt={};function bt(){if(mt)return gt;function e(e,t,n){return{isValid:e,isPotentiallyValid:t,isValidForThisYear:n||!1}}return mt=1,Object.defineProperty(gt,"__esModule",{value:!0}),gt.expirationMonth=function(t){var n=(new Date).getMonth()+1;if("string"!=typeof t)return e(!1,!1);if(""===t.replace(/\s/g,"")||"0"===t)return e(!1,!0);if(!/^\d*$/.test(t))return e(!1,!1);var r=parseInt(t,10);if(isNaN(Number(t)))return e(!1,!1);var o=r>0&&r<13;return e(o,o,o&&r>=n)},gt}var vt,xt,wt,St,Et={},Ct={};const jt=u(function(){if(St)return wt;St=1;var e=wt&&wt.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),t=wt&&wt.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),n=(wt&&wt.__importStar||function(){var n=function(e){return(n=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n);return t})(e)};return function(r){if(r&&r.__esModule)return r;var o={};if(null!=r)for(var a=n(r),i=0;i<a.length;i++)"default"!==a[i]&&e(o,r,a[i]);return t(o,r),o}}())(et()),r=function(){if(tt)return it;tt=1,Object.defineProperty(it,"__esModule",{value:!0}),it.cardholderName=function(r){return"string"!=typeof r?n(!1,!1):0===r.length?n(!1,!0):r.length>t?n(!1,!1):e.test(r)?n(!1,!0):n(!0,!0)};var e=/^[\d\s-]*$/,t=255;function n(e,t){return{isValid:e,isPotentiallyValid:t}}return it}(),o=function(){if(ot)return st;ot=1,Object.defineProperty(st,"__esModule",{value:!0}),st.cardNumber=function(r,o){var a,i;if(void 0===o&&(o={}),"string"!=typeof r&&"number"!=typeof r)return n(null,!1,!1);var s=String(r).replace(/-|\s/g,"");if(!/^\d*$/.test(s))return n(null,!1,!1);var c=t(s);if(0===c.length)return n(null,!1,!1);if(1!==c.length)return n(null,!0,!1);var l=c[0];if(o.maxLength&&s.length>o.maxLength)return n(l,!1,!1);a=!0===o.skipLuhnValidation||l.type===t.types.UNIONPAY&&!0!==o.luhnValidateUnionPay||e(s),i=Math.max.apply(null,l.lengths),o.maxLength&&(i=Math.min(o.maxLength,i));for(var u=0;u<l.lengths.length;u++)if(l.lengths[u]===s.length)return n(l,s.length<i||a,a);return n(l,s.length<i,!1)};var e=rt?nt:(rt=1,nt=function(e){for(var t,n=0,r=!1,o=e.length-1;o>=0;)t=parseInt(e.charAt(o),10),r&&(t*=2)>9&&(t=t%10+1),r=!r,n+=t,o--;return n%10==0}),t=et();function n(e,t,n){return{card:e,isPotentiallyValid:t,isValid:n}}return st}(),a=function(){if(yt)return ct;yt=1;var e=ct&&ct.__assign||function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)};Object.defineProperty(ct,"__esModule",{value:!0}),ct.expirationDate=function(a,i){var s;if("string"==typeof a)a=a.replace(/^(\d\d) (\d\d(\d\d)?)$/,"$1/$2"),s=(0,t.parseDate)(String(a));else{if(null===a||"object"!=typeof a)return o(!1,!1,null,null);var c=e({},a);s={month:String(c.month),year:String(c.year)}}var l=(0,n.expirationMonth)(s.month),u=(0,r.expirationYear)(s.year,i);if(l.isValid){if(u.isCurrentYear){var d=l.isValidForThisYear;return o(d,d,s.month,s.year)}if(u.isValid)return o(!0,!0,s.month,s.year)}return o(!1,!(!l.isPotentiallyValid||!u.isPotentiallyValid),null,null)};var t=function(){if(ft)return lt;ft=1,Object.defineProperty(lt,"__esModule",{value:!0}),lt.parseDate=function(n){var r;if(/^\d{4}-\d{1,2}$/.test(n)?r=n.split("-").reverse():/\//.test(n)?r=n.split(/\s*\/\s*/g):/\s/.test(n)&&(r=n.split(/ +/g)),(0,t.isArray)(r))return{month:r[0]||"",year:r.slice(1).join()};var o,a,i,s=(o=n,0===(i=Number(o[0]))?2:i>1||1===i&&Number(o[1])>2?1:1===i?(a=o.substr(1),(0,e.expirationYear)(a).isPotentiallyValid?1:2):5===o.length?1:o.length>5?2:1),c=n.substr(0,s);return{month:c,year:n.substr(c.length)}};var e=dt(),t=(pt||(pt=1,Object.defineProperty(ht,"__esModule",{value:!0}),ht.isArray=void 0,ht.isArray=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)}),ht);return lt}(),n=bt(),r=dt();function o(e,t,n,r){return{isValid:e,isPotentiallyValid:t,month:n,year:r}}return ct}(),i=bt(),s=dt(),c=function(){if(vt)return Et;vt=1,Object.defineProperty(Et,"__esModule",{value:!0}),Et.cvv=function(n,r){return void 0===r&&(r=e),r=r instanceof Array?r:[r],"string"!=typeof n?t(!1,!1):/^\d*$/.test(n)?function(e,t){for(var n=0;n<e.length;n++)if(t===e[n])return!0;return!1}(r,n.length)?t(!0,!0):n.length<Math.min.apply(null,r)?t(!1,!0):n.length>function(t){for(var n=e,r=0;r<t.length;r++)n=t[r]>n?t[r]:n;return n}(r)?t(!1,!1):t(!0,!0):t(!1,!1)};var e=3;function t(e,t){return{isValid:e,isPotentiallyValid:t}}return Et}(),l=function(){if(xt)return Ct;xt=1,Object.defineProperty(Ct,"__esModule",{value:!0}),Ct.postalCode=function(r,o){void 0===o&&(o={});var a=o.minLength||e;return"string"!=typeof r?n(!1,!1):r.length<a?n(!1,!0):t.test(r.trim().slice(0,a))?n(!0,!0):n(!1,!0)};var e=2,t=new RegExp(/^[a-z0-9]+$/i);function n(e,t){return{isValid:e,isPotentiallyValid:t}}return Ct}();return wt={creditCardType:n,cardholderName:r.cardholderName,number:o.cardNumber,expirationDate:a.expirationDate,expirationMonth:i.expirationMonth,expirationYear:s.expirationYear,cvv:c.cvv,postalCode:l.postalCode}}()),kt=u(et());let Pt=!1;Pt||(Pt=!0,kt.addCard({niceType:"Mada",type:"mada",patterns:[440647,440795,446404,446672,419593,428331,428671,432328,440533,446393,457865,458456,462220,484783,484800,493428,504300,521076,529415,535825,536023,537767,543357,557606,558848,588845,589206],gaps:[4,8,12],lengths:[16,18,19],code:{name:"CVV",size:3}}));const _t=({brand:t,fallbackColor:n,height:r=22})=>{if(!t)return null;switch(t){case"Visa":return e.jsx(At,{height:r});case"Mastercard":return e.jsx(Ot,{height:r});case"American Express":return e.jsx(Tt,{height:r});case"Mada":return e.jsx(It,{height:r});case"Discover":return e.jsx(Nt,{height:r});case"JCB":return e.jsx(Mt,{height:r});default:return e.jsx("span",{className:"text-xs font-medium",style:{color:n},"aria-label":`Card brand: ${t}`,children:t})}},At=({height:t})=>e.jsxs("svg",{role:"img","aria-label":"Visa",viewBox:"0 0 48 16",height:t,width:48*t/16,style:{display:"block"},children:[e.jsx("rect",{width:"48",height:"16",rx:"2",fill:"#1A1F71"}),e.jsx("text",{x:"24",y:"12",textAnchor:"middle",fontFamily:"Helvetica, Arial, sans-serif",fontWeight:"900",fontSize:"11",fill:"#FFFFFF",letterSpacing:"1.4",children:"VISA"})]}),Ot=({height:t})=>e.jsxs("svg",{role:"img","aria-label":"Mastercard",viewBox:"0 0 32 20",height:t,width:32*t/20,style:{display:"block"},children:[e.jsx("circle",{cx:"12",cy:"10",r:"7",fill:"#EB001B"}),e.jsx("circle",{cx:"20",cy:"10",r:"7",fill:"#F79E1B"}),e.jsx("path",{d:"M16 4.5a7 7 0 0 1 0 11 7 7 0 0 1 0-11Z",fill:"#FF5F00","aria-hidden":"true"})]}),Tt=({height:t})=>e.jsxs("svg",{role:"img","aria-label":"American Express",viewBox:"0 0 48 16",height:t,width:48*t/16,style:{display:"block"},children:[e.jsx("rect",{width:"48",height:"16",rx:"2",fill:"#2E77BB"}),e.jsx("text",{x:"24",y:"11.5",textAnchor:"middle",fontFamily:"Helvetica, Arial, sans-serif",fontWeight:"700",fontSize:"9",fill:"#FFFFFF",letterSpacing:"0.4",children:"AMEX"})]}),It=({height:t})=>e.jsxs("svg",{role:"img","aria-label":"Mada",viewBox:"0 0 48 16",height:t,width:48*t/16,style:{display:"block"},children:[e.jsx("rect",{width:"48",height:"16",rx:"2",fill:"#84B740"}),e.jsx("text",{x:"24",y:"11.5",textAnchor:"middle",fontFamily:"Helvetica, Arial, sans-serif",fontWeight:"700",fontSize:"9",fill:"#FFFFFF",letterSpacing:"0.6",children:"mada"})]}),Nt=({height:t})=>e.jsxs("svg",{role:"img","aria-label":"Discover",viewBox:"0 0 56 16",height:t,width:56*t/16,style:{display:"block"},children:[e.jsx("rect",{width:"56",height:"16",rx:"2",fill:"#FFFFFF",stroke:"#E5E7EB"}),e.jsx("text",{x:"20",y:"11.5",textAnchor:"middle",fontFamily:"Helvetica, Arial, sans-serif",fontWeight:"700",fontSize:"8",fill:"#231F20",letterSpacing:"0.2",children:"DISCOVER"}),e.jsx("circle",{cx:"44",cy:"8",r:"4",fill:"#FF6000"})]}),Mt=({height:t})=>e.jsxs("svg",{role:"img","aria-label":"JCB",viewBox:"0 0 32 16",height:t,width:32*t/16,style:{display:"block"},children:[e.jsx("rect",{x:"0",y:"0",width:"10.66",height:"16",rx:"2",fill:"#0E4C96"}),e.jsx("rect",{x:"10.66",y:"0",width:"10.66",height:"16",fill:"#B41E25"}),e.jsx("rect",{x:"21.33",y:"0",width:"10.66",height:"16",rx:"2",fill:"#1B8A3A"}),e.jsx("text",{x:"16",y:"11",textAnchor:"middle",fontFamily:"Helvetica, Arial, sans-serif",fontWeight:"900",fontSize:"9",fill:"#FFFFFF",children:"JCB"})]}),Rt=({skin:r})=>{const{paymentInit:o}=an(),a=o&&"moyasar"===o.provider?o:null,i=de(),s=pe(),c=fe(),[l,u]=t.useState(""),[d,p]=t.useState(""),[f,m]=t.useState(""),[y,h]=t.useState(""),[g,b]=t.useState(!1),[v,x]=t.useState({}),[w,S]=t.useState(null),E=t.useRef({number:l,expiry:d,cvc:f,name:y});E.current={number:l,expiry:d,cvc:f,name:y};const C=t.useRef(i);C.current=i,t.useEffect(()=>{a&&c({amount:a.config.amount,currency:a.config.currency.toUpperCase()})},[a,c]);const j=t.useCallback(async()=>{if(!a)return;const e=function(e,t=new Date){const n=[],r=jt.number(e.number),o=e.number.replace(/\D/g,"");o?r.isValid||n.push({field:"number",message:"Invalid card number"}):n.push({field:"number",message:"Card number is required"});const a=jt.expirationDate(e.expiry);let i=null,s=null;const c=e.expiry.trim();if(c)if(a.isValid){i=Number.parseInt(a.month??"",10);const e=Number.parseInt(a.year??"",10);s=2===(a.year??"").length?e+2e3:e}else{const e=function(e){let t="",n="";if(e.includes("/")){const[r,o]=e.split("/");t=(r??"").replace(/\D/g,""),n=(o??"").replace(/\D/g,"")}else{const r=e.replace(/\D/g,"");t=r.slice(0,2),n=r.slice(2)}const r=Number.parseInt(t,10),o=Number.parseInt(n,10);return Number.isNaN(r)||Number.isNaN(o)?null:{month:r,year:2===n.length?o+2e3:o}}(c);e&&function(e,t,n){const r=n.getFullYear(),o=n.getMonth()+1;return t<r||t===r&&e<o}(e.month,e.year,t)?n.push({field:"expiry",message:"Card expired"}):n.push({field:"expiry",message:"Invalid expiry"})}else n.push({field:"expiry",message:"Expiry is required"});const l=jt.cvv(e.cvc,r.card?.code.size??[3,4]),u=e.cvc.replace(/\D/g,"");u?l.isValid||n.push({field:"cvc",message:"Invalid CVC"}):n.push({field:"cvc",message:"CVC is required"});const d=jt.cardholderName(e.name),p=e.name.trim();return p?d.isValid||n.push({field:"name",message:"Invalid cardholder name"}):n.push({field:"name",message:"Cardholder name is required"}),n.length>0||null==i||null==s?{ok:!1,errors:n}:{ok:!0,card:{number:o,month:String(i).padStart(2,"0"),year:String(s),cvc:u,name:p}}}(E.current);if(!1===e.ok){const t={};for(const n of e.errors)t[n.field]||(t[n.field]=n.message);return void x(t)}x({}),b(!0);try{const t=await async function(e){const t=await Ie("https://api.moyasar.com/v1/tokens",{...e,save_only:!0});if(!t.ok)throw new Oe(Ne(t.body)??`Tokenization failed (${t.status})`,t.status,t.body);const n=t.body;if(!n||"string"!=typeof n.id)throw new Oe("Tokenization returned no token id",t.status,n);return{id:n.id}}({publishable_api_key:a.config.publishable_key,name:e.card.name,number:e.card.number,month:e.card.month,year:e.card.year,cvc:e.card.cvc}),r=Ae(a),o=await Te({publishable_api_key:a.config.publishable_key,given_id:a.config.given_id,amount:a.config.amount,currency:a.config.currency.toUpperCase(),description:a.config.description,callback_url:n.buildCallbackUrl(a.config.given_id),source:{type:"token",token:t.id},...Object.keys(r).length>0?{metadata:r}:{}}),i=o.source?.transaction_url??o.transaction_url;if(i)return void S(i);const s=o.status;C.current("paid"===s||"authorized"===s||"captured"===s?{status:"success",provider:"moyasar",paymentId:o.id,amount:o.amount,currency:o.currency}:"failed"===s?{status:"failure",provider:"moyasar",code:"failed",message:o.source?.message??"Payment failed",paymentId:o.id}:{status:"failure",provider:"moyasar",code:s,message:`Unexpected payment status: ${s}`,paymentId:o.id})}catch(e){const t=e instanceof Oe||e instanceof Error?e.message:"Payment failed";C.current({status:"failure",provider:"moyasar",message:t,paymentId:a.config.given_id})}finally{b(!1)}},[a]);t.useEffect(()=>(s({confirm:j,isConfirming:g}),()=>s(null)),[j,g,s]);const k=t.useMemo(()=>Math.max(r.radius-4,4),[r.radius]),P=t.useMemo(()=>function(e){const t=e.replace(/\D/g,"");if(t.length<2)return null;const n=kt(t);return n[0]?.niceType??null}(l),[l]);return a?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-3",style:{fontFamily:r.fontFamily},children:[e.jsx(Dt,{label:"Card number",value:l,onChange:e=>u(e.replace(/\D/g,"").slice(0,19).replace(/(\d{4})(?=\d)/g,"$1 ")),autoComplete:"cc-number",inputMode:"numeric",placeholder:"1234 5678 9012 3456",error:v.number,skin:r,radius:k,endAdornment:P?e.jsx(_t,{brand:P,fallbackColor:r.muted}):null}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(Dt,{label:"Expiry",value:d,onChange:e=>p(function(e){const t=e.replace(/\D/g,"").slice(0,4);return t.length<=2?t:`${t.slice(0,2)}/${t.slice(2)}`}(e)),autoComplete:"cc-exp",inputMode:"numeric",placeholder:"MM / YY",error:v.expiry,skin:r,radius:k}),e.jsx(Dt,{label:"CVC",value:f,onChange:e=>m(e.replace(/\D/g,"").slice(0,4)),autoComplete:"cc-csc",inputMode:"numeric",placeholder:"123",error:v.cvc,skin:r,radius:k})]}),e.jsx(Dt,{label:"Name on card",value:y,onChange:h,autoComplete:"cc-name",inputMode:"text",placeholder:"Full name",error:v.name,skin:r,radius:k})]}),w&&e.jsx(Re,{url:w,skin:r,onResult:e=>{S(null),C.current(e)}})]}):null};function Ft(e){let t=0;for(let n=0;n<e.length;n++){const r=e.charCodeAt(n);r>=48&&r<=57&&t++}return t}const Dt=({label:n,value:r,onChange:o,placeholder:a,autoComplete:i,inputMode:s,error:c,skin:l,radius:u,endAdornment:d})=>{const p=c?"#dc2626":l.divider,f=t.useRef(null),m=t.useRef(null),y="numeric"===s;return t.useLayoutEffect(()=>{const e=m.current;if(null===e||!f.current)return;m.current=null;const t=f.current.value;let n=0,r=0;for(;r<t.length&&!(n>=e);)/\d/.test(t[r])&&n++,r++;f.current.setSelectionRange(r,r)},[r]),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"block text-xs mb-1",style:{color:l.muted},children:n}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{ref:f,type:"text",value:r,onChange:e=>{y&&(m.current=Ft(e.target.value.slice(0,e.target.selectionStart??e.target.value.length))),o(e.target.value)},onKeyDown:e=>{if(!y||"Backspace"!==e.key)return;const t=e.currentTarget,n=t.selectionStart??0;if(n!==(t.selectionEnd??0)||n<2)return;const r=t.value[n-1];if(!r||/\d/.test(r))return;e.preventDefault();const a=t.value.slice(0,n-2)+t.value.slice(n);m.current=Ft(a.slice(0,n-2)),o(a)},placeholder:a,autoComplete:i,inputMode:s,spellCheck:!1,className:"w-full py-3 px-3 outline-none text-sm transition-colors",style:{background:l.pillBg,color:l.text,border:`1px solid ${p}`,borderRadius:u,paddingRight:d?96:void 0}}),d&&e.jsx("span",{className:"absolute right-3 top-1/2 -translate-y-1/2 text-xs font-medium pointer-events-none",style:{color:l.muted},"aria-label":"Card brand",children:d})]}),c&&e.jsx("span",{className:"block mt-1 text-xs",style:{color:"#dc2626"},children:c})]})},$t=["creditcard","applepay"],Vt=({skin:t})=>e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-x-0 top-1/2",style:{borderTop:`1px solid ${t.divider}`}}),e.jsx("div",{className:"relative flex justify-center",children:e.jsx("span",{className:"px-2 text-xs uppercase tracking-wide",style:{background:t.cardBg,color:t.muted,fontFamily:t.fontFamily},children:"or"})})]}),Lt={type:"moyasar",label:"Moyasar",FormComponent:({skin:n,onReady:r})=>{const{paymentInit:o}=an(),a=o&&"moyasar"===o.provider?o:null,i=function(){const[e,n]=t.useState(!1);return t.useEffect(()=>{if("undefined"==typeof window)return;const e=window.ApplePaySession;if(e&&"function"==typeof e.canMakePayments)try{n(!0===e.canMakePayments())}catch{n(!1)}},[]),e}(),s=t.useRef(r);if(s.current=r,t.useEffect(()=>{s.current?.()},[]),!a)return null;const c=a.config.methods??$t,l=c.includes("creditcard"),u=c.includes("applepay")&&i;return e.jsxs("div",{className:"space-y-4",children:[l&&e.jsx(Rt,{skin:n}),l&&u&&e.jsx(Vt,{skin:n}),u&&e.jsx($e,{skin:n})]})}},Bt="5vh",Ut="5vw",zt="aiatcore-chargebee-modal-style",qt="aiatcore-chargebee-close-button",Yt="aiatcore-chargebee-loader",Wt="aiatcore-cb-spin",Ht='#cb-container, .cb-container, [id^="cb-modal"], [class*="cb-modal"], [class*="cb-checkout"], div[class*="cb-"][class*="overlay"]',Jt="aiatcore-chargebee-open";function Gt(){document.getElementById(qt)?.remove()}function Kt(){document.getElementById(Yt)?.remove()}const Xt={type:"chargebee",label:"Chargebee",FormComponent:({amount:e,currency:n,onReady:r})=>{const{paymentInit:o}=an(),a=de(),i=fe(),s=pe(),c=t.useRef(!1);return t.useEffect(()=>(s(null),()=>s(null)),[s]),t.useEffect(()=>{if("chargebee"!==o?.provider)return;const{site:t,hosted_page_url:s,amount:l,currency:u,expires_at:d}=o.config,p=l??e,f=u??n;null!=p&&f&&i({amount:p,currency:f}),c.current=!1;let m=!1,y=null,h=null;const g=e=>{c.current||(c.current=!0,a(e))};return r?.(),null!=d&&Date.now()>=1e3*d?(g({status:"failure",provider:"chargebee",message:"Payment link has expired. Please request a new one."}),()=>{m=!0}):(function(){const e=document.getElementById(zt)??document.createElement("style");e.id=zt,e.textContent=`\n /* Prevent horizontal page scroll only while Chargebee's overlay is mounted */\n html.${Jt}, body.${Jt} {\n overflow-x: hidden !important;\n }\n\n /* Outer Chargebee overlay container — broad selector net so we catch\n whatever wrapper Chargebee actually uses */\n #cb-container,\n .cb-container,\n [id^="cb-modal"],\n [class*="cb-modal"],\n [class*="cb-checkout"],\n div[class*="cb-"][class*="overlay"] {\n position: fixed !important;\n inset: ${Bt} max(${Ut}, calc((100vw - 1500px) / 2)) !important;\n width: auto !important;\n height: auto !important;\n max-width: none !important;\n max-height: none !important;\n margin: 0 !important;\n border-radius: 12px !important;\n box-shadow: 0 20px 60px rgba(0,0,0,0.35) !important;\n overflow: hidden !important;\n z-index: 2147483646 !important;\n pointer-events: all !important;\n }\n\n /* Inner iframe — fill the container fully and ensure it receives clicks */\n [id^="cb-frame"] {\n width: 100% !important;\n height: 100% !important;\n border: none !important;\n display: block !important;\n z-index: 2147483646 !important;\n pointer-events: all !important;\n outline: none !important;\n box-shadow: none !important;\n }\n\n @keyframes ${Wt} {\n to { transform: rotate(360deg); }\n }\n `,e.parentElement||document.head.appendChild(e),document.documentElement.classList.add(Jt),document.body.classList.add(Jt)}(),function(e){if(window.Chargebee)return Promise.resolve();const t=document.querySelector('script[src*="js.chargebee.com"]');return t?"1"===t.dataset.cbLoaded?Promise.resolve():new Promise((e,n)=>{t.addEventListener("load",()=>e()),t.addEventListener("error",()=>n(new Error("Chargebee.js failed to load")))}):new Promise((t,n)=>{const r=document.createElement("script");r.src="https://js.chargebee.com/v2/chargebee.js",r.setAttribute("data-cb-site",e),r.onload=()=>{r.dataset.cbLoaded="1",t()},r.onerror=()=>n(new Error("Chargebee.js failed to load")),document.head.appendChild(r)})}(t).then(()=>{if(m)return;let e;try{e=window.Chargebee.getInstance()??window.Chargebee.init({site:t})}catch{e=window.Chargebee.init({site:t})}e.openCheckout({hostedPage:()=>Promise.resolve({id:o.payment_id,url:s,type:"checkout_one_time",state:"created"}),success:e=>{Gt(),Kt(),g({status:"success",provider:"chargebee",paymentId:e,amount:p??void 0,currency:f??void 0})},close:()=>{Gt(),Kt(),g({status:"cancel",provider:"chargebee"})},error:e=>{Gt(),Kt(),g({status:"failure",provider:"chargebee",message:e?.message??"Payment failed"})}}),h=function(){let e=0,t=0,n=0,r=null,o=null;const a=Date.now()+5e3,i=()=>{if(m||c.current)return;const t=document.querySelector(Ht);if(t instanceof HTMLElement){const e=t.getBoundingClientRect();if(e.width>0&&e.height>0){!function(){Kt();const e=document.createElement("div");e.id=Yt,e.setAttribute("aria-live","polite"),e.setAttribute("aria-busy","true"),e.style.cssText=`\n position: fixed;\n inset: ${Bt} max(${Ut}, calc((100vw - 1500px) / 2));\n z-index: 2147483646;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n gap: 14px;\n background: #f8f8f8;\n border-radius: 12px;\n color: #6b7280;\n font: 500 14px/1.4 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;\n pointer-events: none;\n `;const t=document.createElement("div");t.style.cssText=`\n width: 32px;\n height: 32px;\n border: 2.5px solid rgba(17, 24, 39, 0.08);\n border-top-color: #6366f1;\n border-radius: 50%;\n animation: ${Wt} 0.8s linear infinite;\n `;const n=document.createElement("p");n.textContent="Loading payment…",n.style.cssText="margin: 0;",e.appendChild(t),e.appendChild(n),document.body.appendChild(e)}();const e=document.querySelector('[id^="cb-frame"]');return void(e instanceof HTMLIFrameElement&&(r=e,o=()=>{n=window.setTimeout(Kt,400)},r.addEventListener("load",o)))}}Date.now()>=a||(e=window.requestAnimationFrame(i))};return t=window.setTimeout(i,100),()=>{window.clearTimeout(t),window.clearTimeout(n),e&&window.cancelAnimationFrame(e),r&&o&&r.removeEventListener("load",o),Kt()}}(),y=function(e){let t=0,n=0;const r=Date.now()+5e3,o=()=>{if(m||c.current)return;const n=document.querySelector(Ht);if(n instanceof HTMLElement){const t=n.getBoundingClientRect();if(t.width>0&&t.height>0)return void function(e){Gt();const t=document.createElement("button");t.id=qt,t.type="button",t.setAttribute("aria-label","Close payment"),t.textContent="×",t.style.cssText=`\n position: fixed;\n top: calc(${Bt} + 12px);\n right: calc(max(${Ut}, calc((100vw - 1500px) / 2)) + 12px);\n z-index: 2147483647;\n width: 32px;\n height: 32px;\n border: 0;\n border-radius: 9999px;\n background: rgba(17, 24, 39, 0.72);\n color: #ffffff;\n font: 600 16px/1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;\n cursor: pointer;\n pointer-events: auto;\n display: flex;\n align-items: center;\n justify-content: center;\n box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);\n `,t.addEventListener("click",e),document.body.appendChild(t)}(e)}Date.now()>=r||(t=window.requestAnimationFrame(o))};return n=window.setTimeout(o,100),()=>{window.clearTimeout(n),t&&window.cancelAnimationFrame(t)}}(()=>{Gt(),Kt(),document.querySelectorAll(Ht).forEach(e=>{e instanceof HTMLElement&&(e.style.display="none")}),g({status:"cancel",provider:"chargebee"});try{e.closeAll()}catch{}})}).catch(e=>{g({status:"failure",provider:"chargebee",message:e?.message??"Failed to load payment form"})}),()=>{m=!0,y?.(),h?.(),Gt(),Kt(),document.documentElement.classList.remove(Jt),document.body.classList.remove(Jt),document.getElementById(zt)?.remove();try{window.Chargebee?.getInstance?.()?.closeAll?.()}catch{}})},[o,e,n,i,r,a]),null},hideShellSubmit:!0},Zt="atb-payment";function Qt(){const e=document.createElement("div");e.style.cssText="position:absolute;top:-9999px;width:100px;height:100px;overflow:scroll;",document.body.appendChild(e);const t=e.offsetWidth-e.clientWidth;return e.remove(),Math.max(0,t)}const en=({init:o,onResult:a,skin:i})=>{const s=t.useRef(null),c=t.useRef(!1),l=t.useRef(!1),[u,d]=t.useState(!1),[p]=t.useState(Qt),f=t.useMemo(()=>n.resolveAtbOrigin(o.config.url),[o.config.url]),m=o.payment_id,y=t.useCallback((e,t={})=>{c.current||(c.current=!0,r.logger.info({message:"[atb] outcome",api_name:Zt,reference_id:m,outcome:e}),a(n.buildAtbResult({outcome:e,init:o,...t})))},[o,m,a]),h=t.useCallback(()=>{l.current=!0,d(!0)},[]);return t.useEffect(()=>{if(!f)return;const e=e=>{if(e.source!==s.current?.contentWindow)return;if(e.origin!==f)return;if(!n.isAtbMessage(e.data))return;const{type:t,data:o}=e.data,a=t===n.ATB_MESSAGE_TYPES.COMPLETED?n.readAtbCompletion(o):{};switch(r.logger.info({message:"[atb] gateway event",api_name:Zt,reference_id:m,type:t,status:a.status??null,checkout_id:a.checkoutId??null}),t){case n.ATB_MESSAGE_TYPES.READY:return void h();case n.ATB_MESSAGE_TYPES.COMPLETED:return void y(n.readAtbOutcome(a.status),{checkoutId:a.checkoutId});case n.ATB_MESSAGE_TYPES.ERROR:return void y(n.ATB_OUTCOMES.FAILED,{message:n.ATB_FAILURE_MESSAGES.SESSION_INVALID,code:n.ATB_FAILURE_CODES.SESSION_INVALID});case n.ATB_MESSAGE_TYPES.REDIRECT:{const e=n.readAtbRedirect(o);if(!e)return void r.logger.warn({message:"ATB wallet redirect carried no https url",api_name:Zt});r.logger.info({message:"[atb] wallet redirect in frame",api_name:Zt,reference_id:m}),s.current&&(s.current.src=e)}}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[f,m,h,y]),t.useEffect(()=>{const e=setTimeout(()=>{l.current||y(n.ATB_OUTCOMES.FAILED,{message:n.ATB_FAILURE_MESSAGES.LOAD_FAILED,code:n.ATB_FAILURE_CODES.LOAD_FAILED})},6e4);return()=>clearTimeout(e)},[y]),e.jsx("div",{className:"absolute inset-0 z-[105] flex flex-col overflow-hidden",style:{background:i.cardBg},role:"region","aria-label":"Payment",children:e.jsxs("div",{className:"relative flex min-h-0 flex-1 overflow-hidden",children:[!u&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center text-sm",style:{color:i.muted,fontFamily:i.fontFamily},children:"Loading…"}),e.jsx("iframe",{ref:s,src:o.config.url,title:"Payment",className:"min-h-0 flex-1 "+(u?"":"invisible"),style:{border:0,background:"white",width:`calc(100% + ${p}px)`},allow:"payment",referrerPolicy:"no-referrer"})]})})},tn=({init:o,skin:a})=>{const i=de(),[s]=t.useState(()=>!n.isAtbCheckoutUrl(o.config.url)),c=t.useRef(!1);return t.useEffect(()=>{s&&!c.current&&(c.current=!0,r.logger.warn({message:"ATB checkout url is not https",api_name:"atb-payment",reference_id:o.payment_id}),i(n.buildAtbResult({outcome:n.ATB_OUTCOMES.FAILED,init:o,message:n.ATB_FAILURE_MESSAGES.SESSION_INVALID,code:n.ATB_FAILURE_CODES.SESSION_INVALID})))},[s,o,i]),s?null:e.jsx(en,{init:o,onResult:i,skin:a})},nn={type:"atb",label:"ATB",hideShellSubmit:!0,hideShellFooter:!0,FormComponent:({skin:n,onReady:r})=>{const{paymentInit:o}=an(),a="atb"===o?.provider?o:null;return t.useEffect(()=>{r?.()},[r]),a?e.jsx(tn,{init:a,skin:n},a.payment_id):null}},rn=t.createContext(void 0),on=({children:r,paymentProvider:o,paymentInit:a=null,conversationId:i=null})=>{const s=a?.provider||o||n.DEFAULT_PAYMENT_PROVIDER,c=t.useMemo(()=>function(e){switch(e){case"stripe":return _e;case"moyasar":return Lt;case"chargebee":return Xt;case"atb":return nn;default:throw new Error(`Unknown payment provider: "${e}". Supported providers: stripe, moyasar, chargebee, atb`)}}(s),[s]),l=t.useMemo(()=>({adapter:c,paymentProvider:s,paymentInit:a,conversationId:i}),[c,s,a,i]),u=c.ProviderWrapper;return e.jsx(rn.Provider,{value:l,children:u?e.jsx(u,{children:r}):r})},an=()=>{const e=t.useContext(rn);if(!e)throw new Error("usePaymentAdapter must be used within a PaymentProvider");return e},sn=({provider:o,paymentInit:a})=>{const{themeStyles:i,theme:s}=r.useBranding(),{adapter:c}=an(),l=ue().summary,[u,d]=t.useState(!1),p=t.useCallback(()=>d(!0),[]),f=t.useMemo(()=>n.buildBrandSkin(i,s),[i,s]),m="moyasar"===a?.provider?a.config:null,y="chargebee"===a?.provider?a.config:null,h=l?.amount??m?.amount??y?.amount??0,g=l?.currency??m?.currency??y?.currency??"usd",b=null!=l?.amount||null!=m?.amount||null!=y?.amount,v=((e,t)=>n.formatAmount(e,t)??"")(h,g),x=o??c.label,w=c.FormComponent;return e.jsxs("div",{className:"w-full flex-1 min-h-0 overflow-y-auto [&::-webkit-scrollbar]:hidden [scrollbar-width:none] relative",style:{background:f.pageBg,color:f.text,fontFamily:f.fontFamily,colorScheme:f.colorScheme},children:[!u&&e.jsx(cn,{skin:f}),e.jsx("div",{className:"min-h-full flex items-center justify-center p-4",style:{visibility:u?"visible":"hidden"},children:e.jsxs("div",{className:"w-full max-w-lg p-6",style:{background:f.cardBg,borderRadius:f.radius,boxShadow:f.cardShadow,color:f.text},children:[e.jsx("h1",{className:"text-base font-semibold text-center mb-3.5",style:{color:f.heading},children:"Payment Options"}),e.jsx("div",{className:"mb-3.5",children:e.jsx(w,{amount:h,currency:g,skin:f,onReady:p})}),!c.hideShellSubmit&&b&&e.jsx(ln,{label:`Pay ${v}`,background:i.statusDiscovery.solid,color:i.statusDiscovery.text,radius:f.radius}),!c.hideShellFooter&&e.jsxs("p",{className:"text-xs text-center mt-2.5",style:{color:f.muted},children:["Powered by ",x]})]})})]})},cn=({skin:t})=>e.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-3",style:{background:t.pageBg,color:t.text},"aria-live":"polite","aria-busy":"true",children:[e.jsx(l,{className:"h-8 w-8 animate-spin",style:{color:t.accent}}),e.jsx("p",{className:"text-sm",style:{color:t.muted},children:"Loading payment…"})]}),ln=({label:t,background:n,color:r,radius:o})=>{const a=ue().confirmHandle;return e.jsx("button",{type:"button",onClick:()=>a?.confirm(),disabled:!a||a.isConfirming,className:"w-full p-3 text-sm font-semibold border-0 cursor-pointer disabled:cursor-not-allowed disabled:opacity-70",style:{background:n,color:r,borderRadius:o},children:a?.isConfirming?"Processing…":t})};exports.default=({provider:t,paymentInit:n=null,onResult:o,conversationId:a=null})=>e.jsx(on,{paymentInit:n,conversationId:a,paymentProvider:r.getPaymentProviderHint(),children:e.jsx(le,{onResult:e=>{o?.(e)},children:e.jsx(sn,{provider:t,paymentInit:n})})},n?.provider??"default");
@@ -0,0 +1 @@
1
+ import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import r,{forwardRef as o,createElement as a,useState as i,useRef as c,useCallback as s,useMemo as l,createContext as u,useContext as d,useEffect as p,useLayoutEffect as f}from"react";import{buildBrandSkin as m,parseMoyasarCallbackFromUrl as y,buildCallbackUrl as h,resolveAtbOrigin as g,buildAtbResult as v,ATB_OUTCOMES as b,ATB_FAILURE_CODES as w,ATB_FAILURE_MESSAGES as x,isAtbMessage as S,ATB_MESSAGE_TYPES as E,readAtbCompletion as C,readAtbRedirect as k,readAtbOutcome as P,isAtbCheckoutUrl as O,DEFAULT_PAYMENT_PROVIDER as _,formatAmount as j}from"@1interface/chat-core";import{useBranding as A,showErrorToast as I,logger as N,getPaymentProviderHint as T}from"@1interface/shared-core";const M=e=>{const t=(e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,t,n)=>n?n.toUpperCase():t.toLowerCase()))(e);return t.charAt(0).toUpperCase()+t.slice(1)},F=(...e)=>e.filter((e,t,n)=>Boolean(e)&&""!==e.trim()&&n.indexOf(e)===t).join(" ").trim(),R=e=>{for(const t in e)if(t.startsWith("aria-")||"role"===t||"title"===t)return!0};var $={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};const D=o(({color:e="currentColor",size:t=24,strokeWidth:n=2,absoluteStrokeWidth:r,className:o="",children:i,iconNode:c,...s},l)=>a("svg",{ref:l,...$,width:t,height:t,stroke:e,strokeWidth:r?24*Number(n)/Number(t):n,className:F("lucide",o),...!i&&!R(s)&&{"aria-hidden":"true"},...s},[...c.map(([e,t])=>a(e,t)),...Array.isArray(i)?i:[i]])),V=((e,t)=>{const n=o(({className:n,...r},o)=>{return a(D,{ref:o,iconNode:t,className:F(`lucide-${i=M(e),i.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}`,`lucide-${e}`,n),...r});var i});return n.displayName=M(e),n})("loader-circle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]);function L(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var B,z,U,q,W,Y,H,J,K,X,Z,G,Q,ee,te,ne,re={exports:{}},oe={exports:{}},ae={},ie={};function ce(){return U||(U=1,oe.exports="production"===process.env.NODE_ENV?function(){if(B)return ae;B=1;var e="function"==typeof Symbol&&Symbol.for,t=e?Symbol.for("react.element"):60103,n=e?Symbol.for("react.portal"):60106,r=e?Symbol.for("react.fragment"):60107,o=e?Symbol.for("react.strict_mode"):60108,a=e?Symbol.for("react.profiler"):60114,i=e?Symbol.for("react.provider"):60109,c=e?Symbol.for("react.context"):60110,s=e?Symbol.for("react.async_mode"):60111,l=e?Symbol.for("react.concurrent_mode"):60111,u=e?Symbol.for("react.forward_ref"):60112,d=e?Symbol.for("react.suspense"):60113,p=e?Symbol.for("react.suspense_list"):60120,f=e?Symbol.for("react.memo"):60115,m=e?Symbol.for("react.lazy"):60116,y=e?Symbol.for("react.block"):60121,h=e?Symbol.for("react.fundamental"):60117,g=e?Symbol.for("react.responder"):60118,v=e?Symbol.for("react.scope"):60119;function b(e){if("object"==typeof e&&null!==e){var p=e.$$typeof;switch(p){case t:switch(e=e.type){case s:case l:case r:case a:case o:case d:return e;default:switch(e=e&&e.$$typeof){case c:case u:case m:case f:case i:return e;default:return p}}case n:return p}}}function w(e){return b(e)===l}return ae.AsyncMode=s,ae.ConcurrentMode=l,ae.ContextConsumer=c,ae.ContextProvider=i,ae.Element=t,ae.ForwardRef=u,ae.Fragment=r,ae.Lazy=m,ae.Memo=f,ae.Portal=n,ae.Profiler=a,ae.StrictMode=o,ae.Suspense=d,ae.isAsyncMode=function(e){return w(e)||b(e)===s},ae.isConcurrentMode=w,ae.isContextConsumer=function(e){return b(e)===c},ae.isContextProvider=function(e){return b(e)===i},ae.isElement=function(e){return"object"==typeof e&&null!==e&&e.$$typeof===t},ae.isForwardRef=function(e){return b(e)===u},ae.isFragment=function(e){return b(e)===r},ae.isLazy=function(e){return b(e)===m},ae.isMemo=function(e){return b(e)===f},ae.isPortal=function(e){return b(e)===n},ae.isProfiler=function(e){return b(e)===a},ae.isStrictMode=function(e){return b(e)===o},ae.isSuspense=function(e){return b(e)===d},ae.isValidElementType=function(e){return"string"==typeof e||"function"==typeof e||e===r||e===l||e===a||e===o||e===d||e===p||"object"==typeof e&&null!==e&&(e.$$typeof===m||e.$$typeof===f||e.$$typeof===i||e.$$typeof===c||e.$$typeof===u||e.$$typeof===h||e.$$typeof===g||e.$$typeof===v||e.$$typeof===y)},ae.typeOf=b,ae}():(z||(z=1,"production"!==process.env.NODE_ENV&&function(){var e="function"==typeof Symbol&&Symbol.for,t=e?Symbol.for("react.element"):60103,n=e?Symbol.for("react.portal"):60106,r=e?Symbol.for("react.fragment"):60107,o=e?Symbol.for("react.strict_mode"):60108,a=e?Symbol.for("react.profiler"):60114,i=e?Symbol.for("react.provider"):60109,c=e?Symbol.for("react.context"):60110,s=e?Symbol.for("react.async_mode"):60111,l=e?Symbol.for("react.concurrent_mode"):60111,u=e?Symbol.for("react.forward_ref"):60112,d=e?Symbol.for("react.suspense"):60113,p=e?Symbol.for("react.suspense_list"):60120,f=e?Symbol.for("react.memo"):60115,m=e?Symbol.for("react.lazy"):60116,y=e?Symbol.for("react.block"):60121,h=e?Symbol.for("react.fundamental"):60117,g=e?Symbol.for("react.responder"):60118,v=e?Symbol.for("react.scope"):60119;function b(e){if("object"==typeof e&&null!==e){var p=e.$$typeof;switch(p){case t:var y=e.type;switch(y){case s:case l:case r:case a:case o:case d:return y;default:var h=y&&y.$$typeof;switch(h){case c:case u:case m:case f:case i:return h;default:return p}}case n:return p}}}var w=l,x=c,S=i,E=t,C=u,k=r,P=m,O=f,_=n,j=a,A=o,I=d,N=!1;function T(e){return b(e)===l}ie.AsyncMode=s,ie.ConcurrentMode=w,ie.ContextConsumer=x,ie.ContextProvider=S,ie.Element=E,ie.ForwardRef=C,ie.Fragment=k,ie.Lazy=P,ie.Memo=O,ie.Portal=_,ie.Profiler=j,ie.StrictMode=A,ie.Suspense=I,ie.isAsyncMode=function(e){return N||(N=!0,console.warn("The ReactIs.isAsyncMode() alias has been deprecated, and will be removed in React 17+. Update your code to use ReactIs.isConcurrentMode() instead. It has the exact same API.")),T(e)||b(e)===s},ie.isConcurrentMode=T,ie.isContextConsumer=function(e){return b(e)===c},ie.isContextProvider=function(e){return b(e)===i},ie.isElement=function(e){return"object"==typeof e&&null!==e&&e.$$typeof===t},ie.isForwardRef=function(e){return b(e)===u},ie.isFragment=function(e){return b(e)===r},ie.isLazy=function(e){return b(e)===m},ie.isMemo=function(e){return b(e)===f},ie.isPortal=function(e){return b(e)===n},ie.isProfiler=function(e){return b(e)===a},ie.isStrictMode=function(e){return b(e)===o},ie.isSuspense=function(e){return b(e)===d},ie.isValidElementType=function(e){return"string"==typeof e||"function"==typeof e||e===r||e===l||e===a||e===o||e===d||e===p||"object"==typeof e&&null!==e&&(e.$$typeof===m||e.$$typeof===f||e.$$typeof===i||e.$$typeof===c||e.$$typeof===u||e.$$typeof===h||e.$$typeof===g||e.$$typeof===v||e.$$typeof===y)},ie.typeOf=b}()),ie)),oe.exports}function se(){return H?Y:(H=1,Y="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}function le(){return K?J:(K=1,J=Function.call.bind(Object.prototype.hasOwnProperty))}function ue(){if(Z)return X;Z=1;var e=function(){};if("production"!==process.env.NODE_ENV){var t=se(),n={},r=le();e=function(e){var t="Warning: "+e;"undefined"!=typeof console&&console.error(t);try{throw new Error(t)}catch(e){}}}function o(o,a,i,c,s){if("production"!==process.env.NODE_ENV)for(var l in o)if(r(o,l)){var u;try{if("function"!=typeof o[l]){var d=Error((c||"React class")+": "+i+" type `"+l+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof o[l]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw d.name="Invariant Violation",d}u=o[l](a,l,c,i,null,t)}catch(e){u=e}if(!u||u instanceof Error||e((c||"React class")+": type specification of "+i+" `"+l+"` is invalid; the type checker function must return `null` or an `Error` but returned a "+typeof u+". You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument)."),u instanceof Error&&!(u.message in n)){n[u.message]=!0;var p=s?s():"";e("Failed "+i+" type: "+u.message+(null!=p?p:""))}}}return o.resetWarningCache=function(){"production"!==process.env.NODE_ENV&&(n={})},X=o}function de(){if(Q)return G;Q=1;var e=ce(),t=function(){if(W)return q;W=1;var e=Object.getOwnPropertySymbols,t=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable;return q=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},n=0;n<10;n++)t["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(t).map(function(e){return t[e]}).join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach(function(e){r[e]=e}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(e){return!1}}()?Object.assign:function(r,o){for(var a,i,c=function(e){if(null==e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}(r),s=1;s<arguments.length;s++){for(var l in a=Object(arguments[s]))t.call(a,l)&&(c[l]=a[l]);if(e){i=e(a);for(var u=0;u<i.length;u++)n.call(a,i[u])&&(c[i[u]]=a[i[u]])}}return c},q}(),n=se(),r=le(),o=ue(),a=function(){};function i(){return null}return"production"!==process.env.NODE_ENV&&(a=function(e){var t="Warning: "+e;"undefined"!=typeof console&&console.error(t);try{throw new Error(t)}catch(e){}}),G=function(c,s){var l="function"==typeof Symbol&&Symbol.iterator,u="<<anonymous>>",d={array:y("array"),bigint:y("bigint"),bool:y("boolean"),func:y("function"),number:y("number"),object:y("object"),string:y("string"),symbol:y("symbol"),any:m(i),arrayOf:function(e){return m(function(t,r,o,a,i){if("function"!=typeof e)return new f("Property `"+i+"` of component `"+o+"` has invalid PropType notation inside arrayOf.");var c=t[r];if(!Array.isArray(c))return new f("Invalid "+a+" `"+i+"` of type `"+v(c)+"` supplied to `"+o+"`, expected an array.");for(var s=0;s<c.length;s++){var l=e(c,s,o,a,i+"["+s+"]",n);if(l instanceof Error)return l}return null})},element:m(function(e,t,n,r,o){var a=e[t];return c(a)?null:new f("Invalid "+r+" `"+o+"` of type `"+v(a)+"` supplied to `"+n+"`, expected a single ReactElement.")}),elementType:m(function(t,n,r,o,a){var i=t[n];return e.isValidElementType(i)?null:new f("Invalid "+o+" `"+a+"` of type `"+v(i)+"` supplied to `"+r+"`, expected a single ReactElement type.")}),instanceOf:function(e){return m(function(t,n,r,o,a){return t[n]instanceof e?null:new f("Invalid "+o+" `"+a+"` of type `"+((i=t[n]).constructor&&i.constructor.name?i.constructor.name:u)+"` supplied to `"+r+"`, expected instance of `"+(e.name||u)+"`.");var i})},node:m(function(e,t,n,r,o){return g(e[t])?null:new f("Invalid "+r+" `"+o+"` supplied to `"+n+"`, expected a ReactNode.")}),objectOf:function(e){return m(function(t,o,a,i,c){if("function"!=typeof e)return new f("Property `"+c+"` of component `"+a+"` has invalid PropType notation inside objectOf.");var s=t[o],l=v(s);if("object"!==l)return new f("Invalid "+i+" `"+c+"` of type `"+l+"` supplied to `"+a+"`, expected an object.");for(var u in s)if(r(s,u)){var d=e(s,u,a,i,c+"."+u,n);if(d instanceof Error)return d}return null})},oneOf:function(e){return Array.isArray(e)?m(function(t,n,r,o,a){for(var i=t[n],c=0;c<e.length;c++)if(p(i,e[c]))return null;var s=JSON.stringify(e,function(e,t){return"symbol"===b(t)?String(t):t});return new f("Invalid "+o+" `"+a+"` of value `"+String(i)+"` supplied to `"+r+"`, expected one of "+s+".")}):("production"!==process.env.NODE_ENV&&a(arguments.length>1?"Invalid arguments supplied to oneOf, expected an array, got "+arguments.length+" arguments. A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z]).":"Invalid argument supplied to oneOf, expected an array."),i)},oneOfType:function(e){if(!Array.isArray(e))return"production"!==process.env.NODE_ENV&&a("Invalid argument supplied to oneOfType, expected an instance of array."),i;for(var t=0;t<e.length;t++){var o=e[t];if("function"!=typeof o)return a("Invalid argument supplied to oneOfType. Expected an array of check functions, but received "+w(o)+" at index "+t+"."),i}return m(function(t,o,a,i,c){for(var s=[],l=0;l<e.length;l++){var u=(0,e[l])(t,o,a,i,c,n);if(null==u)return null;u.data&&r(u.data,"expectedType")&&s.push(u.data.expectedType)}return new f("Invalid "+i+" `"+c+"` supplied to `"+a+"`"+(s.length>0?", expected one of type ["+s.join(", ")+"]":"")+".")})},shape:function(e){return m(function(t,r,o,a,i){var c=t[r],s=v(c);if("object"!==s)return new f("Invalid "+a+" `"+i+"` of type `"+s+"` supplied to `"+o+"`, expected `object`.");for(var l in e){var u=e[l];if("function"!=typeof u)return h(o,a,i,l,b(u));var d=u(c,l,o,a,i+"."+l,n);if(d)return d}return null})},exact:function(e){return m(function(o,a,i,c,s){var l=o[a],u=v(l);if("object"!==u)return new f("Invalid "+c+" `"+s+"` of type `"+u+"` supplied to `"+i+"`, expected `object`.");var d=t({},o[a],e);for(var p in d){var m=e[p];if(r(e,p)&&"function"!=typeof m)return h(i,c,s,p,b(m));if(!m)return new f("Invalid "+c+" `"+s+"` key `"+p+"` supplied to `"+i+"`.\nBad object: "+JSON.stringify(o[a],null," ")+"\nValid keys: "+JSON.stringify(Object.keys(e),null," "));var y=m(l,p,i,c,s+"."+p,n);if(y)return y}return null})}};function p(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t}function f(e,t){this.message=e,this.data=t&&"object"==typeof t?t:{},this.stack=""}function m(e){if("production"!==process.env.NODE_ENV)var t={},r=0;function o(o,i,c,l,d,p,m){if(l=l||u,p=p||c,m!==n){if(s){var y=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use `PropTypes.checkPropTypes()` to call them. Read more at http://fb.me/use-check-prop-types");throw y.name="Invariant Violation",y}if("production"!==process.env.NODE_ENV&&"undefined"!=typeof console){var h=l+":"+c;!t[h]&&r<3&&(a("You are manually calling a React.PropTypes validation function for the `"+p+"` prop on `"+l+"`. This is deprecated and will throw in the standalone `prop-types` package. You may be seeing this warning due to a third-party PropTypes library. See https://fb.me/react-warning-dont-call-proptypes for details."),t[h]=!0,r++)}}return null==i[c]?o?new f(null===i[c]?"The "+d+" `"+p+"` is marked as required in `"+l+"`, but its value is `null`.":"The "+d+" `"+p+"` is marked as required in `"+l+"`, but its value is `undefined`."):null:e(i,c,l,d,p)}var i=o.bind(null,!1);return i.isRequired=o.bind(null,!0),i}function y(e){return m(function(t,n,r,o,a,i){var c=t[n];return v(c)!==e?new f("Invalid "+o+" `"+a+"` of type `"+b(c)+"` supplied to `"+r+"`, expected `"+e+"`.",{expectedType:e}):null})}function h(e,t,n,r,o){return new f((e||"React class")+": "+t+" type `"+n+"."+r+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+o+"`.")}function g(e){switch(typeof e){case"number":case"string":case"undefined":return!0;case"boolean":return!e;case"object":if(Array.isArray(e))return e.every(g);if(null===e||c(e))return!0;var t=function(e){var t=e&&(l&&e[l]||e["@@iterator"]);if("function"==typeof t)return t}(e);if(!t)return!1;var n,r=t.call(e);if(t!==e.entries){for(;!(n=r.next()).done;)if(!g(n.value))return!1}else for(;!(n=r.next()).done;){var o=n.value;if(o&&!g(o[1]))return!1}return!0;default:return!1}}function v(e){var t=typeof e;return Array.isArray(e)?"array":e instanceof RegExp?"object":function(e,t){return"symbol"===e||!!t&&("Symbol"===t["@@toStringTag"]||"function"==typeof Symbol&&t instanceof Symbol)}(t,e)?"symbol":t}function b(e){if(null==e)return""+e;var t=v(e);if("object"===t){if(e instanceof Date)return"date";if(e instanceof RegExp)return"regexp"}return t}function w(e){var t=b(e);switch(t){case"array":case"object":return"an "+t;case"boolean":case"date":case"regexp":return"a "+t;default:return t}}return f.prototype=Error.prototype,d.checkPropTypes=o,d.resetWarningCache=o.resetWarningCache,d.PropTypes=d,d},G}function pe(){if(te)return ee;te=1;var e=se();function t(){}function n(){}return n.resetWarningCache=t,ee=function(){function r(t,n,r,o,a,i){if(i!==e){var c=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw c.name="Invariant Violation",c}}function o(){return r}r.isRequired=r;var a={array:r,bigint:r,bool:r,func:r,number:r,object:r,string:r,symbol:r,any:r,arrayOf:o,element:r,elementType:r,instanceOf:o,node:r,objectOf:o,oneOf:o,oneOfType:o,shape:o,exact:o,checkPropTypes:n,resetWarningCache:t};return a.PropTypes=a,a}}function fe(){if(ne)return re.exports;if(ne=1,"production"!==process.env.NODE_ENV){var e=ce();re.exports=de()(e.isElement,!0)}else re.exports=pe()();return re.exports}const me=L(fe());function ye(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function he(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ye(Object(n),!0).forEach(function(t){ve(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ye(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function ge(e){return(ge="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function ve(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function be(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=e&&("undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"]);if(null!=n){var r,o,a=[],i=!0,c=!1;try{for(n=n.call(e);!(i=(r=n.next()).done)&&(a.push(r.value),!t||a.length!==t);i=!0);}catch(e){c=!0,o=e}finally{try{i||null==n.return||n.return()}finally{if(c)throw o}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return we(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?we(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function we(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var xe=function(e,t,n){var o=!!n,a=r.useRef(n);r.useEffect(function(){a.current=n},[n]),r.useEffect(function(){if(!o||!e)return function(){};var n=function(){a.current&&a.current.apply(a,arguments)};return e.on(t,n),function(){e.off(t,n)}},[o,t,e,a])},Se=function(e){var t=r.useRef(e);return r.useEffect(function(){t.current=e},[e]),t.current},Ee=function(e){return null!==e&&"object"===ge(e)},Ce="[object Object]",ke=function e(t,n){if(!Ee(t)||!Ee(n))return t===n;var r=Array.isArray(t);if(r!==Array.isArray(n))return!1;var o=Object.prototype.toString.call(t)===Ce;if(o!==(Object.prototype.toString.call(n)===Ce))return!1;if(!o&&!r)return t===n;var a=Object.keys(t),i=Object.keys(n);if(a.length!==i.length)return!1;for(var c={},s=0;s<a.length;s+=1)c[a[s]]=!0;for(var l=0;l<i.length;l+=1)c[i[l]]=!0;var u=Object.keys(c);if(u.length!==a.length)return!1;var d=t,p=n;return u.every(function(t){return e(d[t],p[t])})},Pe=function(e,t,n){return Ee(e)?Object.keys(e).reduce(function(r,o){var a=!Ee(t)||!ke(e[o],t[o]);return n.includes(o)?(a&&console.warn("Unsupported prop change: options.".concat(o," is not a mutable property.")),r):a?he(he({},r||{}),{},ve({},o,e[o])):r},null):null},Oe="Invalid prop `stripe` supplied to `Elements`. We recommend using the `loadStripe` utility from `@stripe/stripe-js`. See https://stripe.com/docs/stripe-js/react#elements-props-stripe for details.",_e=function(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Oe;if(null===e||Ee(t=e)&&"function"==typeof t.elements&&"function"==typeof t.createToken&&"function"==typeof t.createPaymentMethod&&"function"==typeof t.confirmCardPayment)return e;throw new Error(n)},je=r.createContext(null);je.displayName="ElementsContext";var Ae=function(e,t){if(!e)throw new Error("Could not find Elements context; You need to wrap the part of your app that ".concat(t," in an <Elements> provider."));return e},Ie=function(e){var t=e.stripe,n=e.options,o=e.children,a=r.useMemo(function(){return function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Oe;if(function(e){return Ee(e)&&"function"==typeof e.then}(e))return{tag:"async",stripePromise:Promise.resolve(e).then(function(e){return _e(e,t)})};var n=_e(e,t);return null===n?{tag:"empty"}:{tag:"sync",stripe:n}}(t)},[t]),i=be(r.useState(function(){return{stripe:"sync"===a.tag?a.stripe:null,elements:"sync"===a.tag?a.stripe.elements(n):null}}),2),c=i[0],s=i[1];r.useEffect(function(){var e=!0,t=function(e){s(function(t){return t.stripe?t:{stripe:e,elements:e.elements(n)}})};return"async"!==a.tag||c.stripe?"sync"!==a.tag||c.stripe||t(a.stripe):a.stripePromise.then(function(n){n&&e&&t(n)}),function(){e=!1}},[a,c,n]);var l=Se(t);r.useEffect(function(){null!==l&&l!==t&&console.warn("Unsupported prop change on Elements: You cannot change the `stripe` prop after setting it.")},[l,t]);var u=Se(n);return r.useEffect(function(){if(c.elements){var e=Pe(n,u,["clientSecret","fonts"]);e&&c.elements.update(e)}},[n,u,c.elements]),r.useEffect(function(){var e;(e=c.stripe)&&e._registerWrapper&&e.registerAppInfo&&(e._registerWrapper({name:"react-stripe-js",version:"3.10.0"}),e.registerAppInfo({name:"react-stripe-js",version:"3.10.0",url:"https://stripe.com/docs/stripe-js/react"}))},[c.stripe]),r.createElement(je.Provider,{value:c},o)};Ie.propTypes={stripe:me.any,options:me.object};var Ne=r.createContext(null);Ne.displayName="CheckoutSdkContext",r.createContext(null).displayName="CheckoutContext",me.shape({fetchClientSecret:me.func.isRequired,elementsOptions:me.object});var Te=function(e){var t=r.useContext(Ne),n=r.useContext(je);if(t&&n)throw new Error("You cannot wrap the part of your app that ".concat(e," in both <CheckoutProvider> and <Elements> providers."));return t?function(e,t){if(!e)throw new Error("Could not find CheckoutProvider context; You need to wrap the part of your app that ".concat(t," in an <CheckoutProvider> provider."));return e}(t,e):Ae(n,e)},Me=["mode"],Fe=function(e,t){var n,o="".concat((n=e).charAt(0).toUpperCase()+n.slice(1),"Element"),a=t?function(e){return Te("mounts <".concat(o,">")),r.createElement("div",{id:e.id,className:e.className})}:function(t){var n,a=t.id,i=t.className,c=t.options,s=void 0===c?{}:c,l=t.onBlur,u=t.onFocus,d=t.onReady,p=t.onChange,f=t.onEscape,m=t.onClick,y=t.onLoadError,h=t.onLoaderStart,g=t.onNetworksChange,v=t.onConfirm,b=t.onCancel,w=t.onShippingAddressChange,x=t.onShippingRateChange,S=t.onSavedPaymentMethodRemove,E=t.onSavedPaymentMethodUpdate,C=Te("mounts <".concat(o,">")),k="elements"in C?C.elements:null,P="checkoutSdk"in C?C.checkoutSdk:null,O=be(r.useState(null),2),_=O[0],j=O[1],A=r.useRef(null),I=r.useRef(null);xe(_,"blur",l),xe(_,"focus",u),xe(_,"escape",f),xe(_,"click",m),xe(_,"loaderror",y),xe(_,"loaderstart",h),xe(_,"networkschange",g),xe(_,"confirm",v),xe(_,"cancel",b),xe(_,"shippingaddresschange",w),xe(_,"shippingratechange",x),xe(_,"savedpaymentmethodremove",S),xe(_,"savedpaymentmethodupdate",E),xe(_,"change",p),d&&(n="expressCheckout"===e?d:function(){d(_)}),xe(_,"ready",n),r.useLayoutEffect(function(){if(null===A.current&&null!==I.current&&(k||P)){var t=null;if(P)switch(e){case"payment":t=P.createPaymentElement(s);break;case"address":if(!("mode"in s))throw new Error("You must supply options.mode. mode must be 'billing' or 'shipping'.");var n=s.mode,r=function(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},a=Object.keys(e);for(r=0;r<a.length;r++)t.indexOf(n=a[r])>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)t.indexOf(n=a[r])>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}(s,Me);if("shipping"===n)t=P.createShippingAddressElement(r);else{if("billing"!==n)throw new Error("Invalid options.mode. mode must be 'billing' or 'shipping'.");t=P.createBillingAddressElement(r)}break;case"expressCheckout":t=P.createExpressCheckoutElement(s);break;case"currencySelector":t=P.createCurrencySelectorElement();break;case"taxId":t=P.createTaxIdElement(s);break;default:throw new Error("Invalid Element type ".concat(o,". You must use either the <PaymentElement />, <AddressElement options={{mode: 'shipping'}} />, <AddressElement options={{mode: 'billing'}} />, or <ExpressCheckoutElement />."))}else k&&(t=k.create(e,s));A.current=t,j(t),t&&t.mount(I.current)}},[k,P,s]);var N=Se(s);return r.useEffect(function(){if(A.current){var e=Pe(s,N,["paymentRequest"]);e&&"update"in A.current&&A.current.update(e)}},[s,N]),r.useLayoutEffect(function(){return function(){if(A.current&&"function"==typeof A.current.destroy)try{A.current.destroy(),A.current=null}catch(e){}}},[]),r.createElement("div",{id:a,className:i,ref:I})};return a.propTypes={id:me.string,className:me.string,onChange:me.func,onBlur:me.func,onFocus:me.func,onReady:me.func,onEscape:me.func,onClick:me.func,onLoadError:me.func,onLoaderStart:me.func,onNetworksChange:me.func,onConfirm:me.func,onCancel:me.func,onShippingAddressChange:me.func,onShippingRateChange:me.func,onSavedPaymentMethodRemove:me.func,onSavedPaymentMethodUpdate:me.func,options:me.object},a.displayName=o,a.__elementType=e,a},Re="undefined"==typeof window;r.createContext(null).displayName="EmbeddedCheckoutProviderContext",Fe("auBankAccount",Re),Fe("card",Re),Fe("cardNumber",Re),Fe("cardExpiry",Re),Fe("cardCvc",Re),Fe("fpxBank",Re),Fe("iban",Re),Fe("idealBank",Re),Fe("p24Bank",Re),Fe("epsBank",Re);var $e=Fe("payment",Re);Fe("expressCheckout",Re),Fe("currencySelector",Re),Fe("paymentRequestButton",Re),Fe("linkAuthentication",Re),Fe("address",Re),Fe("shippingAddress",Re),Fe("paymentMethodMessaging",Re),Fe("affirmMessage",Re),Fe("afterpayClearpayMessage",Re),Fe("taxId",Re);const De=u(null),Ve=({onResult:t,children:n})=>{const[r,o]=i(null),[a,u]=i(null),d=c(t);d.current=t;const p=s(e=>{d.current(e)},[]),f=s(e=>{o(e)},[]),m=s(e=>{u(e)},[]),y=l(()=>({emitResult:p,registerConfirm:f,confirmHandle:r,reportSummary:m,summary:a}),[p,f,r,m,a]);return e(De.Provider,{value:y,children:n})},Le=()=>{const e=d(De);if(!e)throw new Error("Payment result channel hooks must be used inside PaymentResultChannelProvider");return e},Be=()=>Le().emitResult,ze=()=>Le().registerConfirm,Ue=()=>Le().reportSummary;function qe(e){return(qe="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var We,Ye="https://js.stripe.com/v3",He=/^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/,Je="loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used",Ke=function(e){var t=e&&!e.advancedFraudSignals?"?advancedFraudSignals=false":"",n=document.createElement("script");n.src="".concat(Ye).concat(t);var r=document.head||document.body;if(!r)throw new Error("Expected document.body not to be null. Stripe.js requires a <body> element.");return r.appendChild(n),n},Xe=null,Ze=null,Ge=null,Qe=function(e){var t="invalid load parameters; expected object of shape\n\n {advancedFraudSignals: boolean}\n\nbut received\n\n ".concat(JSON.stringify(e),"\n");if(null===e||"object"!==qe(e))throw new Error(t);if(1===Object.keys(e).length&&"boolean"==typeof e.advancedFraudSignals)return e;throw new Error(t)},et=!1,tt=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];et=!0;var r,o=Date.now();return(r=We,null!==Xe?Xe:(Xe=new Promise(function(e,t){if("undefined"!=typeof window&&"undefined"!=typeof document)if(window.Stripe&&r&&console.warn(Je),window.Stripe)e(window.Stripe);else try{var n=function(){for(var e=document.querySelectorAll('script[src^="'.concat(Ye,'"]')),t=0;t<e.length;t++){var n=e[t];if(He.test(n.src))return n}return null}();if(n&&r)console.warn(Je);else if(n){if(n&&null!==Ge&&null!==Ze){var o;n.removeEventListener("load",Ge),n.removeEventListener("error",Ze),null===(o=n.parentNode)||void 0===o||o.removeChild(n),n=Ke(r)}}else n=Ke(r);Ge=function(e,t){return function(){window.Stripe?e(window.Stripe):t(new Error("Stripe.js not available"))}}(e,t),Ze=function(e){return function(){e(new Error("Failed to load Stripe.js"))}}(t),n.addEventListener("load",Ge),n.addEventListener("error",Ze)}catch(e){return void t(e)}else e(null)})).catch(function(e){return Xe=null,Promise.reject(e)})).then(function(e){return function(e,t,n){if(null===e)return null;var r=e.apply(void 0,t);return function(e,t){e&&e._registerWrapper&&e._registerWrapper({name:"stripe-js",version:"4.6.0",startTime:t})}(r,n),r}(e,t,o)})};tt.setLoadParameters=function(e){if(et&&We){var t=Qe(e);if(Object.keys(t).reduce(function(t,n){var r;return t&&e[n]===(null===(r=We)||void 0===r?void 0:r[n])},!0))return}if(et)throw new Error("You cannot change load parameters after calling loadStripe");We=Qe(e)};const nt=u(null),rt=({onReady:t})=>{const n=Te("calls useStripe()").stripe,o=(y=r.useContext(je),Ae(y,"calls useElements()")).elements,{paymentInit:a}=Rn(),c=Be(),l=ze(),u=Ue(),[d,f]=i(!1),m="stripe"===a?.provider?a.config.client_secret:null;var y;p(()=>{if(!n||!m)return;let e=!1;return n.retrievePaymentIntent(m).then(t=>{if(e)return;const n=t.paymentIntent;n&&"number"==typeof n.amount&&n.currency&&u({amount:n.amount,currency:n.currency})}),()=>{e=!0}},[n,m,u]);const h=s(async()=>{if(!n||!o||!m)return;f(!0);const{error:e}=await o.submit();if(e)return void f(!1);const{error:t,paymentIntent:r}=await n.confirmPayment({elements:o,clientSecret:m,confirmParams:{return_url:window.location.href},redirect:"if_required"});f(!1),t||!r||"succeeded"!==r.status&&"requires_capture"!==r.status||c({status:"success",provider:"stripe",paymentId:r.id,amount:r.amount,currency:r.currency})},[n,o,m,c]);return p(()=>(l({confirm:h,isConfirming:d}),()=>l(null)),[h,d,l]),e($e,{options:{layout:"tabs",wallets:{applePay:"auto",googlePay:"auto"}},onReady:t})},ot={type:"stripe",label:"Stripe",ProviderWrapper:({children:t})=>{const{paymentInit:n}=Rn(),[r,o]=i(null),a="stripe"===n?.provider?n.config.publishable_key:null;p(()=>{a&&a.startsWith("pk_")&&o(tt(a))},[a]);const c=l(()=>({stripePromise:r}),[r]);return e(nt.Provider,{value:c,children:t})},FormComponent:({onReady:t})=>{const{themeStyles:n,theme:r}=A(),{stripePromise:o}=(()=>{const e=d(nt);if(!e)throw new Error("Stripe adapter components must be used inside StripeProviderWrapper");return e})(),{paymentInit:a}=Rn(),i=l(()=>m(n,r),[n,r]),c=l(()=>function(e,t,n){return{theme:"dark"===t?"night":"stripe",variables:{colorPrimary:e.statusDiscovery.solid,colorBackground:n.cardBg,colorText:n.text,colorDanger:"#df1b41",fontFamily:n.fontFamily,borderRadius:`${n.radius}px`,spacingUnit:"3px",fontSizeBase:"16px"}}}(n,r,i),[n,r,i]),s="stripe"===a?.provider?a.config.client_secret:null,u=l(()=>s?{clientSecret:s,appearance:c}:null,[s,c]);return o&&u?e(Ie,{stripe:o,options:u,children:e(rt,{onReady:t})},s):null}};function at(e){const t={};if(e.config.metadata)for(const[n,r]of Object.entries(e.config.metadata))null!=r&&(t[n]=String(r));if(e.config.customer){const{name:n,email:r,phone:o,reference_id:a}=e.config.customer;n&&(t.customer_name=n),r&&(t.customer_email=r),o&&(t.customer_phone=o),a&&(t.customer_reference_id=a)}return t}class it extends Error{constructor(e,t,n){super(e),this.status=t,this.body=n,this.name="MoyasarApiError"}}async function ct(e){const t=await st("https://api.moyasar.com/v1/payments",e);if(!t.ok)throw new it(lt(t.body)??`Payment creation failed (${t.status})`,t.status,t.body);const n=t.body;if(!n||"string"!=typeof n.id||"string"!=typeof n.status)throw new it("Payment creation returned no id/status",t.status,n);return n}async function st(e,t){const n=new AbortController,r=setTimeout(()=>n.abort(new DOMException("Request timed out","TimeoutError")),3e4);let o;try{o=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),signal:n.signal})}catch(e){const t=e instanceof DOMException&&"TimeoutError"===e.name?"Payment request timed out — please try again.":e instanceof Error?e.message:"Network request failed";throw new it(t)}finally{clearTimeout(r)}let a=null;try{a=await o.json()}catch{a=null}return{ok:o.ok,status:o.status,body:a}}function lt(e){if(!e||"object"!=typeof e)return null;if("string"==typeof e.message&&e.message.length>0)return e.message;if(e.errors&&"object"==typeof e.errors){const t=e.errors;for(const[e,n]of Object.entries(t)){if(Array.isArray(n)&&"string"==typeof n[0])return`${ut(e)}: ${n[0]}`;if("string"==typeof n)return`${ut(e)}: ${n}`}}return null}function ut(e){return e.replace(/_/g," ")}const dt=({url:n,onResult:r,skin:o})=>{const a=c(r);a.current=r;const l=c(!1),[u,d]=i(!1),f=c(!1),m=s(e=>{l.current||(l.current=!0,a.current({status:"failure",provider:"moyasar",message:e}))},[]);return p(()=>{const e=window.location.origin,t=t=>{if(t.origin!==e)return;if(l.current)return;if(!(n=t.data)||"object"!=typeof n||"moyasar-iframe-callback"!==n.type||"string"!=typeof n.search)return;var n;const r=y(t.data.search);r&&(l.current=!0,a.current(r.result))};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[]),p(()=>{const e=setTimeout(()=>{f.current||m("3D Secure challenge failed to load")},6e4);return()=>clearTimeout(e)},[m]),t("div",{className:"absolute inset-0 z-[105]",style:{background:o.cardBg},role:"dialog","aria-label":"3D Secure authentication",children:[!u&&e("div",{className:"absolute inset-0 flex items-center justify-center text-sm",style:{color:o.muted,fontFamily:o.fontFamily},children:"Loading…"}),e("iframe",{src:n,title:"3D Secure",className:"w-full h-full",style:{border:0,background:"white"},onLoad:()=>{f.current=!0,d(!0)},onError:()=>{m("3D Secure challenge failed to load")},allow:"payment *",sandbox:"allow-scripts allow-forms allow-same-origin allow-popups allow-top-navigation-by-user-activation",referrerPolicy:"no-referrer"})]})},pt=["mada","visa","masterCard"],ft="data-aiatcore-apple-pay",mt=({skin:r})=>{const{paymentInit:o}=Rn(),a=o&&"moyasar"===o.provider?o:null,l=Be(),[u,d]=i(null),f=c(l);f.current=l,p(()=>{!function(){if("undefined"==typeof document)return;if(document.querySelector(`style[${ft}]`))return;const e=document.createElement("style");e.setAttribute(ft,"true"),e.textContent="\n .aiatcore-apple-pay-button {\n -webkit-appearance: -apple-pay-button;\n -apple-pay-button-type: pay;\n -apple-pay-button-style: black;\n width: 100%;\n cursor: pointer;\n border: none;\n padding: 0;\n margin: 0;\n }\n ",document.head.appendChild(e)}()},[]);const m=s(()=>{if(!a)return;const e=window.ApplePaySession;if(!e)return void I("Apple Pay is not available on this device.");const t=a.config.apple_pay?.label??a.config.description??"Payment",n=a.config.apple_pay?.country??"SA",r=a.config.currency.toUpperCase(),o=(a.config.amount/100).toFixed(2),i={countryCode:n,currencyCode:r,supportedNetworks:pt,merchantCapabilities:["supports3DS","supportsDebit","supportsCredit"],total:{label:t,amount:o}};let c;try{c=new e(5,i)}catch(e){return void I(e instanceof Error?e.message:"Failed to start Apple Pay")}c.onvalidatemerchant=async e=>{try{const n=await async function(e){const t={validation_url:e.validationUrl,display_name:e.displayName,domain_name:e.domainName??window.location.hostname,publishable_api_key:e.publishableApiKey},n=new AbortController,r=setTimeout(()=>n.abort(new DOMException("Request timed out","TimeoutError")),3e4);let o;try{o=await fetch("https://api.moyasar.com/v1/applepay/initiate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),signal:n.signal})}catch(e){const t=e instanceof DOMException&&"TimeoutError"===e.name?"Apple Pay merchant validation timed out — please try again.":e instanceof Error?e.message:"Network request failed";throw new it(t)}finally{clearTimeout(r)}let a=null;try{a=await o.json()}catch{a=null}if(!o.ok)throw new it(function(e){return e&&"object"==typeof e&&"string"==typeof e.message&&e.message.length>0?e.message:null}(a)??`Apple Pay merchant validation failed (${o.status})`,o.status,a);return a}({validationUrl:e.validationURL,displayName:t,publishableApiKey:a.config.publishable_key});c.completeMerchantValidation(n)}catch(e){const t=e instanceof Error?e.message:"Merchant validation failed";c.abort(),l({status:"failure",provider:"moyasar",message:t,paymentId:a.config.given_id})}},c.onpaymentauthorized=async t=>{try{const n=at(a),o=await ct({publishable_api_key:a.config.publishable_key,given_id:a.config.given_id,amount:a.config.amount,currency:r,description:a.config.description,callback_url:h(a.config.given_id),source:{type:"applepay",token:t.payment.token},...Object.keys(n).length>0?{metadata:n}:{}}),i=o.source?.transaction_url??o.transaction_url;if(i)return c.completePayment({status:e.STATUS_SUCCESS}),void d(i);const s=o.status;if("paid"===s||"authorized"===s||"captured"===s)c.completePayment({status:e.STATUS_SUCCESS}),l({status:"success",provider:"moyasar",paymentId:o.id,amount:o.amount,currency:o.currency});else if("failed"===s){const t=o.source?.message??"Payment failed";c.completePayment({status:e.STATUS_FAILURE}),l({status:"failure",provider:"moyasar",code:"failed",message:t,paymentId:o.id})}else{const t=`Unexpected payment status: ${s}`;c.completePayment({status:e.STATUS_FAILURE}),l({status:"failure",provider:"moyasar",code:s,message:t,paymentId:o.id})}}catch(t){const n=t instanceof it||t instanceof Error?t.message:"Payment failed";c.completePayment({status:e.STATUS_FAILURE}),l({status:"failure",provider:"moyasar",message:n,paymentId:a.config.given_id})}},c.oncancel=()=>{};try{c.begin()}catch(e){I(e instanceof Error?e.message:"Failed to start Apple Pay")}},[a,l]);return a?t(n,{children:[e("button",{type:"button",onClick:m,className:"aiatcore-apple-pay-button",style:{borderRadius:r.radius,height:44},"aria-label":"Pay with Apple Pay"}),u&&e(dt,{url:u,skin:r,onResult:e=>{d(null),f.current(e)}})]}):null};var yt,ht,gt,vt={},bt={};function wt(){return gt||(gt=1,Object.defineProperty(bt,"__esModule",{value:!0}),bt.clone=function(e){return e?JSON.parse(JSON.stringify(e)):null}),bt}var xt,St,Et,Ct,kt,Pt,Ot={},_t={},jt={};function At(){if(Pt)return kt;Pt=1;var e=kt&&kt.__assign||function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)},t=ht?yt:(ht=1,yt={visa:{niceType:"Visa",type:"visa",patterns:[4],gaps:[4,8,12],lengths:[16,18,19],code:{name:"CVV",size:3}},mastercard:{niceType:"Mastercard",type:"mastercard",patterns:[[51,55],[2221,2229],[223,229],[23,26],[270,271],2720],gaps:[4,8,12],lengths:[16],code:{name:"CVC",size:3}},"american-express":{niceType:"American Express",type:"american-express",patterns:[34,37],gaps:[4,10],lengths:[15],code:{name:"CID",size:4}},"diners-club":{niceType:"Diners Club",type:"diners-club",patterns:[[300,305],36,38,39],gaps:[4,10],lengths:[14,16,19],code:{name:"CVV",size:3}},discover:{niceType:"Discover",type:"discover",patterns:[6011,[644,649],65],gaps:[4,8,12],lengths:[16,19],code:{name:"CID",size:3}},jcb:{niceType:"JCB",type:"jcb",patterns:[2131,1800,[3528,3589]],gaps:[4,8,12],lengths:[16,17,18,19],code:{name:"CVV",size:3}},unionpay:{niceType:"UnionPay",type:"unionpay",patterns:[620,[62100,62182],[62184,62187],[62185,62197],[62200,62205],[622010,622999],622018,[62207,62209],[623,626],6270,6272,6276,[627700,627779],[627781,627799],[6282,6289],6291,6292,810,[8110,8131],[8132,8151],[8152,8163],[8164,8171]],gaps:[4,8,12],lengths:[14,15,16,17,18,19],code:{name:"CVN",size:3}},maestro:{niceType:"Maestro",type:"maestro",patterns:[493698,[5e5,504174],[504176,506698],[506779,508999],[56,59],63,67,6],gaps:[4,8,12],lengths:[12,13,14,15,16,17,18,19],code:{name:"CVC",size:3}},elo:{niceType:"Elo",type:"elo",patterns:[401178,401179,438935,457631,457632,431274,451416,457393,504175,[506699,506778],[509e3,509999],627780,636297,636368,[650031,650033],[650035,650051],[650405,650439],[650485,650538],[650541,650598],[650700,650718],[650720,650727],[650901,650978],[651652,651679],[655e3,655019],[655021,655058]],gaps:[4,8,12],lengths:[16],code:{name:"CVE",size:3}},mir:{niceType:"Mir",type:"mir",patterns:[[2200,2204]],gaps:[4,8,12],lengths:[16,17,18,19],code:{name:"CVP2",size:3}},hiper:{niceType:"Hiper",type:"hiper",patterns:[637095,63737423,63743358,637568,637599,637609,637612],gaps:[4,8,12],lengths:[16],code:{name:"CVC",size:3}},hipercard:{niceType:"Hipercard",type:"hipercard",patterns:[606282],gaps:[4,8,12],lengths:[16],code:{name:"CVC",size:3}},verve:{niceType:"Verve",type:"verve",patterns:[[506099,506127],506129,[506133,506150],[506158,506163],506166,506168,506170,506173,[506176,506180],506184,[506187,506188],506191,506195,506197,507865,507866,[507868,507877],[507880,507888],507900,507941],gaps:[4,8,12],lengths:[16,18,19],code:{name:"CVV",size:3}}}),n=function(){if(St)return vt;St=1,Object.defineProperty(vt,"__esModule",{value:!0}),vt.addMatchingCardsToResults=function(n,r,o){var a,i;for(a=0;a<r.patterns.length;a++){var c=r.patterns[a];if((0,t.matches)(n,c)){var s=(0,e.clone)(r);i=Array.isArray(c)?String(c[0]).length:String(c).length,n.length>=i&&(s.matchStrength=i),o.push(s);break}}};var e=wt(),t=(xt||(xt=1,Object.defineProperty(Ot,"__esModule",{value:!0}),Ot.matches=function(e,t){return Array.isArray(t)?function(e,t,n){var r=String(t).length,o=e.substr(0,r),a=parseInt(o,10);return t=parseInt(String(t).substr(0,o.length),10),n=parseInt(String(n).substr(0,o.length),10),a>=t&&a<=n}(e,t[0],t[1]):function(e,t){return(t=String(t)).substring(0,e.length)===e.substring(0,t.length)}(e,t)}),Ot);return vt}(),r=(Et||(Et=1,Object.defineProperty(_t,"__esModule",{value:!0}),_t.isValidInputType=function(e){return"string"==typeof e||e instanceof String}),_t),o=(Ct||(Ct=1,Object.defineProperty(jt,"__esModule",{value:!0}),jt.findBestMatch=function(e){return function(e){var t=e.filter(function(e){return e.matchStrength}).length;return t>0&&t===e.length}(e)?e.reduce(function(e,t){return e?Number(e.matchStrength)<Number(t.matchStrength)?t:e:t}):null}),jt),a=wt(),i={},c={VISA:"visa",MASTERCARD:"mastercard",AMERICAN_EXPRESS:"american-express",DINERS_CLUB:"diners-club",DISCOVER:"discover",JCB:"jcb",UNIONPAY:"unionpay",VERVE:"verve",MAESTRO:"maestro",ELO:"elo",MIR:"mir",HIPER:"hiper",HIPERCARD:"hipercard"},s=[c.VISA,c.MASTERCARD,c.AMERICAN_EXPRESS,c.DINERS_CLUB,c.DISCOVER,c.JCB,c.UNIONPAY,c.VERVE,c.MAESTRO,c.ELO,c.MIR,c.HIPER,c.HIPERCARD],l=(0,a.clone)(s);function u(e){return i[e]||t[e]}function d(e,t){void 0===t&&(t=!1);var n=l.indexOf(e);if(!t&&-1===n)throw new Error('"'+e+'" is not a supported card type.');return n}function p(e){var t=[];if(!(0,r.isValidInputType)(e))return t;if(0===e.length)return l.map(function(e){return(0,a.clone)(u(e))});l.forEach(function(r){var o=u(r);(0,n.addMatchingCardsToResults)(e,o,t)});var i=(0,o.findBestMatch)(t);return i?[i]:t}return p.getTypeInfo=function(e){return(0,a.clone)(u(e))},p.removeCard=function(e){var t=d(e);l.splice(t,1)},p.addCard=function(e){var t=d(e.type,!0);i[e.type]=e,-1===t&&l.push(e.type)},p.updateCard=function(n,r){var o=i[n]||t[n];if(!o)throw new Error('"'.concat(n,"\" is not a recognized type. Use `addCard` instead.'"));if(r.type&&o.type!==r.type)throw new Error("Cannot overwrite type parameter.");var c=(0,a.clone)(o);c=e(e({},c),r),i[c.type]=c},p.changeOrder=function(e,t){var n=d(e);l.splice(n,1),l.splice(t,0,e)},p.resetModifications=function(){l=(0,a.clone)(s),i={}},p.types=c,kt=p}var It,Nt,Tt,Mt,Ft,Rt={},$t={},Dt={},Vt={},Lt={};function Bt(){if(Ft)return Lt;Ft=1,Object.defineProperty(Lt,"__esModule",{value:!0}),Lt.expirationYear=function(n,r){var o;if(void 0===r&&(r=e),"string"!=typeof n)return t(!1,!1);if(""===n.replace(/\s/g,""))return t(!1,!0);if(!/^\d*$/.test(n))return t(!1,!1);var a=n.length;if(a<2)return t(!1,!0);var i=(new Date).getFullYear();if(3===a)return t(!1,n.slice(0,2)===String(i).slice(0,2));if(a>4)return t(!1,!1);var c=parseInt(n,10),s=Number(String(i).substr(2,2)),l=!1;if(2===a){if(String(i).substr(0,2)===n)return t(!1,!0);o=s===c,l=c>=s&&c<=s+r}else 4===a&&(o=i===c,l=c>=i&&c<=i+r);return t(l,l,o)};var e=19;function t(e,t,n){return{isValid:e,isPotentiallyValid:t,isCurrentYear:n||!1}}return Lt}var zt,Ut,qt,Wt,Yt={},Ht={};function Jt(){if(qt)return Ht;function e(e,t,n){return{isValid:e,isPotentiallyValid:t,isValidForThisYear:n||!1}}return qt=1,Object.defineProperty(Ht,"__esModule",{value:!0}),Ht.expirationMonth=function(t){var n=(new Date).getMonth()+1;if("string"!=typeof t)return e(!1,!1);if(""===t.replace(/\s/g,"")||"0"===t)return e(!1,!0);if(!/^\d*$/.test(t))return e(!1,!1);var r=parseInt(t,10);if(isNaN(Number(t)))return e(!1,!1);var o=r>0&&r<13;return e(o,o,o&&r>=n)},Ht}var Kt,Xt,Zt,Gt,Qt={},en={};const tn=L(function(){if(Gt)return Zt;Gt=1;var e=Zt&&Zt.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),t=Zt&&Zt.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),n=(Zt&&Zt.__importStar||function(){var n=function(e){return(n=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n);return t})(e)};return function(r){if(r&&r.__esModule)return r;var o={};if(null!=r)for(var a=n(r),i=0;i<a.length;i++)"default"!==a[i]&&e(o,r,a[i]);return t(o,r),o}}())(At()),r=function(){if(It)return Rt;It=1,Object.defineProperty(Rt,"__esModule",{value:!0}),Rt.cardholderName=function(r){return"string"!=typeof r?n(!1,!1):0===r.length?n(!1,!0):r.length>t?n(!1,!1):e.test(r)?n(!1,!0):n(!0,!0)};var e=/^[\d\s-]*$/,t=255;function n(e,t){return{isValid:e,isPotentiallyValid:t}}return Rt}(),o=function(){if(Mt)return $t;Mt=1,Object.defineProperty($t,"__esModule",{value:!0}),$t.cardNumber=function(r,o){var a,i;if(void 0===o&&(o={}),"string"!=typeof r&&"number"!=typeof r)return n(null,!1,!1);var c=String(r).replace(/-|\s/g,"");if(!/^\d*$/.test(c))return n(null,!1,!1);var s=t(c);if(0===s.length)return n(null,!1,!1);if(1!==s.length)return n(null,!0,!1);var l=s[0];if(o.maxLength&&c.length>o.maxLength)return n(l,!1,!1);a=!0===o.skipLuhnValidation||l.type===t.types.UNIONPAY&&!0!==o.luhnValidateUnionPay||e(c),i=Math.max.apply(null,l.lengths),o.maxLength&&(i=Math.min(o.maxLength,i));for(var u=0;u<l.lengths.length;u++)if(l.lengths[u]===c.length)return n(l,c.length<i||a,a);return n(l,c.length<i,!1)};var e=Tt?Nt:(Tt=1,Nt=function(e){for(var t,n=0,r=!1,o=e.length-1;o>=0;)t=parseInt(e.charAt(o),10),r&&(t*=2)>9&&(t=t%10+1),r=!r,n+=t,o--;return n%10==0}),t=At();function n(e,t,n){return{card:e,isPotentiallyValid:t,isValid:n}}return $t}(),a=function(){if(Wt)return Dt;Wt=1;var e=Dt&&Dt.__assign||function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)};Object.defineProperty(Dt,"__esModule",{value:!0}),Dt.expirationDate=function(a,i){var c;if("string"==typeof a)a=a.replace(/^(\d\d) (\d\d(\d\d)?)$/,"$1/$2"),c=(0,t.parseDate)(String(a));else{if(null===a||"object"!=typeof a)return o(!1,!1,null,null);var s=e({},a);c={month:String(s.month),year:String(s.year)}}var l=(0,n.expirationMonth)(c.month),u=(0,r.expirationYear)(c.year,i);if(l.isValid){if(u.isCurrentYear){var d=l.isValidForThisYear;return o(d,d,c.month,c.year)}if(u.isValid)return o(!0,!0,c.month,c.year)}return o(!1,!(!l.isPotentiallyValid||!u.isPotentiallyValid),null,null)};var t=function(){if(Ut)return Vt;Ut=1,Object.defineProperty(Vt,"__esModule",{value:!0}),Vt.parseDate=function(n){var r;if(/^\d{4}-\d{1,2}$/.test(n)?r=n.split("-").reverse():/\//.test(n)?r=n.split(/\s*\/\s*/g):/\s/.test(n)&&(r=n.split(/ +/g)),(0,t.isArray)(r))return{month:r[0]||"",year:r.slice(1).join()};var o,a,i,c=(o=n,0===(i=Number(o[0]))?2:i>1||1===i&&Number(o[1])>2?1:1===i?(a=o.substr(1),(0,e.expirationYear)(a).isPotentiallyValid?1:2):5===o.length?1:o.length>5?2:1),s=n.substr(0,c);return{month:s,year:n.substr(s.length)}};var e=Bt(),t=(zt||(zt=1,Object.defineProperty(Yt,"__esModule",{value:!0}),Yt.isArray=void 0,Yt.isArray=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)}),Yt);return Vt}(),n=Jt(),r=Bt();function o(e,t,n,r){return{isValid:e,isPotentiallyValid:t,month:n,year:r}}return Dt}(),i=Jt(),c=Bt(),s=function(){if(Kt)return Qt;Kt=1,Object.defineProperty(Qt,"__esModule",{value:!0}),Qt.cvv=function(n,r){return void 0===r&&(r=e),r=r instanceof Array?r:[r],"string"!=typeof n?t(!1,!1):/^\d*$/.test(n)?function(e,t){for(var n=0;n<e.length;n++)if(t===e[n])return!0;return!1}(r,n.length)?t(!0,!0):n.length<Math.min.apply(null,r)?t(!1,!0):n.length>function(t){for(var n=e,r=0;r<t.length;r++)n=t[r]>n?t[r]:n;return n}(r)?t(!1,!1):t(!0,!0):t(!1,!1)};var e=3;function t(e,t){return{isValid:e,isPotentiallyValid:t}}return Qt}(),l=function(){if(Xt)return en;Xt=1,Object.defineProperty(en,"__esModule",{value:!0}),en.postalCode=function(r,o){void 0===o&&(o={});var a=o.minLength||e;return"string"!=typeof r?n(!1,!1):r.length<a?n(!1,!0):t.test(r.trim().slice(0,a))?n(!0,!0):n(!1,!0)};var e=2,t=new RegExp(/^[a-z0-9]+$/i);function n(e,t){return{isValid:e,isPotentiallyValid:t}}return en}();return Zt={creditCardType:n,cardholderName:r.cardholderName,number:o.cardNumber,expirationDate:a.expirationDate,expirationMonth:i.expirationMonth,expirationYear:c.expirationYear,cvv:s.cvv,postalCode:l.postalCode}}()),nn=L(At());let rn=!1;rn||(rn=!0,nn.addCard({niceType:"Mada",type:"mada",patterns:[440647,440795,446404,446672,419593,428331,428671,432328,440533,446393,457865,458456,462220,484783,484800,493428,504300,521076,529415,535825,536023,537767,543357,557606,558848,588845,589206],gaps:[4,8,12],lengths:[16,18,19],code:{name:"CVV",size:3}}));const on=({brand:t,fallbackColor:n,height:r=22})=>{if(!t)return null;switch(t){case"Visa":return e(an,{height:r});case"Mastercard":return e(cn,{height:r});case"American Express":return e(sn,{height:r});case"Mada":return e(ln,{height:r});case"Discover":return e(un,{height:r});case"JCB":return e(dn,{height:r});default:return e("span",{className:"text-xs font-medium",style:{color:n},"aria-label":`Card brand: ${t}`,children:t})}},an=({height:n})=>t("svg",{role:"img","aria-label":"Visa",viewBox:"0 0 48 16",height:n,width:48*n/16,style:{display:"block"},children:[e("rect",{width:"48",height:"16",rx:"2",fill:"#1A1F71"}),e("text",{x:"24",y:"12",textAnchor:"middle",fontFamily:"Helvetica, Arial, sans-serif",fontWeight:"900",fontSize:"11",fill:"#FFFFFF",letterSpacing:"1.4",children:"VISA"})]}),cn=({height:n})=>t("svg",{role:"img","aria-label":"Mastercard",viewBox:"0 0 32 20",height:n,width:32*n/20,style:{display:"block"},children:[e("circle",{cx:"12",cy:"10",r:"7",fill:"#EB001B"}),e("circle",{cx:"20",cy:"10",r:"7",fill:"#F79E1B"}),e("path",{d:"M16 4.5a7 7 0 0 1 0 11 7 7 0 0 1 0-11Z",fill:"#FF5F00","aria-hidden":"true"})]}),sn=({height:n})=>t("svg",{role:"img","aria-label":"American Express",viewBox:"0 0 48 16",height:n,width:48*n/16,style:{display:"block"},children:[e("rect",{width:"48",height:"16",rx:"2",fill:"#2E77BB"}),e("text",{x:"24",y:"11.5",textAnchor:"middle",fontFamily:"Helvetica, Arial, sans-serif",fontWeight:"700",fontSize:"9",fill:"#FFFFFF",letterSpacing:"0.4",children:"AMEX"})]}),ln=({height:n})=>t("svg",{role:"img","aria-label":"Mada",viewBox:"0 0 48 16",height:n,width:48*n/16,style:{display:"block"},children:[e("rect",{width:"48",height:"16",rx:"2",fill:"#84B740"}),e("text",{x:"24",y:"11.5",textAnchor:"middle",fontFamily:"Helvetica, Arial, sans-serif",fontWeight:"700",fontSize:"9",fill:"#FFFFFF",letterSpacing:"0.6",children:"mada"})]}),un=({height:n})=>t("svg",{role:"img","aria-label":"Discover",viewBox:"0 0 56 16",height:n,width:56*n/16,style:{display:"block"},children:[e("rect",{width:"56",height:"16",rx:"2",fill:"#FFFFFF",stroke:"#E5E7EB"}),e("text",{x:"20",y:"11.5",textAnchor:"middle",fontFamily:"Helvetica, Arial, sans-serif",fontWeight:"700",fontSize:"8",fill:"#231F20",letterSpacing:"0.2",children:"DISCOVER"}),e("circle",{cx:"44",cy:"8",r:"4",fill:"#FF6000"})]}),dn=({height:n})=>t("svg",{role:"img","aria-label":"JCB",viewBox:"0 0 32 16",height:n,width:32*n/16,style:{display:"block"},children:[e("rect",{x:"0",y:"0",width:"10.66",height:"16",rx:"2",fill:"#0E4C96"}),e("rect",{x:"10.66",y:"0",width:"10.66",height:"16",fill:"#B41E25"}),e("rect",{x:"21.33",y:"0",width:"10.66",height:"16",rx:"2",fill:"#1B8A3A"}),e("text",{x:"16",y:"11",textAnchor:"middle",fontFamily:"Helvetica, Arial, sans-serif",fontWeight:"900",fontSize:"9",fill:"#FFFFFF",children:"JCB"})]}),pn=({skin:r})=>{const{paymentInit:o}=Rn(),a=o&&"moyasar"===o.provider?o:null,u=Be(),d=ze(),f=Ue(),[m,y]=i(""),[g,v]=i(""),[b,w]=i(""),[x,S]=i(""),[E,C]=i(!1),[k,P]=i({}),[O,_]=i(null),j=c({number:m,expiry:g,cvc:b,name:x});j.current={number:m,expiry:g,cvc:b,name:x};const A=c(u);A.current=u,p(()=>{a&&f({amount:a.config.amount,currency:a.config.currency.toUpperCase()})},[a,f]);const I=s(async()=>{if(!a)return;const e=function(e,t=new Date){const n=[],r=tn.number(e.number),o=e.number.replace(/\D/g,"");o?r.isValid||n.push({field:"number",message:"Invalid card number"}):n.push({field:"number",message:"Card number is required"});const a=tn.expirationDate(e.expiry);let i=null,c=null;const s=e.expiry.trim();if(s)if(a.isValid){i=Number.parseInt(a.month??"",10);const e=Number.parseInt(a.year??"",10);c=2===(a.year??"").length?e+2e3:e}else{const e=function(e){let t="",n="";if(e.includes("/")){const[r,o]=e.split("/");t=(r??"").replace(/\D/g,""),n=(o??"").replace(/\D/g,"")}else{const r=e.replace(/\D/g,"");t=r.slice(0,2),n=r.slice(2)}const r=Number.parseInt(t,10),o=Number.parseInt(n,10);return Number.isNaN(r)||Number.isNaN(o)?null:{month:r,year:2===n.length?o+2e3:o}}(s);e&&function(e,t,n){const r=n.getFullYear(),o=n.getMonth()+1;return t<r||t===r&&e<o}(e.month,e.year,t)?n.push({field:"expiry",message:"Card expired"}):n.push({field:"expiry",message:"Invalid expiry"})}else n.push({field:"expiry",message:"Expiry is required"});const l=tn.cvv(e.cvc,r.card?.code.size??[3,4]),u=e.cvc.replace(/\D/g,"");u?l.isValid||n.push({field:"cvc",message:"Invalid CVC"}):n.push({field:"cvc",message:"CVC is required"});const d=tn.cardholderName(e.name),p=e.name.trim();return p?d.isValid||n.push({field:"name",message:"Invalid cardholder name"}):n.push({field:"name",message:"Cardholder name is required"}),n.length>0||null==i||null==c?{ok:!1,errors:n}:{ok:!0,card:{number:o,month:String(i).padStart(2,"0"),year:String(c),cvc:u,name:p}}}(j.current);if(!1===e.ok){const t={};for(const n of e.errors)t[n.field]||(t[n.field]=n.message);return void P(t)}P({}),C(!0);try{const t=await async function(e){const t=await st("https://api.moyasar.com/v1/tokens",{...e,save_only:!0});if(!t.ok)throw new it(lt(t.body)??`Tokenization failed (${t.status})`,t.status,t.body);const n=t.body;if(!n||"string"!=typeof n.id)throw new it("Tokenization returned no token id",t.status,n);return{id:n.id}}({publishable_api_key:a.config.publishable_key,name:e.card.name,number:e.card.number,month:e.card.month,year:e.card.year,cvc:e.card.cvc}),n=at(a),r=await ct({publishable_api_key:a.config.publishable_key,given_id:a.config.given_id,amount:a.config.amount,currency:a.config.currency.toUpperCase(),description:a.config.description,callback_url:h(a.config.given_id),source:{type:"token",token:t.id},...Object.keys(n).length>0?{metadata:n}:{}}),o=r.source?.transaction_url??r.transaction_url;if(o)return void _(o);const i=r.status;A.current("paid"===i||"authorized"===i||"captured"===i?{status:"success",provider:"moyasar",paymentId:r.id,amount:r.amount,currency:r.currency}:"failed"===i?{status:"failure",provider:"moyasar",code:"failed",message:r.source?.message??"Payment failed",paymentId:r.id}:{status:"failure",provider:"moyasar",code:i,message:`Unexpected payment status: ${i}`,paymentId:r.id})}catch(e){const t=e instanceof it||e instanceof Error?e.message:"Payment failed";A.current({status:"failure",provider:"moyasar",message:t,paymentId:a.config.given_id})}finally{C(!1)}},[a]);p(()=>(d({confirm:I,isConfirming:E}),()=>d(null)),[I,E,d]);const N=l(()=>Math.max(r.radius-4,4),[r.radius]),T=l(()=>function(e){const t=e.replace(/\D/g,"");if(t.length<2)return null;const n=nn(t);return n[0]?.niceType??null}(m),[m]);return a?t(n,{children:[t("div",{className:"space-y-3",style:{fontFamily:r.fontFamily},children:[e(mn,{label:"Card number",value:m,onChange:e=>y(e.replace(/\D/g,"").slice(0,19).replace(/(\d{4})(?=\d)/g,"$1 ")),autoComplete:"cc-number",inputMode:"numeric",placeholder:"1234 5678 9012 3456",error:k.number,skin:r,radius:N,endAdornment:T?e(on,{brand:T,fallbackColor:r.muted}):null}),t("div",{className:"grid grid-cols-2 gap-3",children:[e(mn,{label:"Expiry",value:g,onChange:e=>v(function(e){const t=e.replace(/\D/g,"").slice(0,4);return t.length<=2?t:`${t.slice(0,2)}/${t.slice(2)}`}(e)),autoComplete:"cc-exp",inputMode:"numeric",placeholder:"MM / YY",error:k.expiry,skin:r,radius:N}),e(mn,{label:"CVC",value:b,onChange:e=>w(e.replace(/\D/g,"").slice(0,4)),autoComplete:"cc-csc",inputMode:"numeric",placeholder:"123",error:k.cvc,skin:r,radius:N})]}),e(mn,{label:"Name on card",value:x,onChange:S,autoComplete:"cc-name",inputMode:"text",placeholder:"Full name",error:k.name,skin:r,radius:N})]}),O&&e(dt,{url:O,skin:r,onResult:e=>{_(null),A.current(e)}})]}):null};function fn(e){let t=0;for(let n=0;n<e.length;n++){const r=e.charCodeAt(n);r>=48&&r<=57&&t++}return t}const mn=({label:n,value:r,onChange:o,placeholder:a,autoComplete:i,inputMode:s,error:l,skin:u,radius:d,endAdornment:p})=>{const m=l?"#dc2626":u.divider,y=c(null),h=c(null),g="numeric"===s;return f(()=>{const e=h.current;if(null===e||!y.current)return;h.current=null;const t=y.current.value;let n=0,r=0;for(;r<t.length&&!(n>=e);)/\d/.test(t[r])&&n++,r++;y.current.setSelectionRange(r,r)},[r]),t("label",{className:"block",children:[e("span",{className:"block text-xs mb-1",style:{color:u.muted},children:n}),t("div",{className:"relative",children:[e("input",{ref:y,type:"text",value:r,onChange:e=>{g&&(h.current=fn(e.target.value.slice(0,e.target.selectionStart??e.target.value.length))),o(e.target.value)},onKeyDown:e=>{if(!g||"Backspace"!==e.key)return;const t=e.currentTarget,n=t.selectionStart??0;if(n!==(t.selectionEnd??0)||n<2)return;const r=t.value[n-1];if(!r||/\d/.test(r))return;e.preventDefault();const a=t.value.slice(0,n-2)+t.value.slice(n);h.current=fn(a.slice(0,n-2)),o(a)},placeholder:a,autoComplete:i,inputMode:s,spellCheck:!1,className:"w-full py-3 px-3 outline-none text-sm transition-colors",style:{background:u.pillBg,color:u.text,border:`1px solid ${m}`,borderRadius:d,paddingRight:p?96:void 0}}),p&&e("span",{className:"absolute right-3 top-1/2 -translate-y-1/2 text-xs font-medium pointer-events-none",style:{color:u.muted},"aria-label":"Card brand",children:p})]}),l&&e("span",{className:"block mt-1 text-xs",style:{color:"#dc2626"},children:l})]})},yn=["creditcard","applepay"],hn=({skin:n})=>t("div",{className:"relative",children:[e("div",{className:"absolute inset-x-0 top-1/2",style:{borderTop:`1px solid ${n.divider}`}}),e("div",{className:"relative flex justify-center",children:e("span",{className:"px-2 text-xs uppercase tracking-wide",style:{background:n.cardBg,color:n.muted,fontFamily:n.fontFamily},children:"or"})})]}),gn={type:"moyasar",label:"Moyasar",FormComponent:({skin:n,onReady:r})=>{const{paymentInit:o}=Rn(),a=o&&"moyasar"===o.provider?o:null,s=function(){const[e,t]=i(!1);return p(()=>{if("undefined"==typeof window)return;const e=window.ApplePaySession;if(e&&"function"==typeof e.canMakePayments)try{t(!0===e.canMakePayments())}catch{t(!1)}},[]),e}(),l=c(r);if(l.current=r,p(()=>{l.current?.()},[]),!a)return null;const u=a.config.methods??yn,d=u.includes("creditcard"),f=u.includes("applepay")&&s;return t("div",{className:"space-y-4",children:[d&&e(pn,{skin:n}),d&&f&&e(hn,{skin:n}),f&&e(mt,{skin:n})]})}},vn="5vh",bn="5vw",wn="aiatcore-chargebee-modal-style",xn="aiatcore-chargebee-close-button",Sn="aiatcore-chargebee-loader",En="aiatcore-cb-spin",Cn='#cb-container, .cb-container, [id^="cb-modal"], [class*="cb-modal"], [class*="cb-checkout"], div[class*="cb-"][class*="overlay"]',kn="aiatcore-chargebee-open";function Pn(){document.getElementById(xn)?.remove()}function On(){document.getElementById(Sn)?.remove()}const _n={type:"chargebee",label:"Chargebee",FormComponent:({amount:e,currency:t,onReady:n})=>{const{paymentInit:r}=Rn(),o=Be(),a=Ue(),i=ze(),s=c(!1);return p(()=>(i(null),()=>i(null)),[i]),p(()=>{if("chargebee"!==r?.provider)return;const{site:i,hosted_page_url:c,amount:l,currency:u,expires_at:d}=r.config,p=l??e,f=u??t;null!=p&&f&&a({amount:p,currency:f}),s.current=!1;let m=!1,y=null,h=null;const g=e=>{s.current||(s.current=!0,o(e))};return n?.(),null!=d&&Date.now()>=1e3*d?(g({status:"failure",provider:"chargebee",message:"Payment link has expired. Please request a new one."}),()=>{m=!0}):(function(){const e=document.getElementById(wn)??document.createElement("style");e.id=wn,e.textContent=`\n /* Prevent horizontal page scroll only while Chargebee's overlay is mounted */\n html.${kn}, body.${kn} {\n overflow-x: hidden !important;\n }\n\n /* Outer Chargebee overlay container — broad selector net so we catch\n whatever wrapper Chargebee actually uses */\n #cb-container,\n .cb-container,\n [id^="cb-modal"],\n [class*="cb-modal"],\n [class*="cb-checkout"],\n div[class*="cb-"][class*="overlay"] {\n position: fixed !important;\n inset: ${vn} max(${bn}, calc((100vw - 1500px) / 2)) !important;\n width: auto !important;\n height: auto !important;\n max-width: none !important;\n max-height: none !important;\n margin: 0 !important;\n border-radius: 12px !important;\n box-shadow: 0 20px 60px rgba(0,0,0,0.35) !important;\n overflow: hidden !important;\n z-index: 2147483646 !important;\n pointer-events: all !important;\n }\n\n /* Inner iframe — fill the container fully and ensure it receives clicks */\n [id^="cb-frame"] {\n width: 100% !important;\n height: 100% !important;\n border: none !important;\n display: block !important;\n z-index: 2147483646 !important;\n pointer-events: all !important;\n outline: none !important;\n box-shadow: none !important;\n }\n\n @keyframes ${En} {\n to { transform: rotate(360deg); }\n }\n `,e.parentElement||document.head.appendChild(e),document.documentElement.classList.add(kn),document.body.classList.add(kn)}(),function(e){if(window.Chargebee)return Promise.resolve();const t=document.querySelector('script[src*="js.chargebee.com"]');return t?"1"===t.dataset.cbLoaded?Promise.resolve():new Promise((e,n)=>{t.addEventListener("load",()=>e()),t.addEventListener("error",()=>n(new Error("Chargebee.js failed to load")))}):new Promise((t,n)=>{const r=document.createElement("script");r.src="https://js.chargebee.com/v2/chargebee.js",r.setAttribute("data-cb-site",e),r.onload=()=>{r.dataset.cbLoaded="1",t()},r.onerror=()=>n(new Error("Chargebee.js failed to load")),document.head.appendChild(r)})}(i).then(()=>{if(m)return;let e;try{e=window.Chargebee.getInstance()??window.Chargebee.init({site:i})}catch{e=window.Chargebee.init({site:i})}e.openCheckout({hostedPage:()=>Promise.resolve({id:r.payment_id,url:c,type:"checkout_one_time",state:"created"}),success:e=>{Pn(),On(),g({status:"success",provider:"chargebee",paymentId:e,amount:p??void 0,currency:f??void 0})},close:()=>{Pn(),On(),g({status:"cancel",provider:"chargebee"})},error:e=>{Pn(),On(),g({status:"failure",provider:"chargebee",message:e?.message??"Payment failed"})}}),h=function(){let e=0,t=0,n=0,r=null,o=null;const a=Date.now()+5e3,i=()=>{if(m||s.current)return;const t=document.querySelector(Cn);if(t instanceof HTMLElement){const e=t.getBoundingClientRect();if(e.width>0&&e.height>0){!function(){On();const e=document.createElement("div");e.id=Sn,e.setAttribute("aria-live","polite"),e.setAttribute("aria-busy","true"),e.style.cssText=`\n position: fixed;\n inset: ${vn} max(${bn}, calc((100vw - 1500px) / 2));\n z-index: 2147483646;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n gap: 14px;\n background: #f8f8f8;\n border-radius: 12px;\n color: #6b7280;\n font: 500 14px/1.4 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;\n pointer-events: none;\n `;const t=document.createElement("div");t.style.cssText=`\n width: 32px;\n height: 32px;\n border: 2.5px solid rgba(17, 24, 39, 0.08);\n border-top-color: #6366f1;\n border-radius: 50%;\n animation: ${En} 0.8s linear infinite;\n `;const n=document.createElement("p");n.textContent="Loading payment…",n.style.cssText="margin: 0;",e.appendChild(t),e.appendChild(n),document.body.appendChild(e)}();const e=document.querySelector('[id^="cb-frame"]');return void(e instanceof HTMLIFrameElement&&(r=e,o=()=>{n=window.setTimeout(On,400)},r.addEventListener("load",o)))}}Date.now()>=a||(e=window.requestAnimationFrame(i))};return t=window.setTimeout(i,100),()=>{window.clearTimeout(t),window.clearTimeout(n),e&&window.cancelAnimationFrame(e),r&&o&&r.removeEventListener("load",o),On()}}(),y=function(e){let t=0,n=0;const r=Date.now()+5e3,o=()=>{if(m||s.current)return;const n=document.querySelector(Cn);if(n instanceof HTMLElement){const t=n.getBoundingClientRect();if(t.width>0&&t.height>0)return void function(e){Pn();const t=document.createElement("button");t.id=xn,t.type="button",t.setAttribute("aria-label","Close payment"),t.textContent="×",t.style.cssText=`\n position: fixed;\n top: calc(${vn} + 12px);\n right: calc(max(${bn}, calc((100vw - 1500px) / 2)) + 12px);\n z-index: 2147483647;\n width: 32px;\n height: 32px;\n border: 0;\n border-radius: 9999px;\n background: rgba(17, 24, 39, 0.72);\n color: #ffffff;\n font: 600 16px/1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;\n cursor: pointer;\n pointer-events: auto;\n display: flex;\n align-items: center;\n justify-content: center;\n box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);\n `,t.addEventListener("click",e),document.body.appendChild(t)}(e)}Date.now()>=r||(t=window.requestAnimationFrame(o))};return n=window.setTimeout(o,100),()=>{window.clearTimeout(n),t&&window.cancelAnimationFrame(t)}}(()=>{Pn(),On(),document.querySelectorAll(Cn).forEach(e=>{e instanceof HTMLElement&&(e.style.display="none")}),g({status:"cancel",provider:"chargebee"});try{e.closeAll()}catch{}})}).catch(e=>{g({status:"failure",provider:"chargebee",message:e?.message??"Failed to load payment form"})}),()=>{m=!0,y?.(),h?.(),Pn(),On(),document.documentElement.classList.remove(kn),document.body.classList.remove(kn),document.getElementById(wn)?.remove();try{window.Chargebee?.getInstance?.()?.closeAll?.()}catch{}})},[r,e,t,a,n,o]),null},hideShellSubmit:!0},jn="atb-payment";function An(){const e=document.createElement("div");e.style.cssText="position:absolute;top:-9999px;width:100px;height:100px;overflow:scroll;",document.body.appendChild(e);const t=e.offsetWidth-e.clientWidth;return e.remove(),Math.max(0,t)}const In=({init:n,onResult:r,skin:o})=>{const a=c(null),u=c(!1),d=c(!1),[f,m]=i(!1),[y]=i(An),h=l(()=>g(n.config.url),[n.config.url]),O=n.payment_id,_=s((e,t={})=>{u.current||(u.current=!0,N.info({message:"[atb] outcome",api_name:jn,reference_id:O,outcome:e}),r(v({outcome:e,init:n,...t})))},[n,O,r]),j=s(()=>{d.current=!0,m(!0)},[]);return p(()=>{if(!h)return;const e=e=>{if(e.source!==a.current?.contentWindow)return;if(e.origin!==h)return;if(!S(e.data))return;const{type:t,data:n}=e.data,r=t===E.COMPLETED?C(n):{};switch(N.info({message:"[atb] gateway event",api_name:jn,reference_id:O,type:t,status:r.status??null,checkout_id:r.checkoutId??null}),t){case E.READY:return void j();case E.COMPLETED:return void _(P(r.status),{checkoutId:r.checkoutId});case E.ERROR:return void _(b.FAILED,{message:x.SESSION_INVALID,code:w.SESSION_INVALID});case E.REDIRECT:{const e=k(n);if(!e)return void N.warn({message:"ATB wallet redirect carried no https url",api_name:jn});N.info({message:"[atb] wallet redirect in frame",api_name:jn,reference_id:O}),a.current&&(a.current.src=e)}}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[h,O,j,_]),p(()=>{const e=setTimeout(()=>{d.current||_(b.FAILED,{message:x.LOAD_FAILED,code:w.LOAD_FAILED})},6e4);return()=>clearTimeout(e)},[_]),e("div",{className:"absolute inset-0 z-[105] flex flex-col overflow-hidden",style:{background:o.cardBg},role:"region","aria-label":"Payment",children:t("div",{className:"relative flex min-h-0 flex-1 overflow-hidden",children:[!f&&e("div",{className:"absolute inset-0 flex items-center justify-center text-sm",style:{color:o.muted,fontFamily:o.fontFamily},children:"Loading…"}),e("iframe",{ref:a,src:n.config.url,title:"Payment",className:"min-h-0 flex-1 "+(f?"":"invisible"),style:{border:0,background:"white",width:`calc(100% + ${y}px)`},allow:"payment",referrerPolicy:"no-referrer"})]})})},Nn=({init:t,skin:n})=>{const r=Be(),[o]=i(()=>!O(t.config.url)),a=c(!1);return p(()=>{o&&!a.current&&(a.current=!0,N.warn({message:"ATB checkout url is not https",api_name:"atb-payment",reference_id:t.payment_id}),r(v({outcome:b.FAILED,init:t,message:x.SESSION_INVALID,code:w.SESSION_INVALID})))},[o,t,r]),o?null:e(In,{init:t,onResult:r,skin:n})},Tn={type:"atb",label:"ATB",hideShellSubmit:!0,hideShellFooter:!0,FormComponent:({skin:t,onReady:n})=>{const{paymentInit:r}=Rn(),o="atb"===r?.provider?r:null;return p(()=>{n?.()},[n]),o?e(Nn,{init:o,skin:t},o.payment_id):null}},Mn=u(void 0),Fn=({children:t,paymentProvider:n,paymentInit:r=null,conversationId:o=null})=>{const a=r?.provider||n||_,i=l(()=>function(e){switch(e){case"stripe":return ot;case"moyasar":return gn;case"chargebee":return _n;case"atb":return Tn;default:throw new Error(`Unknown payment provider: "${e}". Supported providers: stripe, moyasar, chargebee, atb`)}}(a),[a]),c=l(()=>({adapter:i,paymentProvider:a,paymentInit:r,conversationId:o}),[i,a,r,o]),s=i.ProviderWrapper;return e(Mn.Provider,{value:c,children:s?e(s,{children:t}):t})},Rn=()=>{const e=d(Mn);if(!e)throw new Error("usePaymentAdapter must be used within a PaymentProvider");return e},$n=({provider:t,paymentInit:n=null,onResult:r,conversationId:o=null})=>e(Fn,{paymentInit:n,conversationId:o,paymentProvider:T(),children:e(Ve,{onResult:e=>{r?.(e)},children:e(Dn,{provider:t,paymentInit:n})})},n?.provider??"default"),Dn=({provider:n,paymentInit:r})=>{const{themeStyles:o,theme:a}=A(),{adapter:c}=Rn(),u=Le().summary,[d,p]=i(!1),f=s(()=>p(!0),[]),y=l(()=>m(o,a),[o,a]),h="moyasar"===r?.provider?r.config:null,g="chargebee"===r?.provider?r.config:null,v=u?.amount??h?.amount??g?.amount??0,b=u?.currency??h?.currency??g?.currency??"usd",w=null!=u?.amount||null!=h?.amount||null!=g?.amount,x=((e,t)=>j(e,t)??"")(v,b),S=n??c.label,E=c.FormComponent;return t("div",{className:"w-full flex-1 min-h-0 overflow-y-auto [&::-webkit-scrollbar]:hidden [scrollbar-width:none] relative",style:{background:y.pageBg,color:y.text,fontFamily:y.fontFamily,colorScheme:y.colorScheme},children:[!d&&e(Vn,{skin:y}),e("div",{className:"min-h-full flex items-center justify-center p-4",style:{visibility:d?"visible":"hidden"},children:t("div",{className:"w-full max-w-lg p-6",style:{background:y.cardBg,borderRadius:y.radius,boxShadow:y.cardShadow,color:y.text},children:[e("h1",{className:"text-base font-semibold text-center mb-3.5",style:{color:y.heading},children:"Payment Options"}),e("div",{className:"mb-3.5",children:e(E,{amount:v,currency:b,skin:y,onReady:f})}),!c.hideShellSubmit&&w&&e(Ln,{label:`Pay ${x}`,background:o.statusDiscovery.solid,color:o.statusDiscovery.text,radius:y.radius}),!c.hideShellFooter&&t("p",{className:"text-xs text-center mt-2.5",style:{color:y.muted},children:["Powered by ",S]})]})})]})},Vn=({skin:n})=>t("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-3",style:{background:n.pageBg,color:n.text},"aria-live":"polite","aria-busy":"true",children:[e(V,{className:"h-8 w-8 animate-spin",style:{color:n.accent}}),e("p",{className:"text-sm",style:{color:n.muted},children:"Loading payment…"})]}),Ln=({label:t,background:n,color:r,radius:o})=>{const a=Le().confirmHandle;return e("button",{type:"button",onClick:()=>a?.confirm(),disabled:!a||a.isConfirming,className:"w-full p-3 text-sm font-semibold border-0 cursor-pointer disabled:cursor-not-allowed disabled:opacity-70",style:{background:n,color:r,borderRadius:o},children:a?.isConfirming?"Processing…":t})};export{$n as default};
package/dist/index.d.ts CHANGED
@@ -109,6 +109,7 @@ filename: string;
109
109
  mime_type: string;
110
110
  size_bytes: number;
111
111
  }[];
112
+ modelText?: string;
112
113
  }[];
113
114
  pendingTranscriptionIds: string[];
114
115
  };
@@ -213,6 +214,7 @@ filename: string;
213
214
  mime_type: string;
214
215
  size_bytes: number;
215
216
  }[];
217
+ modelText?: string;
216
218
  }[];
217
219
  pendingTranscriptionIds: string[];
218
220
  };
@@ -335,6 +337,7 @@ filename: string;
335
337
  mime_type: string;
336
338
  size_bytes: number;
337
339
  }[];
340
+ modelText?: string;
338
341
  }[];
339
342
  pendingTranscriptionIds: string[];
340
343
  };
@@ -440,6 +443,7 @@ filename: string;
440
443
  mime_type: string;
441
444
  size_bytes: number;
442
445
  }[];
446
+ modelText?: string;
443
447
  }[];
444
448
  pendingTranscriptionIds: string[];
445
449
  };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@reduxjs/toolkit"),t=require("@1interface/chat-core"),n=require("@1interface/shared-core"),r=require("@1interface/voice-core"),o=require("react/jsx-runtime"),s=require("react"),i=require("react-redux"),a=require("@1interface/voice-shell");var c=Symbol.for("immer-nothing"),u=Symbol.for("immer-draftable"),l=Symbol.for("immer-state"),d="production"!==process.env.NODE_ENV?[function(e){return`The plugin for '${e}' has not been loaded into Immer. To enable the plugin, import and call \`enable${e}()\` when initializing your application.`},function(e){return`produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${e}'`},"This object has been frozen and should not be mutated",function(e){return"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+e},"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.","Immer forbids circular references","The first or second argument to `produce` must be a function","The third argument to `produce` must be a function or undefined","First argument to `createDraft` must be a plain object, an array, or an immerable object","First argument to `finishDraft` must be a draft returned by `createDraft`",function(e){return`'current' expects a draft, got: ${e}`},"Object.defineProperty() cannot be used on an Immer draft","Object.setPrototypeOf() cannot be used on an Immer draft","Immer only supports deleting array indices","Immer only supports setting array indices and the 'length' property",function(e){return`'original' expects a draft, got: ${e}`}]:[];function p(e,...t){if("production"!==process.env.NODE_ENV){const n=d[e],r=N(n)?n.apply(null,t):n;throw new Error(`[Immer] ${r}`)}throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var f=Object,h=f.getPrototypeOf,_="constructor",m="prototype",y="configurable",g="enumerable",S="writable",E="value",v=e=>!!e&&!!e[l];function b(e){return!!e&&(w(e)||R(e)||!!e[u]||!!e[_]?.[u]||I(e)||D(e))}var A=f[m][_].toString(),P=new WeakMap;function w(e){if(!e||!k(e))return!1;const t=h(e);if(null===t||t===f[m])return!0;const n=f.hasOwnProperty.call(t,_)&&t[_];if(n===Object)return!0;if(!N(n))return!1;let r=P.get(n);return void 0===r&&(r=Function.toString.call(n),P.set(n,r)),r===A}function C(e,t,n=!0){0===M(e)?(n?Reflect.ownKeys(e):f.keys(e)).forEach(n=>{t(n,e[n],e)}):e.forEach((n,r)=>t(r,n,e))}function M(e){const t=e[l];return t?t.type_:R(e)?1:I(e)?2:D(e)?3:0}var T=(e,t,n=M(e))=>2===n?e.has(t):f[m].hasOwnProperty.call(e,t),O=(e,t,n=M(e))=>2===n?e.get(t):e[t],x=(e,t,n,r=M(e))=>{2===r?e.set(t,n):3===r?e.add(n):e[t]=n},R=Array.isArray,I=e=>e instanceof Map,D=e=>e instanceof Set,k=e=>"object"==typeof e,N=e=>"function"==typeof e,j=e=>"boolean"==typeof e,z=e=>e.copy_||e.base_,L=e=>e.modified_?e.copy_:e.base_;function F(e,t){if(I(e))return new Map(e);if(D(e))return new Set(e);if(R(e))return Array[m].slice.call(e);const n=w(e);if(!0===t||"class_only"===t&&!n){const t=f.getOwnPropertyDescriptors(e);delete t[l];let n=Reflect.ownKeys(t);for(let r=0;r<n.length;r++){const o=n[r],s=t[o];!1===s[S]&&(s[S]=!0,s[y]=!0),(s.get||s.set)&&(t[o]={[y]:!0,[S]:!0,[g]:s[g],[E]:e[o]})}return f.create(h(e),t)}{const t=h(e);if(null!==t&&n)return{...e};const r=f.create(t);return f.assign(r,e)}}function K(e,t=!1){return U(e)||v(e)||!b(e)||(M(e)>1&&f.defineProperties(e,{set:G,add:G,clear:G,delete:G}),f.freeze(e),t&&C(e,(e,t)=>{K(t,!0)},!1)),e}var G={[E]:function(){p(2)}};function U(e){return null===e||!k(e)||f.isFrozen(e)}var Y="MapSet",$="Patches",q="ArrayMethods",H={};function W(e){const t=H[e];return t||p(0,e),t}var B,V=e=>!!H[e],Q=()=>B;function X(e,t){t&&(e.patchPlugin_=W($),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function J(e){Z(e),e.drafts_.forEach(te),e.drafts_=null}function Z(e){e===B&&(B=e.parent_)}var ee=e=>B={drafts_:[],parent_:B,immer_:e,canAutoFreeze_:!0,unfinalizedDrafts_:0,handledSet_:new Set,processedForPatches_:new Set,mapSetPlugin_:V(Y)?W(Y):void 0,arrayMethodsPlugin_:V(q)?W(q):void 0};function te(e){const t=e[l];0===t.type_||1===t.type_?t.revoke_():t.revoked_=!0}function ne(e,t){t.unfinalizedDrafts_=t.drafts_.length;const n=t.drafts_[0];if(void 0!==e&&e!==n){n[l].modified_&&(J(t),p(4)),b(e)&&(e=re(t,e));const{patchPlugin_:r}=t;r&&r.generateReplacementPatches_(n[l].base_,e,t)}else e=re(t,n);return function(e,t,n=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&K(t,n)}(t,e,!0),J(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==c?e:void 0}function re(e,t){if(U(t))return t;const n=t[l];if(!n)return ue(t,e.handledSet_,e);if(!se(n,e))return t;if(!n.modified_)return n.base_;if(!n.finalized_){const{callbacks_:t}=n;if(t)for(;t.length>0;)t.pop()(e);ce(n,e)}return n.copy_}function oe(e){e.finalized_=!0,e.scope_.unfinalizedDrafts_--}var se=(e,t)=>e.scope_===t,ie=[];function ae(e,t,n,r){const o=z(e),s=e.type_;if(void 0!==r&&O(o,r,s)===t)return void x(o,r,n,s);if(!e.draftLocations_){const t=e.draftLocations_=new Map;C(o,(e,n)=>{if(v(n)){const r=t.get(n)||[];r.push(e),t.set(n,r)}})}const i=e.draftLocations_.get(t)??ie;for(const e of i)x(o,e,n,s)}function ce(e,t){if(e.modified_&&!e.finalized_&&(3===e.type_||1===e.type_&&e.allIndicesReassigned_||(e.assigned_?.size??0)>0)){const{patchPlugin_:n}=t;if(n){const r=n.getPath(e);r&&n.generatePatches_(e,r,t)}oe(e)}}function ue(e,t,n){return!n.immer_.autoFreeze_&&n.unfinalizedDrafts_<1||v(e)||t.has(e)||!b(e)||U(e)||(t.add(e),C(e,(r,o)=>{if(v(o)){const t=o[l];if(se(t,n)){const n=L(t);x(e,r,n,e.type_),oe(t)}}else b(o)&&ue(o,t,n)})),e}var le={get(e,t){if(t===l)return e;let n=e.scope_.arrayMethodsPlugin_;const r=1===e.type_&&"string"==typeof t;if(r&&n?.isArrayOperationMethod(t))return n.createMethodInterceptor(e,t);const o=z(e);if(!T(o,t,e.type_))return function(e,t,n){const r=fe(t,n);return r?E in r?r[E]:r.get?.call(e.draft_):void 0}(e,o,t);const s=o[t];if(e.finalized_||!b(s))return s;if(r&&e.operationMethod&&n?.isMutatingArrayMethod(e.operationMethod)&&function(e){const t=+e;return Number.isInteger(t)&&String(t)===e}(t))return s;if(s===pe(e.base_,t)){_e(e);const n=1===e.type_?+t:t,r=me(0,s,e,n);return e.copy_[n]=r}return s},has:(e,t)=>t in z(e),ownKeys:e=>Reflect.ownKeys(z(e)),set(e,t,n){const r=fe(z(e),t);if(r?.set)return r.set.call(e.draft_,n),!0;if(!e.modified_){const r=pe(z(e),t),i=r?.[l];if(i&&i.base_===n)return e.copy_[t]=n,e.assigned_.set(t,!1),!0;if(((o=n)===(s=r)?0!==o||1/o==1/s:o!=o&&s!=s)&&(void 0!==n||T(e.base_,t,e.type_)))return!0;_e(e),he(e)}var o,s;return e.copy_[t]===n&&(void 0!==n||t in e.copy_)||Number.isNaN(n)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=n,e.assigned_.set(t,!0),function(e,t,n){const{scope_:r}=e;if(v(n)){const o=n[l];se(o,r)&&o.callbacks_.push(function(){_e(e);const r=L(o);ae(e,n,r,t)})}else b(n)&&e.callbacks_.push(function(){const o=z(e);3===e.type_?o.has(n)&&ue(n,r.handledSet_,r):O(o,t,e.type_)===n&&r.drafts_.length>1&&!0===(e.assigned_.get(t)??!1)&&e.copy_&&ue(O(e.copy_,t,e.type_),r.handledSet_,r)})}(e,t,n)),!0},deleteProperty:(e,t)=>(_e(e),void 0!==pe(e.base_,t)||t in e.base_?(e.assigned_.set(t,!1),he(e)):e.assigned_.delete(t),e.copy_&&delete e.copy_[t],!0),getOwnPropertyDescriptor(e,t){const n=z(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r?{[S]:!0,[y]:1!==e.type_||"length"!==t,[g]:r[g],[E]:n[t]}:r},defineProperty(){p(11)},getPrototypeOf:e=>h(e.base_),setPrototypeOf(){p(12)}},de={};for(let e in le){let t=le[e];de[e]=function(){const e=arguments;return e[0]=e[0][0],t.apply(this,e)}}function pe(e,t){const n=e[l];return(n?z(n):e)[t]}function fe(e,t){if(!(t in e))return;let n=h(e);for(;n;){const e=Object.getOwnPropertyDescriptor(n,t);if(e)return e;n=h(n)}}function he(e){e.modified_||(e.modified_=!0,e.parent_&&he(e.parent_))}function _e(e){e.copy_||(e.assigned_=new Map,e.copy_=F(e.base_,e.scope_.immer_.useStrictShallowCopy_))}function me(e,t,n,r){const[o,s]=I(t)?W(Y).proxyMap_(t,n):D(t)?W(Y).proxySet_(t,n):function(e,t){const n=R(e),r={type_:n?1:0,scope_:t?t.scope_:Q(),modified_:!1,finalized_:!1,assigned_:void 0,parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1,callbacks_:void 0};let o=r,s=le;n&&(o=[r],s=de);const{revoke:i,proxy:a}=Proxy.revocable(o,s);return r.draft_=a,r.revoke_=i,[a,r]}(t,n);return(n?.scope_??Q()).drafts_.push(o),s.callbacks_=n?.callbacks_??[],s.key_=r,n&&void 0!==r?function(e,t,n){e.callbacks_.push(function(r){const o=t;if(!o||!se(o,r))return;r.mapSetPlugin_?.fixSetContents(o);const s=L(o);ae(e,o.draft_??o,s,n),ce(o,r)})}(n,s,r):s.callbacks_.push(function(e){e.mapSetPlugin_?.fixSetContents(s);const{patchPlugin_:t}=e;s.modified_&&t&&t.generatePatches_(s,[],e)}),o}function ye(e){return v(e)||p(10,e),ge(e)}function ge(e){if(!b(e)||U(e))return e;const t=e[l];let n,r=!0;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,n=F(e,t.scope_.immer_.useStrictShallowCopy_),r=t.scope_.immer_.shouldUseStrictIteration()}else n=F(e,!0);return C(n,(e,t)=>{x(n,e,ge(t))},r),t&&(t.finalized_=!1),n}de.deleteProperty=function(e,t){return"production"!==process.env.NODE_ENV&&isNaN(parseInt(t))&&p(13),de.set.call(this,e,t,void 0)},de.set=function(e,t,n){return"production"!==process.env.NODE_ENV&&"length"!==t&&isNaN(parseInt(t))&&p(14),le.set.call(this,e[0],t,n,e[0])},new class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!1,this.produce=(e,t,n)=>{if(N(e)&&!N(t)){const n=t;t=e;const r=this;return function(e=n,...o){return r.produce(e,e=>t.call(this,e,...o))}}let r;if(N(t)||p(6),void 0===n||N(n)||p(7),b(e)){const o=ee(this),s=me(0,e,void 0);let i=!0;try{r=t(s),i=!1}finally{i?J(o):Z(o)}return X(o,n),ne(r,o)}if(!e||!k(e)){if(r=t(e),void 0===r&&(r=e),r===c&&(r=void 0),this.autoFreeze_&&K(r,!0),n){const t=[],o=[];W($).generateReplacementPatches_(e,r,{patches_:t,inversePatches_:o}),n(t,o)}return r}p(1,e)},this.produceWithPatches=(e,t)=>{if(N(e))return(t,...n)=>this.produceWithPatches(t,t=>e(t,...n));let n,r;return[this.produce(e,t,(e,t)=>{n=e,r=t}),n,r]},j(e?.autoFreeze)&&this.setAutoFreeze(e.autoFreeze),j(e?.useStrictShallowCopy)&&this.setUseStrictShallowCopy(e.useStrictShallowCopy),j(e?.useStrictIteration)&&this.setUseStrictIteration(e.useStrictIteration)}createDraft(e){b(e)||p(8),v(e)&&(e=ye(e));const t=ee(this),n=me(0,e,void 0);return n[l].isManual_=!0,Z(t),n}finishDraft(e,t){const n=e&&e[l];n&&n.isManual_||p(9);const{scope_:r}=n;return X(r,t),ne(void 0,r)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}setUseStrictIteration(e){this.useStrictIteration_=e}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(e,t){let n;for(n=t.length-1;n>=0;n--){const r=t[n];if(0===r.path.length&&"replace"===r.op){e=r.value;break}}n>-1&&(t=t.slice(n+1));const r=W($).applyPatches_;return v(e)?r(e,t):this.produce(e,e=>r(e,t))}},Error;var Se=(e,t,n)=>{if(1===t.length&&t[0]===n){let t=!1;try{const n={};e(n)===n&&(t=!0)}catch{}if(t){let e;try{throw new Error}catch(t){({stack:e}=t)}console.warn("The result function returned its own inputs without modification. e.g\n`createSelector([state => state.todos], todos => todos)`\nThis could lead to inefficient memoization and unnecessary re-renders.\nEnsure transformation logic is in the result function, and extraction logic is in the input selectors.",{stack:e})}}},Ee=(e,t,n)=>{const{memoize:r,memoizeOptions:o}=t,{inputSelectorResults:s,inputSelectorResultsCopy:i}=e,a=r(()=>({}),...o);if(a.apply(null,s)!==a.apply(null,i)){let e;try{throw new Error}catch(t){({stack:e}=t)}console.warn("An input selector returned a different result when passed same arguments.\nThis means your output selector will likely run more frequently than intended.\nAvoid returning a new reference inside your input selector, e.g.\n`createSelector([state => state.todos.map(todo => todo.id)], todoIds => todoIds.length)`",{arguments:n,firstInputs:s,secondInputs:i,stack:e})}},ve={inputStabilityCheck:"once",identityFunctionCheck:"once"},be=e=>Array.isArray(e)?e:[e];function Ae(e,t){const n=[],{length:r}=e;for(let o=0;o<r;o++)n.push(e[o].apply(null,t));return n}var Pe="undefined"!=typeof WeakRef?WeakRef:class{constructor(e){this.value=e}deref(){return this.value}};function we(){return{s:0,v:void 0,o:null,p:null}}function Ce(e,t={}){let n={s:0,v:void 0,o:null,p:null};const{resultEqualityCheck:r}=t;let o,s=0;function i(){let t=n;const{length:i}=arguments;for(let e=0,n=i;e<n;e++){const n=arguments[e];if("function"==typeof n||"object"==typeof n&&null!==n){let e=t.o;null===e&&(t.o=e=new WeakMap);const r=e.get(n);void 0===r?(t=we(),e.set(n,t)):t=r}else{let e=t.p;null===e&&(t.p=e=new Map);const r=e.get(n);void 0===r?(t=we(),e.set(n,t)):t=r}}const a=t;let c;if(1===t.s)c=t.v;else if(c=e.apply(null,arguments),s++,r){const e=o?.deref?.()??o;null!=e&&r(e,c)&&(c=e,0!==s&&s--),o="object"==typeof c&&null!==c||"function"==typeof c?new Pe(c):c}return a.s=1,a.v=c,c}return i.clearCache=()=>{n={s:0,v:void 0,o:null,p:null},i.resetResultsCount()},i.resultsCount=()=>s,i.resetResultsCount=()=>{s=0},i}function Me(e,...t){const n="function"==typeof e?{memoize:e,memoizeOptions:t}:e,r=(...e)=>{let t,r=0,o=0,s={},i=e.pop();"object"==typeof i&&(s=i,i=e.pop()),function(e,t="expected a function, instead received "+typeof e){if("function"!=typeof e)throw new TypeError(t)}(i,`createSelector expects an output function after the inputs, but received: [${typeof i}]`);const a={...n,...s},{memoize:c,memoizeOptions:u=[],argsMemoize:l=Ce,argsMemoizeOptions:d=[],devModeChecks:p={}}=a,f=be(u),h=be(d),_=function(e){const t=Array.isArray(e[0])?e[0]:e;return function(e,t="expected all items to be functions, instead received the following types: "){if(!e.every(e=>"function"==typeof e)){const n=e.map(e=>"function"==typeof e?`function ${e.name||"unnamed"}()`:typeof e).join(", ");throw new TypeError(`${t}[${n}]`)}}(t,"createSelector expects all input-selectors to be functions, but received the following types: "),t}(e),m=c(function(){return r++,i.apply(null,arguments)},...f);let y=!0;const g=l(function(){o++;const e=Ae(_,arguments);if(t=m.apply(null,e),"production"!==process.env.NODE_ENV){const{identityFunctionCheck:n,inputStabilityCheck:r}=((e,t)=>{const{identityFunctionCheck:n,inputStabilityCheck:r}={...ve,...t};return{identityFunctionCheck:{shouldRun:"always"===n||"once"===n&&e,run:Se},inputStabilityCheck:{shouldRun:"always"===r||"once"===r&&e,run:Ee}}})(y,p);if(n.shouldRun&&n.run(i,e,t),r.shouldRun){const t=Ae(_,arguments);r.run({inputSelectorResults:e,inputSelectorResultsCopy:t},{memoize:c,memoizeOptions:f},arguments)}y&&(y=!1)}return t},...h);return Object.assign(g,{resultFunc:i,memoizedResultFunc:m,dependencies:_,dependencyRecomputations:()=>o,resetDependencyRecomputations:()=>{o=0},lastResult:()=>t,recomputations:()=>r,resetRecomputations:()=>{r=0},memoize:c,argsMemoize:l})};return Object.assign(r,{withTypes:()=>r}),r}var Te=Me(Ce),Oe=Object.assign((e,t=Te)=>{!function(e,t="expected an object, instead received "+typeof e){if("object"!=typeof e)throw new TypeError(t)}(e,"createStructuredSelector expects first argument to be an object where each property is a selector, instead received a "+typeof e);const n=Object.keys(e);return t(n.map(t=>e[t]),(...e)=>e.reduce((e,t,r)=>(e[n[r]]=t,e),{}))},{withTypes:()=>Oe}),xe="__rtkq/",Re="online",Ie="offline",De="focus",ke="focused",Ne="visibilitychange",je=e.createAction(`${xe}${ke}`),ze=e.createAction(`${xe}un${ke}`),Le=e.createAction(`${xe}${Re}`),Fe=e.createAction(`${xe}${Ie}`),Ke=!1;WeakMap,new Error("Promise never resolved before cacheEntryRemoved.");const Ge=e.combineReducers({...t.apiReducers,auth:n.sessionReducer,chat:t.chatReducer,conversations:t.conversationsReducer,voice:r.voiceReducer,indicator:n.indicatorReducer}),Ue=e.createListenerMiddleware();Ue.startListening({matcher:e.isAnyOf(n.clearSession,n.sessionExpired),effect:(e,{dispatch:n})=>{n(t.resetAllApiState())}});const Ye=e.configureStore({reducer:Ge,middleware:e=>e({serializableCheck:t.serializableCheck}).prepend(Ue.middleware,n.sessionListenerMiddleware.middleware,r.voiceListenerMiddleware.middleware).concat(t.apiMiddleware)});var $e;$e=Ye.dispatch,function(){const[e,t,n,r]=[je,ze,Le,Fe].map(e=>()=>$e(e())),o=()=>{"visible"===window.document.visibilityState?e():t()};if(!Ke&&"undefined"!=typeof window&&window.addEventListener){let t=function(e){Object.entries(s).forEach(([t,n])=>{e?window.addEventListener(t,n,!1):window.removeEventListener(t,n)})};const s={[De]:e,[Ne]:o,[Re]:n,[Ie]:r};t(!0),Ke=!0}}(),n.setAccessTokenReader(()=>Ye.getState().auth.accessToken),n.setTokenExpiresAtReader(()=>Ye.getState().auth.tokenExpiresAt),t.bindChatLogger(()=>Ye.getState());const qe=!1,He=!0,We=!0,Be=n.STT_IMPLEMENTATIONS.ONLINE,Ve=!0,Qe=(e,t)=>null===e?t:"true"===e,Xe=t.useChatSettings;async function Je(e){if(e instanceof File)return e;const t=e;if(t?.file instanceof File)return t.file;if(t?.uri){const e=await(await fetch(t.uri)).blob();return new File([e],t.name??"upload",{type:t.mimeType??e.type})}throw new Error("Could not read the selected file.")}const Ze=s.createContext(void 0),et=s.createContext({});function tt(){return"undefined"!=typeof window&&window.matchMedia?window.matchMedia("(prefers-color-scheme: dark)").matches?n.APPEARANCE_MODES.DARK:n.APPEARANCE_MODES.LIGHT:n.APPEARANCE_MODES.DARK}const nt=({children:e,orgId:r,fallbackThemeStyles:i,initialAppearanceMode:a=n.APPEARANCE_MODES.SYSTEM})=>{const{user:c}=t.useAuth(),u=c?.id,l=n.useStorage(),[d,p]=s.useState(a),[f,h]=s.useState(()=>a===n.APPEARANCE_MODES.SYSTEM?tt():a);s.useEffect(()=>{let e=!1;const t=n.getAppearanceModeStorageKey(u),r=n.STORAGE_KEYS.APPEARANCE_MODE_KEY;return(async()=>{const o=await l.getItem(t);if(u&&await l.removeItem(r),e)return;const s=((e,t)=>e===n.APPEARANCE_MODES.LIGHT||e===n.APPEARANCE_MODES.DARK||e===n.APPEARANCE_MODES.SYSTEM?e:t)(o,a);p(s),h(s===n.APPEARANCE_MODES.SYSTEM?tt():s)})(),()=>{e=!0}},[u,l,a]),s.useEffect(()=>{if(d!==n.APPEARANCE_MODES.SYSTEM)return;const e=window.matchMedia("(prefers-color-scheme: dark)"),t=e=>{h(e.matches?n.APPEARANCE_MODES.DARK:n.APPEARANCE_MODES.LIGHT)};return h(e.matches?n.APPEARANCE_MODES.DARK:n.APPEARANCE_MODES.LIGHT),e.addEventListener("change",t),()=>e.removeEventListener("change",t)},[d]);const _=r||void 0,{data:m,isLoading:y,error:g}=t.useGetBrandingQuery(_),S=m?.success?m.data??null:null,E=S?.themes?(f===n.APPEARANCE_MODES.LIGHT?S.themes.light:S.themes.dark)??null:null,v=s.useMemo(()=>!S&&i?i:n.brandingToThemeStyles(S,E,f),[S,E,f,i]),b=S?.orbPosition??n.ORB_POSITIONS.FOREGROUND,A=S?.showAmbientWave??!0,P=s.useCallback(e=>{p(e);const t=n.getAppearanceModeStorageKey(u);l.setItem(t,e),u&&l.removeItem(n.STORAGE_KEYS.APPEARANCE_MODE_KEY),h(e===n.APPEARANCE_MODES.SYSTEM?tt():e)},[l,u]),w={theme:f,setTheme:P,appearanceMode:d,isLoading:y,error:g?new Error("Failed to fetch branding"):null,currentThemeColors:E,themeStyles:v,orbPosition:b,showAmbientWave:A};return o.jsx(n.BrandingContext.Provider,{value:w,children:e})},rt=({children:e,protocolType:r})=>{const i=r||t.DEFAULT_PROTOCOL,a=s.useMemo(()=>t.createAdapter(i,t.createDefaultAdapterConfig({onAuthExpired:()=>Ye.dispatch(n.clearSession())})),[i]),c=s.useMemo(()=>({adapter:a,protocolType:i}),[a,i]);return o.jsx(t.ProtocolContext.Provider,{value:c,children:e})},ot=({value:e,children:t,fallback:r,extraHydrations:a})=>{n.setModuleStorage(e);const c=i.useDispatch(),u=void 0!==r,[l,d]=s.useState(!u);return s.useEffect(()=>{let t=!1;const r=[c(n.hydrateSession(e))];if(a)for(const t of a)r.push(Promise.resolve(t(e,c)).catch(e=>{n.logger.error({message:"StorageProvider hydration step failed",component:"StorageProvider",error_message:e instanceof Error?e.message:String(e)})}));return Promise.all(r).finally(()=>{t||u&&d(!0)}),()=>{t=!0}},[]),o.jsx(n.StorageContext.Provider,{value:e,children:u&&!l?o.jsx(o.Fragment,{children:r}):t})},st=({token:e,user:t,children:r})=>{const i=s.useRef(null);return e&&e!==i.current&&(i.current=e,Ye.dispatch(n.setSession({accessToken:e,expiresIn:Math.floor(Date.now()/1e3)+3600,...t&&{user:{id:"",email:t.email||"",name:t.name}}}))),o.jsx(o.Fragment,{children:r})},it=({children:e})=>o.jsx(t.ConfigurationContext.Provider,{value:t.useConfigurationValue(),children:e}),at=({children:e,callbacks:n})=>o.jsx(t.ChatCallbacksContext.Provider,{value:n,children:e}),ct=s.lazy(()=>Promise.resolve().then(()=>require("./PaymentProviderHost-D6uCrDL1.cjs")));exports.BrandingProvider=nt,exports.ChatClientProvider=({baseUrl:e,customHeaders:r,token:s,user:c,protocol:u=t.DEFAULT_PROTOCOL,paymentProvider:l,onConversationChange:d,onConversationTitleChange:p,onMessagesChange:f,onLogoutRequested:h,onSessionExpired:_,storage:m,storageFallback:y,extraHydrations:g,orgId:S,initialThemeStyles:E,initialAppearanceMode:v,reuseHostBranding:b=!1,manageTokenRefresh:A=!0,audioPlatform:P,networkMonitor:w,children:C})=>{n.initializeChatConfig({baseUrl:e,customHeaders:r,paymentProvider:l}),A&&n.setTokenRefreshHandler(_??null);const M=o.jsx(a.AudioPlatformProvider,{value:P,children:C});let T=o.jsx(st,{token:s,user:c,children:o.jsx(rt,{protocolType:u,children:o.jsx(it,{children:o.jsx(at,{callbacks:{onConversationChange:d,onConversationTitleChange:p,onMessagesChange:f,onLogoutRequested:h},children:b?M:o.jsx(nt,{orgId:S,fallbackThemeStyles:E,initialAppearanceMode:v,children:M})})})})});return w&&(T=o.jsx(n.NetworkContext.Provider,{value:w,children:T})),o.jsx(i.Provider,{store:Ye,children:m?o.jsx(ot,{value:m,fallback:y,extraHydrations:g,children:T}):T})},exports.MessageContextProvider=({children:e,messageId:t,isDisabled:n=!1})=>{const[r,i]=s.useState({});return o.jsx(Ze.Provider,{value:{messageContext:r,setMessageContext:i,updateMessageContext:(e,t)=>{i(n=>({...n,[e]:t}))},messageId:t},children:o.jsx(et.Provider,{value:{messageId:t,isDisabled:n},children:e})})},exports.PaymentProviderHost=e=>o.jsx(s.Suspense,{fallback:null,children:o.jsx(ct,{...e})}),exports.SettingsProvider=({children:e,defaultSttImplementation:r=Be})=>{const{user:i}=t.useAuth(),a=i?.id,c=n.useStorage(),[u,l]=s.useState(!1),[d,p]=s.useState(qe),[f,h]=s.useState(He),[_,m]=s.useState(We),[y,g]=s.useState(r),[S,E]=s.useState(Ve);return s.useEffect(()=>{let e=!1;return Promise.all([c.getItem(n.STORAGE_KEYS.DEBUG_MODE),c.getItem(n.STORAGE_KEYS.LOCATION_ENABLED),c.getItem(n.STORAGE_KEYS.STT_AUTO_SEND),c.getItem(n.STORAGE_KEYS.STT_IMPLEMENTATION),c.getItem(n.STORAGE_KEYS.SEND_DIAGNOSTICS)]).then(([t,o,s,i,a])=>{if(e)return;var c;p(Qe(t,qe)),h(Qe(o,He)),m(Qe(s,We)),g((c=i)===n.STT_IMPLEMENTATIONS.ONLINE||c===n.STT_IMPLEMENTATIONS.DEVICE?c:r);const u=Qe(a,Ve);E(u),n.setNetworkLoggingEnabled(u)}),()=>{e=!0}},[r,a,c]),o.jsx(t.ChatSettingsContext.Provider,{value:{enableTts:u,setEnableTts:l,debugMode:d,setDebugMode:e=>{p(e),c.setItem(n.STORAGE_KEYS.DEBUG_MODE,String(e))},locationEnabled:f,setLocationEnabled:e=>{h(e),c.setItem(n.STORAGE_KEYS.LOCATION_ENABLED,String(e))},autoSendVoice:_,setAutoSendVoice:e=>{m(e),c.setItem(n.STORAGE_KEYS.STT_AUTO_SEND,String(e))},sttImplementation:y,setSttImplementation:e=>{g(e),c.setItem(n.STORAGE_KEYS.STT_IMPLEMENTATION,e)},sendDiagnostics:S,setSendDiagnostics:e=>{E(e),n.setNetworkLoggingEnabled(e),c.setItem(n.STORAGE_KEYS.SEND_DIAGNOSTICS,String(e))}},children:e})},exports.StorageProvider=ot,exports.preloadPaymentModal=()=>Promise.resolve().then(()=>require("./PaymentProviderHost-D6uCrDL1.cjs")).catch(()=>{}),exports.rootReducer=Ge,exports.store=Ye,exports.useDocumentUploadHandlers=function(e){const[n]=t.useUploadDocumentMutation(),[r]=t.useDeleteDocumentMutation();return{onUploadFile:s.useCallback(async(r,o)=>{try{return{documentId:(await n({file:await Je(r),filename:o.fileRequestId,documentType:o.documentType,conversationId:e,onUploadProgress:o.onProgress,onUploadComplete:()=>o.onPhase?.("processing")}).unwrap()).data.document_id}}catch(e){if(e instanceof Error)throw e;throw new Error(t.getApiErrorMessage(e,"Upload failed. Please try again."))}},[n,e]),onRemoveFile:s.useCallback(e=>{r(e)},[r])}},exports.useMessageContext=()=>{const e=s.useContext(Ze);if(!e)throw new Error("useMessageContext must be used within MessageContextProvider");return e},exports.useMessageDisabled=()=>{const e=s.useContext(et);return e?.isDisabled??!1},exports.useMessageId=()=>{const e=s.useContext(et);return e?.messageId},exports.useSettings=Xe;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@reduxjs/toolkit"),t=require("@1interface/chat-core"),n=require("@1interface/shared-core"),r=require("@1interface/voice-core"),o=require("react/jsx-runtime"),s=require("react"),i=require("react-redux"),a=require("@1interface/voice-shell");var c=Symbol.for("immer-nothing"),u=Symbol.for("immer-draftable"),l=Symbol.for("immer-state"),d="production"!==process.env.NODE_ENV?[function(e){return`The plugin for '${e}' has not been loaded into Immer. To enable the plugin, import and call \`enable${e}()\` when initializing your application.`},function(e){return`produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${e}'`},"This object has been frozen and should not be mutated",function(e){return"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+e},"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.","Immer forbids circular references","The first or second argument to `produce` must be a function","The third argument to `produce` must be a function or undefined","First argument to `createDraft` must be a plain object, an array, or an immerable object","First argument to `finishDraft` must be a draft returned by `createDraft`",function(e){return`'current' expects a draft, got: ${e}`},"Object.defineProperty() cannot be used on an Immer draft","Object.setPrototypeOf() cannot be used on an Immer draft","Immer only supports deleting array indices","Immer only supports setting array indices and the 'length' property",function(e){return`'original' expects a draft, got: ${e}`}]:[];function p(e,...t){if("production"!==process.env.NODE_ENV){const n=d[e],r=N(n)?n.apply(null,t):n;throw new Error(`[Immer] ${r}`)}throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var f=Object,h=f.getPrototypeOf,_="constructor",m="prototype",y="configurable",g="enumerable",S="writable",E="value",v=e=>!!e&&!!e[l];function b(e){return!!e&&(w(e)||R(e)||!!e[u]||!!e[_]?.[u]||I(e)||D(e))}var A=f[m][_].toString(),P=new WeakMap;function w(e){if(!e||!k(e))return!1;const t=h(e);if(null===t||t===f[m])return!0;const n=f.hasOwnProperty.call(t,_)&&t[_];if(n===Object)return!0;if(!N(n))return!1;let r=P.get(n);return void 0===r&&(r=Function.toString.call(n),P.set(n,r)),r===A}function C(e,t,n=!0){0===M(e)?(n?Reflect.ownKeys(e):f.keys(e)).forEach(n=>{t(n,e[n],e)}):e.forEach((n,r)=>t(r,n,e))}function M(e){const t=e[l];return t?t.type_:R(e)?1:I(e)?2:D(e)?3:0}var T=(e,t,n=M(e))=>2===n?e.has(t):f[m].hasOwnProperty.call(e,t),O=(e,t,n=M(e))=>2===n?e.get(t):e[t],x=(e,t,n,r=M(e))=>{2===r?e.set(t,n):3===r?e.add(n):e[t]=n},R=Array.isArray,I=e=>e instanceof Map,D=e=>e instanceof Set,k=e=>"object"==typeof e,N=e=>"function"==typeof e,j=e=>"boolean"==typeof e,z=e=>e.copy_||e.base_,L=e=>e.modified_?e.copy_:e.base_;function F(e,t){if(I(e))return new Map(e);if(D(e))return new Set(e);if(R(e))return Array[m].slice.call(e);const n=w(e);if(!0===t||"class_only"===t&&!n){const t=f.getOwnPropertyDescriptors(e);delete t[l];let n=Reflect.ownKeys(t);for(let r=0;r<n.length;r++){const o=n[r],s=t[o];!1===s[S]&&(s[S]=!0,s[y]=!0),(s.get||s.set)&&(t[o]={[y]:!0,[S]:!0,[g]:s[g],[E]:e[o]})}return f.create(h(e),t)}{const t=h(e);if(null!==t&&n)return{...e};const r=f.create(t);return f.assign(r,e)}}function K(e,t=!1){return U(e)||v(e)||!b(e)||(M(e)>1&&f.defineProperties(e,{set:G,add:G,clear:G,delete:G}),f.freeze(e),t&&C(e,(e,t)=>{K(t,!0)},!1)),e}var G={[E]:function(){p(2)}};function U(e){return null===e||!k(e)||f.isFrozen(e)}var Y="MapSet",$="Patches",q="ArrayMethods",H={};function W(e){const t=H[e];return t||p(0,e),t}var B,V=e=>!!H[e],Q=()=>B;function X(e,t){t&&(e.patchPlugin_=W($),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function J(e){Z(e),e.drafts_.forEach(te),e.drafts_=null}function Z(e){e===B&&(B=e.parent_)}var ee=e=>B={drafts_:[],parent_:B,immer_:e,canAutoFreeze_:!0,unfinalizedDrafts_:0,handledSet_:new Set,processedForPatches_:new Set,mapSetPlugin_:V(Y)?W(Y):void 0,arrayMethodsPlugin_:V(q)?W(q):void 0};function te(e){const t=e[l];0===t.type_||1===t.type_?t.revoke_():t.revoked_=!0}function ne(e,t){t.unfinalizedDrafts_=t.drafts_.length;const n=t.drafts_[0];if(void 0!==e&&e!==n){n[l].modified_&&(J(t),p(4)),b(e)&&(e=re(t,e));const{patchPlugin_:r}=t;r&&r.generateReplacementPatches_(n[l].base_,e,t)}else e=re(t,n);return function(e,t,n=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&K(t,n)}(t,e,!0),J(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==c?e:void 0}function re(e,t){if(U(t))return t;const n=t[l];if(!n)return ue(t,e.handledSet_,e);if(!se(n,e))return t;if(!n.modified_)return n.base_;if(!n.finalized_){const{callbacks_:t}=n;if(t)for(;t.length>0;)t.pop()(e);ce(n,e)}return n.copy_}function oe(e){e.finalized_=!0,e.scope_.unfinalizedDrafts_--}var se=(e,t)=>e.scope_===t,ie=[];function ae(e,t,n,r){const o=z(e),s=e.type_;if(void 0!==r&&O(o,r,s)===t)return void x(o,r,n,s);if(!e.draftLocations_){const t=e.draftLocations_=new Map;C(o,(e,n)=>{if(v(n)){const r=t.get(n)||[];r.push(e),t.set(n,r)}})}const i=e.draftLocations_.get(t)??ie;for(const e of i)x(o,e,n,s)}function ce(e,t){if(e.modified_&&!e.finalized_&&(3===e.type_||1===e.type_&&e.allIndicesReassigned_||(e.assigned_?.size??0)>0)){const{patchPlugin_:n}=t;if(n){const r=n.getPath(e);r&&n.generatePatches_(e,r,t)}oe(e)}}function ue(e,t,n){return!n.immer_.autoFreeze_&&n.unfinalizedDrafts_<1||v(e)||t.has(e)||!b(e)||U(e)||(t.add(e),C(e,(r,o)=>{if(v(o)){const t=o[l];if(se(t,n)){const n=L(t);x(e,r,n,e.type_),oe(t)}}else b(o)&&ue(o,t,n)})),e}var le={get(e,t){if(t===l)return e;let n=e.scope_.arrayMethodsPlugin_;const r=1===e.type_&&"string"==typeof t;if(r&&n?.isArrayOperationMethod(t))return n.createMethodInterceptor(e,t);const o=z(e);if(!T(o,t,e.type_))return function(e,t,n){const r=fe(t,n);return r?E in r?r[E]:r.get?.call(e.draft_):void 0}(e,o,t);const s=o[t];if(e.finalized_||!b(s))return s;if(r&&e.operationMethod&&n?.isMutatingArrayMethod(e.operationMethod)&&function(e){const t=+e;return Number.isInteger(t)&&String(t)===e}(t))return s;if(s===pe(e.base_,t)){_e(e);const n=1===e.type_?+t:t,r=me(0,s,e,n);return e.copy_[n]=r}return s},has:(e,t)=>t in z(e),ownKeys:e=>Reflect.ownKeys(z(e)),set(e,t,n){const r=fe(z(e),t);if(r?.set)return r.set.call(e.draft_,n),!0;if(!e.modified_){const r=pe(z(e),t),i=r?.[l];if(i&&i.base_===n)return e.copy_[t]=n,e.assigned_.set(t,!1),!0;if(((o=n)===(s=r)?0!==o||1/o==1/s:o!=o&&s!=s)&&(void 0!==n||T(e.base_,t,e.type_)))return!0;_e(e),he(e)}var o,s;return e.copy_[t]===n&&(void 0!==n||t in e.copy_)||Number.isNaN(n)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=n,e.assigned_.set(t,!0),function(e,t,n){const{scope_:r}=e;if(v(n)){const o=n[l];se(o,r)&&o.callbacks_.push(function(){_e(e);const r=L(o);ae(e,n,r,t)})}else b(n)&&e.callbacks_.push(function(){const o=z(e);3===e.type_?o.has(n)&&ue(n,r.handledSet_,r):O(o,t,e.type_)===n&&r.drafts_.length>1&&!0===(e.assigned_.get(t)??!1)&&e.copy_&&ue(O(e.copy_,t,e.type_),r.handledSet_,r)})}(e,t,n)),!0},deleteProperty:(e,t)=>(_e(e),void 0!==pe(e.base_,t)||t in e.base_?(e.assigned_.set(t,!1),he(e)):e.assigned_.delete(t),e.copy_&&delete e.copy_[t],!0),getOwnPropertyDescriptor(e,t){const n=z(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r?{[S]:!0,[y]:1!==e.type_||"length"!==t,[g]:r[g],[E]:n[t]}:r},defineProperty(){p(11)},getPrototypeOf:e=>h(e.base_),setPrototypeOf(){p(12)}},de={};for(let e in le){let t=le[e];de[e]=function(){const e=arguments;return e[0]=e[0][0],t.apply(this,e)}}function pe(e,t){const n=e[l];return(n?z(n):e)[t]}function fe(e,t){if(!(t in e))return;let n=h(e);for(;n;){const e=Object.getOwnPropertyDescriptor(n,t);if(e)return e;n=h(n)}}function he(e){e.modified_||(e.modified_=!0,e.parent_&&he(e.parent_))}function _e(e){e.copy_||(e.assigned_=new Map,e.copy_=F(e.base_,e.scope_.immer_.useStrictShallowCopy_))}function me(e,t,n,r){const[o,s]=I(t)?W(Y).proxyMap_(t,n):D(t)?W(Y).proxySet_(t,n):function(e,t){const n=R(e),r={type_:n?1:0,scope_:t?t.scope_:Q(),modified_:!1,finalized_:!1,assigned_:void 0,parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1,callbacks_:void 0};let o=r,s=le;n&&(o=[r],s=de);const{revoke:i,proxy:a}=Proxy.revocable(o,s);return r.draft_=a,r.revoke_=i,[a,r]}(t,n);return(n?.scope_??Q()).drafts_.push(o),s.callbacks_=n?.callbacks_??[],s.key_=r,n&&void 0!==r?function(e,t,n){e.callbacks_.push(function(r){const o=t;if(!o||!se(o,r))return;r.mapSetPlugin_?.fixSetContents(o);const s=L(o);ae(e,o.draft_??o,s,n),ce(o,r)})}(n,s,r):s.callbacks_.push(function(e){e.mapSetPlugin_?.fixSetContents(s);const{patchPlugin_:t}=e;s.modified_&&t&&t.generatePatches_(s,[],e)}),o}function ye(e){return v(e)||p(10,e),ge(e)}function ge(e){if(!b(e)||U(e))return e;const t=e[l];let n,r=!0;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,n=F(e,t.scope_.immer_.useStrictShallowCopy_),r=t.scope_.immer_.shouldUseStrictIteration()}else n=F(e,!0);return C(n,(e,t)=>{x(n,e,ge(t))},r),t&&(t.finalized_=!1),n}de.deleteProperty=function(e,t){return"production"!==process.env.NODE_ENV&&isNaN(parseInt(t))&&p(13),de.set.call(this,e,t,void 0)},de.set=function(e,t,n){return"production"!==process.env.NODE_ENV&&"length"!==t&&isNaN(parseInt(t))&&p(14),le.set.call(this,e[0],t,n,e[0])},new class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!1,this.produce=(e,t,n)=>{if(N(e)&&!N(t)){const n=t;t=e;const r=this;return function(e=n,...o){return r.produce(e,e=>t.call(this,e,...o))}}let r;if(N(t)||p(6),void 0===n||N(n)||p(7),b(e)){const o=ee(this),s=me(0,e,void 0);let i=!0;try{r=t(s),i=!1}finally{i?J(o):Z(o)}return X(o,n),ne(r,o)}if(!e||!k(e)){if(r=t(e),void 0===r&&(r=e),r===c&&(r=void 0),this.autoFreeze_&&K(r,!0),n){const t=[],o=[];W($).generateReplacementPatches_(e,r,{patches_:t,inversePatches_:o}),n(t,o)}return r}p(1,e)},this.produceWithPatches=(e,t)=>{if(N(e))return(t,...n)=>this.produceWithPatches(t,t=>e(t,...n));let n,r;return[this.produce(e,t,(e,t)=>{n=e,r=t}),n,r]},j(e?.autoFreeze)&&this.setAutoFreeze(e.autoFreeze),j(e?.useStrictShallowCopy)&&this.setUseStrictShallowCopy(e.useStrictShallowCopy),j(e?.useStrictIteration)&&this.setUseStrictIteration(e.useStrictIteration)}createDraft(e){b(e)||p(8),v(e)&&(e=ye(e));const t=ee(this),n=me(0,e,void 0);return n[l].isManual_=!0,Z(t),n}finishDraft(e,t){const n=e&&e[l];n&&n.isManual_||p(9);const{scope_:r}=n;return X(r,t),ne(void 0,r)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}setUseStrictIteration(e){this.useStrictIteration_=e}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(e,t){let n;for(n=t.length-1;n>=0;n--){const r=t[n];if(0===r.path.length&&"replace"===r.op){e=r.value;break}}n>-1&&(t=t.slice(n+1));const r=W($).applyPatches_;return v(e)?r(e,t):this.produce(e,e=>r(e,t))}},Error;var Se=(e,t,n)=>{if(1===t.length&&t[0]===n){let t=!1;try{const n={};e(n)===n&&(t=!0)}catch{}if(t){let e;try{throw new Error}catch(t){({stack:e}=t)}console.warn("The result function returned its own inputs without modification. e.g\n`createSelector([state => state.todos], todos => todos)`\nThis could lead to inefficient memoization and unnecessary re-renders.\nEnsure transformation logic is in the result function, and extraction logic is in the input selectors.",{stack:e})}}},Ee=(e,t,n)=>{const{memoize:r,memoizeOptions:o}=t,{inputSelectorResults:s,inputSelectorResultsCopy:i}=e,a=r(()=>({}),...o);if(a.apply(null,s)!==a.apply(null,i)){let e;try{throw new Error}catch(t){({stack:e}=t)}console.warn("An input selector returned a different result when passed same arguments.\nThis means your output selector will likely run more frequently than intended.\nAvoid returning a new reference inside your input selector, e.g.\n`createSelector([state => state.todos.map(todo => todo.id)], todoIds => todoIds.length)`",{arguments:n,firstInputs:s,secondInputs:i,stack:e})}},ve={inputStabilityCheck:"once",identityFunctionCheck:"once"},be=e=>Array.isArray(e)?e:[e];function Ae(e,t){const n=[],{length:r}=e;for(let o=0;o<r;o++)n.push(e[o].apply(null,t));return n}var Pe="undefined"!=typeof WeakRef?WeakRef:class{constructor(e){this.value=e}deref(){return this.value}};function we(){return{s:0,v:void 0,o:null,p:null}}function Ce(e,t={}){let n={s:0,v:void 0,o:null,p:null};const{resultEqualityCheck:r}=t;let o,s=0;function i(){let t=n;const{length:i}=arguments;for(let e=0,n=i;e<n;e++){const n=arguments[e];if("function"==typeof n||"object"==typeof n&&null!==n){let e=t.o;null===e&&(t.o=e=new WeakMap);const r=e.get(n);void 0===r?(t=we(),e.set(n,t)):t=r}else{let e=t.p;null===e&&(t.p=e=new Map);const r=e.get(n);void 0===r?(t=we(),e.set(n,t)):t=r}}const a=t;let c;if(1===t.s)c=t.v;else if(c=e.apply(null,arguments),s++,r){const e=o?.deref?.()??o;null!=e&&r(e,c)&&(c=e,0!==s&&s--),o="object"==typeof c&&null!==c||"function"==typeof c?new Pe(c):c}return a.s=1,a.v=c,c}return i.clearCache=()=>{n={s:0,v:void 0,o:null,p:null},i.resetResultsCount()},i.resultsCount=()=>s,i.resetResultsCount=()=>{s=0},i}function Me(e,...t){const n="function"==typeof e?{memoize:e,memoizeOptions:t}:e,r=(...e)=>{let t,r=0,o=0,s={},i=e.pop();"object"==typeof i&&(s=i,i=e.pop()),function(e,t="expected a function, instead received "+typeof e){if("function"!=typeof e)throw new TypeError(t)}(i,`createSelector expects an output function after the inputs, but received: [${typeof i}]`);const a={...n,...s},{memoize:c,memoizeOptions:u=[],argsMemoize:l=Ce,argsMemoizeOptions:d=[],devModeChecks:p={}}=a,f=be(u),h=be(d),_=function(e){const t=Array.isArray(e[0])?e[0]:e;return function(e,t="expected all items to be functions, instead received the following types: "){if(!e.every(e=>"function"==typeof e)){const n=e.map(e=>"function"==typeof e?`function ${e.name||"unnamed"}()`:typeof e).join(", ");throw new TypeError(`${t}[${n}]`)}}(t,"createSelector expects all input-selectors to be functions, but received the following types: "),t}(e),m=c(function(){return r++,i.apply(null,arguments)},...f);let y=!0;const g=l(function(){o++;const e=Ae(_,arguments);if(t=m.apply(null,e),"production"!==process.env.NODE_ENV){const{identityFunctionCheck:n,inputStabilityCheck:r}=((e,t)=>{const{identityFunctionCheck:n,inputStabilityCheck:r}={...ve,...t};return{identityFunctionCheck:{shouldRun:"always"===n||"once"===n&&e,run:Se},inputStabilityCheck:{shouldRun:"always"===r||"once"===r&&e,run:Ee}}})(y,p);if(n.shouldRun&&n.run(i,e,t),r.shouldRun){const t=Ae(_,arguments);r.run({inputSelectorResults:e,inputSelectorResultsCopy:t},{memoize:c,memoizeOptions:f},arguments)}y&&(y=!1)}return t},...h);return Object.assign(g,{resultFunc:i,memoizedResultFunc:m,dependencies:_,dependencyRecomputations:()=>o,resetDependencyRecomputations:()=>{o=0},lastResult:()=>t,recomputations:()=>r,resetRecomputations:()=>{r=0},memoize:c,argsMemoize:l})};return Object.assign(r,{withTypes:()=>r}),r}var Te=Me(Ce),Oe=Object.assign((e,t=Te)=>{!function(e,t="expected an object, instead received "+typeof e){if("object"!=typeof e)throw new TypeError(t)}(e,"createStructuredSelector expects first argument to be an object where each property is a selector, instead received a "+typeof e);const n=Object.keys(e);return t(n.map(t=>e[t]),(...e)=>e.reduce((e,t,r)=>(e[n[r]]=t,e),{}))},{withTypes:()=>Oe}),xe="__rtkq/",Re="online",Ie="offline",De="focus",ke="focused",Ne="visibilitychange",je=e.createAction(`${xe}${ke}`),ze=e.createAction(`${xe}un${ke}`),Le=e.createAction(`${xe}${Re}`),Fe=e.createAction(`${xe}${Ie}`),Ke=!1;WeakMap,new Error("Promise never resolved before cacheEntryRemoved.");const Ge=e.combineReducers({...t.apiReducers,auth:n.sessionReducer,chat:t.chatReducer,conversations:t.conversationsReducer,voice:r.voiceReducer,indicator:n.indicatorReducer}),Ue=e.createListenerMiddleware();Ue.startListening({matcher:e.isAnyOf(n.clearSession,n.sessionExpired),effect:(e,{dispatch:n})=>{n(t.resetAllApiState())}});const Ye=e.configureStore({reducer:Ge,middleware:e=>e({serializableCheck:t.serializableCheck}).prepend(Ue.middleware,n.sessionListenerMiddleware.middleware,r.voiceListenerMiddleware.middleware).concat(t.apiMiddleware)});var $e;$e=Ye.dispatch,function(){const[e,t,n,r]=[je,ze,Le,Fe].map(e=>()=>$e(e())),o=()=>{"visible"===window.document.visibilityState?e():t()};if(!Ke&&"undefined"!=typeof window&&window.addEventListener){let t=function(e){Object.entries(s).forEach(([t,n])=>{e?window.addEventListener(t,n,!1):window.removeEventListener(t,n)})};const s={[De]:e,[Ne]:o,[Re]:n,[Ie]:r};t(!0),Ke=!0}}(),n.setAccessTokenReader(()=>Ye.getState().auth.accessToken),n.setTokenExpiresAtReader(()=>Ye.getState().auth.tokenExpiresAt),t.bindChatLogger(()=>Ye.getState());const qe=!1,He=!0,We=!0,Be=n.STT_IMPLEMENTATIONS.ONLINE,Ve=!0,Qe=(e,t)=>null===e?t:"true"===e,Xe=t.useChatSettings;async function Je(e){if(e instanceof File)return e;const t=e;if(t?.file instanceof File)return t.file;if(t?.uri){const e=await(await fetch(t.uri)).blob();return new File([e],t.name??"upload",{type:t.mimeType??e.type})}throw new Error("Could not read the selected file.")}const Ze=s.createContext(void 0),et=s.createContext({});function tt(){return"undefined"!=typeof window&&window.matchMedia?window.matchMedia("(prefers-color-scheme: dark)").matches?n.APPEARANCE_MODES.DARK:n.APPEARANCE_MODES.LIGHT:n.APPEARANCE_MODES.DARK}const nt=({children:e,orgId:r,fallbackThemeStyles:i,initialAppearanceMode:a=n.APPEARANCE_MODES.SYSTEM})=>{const{user:c}=t.useAuth(),u=c?.id,l=n.useStorage(),[d,p]=s.useState(a),[f,h]=s.useState(()=>a===n.APPEARANCE_MODES.SYSTEM?tt():a);s.useEffect(()=>{let e=!1;const t=n.getAppearanceModeStorageKey(u),r=n.STORAGE_KEYS.APPEARANCE_MODE_KEY;return(async()=>{const o=await l.getItem(t);if(u&&await l.removeItem(r),e)return;const s=((e,t)=>e===n.APPEARANCE_MODES.LIGHT||e===n.APPEARANCE_MODES.DARK||e===n.APPEARANCE_MODES.SYSTEM?e:t)(o,a);p(s),h(s===n.APPEARANCE_MODES.SYSTEM?tt():s)})(),()=>{e=!0}},[u,l,a]),s.useEffect(()=>{if(d!==n.APPEARANCE_MODES.SYSTEM)return;const e=window.matchMedia("(prefers-color-scheme: dark)"),t=e=>{h(e.matches?n.APPEARANCE_MODES.DARK:n.APPEARANCE_MODES.LIGHT)};return h(e.matches?n.APPEARANCE_MODES.DARK:n.APPEARANCE_MODES.LIGHT),e.addEventListener("change",t),()=>e.removeEventListener("change",t)},[d]);const _=r||void 0,{data:m,isLoading:y,error:g}=t.useGetBrandingQuery(_),S=m?.success?m.data??null:null,E=S?.themes?(f===n.APPEARANCE_MODES.LIGHT?S.themes.light:S.themes.dark)??null:null,v=s.useMemo(()=>!S&&i?i:n.brandingToThemeStyles(S,E,f),[S,E,f,i]),b=S?.orbPosition??n.ORB_POSITIONS.FOREGROUND,A=S?.showAmbientWave??!0,P=s.useCallback(e=>{p(e);const t=n.getAppearanceModeStorageKey(u);l.setItem(t,e),u&&l.removeItem(n.STORAGE_KEYS.APPEARANCE_MODE_KEY),h(e===n.APPEARANCE_MODES.SYSTEM?tt():e)},[l,u]),w={theme:f,setTheme:P,appearanceMode:d,isLoading:y,error:g?new Error("Failed to fetch branding"):null,currentThemeColors:E,themeStyles:v,orbPosition:b,showAmbientWave:A};return o.jsx(n.BrandingContext.Provider,{value:w,children:e})},rt=({children:e,protocolType:r})=>{const i=r||t.DEFAULT_PROTOCOL,a=s.useMemo(()=>t.createAdapter(i,t.createDefaultAdapterConfig({onAuthExpired:()=>Ye.dispatch(n.clearSession())})),[i]),c=s.useMemo(()=>({adapter:a,protocolType:i}),[a,i]);return o.jsx(t.ProtocolContext.Provider,{value:c,children:e})},ot=({value:e,children:t,fallback:r,extraHydrations:a})=>{n.setModuleStorage(e);const c=i.useDispatch(),u=void 0!==r,[l,d]=s.useState(!u);return s.useEffect(()=>{let t=!1;const r=[c(n.hydrateSession(e))];if(a)for(const t of a)r.push(Promise.resolve(t(e,c)).catch(e=>{n.logger.error({message:"StorageProvider hydration step failed",component:"StorageProvider",error_message:e instanceof Error?e.message:String(e)})}));return Promise.all(r).finally(()=>{t||u&&d(!0)}),()=>{t=!0}},[]),o.jsx(n.StorageContext.Provider,{value:e,children:u&&!l?o.jsx(o.Fragment,{children:r}):t})},st=({token:e,user:t,children:r})=>{const i=s.useRef(null);return e&&e!==i.current&&(i.current=e,Ye.dispatch(n.setSession({accessToken:e,expiresIn:Math.floor(Date.now()/1e3)+3600,...t&&{user:{id:"",email:t.email||"",name:t.name}}}))),o.jsx(o.Fragment,{children:r})},it=({children:e})=>o.jsx(t.ConfigurationContext.Provider,{value:t.useConfigurationValue(),children:e}),at=({children:e,callbacks:n})=>o.jsx(t.ChatCallbacksContext.Provider,{value:n,children:e}),ct=s.lazy(()=>Promise.resolve().then(()=>require("./PaymentProviderHost-BTdzqJNn.cjs")));exports.BrandingProvider=nt,exports.ChatClientProvider=({baseUrl:e,customHeaders:r,token:s,user:c,protocol:u=t.DEFAULT_PROTOCOL,paymentProvider:l,onConversationChange:d,onConversationTitleChange:p,onMessagesChange:f,onLogoutRequested:h,onSessionExpired:_,storage:m,storageFallback:y,extraHydrations:g,orgId:S,initialThemeStyles:E,initialAppearanceMode:v,reuseHostBranding:b=!1,manageTokenRefresh:A=!0,audioPlatform:P,networkMonitor:w,children:C})=>{n.initializeChatConfig({baseUrl:e,customHeaders:r,paymentProvider:l}),A&&n.setTokenRefreshHandler(_??null);const M=o.jsx(a.AudioPlatformProvider,{value:P,children:C});let T=o.jsx(st,{token:s,user:c,children:o.jsx(rt,{protocolType:u,children:o.jsx(it,{children:o.jsx(at,{callbacks:{onConversationChange:d,onConversationTitleChange:p,onMessagesChange:f,onLogoutRequested:h},children:b?M:o.jsx(nt,{orgId:S,fallbackThemeStyles:E,initialAppearanceMode:v,children:M})})})})});return w&&(T=o.jsx(n.NetworkContext.Provider,{value:w,children:T})),o.jsx(i.Provider,{store:Ye,children:m?o.jsx(ot,{value:m,fallback:y,extraHydrations:g,children:T}):T})},exports.MessageContextProvider=({children:e,messageId:t,isDisabled:n=!1})=>{const[r,i]=s.useState({});return o.jsx(Ze.Provider,{value:{messageContext:r,setMessageContext:i,updateMessageContext:(e,t)=>{i(n=>({...n,[e]:t}))},messageId:t},children:o.jsx(et.Provider,{value:{messageId:t,isDisabled:n},children:e})})},exports.PaymentProviderHost=e=>o.jsx(s.Suspense,{fallback:null,children:o.jsx(ct,{...e})}),exports.SettingsProvider=({children:e,defaultSttImplementation:r=Be})=>{const{user:i}=t.useAuth(),a=i?.id,c=n.useStorage(),[u,l]=s.useState(!1),[d,p]=s.useState(qe),[f,h]=s.useState(He),[_,m]=s.useState(We),[y,g]=s.useState(r),[S,E]=s.useState(Ve);return s.useEffect(()=>{let e=!1;return Promise.all([c.getItem(n.STORAGE_KEYS.DEBUG_MODE),c.getItem(n.STORAGE_KEYS.LOCATION_ENABLED),c.getItem(n.STORAGE_KEYS.STT_AUTO_SEND),c.getItem(n.STORAGE_KEYS.STT_IMPLEMENTATION),c.getItem(n.STORAGE_KEYS.SEND_DIAGNOSTICS)]).then(([t,o,s,i,a])=>{if(e)return;var c;p(Qe(t,qe)),h(Qe(o,He)),m(Qe(s,We)),g((c=i)===n.STT_IMPLEMENTATIONS.ONLINE||c===n.STT_IMPLEMENTATIONS.DEVICE?c:r);const u=Qe(a,Ve);E(u),n.setNetworkLoggingEnabled(u)}),()=>{e=!0}},[r,a,c]),o.jsx(t.ChatSettingsContext.Provider,{value:{enableTts:u,setEnableTts:l,debugMode:d,setDebugMode:e=>{p(e),c.setItem(n.STORAGE_KEYS.DEBUG_MODE,String(e))},locationEnabled:f,setLocationEnabled:e=>{h(e),c.setItem(n.STORAGE_KEYS.LOCATION_ENABLED,String(e))},autoSendVoice:_,setAutoSendVoice:e=>{m(e),c.setItem(n.STORAGE_KEYS.STT_AUTO_SEND,String(e))},sttImplementation:y,setSttImplementation:e=>{g(e),c.setItem(n.STORAGE_KEYS.STT_IMPLEMENTATION,e)},sendDiagnostics:S,setSendDiagnostics:e=>{E(e),n.setNetworkLoggingEnabled(e),c.setItem(n.STORAGE_KEYS.SEND_DIAGNOSTICS,String(e))}},children:e})},exports.StorageProvider=ot,exports.preloadPaymentModal=()=>Promise.resolve().then(()=>require("./PaymentProviderHost-BTdzqJNn.cjs")).catch(()=>{}),exports.rootReducer=Ge,exports.store=Ye,exports.useDocumentUploadHandlers=function(e){const[n]=t.useUploadDocumentMutation(),[r]=t.useDeleteDocumentMutation();return{onUploadFile:s.useCallback(async(r,o)=>{try{return{documentId:(await n({file:await Je(r),filename:o.fileRequestId,documentType:o.documentType,conversationId:e,onUploadProgress:o.onProgress,onUploadComplete:()=>o.onPhase?.("processing")}).unwrap()).data.document_id}}catch(e){if(e instanceof Error)throw e;throw new Error(t.getApiErrorMessage(e,"Upload failed. Please try again."))}},[n,e]),onRemoveFile:s.useCallback(e=>{r(e)},[r])}},exports.useMessageContext=()=>{const e=s.useContext(Ze);if(!e)throw new Error("useMessageContext must be used within MessageContextProvider");return e},exports.useMessageDisabled=()=>{const e=s.useContext(et);return e?.isDisabled??!1},exports.useMessageId=()=>{const e=s.useContext(et);return e?.messageId},exports.useSettings=Xe;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{createAction as e,nanoid as t,formatProdErrorMessage as n,createSelector as r,createAsyncThunk as o,createSlice as i,prepareAutoBatched as s,isAnyOf as a,isFulfilled as c,isRejectedWithValue as l,combineReducers as u,isPlainObject as d,SHOULD_AUTOBATCH as f,isAllOf as p,isRejected as h,isPending as m,isAction as _,createNextState as y,isAsyncThunkAction as g,configureStore as v,createListenerMiddleware as b}from"@reduxjs/toolkit";import{conversationsReducer as S,chatReducer as w,apiReducers as E,serializableCheck as P,apiMiddleware as I,resetAllApiState as k,bindChatLogger as T,useChatSettings as M,useAuth as C,ChatSettingsContext as O,useUploadDocumentMutation as D,useDeleteDocumentMutation as A,getApiErrorMessage as z,useGetBrandingQuery as N,createAdapter as R,DEFAULT_PROTOCOL as x,createDefaultAdapterConfig as F,ProtocolContext as L,ConfigurationContext as j,useConfigurationValue as $,ChatCallbacksContext as U}from"@1interface/chat-core";import{indicatorReducer as H,sessionReducer as K,sessionListenerMiddleware as G,clearSession as W,sessionExpired as V,setAccessTokenReader as Y,setTokenExpiresAtReader as q,useStorage as B,STT_IMPLEMENTATIONS as X,STORAGE_KEYS as J,setNetworkLoggingEnabled as Q,APPEARANCE_MODES as Z,getAppearanceModeStorageKey as ee,brandingToThemeStyles as te,ORB_POSITIONS as ne,BrandingContext as re,setModuleStorage as oe,hydrateSession as ie,logger as se,StorageContext as ae,setSession as ce,initializeChatConfig as le,setTokenRefreshHandler as ue,NetworkContext as de}from"@1interface/shared-core";import{voiceReducer as fe,voiceListenerMiddleware as pe}from"@1interface/voice-core";import{jsx as he,Fragment as me}from"react/jsx-runtime";import{useState as _e,useEffect as ye,useCallback as ge,useContext as ve,createContext as be,useMemo as Se,useRef as we,Suspense as Ee,lazy as Pe}from"react";import{useDispatch as Ie,Provider as ke}from"react-redux";import{AudioPlatformProvider as Te}from"@1interface/voice-shell";var Me=Symbol.for("immer-nothing"),Ce=Symbol.for("immer-draftable"),Oe=Symbol.for("immer-state"),De="production"!==process.env.NODE_ENV?[function(e){return`The plugin for '${e}' has not been loaded into Immer. To enable the plugin, import and call \`enable${e}()\` when initializing your application.`},function(e){return`produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${e}'`},"This object has been frozen and should not be mutated",function(e){return"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+e},"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.","Immer forbids circular references","The first or second argument to `produce` must be a function","The third argument to `produce` must be a function or undefined","First argument to `createDraft` must be a plain object, an array, or an immerable object","First argument to `finishDraft` must be a draft returned by `createDraft`",function(e){return`'current' expects a draft, got: ${e}`},"Object.defineProperty() cannot be used on an Immer draft","Object.setPrototypeOf() cannot be used on an Immer draft","Immer only supports deleting array indices","Immer only supports setting array indices and the 'length' property",function(e){return`'original' expects a draft, got: ${e}`}]:[];function Ae(e,...t){if("production"!==process.env.NODE_ENV){const n=De[e],r=tt(n)?n.apply(null,t):n;throw new Error(`[Immer] ${r}`)}throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var ze=Object,Ne=ze.getPrototypeOf,Re="constructor",xe="prototype",Fe="configurable",Le="enumerable",je="writable",$e="value",Ue=e=>!!e&&!!e[Oe];function He(e){return!!e&&(We(e)||Je(e)||!!e[Ce]||!!e[Re]?.[Ce]||Qe(e)||Ze(e))}var Ke=ze[xe][Re].toString(),Ge=new WeakMap;function We(e){if(!e||!et(e))return!1;const t=Ne(e);if(null===t||t===ze[xe])return!0;const n=ze.hasOwnProperty.call(t,Re)&&t[Re];if(n===Object)return!0;if(!tt(n))return!1;let r=Ge.get(n);return void 0===r&&(r=Function.toString.call(n),Ge.set(n,r)),r===Ke}function Ve(e,t,n=!0){0===Ye(e)?(n?Reflect.ownKeys(e):ze.keys(e)).forEach(n=>{t(n,e[n],e)}):e.forEach((n,r)=>t(r,n,e))}function Ye(e){const t=e[Oe];return t?t.type_:Je(e)?1:Qe(e)?2:Ze(e)?3:0}var qe=(e,t,n=Ye(e))=>2===n?e.has(t):ze[xe].hasOwnProperty.call(e,t),Be=(e,t,n=Ye(e))=>2===n?e.get(t):e[t],Xe=(e,t,n,r=Ye(e))=>{2===r?e.set(t,n):3===r?e.add(n):e[t]=n},Je=Array.isArray,Qe=e=>e instanceof Map,Ze=e=>e instanceof Set,et=e=>"object"==typeof e,tt=e=>"function"==typeof e,nt=e=>"boolean"==typeof e,rt=e=>e.copy_||e.base_,ot=e=>e.modified_?e.copy_:e.base_;function it(e,t){if(Qe(e))return new Map(e);if(Ze(e))return new Set(e);if(Je(e))return Array[xe].slice.call(e);const n=We(e);if(!0===t||"class_only"===t&&!n){const t=ze.getOwnPropertyDescriptors(e);delete t[Oe];let n=Reflect.ownKeys(t);for(let r=0;r<n.length;r++){const o=n[r],i=t[o];!1===i[je]&&(i[je]=!0,i[Fe]=!0),(i.get||i.set)&&(t[o]={[Fe]:!0,[je]:!0,[Le]:i[Le],[$e]:e[o]})}return ze.create(Ne(e),t)}{const t=Ne(e);if(null!==t&&n)return{...e};const r=ze.create(t);return ze.assign(r,e)}}function st(e,t=!1){return ct(e)||Ue(e)||!He(e)||(Ye(e)>1&&ze.defineProperties(e,{set:at,add:at,clear:at,delete:at}),ze.freeze(e),t&&Ve(e,(e,t)=>{st(t,!0)},!1)),e}var at={[$e]:function(){Ae(2)}};function ct(e){return null===e||!et(e)||ze.isFrozen(e)}var lt="MapSet",ut="Patches",dt="ArrayMethods",ft={};function pt(e){const t=ft[e];return t||Ae(0,e),t}var ht,mt=e=>!!ft[e],_t=()=>ht;function yt(e,t){t&&(e.patchPlugin_=pt(ut),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function gt(e){vt(e),e.drafts_.forEach(St),e.drafts_=null}function vt(e){e===ht&&(ht=e.parent_)}var bt=e=>ht={drafts_:[],parent_:ht,immer_:e,canAutoFreeze_:!0,unfinalizedDrafts_:0,handledSet_:new Set,processedForPatches_:new Set,mapSetPlugin_:mt(lt)?pt(lt):void 0,arrayMethodsPlugin_:mt(dt)?pt(dt):void 0};function St(e){const t=e[Oe];0===t.type_||1===t.type_?t.revoke_():t.revoked_=!0}function wt(e,t){t.unfinalizedDrafts_=t.drafts_.length;const n=t.drafts_[0];if(void 0!==e&&e!==n){n[Oe].modified_&&(gt(t),Ae(4)),He(e)&&(e=Et(t,e));const{patchPlugin_:r}=t;r&&r.generateReplacementPatches_(n[Oe].base_,e,t)}else e=Et(t,n);return function(e,t,n=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&st(t,n)}(t,e,!0),gt(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==Me?e:void 0}function Et(e,t){if(ct(t))return t;const n=t[Oe];if(!n)return Ct(t,e.handledSet_,e);if(!It(n,e))return t;if(!n.modified_)return n.base_;if(!n.finalized_){const{callbacks_:t}=n;if(t)for(;t.length>0;)t.pop()(e);Mt(n,e)}return n.copy_}function Pt(e){e.finalized_=!0,e.scope_.unfinalizedDrafts_--}var It=(e,t)=>e.scope_===t,kt=[];function Tt(e,t,n,r){const o=rt(e),i=e.type_;if(void 0!==r&&Be(o,r,i)===t)return void Xe(o,r,n,i);if(!e.draftLocations_){const t=e.draftLocations_=new Map;Ve(o,(e,n)=>{if(Ue(n)){const r=t.get(n)||[];r.push(e),t.set(n,r)}})}const s=e.draftLocations_.get(t)??kt;for(const e of s)Xe(o,e,n,i)}function Mt(e,t){if(e.modified_&&!e.finalized_&&(3===e.type_||1===e.type_&&e.allIndicesReassigned_||(e.assigned_?.size??0)>0)){const{patchPlugin_:n}=t;if(n){const r=n.getPath(e);r&&n.generatePatches_(e,r,t)}Pt(e)}}function Ct(e,t,n){return!n.immer_.autoFreeze_&&n.unfinalizedDrafts_<1||Ue(e)||t.has(e)||!He(e)||ct(e)||(t.add(e),Ve(e,(r,o)=>{if(Ue(o)){const t=o[Oe];if(It(t,n)){const n=ot(t);Xe(e,r,n,e.type_),Pt(t)}}else He(o)&&Ct(o,t,n)})),e}var Ot={get(e,t){if(t===Oe)return e;let n=e.scope_.arrayMethodsPlugin_;const r=1===e.type_&&"string"==typeof t;if(r&&n?.isArrayOperationMethod(t))return n.createMethodInterceptor(e,t);const o=rt(e);if(!qe(o,t,e.type_))return function(e,t,n){const r=zt(t,n);return r?$e in r?r[$e]:r.get?.call(e.draft_):void 0}(e,o,t);const i=o[t];if(e.finalized_||!He(i))return i;if(r&&e.operationMethod&&n?.isMutatingArrayMethod(e.operationMethod)&&function(e){const t=+e;return Number.isInteger(t)&&String(t)===e}(t))return i;if(i===At(e.base_,t)){Rt(e);const n=1===e.type_?+t:t,r=xt(0,i,e,n);return e.copy_[n]=r}return i},has:(e,t)=>t in rt(e),ownKeys:e=>Reflect.ownKeys(rt(e)),set(e,t,n){const r=zt(rt(e),t);if(r?.set)return r.set.call(e.draft_,n),!0;if(!e.modified_){const r=At(rt(e),t),s=r?.[Oe];if(s&&s.base_===n)return e.copy_[t]=n,e.assigned_.set(t,!1),!0;if(((o=n)===(i=r)?0!==o||1/o==1/i:o!=o&&i!=i)&&(void 0!==n||qe(e.base_,t,e.type_)))return!0;Rt(e),Nt(e)}var o,i;return e.copy_[t]===n&&(void 0!==n||t in e.copy_)||Number.isNaN(n)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=n,e.assigned_.set(t,!0),function(e,t,n){const{scope_:r}=e;if(Ue(n)){const o=n[Oe];It(o,r)&&o.callbacks_.push(function(){Rt(e);const r=ot(o);Tt(e,n,r,t)})}else He(n)&&e.callbacks_.push(function(){const o=rt(e);3===e.type_?o.has(n)&&Ct(n,r.handledSet_,r):Be(o,t,e.type_)===n&&r.drafts_.length>1&&!0===(e.assigned_.get(t)??!1)&&e.copy_&&Ct(Be(e.copy_,t,e.type_),r.handledSet_,r)})}(e,t,n)),!0},deleteProperty:(e,t)=>(Rt(e),void 0!==At(e.base_,t)||t in e.base_?(e.assigned_.set(t,!1),Nt(e)):e.assigned_.delete(t),e.copy_&&delete e.copy_[t],!0),getOwnPropertyDescriptor(e,t){const n=rt(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r?{[je]:!0,[Fe]:1!==e.type_||"length"!==t,[Le]:r[Le],[$e]:n[t]}:r},defineProperty(){Ae(11)},getPrototypeOf:e=>Ne(e.base_),setPrototypeOf(){Ae(12)}},Dt={};for(let e in Ot){let t=Ot[e];Dt[e]=function(){const e=arguments;return e[0]=e[0][0],t.apply(this,e)}}function At(e,t){const n=e[Oe];return(n?rt(n):e)[t]}function zt(e,t){if(!(t in e))return;let n=Ne(e);for(;n;){const e=Object.getOwnPropertyDescriptor(n,t);if(e)return e;n=Ne(n)}}function Nt(e){e.modified_||(e.modified_=!0,e.parent_&&Nt(e.parent_))}function Rt(e){e.copy_||(e.assigned_=new Map,e.copy_=it(e.base_,e.scope_.immer_.useStrictShallowCopy_))}function xt(e,t,n,r){const[o,i]=Qe(t)?pt(lt).proxyMap_(t,n):Ze(t)?pt(lt).proxySet_(t,n):function(e,t){const n=Je(e),r={type_:n?1:0,scope_:t?t.scope_:_t(),modified_:!1,finalized_:!1,assigned_:void 0,parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1,callbacks_:void 0};let o=r,i=Ot;n&&(o=[r],i=Dt);const{revoke:s,proxy:a}=Proxy.revocable(o,i);return r.draft_=a,r.revoke_=s,[a,r]}(t,n);return(n?.scope_??_t()).drafts_.push(o),i.callbacks_=n?.callbacks_??[],i.key_=r,n&&void 0!==r?function(e,t,n){e.callbacks_.push(function(r){const o=t;if(!o||!It(o,r))return;r.mapSetPlugin_?.fixSetContents(o);const i=ot(o);Tt(e,o.draft_??o,i,n),Mt(o,r)})}(n,i,r):i.callbacks_.push(function(e){e.mapSetPlugin_?.fixSetContents(i);const{patchPlugin_:t}=e;i.modified_&&t&&t.generatePatches_(i,[],e)}),o}function Ft(e){return Ue(e)||Ae(10,e),Lt(e)}function Lt(e){if(!He(e)||ct(e))return e;const t=e[Oe];let n,r=!0;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,n=it(e,t.scope_.immer_.useStrictShallowCopy_),r=t.scope_.immer_.shouldUseStrictIteration()}else n=it(e,!0);return Ve(n,(e,t)=>{Xe(n,e,Lt(t))},r),t&&(t.finalized_=!1),n}Dt.deleteProperty=function(e,t){return"production"!==process.env.NODE_ENV&&isNaN(parseInt(t))&&Ae(13),Dt.set.call(this,e,t,void 0)},Dt.set=function(e,t,n){return"production"!==process.env.NODE_ENV&&"length"!==t&&isNaN(parseInt(t))&&Ae(14),Ot.set.call(this,e[0],t,n,e[0])},new class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!1,this.produce=(e,t,n)=>{if(tt(e)&&!tt(t)){const n=t;t=e;const r=this;return function(e=n,...o){return r.produce(e,e=>t.call(this,e,...o))}}let r;if(tt(t)||Ae(6),void 0===n||tt(n)||Ae(7),He(e)){const o=bt(this),i=xt(0,e,void 0);let s=!0;try{r=t(i),s=!1}finally{s?gt(o):vt(o)}return yt(o,n),wt(r,o)}if(!e||!et(e)){if(r=t(e),void 0===r&&(r=e),r===Me&&(r=void 0),this.autoFreeze_&&st(r,!0),n){const t=[],o=[];pt(ut).generateReplacementPatches_(e,r,{patches_:t,inversePatches_:o}),n(t,o)}return r}Ae(1,e)},this.produceWithPatches=(e,t)=>{if(tt(e))return(t,...n)=>this.produceWithPatches(t,t=>e(t,...n));let n,r;return[this.produce(e,t,(e,t)=>{n=e,r=t}),n,r]},nt(e?.autoFreeze)&&this.setAutoFreeze(e.autoFreeze),nt(e?.useStrictShallowCopy)&&this.setUseStrictShallowCopy(e.useStrictShallowCopy),nt(e?.useStrictIteration)&&this.setUseStrictIteration(e.useStrictIteration)}createDraft(e){He(e)||Ae(8),Ue(e)&&(e=Ft(e));const t=bt(this),n=xt(0,e,void 0);return n[Oe].isManual_=!0,vt(t),n}finishDraft(e,t){const n=e&&e[Oe];n&&n.isManual_||Ae(9);const{scope_:r}=n;return yt(r,t),wt(void 0,r)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}setUseStrictIteration(e){this.useStrictIteration_=e}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(e,t){let n;for(n=t.length-1;n>=0;n--){const r=t[n];if(0===r.path.length&&"replace"===r.op){e=r.value;break}}n>-1&&(t=t.slice(n+1));const r=pt(ut).applyPatches_;return Ue(e)?r(e,t):this.produce(e,e=>r(e,t))}},Error;var jt=(e,t,n)=>{if(1===t.length&&t[0]===n){let t=!1;try{const n={};e(n)===n&&(t=!0)}catch{}if(t){let e;try{throw new Error}catch(t){({stack:e}=t)}console.warn("The result function returned its own inputs without modification. e.g\n`createSelector([state => state.todos], todos => todos)`\nThis could lead to inefficient memoization and unnecessary re-renders.\nEnsure transformation logic is in the result function, and extraction logic is in the input selectors.",{stack:e})}}},$t=(e,t,n)=>{const{memoize:r,memoizeOptions:o}=t,{inputSelectorResults:i,inputSelectorResultsCopy:s}=e,a=r(()=>({}),...o);if(a.apply(null,i)!==a.apply(null,s)){let e;try{throw new Error}catch(t){({stack:e}=t)}console.warn("An input selector returned a different result when passed same arguments.\nThis means your output selector will likely run more frequently than intended.\nAvoid returning a new reference inside your input selector, e.g.\n`createSelector([state => state.todos.map(todo => todo.id)], todoIds => todoIds.length)`",{arguments:n,firstInputs:i,secondInputs:s,stack:e})}},Ut={inputStabilityCheck:"once",identityFunctionCheck:"once"},Ht=e=>Array.isArray(e)?e:[e];function Kt(e,t){const n=[],{length:r}=e;for(let o=0;o<r;o++)n.push(e[o].apply(null,t));return n}var Gt="undefined"!=typeof WeakRef?WeakRef:class{constructor(e){this.value=e}deref(){return this.value}};function Wt(){return{s:0,v:void 0,o:null,p:null}}function Vt(e,t={}){let n={s:0,v:void 0,o:null,p:null};const{resultEqualityCheck:r}=t;let o,i=0;function s(){let t=n;const{length:s}=arguments;for(let e=0,n=s;e<n;e++){const n=arguments[e];if("function"==typeof n||"object"==typeof n&&null!==n){let e=t.o;null===e&&(t.o=e=new WeakMap);const r=e.get(n);void 0===r?(t=Wt(),e.set(n,t)):t=r}else{let e=t.p;null===e&&(t.p=e=new Map);const r=e.get(n);void 0===r?(t=Wt(),e.set(n,t)):t=r}}const a=t;let c;if(1===t.s)c=t.v;else if(c=e.apply(null,arguments),i++,r){const e=o?.deref?.()??o;null!=e&&r(e,c)&&(c=e,0!==i&&i--),o="object"==typeof c&&null!==c||"function"==typeof c?new Gt(c):c}return a.s=1,a.v=c,c}return s.clearCache=()=>{n={s:0,v:void 0,o:null,p:null},s.resetResultsCount()},s.resultsCount=()=>i,s.resetResultsCount=()=>{i=0},s}function Yt(e,...t){const n="function"==typeof e?{memoize:e,memoizeOptions:t}:e,r=(...e)=>{let t,r=0,o=0,i={},s=e.pop();"object"==typeof s&&(i=s,s=e.pop()),function(e,t="expected a function, instead received "+typeof e){if("function"!=typeof e)throw new TypeError(t)}(s,`createSelector expects an output function after the inputs, but received: [${typeof s}]`);const a={...n,...i},{memoize:c,memoizeOptions:l=[],argsMemoize:u=Vt,argsMemoizeOptions:d=[],devModeChecks:f={}}=a,p=Ht(l),h=Ht(d),m=function(e){const t=Array.isArray(e[0])?e[0]:e;return function(e,t="expected all items to be functions, instead received the following types: "){if(!e.every(e=>"function"==typeof e)){const n=e.map(e=>"function"==typeof e?`function ${e.name||"unnamed"}()`:typeof e).join(", ");throw new TypeError(`${t}[${n}]`)}}(t,"createSelector expects all input-selectors to be functions, but received the following types: "),t}(e),_=c(function(){return r++,s.apply(null,arguments)},...p);let y=!0;const g=u(function(){o++;const e=Kt(m,arguments);if(t=_.apply(null,e),"production"!==process.env.NODE_ENV){const{identityFunctionCheck:n,inputStabilityCheck:r}=((e,t)=>{const{identityFunctionCheck:n,inputStabilityCheck:r}={...Ut,...t};return{identityFunctionCheck:{shouldRun:"always"===n||"once"===n&&e,run:jt},inputStabilityCheck:{shouldRun:"always"===r||"once"===r&&e,run:$t}}})(y,f);if(n.shouldRun&&n.run(s,e,t),r.shouldRun){const t=Kt(m,arguments);r.run({inputSelectorResults:e,inputSelectorResultsCopy:t},{memoize:c,memoizeOptions:p},arguments)}y&&(y=!1)}return t},...h);return Object.assign(g,{resultFunc:s,memoizedResultFunc:_,dependencies:m,dependencyRecomputations:()=>o,resetDependencyRecomputations:()=>{o=0},lastResult:()=>t,recomputations:()=>r,resetRecomputations:()=>{r=0},memoize:c,argsMemoize:u})};return Object.assign(r,{withTypes:()=>r}),r}var qt=Yt(Vt),Bt=Object.assign((e,t=qt)=>{!function(e,t="expected an object, instead received "+typeof e){if("object"!=typeof e)throw new TypeError(t)}(e,"createStructuredSelector expects first argument to be an object where each property is a selector, instead received a "+typeof e);const n=Object.keys(e);return t(n.map(t=>e[t]),(...e)=>e.reduce((e,t,r)=>(e[n[r]]=t,e),{}))},{withTypes:()=>Bt}),Xt="__rtkq/",Jt="online",Qt="offline",Zt="focus",en="focused",tn="visibilitychange",nn=e(`${Xt}${en}`),rn=e(`${Xt}un${en}`),on=e(`${Xt}${Jt}`),sn=e(`${Xt}${Qt}`),an=!1;WeakMap,new Error("Promise never resolved before cacheEntryRemoved.");const cn=u({...E,auth:K,chat:w,conversations:S,voice:fe,indicator:H}),ln=b();ln.startListening({matcher:a(W,V),effect:(e,{dispatch:t})=>{t(k())}});const un=v({reducer:cn,middleware:e=>e({serializableCheck:P}).prepend(ln.middleware,G.middleware,pe.middleware).concat(I)});var dn;dn=un.dispatch,function(){const[e,t,n,r]=[nn,rn,on,sn].map(e=>()=>dn(e())),o=()=>{"visible"===window.document.visibilityState?e():t()};if(!an&&"undefined"!=typeof window&&window.addEventListener){let t=function(e){Object.entries(i).forEach(([t,n])=>{e?window.addEventListener(t,n,!1):window.removeEventListener(t,n)})};const i={[Zt]:e,[tn]:o,[Jt]:n,[Qt]:r};t(!0),an=!0}}(),Y(()=>un.getState().auth.accessToken),q(()=>un.getState().auth.tokenExpiresAt),T(()=>un.getState());const fn=!1,pn=!0,hn=!0,mn=X.ONLINE,_n=!0,yn=(e,t)=>null===e?t:"true"===e,gn=({children:e,defaultSttImplementation:t=mn})=>{const{user:n}=C(),r=n?.id,o=B(),[i,s]=_e(!1),[a,c]=_e(fn),[l,u]=_e(pn),[d,f]=_e(hn),[p,h]=_e(t),[m,_]=_e(_n);return ye(()=>{let e=!1;return Promise.all([o.getItem(J.DEBUG_MODE),o.getItem(J.LOCATION_ENABLED),o.getItem(J.STT_AUTO_SEND),o.getItem(J.STT_IMPLEMENTATION),o.getItem(J.SEND_DIAGNOSTICS)]).then(([n,r,o,i,s])=>{if(e)return;var a;c(yn(n,fn)),u(yn(r,pn)),f(yn(o,hn)),h((a=i)===X.ONLINE||a===X.DEVICE?a:t);const l=yn(s,_n);_(l),Q(l)}),()=>{e=!0}},[t,r,o]),he(O.Provider,{value:{enableTts:i,setEnableTts:s,debugMode:a,setDebugMode:e=>{c(e),o.setItem(J.DEBUG_MODE,String(e))},locationEnabled:l,setLocationEnabled:e=>{u(e),o.setItem(J.LOCATION_ENABLED,String(e))},autoSendVoice:d,setAutoSendVoice:e=>{f(e),o.setItem(J.STT_AUTO_SEND,String(e))},sttImplementation:p,setSttImplementation:e=>{h(e),o.setItem(J.STT_IMPLEMENTATION,e)},sendDiagnostics:m,setSendDiagnostics:e=>{_(e),Q(e),o.setItem(J.SEND_DIAGNOSTICS,String(e))}},children:e})},vn=M;async function bn(e){if(e instanceof File)return e;const t=e;if(t?.file instanceof File)return t.file;if(t?.uri){const e=await(await fetch(t.uri)).blob();return new File([e],t.name??"upload",{type:t.mimeType??e.type})}throw new Error("Could not read the selected file.")}function Sn(e){const[t]=D(),[n]=A();return{onUploadFile:ge(async(n,r)=>{try{return{documentId:(await t({file:await bn(n),filename:r.fileRequestId,documentType:r.documentType,conversationId:e,onUploadProgress:r.onProgress,onUploadComplete:()=>r.onPhase?.("processing")}).unwrap()).data.document_id}}catch(e){if(e instanceof Error)throw e;throw new Error(z(e,"Upload failed. Please try again."))}},[t,e]),onRemoveFile:ge(e=>{n(e)},[n])}}const wn=be(void 0),En=be({}),Pn=({children:e,messageId:t,isDisabled:n=!1})=>{const[r,o]=_e({});return he(wn.Provider,{value:{messageContext:r,setMessageContext:o,updateMessageContext:(e,t)=>{o(n=>({...n,[e]:t}))},messageId:t},children:he(En.Provider,{value:{messageId:t,isDisabled:n},children:e})})},In=()=>{const e=ve(wn);if(!e)throw new Error("useMessageContext must be used within MessageContextProvider");return e},kn=()=>{const e=ve(En);return e?.messageId},Tn=()=>{const e=ve(En);return e?.isDisabled??!1};function Mn(){return"undefined"!=typeof window&&window.matchMedia?window.matchMedia("(prefers-color-scheme: dark)").matches?Z.DARK:Z.LIGHT:Z.DARK}const Cn=({children:e,orgId:t,fallbackThemeStyles:n,initialAppearanceMode:r=Z.SYSTEM})=>{const{user:o}=C(),i=o?.id,s=B(),[a,c]=_e(r),[l,u]=_e(()=>r===Z.SYSTEM?Mn():r);ye(()=>{let e=!1;const t=ee(i),n=J.APPEARANCE_MODE_KEY;return(async()=>{const o=await s.getItem(t);if(i&&await s.removeItem(n),e)return;const a=((e,t)=>e===Z.LIGHT||e===Z.DARK||e===Z.SYSTEM?e:t)(o,r);c(a),u(a===Z.SYSTEM?Mn():a)})(),()=>{e=!0}},[i,s,r]),ye(()=>{if(a!==Z.SYSTEM)return;const e=window.matchMedia("(prefers-color-scheme: dark)"),t=e=>{u(e.matches?Z.DARK:Z.LIGHT)};return u(e.matches?Z.DARK:Z.LIGHT),e.addEventListener("change",t),()=>e.removeEventListener("change",t)},[a]);const d=t||void 0,{data:f,isLoading:p,error:h}=N(d),m=f?.success?f.data??null:null,_=m?.themes?(l===Z.LIGHT?m.themes.light:m.themes.dark)??null:null,y=Se(()=>!m&&n?n:te(m,_,l),[m,_,l,n]),g=m?.orbPosition??ne.FOREGROUND,v=m?.showAmbientWave??!0,b=ge(e=>{c(e);const t=ee(i);s.setItem(t,e),i&&s.removeItem(J.APPEARANCE_MODE_KEY),u(e===Z.SYSTEM?Mn():e)},[s,i]),S={theme:l,setTheme:b,appearanceMode:a,isLoading:p,error:h?new Error("Failed to fetch branding"):null,currentThemeColors:_,themeStyles:y,orbPosition:g,showAmbientWave:v};return he(re.Provider,{value:S,children:e})},On=({children:e,protocolType:t})=>{const n=t||x,r=Se(()=>R(n,F({onAuthExpired:()=>un.dispatch(W())})),[n]),o=Se(()=>({adapter:r,protocolType:n}),[r,n]);return he(L.Provider,{value:o,children:e})},Dn=({value:e,children:t,fallback:n,extraHydrations:r})=>{oe(e);const o=Ie(),i=void 0!==n,[s,a]=_e(!i);return ye(()=>{let t=!1;const n=[o(ie(e))];if(r)for(const t of r)n.push(Promise.resolve(t(e,o)).catch(e=>{se.error({message:"StorageProvider hydration step failed",component:"StorageProvider",error_message:e instanceof Error?e.message:String(e)})}));return Promise.all(n).finally(()=>{t||i&&a(!0)}),()=>{t=!0}},[]),he(ae.Provider,{value:e,children:i&&!s?he(me,{children:n}):t})},An=({token:e,user:t,children:n})=>{const r=we(null);return e&&e!==r.current&&(r.current=e,un.dispatch(ce({accessToken:e,expiresIn:Math.floor(Date.now()/1e3)+3600,...t&&{user:{id:"",email:t.email||"",name:t.name}}}))),he(me,{children:n})},zn=({children:e})=>he(j.Provider,{value:$(),children:e}),Nn=({children:e,callbacks:t})=>he(U.Provider,{value:t,children:e}),Rn=({baseUrl:e,customHeaders:t,token:n,user:r,protocol:o=x,paymentProvider:i,onConversationChange:s,onConversationTitleChange:a,onMessagesChange:c,onLogoutRequested:l,onSessionExpired:u,storage:d,storageFallback:f,extraHydrations:p,orgId:h,initialThemeStyles:m,initialAppearanceMode:_,reuseHostBranding:y=!1,manageTokenRefresh:g=!0,audioPlatform:v,networkMonitor:b,children:S})=>{le({baseUrl:e,customHeaders:t,paymentProvider:i}),g&&ue(u??null);const w=he(Te,{value:v,children:S});let E=he(An,{token:n,user:r,children:he(On,{protocolType:o,children:he(zn,{children:he(Nn,{callbacks:{onConversationChange:s,onConversationTitleChange:a,onMessagesChange:c,onLogoutRequested:l},children:y?w:he(Cn,{orgId:h,fallbackThemeStyles:m,initialAppearanceMode:_,children:w})})})})});return b&&(E=he(de.Provider,{value:b,children:E})),he(ke,{store:un,children:d?he(Dn,{value:d,fallback:f,extraHydrations:p,children:E}):E})},xn=Pe(()=>import("./PaymentProviderHost-DarMRZKF.js")),Fn=e=>he(Ee,{fallback:null,children:he(xn,{...e})}),Ln=()=>import("./PaymentProviderHost-DarMRZKF.js").catch(()=>{});export{Cn as BrandingProvider,Rn as ChatClientProvider,Pn as MessageContextProvider,Fn as PaymentProviderHost,gn as SettingsProvider,Dn as StorageProvider,Ln as preloadPaymentModal,cn as rootReducer,un as store,Sn as useDocumentUploadHandlers,In as useMessageContext,Tn as useMessageDisabled,kn as useMessageId,vn as useSettings};
1
+ import{createAction as e,nanoid as t,formatProdErrorMessage as n,createSelector as r,createAsyncThunk as o,createSlice as i,prepareAutoBatched as s,isAnyOf as a,isFulfilled as c,isRejectedWithValue as l,combineReducers as u,isPlainObject as d,SHOULD_AUTOBATCH as f,isAllOf as p,isRejected as h,isPending as m,isAction as _,createNextState as y,isAsyncThunkAction as g,configureStore as v,createListenerMiddleware as b}from"@reduxjs/toolkit";import{conversationsReducer as S,chatReducer as w,apiReducers as E,serializableCheck as P,apiMiddleware as I,resetAllApiState as k,bindChatLogger as T,useChatSettings as M,useAuth as C,ChatSettingsContext as O,useUploadDocumentMutation as D,useDeleteDocumentMutation as A,getApiErrorMessage as z,useGetBrandingQuery as N,createAdapter as R,DEFAULT_PROTOCOL as x,createDefaultAdapterConfig as F,ProtocolContext as L,ConfigurationContext as j,useConfigurationValue as $,ChatCallbacksContext as U}from"@1interface/chat-core";import{indicatorReducer as H,sessionReducer as K,sessionListenerMiddleware as G,clearSession as W,sessionExpired as V,setAccessTokenReader as Y,setTokenExpiresAtReader as q,useStorage as B,STT_IMPLEMENTATIONS as X,STORAGE_KEYS as J,setNetworkLoggingEnabled as Q,APPEARANCE_MODES as Z,getAppearanceModeStorageKey as ee,brandingToThemeStyles as te,ORB_POSITIONS as ne,BrandingContext as re,setModuleStorage as oe,hydrateSession as ie,logger as se,StorageContext as ae,setSession as ce,initializeChatConfig as le,setTokenRefreshHandler as ue,NetworkContext as de}from"@1interface/shared-core";import{voiceReducer as fe,voiceListenerMiddleware as pe}from"@1interface/voice-core";import{jsx as he,Fragment as me}from"react/jsx-runtime";import{useState as _e,useEffect as ye,useCallback as ge,useContext as ve,createContext as be,useMemo as Se,useRef as we,Suspense as Ee,lazy as Pe}from"react";import{useDispatch as Ie,Provider as ke}from"react-redux";import{AudioPlatformProvider as Te}from"@1interface/voice-shell";var Me=Symbol.for("immer-nothing"),Ce=Symbol.for("immer-draftable"),Oe=Symbol.for("immer-state"),De="production"!==process.env.NODE_ENV?[function(e){return`The plugin for '${e}' has not been loaded into Immer. To enable the plugin, import and call \`enable${e}()\` when initializing your application.`},function(e){return`produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${e}'`},"This object has been frozen and should not be mutated",function(e){return"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+e},"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.","Immer forbids circular references","The first or second argument to `produce` must be a function","The third argument to `produce` must be a function or undefined","First argument to `createDraft` must be a plain object, an array, or an immerable object","First argument to `finishDraft` must be a draft returned by `createDraft`",function(e){return`'current' expects a draft, got: ${e}`},"Object.defineProperty() cannot be used on an Immer draft","Object.setPrototypeOf() cannot be used on an Immer draft","Immer only supports deleting array indices","Immer only supports setting array indices and the 'length' property",function(e){return`'original' expects a draft, got: ${e}`}]:[];function Ae(e,...t){if("production"!==process.env.NODE_ENV){const n=De[e],r=tt(n)?n.apply(null,t):n;throw new Error(`[Immer] ${r}`)}throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var ze=Object,Ne=ze.getPrototypeOf,Re="constructor",xe="prototype",Fe="configurable",Le="enumerable",je="writable",$e="value",Ue=e=>!!e&&!!e[Oe];function He(e){return!!e&&(We(e)||Je(e)||!!e[Ce]||!!e[Re]?.[Ce]||Qe(e)||Ze(e))}var Ke=ze[xe][Re].toString(),Ge=new WeakMap;function We(e){if(!e||!et(e))return!1;const t=Ne(e);if(null===t||t===ze[xe])return!0;const n=ze.hasOwnProperty.call(t,Re)&&t[Re];if(n===Object)return!0;if(!tt(n))return!1;let r=Ge.get(n);return void 0===r&&(r=Function.toString.call(n),Ge.set(n,r)),r===Ke}function Ve(e,t,n=!0){0===Ye(e)?(n?Reflect.ownKeys(e):ze.keys(e)).forEach(n=>{t(n,e[n],e)}):e.forEach((n,r)=>t(r,n,e))}function Ye(e){const t=e[Oe];return t?t.type_:Je(e)?1:Qe(e)?2:Ze(e)?3:0}var qe=(e,t,n=Ye(e))=>2===n?e.has(t):ze[xe].hasOwnProperty.call(e,t),Be=(e,t,n=Ye(e))=>2===n?e.get(t):e[t],Xe=(e,t,n,r=Ye(e))=>{2===r?e.set(t,n):3===r?e.add(n):e[t]=n},Je=Array.isArray,Qe=e=>e instanceof Map,Ze=e=>e instanceof Set,et=e=>"object"==typeof e,tt=e=>"function"==typeof e,nt=e=>"boolean"==typeof e,rt=e=>e.copy_||e.base_,ot=e=>e.modified_?e.copy_:e.base_;function it(e,t){if(Qe(e))return new Map(e);if(Ze(e))return new Set(e);if(Je(e))return Array[xe].slice.call(e);const n=We(e);if(!0===t||"class_only"===t&&!n){const t=ze.getOwnPropertyDescriptors(e);delete t[Oe];let n=Reflect.ownKeys(t);for(let r=0;r<n.length;r++){const o=n[r],i=t[o];!1===i[je]&&(i[je]=!0,i[Fe]=!0),(i.get||i.set)&&(t[o]={[Fe]:!0,[je]:!0,[Le]:i[Le],[$e]:e[o]})}return ze.create(Ne(e),t)}{const t=Ne(e);if(null!==t&&n)return{...e};const r=ze.create(t);return ze.assign(r,e)}}function st(e,t=!1){return ct(e)||Ue(e)||!He(e)||(Ye(e)>1&&ze.defineProperties(e,{set:at,add:at,clear:at,delete:at}),ze.freeze(e),t&&Ve(e,(e,t)=>{st(t,!0)},!1)),e}var at={[$e]:function(){Ae(2)}};function ct(e){return null===e||!et(e)||ze.isFrozen(e)}var lt="MapSet",ut="Patches",dt="ArrayMethods",ft={};function pt(e){const t=ft[e];return t||Ae(0,e),t}var ht,mt=e=>!!ft[e],_t=()=>ht;function yt(e,t){t&&(e.patchPlugin_=pt(ut),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function gt(e){vt(e),e.drafts_.forEach(St),e.drafts_=null}function vt(e){e===ht&&(ht=e.parent_)}var bt=e=>ht={drafts_:[],parent_:ht,immer_:e,canAutoFreeze_:!0,unfinalizedDrafts_:0,handledSet_:new Set,processedForPatches_:new Set,mapSetPlugin_:mt(lt)?pt(lt):void 0,arrayMethodsPlugin_:mt(dt)?pt(dt):void 0};function St(e){const t=e[Oe];0===t.type_||1===t.type_?t.revoke_():t.revoked_=!0}function wt(e,t){t.unfinalizedDrafts_=t.drafts_.length;const n=t.drafts_[0];if(void 0!==e&&e!==n){n[Oe].modified_&&(gt(t),Ae(4)),He(e)&&(e=Et(t,e));const{patchPlugin_:r}=t;r&&r.generateReplacementPatches_(n[Oe].base_,e,t)}else e=Et(t,n);return function(e,t,n=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&st(t,n)}(t,e,!0),gt(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==Me?e:void 0}function Et(e,t){if(ct(t))return t;const n=t[Oe];if(!n)return Ct(t,e.handledSet_,e);if(!It(n,e))return t;if(!n.modified_)return n.base_;if(!n.finalized_){const{callbacks_:t}=n;if(t)for(;t.length>0;)t.pop()(e);Mt(n,e)}return n.copy_}function Pt(e){e.finalized_=!0,e.scope_.unfinalizedDrafts_--}var It=(e,t)=>e.scope_===t,kt=[];function Tt(e,t,n,r){const o=rt(e),i=e.type_;if(void 0!==r&&Be(o,r,i)===t)return void Xe(o,r,n,i);if(!e.draftLocations_){const t=e.draftLocations_=new Map;Ve(o,(e,n)=>{if(Ue(n)){const r=t.get(n)||[];r.push(e),t.set(n,r)}})}const s=e.draftLocations_.get(t)??kt;for(const e of s)Xe(o,e,n,i)}function Mt(e,t){if(e.modified_&&!e.finalized_&&(3===e.type_||1===e.type_&&e.allIndicesReassigned_||(e.assigned_?.size??0)>0)){const{patchPlugin_:n}=t;if(n){const r=n.getPath(e);r&&n.generatePatches_(e,r,t)}Pt(e)}}function Ct(e,t,n){return!n.immer_.autoFreeze_&&n.unfinalizedDrafts_<1||Ue(e)||t.has(e)||!He(e)||ct(e)||(t.add(e),Ve(e,(r,o)=>{if(Ue(o)){const t=o[Oe];if(It(t,n)){const n=ot(t);Xe(e,r,n,e.type_),Pt(t)}}else He(o)&&Ct(o,t,n)})),e}var Ot={get(e,t){if(t===Oe)return e;let n=e.scope_.arrayMethodsPlugin_;const r=1===e.type_&&"string"==typeof t;if(r&&n?.isArrayOperationMethod(t))return n.createMethodInterceptor(e,t);const o=rt(e);if(!qe(o,t,e.type_))return function(e,t,n){const r=zt(t,n);return r?$e in r?r[$e]:r.get?.call(e.draft_):void 0}(e,o,t);const i=o[t];if(e.finalized_||!He(i))return i;if(r&&e.operationMethod&&n?.isMutatingArrayMethod(e.operationMethod)&&function(e){const t=+e;return Number.isInteger(t)&&String(t)===e}(t))return i;if(i===At(e.base_,t)){Rt(e);const n=1===e.type_?+t:t,r=xt(0,i,e,n);return e.copy_[n]=r}return i},has:(e,t)=>t in rt(e),ownKeys:e=>Reflect.ownKeys(rt(e)),set(e,t,n){const r=zt(rt(e),t);if(r?.set)return r.set.call(e.draft_,n),!0;if(!e.modified_){const r=At(rt(e),t),s=r?.[Oe];if(s&&s.base_===n)return e.copy_[t]=n,e.assigned_.set(t,!1),!0;if(((o=n)===(i=r)?0!==o||1/o==1/i:o!=o&&i!=i)&&(void 0!==n||qe(e.base_,t,e.type_)))return!0;Rt(e),Nt(e)}var o,i;return e.copy_[t]===n&&(void 0!==n||t in e.copy_)||Number.isNaN(n)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=n,e.assigned_.set(t,!0),function(e,t,n){const{scope_:r}=e;if(Ue(n)){const o=n[Oe];It(o,r)&&o.callbacks_.push(function(){Rt(e);const r=ot(o);Tt(e,n,r,t)})}else He(n)&&e.callbacks_.push(function(){const o=rt(e);3===e.type_?o.has(n)&&Ct(n,r.handledSet_,r):Be(o,t,e.type_)===n&&r.drafts_.length>1&&!0===(e.assigned_.get(t)??!1)&&e.copy_&&Ct(Be(e.copy_,t,e.type_),r.handledSet_,r)})}(e,t,n)),!0},deleteProperty:(e,t)=>(Rt(e),void 0!==At(e.base_,t)||t in e.base_?(e.assigned_.set(t,!1),Nt(e)):e.assigned_.delete(t),e.copy_&&delete e.copy_[t],!0),getOwnPropertyDescriptor(e,t){const n=rt(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r?{[je]:!0,[Fe]:1!==e.type_||"length"!==t,[Le]:r[Le],[$e]:n[t]}:r},defineProperty(){Ae(11)},getPrototypeOf:e=>Ne(e.base_),setPrototypeOf(){Ae(12)}},Dt={};for(let e in Ot){let t=Ot[e];Dt[e]=function(){const e=arguments;return e[0]=e[0][0],t.apply(this,e)}}function At(e,t){const n=e[Oe];return(n?rt(n):e)[t]}function zt(e,t){if(!(t in e))return;let n=Ne(e);for(;n;){const e=Object.getOwnPropertyDescriptor(n,t);if(e)return e;n=Ne(n)}}function Nt(e){e.modified_||(e.modified_=!0,e.parent_&&Nt(e.parent_))}function Rt(e){e.copy_||(e.assigned_=new Map,e.copy_=it(e.base_,e.scope_.immer_.useStrictShallowCopy_))}function xt(e,t,n,r){const[o,i]=Qe(t)?pt(lt).proxyMap_(t,n):Ze(t)?pt(lt).proxySet_(t,n):function(e,t){const n=Je(e),r={type_:n?1:0,scope_:t?t.scope_:_t(),modified_:!1,finalized_:!1,assigned_:void 0,parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1,callbacks_:void 0};let o=r,i=Ot;n&&(o=[r],i=Dt);const{revoke:s,proxy:a}=Proxy.revocable(o,i);return r.draft_=a,r.revoke_=s,[a,r]}(t,n);return(n?.scope_??_t()).drafts_.push(o),i.callbacks_=n?.callbacks_??[],i.key_=r,n&&void 0!==r?function(e,t,n){e.callbacks_.push(function(r){const o=t;if(!o||!It(o,r))return;r.mapSetPlugin_?.fixSetContents(o);const i=ot(o);Tt(e,o.draft_??o,i,n),Mt(o,r)})}(n,i,r):i.callbacks_.push(function(e){e.mapSetPlugin_?.fixSetContents(i);const{patchPlugin_:t}=e;i.modified_&&t&&t.generatePatches_(i,[],e)}),o}function Ft(e){return Ue(e)||Ae(10,e),Lt(e)}function Lt(e){if(!He(e)||ct(e))return e;const t=e[Oe];let n,r=!0;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,n=it(e,t.scope_.immer_.useStrictShallowCopy_),r=t.scope_.immer_.shouldUseStrictIteration()}else n=it(e,!0);return Ve(n,(e,t)=>{Xe(n,e,Lt(t))},r),t&&(t.finalized_=!1),n}Dt.deleteProperty=function(e,t){return"production"!==process.env.NODE_ENV&&isNaN(parseInt(t))&&Ae(13),Dt.set.call(this,e,t,void 0)},Dt.set=function(e,t,n){return"production"!==process.env.NODE_ENV&&"length"!==t&&isNaN(parseInt(t))&&Ae(14),Ot.set.call(this,e[0],t,n,e[0])},new class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!1,this.produce=(e,t,n)=>{if(tt(e)&&!tt(t)){const n=t;t=e;const r=this;return function(e=n,...o){return r.produce(e,e=>t.call(this,e,...o))}}let r;if(tt(t)||Ae(6),void 0===n||tt(n)||Ae(7),He(e)){const o=bt(this),i=xt(0,e,void 0);let s=!0;try{r=t(i),s=!1}finally{s?gt(o):vt(o)}return yt(o,n),wt(r,o)}if(!e||!et(e)){if(r=t(e),void 0===r&&(r=e),r===Me&&(r=void 0),this.autoFreeze_&&st(r,!0),n){const t=[],o=[];pt(ut).generateReplacementPatches_(e,r,{patches_:t,inversePatches_:o}),n(t,o)}return r}Ae(1,e)},this.produceWithPatches=(e,t)=>{if(tt(e))return(t,...n)=>this.produceWithPatches(t,t=>e(t,...n));let n,r;return[this.produce(e,t,(e,t)=>{n=e,r=t}),n,r]},nt(e?.autoFreeze)&&this.setAutoFreeze(e.autoFreeze),nt(e?.useStrictShallowCopy)&&this.setUseStrictShallowCopy(e.useStrictShallowCopy),nt(e?.useStrictIteration)&&this.setUseStrictIteration(e.useStrictIteration)}createDraft(e){He(e)||Ae(8),Ue(e)&&(e=Ft(e));const t=bt(this),n=xt(0,e,void 0);return n[Oe].isManual_=!0,vt(t),n}finishDraft(e,t){const n=e&&e[Oe];n&&n.isManual_||Ae(9);const{scope_:r}=n;return yt(r,t),wt(void 0,r)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}setUseStrictIteration(e){this.useStrictIteration_=e}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(e,t){let n;for(n=t.length-1;n>=0;n--){const r=t[n];if(0===r.path.length&&"replace"===r.op){e=r.value;break}}n>-1&&(t=t.slice(n+1));const r=pt(ut).applyPatches_;return Ue(e)?r(e,t):this.produce(e,e=>r(e,t))}},Error;var jt=(e,t,n)=>{if(1===t.length&&t[0]===n){let t=!1;try{const n={};e(n)===n&&(t=!0)}catch{}if(t){let e;try{throw new Error}catch(t){({stack:e}=t)}console.warn("The result function returned its own inputs without modification. e.g\n`createSelector([state => state.todos], todos => todos)`\nThis could lead to inefficient memoization and unnecessary re-renders.\nEnsure transformation logic is in the result function, and extraction logic is in the input selectors.",{stack:e})}}},$t=(e,t,n)=>{const{memoize:r,memoizeOptions:o}=t,{inputSelectorResults:i,inputSelectorResultsCopy:s}=e,a=r(()=>({}),...o);if(a.apply(null,i)!==a.apply(null,s)){let e;try{throw new Error}catch(t){({stack:e}=t)}console.warn("An input selector returned a different result when passed same arguments.\nThis means your output selector will likely run more frequently than intended.\nAvoid returning a new reference inside your input selector, e.g.\n`createSelector([state => state.todos.map(todo => todo.id)], todoIds => todoIds.length)`",{arguments:n,firstInputs:i,secondInputs:s,stack:e})}},Ut={inputStabilityCheck:"once",identityFunctionCheck:"once"},Ht=e=>Array.isArray(e)?e:[e];function Kt(e,t){const n=[],{length:r}=e;for(let o=0;o<r;o++)n.push(e[o].apply(null,t));return n}var Gt="undefined"!=typeof WeakRef?WeakRef:class{constructor(e){this.value=e}deref(){return this.value}};function Wt(){return{s:0,v:void 0,o:null,p:null}}function Vt(e,t={}){let n={s:0,v:void 0,o:null,p:null};const{resultEqualityCheck:r}=t;let o,i=0;function s(){let t=n;const{length:s}=arguments;for(let e=0,n=s;e<n;e++){const n=arguments[e];if("function"==typeof n||"object"==typeof n&&null!==n){let e=t.o;null===e&&(t.o=e=new WeakMap);const r=e.get(n);void 0===r?(t=Wt(),e.set(n,t)):t=r}else{let e=t.p;null===e&&(t.p=e=new Map);const r=e.get(n);void 0===r?(t=Wt(),e.set(n,t)):t=r}}const a=t;let c;if(1===t.s)c=t.v;else if(c=e.apply(null,arguments),i++,r){const e=o?.deref?.()??o;null!=e&&r(e,c)&&(c=e,0!==i&&i--),o="object"==typeof c&&null!==c||"function"==typeof c?new Gt(c):c}return a.s=1,a.v=c,c}return s.clearCache=()=>{n={s:0,v:void 0,o:null,p:null},s.resetResultsCount()},s.resultsCount=()=>i,s.resetResultsCount=()=>{i=0},s}function Yt(e,...t){const n="function"==typeof e?{memoize:e,memoizeOptions:t}:e,r=(...e)=>{let t,r=0,o=0,i={},s=e.pop();"object"==typeof s&&(i=s,s=e.pop()),function(e,t="expected a function, instead received "+typeof e){if("function"!=typeof e)throw new TypeError(t)}(s,`createSelector expects an output function after the inputs, but received: [${typeof s}]`);const a={...n,...i},{memoize:c,memoizeOptions:l=[],argsMemoize:u=Vt,argsMemoizeOptions:d=[],devModeChecks:f={}}=a,p=Ht(l),h=Ht(d),m=function(e){const t=Array.isArray(e[0])?e[0]:e;return function(e,t="expected all items to be functions, instead received the following types: "){if(!e.every(e=>"function"==typeof e)){const n=e.map(e=>"function"==typeof e?`function ${e.name||"unnamed"}()`:typeof e).join(", ");throw new TypeError(`${t}[${n}]`)}}(t,"createSelector expects all input-selectors to be functions, but received the following types: "),t}(e),_=c(function(){return r++,s.apply(null,arguments)},...p);let y=!0;const g=u(function(){o++;const e=Kt(m,arguments);if(t=_.apply(null,e),"production"!==process.env.NODE_ENV){const{identityFunctionCheck:n,inputStabilityCheck:r}=((e,t)=>{const{identityFunctionCheck:n,inputStabilityCheck:r}={...Ut,...t};return{identityFunctionCheck:{shouldRun:"always"===n||"once"===n&&e,run:jt},inputStabilityCheck:{shouldRun:"always"===r||"once"===r&&e,run:$t}}})(y,f);if(n.shouldRun&&n.run(s,e,t),r.shouldRun){const t=Kt(m,arguments);r.run({inputSelectorResults:e,inputSelectorResultsCopy:t},{memoize:c,memoizeOptions:p},arguments)}y&&(y=!1)}return t},...h);return Object.assign(g,{resultFunc:s,memoizedResultFunc:_,dependencies:m,dependencyRecomputations:()=>o,resetDependencyRecomputations:()=>{o=0},lastResult:()=>t,recomputations:()=>r,resetRecomputations:()=>{r=0},memoize:c,argsMemoize:u})};return Object.assign(r,{withTypes:()=>r}),r}var qt=Yt(Vt),Bt=Object.assign((e,t=qt)=>{!function(e,t="expected an object, instead received "+typeof e){if("object"!=typeof e)throw new TypeError(t)}(e,"createStructuredSelector expects first argument to be an object where each property is a selector, instead received a "+typeof e);const n=Object.keys(e);return t(n.map(t=>e[t]),(...e)=>e.reduce((e,t,r)=>(e[n[r]]=t,e),{}))},{withTypes:()=>Bt}),Xt="__rtkq/",Jt="online",Qt="offline",Zt="focus",en="focused",tn="visibilitychange",nn=e(`${Xt}${en}`),rn=e(`${Xt}un${en}`),on=e(`${Xt}${Jt}`),sn=e(`${Xt}${Qt}`),an=!1;WeakMap,new Error("Promise never resolved before cacheEntryRemoved.");const cn=u({...E,auth:K,chat:w,conversations:S,voice:fe,indicator:H}),ln=b();ln.startListening({matcher:a(W,V),effect:(e,{dispatch:t})=>{t(k())}});const un=v({reducer:cn,middleware:e=>e({serializableCheck:P}).prepend(ln.middleware,G.middleware,pe.middleware).concat(I)});var dn;dn=un.dispatch,function(){const[e,t,n,r]=[nn,rn,on,sn].map(e=>()=>dn(e())),o=()=>{"visible"===window.document.visibilityState?e():t()};if(!an&&"undefined"!=typeof window&&window.addEventListener){let t=function(e){Object.entries(i).forEach(([t,n])=>{e?window.addEventListener(t,n,!1):window.removeEventListener(t,n)})};const i={[Zt]:e,[tn]:o,[Jt]:n,[Qt]:r};t(!0),an=!0}}(),Y(()=>un.getState().auth.accessToken),q(()=>un.getState().auth.tokenExpiresAt),T(()=>un.getState());const fn=!1,pn=!0,hn=!0,mn=X.ONLINE,_n=!0,yn=(e,t)=>null===e?t:"true"===e,gn=({children:e,defaultSttImplementation:t=mn})=>{const{user:n}=C(),r=n?.id,o=B(),[i,s]=_e(!1),[a,c]=_e(fn),[l,u]=_e(pn),[d,f]=_e(hn),[p,h]=_e(t),[m,_]=_e(_n);return ye(()=>{let e=!1;return Promise.all([o.getItem(J.DEBUG_MODE),o.getItem(J.LOCATION_ENABLED),o.getItem(J.STT_AUTO_SEND),o.getItem(J.STT_IMPLEMENTATION),o.getItem(J.SEND_DIAGNOSTICS)]).then(([n,r,o,i,s])=>{if(e)return;var a;c(yn(n,fn)),u(yn(r,pn)),f(yn(o,hn)),h((a=i)===X.ONLINE||a===X.DEVICE?a:t);const l=yn(s,_n);_(l),Q(l)}),()=>{e=!0}},[t,r,o]),he(O.Provider,{value:{enableTts:i,setEnableTts:s,debugMode:a,setDebugMode:e=>{c(e),o.setItem(J.DEBUG_MODE,String(e))},locationEnabled:l,setLocationEnabled:e=>{u(e),o.setItem(J.LOCATION_ENABLED,String(e))},autoSendVoice:d,setAutoSendVoice:e=>{f(e),o.setItem(J.STT_AUTO_SEND,String(e))},sttImplementation:p,setSttImplementation:e=>{h(e),o.setItem(J.STT_IMPLEMENTATION,e)},sendDiagnostics:m,setSendDiagnostics:e=>{_(e),Q(e),o.setItem(J.SEND_DIAGNOSTICS,String(e))}},children:e})},vn=M;async function bn(e){if(e instanceof File)return e;const t=e;if(t?.file instanceof File)return t.file;if(t?.uri){const e=await(await fetch(t.uri)).blob();return new File([e],t.name??"upload",{type:t.mimeType??e.type})}throw new Error("Could not read the selected file.")}function Sn(e){const[t]=D(),[n]=A();return{onUploadFile:ge(async(n,r)=>{try{return{documentId:(await t({file:await bn(n),filename:r.fileRequestId,documentType:r.documentType,conversationId:e,onUploadProgress:r.onProgress,onUploadComplete:()=>r.onPhase?.("processing")}).unwrap()).data.document_id}}catch(e){if(e instanceof Error)throw e;throw new Error(z(e,"Upload failed. Please try again."))}},[t,e]),onRemoveFile:ge(e=>{n(e)},[n])}}const wn=be(void 0),En=be({}),Pn=({children:e,messageId:t,isDisabled:n=!1})=>{const[r,o]=_e({});return he(wn.Provider,{value:{messageContext:r,setMessageContext:o,updateMessageContext:(e,t)=>{o(n=>({...n,[e]:t}))},messageId:t},children:he(En.Provider,{value:{messageId:t,isDisabled:n},children:e})})},In=()=>{const e=ve(wn);if(!e)throw new Error("useMessageContext must be used within MessageContextProvider");return e},kn=()=>{const e=ve(En);return e?.messageId},Tn=()=>{const e=ve(En);return e?.isDisabled??!1};function Mn(){return"undefined"!=typeof window&&window.matchMedia?window.matchMedia("(prefers-color-scheme: dark)").matches?Z.DARK:Z.LIGHT:Z.DARK}const Cn=({children:e,orgId:t,fallbackThemeStyles:n,initialAppearanceMode:r=Z.SYSTEM})=>{const{user:o}=C(),i=o?.id,s=B(),[a,c]=_e(r),[l,u]=_e(()=>r===Z.SYSTEM?Mn():r);ye(()=>{let e=!1;const t=ee(i),n=J.APPEARANCE_MODE_KEY;return(async()=>{const o=await s.getItem(t);if(i&&await s.removeItem(n),e)return;const a=((e,t)=>e===Z.LIGHT||e===Z.DARK||e===Z.SYSTEM?e:t)(o,r);c(a),u(a===Z.SYSTEM?Mn():a)})(),()=>{e=!0}},[i,s,r]),ye(()=>{if(a!==Z.SYSTEM)return;const e=window.matchMedia("(prefers-color-scheme: dark)"),t=e=>{u(e.matches?Z.DARK:Z.LIGHT)};return u(e.matches?Z.DARK:Z.LIGHT),e.addEventListener("change",t),()=>e.removeEventListener("change",t)},[a]);const d=t||void 0,{data:f,isLoading:p,error:h}=N(d),m=f?.success?f.data??null:null,_=m?.themes?(l===Z.LIGHT?m.themes.light:m.themes.dark)??null:null,y=Se(()=>!m&&n?n:te(m,_,l),[m,_,l,n]),g=m?.orbPosition??ne.FOREGROUND,v=m?.showAmbientWave??!0,b=ge(e=>{c(e);const t=ee(i);s.setItem(t,e),i&&s.removeItem(J.APPEARANCE_MODE_KEY),u(e===Z.SYSTEM?Mn():e)},[s,i]),S={theme:l,setTheme:b,appearanceMode:a,isLoading:p,error:h?new Error("Failed to fetch branding"):null,currentThemeColors:_,themeStyles:y,orbPosition:g,showAmbientWave:v};return he(re.Provider,{value:S,children:e})},On=({children:e,protocolType:t})=>{const n=t||x,r=Se(()=>R(n,F({onAuthExpired:()=>un.dispatch(W())})),[n]),o=Se(()=>({adapter:r,protocolType:n}),[r,n]);return he(L.Provider,{value:o,children:e})},Dn=({value:e,children:t,fallback:n,extraHydrations:r})=>{oe(e);const o=Ie(),i=void 0!==n,[s,a]=_e(!i);return ye(()=>{let t=!1;const n=[o(ie(e))];if(r)for(const t of r)n.push(Promise.resolve(t(e,o)).catch(e=>{se.error({message:"StorageProvider hydration step failed",component:"StorageProvider",error_message:e instanceof Error?e.message:String(e)})}));return Promise.all(n).finally(()=>{t||i&&a(!0)}),()=>{t=!0}},[]),he(ae.Provider,{value:e,children:i&&!s?he(me,{children:n}):t})},An=({token:e,user:t,children:n})=>{const r=we(null);return e&&e!==r.current&&(r.current=e,un.dispatch(ce({accessToken:e,expiresIn:Math.floor(Date.now()/1e3)+3600,...t&&{user:{id:"",email:t.email||"",name:t.name}}}))),he(me,{children:n})},zn=({children:e})=>he(j.Provider,{value:$(),children:e}),Nn=({children:e,callbacks:t})=>he(U.Provider,{value:t,children:e}),Rn=({baseUrl:e,customHeaders:t,token:n,user:r,protocol:o=x,paymentProvider:i,onConversationChange:s,onConversationTitleChange:a,onMessagesChange:c,onLogoutRequested:l,onSessionExpired:u,storage:d,storageFallback:f,extraHydrations:p,orgId:h,initialThemeStyles:m,initialAppearanceMode:_,reuseHostBranding:y=!1,manageTokenRefresh:g=!0,audioPlatform:v,networkMonitor:b,children:S})=>{le({baseUrl:e,customHeaders:t,paymentProvider:i}),g&&ue(u??null);const w=he(Te,{value:v,children:S});let E=he(An,{token:n,user:r,children:he(On,{protocolType:o,children:he(zn,{children:he(Nn,{callbacks:{onConversationChange:s,onConversationTitleChange:a,onMessagesChange:c,onLogoutRequested:l},children:y?w:he(Cn,{orgId:h,fallbackThemeStyles:m,initialAppearanceMode:_,children:w})})})})});return b&&(E=he(de.Provider,{value:b,children:E})),he(ke,{store:un,children:d?he(Dn,{value:d,fallback:f,extraHydrations:p,children:E}):E})},xn=Pe(()=>import("./PaymentProviderHost-DAkTAIUt.js")),Fn=e=>he(Ee,{fallback:null,children:he(xn,{...e})}),Ln=()=>import("./PaymentProviderHost-DAkTAIUt.js").catch(()=>{});export{Cn as BrandingProvider,Rn as ChatClientProvider,Pn as MessageContextProvider,Fn as PaymentProviderHost,gn as SettingsProvider,Dn as StorageProvider,Ln as preloadPaymentModal,cn as rootReducer,un as store,Sn as useDocumentUploadHandlers,In as useMessageContext,Tn as useMessageDisabled,kn as useMessageId,vn as useSettings};
@@ -0,0 +1 @@
1
+ import{jsx as u}from"react/jsx-runtime";import{useEffect as m,useRef as a,useState as s}from"react";import{ATB_FAILURE_CODES as i,ATB_FAILURE_MESSAGES as p,ATB_OUTCOMES as c,buildAtbResult as l,isAtbCheckoutUrl as A}from"@1interface/chat-core";import{logger as y}from"@1interface/shared-core";import{usePaymentAdapter as b}from"../PaymentProvider";import{useResultEmitter as f}from"../PaymentResultChannel";import{AtbCheckoutFrame as S}from"./atb/AtbCheckoutFrame";const d=({init:t,skin:n})=>{const r=f(),[e]=s(()=>!A(t.config.url)),o=a(!1);return m(()=>{!e||o.current||(o.current=!0,y.warn({message:"ATB checkout url is not https",api_name:"atb-payment",reference_id:t.payment_id}),r(l({outcome:c.FAILED,init:t,message:p.SESSION_INVALID,code:i.SESSION_INVALID})))},[e,t,r]),e?null:u(S,{init:t,onResult:r,skin:n})},E=({skin:t,onReady:n})=>{const{paymentInit:r}=b(),e=r?.provider==="atb"?r:null;return m(()=>{n?.()},[n]),e?u(d,{init:e,skin:t},e.payment_id):null},R={type:"atb",label:"ATB",hideShellSubmit:!0,hideShellFooter:!0,FormComponent:E};export{R as atbPaymentAdapter};
@@ -0,0 +1 @@
1
+ import{jsx as A,jsxs as W}from"react/jsx-runtime";import{useCallback as I,useEffect as w,useMemo as P,useRef as p,useState as S}from"react";import{ATB_FAILURE_CODES as L,ATB_FAILURE_MESSAGES as R,ATB_OUTCOMES as T,ATB_MESSAGE_TYPES as n,buildAtbResult as x,isAtbMessage as D,readAtbOutcome as k,readAtbCompletion as F,readAtbRedirect as M,resolveAtbOrigin as C}from"@1interface/chat-core";import{logger as l}from"@1interface/shared-core";const N=6e4,d="atb-payment";function B(){const e=document.createElement("div");e.style.cssText="position:absolute;top:-9999px;width:100px;height:100px;overflow:scroll;",document.body.appendChild(e);const s=e.offsetWidth-e.clientWidth;return e.remove(),Math.max(0,s)}const $=({init:e,onResult:s,skin:u})=>{const i=p(null),b=p(!1),g=p(!1),[E,v]=S(!1),[O]=S(B),m=P(()=>C(e.config.url),[e.config.url]),a=e.payment_id,o=I((t,r={})=>{b.current||(b.current=!0,l.info({message:"[atb] outcome",api_name:d,reference_id:a,outcome:t}),s(x({outcome:t,init:e,...r})))},[e,a,s]),h=I(()=>{g.current=!0,v(!0)},[]);return w(()=>{if(!m)return;const t=r=>{if(r.source!==i.current?.contentWindow||r.origin!==m||!D(r.data))return;const{type:f,data:y}=r.data,c=f===n.COMPLETED?F(y):{};switch(l.info({message:"[atb] gateway event",api_name:d,reference_id:a,type:f,status:c.status??null,checkout_id:c.checkoutId??null}),f){case n.READY:h();return;case n.COMPLETED:o(k(c.status),{checkoutId:c.checkoutId});return;case n.ERROR:o(T.FAILED,{message:R.SESSION_INVALID,code:L.SESSION_INVALID});return;case n.REDIRECT:{const _=M(y);if(!_){l.warn({message:"ATB wallet redirect carried no https url",api_name:d});return}l.info({message:"[atb] wallet redirect in frame",api_name:d,reference_id:a}),i.current&&(i.current.src=_)}}};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[m,a,h,o]),w(()=>{const t=setTimeout(()=>{g.current||o(T.FAILED,{message:R.LOAD_FAILED,code:L.LOAD_FAILED})},N);return()=>clearTimeout(t)},[o]),A("div",{className:"absolute inset-0 z-[105] flex flex-col overflow-hidden",style:{background:u.cardBg},role:"region","aria-label":"Payment",children:W("div",{className:"relative flex min-h-0 flex-1 overflow-hidden",children:[!E&&A("div",{className:"absolute inset-0 flex items-center justify-center text-sm",style:{color:u.muted,fontFamily:u.fontFamily},children:"Loading\u2026"}),A("iframe",{ref:i,src:e.config.url,title:"Payment",className:`min-h-0 flex-1 ${E?"":"invisible"}`,style:{border:0,background:"white",width:`calc(100% + ${O}px)`},allow:"payment",referrerPolicy:"no-referrer"})]})})};export{N as ATB_LOAD_TIMEOUT_MS,$ as AtbCheckoutFrame};
@@ -1 +1 @@
1
- import{stripePaymentAdapter as t}from"./StripePaymentAdapter";import{moyasarPaymentAdapter as o}from"./MoyasarPaymentAdapter";import{chargebeePaymentAdapter as p}from"./ChargebeePaymentAdapter";import{hostedPaymentPageAdapter as y}from"./HostedPaymentPageAdapter";export{p as chargebeePaymentAdapter,y as hostedPaymentPageAdapter,o as moyasarPaymentAdapter,t as stripePaymentAdapter};
1
+ import{stripePaymentAdapter as t}from"./StripePaymentAdapter";import{moyasarPaymentAdapter as m}from"./MoyasarPaymentAdapter";import{chargebeePaymentAdapter as p}from"./ChargebeePaymentAdapter";import{atbPaymentAdapter as d}from"./AtbPaymentAdapter";export{d as atbPaymentAdapter,p as chargebeePaymentAdapter,m as moyasarPaymentAdapter,t as stripePaymentAdapter};
@@ -1 +1 @@
1
- import{chargebeePaymentAdapter as r,hostedPaymentPageAdapter as t,moyasarPaymentAdapter as a,stripePaymentAdapter as p}from"./adapters";function o(e){switch(e){case"stripe":return p;case"moyasar":return a;case"chargebee":return r;case"hosted_payment_page":return t;default:throw new Error(`Unknown payment provider: "${e}". Supported providers: stripe, moyasar, chargebee, hosted_payment_page`)}}export{o as createPaymentAdapter};
1
+ import{atbPaymentAdapter as r,chargebeePaymentAdapter as t,moyasarPaymentAdapter as a,stripePaymentAdapter as n}from"./adapters";function o(e){switch(e){case"stripe":return n;case"moyasar":return a;case"chargebee":return t;case"atb":return r;default:throw new Error(`Unknown payment provider: "${e}". Supported providers: stripe, moyasar, chargebee, atb`)}}export{o as createPaymentAdapter};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1interface/chat-shell",
3
- "version": "0.9.9",
3
+ "version": "0.10.0-dev.0",
4
4
  "license": "UNLICENSED",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -51,11 +51,11 @@
51
51
  "lucide-react": "^0.562.0",
52
52
  "streamdown": "^1.6.11",
53
53
  "tailwind-merge": "^3.6.0",
54
- "@1interface/chat-core": "^0.18.0",
55
- "@1interface/shared-core": "^0.13.0",
56
- "@1interface/voice-core": "^0.6.0",
57
- "@1interface/widgets": "^0.9.3",
58
- "@1interface/voice-shell": "^0.5.7"
54
+ "@1interface/shared-core": "^0.14.0-dev.1",
55
+ "@1interface/voice-core": "^0.6.1-dev.1",
56
+ "@1interface/chat-core": "^0.19.0-dev.1",
57
+ "@1interface/widgets": "^0.10.1",
58
+ "@1interface/voice-shell": "^0.5.8-dev.1"
59
59
  },
60
60
  "peerDependencies": {
61
61
  "@reduxjs/toolkit": "^2.0.0",
@@ -1 +0,0 @@
1
- import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import r,{forwardRef as o,createElement as a,useState as i,useRef as s,useCallback as c,useMemo as l,createContext as u,useContext as d,useEffect as p,useLayoutEffect as f}from"react";import{buildBrandSkin as m,parseMoyasarCallbackFromUrl as y,buildCallbackUrl as h,buildHostedPaymentPageThemeMessage as g,isHostedPaymentPageCallbackMessage as v,HOSTED_PAYMENT_PAGE_CALLBACK_ACTIONS as b,parseHostedPaymentPageCallback as w,HOSTED_PAYMENT_PAGE_STATUSES as x,DEFAULT_PAYMENT_PROVIDER as S,formatAmount as E}from"@1interface/chat-core";import{useBranding as C,showErrorToast as k,logger as P,getPaymentProviderHint as _}from"@1interface/shared-core";const O=e=>{const t=(e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,t,n)=>n?n.toUpperCase():t.toLowerCase()))(e);return t.charAt(0).toUpperCase()+t.slice(1)},j=(...e)=>e.filter((e,t,n)=>Boolean(e)&&""!==e.trim()&&n.indexOf(e)===t).join(" ").trim(),A=e=>{for(const t in e)if(t.startsWith("aria-")||"role"===t||"title"===t)return!0};var N={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};const I=o(({color:e="currentColor",size:t=24,strokeWidth:n=2,absoluteStrokeWidth:r,className:o="",children:i,iconNode:s,...c},l)=>a("svg",{ref:l,...N,width:t,height:t,stroke:e,strokeWidth:r?24*Number(n)/Number(t):n,className:j("lucide",o),...!i&&!A(c)&&{"aria-hidden":"true"},...c},[...s.map(([e,t])=>a(e,t)),...Array.isArray(i)?i:[i]])),T=((e,t)=>{const n=o(({className:n,...r},o)=>{return a(I,{ref:o,iconNode:t,className:j(`lucide-${i=O(e),i.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}`,`lucide-${e}`,n),...r});var i});return n.displayName=O(e),n})("loader-circle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]);function M(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var F,R,$,D,V,L,B,z,U,q,W,Y,H,J,K,X,Z={exports:{}},G={exports:{}},Q={},ee={};function te(){return $||($=1,G.exports="production"===process.env.NODE_ENV?function(){if(F)return Q;F=1;var e="function"==typeof Symbol&&Symbol.for,t=e?Symbol.for("react.element"):60103,n=e?Symbol.for("react.portal"):60106,r=e?Symbol.for("react.fragment"):60107,o=e?Symbol.for("react.strict_mode"):60108,a=e?Symbol.for("react.profiler"):60114,i=e?Symbol.for("react.provider"):60109,s=e?Symbol.for("react.context"):60110,c=e?Symbol.for("react.async_mode"):60111,l=e?Symbol.for("react.concurrent_mode"):60111,u=e?Symbol.for("react.forward_ref"):60112,d=e?Symbol.for("react.suspense"):60113,p=e?Symbol.for("react.suspense_list"):60120,f=e?Symbol.for("react.memo"):60115,m=e?Symbol.for("react.lazy"):60116,y=e?Symbol.for("react.block"):60121,h=e?Symbol.for("react.fundamental"):60117,g=e?Symbol.for("react.responder"):60118,v=e?Symbol.for("react.scope"):60119;function b(e){if("object"==typeof e&&null!==e){var p=e.$$typeof;switch(p){case t:switch(e=e.type){case c:case l:case r:case a:case o:case d:return e;default:switch(e=e&&e.$$typeof){case s:case u:case m:case f:case i:return e;default:return p}}case n:return p}}}function w(e){return b(e)===l}return Q.AsyncMode=c,Q.ConcurrentMode=l,Q.ContextConsumer=s,Q.ContextProvider=i,Q.Element=t,Q.ForwardRef=u,Q.Fragment=r,Q.Lazy=m,Q.Memo=f,Q.Portal=n,Q.Profiler=a,Q.StrictMode=o,Q.Suspense=d,Q.isAsyncMode=function(e){return w(e)||b(e)===c},Q.isConcurrentMode=w,Q.isContextConsumer=function(e){return b(e)===s},Q.isContextProvider=function(e){return b(e)===i},Q.isElement=function(e){return"object"==typeof e&&null!==e&&e.$$typeof===t},Q.isForwardRef=function(e){return b(e)===u},Q.isFragment=function(e){return b(e)===r},Q.isLazy=function(e){return b(e)===m},Q.isMemo=function(e){return b(e)===f},Q.isPortal=function(e){return b(e)===n},Q.isProfiler=function(e){return b(e)===a},Q.isStrictMode=function(e){return b(e)===o},Q.isSuspense=function(e){return b(e)===d},Q.isValidElementType=function(e){return"string"==typeof e||"function"==typeof e||e===r||e===l||e===a||e===o||e===d||e===p||"object"==typeof e&&null!==e&&(e.$$typeof===m||e.$$typeof===f||e.$$typeof===i||e.$$typeof===s||e.$$typeof===u||e.$$typeof===h||e.$$typeof===g||e.$$typeof===v||e.$$typeof===y)},Q.typeOf=b,Q}():(R||(R=1,"production"!==process.env.NODE_ENV&&function(){var e="function"==typeof Symbol&&Symbol.for,t=e?Symbol.for("react.element"):60103,n=e?Symbol.for("react.portal"):60106,r=e?Symbol.for("react.fragment"):60107,o=e?Symbol.for("react.strict_mode"):60108,a=e?Symbol.for("react.profiler"):60114,i=e?Symbol.for("react.provider"):60109,s=e?Symbol.for("react.context"):60110,c=e?Symbol.for("react.async_mode"):60111,l=e?Symbol.for("react.concurrent_mode"):60111,u=e?Symbol.for("react.forward_ref"):60112,d=e?Symbol.for("react.suspense"):60113,p=e?Symbol.for("react.suspense_list"):60120,f=e?Symbol.for("react.memo"):60115,m=e?Symbol.for("react.lazy"):60116,y=e?Symbol.for("react.block"):60121,h=e?Symbol.for("react.fundamental"):60117,g=e?Symbol.for("react.responder"):60118,v=e?Symbol.for("react.scope"):60119;function b(e){if("object"==typeof e&&null!==e){var p=e.$$typeof;switch(p){case t:var y=e.type;switch(y){case c:case l:case r:case a:case o:case d:return y;default:var h=y&&y.$$typeof;switch(h){case s:case u:case m:case f:case i:return h;default:return p}}case n:return p}}}var w=l,x=s,S=i,E=t,C=u,k=r,P=m,_=f,O=n,j=a,A=o,N=d,I=!1;function T(e){return b(e)===l}ee.AsyncMode=c,ee.ConcurrentMode=w,ee.ContextConsumer=x,ee.ContextProvider=S,ee.Element=E,ee.ForwardRef=C,ee.Fragment=k,ee.Lazy=P,ee.Memo=_,ee.Portal=O,ee.Profiler=j,ee.StrictMode=A,ee.Suspense=N,ee.isAsyncMode=function(e){return I||(I=!0,console.warn("The ReactIs.isAsyncMode() alias has been deprecated, and will be removed in React 17+. Update your code to use ReactIs.isConcurrentMode() instead. It has the exact same API.")),T(e)||b(e)===c},ee.isConcurrentMode=T,ee.isContextConsumer=function(e){return b(e)===s},ee.isContextProvider=function(e){return b(e)===i},ee.isElement=function(e){return"object"==typeof e&&null!==e&&e.$$typeof===t},ee.isForwardRef=function(e){return b(e)===u},ee.isFragment=function(e){return b(e)===r},ee.isLazy=function(e){return b(e)===m},ee.isMemo=function(e){return b(e)===f},ee.isPortal=function(e){return b(e)===n},ee.isProfiler=function(e){return b(e)===a},ee.isStrictMode=function(e){return b(e)===o},ee.isSuspense=function(e){return b(e)===d},ee.isValidElementType=function(e){return"string"==typeof e||"function"==typeof e||e===r||e===l||e===a||e===o||e===d||e===p||"object"==typeof e&&null!==e&&(e.$$typeof===m||e.$$typeof===f||e.$$typeof===i||e.$$typeof===s||e.$$typeof===u||e.$$typeof===h||e.$$typeof===g||e.$$typeof===v||e.$$typeof===y)},ee.typeOf=b}()),ee)),G.exports}function ne(){return B?L:(B=1,L="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}function re(){return U?z:(U=1,z=Function.call.bind(Object.prototype.hasOwnProperty))}function oe(){if(W)return q;W=1;var e=function(){};if("production"!==process.env.NODE_ENV){var t=ne(),n={},r=re();e=function(e){var t="Warning: "+e;"undefined"!=typeof console&&console.error(t);try{throw new Error(t)}catch(e){}}}function o(o,a,i,s,c){if("production"!==process.env.NODE_ENV)for(var l in o)if(r(o,l)){var u;try{if("function"!=typeof o[l]){var d=Error((s||"React class")+": "+i+" type `"+l+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof o[l]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw d.name="Invariant Violation",d}u=o[l](a,l,s,i,null,t)}catch(e){u=e}if(!u||u instanceof Error||e((s||"React class")+": type specification of "+i+" `"+l+"` is invalid; the type checker function must return `null` or an `Error` but returned a "+typeof u+". You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument)."),u instanceof Error&&!(u.message in n)){n[u.message]=!0;var p=c?c():"";e("Failed "+i+" type: "+u.message+(null!=p?p:""))}}}return o.resetWarningCache=function(){"production"!==process.env.NODE_ENV&&(n={})},q=o}function ae(){if(H)return Y;H=1;var e=te(),t=function(){if(V)return D;V=1;var e=Object.getOwnPropertySymbols,t=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable;return D=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},n=0;n<10;n++)t["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(t).map(function(e){return t[e]}).join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach(function(e){r[e]=e}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(e){return!1}}()?Object.assign:function(r,o){for(var a,i,s=function(e){if(null==e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}(r),c=1;c<arguments.length;c++){for(var l in a=Object(arguments[c]))t.call(a,l)&&(s[l]=a[l]);if(e){i=e(a);for(var u=0;u<i.length;u++)n.call(a,i[u])&&(s[i[u]]=a[i[u]])}}return s},D}(),n=ne(),r=re(),o=oe(),a=function(){};function i(){return null}return"production"!==process.env.NODE_ENV&&(a=function(e){var t="Warning: "+e;"undefined"!=typeof console&&console.error(t);try{throw new Error(t)}catch(e){}}),Y=function(s,c){var l="function"==typeof Symbol&&Symbol.iterator,u="<<anonymous>>",d={array:y("array"),bigint:y("bigint"),bool:y("boolean"),func:y("function"),number:y("number"),object:y("object"),string:y("string"),symbol:y("symbol"),any:m(i),arrayOf:function(e){return m(function(t,r,o,a,i){if("function"!=typeof e)return new f("Property `"+i+"` of component `"+o+"` has invalid PropType notation inside arrayOf.");var s=t[r];if(!Array.isArray(s))return new f("Invalid "+a+" `"+i+"` of type `"+v(s)+"` supplied to `"+o+"`, expected an array.");for(var c=0;c<s.length;c++){var l=e(s,c,o,a,i+"["+c+"]",n);if(l instanceof Error)return l}return null})},element:m(function(e,t,n,r,o){var a=e[t];return s(a)?null:new f("Invalid "+r+" `"+o+"` of type `"+v(a)+"` supplied to `"+n+"`, expected a single ReactElement.")}),elementType:m(function(t,n,r,o,a){var i=t[n];return e.isValidElementType(i)?null:new f("Invalid "+o+" `"+a+"` of type `"+v(i)+"` supplied to `"+r+"`, expected a single ReactElement type.")}),instanceOf:function(e){return m(function(t,n,r,o,a){return t[n]instanceof e?null:new f("Invalid "+o+" `"+a+"` of type `"+((i=t[n]).constructor&&i.constructor.name?i.constructor.name:u)+"` supplied to `"+r+"`, expected instance of `"+(e.name||u)+"`.");var i})},node:m(function(e,t,n,r,o){return g(e[t])?null:new f("Invalid "+r+" `"+o+"` supplied to `"+n+"`, expected a ReactNode.")}),objectOf:function(e){return m(function(t,o,a,i,s){if("function"!=typeof e)return new f("Property `"+s+"` of component `"+a+"` has invalid PropType notation inside objectOf.");var c=t[o],l=v(c);if("object"!==l)return new f("Invalid "+i+" `"+s+"` of type `"+l+"` supplied to `"+a+"`, expected an object.");for(var u in c)if(r(c,u)){var d=e(c,u,a,i,s+"."+u,n);if(d instanceof Error)return d}return null})},oneOf:function(e){return Array.isArray(e)?m(function(t,n,r,o,a){for(var i=t[n],s=0;s<e.length;s++)if(p(i,e[s]))return null;var c=JSON.stringify(e,function(e,t){return"symbol"===b(t)?String(t):t});return new f("Invalid "+o+" `"+a+"` of value `"+String(i)+"` supplied to `"+r+"`, expected one of "+c+".")}):("production"!==process.env.NODE_ENV&&a(arguments.length>1?"Invalid arguments supplied to oneOf, expected an array, got "+arguments.length+" arguments. A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z]).":"Invalid argument supplied to oneOf, expected an array."),i)},oneOfType:function(e){if(!Array.isArray(e))return"production"!==process.env.NODE_ENV&&a("Invalid argument supplied to oneOfType, expected an instance of array."),i;for(var t=0;t<e.length;t++){var o=e[t];if("function"!=typeof o)return a("Invalid argument supplied to oneOfType. Expected an array of check functions, but received "+w(o)+" at index "+t+"."),i}return m(function(t,o,a,i,s){for(var c=[],l=0;l<e.length;l++){var u=(0,e[l])(t,o,a,i,s,n);if(null==u)return null;u.data&&r(u.data,"expectedType")&&c.push(u.data.expectedType)}return new f("Invalid "+i+" `"+s+"` supplied to `"+a+"`"+(c.length>0?", expected one of type ["+c.join(", ")+"]":"")+".")})},shape:function(e){return m(function(t,r,o,a,i){var s=t[r],c=v(s);if("object"!==c)return new f("Invalid "+a+" `"+i+"` of type `"+c+"` supplied to `"+o+"`, expected `object`.");for(var l in e){var u=e[l];if("function"!=typeof u)return h(o,a,i,l,b(u));var d=u(s,l,o,a,i+"."+l,n);if(d)return d}return null})},exact:function(e){return m(function(o,a,i,s,c){var l=o[a],u=v(l);if("object"!==u)return new f("Invalid "+s+" `"+c+"` of type `"+u+"` supplied to `"+i+"`, expected `object`.");var d=t({},o[a],e);for(var p in d){var m=e[p];if(r(e,p)&&"function"!=typeof m)return h(i,s,c,p,b(m));if(!m)return new f("Invalid "+s+" `"+c+"` key `"+p+"` supplied to `"+i+"`.\nBad object: "+JSON.stringify(o[a],null," ")+"\nValid keys: "+JSON.stringify(Object.keys(e),null," "));var y=m(l,p,i,s,c+"."+p,n);if(y)return y}return null})}};function p(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t}function f(e,t){this.message=e,this.data=t&&"object"==typeof t?t:{},this.stack=""}function m(e){if("production"!==process.env.NODE_ENV)var t={},r=0;function o(o,i,s,l,d,p,m){if(l=l||u,p=p||s,m!==n){if(c){var y=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use `PropTypes.checkPropTypes()` to call them. Read more at http://fb.me/use-check-prop-types");throw y.name="Invariant Violation",y}if("production"!==process.env.NODE_ENV&&"undefined"!=typeof console){var h=l+":"+s;!t[h]&&r<3&&(a("You are manually calling a React.PropTypes validation function for the `"+p+"` prop on `"+l+"`. This is deprecated and will throw in the standalone `prop-types` package. You may be seeing this warning due to a third-party PropTypes library. See https://fb.me/react-warning-dont-call-proptypes for details."),t[h]=!0,r++)}}return null==i[s]?o?new f(null===i[s]?"The "+d+" `"+p+"` is marked as required in `"+l+"`, but its value is `null`.":"The "+d+" `"+p+"` is marked as required in `"+l+"`, but its value is `undefined`."):null:e(i,s,l,d,p)}var i=o.bind(null,!1);return i.isRequired=o.bind(null,!0),i}function y(e){return m(function(t,n,r,o,a,i){var s=t[n];return v(s)!==e?new f("Invalid "+o+" `"+a+"` of type `"+b(s)+"` supplied to `"+r+"`, expected `"+e+"`.",{expectedType:e}):null})}function h(e,t,n,r,o){return new f((e||"React class")+": "+t+" type `"+n+"."+r+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+o+"`.")}function g(e){switch(typeof e){case"number":case"string":case"undefined":return!0;case"boolean":return!e;case"object":if(Array.isArray(e))return e.every(g);if(null===e||s(e))return!0;var t=function(e){var t=e&&(l&&e[l]||e["@@iterator"]);if("function"==typeof t)return t}(e);if(!t)return!1;var n,r=t.call(e);if(t!==e.entries){for(;!(n=r.next()).done;)if(!g(n.value))return!1}else for(;!(n=r.next()).done;){var o=n.value;if(o&&!g(o[1]))return!1}return!0;default:return!1}}function v(e){var t=typeof e;return Array.isArray(e)?"array":e instanceof RegExp?"object":function(e,t){return"symbol"===e||!!t&&("Symbol"===t["@@toStringTag"]||"function"==typeof Symbol&&t instanceof Symbol)}(t,e)?"symbol":t}function b(e){if(null==e)return""+e;var t=v(e);if("object"===t){if(e instanceof Date)return"date";if(e instanceof RegExp)return"regexp"}return t}function w(e){var t=b(e);switch(t){case"array":case"object":return"an "+t;case"boolean":case"date":case"regexp":return"a "+t;default:return t}}return f.prototype=Error.prototype,d.checkPropTypes=o,d.resetWarningCache=o.resetWarningCache,d.PropTypes=d,d},Y}function ie(){if(K)return J;K=1;var e=ne();function t(){}function n(){}return n.resetWarningCache=t,J=function(){function r(t,n,r,o,a,i){if(i!==e){var s=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw s.name="Invariant Violation",s}}function o(){return r}r.isRequired=r;var a={array:r,bigint:r,bool:r,func:r,number:r,object:r,string:r,symbol:r,any:r,arrayOf:o,element:r,elementType:r,instanceOf:o,node:r,objectOf:o,oneOf:o,oneOfType:o,shape:o,exact:o,checkPropTypes:n,resetWarningCache:t};return a.PropTypes=a,a}}function se(){if(X)return Z.exports;if(X=1,"production"!==process.env.NODE_ENV){var e=te();Z.exports=ae()(e.isElement,!0)}else Z.exports=ie()();return Z.exports}const ce=M(se());function le(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function ue(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?le(Object(n),!0).forEach(function(t){pe(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):le(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function de(e){return(de="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function pe(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function fe(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=e&&("undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"]);if(null!=n){var r,o,a=[],i=!0,s=!1;try{for(n=n.call(e);!(i=(r=n.next()).done)&&(a.push(r.value),!t||a.length!==t);i=!0);}catch(e){s=!0,o=e}finally{try{i||null==n.return||n.return()}finally{if(s)throw o}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return me(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?me(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function me(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var ye=function(e,t,n){var o=!!n,a=r.useRef(n);r.useEffect(function(){a.current=n},[n]),r.useEffect(function(){if(!o||!e)return function(){};var n=function(){a.current&&a.current.apply(a,arguments)};return e.on(t,n),function(){e.off(t,n)}},[o,t,e,a])},he=function(e){var t=r.useRef(e);return r.useEffect(function(){t.current=e},[e]),t.current},ge=function(e){return null!==e&&"object"===de(e)},ve="[object Object]",be=function e(t,n){if(!ge(t)||!ge(n))return t===n;var r=Array.isArray(t);if(r!==Array.isArray(n))return!1;var o=Object.prototype.toString.call(t)===ve;if(o!==(Object.prototype.toString.call(n)===ve))return!1;if(!o&&!r)return t===n;var a=Object.keys(t),i=Object.keys(n);if(a.length!==i.length)return!1;for(var s={},c=0;c<a.length;c+=1)s[a[c]]=!0;for(var l=0;l<i.length;l+=1)s[i[l]]=!0;var u=Object.keys(s);if(u.length!==a.length)return!1;var d=t,p=n;return u.every(function(t){return e(d[t],p[t])})},we=function(e,t,n){return ge(e)?Object.keys(e).reduce(function(r,o){var a=!ge(t)||!be(e[o],t[o]);return n.includes(o)?(a&&console.warn("Unsupported prop change: options.".concat(o," is not a mutable property.")),r):a?ue(ue({},r||{}),{},pe({},o,e[o])):r},null):null},xe="Invalid prop `stripe` supplied to `Elements`. We recommend using the `loadStripe` utility from `@stripe/stripe-js`. See https://stripe.com/docs/stripe-js/react#elements-props-stripe for details.",Se=function(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:xe;if(null===e||ge(t=e)&&"function"==typeof t.elements&&"function"==typeof t.createToken&&"function"==typeof t.createPaymentMethod&&"function"==typeof t.confirmCardPayment)return e;throw new Error(n)},Ee=r.createContext(null);Ee.displayName="ElementsContext";var Ce=function(e,t){if(!e)throw new Error("Could not find Elements context; You need to wrap the part of your app that ".concat(t," in an <Elements> provider."));return e},ke=function(e){var t=e.stripe,n=e.options,o=e.children,a=r.useMemo(function(){return function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:xe;if(function(e){return ge(e)&&"function"==typeof e.then}(e))return{tag:"async",stripePromise:Promise.resolve(e).then(function(e){return Se(e,t)})};var n=Se(e,t);return null===n?{tag:"empty"}:{tag:"sync",stripe:n}}(t)},[t]),i=fe(r.useState(function(){return{stripe:"sync"===a.tag?a.stripe:null,elements:"sync"===a.tag?a.stripe.elements(n):null}}),2),s=i[0],c=i[1];r.useEffect(function(){var e=!0,t=function(e){c(function(t){return t.stripe?t:{stripe:e,elements:e.elements(n)}})};return"async"!==a.tag||s.stripe?"sync"!==a.tag||s.stripe||t(a.stripe):a.stripePromise.then(function(n){n&&e&&t(n)}),function(){e=!1}},[a,s,n]);var l=he(t);r.useEffect(function(){null!==l&&l!==t&&console.warn("Unsupported prop change on Elements: You cannot change the `stripe` prop after setting it.")},[l,t]);var u=he(n);return r.useEffect(function(){if(s.elements){var e=we(n,u,["clientSecret","fonts"]);e&&s.elements.update(e)}},[n,u,s.elements]),r.useEffect(function(){var e;(e=s.stripe)&&e._registerWrapper&&e.registerAppInfo&&(e._registerWrapper({name:"react-stripe-js",version:"3.10.0"}),e.registerAppInfo({name:"react-stripe-js",version:"3.10.0",url:"https://stripe.com/docs/stripe-js/react"}))},[s.stripe]),r.createElement(Ee.Provider,{value:s},o)};ke.propTypes={stripe:ce.any,options:ce.object};var Pe=r.createContext(null);Pe.displayName="CheckoutSdkContext",r.createContext(null).displayName="CheckoutContext",ce.shape({fetchClientSecret:ce.func.isRequired,elementsOptions:ce.object});var _e=function(e){var t=r.useContext(Pe),n=r.useContext(Ee);if(t&&n)throw new Error("You cannot wrap the part of your app that ".concat(e," in both <CheckoutProvider> and <Elements> providers."));return t?function(e,t){if(!e)throw new Error("Could not find CheckoutProvider context; You need to wrap the part of your app that ".concat(t," in an <CheckoutProvider> provider."));return e}(t,e):Ce(n,e)},Oe=["mode"],je=function(e,t){var n,o="".concat((n=e).charAt(0).toUpperCase()+n.slice(1),"Element"),a=t?function(e){return _e("mounts <".concat(o,">")),r.createElement("div",{id:e.id,className:e.className})}:function(t){var n,a=t.id,i=t.className,s=t.options,c=void 0===s?{}:s,l=t.onBlur,u=t.onFocus,d=t.onReady,p=t.onChange,f=t.onEscape,m=t.onClick,y=t.onLoadError,h=t.onLoaderStart,g=t.onNetworksChange,v=t.onConfirm,b=t.onCancel,w=t.onShippingAddressChange,x=t.onShippingRateChange,S=t.onSavedPaymentMethodRemove,E=t.onSavedPaymentMethodUpdate,C=_e("mounts <".concat(o,">")),k="elements"in C?C.elements:null,P="checkoutSdk"in C?C.checkoutSdk:null,_=fe(r.useState(null),2),O=_[0],j=_[1],A=r.useRef(null),N=r.useRef(null);ye(O,"blur",l),ye(O,"focus",u),ye(O,"escape",f),ye(O,"click",m),ye(O,"loaderror",y),ye(O,"loaderstart",h),ye(O,"networkschange",g),ye(O,"confirm",v),ye(O,"cancel",b),ye(O,"shippingaddresschange",w),ye(O,"shippingratechange",x),ye(O,"savedpaymentmethodremove",S),ye(O,"savedpaymentmethodupdate",E),ye(O,"change",p),d&&(n="expressCheckout"===e?d:function(){d(O)}),ye(O,"ready",n),r.useLayoutEffect(function(){if(null===A.current&&null!==N.current&&(k||P)){var t=null;if(P)switch(e){case"payment":t=P.createPaymentElement(c);break;case"address":if(!("mode"in c))throw new Error("You must supply options.mode. mode must be 'billing' or 'shipping'.");var n=c.mode,r=function(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},a=Object.keys(e);for(r=0;r<a.length;r++)t.indexOf(n=a[r])>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)t.indexOf(n=a[r])>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}(c,Oe);if("shipping"===n)t=P.createShippingAddressElement(r);else{if("billing"!==n)throw new Error("Invalid options.mode. mode must be 'billing' or 'shipping'.");t=P.createBillingAddressElement(r)}break;case"expressCheckout":t=P.createExpressCheckoutElement(c);break;case"currencySelector":t=P.createCurrencySelectorElement();break;case"taxId":t=P.createTaxIdElement(c);break;default:throw new Error("Invalid Element type ".concat(o,". You must use either the <PaymentElement />, <AddressElement options={{mode: 'shipping'}} />, <AddressElement options={{mode: 'billing'}} />, or <ExpressCheckoutElement />."))}else k&&(t=k.create(e,c));A.current=t,j(t),t&&t.mount(N.current)}},[k,P,c]);var I=he(c);return r.useEffect(function(){if(A.current){var e=we(c,I,["paymentRequest"]);e&&"update"in A.current&&A.current.update(e)}},[c,I]),r.useLayoutEffect(function(){return function(){if(A.current&&"function"==typeof A.current.destroy)try{A.current.destroy(),A.current=null}catch(e){}}},[]),r.createElement("div",{id:a,className:i,ref:N})};return a.propTypes={id:ce.string,className:ce.string,onChange:ce.func,onBlur:ce.func,onFocus:ce.func,onReady:ce.func,onEscape:ce.func,onClick:ce.func,onLoadError:ce.func,onLoaderStart:ce.func,onNetworksChange:ce.func,onConfirm:ce.func,onCancel:ce.func,onShippingAddressChange:ce.func,onShippingRateChange:ce.func,onSavedPaymentMethodRemove:ce.func,onSavedPaymentMethodUpdate:ce.func,options:ce.object},a.displayName=o,a.__elementType=e,a},Ae="undefined"==typeof window;r.createContext(null).displayName="EmbeddedCheckoutProviderContext",je("auBankAccount",Ae),je("card",Ae),je("cardNumber",Ae),je("cardExpiry",Ae),je("cardCvc",Ae),je("fpxBank",Ae),je("iban",Ae),je("idealBank",Ae),je("p24Bank",Ae),je("epsBank",Ae);var Ne=je("payment",Ae);je("expressCheckout",Ae),je("currencySelector",Ae),je("paymentRequestButton",Ae),je("linkAuthentication",Ae),je("address",Ae),je("shippingAddress",Ae),je("paymentMethodMessaging",Ae),je("affirmMessage",Ae),je("afterpayClearpayMessage",Ae),je("taxId",Ae);const Ie=u(null),Te=({onResult:t,children:n})=>{const[r,o]=i(null),[a,u]=i(null),d=s(t);d.current=t;const p=c(e=>{d.current(e)},[]),f=c(e=>{o(e)},[]),m=c(e=>{u(e)},[]),y=l(()=>({emitResult:p,registerConfirm:f,confirmHandle:r,reportSummary:m,summary:a}),[p,f,r,m,a]);return e(Ie.Provider,{value:y,children:n})},Me=()=>{const e=d(Ie);if(!e)throw new Error("Payment result channel hooks must be used inside PaymentResultChannelProvider");return e},Fe=()=>Me().emitResult,Re=()=>Me().registerConfirm,$e=()=>Me().reportSummary;function De(e){return(De="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var Ve,Le="https://js.stripe.com/v3",Be=/^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/,ze="loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used",Ue=function(e){var t=e&&!e.advancedFraudSignals?"?advancedFraudSignals=false":"",n=document.createElement("script");n.src="".concat(Le).concat(t);var r=document.head||document.body;if(!r)throw new Error("Expected document.body not to be null. Stripe.js requires a <body> element.");return r.appendChild(n),n},qe=null,We=null,Ye=null,He=function(e){var t="invalid load parameters; expected object of shape\n\n {advancedFraudSignals: boolean}\n\nbut received\n\n ".concat(JSON.stringify(e),"\n");if(null===e||"object"!==De(e))throw new Error(t);if(1===Object.keys(e).length&&"boolean"==typeof e.advancedFraudSignals)return e;throw new Error(t)},Je=!1,Ke=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];Je=!0;var r,o=Date.now();return(r=Ve,null!==qe?qe:(qe=new Promise(function(e,t){if("undefined"!=typeof window&&"undefined"!=typeof document)if(window.Stripe&&r&&console.warn(ze),window.Stripe)e(window.Stripe);else try{var n=function(){for(var e=document.querySelectorAll('script[src^="'.concat(Le,'"]')),t=0;t<e.length;t++){var n=e[t];if(Be.test(n.src))return n}return null}();if(n&&r)console.warn(ze);else if(n){if(n&&null!==Ye&&null!==We){var o;n.removeEventListener("load",Ye),n.removeEventListener("error",We),null===(o=n.parentNode)||void 0===o||o.removeChild(n),n=Ue(r)}}else n=Ue(r);Ye=function(e,t){return function(){window.Stripe?e(window.Stripe):t(new Error("Stripe.js not available"))}}(e,t),We=function(e){return function(){e(new Error("Failed to load Stripe.js"))}}(t),n.addEventListener("load",Ye),n.addEventListener("error",We)}catch(e){return void t(e)}else e(null)})).catch(function(e){return qe=null,Promise.reject(e)})).then(function(e){return function(e,t,n){if(null===e)return null;var r=e.apply(void 0,t);return function(e,t){e&&e._registerWrapper&&e._registerWrapper({name:"stripe-js",version:"4.6.0",startTime:t})}(r,n),r}(e,t,o)})};Ke.setLoadParameters=function(e){if(Je&&Ve){var t=He(e);if(Object.keys(t).reduce(function(t,n){var r;return t&&e[n]===(null===(r=Ve)||void 0===r?void 0:r[n])},!0))return}if(Je)throw new Error("You cannot change load parameters after calling loadStripe");Ve=He(e)};const Xe=u(null),Ze=({onReady:t})=>{const n=_e("calls useStripe()").stripe,o=(y=r.useContext(Ee),Ce(y,"calls useElements()")).elements,{paymentInit:a}=jn(),s=Fe(),l=Re(),u=$e(),[d,f]=i(!1),m="stripe"===a?.provider?a.config.client_secret:null;var y;p(()=>{if(!n||!m)return;let e=!1;return n.retrievePaymentIntent(m).then(t=>{if(e)return;const n=t.paymentIntent;n&&"number"==typeof n.amount&&n.currency&&u({amount:n.amount,currency:n.currency})}),()=>{e=!0}},[n,m,u]);const h=c(async()=>{if(!n||!o||!m)return;f(!0);const{error:e}=await o.submit();if(e)return void f(!1);const{error:t,paymentIntent:r}=await n.confirmPayment({elements:o,clientSecret:m,confirmParams:{return_url:window.location.href},redirect:"if_required"});f(!1),t||!r||"succeeded"!==r.status&&"requires_capture"!==r.status||s({status:"success",provider:"stripe",paymentId:r.id,amount:r.amount,currency:r.currency})},[n,o,m,s]);return p(()=>(l({confirm:h,isConfirming:d}),()=>l(null)),[h,d,l]),e(Ne,{options:{layout:"tabs",wallets:{applePay:"auto",googlePay:"auto"}},onReady:t})},Ge={type:"stripe",label:"Stripe",ProviderWrapper:({children:t})=>{const{paymentInit:n}=jn(),[r,o]=i(null),a="stripe"===n?.provider?n.config.publishable_key:null;p(()=>{a&&a.startsWith("pk_")&&o(Ke(a))},[a]);const s=l(()=>({stripePromise:r}),[r]);return e(Xe.Provider,{value:s,children:t})},FormComponent:({onReady:t})=>{const{themeStyles:n,theme:r}=C(),{stripePromise:o}=(()=>{const e=d(Xe);if(!e)throw new Error("Stripe adapter components must be used inside StripeProviderWrapper");return e})(),{paymentInit:a}=jn(),i=l(()=>m(n,r),[n,r]),s=l(()=>function(e,t,n){return{theme:"dark"===t?"night":"stripe",variables:{colorPrimary:e.statusDiscovery.solid,colorBackground:n.cardBg,colorText:n.text,colorDanger:"#df1b41",fontFamily:n.fontFamily,borderRadius:`${n.radius}px`,spacingUnit:"3px",fontSizeBase:"16px"}}}(n,r,i),[n,r,i]),c="stripe"===a?.provider?a.config.client_secret:null,u=l(()=>c?{clientSecret:c,appearance:s}:null,[c,s]);return o&&u?e(ke,{stripe:o,options:u,children:e(Ze,{onReady:t})},c):null}};function Qe(e){const t={};if(e.config.metadata)for(const[n,r]of Object.entries(e.config.metadata))null!=r&&(t[n]=String(r));if(e.config.customer){const{name:n,email:r,phone:o,reference_id:a}=e.config.customer;n&&(t.customer_name=n),r&&(t.customer_email=r),o&&(t.customer_phone=o),a&&(t.customer_reference_id=a)}return t}class et extends Error{constructor(e,t,n){super(e),this.status=t,this.body=n,this.name="MoyasarApiError"}}async function tt(e){const t=await nt("https://api.moyasar.com/v1/payments",e);if(!t.ok)throw new et(rt(t.body)??`Payment creation failed (${t.status})`,t.status,t.body);const n=t.body;if(!n||"string"!=typeof n.id||"string"!=typeof n.status)throw new et("Payment creation returned no id/status",t.status,n);return n}async function nt(e,t){const n=new AbortController,r=setTimeout(()=>n.abort(new DOMException("Request timed out","TimeoutError")),3e4);let o;try{o=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),signal:n.signal})}catch(e){const t=e instanceof DOMException&&"TimeoutError"===e.name?"Payment request timed out — please try again.":e instanceof Error?e.message:"Network request failed";throw new et(t)}finally{clearTimeout(r)}let a=null;try{a=await o.json()}catch{a=null}return{ok:o.ok,status:o.status,body:a}}function rt(e){if(!e||"object"!=typeof e)return null;if("string"==typeof e.message&&e.message.length>0)return e.message;if(e.errors&&"object"==typeof e.errors){const t=e.errors;for(const[e,n]of Object.entries(t)){if(Array.isArray(n)&&"string"==typeof n[0])return`${ot(e)}: ${n[0]}`;if("string"==typeof n)return`${ot(e)}: ${n}`}}return null}function ot(e){return e.replace(/_/g," ")}const at=({url:n,onResult:r,skin:o})=>{const a=s(r);a.current=r;const l=s(!1),[u,d]=i(!1),f=s(!1),m=c(e=>{l.current||(l.current=!0,a.current({status:"failure",provider:"moyasar",message:e}))},[]);return p(()=>{const e=window.location.origin,t=t=>{if(t.origin!==e)return;if(l.current)return;if(!(n=t.data)||"object"!=typeof n||"moyasar-iframe-callback"!==n.type||"string"!=typeof n.search)return;var n;const r=y(t.data.search);r&&(l.current=!0,a.current(r.result))};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[]),p(()=>{const e=setTimeout(()=>{f.current||m("3D Secure challenge failed to load")},6e4);return()=>clearTimeout(e)},[m]),t("div",{className:"absolute inset-0 z-[105]",style:{background:o.cardBg},role:"dialog","aria-label":"3D Secure authentication",children:[!u&&e("div",{className:"absolute inset-0 flex items-center justify-center text-sm",style:{color:o.muted,fontFamily:o.fontFamily},children:"Loading…"}),e("iframe",{src:n,title:"3D Secure",className:"w-full h-full",style:{border:0,background:"white"},onLoad:()=>{f.current=!0,d(!0)},onError:()=>{m("3D Secure challenge failed to load")},allow:"payment *",sandbox:"allow-scripts allow-forms allow-same-origin allow-popups allow-top-navigation-by-user-activation",referrerPolicy:"no-referrer"})]})},it=["mada","visa","masterCard"],st="data-aiatcore-apple-pay",ct=({skin:r})=>{const{paymentInit:o}=jn(),a=o&&"moyasar"===o.provider?o:null,l=Fe(),[u,d]=i(null),f=s(l);f.current=l,p(()=>{!function(){if("undefined"==typeof document)return;if(document.querySelector(`style[${st}]`))return;const e=document.createElement("style");e.setAttribute(st,"true"),e.textContent="\n .aiatcore-apple-pay-button {\n -webkit-appearance: -apple-pay-button;\n -apple-pay-button-type: pay;\n -apple-pay-button-style: black;\n width: 100%;\n cursor: pointer;\n border: none;\n padding: 0;\n margin: 0;\n }\n ",document.head.appendChild(e)}()},[]);const m=c(()=>{if(!a)return;const e=window.ApplePaySession;if(!e)return void k("Apple Pay is not available on this device.");const t=a.config.apple_pay?.label??a.config.description??"Payment",n=a.config.apple_pay?.country??"SA",r=a.config.currency.toUpperCase(),o=(a.config.amount/100).toFixed(2),i={countryCode:n,currencyCode:r,supportedNetworks:it,merchantCapabilities:["supports3DS","supportsDebit","supportsCredit"],total:{label:t,amount:o}};let s;try{s=new e(5,i)}catch(e){return void k(e instanceof Error?e.message:"Failed to start Apple Pay")}s.onvalidatemerchant=async e=>{try{const n=await async function(e){const t={validation_url:e.validationUrl,display_name:e.displayName,domain_name:e.domainName??window.location.hostname,publishable_api_key:e.publishableApiKey},n=new AbortController,r=setTimeout(()=>n.abort(new DOMException("Request timed out","TimeoutError")),3e4);let o;try{o=await fetch("https://api.moyasar.com/v1/applepay/initiate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),signal:n.signal})}catch(e){const t=e instanceof DOMException&&"TimeoutError"===e.name?"Apple Pay merchant validation timed out — please try again.":e instanceof Error?e.message:"Network request failed";throw new et(t)}finally{clearTimeout(r)}let a=null;try{a=await o.json()}catch{a=null}if(!o.ok)throw new et(function(e){return e&&"object"==typeof e&&"string"==typeof e.message&&e.message.length>0?e.message:null}(a)??`Apple Pay merchant validation failed (${o.status})`,o.status,a);return a}({validationUrl:e.validationURL,displayName:t,publishableApiKey:a.config.publishable_key});s.completeMerchantValidation(n)}catch(e){const t=e instanceof Error?e.message:"Merchant validation failed";s.abort(),l({status:"failure",provider:"moyasar",message:t,paymentId:a.config.given_id})}},s.onpaymentauthorized=async t=>{try{const n=Qe(a),o=await tt({publishable_api_key:a.config.publishable_key,given_id:a.config.given_id,amount:a.config.amount,currency:r,description:a.config.description,callback_url:h(a.config.given_id),source:{type:"applepay",token:t.payment.token},...Object.keys(n).length>0?{metadata:n}:{}}),i=o.source?.transaction_url??o.transaction_url;if(i)return s.completePayment({status:e.STATUS_SUCCESS}),void d(i);const c=o.status;if("paid"===c||"authorized"===c||"captured"===c)s.completePayment({status:e.STATUS_SUCCESS}),l({status:"success",provider:"moyasar",paymentId:o.id,amount:o.amount,currency:o.currency});else if("failed"===c){const t=o.source?.message??"Payment failed";s.completePayment({status:e.STATUS_FAILURE}),l({status:"failure",provider:"moyasar",code:"failed",message:t,paymentId:o.id})}else{const t=`Unexpected payment status: ${c}`;s.completePayment({status:e.STATUS_FAILURE}),l({status:"failure",provider:"moyasar",code:c,message:t,paymentId:o.id})}}catch(t){const n=t instanceof et||t instanceof Error?t.message:"Payment failed";s.completePayment({status:e.STATUS_FAILURE}),l({status:"failure",provider:"moyasar",message:n,paymentId:a.config.given_id})}},s.oncancel=()=>{};try{s.begin()}catch(e){k(e instanceof Error?e.message:"Failed to start Apple Pay")}},[a,l]);return a?t(n,{children:[e("button",{type:"button",onClick:m,className:"aiatcore-apple-pay-button",style:{borderRadius:r.radius,height:44},"aria-label":"Pay with Apple Pay"}),u&&e(at,{url:u,skin:r,onResult:e=>{d(null),f.current(e)}})]}):null};var lt,ut,dt,pt={},ft={};function mt(){return dt||(dt=1,Object.defineProperty(ft,"__esModule",{value:!0}),ft.clone=function(e){return e?JSON.parse(JSON.stringify(e)):null}),ft}var yt,ht,gt,vt,bt,wt,xt={},St={},Et={};function Ct(){if(wt)return bt;wt=1;var e=bt&&bt.__assign||function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)},t=ut?lt:(ut=1,lt={visa:{niceType:"Visa",type:"visa",patterns:[4],gaps:[4,8,12],lengths:[16,18,19],code:{name:"CVV",size:3}},mastercard:{niceType:"Mastercard",type:"mastercard",patterns:[[51,55],[2221,2229],[223,229],[23,26],[270,271],2720],gaps:[4,8,12],lengths:[16],code:{name:"CVC",size:3}},"american-express":{niceType:"American Express",type:"american-express",patterns:[34,37],gaps:[4,10],lengths:[15],code:{name:"CID",size:4}},"diners-club":{niceType:"Diners Club",type:"diners-club",patterns:[[300,305],36,38,39],gaps:[4,10],lengths:[14,16,19],code:{name:"CVV",size:3}},discover:{niceType:"Discover",type:"discover",patterns:[6011,[644,649],65],gaps:[4,8,12],lengths:[16,19],code:{name:"CID",size:3}},jcb:{niceType:"JCB",type:"jcb",patterns:[2131,1800,[3528,3589]],gaps:[4,8,12],lengths:[16,17,18,19],code:{name:"CVV",size:3}},unionpay:{niceType:"UnionPay",type:"unionpay",patterns:[620,[62100,62182],[62184,62187],[62185,62197],[62200,62205],[622010,622999],622018,[62207,62209],[623,626],6270,6272,6276,[627700,627779],[627781,627799],[6282,6289],6291,6292,810,[8110,8131],[8132,8151],[8152,8163],[8164,8171]],gaps:[4,8,12],lengths:[14,15,16,17,18,19],code:{name:"CVN",size:3}},maestro:{niceType:"Maestro",type:"maestro",patterns:[493698,[5e5,504174],[504176,506698],[506779,508999],[56,59],63,67,6],gaps:[4,8,12],lengths:[12,13,14,15,16,17,18,19],code:{name:"CVC",size:3}},elo:{niceType:"Elo",type:"elo",patterns:[401178,401179,438935,457631,457632,431274,451416,457393,504175,[506699,506778],[509e3,509999],627780,636297,636368,[650031,650033],[650035,650051],[650405,650439],[650485,650538],[650541,650598],[650700,650718],[650720,650727],[650901,650978],[651652,651679],[655e3,655019],[655021,655058]],gaps:[4,8,12],lengths:[16],code:{name:"CVE",size:3}},mir:{niceType:"Mir",type:"mir",patterns:[[2200,2204]],gaps:[4,8,12],lengths:[16,17,18,19],code:{name:"CVP2",size:3}},hiper:{niceType:"Hiper",type:"hiper",patterns:[637095,63737423,63743358,637568,637599,637609,637612],gaps:[4,8,12],lengths:[16],code:{name:"CVC",size:3}},hipercard:{niceType:"Hipercard",type:"hipercard",patterns:[606282],gaps:[4,8,12],lengths:[16],code:{name:"CVC",size:3}},verve:{niceType:"Verve",type:"verve",patterns:[[506099,506127],506129,[506133,506150],[506158,506163],506166,506168,506170,506173,[506176,506180],506184,[506187,506188],506191,506195,506197,507865,507866,[507868,507877],[507880,507888],507900,507941],gaps:[4,8,12],lengths:[16,18,19],code:{name:"CVV",size:3}}}),n=function(){if(ht)return pt;ht=1,Object.defineProperty(pt,"__esModule",{value:!0}),pt.addMatchingCardsToResults=function(n,r,o){var a,i;for(a=0;a<r.patterns.length;a++){var s=r.patterns[a];if((0,t.matches)(n,s)){var c=(0,e.clone)(r);i=Array.isArray(s)?String(s[0]).length:String(s).length,n.length>=i&&(c.matchStrength=i),o.push(c);break}}};var e=mt(),t=(yt||(yt=1,Object.defineProperty(xt,"__esModule",{value:!0}),xt.matches=function(e,t){return Array.isArray(t)?function(e,t,n){var r=String(t).length,o=e.substr(0,r),a=parseInt(o,10);return t=parseInt(String(t).substr(0,o.length),10),n=parseInt(String(n).substr(0,o.length),10),a>=t&&a<=n}(e,t[0],t[1]):function(e,t){return(t=String(t)).substring(0,e.length)===e.substring(0,t.length)}(e,t)}),xt);return pt}(),r=(gt||(gt=1,Object.defineProperty(St,"__esModule",{value:!0}),St.isValidInputType=function(e){return"string"==typeof e||e instanceof String}),St),o=(vt||(vt=1,Object.defineProperty(Et,"__esModule",{value:!0}),Et.findBestMatch=function(e){return function(e){var t=e.filter(function(e){return e.matchStrength}).length;return t>0&&t===e.length}(e)?e.reduce(function(e,t){return e?Number(e.matchStrength)<Number(t.matchStrength)?t:e:t}):null}),Et),a=mt(),i={},s={VISA:"visa",MASTERCARD:"mastercard",AMERICAN_EXPRESS:"american-express",DINERS_CLUB:"diners-club",DISCOVER:"discover",JCB:"jcb",UNIONPAY:"unionpay",VERVE:"verve",MAESTRO:"maestro",ELO:"elo",MIR:"mir",HIPER:"hiper",HIPERCARD:"hipercard"},c=[s.VISA,s.MASTERCARD,s.AMERICAN_EXPRESS,s.DINERS_CLUB,s.DISCOVER,s.JCB,s.UNIONPAY,s.VERVE,s.MAESTRO,s.ELO,s.MIR,s.HIPER,s.HIPERCARD],l=(0,a.clone)(c);function u(e){return i[e]||t[e]}function d(e,t){void 0===t&&(t=!1);var n=l.indexOf(e);if(!t&&-1===n)throw new Error('"'+e+'" is not a supported card type.');return n}function p(e){var t=[];if(!(0,r.isValidInputType)(e))return t;if(0===e.length)return l.map(function(e){return(0,a.clone)(u(e))});l.forEach(function(r){var o=u(r);(0,n.addMatchingCardsToResults)(e,o,t)});var i=(0,o.findBestMatch)(t);return i?[i]:t}return p.getTypeInfo=function(e){return(0,a.clone)(u(e))},p.removeCard=function(e){var t=d(e);l.splice(t,1)},p.addCard=function(e){var t=d(e.type,!0);i[e.type]=e,-1===t&&l.push(e.type)},p.updateCard=function(n,r){var o=i[n]||t[n];if(!o)throw new Error('"'.concat(n,"\" is not a recognized type. Use `addCard` instead.'"));if(r.type&&o.type!==r.type)throw new Error("Cannot overwrite type parameter.");var s=(0,a.clone)(o);s=e(e({},s),r),i[s.type]=s},p.changeOrder=function(e,t){var n=d(e);l.splice(n,1),l.splice(t,0,e)},p.resetModifications=function(){l=(0,a.clone)(c),i={}},p.types=s,bt=p}var kt,Pt,_t,Ot,jt,At={},Nt={},It={},Tt={},Mt={};function Ft(){if(jt)return Mt;jt=1,Object.defineProperty(Mt,"__esModule",{value:!0}),Mt.expirationYear=function(n,r){var o;if(void 0===r&&(r=e),"string"!=typeof n)return t(!1,!1);if(""===n.replace(/\s/g,""))return t(!1,!0);if(!/^\d*$/.test(n))return t(!1,!1);var a=n.length;if(a<2)return t(!1,!0);var i=(new Date).getFullYear();if(3===a)return t(!1,n.slice(0,2)===String(i).slice(0,2));if(a>4)return t(!1,!1);var s=parseInt(n,10),c=Number(String(i).substr(2,2)),l=!1;if(2===a){if(String(i).substr(0,2)===n)return t(!1,!0);o=c===s,l=s>=c&&s<=c+r}else 4===a&&(o=i===s,l=s>=i&&s<=i+r);return t(l,l,o)};var e=19;function t(e,t,n){return{isValid:e,isPotentiallyValid:t,isCurrentYear:n||!1}}return Mt}var Rt,$t,Dt,Vt,Lt={},Bt={};function zt(){if(Dt)return Bt;function e(e,t,n){return{isValid:e,isPotentiallyValid:t,isValidForThisYear:n||!1}}return Dt=1,Object.defineProperty(Bt,"__esModule",{value:!0}),Bt.expirationMonth=function(t){var n=(new Date).getMonth()+1;if("string"!=typeof t)return e(!1,!1);if(""===t.replace(/\s/g,"")||"0"===t)return e(!1,!0);if(!/^\d*$/.test(t))return e(!1,!1);var r=parseInt(t,10);if(isNaN(Number(t)))return e(!1,!1);var o=r>0&&r<13;return e(o,o,o&&r>=n)},Bt}var Ut,qt,Wt,Yt,Ht={},Jt={};const Kt=M(function(){if(Yt)return Wt;Yt=1;var e=Wt&&Wt.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),t=Wt&&Wt.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),n=(Wt&&Wt.__importStar||function(){var n=function(e){return(n=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n);return t})(e)};return function(r){if(r&&r.__esModule)return r;var o={};if(null!=r)for(var a=n(r),i=0;i<a.length;i++)"default"!==a[i]&&e(o,r,a[i]);return t(o,r),o}}())(Ct()),r=function(){if(kt)return At;kt=1,Object.defineProperty(At,"__esModule",{value:!0}),At.cardholderName=function(r){return"string"!=typeof r?n(!1,!1):0===r.length?n(!1,!0):r.length>t?n(!1,!1):e.test(r)?n(!1,!0):n(!0,!0)};var e=/^[\d\s-]*$/,t=255;function n(e,t){return{isValid:e,isPotentiallyValid:t}}return At}(),o=function(){if(Ot)return Nt;Ot=1,Object.defineProperty(Nt,"__esModule",{value:!0}),Nt.cardNumber=function(r,o){var a,i;if(void 0===o&&(o={}),"string"!=typeof r&&"number"!=typeof r)return n(null,!1,!1);var s=String(r).replace(/-|\s/g,"");if(!/^\d*$/.test(s))return n(null,!1,!1);var c=t(s);if(0===c.length)return n(null,!1,!1);if(1!==c.length)return n(null,!0,!1);var l=c[0];if(o.maxLength&&s.length>o.maxLength)return n(l,!1,!1);a=!0===o.skipLuhnValidation||l.type===t.types.UNIONPAY&&!0!==o.luhnValidateUnionPay||e(s),i=Math.max.apply(null,l.lengths),o.maxLength&&(i=Math.min(o.maxLength,i));for(var u=0;u<l.lengths.length;u++)if(l.lengths[u]===s.length)return n(l,s.length<i||a,a);return n(l,s.length<i,!1)};var e=_t?Pt:(_t=1,Pt=function(e){for(var t,n=0,r=!1,o=e.length-1;o>=0;)t=parseInt(e.charAt(o),10),r&&(t*=2)>9&&(t=t%10+1),r=!r,n+=t,o--;return n%10==0}),t=Ct();function n(e,t,n){return{card:e,isPotentiallyValid:t,isValid:n}}return Nt}(),a=function(){if(Vt)return It;Vt=1;var e=It&&It.__assign||function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)};Object.defineProperty(It,"__esModule",{value:!0}),It.expirationDate=function(a,i){var s;if("string"==typeof a)a=a.replace(/^(\d\d) (\d\d(\d\d)?)$/,"$1/$2"),s=(0,t.parseDate)(String(a));else{if(null===a||"object"!=typeof a)return o(!1,!1,null,null);var c=e({},a);s={month:String(c.month),year:String(c.year)}}var l=(0,n.expirationMonth)(s.month),u=(0,r.expirationYear)(s.year,i);if(l.isValid){if(u.isCurrentYear){var d=l.isValidForThisYear;return o(d,d,s.month,s.year)}if(u.isValid)return o(!0,!0,s.month,s.year)}return o(!1,!(!l.isPotentiallyValid||!u.isPotentiallyValid),null,null)};var t=function(){if($t)return Tt;$t=1,Object.defineProperty(Tt,"__esModule",{value:!0}),Tt.parseDate=function(n){var r;if(/^\d{4}-\d{1,2}$/.test(n)?r=n.split("-").reverse():/\//.test(n)?r=n.split(/\s*\/\s*/g):/\s/.test(n)&&(r=n.split(/ +/g)),(0,t.isArray)(r))return{month:r[0]||"",year:r.slice(1).join()};var o,a,i,s=(o=n,0===(i=Number(o[0]))?2:i>1||1===i&&Number(o[1])>2?1:1===i?(a=o.substr(1),(0,e.expirationYear)(a).isPotentiallyValid?1:2):5===o.length?1:o.length>5?2:1),c=n.substr(0,s);return{month:c,year:n.substr(c.length)}};var e=Ft(),t=(Rt||(Rt=1,Object.defineProperty(Lt,"__esModule",{value:!0}),Lt.isArray=void 0,Lt.isArray=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)}),Lt);return Tt}(),n=zt(),r=Ft();function o(e,t,n,r){return{isValid:e,isPotentiallyValid:t,month:n,year:r}}return It}(),i=zt(),s=Ft(),c=function(){if(Ut)return Ht;Ut=1,Object.defineProperty(Ht,"__esModule",{value:!0}),Ht.cvv=function(n,r){return void 0===r&&(r=e),r=r instanceof Array?r:[r],"string"!=typeof n?t(!1,!1):/^\d*$/.test(n)?function(e,t){for(var n=0;n<e.length;n++)if(t===e[n])return!0;return!1}(r,n.length)?t(!0,!0):n.length<Math.min.apply(null,r)?t(!1,!0):n.length>function(t){for(var n=e,r=0;r<t.length;r++)n=t[r]>n?t[r]:n;return n}(r)?t(!1,!1):t(!0,!0):t(!1,!1)};var e=3;function t(e,t){return{isValid:e,isPotentiallyValid:t}}return Ht}(),l=function(){if(qt)return Jt;qt=1,Object.defineProperty(Jt,"__esModule",{value:!0}),Jt.postalCode=function(r,o){void 0===o&&(o={});var a=o.minLength||e;return"string"!=typeof r?n(!1,!1):r.length<a?n(!1,!0):t.test(r.trim().slice(0,a))?n(!0,!0):n(!1,!0)};var e=2,t=new RegExp(/^[a-z0-9]+$/i);function n(e,t){return{isValid:e,isPotentiallyValid:t}}return Jt}();return Wt={creditCardType:n,cardholderName:r.cardholderName,number:o.cardNumber,expirationDate:a.expirationDate,expirationMonth:i.expirationMonth,expirationYear:s.expirationYear,cvv:c.cvv,postalCode:l.postalCode}}()),Xt=M(Ct());let Zt=!1;Zt||(Zt=!0,Xt.addCard({niceType:"Mada",type:"mada",patterns:[440647,440795,446404,446672,419593,428331,428671,432328,440533,446393,457865,458456,462220,484783,484800,493428,504300,521076,529415,535825,536023,537767,543357,557606,558848,588845,589206],gaps:[4,8,12],lengths:[16,18,19],code:{name:"CVV",size:3}}));const Gt=({brand:t,fallbackColor:n,height:r=22})=>{if(!t)return null;switch(t){case"Visa":return e(Qt,{height:r});case"Mastercard":return e(en,{height:r});case"American Express":return e(tn,{height:r});case"Mada":return e(nn,{height:r});case"Discover":return e(rn,{height:r});case"JCB":return e(on,{height:r});default:return e("span",{className:"text-xs font-medium",style:{color:n},"aria-label":`Card brand: ${t}`,children:t})}},Qt=({height:n})=>t("svg",{role:"img","aria-label":"Visa",viewBox:"0 0 48 16",height:n,width:48*n/16,style:{display:"block"},children:[e("rect",{width:"48",height:"16",rx:"2",fill:"#1A1F71"}),e("text",{x:"24",y:"12",textAnchor:"middle",fontFamily:"Helvetica, Arial, sans-serif",fontWeight:"900",fontSize:"11",fill:"#FFFFFF",letterSpacing:"1.4",children:"VISA"})]}),en=({height:n})=>t("svg",{role:"img","aria-label":"Mastercard",viewBox:"0 0 32 20",height:n,width:32*n/20,style:{display:"block"},children:[e("circle",{cx:"12",cy:"10",r:"7",fill:"#EB001B"}),e("circle",{cx:"20",cy:"10",r:"7",fill:"#F79E1B"}),e("path",{d:"M16 4.5a7 7 0 0 1 0 11 7 7 0 0 1 0-11Z",fill:"#FF5F00","aria-hidden":"true"})]}),tn=({height:n})=>t("svg",{role:"img","aria-label":"American Express",viewBox:"0 0 48 16",height:n,width:48*n/16,style:{display:"block"},children:[e("rect",{width:"48",height:"16",rx:"2",fill:"#2E77BB"}),e("text",{x:"24",y:"11.5",textAnchor:"middle",fontFamily:"Helvetica, Arial, sans-serif",fontWeight:"700",fontSize:"9",fill:"#FFFFFF",letterSpacing:"0.4",children:"AMEX"})]}),nn=({height:n})=>t("svg",{role:"img","aria-label":"Mada",viewBox:"0 0 48 16",height:n,width:48*n/16,style:{display:"block"},children:[e("rect",{width:"48",height:"16",rx:"2",fill:"#84B740"}),e("text",{x:"24",y:"11.5",textAnchor:"middle",fontFamily:"Helvetica, Arial, sans-serif",fontWeight:"700",fontSize:"9",fill:"#FFFFFF",letterSpacing:"0.6",children:"mada"})]}),rn=({height:n})=>t("svg",{role:"img","aria-label":"Discover",viewBox:"0 0 56 16",height:n,width:56*n/16,style:{display:"block"},children:[e("rect",{width:"56",height:"16",rx:"2",fill:"#FFFFFF",stroke:"#E5E7EB"}),e("text",{x:"20",y:"11.5",textAnchor:"middle",fontFamily:"Helvetica, Arial, sans-serif",fontWeight:"700",fontSize:"8",fill:"#231F20",letterSpacing:"0.2",children:"DISCOVER"}),e("circle",{cx:"44",cy:"8",r:"4",fill:"#FF6000"})]}),on=({height:n})=>t("svg",{role:"img","aria-label":"JCB",viewBox:"0 0 32 16",height:n,width:32*n/16,style:{display:"block"},children:[e("rect",{x:"0",y:"0",width:"10.66",height:"16",rx:"2",fill:"#0E4C96"}),e("rect",{x:"10.66",y:"0",width:"10.66",height:"16",fill:"#B41E25"}),e("rect",{x:"21.33",y:"0",width:"10.66",height:"16",rx:"2",fill:"#1B8A3A"}),e("text",{x:"16",y:"11",textAnchor:"middle",fontFamily:"Helvetica, Arial, sans-serif",fontWeight:"900",fontSize:"9",fill:"#FFFFFF",children:"JCB"})]}),an=({skin:r})=>{const{paymentInit:o}=jn(),a=o&&"moyasar"===o.provider?o:null,u=Fe(),d=Re(),f=$e(),[m,y]=i(""),[g,v]=i(""),[b,w]=i(""),[x,S]=i(""),[E,C]=i(!1),[k,P]=i({}),[_,O]=i(null),j=s({number:m,expiry:g,cvc:b,name:x});j.current={number:m,expiry:g,cvc:b,name:x};const A=s(u);A.current=u,p(()=>{a&&f({amount:a.config.amount,currency:a.config.currency.toUpperCase()})},[a,f]);const N=c(async()=>{if(!a)return;const e=function(e,t=new Date){const n=[],r=Kt.number(e.number),o=e.number.replace(/\D/g,"");o?r.isValid||n.push({field:"number",message:"Invalid card number"}):n.push({field:"number",message:"Card number is required"});const a=Kt.expirationDate(e.expiry);let i=null,s=null;const c=e.expiry.trim();if(c)if(a.isValid){i=Number.parseInt(a.month??"",10);const e=Number.parseInt(a.year??"",10);s=2===(a.year??"").length?e+2e3:e}else{const e=function(e){let t="",n="";if(e.includes("/")){const[r,o]=e.split("/");t=(r??"").replace(/\D/g,""),n=(o??"").replace(/\D/g,"")}else{const r=e.replace(/\D/g,"");t=r.slice(0,2),n=r.slice(2)}const r=Number.parseInt(t,10),o=Number.parseInt(n,10);return Number.isNaN(r)||Number.isNaN(o)?null:{month:r,year:2===n.length?o+2e3:o}}(c);e&&function(e,t,n){const r=n.getFullYear(),o=n.getMonth()+1;return t<r||t===r&&e<o}(e.month,e.year,t)?n.push({field:"expiry",message:"Card expired"}):n.push({field:"expiry",message:"Invalid expiry"})}else n.push({field:"expiry",message:"Expiry is required"});const l=Kt.cvv(e.cvc,r.card?.code.size??[3,4]),u=e.cvc.replace(/\D/g,"");u?l.isValid||n.push({field:"cvc",message:"Invalid CVC"}):n.push({field:"cvc",message:"CVC is required"});const d=Kt.cardholderName(e.name),p=e.name.trim();return p?d.isValid||n.push({field:"name",message:"Invalid cardholder name"}):n.push({field:"name",message:"Cardholder name is required"}),n.length>0||null==i||null==s?{ok:!1,errors:n}:{ok:!0,card:{number:o,month:String(i).padStart(2,"0"),year:String(s),cvc:u,name:p}}}(j.current);if(!1===e.ok){const t={};for(const n of e.errors)t[n.field]||(t[n.field]=n.message);return void P(t)}P({}),C(!0);try{const t=await async function(e){const t=await nt("https://api.moyasar.com/v1/tokens",{...e,save_only:!0});if(!t.ok)throw new et(rt(t.body)??`Tokenization failed (${t.status})`,t.status,t.body);const n=t.body;if(!n||"string"!=typeof n.id)throw new et("Tokenization returned no token id",t.status,n);return{id:n.id}}({publishable_api_key:a.config.publishable_key,name:e.card.name,number:e.card.number,month:e.card.month,year:e.card.year,cvc:e.card.cvc}),n=Qe(a),r=await tt({publishable_api_key:a.config.publishable_key,given_id:a.config.given_id,amount:a.config.amount,currency:a.config.currency.toUpperCase(),description:a.config.description,callback_url:h(a.config.given_id),source:{type:"token",token:t.id},...Object.keys(n).length>0?{metadata:n}:{}}),o=r.source?.transaction_url??r.transaction_url;if(o)return void O(o);const i=r.status;A.current("paid"===i||"authorized"===i||"captured"===i?{status:"success",provider:"moyasar",paymentId:r.id,amount:r.amount,currency:r.currency}:"failed"===i?{status:"failure",provider:"moyasar",code:"failed",message:r.source?.message??"Payment failed",paymentId:r.id}:{status:"failure",provider:"moyasar",code:i,message:`Unexpected payment status: ${i}`,paymentId:r.id})}catch(e){const t=e instanceof et||e instanceof Error?e.message:"Payment failed";A.current({status:"failure",provider:"moyasar",message:t,paymentId:a.config.given_id})}finally{C(!1)}},[a]);p(()=>(d({confirm:N,isConfirming:E}),()=>d(null)),[N,E,d]);const I=l(()=>Math.max(r.radius-4,4),[r.radius]),T=l(()=>function(e){const t=e.replace(/\D/g,"");if(t.length<2)return null;const n=Xt(t);return n[0]?.niceType??null}(m),[m]);return a?t(n,{children:[t("div",{className:"space-y-3",style:{fontFamily:r.fontFamily},children:[e(cn,{label:"Card number",value:m,onChange:e=>y(e.replace(/\D/g,"").slice(0,19).replace(/(\d{4})(?=\d)/g,"$1 ")),autoComplete:"cc-number",inputMode:"numeric",placeholder:"1234 5678 9012 3456",error:k.number,skin:r,radius:I,endAdornment:T?e(Gt,{brand:T,fallbackColor:r.muted}):null}),t("div",{className:"grid grid-cols-2 gap-3",children:[e(cn,{label:"Expiry",value:g,onChange:e=>v(function(e){const t=e.replace(/\D/g,"").slice(0,4);return t.length<=2?t:`${t.slice(0,2)}/${t.slice(2)}`}(e)),autoComplete:"cc-exp",inputMode:"numeric",placeholder:"MM / YY",error:k.expiry,skin:r,radius:I}),e(cn,{label:"CVC",value:b,onChange:e=>w(e.replace(/\D/g,"").slice(0,4)),autoComplete:"cc-csc",inputMode:"numeric",placeholder:"123",error:k.cvc,skin:r,radius:I})]}),e(cn,{label:"Name on card",value:x,onChange:S,autoComplete:"cc-name",inputMode:"text",placeholder:"Full name",error:k.name,skin:r,radius:I})]}),_&&e(at,{url:_,skin:r,onResult:e=>{O(null),A.current(e)}})]}):null};function sn(e){let t=0;for(let n=0;n<e.length;n++){const r=e.charCodeAt(n);r>=48&&r<=57&&t++}return t}const cn=({label:n,value:r,onChange:o,placeholder:a,autoComplete:i,inputMode:c,error:l,skin:u,radius:d,endAdornment:p})=>{const m=l?"#dc2626":u.divider,y=s(null),h=s(null),g="numeric"===c;return f(()=>{const e=h.current;if(null===e||!y.current)return;h.current=null;const t=y.current.value;let n=0,r=0;for(;r<t.length&&!(n>=e);)/\d/.test(t[r])&&n++,r++;y.current.setSelectionRange(r,r)},[r]),t("label",{className:"block",children:[e("span",{className:"block text-xs mb-1",style:{color:u.muted},children:n}),t("div",{className:"relative",children:[e("input",{ref:y,type:"text",value:r,onChange:e=>{g&&(h.current=sn(e.target.value.slice(0,e.target.selectionStart??e.target.value.length))),o(e.target.value)},onKeyDown:e=>{if(!g||"Backspace"!==e.key)return;const t=e.currentTarget,n=t.selectionStart??0;if(n!==(t.selectionEnd??0)||n<2)return;const r=t.value[n-1];if(!r||/\d/.test(r))return;e.preventDefault();const a=t.value.slice(0,n-2)+t.value.slice(n);h.current=sn(a.slice(0,n-2)),o(a)},placeholder:a,autoComplete:i,inputMode:c,spellCheck:!1,className:"w-full py-3 px-3 outline-none text-sm transition-colors",style:{background:u.pillBg,color:u.text,border:`1px solid ${m}`,borderRadius:d,paddingRight:p?96:void 0}}),p&&e("span",{className:"absolute right-3 top-1/2 -translate-y-1/2 text-xs font-medium pointer-events-none",style:{color:u.muted},"aria-label":"Card brand",children:p})]}),l&&e("span",{className:"block mt-1 text-xs",style:{color:"#dc2626"},children:l})]})},ln=["creditcard","applepay"],un=({skin:n})=>t("div",{className:"relative",children:[e("div",{className:"absolute inset-x-0 top-1/2",style:{borderTop:`1px solid ${n.divider}`}}),e("div",{className:"relative flex justify-center",children:e("span",{className:"px-2 text-xs uppercase tracking-wide",style:{background:n.cardBg,color:n.muted,fontFamily:n.fontFamily},children:"or"})})]}),dn={type:"moyasar",label:"Moyasar",FormComponent:({skin:n,onReady:r})=>{const{paymentInit:o}=jn(),a=o&&"moyasar"===o.provider?o:null,c=function(){const[e,t]=i(!1);return p(()=>{if("undefined"==typeof window)return;const e=window.ApplePaySession;if(e&&"function"==typeof e.canMakePayments)try{t(!0===e.canMakePayments())}catch{t(!1)}},[]),e}(),l=s(r);if(l.current=r,p(()=>{l.current?.()},[]),!a)return null;const u=a.config.methods??ln,d=u.includes("creditcard"),f=u.includes("applepay")&&c;return t("div",{className:"space-y-4",children:[d&&e(an,{skin:n}),d&&f&&e(un,{skin:n}),f&&e(ct,{skin:n})]})}},pn="5vh",fn="5vw",mn="aiatcore-chargebee-modal-style",yn="aiatcore-chargebee-close-button",hn="aiatcore-chargebee-loader",gn="aiatcore-cb-spin",vn='#cb-container, .cb-container, [id^="cb-modal"], [class*="cb-modal"], [class*="cb-checkout"], div[class*="cb-"][class*="overlay"]',bn="aiatcore-chargebee-open";function wn(){document.getElementById(yn)?.remove()}function xn(){document.getElementById(hn)?.remove()}const Sn={type:"chargebee",label:"Chargebee",FormComponent:({amount:e,currency:t,onReady:n})=>{const{paymentInit:r}=jn(),o=Fe(),a=$e(),i=Re(),c=s(!1);return p(()=>(i(null),()=>i(null)),[i]),p(()=>{if("chargebee"!==r?.provider)return;const{site:i,hosted_page_url:s,amount:l,currency:u,expires_at:d}=r.config,p=l??e,f=u??t;null!=p&&f&&a({amount:p,currency:f}),c.current=!1;let m=!1,y=null,h=null;const g=e=>{c.current||(c.current=!0,o(e))};return n?.(),null!=d&&Date.now()>=1e3*d?(g({status:"failure",provider:"chargebee",message:"Payment link has expired. Please request a new one."}),()=>{m=!0}):(function(){const e=document.getElementById(mn)??document.createElement("style");e.id=mn,e.textContent=`\n /* Prevent horizontal page scroll only while Chargebee's overlay is mounted */\n html.${bn}, body.${bn} {\n overflow-x: hidden !important;\n }\n\n /* Outer Chargebee overlay container — broad selector net so we catch\n whatever wrapper Chargebee actually uses */\n #cb-container,\n .cb-container,\n [id^="cb-modal"],\n [class*="cb-modal"],\n [class*="cb-checkout"],\n div[class*="cb-"][class*="overlay"] {\n position: fixed !important;\n inset: ${pn} max(${fn}, calc((100vw - 1500px) / 2)) !important;\n width: auto !important;\n height: auto !important;\n max-width: none !important;\n max-height: none !important;\n margin: 0 !important;\n border-radius: 12px !important;\n box-shadow: 0 20px 60px rgba(0,0,0,0.35) !important;\n overflow: hidden !important;\n z-index: 2147483646 !important;\n pointer-events: all !important;\n }\n\n /* Inner iframe — fill the container fully and ensure it receives clicks */\n [id^="cb-frame"] {\n width: 100% !important;\n height: 100% !important;\n border: none !important;\n display: block !important;\n z-index: 2147483646 !important;\n pointer-events: all !important;\n outline: none !important;\n box-shadow: none !important;\n }\n\n @keyframes ${gn} {\n to { transform: rotate(360deg); }\n }\n `,e.parentElement||document.head.appendChild(e),document.documentElement.classList.add(bn),document.body.classList.add(bn)}(),function(e){if(window.Chargebee)return Promise.resolve();const t=document.querySelector('script[src*="js.chargebee.com"]');return t?"1"===t.dataset.cbLoaded?Promise.resolve():new Promise((e,n)=>{t.addEventListener("load",()=>e()),t.addEventListener("error",()=>n(new Error("Chargebee.js failed to load")))}):new Promise((t,n)=>{const r=document.createElement("script");r.src="https://js.chargebee.com/v2/chargebee.js",r.setAttribute("data-cb-site",e),r.onload=()=>{r.dataset.cbLoaded="1",t()},r.onerror=()=>n(new Error("Chargebee.js failed to load")),document.head.appendChild(r)})}(i).then(()=>{if(m)return;let e;try{e=window.Chargebee.getInstance()??window.Chargebee.init({site:i})}catch{e=window.Chargebee.init({site:i})}e.openCheckout({hostedPage:()=>Promise.resolve({id:r.payment_id,url:s,type:"checkout_one_time",state:"created"}),success:e=>{wn(),xn(),g({status:"success",provider:"chargebee",paymentId:e,amount:p??void 0,currency:f??void 0})},close:()=>{wn(),xn(),g({status:"cancel",provider:"chargebee"})},error:e=>{wn(),xn(),g({status:"failure",provider:"chargebee",message:e?.message??"Payment failed"})}}),h=function(){let e=0,t=0,n=0,r=null,o=null;const a=Date.now()+5e3,i=()=>{if(m||c.current)return;const t=document.querySelector(vn);if(t instanceof HTMLElement){const e=t.getBoundingClientRect();if(e.width>0&&e.height>0){!function(){xn();const e=document.createElement("div");e.id=hn,e.setAttribute("aria-live","polite"),e.setAttribute("aria-busy","true"),e.style.cssText=`\n position: fixed;\n inset: ${pn} max(${fn}, calc((100vw - 1500px) / 2));\n z-index: 2147483646;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n gap: 14px;\n background: #f8f8f8;\n border-radius: 12px;\n color: #6b7280;\n font: 500 14px/1.4 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;\n pointer-events: none;\n `;const t=document.createElement("div");t.style.cssText=`\n width: 32px;\n height: 32px;\n border: 2.5px solid rgba(17, 24, 39, 0.08);\n border-top-color: #6366f1;\n border-radius: 50%;\n animation: ${gn} 0.8s linear infinite;\n `;const n=document.createElement("p");n.textContent="Loading payment…",n.style.cssText="margin: 0;",e.appendChild(t),e.appendChild(n),document.body.appendChild(e)}();const e=document.querySelector('[id^="cb-frame"]');return void(e instanceof HTMLIFrameElement&&(r=e,o=()=>{n=window.setTimeout(xn,400)},r.addEventListener("load",o)))}}Date.now()>=a||(e=window.requestAnimationFrame(i))};return t=window.setTimeout(i,100),()=>{window.clearTimeout(t),window.clearTimeout(n),e&&window.cancelAnimationFrame(e),r&&o&&r.removeEventListener("load",o),xn()}}(),y=function(e){let t=0,n=0;const r=Date.now()+5e3,o=()=>{if(m||c.current)return;const n=document.querySelector(vn);if(n instanceof HTMLElement){const t=n.getBoundingClientRect();if(t.width>0&&t.height>0)return void function(e){wn();const t=document.createElement("button");t.id=yn,t.type="button",t.setAttribute("aria-label","Close payment"),t.textContent="×",t.style.cssText=`\n position: fixed;\n top: calc(${pn} + 12px);\n right: calc(max(${fn}, calc((100vw - 1500px) / 2)) + 12px);\n z-index: 2147483647;\n width: 32px;\n height: 32px;\n border: 0;\n border-radius: 9999px;\n background: rgba(17, 24, 39, 0.72);\n color: #ffffff;\n font: 600 16px/1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;\n cursor: pointer;\n pointer-events: auto;\n display: flex;\n align-items: center;\n justify-content: center;\n box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);\n `,t.addEventListener("click",e),document.body.appendChild(t)}(e)}Date.now()>=r||(t=window.requestAnimationFrame(o))};return n=window.setTimeout(o,100),()=>{window.clearTimeout(n),t&&window.cancelAnimationFrame(t)}}(()=>{wn(),xn(),document.querySelectorAll(vn).forEach(e=>{e instanceof HTMLElement&&(e.style.display="none")}),g({status:"cancel",provider:"chargebee"});try{e.closeAll()}catch{}})}).catch(e=>{g({status:"failure",provider:"chargebee",message:e?.message??"Failed to load payment form"})}),()=>{m=!0,y?.(),h?.(),wn(),xn(),document.documentElement.classList.remove(bn),document.body.classList.remove(bn),document.getElementById(mn)?.remove();try{window.Chargebee?.getInstance?.()?.closeAll?.()}catch{}})},[r,e,t,a,n,o]),null},hideShellSubmit:!0};function En(){const e=document.createElement("div");e.style.cssText="position:absolute;top:-9999px;width:100px;height:100px;overflow:scroll;",document.body.appendChild(e);const t=e.offsetWidth-e.clientWidth;return e.remove(),Math.max(0,t)}function Cn(e,t,n){e?.contentWindow?.postMessage(g(t),n)}const kn=({init:n,onResult:r,skin:o})=>{const a=s(null),l=s(r);f(()=>{l.current=r},[r]);const u=s(o),d=s(!1),m=s(null);f(()=>{u.current=o,d.current&&Cn(a.current,o,m.current??"*")},[o]);const y=s(!1),h=s(!1),g=s(!1),[S,E]=i(!1),[C]=i(En),k=c(e=>{h.current||y.current||(h.current=!0,l.current({status:"failure",provider:"hosted_payment_page",message:e,paymentId:n.payment_id}))},[n.payment_id]);return p(()=>{const e=e=>{if(e.source!==a.current?.contentWindow)return;if(!v(e.data))return;if(m.current=e.origin,e.data.action===b.LOADED&&(d.current=!0,Cn(a.current,u.current,e.origin)),h.current)return;const t=w(e.data.search);if(!t)return P.warn({message:"Hosted payment callback arrived without a paymentId or a known paymentStatus",api_name:"hosted-payment-page-callback"}),void k("Payment confirmation was incomplete. Please try again.");const r=e.data.action===b.DONE;if(y.current=!0,t.paymentStatus===x.CANCELED){if(!r)return;return h.current=!0,void l.current({status:"cancel",provider:"hosted_payment_page"})}r&&(h.current=!0),l.current(t.paymentStatus===x.SUCCEEDED?{status:"success",provider:"hosted_payment_page",paymentId:t.paymentId,...t.amount&&t.currency?{amount:t.amount,currency:t.currency}:{amount:n.config.amount,currency:n.config.currency},dismissed:r}:{status:"failure",provider:"hosted_payment_page",code:t.paymentStatus,message:t.message??"The payment was not completed.",paymentId:t.paymentId,dismissed:r})};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[k,n]),p(()=>{const e=setTimeout(()=>{g.current||k("The payment page failed to load.")},6e4);return()=>clearTimeout(e)},[k]),t("div",{className:"absolute inset-0 z-[105] overflow-hidden",style:{background:o.cardBg},role:"region","aria-label":"Payment",children:[!S&&e("div",{className:"absolute inset-0 flex items-center justify-center text-sm",style:{color:o.muted,fontFamily:o.fontFamily},children:"Loading…"}),e("iframe",{ref:a,src:n.config.url,title:"Payment",className:"h-full",style:{border:0,background:"white",width:`calc(100% + ${C}px)`},onLoad:()=>{g.current=!0,E(!0)},onError:()=>k("The payment page failed to load."),allow:"payment",referrerPolicy:"no-referrer"})]})},Pn={type:"hosted_payment_page",label:"Secure checkout",hideShellSubmit:!0,hideShellFooter:!0,FormComponent:({skin:t,onReady:n})=>{const{paymentInit:r}=jn(),o=r&&"hosted_payment_page"===r.provider?r:null,a=Fe(),c=s(!1);p(()=>{n?.()},[n]);const l=o?.config.expires_at,[u]=i(()=>null!=l&&Date.now()>=1e3*l);return p(()=>{o&&u&&!c.current&&(c.current=!0,a({status:"failure",provider:"hosted_payment_page",message:"Payment link has expired. Please request a new one.",paymentId:o.payment_id}))},[o,u,a]),!o||u?null:e(kn,{init:o,onResult:a,skin:t})}},_n=u(void 0),On=({children:t,paymentProvider:n,paymentInit:r=null,conversationId:o=null})=>{const a=r?.provider||n||S,i=l(()=>function(e){switch(e){case"stripe":return Ge;case"moyasar":return dn;case"chargebee":return Sn;case"hosted_payment_page":return Pn;default:throw new Error(`Unknown payment provider: "${e}". Supported providers: stripe, moyasar, chargebee, hosted_payment_page`)}}(a),[a]),s=l(()=>({adapter:i,paymentProvider:a,paymentInit:r,conversationId:o}),[i,a,r,o]),c=i.ProviderWrapper;return e(_n.Provider,{value:s,children:c?e(c,{children:t}):t})},jn=()=>{const e=d(_n);if(!e)throw new Error("usePaymentAdapter must be used within a PaymentProvider");return e},An=({provider:t,paymentInit:n=null,onResult:r,conversationId:o=null})=>e(On,{paymentInit:n,conversationId:o,paymentProvider:_(),children:e(Te,{onResult:e=>{r?.(e)},children:e(Nn,{provider:t,paymentInit:n})})},n?.provider??"default"),Nn=({provider:n,paymentInit:r})=>{const{themeStyles:o,theme:a}=C(),{adapter:s}=jn(),u=Me().summary,[d,p]=i(!1),f=c(()=>p(!0),[]),y=l(()=>m(o,a),[o,a]),h="moyasar"===r?.provider?r.config:null,g="chargebee"===r?.provider?r.config:null,v=u?.amount??h?.amount??g?.amount??0,b=u?.currency??h?.currency??g?.currency??"usd",w=null!=u?.amount||null!=h?.amount||null!=g?.amount,x=((e,t)=>E(e,t)??"")(v,b),S=n??s.label,k=s.FormComponent;return t("div",{className:"w-full flex-1 min-h-0 overflow-y-auto [&::-webkit-scrollbar]:hidden [scrollbar-width:none] relative",style:{background:y.pageBg,color:y.text,fontFamily:y.fontFamily,colorScheme:y.colorScheme},children:[!d&&e(In,{skin:y}),e("div",{className:"min-h-full flex items-center justify-center p-4",style:{visibility:d?"visible":"hidden"},children:t("div",{className:"w-full max-w-lg p-6",style:{background:y.cardBg,borderRadius:y.radius,boxShadow:y.cardShadow,color:y.text},children:[e("h1",{className:"text-base font-semibold text-center mb-3.5",style:{color:y.heading},children:"Payment Options"}),e("div",{className:"mb-3.5",children:e(k,{amount:v,currency:b,skin:y,onReady:f})}),!s.hideShellSubmit&&w&&e(Tn,{label:`Pay ${x}`,background:o.statusDiscovery.solid,color:o.statusDiscovery.text,radius:y.radius}),!s.hideShellFooter&&t("p",{className:"text-xs text-center mt-2.5",style:{color:y.muted},children:["Powered by ",S]})]})})]})},In=({skin:n})=>t("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-3",style:{background:n.pageBg,color:n.text},"aria-live":"polite","aria-busy":"true",children:[e(T,{className:"h-8 w-8 animate-spin",style:{color:n.accent}}),e("p",{className:"text-sm",style:{color:n.muted},children:"Loading payment…"})]}),Tn=({label:t,background:n,color:r,radius:o})=>{const a=Me().confirmHandle;return e("button",{type:"button",onClick:()=>a?.confirm(),disabled:!a||a.isConfirming,className:"w-full p-3 text-sm font-semibold border-0 cursor-pointer disabled:cursor-not-allowed disabled:opacity-70",style:{background:n,color:r,borderRadius:o},children:a?.isConfirming?"Processing…":t})};export{An as default};
@@ -1 +0,0 @@
1
- import{jsx as y}from"react/jsx-runtime";import{useEffect as s,useRef as i,useState as u}from"react";import{usePaymentAdapter as c}from"../PaymentProvider";import{useResultEmitter as d}from"../PaymentResultChannel";import{HostedPaymentPageIframe as l}from"./hostedPaymentPage/HostedPaymentPageIframe";const f=({skin:p,onReady:o})=>{const{paymentInit:t}=c(),e=t&&t.provider==="hosted_payment_page"?t:null,r=d(),a=i(!1);s(()=>{o?.()},[o]);const m=e?.config.expires_at,[n]=u(()=>m!=null&&Date.now()>=m*1e3);return s(()=>{!e||!n||a.current||(a.current=!0,r({status:"failure",provider:"hosted_payment_page",message:"Payment link has expired. Please request a new one.",paymentId:e.payment_id}))},[e,n,r]),!e||n?null:y(l,{init:e,onResult:r,skin:p})},x={type:"hosted_payment_page",label:"Secure checkout",hideShellSubmit:!0,hideShellFooter:!0,FormComponent:f};export{x as hostedPaymentPageAdapter};
@@ -1 +0,0 @@
1
- import{jsx as T,jsxs as D}from"react/jsx-runtime";import{useCallback as R,useEffect as h,useLayoutEffect as P,useRef as a,useState as b}from"react";import{HOSTED_PAYMENT_PAGE_CALLBACK_ACTIONS as w,HOSTED_PAYMENT_PAGE_STATUSES as E,buildHostedPaymentPageThemeMessage as H,isHostedPaymentPageCallbackMessage as L,parseHostedPaymentPageCallback as k}from"@1interface/chat-core";import{logger as A}from"@1interface/shared-core";const M=6e4;function x(){const e=document.createElement("div");e.style.cssText="position:absolute;top:-9999px;width:100px;height:100px;overflow:scroll;",document.body.appendChild(e);const n=e.offsetWidth-e.clientWidth;return e.remove(),Math.max(0,n)}function _(e,n,r){e?.contentWindow?.postMessage(H(n),r)}const G=({init:e,onResult:n,skin:r})=>{const l=a(null),u=a(n);P(()=>{u.current=n},[n]);const m=a(r),p=a(!1),f=a(null);P(()=>{m.current=r,p.current&&_(l.current,r,f.current??"*")},[r]);const y=a(!1),c=a(!1),g=a(!1),[S,I]=b(!1),[v]=b(x),i=R(s=>{c.current||y.current||(c.current=!0,u.current({status:"failure",provider:"hosted_payment_page",message:s,paymentId:e.payment_id}))},[e.payment_id]);return h(()=>{const s=o=>{if(o.source!==l.current?.contentWindow||!L(o.data)||(f.current=o.origin,o.data.action===w.LOADED&&(p.current=!0,_(l.current,m.current,o.origin)),c.current))return;const t=k(o.data.search);if(!t){A.warn({message:"Hosted payment callback arrived without a paymentId or a known paymentStatus",api_name:"hosted-payment-page-callback"}),i("Payment confirmation was incomplete. Please try again.");return}const d=o.data.action===w.DONE;if(y.current=!0,t.paymentStatus===E.CANCELED){if(!d)return;c.current=!0,u.current({status:"cancel",provider:"hosted_payment_page"});return}d&&(c.current=!0);const C=t.amount&&t.currency?{amount:t.amount,currency:t.currency}:{amount:e.config.amount,currency:e.config.currency};u.current(t.paymentStatus===E.SUCCEEDED?{status:"success",provider:"hosted_payment_page",paymentId:t.paymentId,...C,dismissed:d}:{status:"failure",provider:"hosted_payment_page",code:t.paymentStatus,message:t.message??"The payment was not completed.",paymentId:t.paymentId,dismissed:d})};return window.addEventListener("message",s),()=>window.removeEventListener("message",s)},[i,e]),h(()=>{const s=setTimeout(()=>{g.current||i("The payment page failed to load.")},M);return()=>clearTimeout(s)},[i]),D("div",{className:"absolute inset-0 z-[105] overflow-hidden",style:{background:r.cardBg},role:"region","aria-label":"Payment",children:[!S&&T("div",{className:"absolute inset-0 flex items-center justify-center text-sm",style:{color:r.muted,fontFamily:r.fontFamily},children:"Loading\u2026"}),T("iframe",{ref:l,src:e.config.url,title:"Payment",className:"h-full",style:{border:0,background:"white",width:`calc(100% + ${v}px)`},onLoad:()=>{g.current=!0,I(!0)},onError:()=>i("The payment page failed to load."),allow:"payment",referrerPolicy:"no-referrer"})]})};export{G as HostedPaymentPageIframe};