import{u as C}from"./DzzIZdzn.js";import{d as K,e as D,r as E,j as O,aF as R,f as v,x as g,bi as A,g as a,v as B,o as m,_ as L}from"./BxiWQxwE.js";const I=()=>{const{initializeNeo:h,isIos:f,isAndroid:w,neoInstance:c,isAuthenticated:p,authenticateUser:y}=C();return{invokeSdkAction:async(s,o={})=>{var d,u,i,r;await h();const n={action:s,params:o};try{if(f.value){console.info("[useMobileBridge] Calling iOS SDK:",n),(i=(u=(d=window.webkit)==null?void 0:d.messageHandlers)==null?void 0:u.iosCommunication)==null||i.postMessage(n);return}if(w.value){console.info("[useMobileBridge] Calling Android SDK:",n),(r=window.androidCommunication)==null||r.postMessage(JSON.stringify(n));return}if(c.value){if(!p.value&&!await y())return!1;c.value.openView(s,o);return}console.error("SDK not ready")}catch(t){console.error("Error invoking SDK action:",t)}},setupNativeReceiver:()=>{console.info("[useMobileBridge] Setting up native message receiver"),typeof window<"u"&&(window.receiveMessageFromNative=s=>{try{const o=JSON.parse(s);window.dispatchEvent(new CustomEvent("native-message",{detail:o})),console.info("[useMobileBridge] Message received from native:",o)}catch{console.warn("[useMobileBridge] Received non-JSON message:",s),window.dispatchEvent(new CustomEvent("native-message",{detail:{message:s}}))}})},onNativeMessage:s=>{const o=n=>s(n.detail);return window==null||window.addEventListener("native-message",o),()=>window==null?void 0:window.removeEventListener("native-message",o)}}},J={class:"neo--sdk-container"},U={key:0,class:"neo--loading"},V={key:1,class:"neo--error"},x={key:3,class:"neo--message"},F=K({__name:"sdk-bridge",emits:["ready","error","message"],setup(h,{expose:f,emit:w}){const{isSDKLoaded:c,isSDKLoading:p,loadError:y,initializeNeo:M,authenticateUser:S,isAuthenticated:k,isIos:s,isAndroid:o}=C(),{invokeSdkAction:n,setupNativeReceiver:d,onNativeMessage:u}=I(),i=w,r=D(()=>{var e;return((e=y.value)==null?void 0:e.message)||""}),t=D(()=>c.value&&k.value),_=E(""),N=E();return O(async()=>{try{await M(),(s.value||o.value)&&d(),await n("mobileSdkReady"),N.value=u(e=>{_.value=typeof e=="string"?e:e.message||JSON.stringify(e),i("message",e)}),t.value&&i("ready")}catch(e){const l=e instanceof Error?e.message:String(e);i("error",l)}}),R(()=>{N.value=()=>null}),f({openView:async(e,l)=>{if(!k.value&&!await S())return console.warn("User authentication failed"),!1;try{return await n(e,l),!0}catch(b){return console.error("Failed to call iOS SDK:",b),!1}},authenticateUser:S,isReady:t,invokeSdkAction:n}),(e,l)=>(m(),v("div",J,[a(p)?(m(),v("div",U,"Loading NeoDay SDK...")):g("",!0),a(r)?(m(),v("div",V,B(a(r)),1)):g("",!0),a(t)?A(e.$slots,"controls",{key:2},void 0,!0):g("",!0),a(_)?(m(),v("div",x,B(a(_)),1)):g("",!0),A(e.$slots,"default",{},void 0,!0)]))}}),H=L(F,[["__scopeId","data-v-b814856a"]]);export{H as default};
