1import{g as L,h as U,r as C,u as j,E as A,H as q,ay as z,e as Q,aW as $,P as X}from"./CeZ4BE6v.js";const Z=["aibase.com","aibase.cn"];function W(s){try{const u=new URL(s).hostname;return Z.some(d=>u===d||u.endsWith(`.${d}`))}catch{return!1}}function x(s){try{return new URL(s).origin}catch{return""}}const E={OPEN_VIP_PAY:"open_vip_pay",OPEN_VIP_UPGRADE:"open_vip_upgrade",OPEN_VIP_RENEW:"open_vip_renew",OPEN_NOTIFY:"open_notify",OPEN_BIND:"open_bind",OPEN_COUPON:"open_coupon",NOTIFY_VISIBLE:"notify_visible",REQUEST_TOKEN:"request_token"},O={SUCCESS:"success",CLOSE:"close",ERROR:"error",TOKEN_RESPONSE:"token_response"},V={VIP_INTL_PAY:"vip_intl_pay",NAVIGATE_TO_PAGE:"navigate_to_page"};let D=!1;function ee(){const s=C(null),y=q(),{locale:u,t:d}=j();let w=null;L(()=>{if(D)return;const a=new URLSearchParams(window.location.search).get("type");a&&(D=!0,a==="SUCCESS_URL"?(A.success(d("submission.paymentSuccess")),w=setTimeout(()=>{const{origin:l,pathname:P}=window.location,f=`${l}${P}`;window.location.href=f},1e3)):A.error(d("submission.paymentError")))}),U(()=>{w&&(clearTimeout(w),w=null)});const h=async()=>{var i;if(console.log("[useVipIntlPay.ensureSdk] å
¥å£",{alreadyInit:!!s.value}),s.value)return s.value;try{console.log("[useVipIntlPay.ensureSdk] 卿 import @airwallex/components-sdk ...");const{init:a}=await $(async()=>{const{init:I}=await import("./FavMBjHx.js");return{init:I}},[],import.meta.url),l=y.public.isTest?"demo":"prod",P=(i=window==null?void 0:window.location)==null?void 0:i.origin;console.log("[useVipIntlPay.ensureSdk] SDK 模åå·²å è½½ï¼è°ç¨ init",{env:l,origin:P});const{payments:f}=await a({env:l,origin:P,enabledElements:["payments"]});return console.log("[useVipIntlPay.ensureSdk] â init æå",{hasPayments:f}),s.value=f,f}catch(a){return console.error("[useVipIntlPay.ensureSdk] â Airwallex SDK åå§å失败:",a),null}};return{redirect:async(i,a)=>{var f;if(console.log("[useVipIntlPay.redirect] å
¥å£",{airwallex:i,options:a}),!(i!=null&&i.id)||!(i!=null&&i.clientSecret)){console.error("[useVipIntlPay.redirect] â ç¼ºå° Airwallex æ¯ä»åæ°");return}const l=await h();if(!l){console.error("[useVipIntlPay.redirect] â SDK æªå°±ç»ªï¼ä¸æ¢è·³è½¬");return}const P={zh:"zh",en:"en",ja:"ja",tw:"zh-HK"};console.log("[useVipIntlPay.redirect] â è°ç¨ payments.redirectToCheckout",{intent_id:i.id,client_secret:i.clientSecret});try{await l.redirectToCheckout({intent_id:i.id,client_secret:i.clientSecret,currency:i.currency||"USD",successUrl:(a==null?void 0:a.successUrl)||((f=window==null?void 0:window.location)==null?void 0:f.href),logoUrl:"https://www.aibase.com/favicon.ico",locale:P[u.value]||"en",withBilling:!0,requiredBillingContactFields:["name","email","address"],methods:["card"],mode:"payment"}),console.log("[useVipIntlPay.redirect] â redirectToCheckout 宿")}catch(I){console.error("[useVipIntlPay.redirect] â redirectToCheckout 失败:",I)}},ensureSdk:h}}function te(){const s=C(""),y=new Map,u=[];function d(){try{if(document.referrer)return new URL(document.referrer).origin}catch{}return""}function w(t,c){if(!(typeof window>"u")&&window.parent!==window){const _=s.value||d()||"*",v=c===void 0?void 0:JSON.parse(JSON.stringify(c));window.parent.postMessage({type:t,data:v},_)}}function h(t){w(O.SUCCESS,t)}function T(){w(O.CLOSE)}function i(t){w(O.ERROR,{error:t})}function a(){if(typeof window>"u"||window.parent===window)return;const t=s.value||d()||"*";window.parent.postMessage({type:E.REQUEST_TOKEN,data:{}},t)}function l(t){u.push(t)}function P(t){w(E.NOTIFY_VISIBLE,{visible:t})}function f(t){if(!(typeof window>"u"))if(console.log("[useIframeHost.sendVipIntlPay] åå¤åé vip_intl_pay ç» window.parent",{data:t,parentIsWindow:window.parent===window,currentOrigin:window.location.origin}),window.parent!==window){const c=s.value||d()||"*",_=JSON.parse(JSON.stringify(t));console.log("[useIframeHost.sendVipIntlPay] â åé",{targetOrigin:c,childOrigin:s.value,referrerOrigin:d()}),window.parent.postMessage({type:V.VIP_INTL_PAY,data:_},c),console.log("[useIframeHost.sendVipIntlPay] â postMessage å·²è°ç¨")}else console.warn("[useIframeHost.sendVipIntlPay] â window.parent === windowï¼æªå¨ iframe å
ï¼è·³è¿åé")}function I(t){if(!(typeof window>"u"))if(console.log("[useIframeHost.sendNavigateToPage] åå¤åé navigate_to_page ç» window.parent",{data:t,parentIsWindow:window.parent===window}),window.parent!==window){const c=s.value||d()||"*",_=JSON.parse(JSON.stringify(t));window.parent.postMessage({type:V.NAVIGATE_TO_PAGE,data:_},c),console.log("[useIframeHost.sendNavigateToPage] â postMessage å·²è°ç¨")}else console.warn("[useIframeHost.sendNavigateToPage] â window.parent === windowï¼æªå¨ iframe å
ï¼è·³è¿åé")}function m(t,c){y.has(t)||y.set(t,[]),y.get(t).push(c)}let p=null;function k(){p||(p=t=>{var v;if(!W(t.origin))return;s.value||(s.value=t.origin);const c=t.data;if(!c||typeof c!="object")return;if(c.type===O.TOKEN_RESPONSE){const N=((v=c.data)==null?void 0:v.token)||"";N&&u.forEach(R=>R(N));return}const _=y.get(c.type);_&&_.forEach(N=>N(c.data))},window.addEventListener("message",p))}return L(()=>{k()}),U(()=>{p&&(window.removeEventListener("message",p),p=null)}),{onRequest:m,sendSuccess:h,sendClose:T,sendError:i,sendVipIntlPay:f,sendNavigateToPage:I,sendVisibleRequest:P,requestToken:a,onTokenResponse:l,childOrigin:s}}function oe(s,y){const u=y||C(null),d=typeof s=="string"?C(s):s,w=X(()=>x(d.value)),h=[],T=[],i=[],a=[],l=[],P=[],{redirect:f}=ee();function I(){if(typeof window>"u")return"";try{const e=q(),o=z("token",{domain:e.public.cookieDomain});if(o.value)return o.value;const g=Q();return(g==null?void 0:g.token)||""}catch{return""}}function m(e){if(e.token)return e;const o=I();return o?{...e,token:o}:e}function p(e,o){var g;if((g=u.value)!=null&&g.contentWindow){const n=w.value;let r=n;try{const b=u.value.contentWindow.location.origin;n&&b&&b!=="null"&&b!==n&&(r="*")}catch{r="*"}const F=JSON.parse(JSON.stringify(o));u.value.contentWindow.postMessage({type:e,data:F},r||"*")}}function k(e){var n;if(!((n=u.value)!=null&&n.contentWindow)||!e)return;const o=w.value;let g=o;try{const r=u.value.contentWindow.location.origin;o&&r&&r!=="null"&&r!==o&&(g="*")}catch{g="*"}u.value.contentWindow.postMessage({type:O.TOKEN_RESPONSE,data:{token:e}},g||"*")}function t(e){p(E.OPEN_VIP_PAY,m(e))}function c(e={}){p(E.OPEN_VIP_UPGRADE,m(e))}function _(e={}){p(E.OPEN_VIP_RENEW,m(e))}function v(e){p(E.OPEN_NOTIFY,m(e))}function N(e={}){p(E.OPEN_BIND,m(e))}function R(e={}){p(E.OPEN_COUPON,m(e))}function H(e){h.push(e)}function M(e){T.push(e)}function K(e){i.push(e)}function Y(e){a.push(e)}function B(e){l.push(e)}function G(e){P.push(e)}let S=null;function J(){S||(S=e=>{var g;if(!W(e.origin)||u.value&&e.source!==u.value.contentWindow)return;const o=e.data;if(!(!o||typeof o!="object"))switch(o.type){case O.SUCCESS:h.forEac
1h(n=>n(o.data));break;case O.CLOSE:T.forEach(n=>n());break;case O.ERROR:i.forEach(n=>{var r;return n(((r=o.data)==null?void 0:r.error)||"æªç¥é误")});break;case V.VIP_INTL_PAY:{console.log("[useIframeClient.setupListener] â
æ¶å° vip_intl_pay æ¶æ¯",{origin:e.origin,data:o.data});const n=o.data;a.length?(console.log("[useIframeClient.setupListener] â 触åç¨æ·æ³¨åç vipIntlPay åè°ï¼å
±",a.length,"个"),a.forEach(r=>r(n))):(console.log("[useIframeClient.setupListener] â é»è®¤è¡ä¸ºï¼è°ç¨ redirectToVipPay",{airwallex:n.airwallex}),f(n.airwallex,{successUrl:n.successUrl,failUrl:n.failUrl}));break}case V.NAVIGATE_TO_PAGE:{console.log("[useIframeClient.setupListener] â
æ¶å° navigate_to_page æ¶æ¯",{origin:e.origin,data:o.data});const n=o.data;if(l.length)console.log("[useIframeClient.setupListener] â 触åç¨æ·æ³¨åç navigateToPage åè°ï¼å
±",l.length,"个"),l.forEach(r=>r(n));else{const r=n.target||"location";console.log("[useIframeClient.setupListener] â é»è®¤è¡ä¸ºï¼æ§è¡é¡µé¢è·³è½¬",{url:n.url,mode:r}),r==="open"?window.open(n.url,"_blank"):window.location.href=n.url}break}case E.NOTIFY_VISIBLE:{const n=!!((g=o.data)!=null&&g.visible);P.forEach(r=>r(n));break}case E.REQUEST_TOKEN:{const n=I();n?k(n):console.warn("[useIframeClient.setupListener] â å½åç¶é¡¹ç®æ tokenï¼æ æ³åä¼ ç» iframe");break}}},window.addEventListener("message",S))}return L(()=>{J()}),U(()=>{S&&(window.removeEventListener("message",S),S=null)}),{iframeRef:u,requestVipPay:t,requestVipUpgrade:c,requestVipRenew:_,requestNotify:v,requestBind:N,requestCoupon:R,onSuccess:H,onClose:M,onError:K,onVipIntlPay:Y,onNavigateToPage:B,onVisibleRequest:G,redirectToVipPay:f,sendTokenResponse:k,getCurrentToken:I}}export{E as C,oe as a,te as u};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.