"use strict";const u=require("react"),y=require("zod"),r=require("./FetchConfigsUtils-c73b687c.js"),m=require("@accelbyte/sdk-platform");y.z.enum(["locationChange","heightChange"]);class d{static sendMessageToParentWindow({message:s,channel:c,origin:l="*"}){const i=JSON.stringify({...s,channel:c});if(!this.isInIframe()){console.log("Message to parent window ignored: ",{...s,channel:c});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 p={paymentAccounts:null,paymentAccountsFetchStatus:r.FetchStatus.IDLE,paymentAccountsError:null,deletePaymentAccountFetchStatus:r.FetchStatus.IDLE,deletePaymentAccountError:null,paymentData:{},paymentStationMessage:null},h=r.createStore(p);function f(){const[o]=r.useSdk(),[s,c]=r.useStore(h),l=u.useCallback(async t=>{let a=null,n=null;try{return c(e=>({...e,paymentAccountsFetchStatus:r.FetchStatus.FETCHING,paymentAccountsError:null})),a=await m.Platform.PaymentAccountApi(o).getPaymentAccounts_ByUserId(t),{data:a}}catch(e){return n=r.WidgetErrorHelper.getErrorType(e),{error:n}}finally{c(e=>({...e,paymentAccounts:a,paymentAccountsError:n,paymentAccountsFetchStatus:r.FetchStatus.IDLE}))}},[o]),i=u.useCallback(async(t,a)=>{let n=null;try{return c(e=>({...e,deletePaymentAccountFetchStatus:r.FetchStatus.DELETING,deletePaymentAccountError:null})),await m.Platform.PaymentAccountApi(o).deletePaymentAccount_ByUserId_ByType_ById(t,a.type,a.id),{data:!0}}catch(e){return n=r.WidgetErrorHelper.getErrorType(e),{error:n}}finally{c(e=>({...e,deletePaymentAccountError:n,deletePaymentAccountFetchStatus:r.FetchStatus.IDLE}))}},[o]),S=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(!d.isInIframe()){c(e=>({...e,paymentStationMessage:n}));return}window.parent.postMessage(n,a)},[]),P=u.useCallback(t=>{c(a=>({...a,paymentData:t}))},[]),E=u.useCallback(()=>{c(p)},[]);return{state:s,mutations:{getPaymentAccounts:l,deletePaymentAccount:i,setPaymentData:P,setPaymentStationMessage:S,resetState:E}}}exports.ChildUtils=d;exports.PAYMENT_STATION_ACTION=A;exports.usePayment=f;
