"use strict";const u=require("react"),y=require("zod"),c=require("./Env-a6f11491.js"),d=require("./useRoutes-df841412.js"),m=require("@accelbyte/sdk-platform");y.z.enum(["locationChange","heightChange"]);class p{static sendMessageToParentWindow({message:s,channel:r,origin:l="*"}){const i=JSON.stringify({...s,channel:r});if(!this.isInIframe()){console.log("Message to parent window ignored: ",{...s,channel:r});return}window.parent.postMessage(i,l)}static isInIframe(){try{return window.self!==window.top}catch{return!0}}}const A=y.z.enum(["complete","cancel","requestData"]);y.z.enum(["paymentSuccess","paymentGenericError"]);const S={paymentAccounts:null,paymentAccountsFetchStatus:c.FetchStatus.IDLE,paymentAccountsError:null,deletePaymentAccountFetchStatus:c.FetchStatus.IDLE,deletePaymentAccountError:null,paymentData:{},paymentStationMessage:null},f=d.createStore("payment",S);function I(){const[o]=c.useSdk(),[s,r]=d.useStore(f),l=u.useCallback(async t=>{let a=null,n=null;try{return r(e=>({...e,paymentAccountsFetchStatus:c.FetchStatus.FETCHING,paymentAccountsError:null})),a=await m.Platform.PaymentAccountApi(o).getPaymentAccounts_ByUserId(t),{data:a}}catch(e){return n=c.WidgetErrorHelper.getErrorType(e),{error:n}}finally{r(e=>({...e,paymentAccounts:a,paymentAccountsError:n,paymentAccountsFetchStatus:c.FetchStatus.IDLE}))}},[o]),i=u.useCallback(async(t,a)=>{let n=null;try{return r(e=>({...e,deletePaymentAccountFetchStatus:c.FetchStatus.DELETING,deletePaymentAccountError:null})),await m.Platform.PaymentAccountApi(o).deletePaymentAccount_ByUserId_ByType_ById(t,a.type,a.id),{data:!0}}catch(e){return n=c.WidgetErrorHelper.getErrorType(e),{error:n}}finally{r(e=>({...e,deletePaymentAccountError:n,deletePaymentAccountFetchStatus:c.FetchStatus.IDLE}))}},[o]),E=u.useCallback(({message:t,origin:a="*"})=>{let n="";if(typeof t=="object"){if(!A.options.includes(t==null?void 0:t.action))return;n=JSON.stringify(t)}else typeof t=="string"&&(n=t);if(!p.isInIframe()){r(e=>({...e,paymentStationMessage:n}));return}window.parent.postMessage(n,a)},[]),P=u.useCallback(t=>{r(a=>({...a,paymentData:t}))},[]),h=u.useCallback(()=>{r(S)},[]);return{state:s,mutations:{getPaymentAccounts:l,deletePaymentAccount:i,setPaymentData:P,setPaymentStationMessage:E,resetState:h}}}exports.ChildUtils=p;exports.PAYMENT_STATION_ACTION=A;exports.usePayment=I;
