import{cO as B,dv as d,dw as Le,dx as Q,dy as V,dz as $,dq as c,dA as qe,dB as xe,dC as Ne,dD as We,dE as ke}from"./BC4hLSsA.js";import{B as h}from"./CcWg-pq4.js";import{g as Fe}from"./BnyoSkOr.js";import{u as Me}from"./CEx-2nn-.js";import{u as ze}from"./BLzfDeQN.js";const je=p=>{const{filter:t,chainId:J,itemsPerPageParam:X,query:Y}=p,{currentAzuroChain:y}=Me(J),P=B(()=>y.value.chain.graphql.bets),r=B(()=>X.value??100),Z={queryKey:["bets",P,r,t.bettor,B(()=>{var n;return(n=t.ids.value)==null?void 0:n.join("-")}),t.type,t.affiliate],queryFn:async({pageParam:n})=>{var q,x;const s={first:r.value,skip:r.value*(n-1),where:{}};t.type===h.Unredeemed&&(s.where.isRedeemable=!0,s.where.isCashedOut=!1),t.type===h.Accepted&&(s.where.status=d.Accepted,s.where.isCashedOut=!1),t.type===h.Settled&&(s.where.status_in=[d.Resolved,d.Canceled],s.where.isRedeemable=!1),t.type===h.CashedOut&&(s.where.isCashedOut=!0),t.bettor.value&&(s.where.actor=(q=t.bettor.value)==null?void 0:q.toLowerCase()),t.affiliate.value&&(s.where.affiliate=(x=t.affiliate.value)==null?void 0:x.toLowerCase()),t.ids.value&&(s.where.id_in=t.ids.value);const{v3Bets:l}=await Fe({url:P.value,document:ke,variables:s});if(!(l!=null&&l.length))return{bets:[],nextPage:void 0};const ee=l.reduce((o,{selections:i})=>(i.forEach(v=>{const{outcome:{condition:{gameId:b}}}=v;o.add(b)}),o),new Set),te=(await Le({chainId:y.value.chain.chain.id,gameIds:[...ee]})).reduce((o,i)=>(o[i.gameId]=i,o),{}),L=l.map(o=>{const{id:i,tokenId:v,actor:b,status:u,amount:C,odds:se,settledOdds:N,createdAt:ae,result:W,resolvedAt:k,affiliate:ne,selections:F,cashout:w,isCashedOut:M,payout:z,isRedeemed:oe,isRedeemable:ie,freebetId:G,isFreebetAmountReturnable:_,paymasterContractAddress:de,txHash:le,redeemedTxHash:ce,core:{address:D,liquidityPool:{address:re}}}=o,g=W===Q.Won,ue=W===Q.Lost,K=u===d.Canceled,me=(g||K)&&oe,fe=!!G,he=g&&z?+z:null,pe=fe&&_?C:0,ye=M?w==null?void 0:w.payout:void 0,E=F.length>1,I=[],ve=F.map(O=>{const{odds:m,result:a,conditionKind:f,outcome:{outcomeId:A,title:R,condition:{conditionId:we,status:T,title:S,gameId:ge,wonOutcomeIds:Ie}}}=O,e=te[ge],Oe=a?a===V.Won:null,Ae=a?a===V.Lost:null,U=!a&&(T===$.Canceled||(e==null?void 0:e.state)===c.Stopped||(e==null?void 0:e.state)===c.Canceled),j=u===d.Canceled&&!a&&T==$.Resolved,Re=!a&&((e==null?void 0:e.state)===c.Stopped||(e==null?void 0:e.state)===c.Canceled),Se=!a&&(e==null?void 0:e.state)===c.Stopped&&u===d.Accepted,Be=f===qe.Live;E&&!U&&I.push(+m);const Pe=S&&S!=="null"?S:xe({outcomeId:A});return{selectionName:R&&R!=="null"?R:Ne({outcomeId:A,withPoint:!0}),outcomeId:A,conditionId:we,coreAddress:D,odds:+m,marketName:Pe,wonOutcomeIds:Ie||null,game:e,isWin:Oe,isLose:Ae,isCanceled:U||j,isCancelledByAzuro:j,isCancelledBecauseGameStopped:Re,isMayBeUnCancelled:Se,isLive:Be}}).sort((O,m)=>{var a,f;return+(((a=O.game)==null?void 0:a.startsAt)||0)-+(((f=m.game)==null?void 0:f.startsAt)||0)}),H=E&&I.length?+We({odds:I,slippage:0}):N?+N:+se,be=+C*H-+pe,Ce=ie;return{actor:b,affiliate:ne,id:i,tokenId:v,freebetId:G||null,isFreebetAmountReturnable:_??null,paymaster:de||null,txHash:le,redeemedTxHash:ce,totalOdds:H,status:u,amount:C,possibleWin:be,payout:he,createdAt:+ae,resolvedAt:k?+k:null,cashout:ye,isWin:g,isLose:ue,isRedeemable:Ce,isRedeemed:me,isCanceled:K,isCashedOut:M,coreAddress:D,lpAddress:re,outcomes:ve,isLegacy:!1,chainId:y.value.chain.chain.id}});return{bets:L,nextPage:L.lengthn.nextPage??void 0,refetchOnMount:!1,refetchOnWindowFocus:!1,...Y||{}};return ze({...Z,clientOnly:p.clientOnly,serverOnly:p.serverOnly})};export{je as u};