@liberfi.io/ui-predict 0.1.46 → 0.1.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,3 +1,2 @@
1
- 'use strict';var react=require('react'),reactQuery=require('@tanstack/react-query'),i18n=require('@liberfi.io/i18n'),ui=require('@liberfi.io/ui'),jsxRuntime=require('react/jsx-runtime'),reactWindow=require('react-window'),reactWindowInfiniteLoader=require('react-window-infinite-loader'),hooks=require('@liberfi.io/hooks'),utils=require('@liberfi.io/utils'),walletConnector=require('@liberfi.io/wallet-connector'),mt=require('canvas-confetti'),react$1=require('@liberfi.io/react'),types=require('@liberfi.io/types'),recharts=require('recharts');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var mt__default=/*#__PURE__*/_interopDefault(mt);typeof window<"u"&&(window.__LIBERFI_VERSION__=window.__LIBERFI_VERSION__||{},window.__LIBERFI_VERSION__["@liberfi.io/ui-predict"]="0.1.46");var Wn="0.1.46";var ke=react.createContext({});function Ut(){let e=react.useContext(ke);if(!e)throw new Error("usePredictContext must be used within a PredictProvider");return e}function v(){let{client:e}=Ut();return e}function $n(e){return ["predict","events",e??{}]}async function tt(e,t){return await e.getEvents(t)}function Ul(e,t={}){let r=v();return reactQuery.useQuery({queryKey:$n(e),queryFn:async()=>tt(r,e),...t})}function zn(e){return ["predict","events","infinite",e??{}]}function At(e={},t={}){let r=v();return reactQuery.useInfiniteQuery({queryKey:zn(e),queryFn:async({pageParam:n})=>tt(r,{...e,...n!==void 0?{cursor:n}:{}}),initialPageParam:void 0,getNextPageParam:n=>n.cursor??void 0,...t})}function Yn(e){return ["predict","event","byId",e.id,e.withNestedMarkets]}async function jn(e,t){return await e.getEventById(t.id,t.withNestedMarkets)}function Le(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Yn(e),queryFn:async()=>jn(r,e),...t})}function Zn(e){return ["predict","markets",e??{}]}async function Jn(e,t){return await e.getMarkets(t)}function zl(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Zn(e),queryFn:async()=>Jn(r,e),...t})}function ts(e){return ["predict","market","byId",e.id]}async function rs(e,t){return await e.getMarketById(t.id)}function Xl(e,t={}){let r=v();return reactQuery.useQuery({queryKey:ts(e),queryFn:async()=>rs(r,e),...t})}function ss(e){return ["predict","market","byMint",e]}async function os(e,t){return await e.getMarketByMint(t)}function tc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:ss(e),queryFn:async()=>os(r,e),...t})}function is(e){return ["predict","markets","batch",e]}async function ls(e,t){return await e.getMarketsBatch(t)}function oc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:is(e),queryFn:async()=>ls(r,e),enabled:!!(e.tickers?.length||e.mints?.length),...t})}function cs(e){return ["predict","orderBook",e]}async function us(e,t){return await e.getOrderbook(t)}function he(e,t={}){let r=v();return reactQuery.useQuery({queryKey:cs(e),queryFn:async()=>us(r,e),...t})}function ds(e){return ["predict","orderBook","byMint",e]}async function ps(e,t){return await e.getOrderbookByMint(t)}function cc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:ds(e),queryFn:async()=>ps(r,e),...t})}function ms(e){return ["predict","trades",e??{}]}async function ys(e,t){return await e.getTrades(t)}function Ft(e,t={}){let r=v();return reactQuery.useQuery({queryKey:ms(e),queryFn:async()=>ys(r,e),...t})}function fs(e){return ["predict","trades","byMint",e]}async function gs(e,t){return await e.getTradesByMint(t)}function mc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:fs(e),queryFn:async()=>gs(r,e),...t})}function xs(e){return ["predict","candlesticks","event",e]}async function bs(e,t){let{ticker:r,...n}=t;return await e.getEventCandlesticks(r,n)}function xc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:xs(e),queryFn:async()=>bs(r,e),...t})}function nt(e){return ["predict","candlesticks","market",e]}async function st(e,t){let{ticker:r,...n}=t;return await e.getMarketCandlesticks(r,n)}function ot(e,t={}){let r=v();return reactQuery.useQuery({queryKey:nt(e),queryFn:async()=>st(r,e),...t})}function vs(e){return ["predict","candlesticks","market","byMint",e]}async function ks(e,t){let{mintAddress:r,...n}=t;return await e.getMarketCandlesticksByMint(r,n)}function bc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:vs(e),queryFn:async()=>ks(r,e),...t})}var vc=ot;function hs(e){return ["predict","forecast","percentileHistory",e]}async function Ps(e,t){return await e.getEventForecastPercentileHistory(t)}function Cc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:hs(e),queryFn:async()=>Ps(r,e),...t})}function Cs(e){return ["predict","forecast","percentileHistory","byMint",e]}async function Ss(e,t){return await e.getEventForecastPercentileHistoryByMint(t)}function Sc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Cs(e),queryFn:async()=>Ss(r,e),...t})}function ws(e){return ["predict","liveData",e]}async function Rs(e,t){return await e.getLiveData(t)}function Tc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:ws(e),queryFn:async()=>Rs(r,e),enabled:e.milestoneIds.length>0,...t})}function Ms(e){return ["predict","liveData","byEvent",e]}async function Ts(e,t){return await e.getLiveDataByEvent(t)}function Nc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Ms(e),queryFn:async()=>Ts(r,e),enabled:!!e.eventTicker,...t})}function Ns(e){return ["predict","liveData","byMint",e]}async function Es(e,t){return await e.getLiveDataByMint(t)}function Ec(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Ns(e),queryFn:async()=>Es(r,e),enabled:!!e.mintAddress,...t})}function Os(e){return ["predict","series",e??{}]}async function Is(e,t){return await e.getSeries(t)}function Ht(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Os(e),queryFn:async()=>Is(r,e),...t})}function Qs(e){return ["predict","series","byTicker",e]}async function Bs(e,t){return await e.getSeriesByTicker(t)}function Kt(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Qs(e),queryFn:async()=>Bs(r,e),...t})}function Ls(){return ["predict","tags","byCategories"]}async function Us(e){return await e.getTagsByCategories()}function it(e={}){let t=v();return reactQuery.useQuery({queryKey:Ls(),queryFn:async()=>Us(t),...e})}function As(){return ["predict","filters","bySports"]}async function Ds(e){return await e.getFiltersBySports()}function Ac(e={}){let t=v();return reactQuery.useQuery({queryKey:As(),queryFn:async()=>Ds(t),...e})}var Dc=it;function Fs(e){return ["predict","search",e]}async function Ws(e,t){return await e.search(t)}function qc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Fs(e),queryFn:async()=>Ws(r,e),...t})}function Ks(e){return ["predict","outcomeMints",e??{}]}async function $s(e,t){return await e.getOutcomeMints(t)}function Vc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Ks(e),queryFn:async()=>$s(r,e),...t})}async function Vs(e,t){return await e.filterOutcomeMints(t)}function zc(e={}){let t=v();return reactQuery.useMutation({mutationFn:async r=>Vs(t,r),...e})}function Gs(e){return ["predict","quote",e]}async function Ys(e,t){return await e.getQuote(t)}function Xc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Gs(e),queryFn:async()=>Ys(r,e),enabled:!!(e.inputMint&&e.outputMint&&e.amount>0),staleTime:1e4,gcTime:3e4,...t})}async function js(e,t){return await e.createSwap(t)}function tu(e={}){let t=v();return reactQuery.useMutation({mutationFn:async r=>js(t,r),...e})}async function Xs(e,t){return await e.createSwapInstructions(t)}function ru(e={}){let t=v();return reactQuery.useMutation({mutationFn:async r=>Xs(t,r),...e})}function Zs(e){return ["predict","order",e]}async function Js(e,t){return await e.getOrder(t)}function Gt(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Zs(e),queryFn:async()=>Js(r,e),enabled:!!(e.inputMint&&e.outputMint&&e.amount>0),staleTime:1e4,gcTime:3e4,...t})}function eo(e){return ["predict","order","status",e.signature]}async function to(e,t){return await e.getOrderStatus(t)}function au(e,t={}){let r=v();return reactQuery.useQuery({queryKey:eo(e),queryFn:async()=>to(r,e),enabled:!!e.signature,refetchInterval:t.refetchInterval??3e3,...t})}function so(e){return ["predict","intent","quote",e]}async function oo(e,t){return await e.getIntentQuote(t)}function uu(e,t={}){let r=v();return reactQuery.useQuery({queryKey:so(e),queryFn:async()=>oo(r,e),enabled:!!(e.inputMint&&e.outputMint&&e.amount>0),staleTime:1e4,gcTime:3e4,...t})}async function ao(e,t){return await e.submitIntentSwap(t)}function du(e={}){let t=v();return reactQuery.useMutation({mutationFn:async r=>ao(t,r),...e})}async function lo(e,t){return await e.initPredictionMarket(t)}function fu(e={}){let t=v();return reactQuery.useMutation({mutationFn:async r=>lo(t,r),...e})}function co(){return ["predict","tokens"]}async function uo(e){return await e.getTokens()}function vu(e={}){let t=v();return reactQuery.useQuery({queryKey:co(),queryFn:async()=>uo(t),staleTime:300*1e3,gcTime:1800*1e3,...e})}function po(){return ["predict","tokens","decimals"]}async function mo(e){return await e.getTokensWithDecimals()}function ku(e={}){let t=v();return reactQuery.useQuery({queryKey:po(),queryFn:async()=>mo(t),staleTime:300*1e3,gcTime:1800*1e3,...e})}function fo(){return ["predict","venues"]}async function go(e){return await e.getVenues()}function Su(e={}){let t=v();return reactQuery.useQuery({queryKey:fo(),queryFn:async()=>go(t),staleTime:300*1e3,gcTime:1800*1e3,...e})}var Me=class{ws=null;wsUrl;autoReconnect;reconnectIntervalBase;reconnectMaxInterval;pingInterval;status="disconnected";reconnectAttempts=0;reconnectTimeout=null;pingIntervalId=null;shouldReconnect=true;listeners={connect:[],disconnect:[],reconnecting:[],error:[],price:[],trade:[],orderbook:[],status:[],subscribed:[],unsubscribed:[]};subscriptions={prices:{all:false,tickers:new Set},trades:{all:false,tickers:new Set},orderbook:{all:false,tickers:new Set}};constructor(t){this.wsUrl=t.wsUrl,this.autoReconnect=t.autoReconnect??true,this.reconnectIntervalBase=t.reconnectIntervalBase??1e3,this.reconnectMaxInterval=t.reconnectMaxInterval??3e4,this.pingInterval=t.pingInterval??3e4,t.autoConnect!==false&&this.connect();}connect(){if(!(this.ws&&(this.ws.readyState===WebSocket.OPEN||this.ws.readyState===WebSocket.CONNECTING))){this.shouldReconnect=true,this.setStatus("connecting");try{this.ws=new WebSocket(this.wsUrl),this.ws.onopen=()=>{this.reconnectAttempts=0,this.setStatus("connected"),this.emit("connect",void 0),this.restoreSubscriptions(),this.startPingInterval();},this.ws.onmessage=t=>{this.handleMessage(t.data);},this.ws.onerror=t=>{let r=new Error("WebSocket error");this.emit("error",r);},this.ws.onclose=t=>{this.stopPingInterval(),this.setStatus("disconnected"),this.emit("disconnect",{code:t.code,reason:t.reason}),this.shouldReconnect&&this.autoReconnect&&this.scheduleReconnect();};}catch(t){this.emit("error",t instanceof Error?t:new Error(String(t))),this.shouldReconnect&&this.autoReconnect&&this.scheduleReconnect();}}}disconnect(){this.shouldReconnect=false,this.stopPingInterval(),this.reconnectTimeout&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=null),this.ws&&(this.ws.close(),this.ws=null),this.setStatus("disconnected");}isConnected(){return this.ws!==null&&this.ws.readyState===WebSocket.OPEN}getStatus(){return this.status}subscribePrices(t,r){this.subscribeChannel("prices",t);let n=this.on("price",r);return ()=>{n(),this.unsubscribeChannel("prices",t);}}subscribeTrades(t,r){this.subscribeChannel("trades",t);let n=this.on("trade",r);return ()=>{n(),this.unsubscribeChannel("trades",t);}}subscribeOrderbook(t,r){this.subscribeChannel("orderbook",t);let n=this.on("orderbook",r);return ()=>{n(),this.unsubscribeChannel("orderbook",t);}}onStatusChange(t){return this.on("status",t)}on(t,r){return this.listeners[t].push(r),()=>{this.off(t,r);}}off(t,r){let n=this.listeners[t],s=n.indexOf(r);s!==-1&&n.splice(s,1);}removeAllListeners(t){if(t)this.listeners[t].length=0;else for(let r of Object.keys(this.listeners))this.listeners[r].length=0;}subscribeChannel(t,r){let n=this.subscriptions[t];if(r.all)n.all=true,n.tickers.clear();else if(r.tickers&&r.tickers.length>0){n.all=false;for(let s of r.tickers)n.tickers.add(s);}this.sendSubscription("subscribe",t,r);}unsubscribeChannel(t,r){let n=this.subscriptions[t];if(r.all)n.all=false,n.tickers.clear();else if(r.tickers&&r.tickers.length>0)for(let s of r.tickers)n.tickers.delete(s);this.sendSubscription("unsubscribe",t,r);}setStatus(t){this.status!==t&&(this.status=t,this.emit("status",t));}emit(t,r){let n=this.listeners[t];for(let s of n)try{s(r);}catch{}}send(t){if(!this.ws||this.ws.readyState!==WebSocket.OPEN)return false;try{return this.ws.send(JSON.stringify(t)),!0}catch{return false}}sendSubscription(t,r,n){this.send({type:t,channel:r,all:n.all,tickers:n.tickers});}handleMessage(t){try{let r=JSON.parse(t);switch(r.type){case "ticker":this.emit("price",r);break;case "trade":this.emit("trade",r);break;case "orderbook":this.emit("orderbook",r);break;case "status":break;case "subscribed":this.emit("subscribed",{channel:r.channel,all:r.all,tickers:r.tickers});break;case "unsubscribed":this.emit("unsubscribed",{channel:r.channel,all:r.all,tickers:r.tickers});break;case "pong":break;case "error":this.emit("error",new Error(r.message));break;default:if("channel"in r){let n=r;switch(n.channel){case "prices":this.emit("price",n);break;case "trades":this.emit("trade",n);break;case "orderbook":this.emit("orderbook",n);break}}}}catch{}}scheduleReconnect(){if(this.reconnectTimeout)return;let t=Math.min(this.reconnectIntervalBase*Math.pow(2,this.reconnectAttempts),this.reconnectMaxInterval);this.setStatus("reconnecting"),this.emit("reconnecting",{attempt:this.reconnectAttempts+1,delay:t}),this.reconnectTimeout=setTimeout(()=>{this.reconnectTimeout=null,this.reconnectAttempts++,this.connect();},t);}restoreSubscriptions(){for(let t of ["prices","trades","orderbook"]){let r=this.subscriptions[t];r.all?this.sendSubscription("subscribe",t,{all:true}):r.tickers.size>0&&this.sendSubscription("subscribe",t,{tickers:Array.from(r.tickers)});}}startPingInterval(){this.stopPingInterval(),this.pingIntervalId=setInterval(()=>{this.send({type:"ping"});},this.pingInterval);}stopPingInterval(){this.pingIntervalId&&(clearInterval(this.pingIntervalId),this.pingIntervalId=null);}};function Ue(e){return new Me(e)}function Eu({wsEndpoint:e,autoConnect:t=true,autoReconnect:r=true,enabled:n=true}){let[s,i]=react.useState("disconnected"),[o,l]=react.useState(null),a=react.useRef(null);react.useEffect(()=>{if(!n){a.current&&(a.current.disconnect(),a.current=null),i("disconnected");return}let p=Ue({wsUrl:e,autoConnect:t,autoReconnect:r});a.current=p;let f=p.on("status",x=>{i(x);}),c=p.on("error",x=>{l(x);}),b=p.on("connect",()=>{l(null);});return ()=>{f(),c(),b(),p.disconnect(),a.current=null;}},[e,t,r,n]);let u=react.useCallback(()=>{a.current?.connect();},[]),d=react.useCallback(()=>{a.current?.disconnect();},[]);return {client:a.current,status:s,isConnected:s==="connected",connect:u,disconnect:d,error:o}}function Bu(){let e=react.useContext(ke);if(!e)throw new Error("useWsClient must be used within a PredictProvider");let{wsClient:t}=e,[r,n]=react.useState(t?.getStatus()??"disconnected");return react.useEffect(()=>{if(!t){n("disconnected");return}return n(t.getStatus()),t.onStatusChange(n)},[t]),{wsClient:t,wsStatus:r,isWsConnected:r==="connected"}}function Au({client:e,all:t=false,tickers:r=[],enabled:n=true,onUpdate:s}){let[i,o]=react.useState(new Map),[l,a]=react.useState(false),u=react.useRef(s);return react.useEffect(()=>{u.current=s;},[s]),react.useEffect(()=>{if(!e||!n){a(false);return}if(!t&&r.length===0)return;let d=t?{all:true}:{tickers:r},m=e.subscribePrices(d,p=>{o(f=>{let c=new Map(f);return c.set(p.market_ticker,{yesBid:p.yes_bid,yesAsk:p.yes_ask,noBid:p.no_bid,noAsk:p.no_ask,updatedAt:Date.now()}),c}),u.current?.(p);});return a(true),()=>{m(),a(false);}},[e,t,r.join(","),n]),{prices:i,isSubscribed:l}}function Fu({client:e,all:t=false,tickers:r=[],enabled:n=true,maxHistory:s=100,onUpdate:i}){let[o,l]=react.useState([]),[a,u]=react.useState(false),d=react.useRef(i);react.useEffect(()=>{d.current=i;},[i]),react.useEffect(()=>{if(!e||!n){u(false);return}if(!t&&r.length===0)return;let p=t?{all:true}:{tickers:r},f=e.subscribeTrades(p,c=>{let b={tradeId:c.trade_id,marketTicker:c.market_ticker,price:c.price,count:c.count,yesPrice:c.yes_price,noPrice:c.no_price,takerSide:c.taker_side,createdTime:c.created_time};l(x=>{let g=[b,...x];return g.length>s?g.slice(0,s):g}),d.current?.(c);});return u(true),()=>{f(),u(false);}},[e,t,r.join(","),n,s]);let m=react.useCallback(()=>{l([]);},[]);return {trades:o,isSubscribed:a,clearHistory:m}}function Hu({client:e,all:t=false,tickers:r=[],enabled:n=true,onUpdate:s}){let[i,o]=react.useState(new Map),[l,a]=react.useState(false),u=react.useRef(s);react.useEffect(()=>{u.current=s;},[s]),react.useEffect(()=>{if(!e||!n){a(false);return}if(!t&&r.length===0)return;let m=t?{all:true}:{tickers:r},p=e.subscribeOrderbook(m,f=>{o(c=>{let b=new Map(c);return b.set(f.market_ticker,{yesBids:f.yes_bids,yesAsks:f.yes_asks,noBids:f.no_bids,noAsks:f.no_asks,updatedAt:Date.now()}),b}),u.current?.(f);});return a(true),()=>{p(),a(false);}},[e,t,r.join(","),n]);let d=react.useCallback(m=>i.get(m),[i]);return {orderbooks:i,isSubscribed:l,getOrderbook:d}}var sr=["Politics","Sports","Culture","Crypto","Climate","Economics","Mentions","Companies","Financials","Tech & Science"];function or(){let{data:e,isLoading:t,isError:r,error:n}=it();return {data:react.useMemo(()=>{if(!e?.tagsByCategories)return [];let i=o=>{let l=sr.indexOf(o);return l===-1?sr.length:l};return Object.entries(e.tagsByCategories).map(([o,l])=>({category:o,tags:l})).sort((o,l)=>i(o.category)-i(l.category))},[e]),isLoading:t,isError:r,error:n??null}}function lr({categories:e,selectedCategory:t,selectedTag:r,activeTags:n,onCategorySelect:s,onTagSelect:i,className:o}){let{t:l}=i18n.useTranslation(),a=react.useCallback(()=>{s(null);},[s]);return jsxRuntime.jsxs("div",{className:ui.cn("flex w-full flex-col gap-2",o),children:[jsxRuntime.jsx(ui.HorizontalScrollContainer,{children:jsxRuntime.jsxs("div",{className:"flex items-center gap-2 px-0.5 py-1",children:[jsxRuntime.jsx(Ae,{label:l("predict.categories.trending"),isSelected:t===null,onPress:a}),e.map(u=>jsxRuntime.jsx(Ae,{label:u.category,isSelected:t===u.category,onPress:()=>s(u.category)},u.category))]})}),t&&n.length>0&&jsxRuntime.jsx(ui.HorizontalScrollContainer,{children:jsxRuntime.jsxs("div",{className:"flex items-center gap-2 px-0.5 py-1",children:[jsxRuntime.jsx(Ae,{label:l("predict.categories.allMarkets"),isSelected:r===null,onPress:()=>i(null),variant:"secondary"}),n.map(u=>jsxRuntime.jsx(Ae,{label:u,isSelected:r===u,onPress:()=>i(u),variant:"secondary"},u))]})})]})}function Ae({label:e,isSelected:t,onPress:r,variant:n="primary"}){return jsxRuntime.jsx("button",{type:"button",onClick:r,className:ui.cn("shrink-0 rounded-full px-3 py-1.5 text-xs font-medium transition-colors duration-150 cursor-pointer","border whitespace-nowrap",n==="primary"?t?"bg-foreground text-background border-foreground":"bg-content1 text-foreground/70 border-default-200 hover:bg-default-100 hover:text-foreground":t?"bg-primary/15 text-primary border-primary/40":"bg-content1 text-foreground/50 border-default-100 hover:bg-default-50 hover:text-foreground/70"),children:e})}function cr({count:e=6}){return jsxRuntime.jsx("div",{className:"flex items-center gap-2 px-0.5 py-1",children:Array.from({length:e}).map((t,r)=>jsxRuntime.jsx(ui.Skeleton,{className:"h-8 shrink-0 rounded-full",style:{width:`${60+Math.random()*40}px`}},r))})}function mr({onSelect:e,className:t}){let{data:r,isLoading:n}=or(),[s,i]=react.useState(null),[o,l]=react.useState(null),a=react.useCallback(m=>{if(i(m),l(null),!m)e?.({category:null,tags:null});else {let p=r.find(f=>f.category===m);e?.({category:m,tags:p?.tags??null});}},[r,e]),u=react.useCallback(m=>{if(l(m),m)e?.({category:s,tags:[m]});else {let p=r.find(f=>f.category===s);e?.({category:s,tags:p?.tags??null});}},[r,s,e]);if(n)return jsxRuntime.jsx(cr,{});let d=r.find(m=>m.category===s)?.tags??[];return jsxRuntime.jsx(lr,{categories:r,selectedCategory:s,selectedTag:o,activeTags:d,onCategorySelect:a,onTagSelect:u,className:t})}var fe=48,le=4,De={ONE_MINUTE:1,ONE_HOUR:60,ONE_DAY:1440},w={ONE_DAY:"1d",ONE_WEEK:"1w",ONE_MONTH:"1m",ALL:"all"},ce=w.ALL,_e={[w.ONE_DAY]:De.ONE_MINUTE,[w.ONE_WEEK]:De.ONE_HOUR,[w.ONE_MONTH]:De.ONE_HOUR,[w.ALL]:De.ONE_DAY},Fe={[w.ONE_DAY]:300,[w.ONE_WEEK]:3600,[w.ONE_MONTH]:10800,[w.ALL]:1440*60},We={[w.ONE_DAY]:1440*60,[w.ONE_WEEK]:10080*60,[w.ONE_MONTH]:720*60*60,[w.ALL]:null},ct=1,Ld=1,Ud=1,Ad=99,Pe={ONE_HOUR:"1h",SIX_HOURS:"6h",ONE_DAY:"1d",ONE_WEEK:"1w",MAX:"max"},Dd=Pe.ONE_WEEK,_d={[Pe.ONE_HOUR]:60,[Pe.SIX_HOURS]:60,[Pe.ONE_DAY]:300,[Pe.ONE_WEEK]:1800,[Pe.MAX]:1800};function yr(e={}){let{category:t,tags:r,...n}=e,s=!!t||!!r&&r.length>0,{data:i,isFetching:o,isError:l,error:a}=Ht({...t?{category:t}:{},...r&&r.length>0?{tags:r.join(",")}:{},isInitialized:true,status:"active"},{enabled:s}),u=react.useMemo(()=>{if(!s||!i?.series)return;let j=i.series.map(C=>C.ticker).slice(0,25);return j.length>0?j.join(","):void 0},[s,i]),d=react.useMemo(()=>({status:"active",withNestedMarkets:true,sort:"volume24h",order:"desc",limit:48,...n,...u!==void 0?{seriesTickers:u}:{}}),[n,u]),{data:m,isLoading:p,isFetching:f,isFetchingNextPage:c,isError:b,error:x,hasNextPage:g,fetchNextPage:k,refetch:h}=At(d),y=react.useMemo(()=>m?.pages.flatMap(j=>j.events)??[],[m]),P=s&&!i&&!l;return {data:y,isLoading:P||p,isFetching:o||P||f&&!c,isFetchingMore:c,isError:l||b,error:a??x,hasMore:g,fetchMore:k,refetch:h}}function Oo({className:e}){return jsxRuntime.jsxs("div",{className:`flex h-full w-full flex-col justify-between gap-y-1.5 rounded-xl border border-border bg-content1 p-3 @5xl:gap-y-3 @5xl:p-4 ${e??""}`,children:[jsxRuntime.jsxs("div",{className:"flex w-full flex-1 flex-col gap-y-1.5 @5xl:gap-y-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-4",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-8 w-8 flex-shrink-0 rounded-lg @5xl:h-12 @5xl:w-12"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-10 flex-1 rounded-md @5xl:h-12"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-8 w-12 flex-shrink-0 rounded-lg @5xl:h-10 @5xl:w-14"})]}),jsxRuntime.jsxs("div",{className:"flex w-full flex-col gap-y-0.5 @5xl:gap-y-1",children:[jsxRuntime.jsxs("div",{className:"flex min-h-8 w-full items-center justify-between gap-x-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-2/3 rounded-md"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-8 rounded-md"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-6 w-16 rounded-lg"})]})]}),jsxRuntime.jsxs("div",{className:"flex min-h-8 w-full items-center justify-between gap-x-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-1/2 rounded-md"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-8 rounded-md"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-6 w-16 rounded-lg"})]})]})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between gap-x-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-3 w-16 rounded-md @5xl:h-4"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-3 w-20 rounded-md @5xl:h-4"})]})]})}function fr({count:e=8}){return jsxRuntime.jsx("div",{className:"@container w-full h-full",children:jsxRuntime.jsx("div",{className:"grid grid-cols-1 gap-4 @[640px]:grid-cols-2 @[1024px]:grid-cols-3 @[1280px]:grid-cols-4",children:Array.from({length:e}).map((t,r)=>jsxRuntime.jsx(Oo,{className:"min-h-44 @5xl:min-h-56"},r))})})}function gr({value:e,showLabel:t=true}){let r=e/100;return jsxRuntime.jsx("div",{className:"flex-shrink-0 flex flex-col items-center",children:jsxRuntime.jsxs("div",{className:"relative w-16 h-12 lg:w-20 lg:h-14",children:[jsxRuntime.jsxs("svg",{className:"w-full h-full",viewBox:"0 0 100 70",children:[jsxRuntime.jsx("path",{d:"M 10 55 A 40 40 0 0 1 90 55",fill:"none",className:"stroke-default-200",strokeWidth:"6",strokeLinecap:"round"}),jsxRuntime.jsx("path",{d:"M 10 55 A 40 40 0 0 1 90 55",fill:"none",className:"stroke-primary",strokeWidth:"6",strokeLinecap:"round",strokeDasharray:`${r*125.6} 125.6`,style:{transition:"stroke-dasharray 0.5s ease-in-out"}})]}),t&&jsxRuntime.jsx("div",{className:"absolute inset-0 flex items-center justify-center pt-3 lg:pt-4",children:jsxRuntime.jsxs("span",{className:"text-sm font-bold text-foreground lg:text-base leading-none",children:[e.toFixed(0),"%"]})})]})})}function vr({event:e,onSelect:t,onSelectOutcome:r}){let{t:n}=i18n.useTranslation(),[s,i]=react.useState(null),o=e.markets||[],l=o.length>2?[...o].sort((C,Q)=>Number(Q.yesAsk??0)-Number(C.yesAsk??0)):o,a=l.filter(C=>C.status==="active"),u=l.length===1,d=u?l[0]:s,m=react.useMemo(()=>utils.formatAmountUSDCompact((e.volume??0)/100),[e.volume]),p=C=>C.yesAsk?parseFloat(C.yesAsk)*100:null,f=C=>C.noAsk?parseFloat(C.noAsk)*100:null,c=C=>{let Q=p(C),O=f(C);return Q!=null?O==null&&Q<=1?"< 1%":x(Q):O!=null?O<=1?"> 99%":x(100-O):"0%"},b=C=>{let Q=p(C),O=f(C);return O!=null?Q==null&&O<=1?"< 1%":x(O):Q!=null?Q<=1?"> 99%":x(100-Q):"0%"},x=C=>C!=null?`${C.toFixed(0)}%`:"--",g=react.useMemo(()=>{let C=l.some(O=>O.status==="active");return l.every(O=>O.status==="closed"||O.status==="determined")?{label:n("predict.event.status.closed"),color:"bg-danger-100/50 text-danger"}:C?{label:n("predict.event.status.live"),color:"bg-primary-100/50 text-primary"}:{label:n("predict.event.status.pending"),color:"bg-warning-100/50 text-warning"}},[l,n]),k=C=>{i(C);},h=()=>{i(null);},y=()=>{d&&r&&r(e,d,"yes");},P=()=>{d&&r&&r(e,d,"no");},T=()=>{t&&t(e);},U=a.slice(0,2),j=a.length>2;return jsxRuntime.jsxs("div",{className:"flex h-full w-full flex-col justify-between gap-y-1.5 rounded-xl border border-border bg-content1 p-3 transition-all duration-300 cursor-pointer hover:border-primary hover:ring-2 hover:ring-primary/20 focus-within:border-primary focus-within:bg-content2 focus-within:ring-2 focus-within:ring-primary/20 @5xl:gap-y-3 @5xl:p-4",onClick:T,children:[jsxRuntime.jsxs("div",{className:"flex w-full flex-1 flex-col gap-y-1.5 @5xl:gap-y-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-4",children:[jsxRuntime.jsx(ui.Avatar,{src:e.imageUrl||void 0,name:e.title||"Event",radius:"md",className:"h-8 w-8 flex-shrink-0 transition-transform duration-300 group-hover:scale-110 @5xl:h-12 @5xl:w-12"}),jsxRuntime.jsx(ui.StyledTooltip,{content:e.title,placement:"bottom",children:jsxRuntime.jsx("p",{className:"flex-1 min-w-0 h-10 @5xl:h-12 text-sm font-semibold @5xl:text-base line-clamp-2",children:e.title})}),u?jsxRuntime.jsx(gr,{value:p(l[0])??50}):g.label!==n("predict.event.status.live")&&jsxRuntime.jsx("div",{className:`flex-shrink-0 flex items-center gap-x-2 rounded-lg px-2 py-1 text-sm @5xl:px-4 @5xl:py-2 ${g.color}`,children:jsxRuntime.jsx("span",{children:g.label})})]}),d&&!u&&jsxRuntime.jsxs("button",{type:"button",className:"flex min-h-9 w-full items-center justify-between gap-x-2 transition-opacity hover:cursor-pointer hover:opacity-80",onClick:C=>{C.stopPropagation(),h();},children:[jsxRuntime.jsx("span",{className:"text-left text-xs text-foreground @5xl:text-sm line-clamp-1",children:d.yesSubTitle}),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2",children:[jsxRuntime.jsx("span",{className:"text-sm font-semibold text-foreground @5xl:text-lg",children:c(d)}),jsxRuntime.jsx(ui.ChevronUpIcon,{className:"w-3 h-3 text-default-500 @5xl:w-4 @5xl:h-4"})]})]}),!d&&!u&&U.length>0&&jsxRuntime.jsxs("div",{className:"flex w-full flex-col gap-y-0.5 text-xs @5xl:gap-y-1 @5xl:text-sm",children:[U.map(C=>jsxRuntime.jsxs("button",{type:"button",className:"flex min-h-8 w-full items-center justify-between gap-x-2 transition-opacity hover:cursor-pointer hover:opacity-80",onClick:Q=>{Q.stopPropagation(),k(C);},children:[jsxRuntime.jsx("span",{className:"text-left text-xs text-foreground @5xl:text-sm line-clamp-1",children:C.yesSubTitle}),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2",children:[jsxRuntime.jsx("span",{className:"text-xs text-foreground @5xl:text-base",children:c(C)}),jsxRuntime.jsxs("div",{className:"flex h-full items-center gap-x-3 rounded-lg p-1 @5xl:p-1.5 bg-gradient-to-r from-primary-50/20 via-primary-50/20 to-secondary-50/20",children:[jsxRuntime.jsx("span",{className:"text-primary",children:n("predict.market.yes")}),jsxRuntime.jsx("span",{className:"text-default-400",children:"/"}),jsxRuntime.jsx("span",{className:"text-secondary",children:n("predict.market.no")})]})]})]},C.ticker)),j&&jsxRuntime.jsx("span",{className:"text-xxs text-default-500 @5xl:text-xs",children:n("predict.event.moreMarkets",{count:a.length-2})})]}),d&&jsxRuntime.jsxs("div",{className:`flex items-center gap-x-2 text-sm @5xl:text-base ${u?"mt-3":""}`,children:[jsxRuntime.jsxs(ui.Button,{color:"primary",fullWidth:true,className:"group/yes bg-primary-100 text-primary @3xl:!h-12 @3xl:!text-base",size:"sm",onPress:y,children:[jsxRuntime.jsx("span",{className:"group-hover/yes:hidden",children:n("predict.market.yes")}),jsxRuntime.jsx("span",{className:"hidden group-hover/yes:inline",children:c(d)})]}),jsxRuntime.jsxs(ui.Button,{color:"secondary",fullWidth:true,className:"group/no bg-secondary-100 text-secondary @3xl:!h-12 @3xl:!text-base",size:"sm",onPress:P,children:[jsxRuntime.jsx("span",{className:"group-hover/no:hidden",children:n("predict.market.no")}),jsxRuntime.jsx("span",{className:"hidden group-hover/no:inline",children:b(d)})]})]})]}),!d||u?jsxRuntime.jsxs("div",{className:"flex items-center justify-between gap-x-2",children:[jsxRuntime.jsxs("button",{type:"button",className:"flex items-center gap-x-1 text-xxs text-default-600 hover:text-foreground @5xl:text-xs",onClick:C=>{C.stopPropagation(),T();},children:[jsxRuntime.jsx("span",{children:n("predict.event.showMore")}),jsxRuntime.jsx(ui.ChevronRightIcon,{className:"h-3 w-3 @5xl:h-4 @5xl:w-4"})]}),jsxRuntime.jsxs("span",{className:"text-xxs text-default-600 @5xl:text-xs",children:[m," ",n("predict.event.volume")]})]}):jsxRuntime.jsxs("button",{type:"button",className:"flex items-center cursor-pointer gap-x-1 text-xxs text-default-600 hover:text-foreground @5xl:text-xs",onClick:C=>{C.stopPropagation(),h();},children:[jsxRuntime.jsx(ui.ChevronLeftIcon,{className:"h-3 w-3 @5xl:h-4 @5xl:w-4"}),jsxRuntime.jsx("span",{children:n("predict.event.back")})]})]})}var $o=640,Vo=768,hr=1024,zo=1280,Go=16,Yo=192,jo=228,Xo=244;function Zo(e){return e>=zo?4:e>=hr?3:e>=$o?2:1}function Jo(e){return e>=hr?Xo:e>=Vo?jo:Yo}function Pr({events:e,hasMore:t=false,onFetchMore:r,onSelect:n,onSelectOutcome:s}){let i=react.useRef(null),{width:o=0,height:l=0}=hooks.useResizeObserver({ref:i}),a=Zo(o),u=Jo(o),d=Math.ceil(e.length/a)||0,m=t?d+1:d,p=react.useCallback(b=>b<d,[d]),f=react.useCallback(async()=>{r?.();},[r]),c=reactWindowInfiniteLoader.useInfiniteLoader({isRowLoaded:p,loadMoreRows:f,rowCount:m,threshold:3});return jsxRuntime.jsx("div",{ref:i,className:"@container w-full h-full",children:l>0&&jsxRuntime.jsx(reactWindow.List,{style:{height:l},onRowsRendered:c,rowComponent:ea,rowCount:m,rowHeight:u,rowProps:{events:e,columnCount:a,dataRowCount:d,gap:Go,onSelect:n,onSelectOutcome:s}})})}function ea({index:e,style:t,events:r,columnCount:n,dataRowCount:s,gap:i,onSelect:o,onSelectOutcome:l}){if(e>=s)return jsxRuntime.jsx("div",{style:t,className:"flex justify-center items-start pt-4",children:jsxRuntime.jsx(ui.Spinner,{size:"sm"})});let a=e*n,u=r.slice(a,a+n),d=n-u.length,m={display:"flex",gap:i,height:`calc(100% - ${i}px)`};return jsxRuntime.jsx("div",{style:t,children:jsxRuntime.jsxs("div",{style:m,children:[u.map(p=>jsxRuntime.jsx("div",{style:{flex:1,minWidth:0},children:jsxRuntime.jsx(vr,{event:p,onSelect:o,onSelectOutcome:l})},p.ticker)),d>0&&Array.from({length:d}).map((p,f)=>jsxRuntime.jsx("div",{style:{flex:1,minWidth:0}},`spacer-${f}`))]})})}function Sr({onSelect:e,onSelectOutcome:t,...r}){let{data:n,hasMore:s,fetchMore:i,isFetching:o}=yr({limit:48,...r});return o?jsxRuntime.jsx(fr,{count:48}):jsxRuntime.jsx(Pr,{events:n,hasMore:s,onFetchMore:i,onSelect:e,onSelectOutcome:t})}function kp({onSelect:e,onSelectOutcome:t}){let[r,n]=react.useState({category:null,tags:null}),s=react.useCallback(i=>{n(i);},[]);return jsxRuntime.jsxs("div",{className:"flex h-full w-full flex-col gap-y-3",children:[jsxRuntime.jsx(mr,{onSelect:s}),jsxRuntime.jsx("div",{className:"min-h-0 flex-1",children:jsxRuntime.jsx(Sr,{category:r.category,tags:r.tags,onSelect:e,onSelectOutcome:t})})]})}function yt(e,t,r){let n=e[t];return n?r==="yes"?n.yesMint:n.noMint:null}var Ce=utils.SOLANA_TOKENS.stablecoins.USDC.address;function ma(){let e={startVelocity:30,spread:360,ticks:60,zIndex:9999};mt__default.default({...e,particleCount:80,origin:{x:.5,y:.4}}),setTimeout(()=>{mt__default.default({...e,particleCount:40,origin:{x:.3,y:.6}});},150),setTimeout(()=>{mt__default.default({...e,particleCount:40,origin:{x:.7,y:.6}});},300);}function Rr({market:e,chain:t="solana",initialOutcome:r="yes",initialSide:n="buy"}){let{t:s}=i18n.useTranslation(),{status:i}=walletConnector.useAuth(),l=walletConnector.useWallets().find(S=>S.chainNamespace===types.ChainNamespace.SOLANA&&S.isConnected),a=i==="authenticated",u=l?.address,[d,m]=react.useState(r),[p,f]=react.useState(n),[c,b]=react.useState(NaN),x=react.useMemo(()=>yt(e.accounts,Ce,d),[e.accounts,d]),{inputMint:g,outputMint:k}=react.useMemo(()=>p==="buy"?{inputMint:Ce,outputMint:x}:{inputMint:x,outputMint:Ce},[p,x]),h=!!g&&!!k&&c>0,y=react.useMemo(()=>Number(d==="yes"?e.yesAsk??.5:e.noAsk??.5),[d,e.yesAsk,e.noAsk]),P=react.useMemo(()=>isNaN(c)||c<=0?0:p==="buy"?y>0?c/y:0:c,[p,c,y]),T=react.useMemo(()=>isNaN(c)||c<=0?0:Math.round(c*1e6),[c]),{data:U,isLoading:j,error:C,refetch:Q}=Gt({userPublicKey:u??void 0,inputMint:g??"",outputMint:k??"",amount:T,slippageBps:100},{enabled:h}),{data:O,isLoading:Ye,refetch:It}=react$1.useWalletPortfoliosQuery({chain:types.Chain.SOLANA,address:u??""},{enabled:a&&!!u,refetchInterval:1e4}),Ie=react.useMemo(()=>{if(!O?.portfolios)return null;let S=O.portfolios.find(X=>X.address===Ce);return S?parseFloat(S.amount):0},[O]),Qe=react.useMemo(()=>{if(!O?.portfolios||!x)return null;let S=O.portfolios.find(X=>X.address===x);return S?parseFloat(S.amount):0},[O,x]),je=react.useMemo(()=>yt(e.accounts,Ce,"yes"),[e.accounts]),Xe=react.useMemo(()=>yt(e.accounts,Ce,"no"),[e.accounts]),Nn=react.useMemo(()=>{if(!O?.portfolios||!je)return null;let S=O.portfolios.find(X=>X.address===je);return S?parseFloat(S.amount):0},[O,je]),En=react.useMemo(()=>{if(!O?.portfolios||!Xe)return null;let S=O.portfolios.find(X=>X.address===Xe);return S?parseFloat(S.amount):0},[O,Xe]),{data:ve}=he(e.ticker,{refetchInterval:5e3}),On=react.useMemo(()=>(d==="yes"?ve?.yesBids:ve?.noBids)?.[0]?.price??null,[ve,d]),In=react.useMemo(()=>(d==="yes"?ve?.yesAsks:ve?.noAsks)?.[0]?.price??null,[ve,d]),Qn=react.useMemo(()=>U?.priceImpactPct?parseFloat(U.priceImpactPct):null,[U]),Be=react.useMemo(()=>{if(isNaN(c)||c<=0)return 0;if(U)return parseInt(U.inAmount)/1e6;if(p==="buy")return c;let S=Number(d==="yes"?e.yesBid??0:e.noBid??0);return c*S},[U,p,d,c,e.yesBid,e.noBid]),Qt=react.useMemo(()=>isNaN(c)||c<=0?0:p==="buy"?P*1:Be,[p,P,Be,c]),Bn=Qt-Be,Ln=react.useCallback(S=>{f(S),b(NaN);},[]),Un=react.useCallback(S=>{if(isNaN(S)){b(NaN);return}let X=Math.max(0,S),et=p==="buy"?Math.round(X*100)/100:Math.round(X);b(et);},[p]);react.useEffect(()=>{h&&Q();},[c,d,p,h,Q]);let Ze=react.useMemo(()=>{let S=[];return (isNaN(c)||c<ct)&&S.push(`Minimum quantity is ${ct}`),e.status!=="active"&&S.push("Market is not active"),p==="buy"&&Ie!=null&&!isNaN(c)&&c>0&&c>Ie&&S.push("Insufficient USDC balance"),p==="sell"&&Qe!=null&&!isNaN(c)&&c>0&&c>Qe&&S.push("Insufficient shares"),{isValid:S.length===0,errors:S}},[c,e.status,p,Ie,Qe]),[An,Je]=react.useState(null),[Dn,Bt]=react.useState(false),_n=react.useCallback(async()=>{if(!(!Ze.isValid||!a||!u||!l||Ye)){Je(null),Bt(true);try{let S=U;if(S?.transaction||(S=(await Q()).data),!S?.transaction)return;let X=Uint8Array.from(atob(S.transaction),Lt=>Lt.charCodeAt(0)),et=await l.sendTransaction(X);Je(et),ui.toast.success(s("predict.trade.submitSuccess")),ma(),b(NaN),It();}catch{ui.toast.error(s("predict.trade.submitError"));}finally{Bt(false);}}},[Ze.isValid,a,u,l,U,Ye,Q,It,s]),Fn=react.useCallback(()=>{m(r),f(n),b(NaN),Je(null);},[r,n]);return {outcome:d,side:p,quantity:c,shares:P,estimatedCost:Be,potentialPayout:Qt,potentialProfit:Bn,isAuthenticated:a,bestBid:On,bestAsk:In,order:U??null,priceImpact:Qn,usdcBalance:Ie,outcomeTokenBalance:Qe,yesTokenBalance:Nn,noTokenBalance:En,isBalanceLoading:Ye,isQuoteLoading:j,isSubmitting:Dn,quoteError:C??null,txHash:An,validation:Ze,setOutcome:m,setSide:Ln,setQuantity:Un,submit:_n,reset:Fn}}var va=`https://s1.chainstream.io/chains/sol/tokens/${utils.SOLANA_TOKENS.stablecoins.USDC.address}/image.png`;function Er({event:e,market:t,outcome:r,side:n,quantity:s,potentialProfit:i,estimatedCost:o,usdcBalance:l,yesTokenBalance:a,noTokenBalance:u,isBalanceLoading:d,isSubmitting:m,isValid:p,onOutcomeChange:f,onSideChange:c,onQuantityChange:b,onSubmit:x}){let{t:g}=i18n.useTranslation(),k=react.useMemo(()=>{if(m)return g("predict.trade.submitting");let y=g(n==="buy"?"predict.trade.buy":"predict.trade.sell"),P=g(r==="yes"?"predict.trade.yes":"predict.trade.no");return `${y} ${P}`},[m,n,r,g]),h=react.useMemo(()=>r==="yes"?"primary":"secondary",[r]);return jsxRuntime.jsxs("div",{className:"flex w-full flex-col gap-y-4 rounded-xl border border-default-200 bg-content1 p-4",children:[e&&jsxRuntime.jsxs("div",{className:"flex items-center gap-x-3",children:[e.imageUrl&&jsxRuntime.jsx("img",{src:e.imageUrl,alt:e.title,className:"h-10 w-10 shrink-0 rounded-lg object-cover"}),jsxRuntime.jsxs("div",{className:"flex min-w-0 flex-col gap-y-0.5",children:[jsxRuntime.jsx("span",{className:"text-sm text-neutral-500 leading-tight line-clamp-1",children:e.title}),jsxRuntime.jsxs("span",{className:"text-base font-semibold leading-tight line-clamp-1",children:[jsxRuntime.jsxs("span",{className:r==="yes"?"text-bullish":"text-bearish",children:[g(n==="buy"?"predict.trade.buy":"predict.trade.sell")," ",g(r==="yes"?"predict.trade.yes":"predict.trade.no")]}),jsxRuntime.jsxs("span",{className:"text-foreground",children:[" \xB7 ",r==="yes"?t.yesSubTitle:t.noSubTitle]})]})]})]}),jsxRuntime.jsxs(ui.Tabs,{variant:"underlined",selectedKey:n,onSelectionChange:y=>c(y),classNames:{tabList:"gap-x-4",tab:"px-0"},children:[jsxRuntime.jsx(ui.Tab,{title:g("predict.trade.buy")},"buy"),jsxRuntime.jsx(ui.Tab,{title:g("predict.trade.sell")},"sell")]}),jsxRuntime.jsx("div",{className:"flex gap-x-2",children:["yes","no"].map(y=>{let P=y==="yes"?a:u;return jsxRuntime.jsxs("div",{className:"flex flex-1 flex-col gap-y-1",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>f(y),className:`w-full rounded-lg border py-2 text-sm font-medium transition-colors cursor-pointer ${r===y?y==="yes"?"border-primary bg-primary-50 text-primary":"border-secondary bg-secondary-50 text-secondary":"border-default-400 text-foreground hover:border-default-500"}`,children:[jsxRuntime.jsx("span",{children:g(y==="yes"?"predict.trade.yes":"predict.trade.no")}),(()=>{let T=n==="buy"?y==="yes"?t.yesAsk:t.noAsk:y==="yes"?t.yesBid:t.noBid;return T!=null?jsxRuntime.jsxs("span",{className:"ml-1 opacity-70",children:[Math.round(Number(T)*100),"\xA2"]}):null})()]}),n==="sell"&&r===y&&jsxRuntime.jsx("span",{className:"text-center text-xs text-foreground",children:d?"\u2013":`${P??0} shares`})]},y)})}),n==="buy"&&jsxRuntime.jsxs("div",{className:"flex items-center justify-end gap-x-1 text-xs text-default-500",children:[jsxRuntime.jsx("img",{src:va,alt:"USDC",className:"h-4 w-4 rounded-full object-cover"}),jsxRuntime.jsxs("span",{children:[g("predict.trade.balance"),":"]}),jsxRuntime.jsx("span",{className:"font-medium text-foreground",children:d?"\u2013":l!=null?`$${l.toFixed(2)}`:"\u2013"})]}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-1.5",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium text-foreground",children:g(n==="buy"?"predict.trade.amount":"predict.trade.contracts")}),jsxRuntime.jsx(ui.StyledNumberInput,{fullWidth:true,placeholder:"0",radius:"lg",size:"lg",value:isNaN(s)?void 0:s,onValueChange:y=>{b(y);},minValue:0,step:n==="buy"?.01:1,formatOptions:n==="buy"?{maximumFractionDigits:2}:{maximumFractionDigits:0},startContent:n==="buy"?jsxRuntime.jsx("span",{className:"text-default-600 text-xl",children:"$"}):void 0,classNames:{inputWrapper:"bg-content2 data-[hover=true]:bg-content2 group-data-[focus=true]:bg-content2 h-14 min-h-14",input:"text-lg"}},n),jsxRuntime.jsx("div",{className:"flex gap-x-2 justify-end",children:n==="buy"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[[1,5,10,100].map(y=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>b(Math.round(((isNaN(s)?0:s)+y)*100)/100),className:"rounded-md bg-content2 px-2.5 py-1 text-xs font-medium text-default-600 transition-colors hover:bg-content3 cursor-pointer",children:["+",y,"$"]},y)),jsxRuntime.jsx("button",{type:"button",onClick:()=>{},className:"rounded-md bg-content2 px-2.5 py-1 text-xs font-medium text-default-600 transition-colors hover:bg-content3 cursor-pointer",children:g("common.all")})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[[25,50].map(y=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>{},className:"rounded-md bg-content2 px-2.5 py-1 text-xs font-medium text-default-600 transition-colors hover:bg-content3 cursor-pointer",children:[y,"%"]},y)),jsxRuntime.jsx("button",{type:"button",onClick:()=>{},className:"rounded-md bg-content2 px-2.5 py-1 text-xs font-medium text-default-600 transition-colors hover:bg-content3 cursor-pointer",children:g("common.all")})]})})]}),!isNaN(s)&&s>0&&jsxRuntime.jsxs("div",{className:"flex flex-col items-end gap-y-0.5",children:[jsxRuntime.jsx("span",{className:"text-sm text-foreground",children:g(n==="buy"?"predict.trade.potentialWin":"predict.trade.estimatedReceive")}),jsxRuntime.jsxs("span",{className:"text-xl font-semibold text-bullish",children:["$",(n==="buy"?i:o).toFixed(2)]})]}),jsxRuntime.jsx(ui.Button,{color:h,fullWidth:true,radius:"lg",size:"lg",isDisabled:!p||m,isLoading:m,onPress:x,children:k})]})}function ft({event:e,market:t,initialSide:r,initialOutcome:n,chain:s}){let{outcome:i,side:o,quantity:l,estimatedCost:a,potentialPayout:u,potentialProfit:d,usdcBalance:m,yesTokenBalance:p,noTokenBalance:f,isBalanceLoading:c,isSubmitting:b,validation:x,setOutcome:g,setSide:k,setQuantity:h,submit:y}=Rr({market:t,initialSide:r,initialOutcome:n,chain:s}),P=walletConnector.useAuthCallback(y);return jsxRuntime.jsx(Er,{event:e,market:t,outcome:i,side:o,quantity:l,estimatedCost:a,potentialPayout:u,potentialProfit:d,usdcBalance:m,yesTokenBalance:p,noTokenBalance:f,isBalanceLoading:c,isSubmitting:b,isValid:x.isValid,validationErrors:x.errors,onOutcomeChange:g,onSideChange:k,onQuantityChange:h,onSubmit:P})}function Pa(){return jsxRuntime.jsxs("div",{className:"flex items-center gap-x-3 px-2 py-3 lg:gap-x-4",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-4 flex-1 rounded-md"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-10 shrink-0 rounded-md"}),jsxRuntime.jsxs("div",{className:"flex gap-x-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-8 w-16 rounded-lg"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-8 w-16 rounded-lg"})]})]})}function Ne({marketCount:e=4}){return jsxRuntime.jsxs("div",{className:"w-full flex flex-col gap-4 lg:gap-y-6 px-1 lg:px-4 lg:max-w-3xl animate-pulse",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-x-3 lg:gap-x-4",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-14 w-14 shrink-0 rounded-lg lg:h-18 lg:w-18"}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-1.5 min-w-0 flex-1",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-3 w-24 rounded-md lg:w-32"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-48 rounded-md lg:h-6 lg:w-72"})]})]}),jsxRuntime.jsx(ui.Skeleton,{className:"h-[200px] w-full rounded-xl lg:h-[280px]"}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-3 w-32 rounded-md"}),jsxRuntime.jsx("div",{className:"flex gap-x-1",children:Array.from({length:4}).map((t,r)=>jsxRuntime.jsx(ui.Skeleton,{className:"h-7 w-10 rounded-md"},r))})]}),jsxRuntime.jsx("div",{className:"flex flex-col divide-y divide-default-200",children:Array.from({length:e}).map((t,r)=>jsxRuntime.jsx(Pa,{},r))})]})}function Or(){return jsxRuntime.jsxs("div",{className:"flex w-full flex-col gap-y-4 rounded-xl border border-default-200 bg-content1 p-4 animate-pulse",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-x-3",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-10 w-10 shrink-0 rounded-lg"}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-1 flex-1",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-3 w-28 rounded-md"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-40 rounded-md"})]})]}),jsxRuntime.jsxs("div",{className:"flex gap-x-4",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-12 rounded-md"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-12 rounded-md"})]}),jsxRuntime.jsxs("div",{className:"flex gap-x-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-10 flex-1 rounded-lg"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-10 flex-1 rounded-lg"})]}),jsxRuntime.jsx(ui.Skeleton,{className:"h-14 w-full rounded-lg"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-12 w-full rounded-lg"})]})}var Ir=e=>{let{candlestickMarketTickers:t,chartRange:r=ce}=e,n=_e[r],s=We[r],i=react.useMemo(()=>Math.floor(Date.now()/1e3),[r]),o=v(),{data:l,isLoading:a,error:u}=Le({id:e.eventId,withNestedMarkets:true}),d=react.useMemo(()=>{if(s!=null)return i-s;let h=l?.markets;return h?.length?Math.min(...h.map(y=>y.openTime)):i},[i,s,l?.markets]),{data:m,isLoading:p,error:f}=Kt(l?.seriesTicker??"",{enabled:!!l?.seriesTicker}),c=react.useMemo(()=>l?.markets?(t&&t.length>0?t.slice(0,4).map(y=>l.markets.find(P=>P.ticker===y)).filter(y=>y!==void 0):[...l.markets].sort((y,P)=>Number(P.yesAsk??0)-Number(y.yesAsk??0)).slice(0,4)).map(y=>y.ticker):[],[t,l?.markets]),b=reactQuery.useQueries({queries:c.map(h=>({queryKey:nt({ticker:h,startTs:d,endTs:i,periodInterval:n}),queryFn:()=>st(o,{ticker:h,startTs:d,endTs:i,periodInterval:n}),enabled:c.length>0}))}),x=b.some(h=>h.isLoading),g=react.useMemo(()=>{let h=new Map;return c.forEach((y,P)=>{let T=b[P]?.error;T&&h.set(y,T);}),h},[c,b]),k=react.useMemo(()=>{let h=new Map;return c.forEach((y,P)=>{let T=b[P]?.data;T&&h.set(y,T);}),h},[c,b]);return {event:l,isEventLoading:a,eventError:u,series:m,isSeriesLoading:p,seriesError:f,periodInterval:n,candlesticks:k,isCandlesticksLoading:x,candlestickErrors:g}};var Oa=utils.SOLANA_TOKENS.stablecoins.USDC.address;function Qr(e){let{status:t}=walletConnector.useAuth(),n=walletConnector.useWallets().find(u=>u.chainNamespace===types.ChainNamespace.SOLANA&&u.isConnected),s=t==="authenticated",i=n?.address,{data:o,isLoading:l}=react$1.useWalletPortfoliosQuery({chain:types.Chain.SOLANA,address:i??""},{enabled:s&&!!i,refetchInterval:1e4});return {holdings:react.useMemo(()=>{let u=new Map;if(!o?.portfolios||e.length===0)return u;let d=new Map;for(let m of o.portfolios)d.set(m.address,parseFloat(m.amount));for(let m of e){let p=m.accounts[Oa];if(!p)continue;let f=d.get(p.yesMint)??0,c=d.get(p.noMint)??0;(f>0||c>0)&&u.set(m.ticker,{yesShares:f,noShares:c});}return u},[o,e]),isLoading:l}}function Wa(e){let{cx:t,cy:r,index:n,dataLength:s,stroke:i}=e;return n!==s-1||t==null||r==null?null:jsxRuntime.jsxs("g",{children:[jsxRuntime.jsxs("circle",{cx:t,cy:r,r:6,fill:i,opacity:.3,children:[jsxRuntime.jsx("animate",{attributeName:"r",values:"4;8;4",dur:"2s",repeatCount:"indefinite"}),jsxRuntime.jsx("animate",{attributeName:"opacity",values:"0.4;0.1;0.4",dur:"2s",repeatCount:"indefinite"})]}),jsxRuntime.jsx("circle",{cx:t,cy:r,r:3,fill:i})]})}var Ke=[{stroke:"hsl(var(--heroui-primary))",id:"colorMarket0"},{stroke:"hsl(var(--heroui-secondary))",id:"colorMarket1"},{stroke:"hsl(var(--heroui-success))",id:"colorMarket2"},{stroke:"hsl(var(--heroui-warning))",id:"colorMarket3"}];function Br(e,t){let r=new Date(e*1e3);switch(t){case w.ONE_DAY:return r.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:false});case w.ONE_WEEK:case w.ONE_MONTH:return r.toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:false});case w.ALL:default:return r.toLocaleDateString("en-US",{month:"short",day:"numeric"})}}function qa(e,t,r){let n=Fe[r],s=new Map;e.forEach((a,u)=>{let d=new Map;(a.candlesticks??[]).forEach(p=>{let f=p.end_period_ts-p.end_period_ts%n;d.set(f,p.yes_ask.close);}),s.set(u,d);});let i=new Set;for(let a of s.values())for(let u of a.keys())i.add(u);let o=Array.from(i).sort((a,u)=>a-u),l=new Map;return o.map(a=>{let d={date:new Date(a*1e3).toLocaleDateString("en-US",{month:"short",day:"numeric"}),timestamp:a};return t.forEach(m=>{let p=s.get(m)?.get(a);if(p!==void 0)d[m]=Math.round(p*100)/100,l.set(m,d[m]);else {let f=l.get(m);f!==void 0&&(d[m]=f);}}),d})}function Lr({candlesticks:e,markets:t=[],isLoading:r,chartRange:n=w.ALL,onDataChange:s}){let[i,o]=react.useState(null),l=react.useRef(s);react.useEffect(()=>{l.current=s;});let a=react.useMemo(()=>e?Array.from(e.keys()).slice(0,4):[],[e]),u=react.useMemo(()=>!e||e.size===0?[]:qa(e,a,n),[e,a,n]),d=react.useMemo(()=>{if(u.length===0||a.length===0)return [0,100];let c=1/0,b=-1/0;if(u.forEach(y=>{a.forEach(P=>{let T=y[P];T!==void 0&&(c=Math.min(c,T),b=Math.max(b,T));});}),c===1/0||b===-1/0)return [0,100];let x=b-c,g=Math.max(x*.2,5),k=Math.max(0,Math.floor(c-g)),h=Math.min(100,Math.ceil(b+g));return [k,h]},[u,a]),m=react.useCallback(c=>{if(u.length===0)return null;let b=c!==null?u[c]:u[u.length-1];return b?{timestamp:b.timestamp,date:b.date,markets:a.map((x,g)=>{let k=t.find(h=>h.ticker===x);return {id:x,label:k?.yesSubTitle||`Market ${g+1}`,value:b[x]??0,color:Ke[g%Ke.length].stroke}})}:null},[u,a,t]);react.useEffect(()=>{l.current&&u.length>0&&l.current(m(null));},[u,m]),react.useEffect(()=>{l.current&&l.current(m(i));},[i,m]);let p=react.useCallback(c=>{typeof c?.activeTooltipIndex=="number"&&o(c.activeTooltipIndex);},[]),f=react.useCallback(()=>{o(null);},[]);return r?jsxRuntime.jsx("div",{className:"h-[200px] w-full lg:h-[300px] flex items-center justify-center",children:jsxRuntime.jsx("div",{className:"text-default-400 text-sm",children:"Loading chart..."})}):u.length===0?jsxRuntime.jsx("div",{className:"h-[200px] w-full lg:h-[300px] flex items-center justify-center",children:jsxRuntime.jsx("div",{className:"text-default-400 text-sm",children:"No price history data"})}):jsxRuntime.jsx("div",{className:"h-[200px] w-full lg:h-[300px]",children:jsxRuntime.jsx(recharts.ResponsiveContainer,{width:"100%",height:"100%",children:jsxRuntime.jsxs(recharts.LineChart,{data:u,margin:{top:10,right:16,left:16,bottom:0},onMouseMove:p,onMouseLeave:f,children:[jsxRuntime.jsx(recharts.XAxis,{dataKey:"timestamp",tick:c=>{let{x:b,y:x,payload:g,index:k}=c,h=u.length,P=Math.max(1,Math.ceil(h/6)),T=k===0,U=k===h-1,j=k%P===0;return !T&&!U&&!j?null:jsxRuntime.jsx("text",{x:b,y:x+10,textAnchor:"middle",fill:"hsl(var(--heroui-default-500))",fontSize:10,children:Br(g.value,n)})},tickLine:false,axisLine:false,interval:0}),jsxRuntime.jsx(recharts.CartesianGrid,{horizontal:true,vertical:false,strokeDasharray:"3 3",stroke:"hsl(var(--heroui-default-200))"}),jsxRuntime.jsx(recharts.YAxis,{domain:d,tickLine:false,axisLine:false,tick:{fontSize:10,fill:"hsl(var(--heroui-default-500))"},tickFormatter:c=>`${c}%`,width:40}),jsxRuntime.jsx(recharts.Tooltip,{contentStyle:{backgroundColor:"hsl(var(--heroui-content1))",border:"1px solid hsl(var(--heroui-default-200))",borderRadius:"8px",fontSize:"12px"},labelFormatter:c=>Br(c,n),formatter:(c,b)=>{let g=t.find(k=>k.ticker===b)?.yesSubTitle||b;return [`${c.toFixed(2)}%`,g]}}),a.map((c,b)=>jsxRuntime.jsx(recharts.Line,{type:"monotone",dataKey:c,stroke:Ke[b%Ke.length].stroke,strokeWidth:2,isAnimationActive:false,dot:x=>jsxRuntime.jsx(Wa,{...x,dataLength:u.length},`dot-${c}-${x.index}`),activeDot:false},c))]})})})}function Ur(){return {timestamp:Date.now()/1e3,date:new Date().toLocaleDateString("en-US",{month:"short",day:"numeric"}),markets:[]}}function Dr({marketTicker:e,openTime:t,chartRange:r=ce}){let n=_e[r],s=We[r],i=react.useMemo(()=>Math.floor(Date.now()/1e3),[r]),o=react.useMemo(()=>s!=null?i-s:t??i,[i,s,t]),{data:l,isLoading:a,isFetching:u,error:d}=ot({ticker:e,startTs:o,endTs:i,periodInterval:n},{enabled:!!e});return {candlesticks:l,isLoading:a,isFetching:u,error:d,periodInterval:n}}var ja="hsl(var(--heroui-primary))",Xa=[{value:w.ONE_DAY,label:"1D"},{value:w.ONE_WEEK,label:"1W"},{value:w.ONE_MONTH,label:"1M"},{value:w.ALL,label:"ALL"}];function Za(e){let{cx:t,cy:r,index:n,dataLength:s,stroke:i}=e;return n!==s-1||t==null||r==null?null:jsxRuntime.jsxs("g",{children:[jsxRuntime.jsxs("circle",{cx:t,cy:r,r:6,fill:i,opacity:.3,children:[jsxRuntime.jsx("animate",{attributeName:"r",values:"4;8;4",dur:"2s",repeatCount:"indefinite"}),jsxRuntime.jsx("animate",{attributeName:"opacity",values:"0.4;0.1;0.4",dur:"2s",repeatCount:"indefinite"})]}),jsxRuntime.jsx("circle",{cx:t,cy:r,r:3,fill:i})]})}function Fr(e,t){let r=new Date(e*1e3);switch(t){case w.ONE_DAY:return r.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:false});case w.ONE_WEEK:case w.ONE_MONTH:return r.toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:false});case w.ALL:default:return r.toLocaleDateString("en-US",{month:"short",day:"numeric"})}}function Ja(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toFixed(0)}function ei(e,t){let r=Fe[t],n=e.candlesticks??[],s=new Map;for(let o of n){let l=o.end_period_ts-o.end_period_ts%r,a=s.get(l);s.set(l,{close:o.yes_ask.close,volume:(a?.volume??0)+(o.volume??0)});}return Array.from(s.entries()).sort((o,l)=>o[0]-l[0]).map(([o,{close:l,volume:a}])=>({timestamp:o,date:new Date(o*1e3).toLocaleDateString("en-US",{month:"short",day:"numeric"}),value:Math.round(l*100)/100,volume:a}))}function Wr({candlesticks:e,isLoading:t,chartRange:r,onRangeChange:n}){let s=react.useMemo(()=>e?ei(e,r):[],[e,r]),i=react.useMemo(()=>{if(s.length===0)return [0,100];let o=1/0,l=-1/0;for(let p of s)p.value<o&&(o=p.value),p.value>l&&(l=p.value);if(o===1/0||l===-1/0)return [0,100];let a=l-o,u=Math.max(a*.2,5),d=Math.max(0,Math.floor(o-u)),m=Math.min(100,Math.ceil(l+u));return [d,m]},[s]);return t?jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-2",children:[jsxRuntime.jsx("div",{className:"h-[200px] w-full flex items-center justify-center",children:jsxRuntime.jsx("div",{className:"text-neutral text-sm",children:"Loading chart..."})}),jsxRuntime.jsx(kt,{chartRange:r,onRangeChange:n})]}):s.length===0?jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-2",children:[jsxRuntime.jsx("div",{className:"h-[200px] w-full flex items-center justify-center",children:jsxRuntime.jsx("div",{className:"text-neutral text-sm",children:"No price history data"})}),jsxRuntime.jsx(kt,{chartRange:r,onRangeChange:n})]}):jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-2",children:[jsxRuntime.jsx("div",{className:"h-[200px] w-full",children:jsxRuntime.jsx(recharts.ResponsiveContainer,{width:"100%",height:"100%",children:jsxRuntime.jsxs(recharts.LineChart,{data:s,margin:{top:10,right:16,left:16,bottom:0},children:[jsxRuntime.jsx(recharts.XAxis,{dataKey:"timestamp",tick:o=>{let{x:l,y:a,payload:u,index:d}=o,m=s.length,f=Math.max(1,Math.ceil(m/6)),c=d===0,b=d===m-1,x=d%f===0;return !c&&!b&&!x?null:jsxRuntime.jsx("text",{x:l,y:a+10,textAnchor:"middle",fill:"hsl(var(--heroui-default-500))",fontSize:10,children:Fr(u.value,r)})},tickLine:false,axisLine:false,interval:0}),jsxRuntime.jsx(recharts.CartesianGrid,{horizontal:true,vertical:false,strokeDasharray:"3 3",stroke:"hsl(var(--heroui-default-200))"}),jsxRuntime.jsx(recharts.YAxis,{domain:i,tickLine:false,axisLine:false,tick:{fontSize:10,fill:"hsl(var(--heroui-default-500))"},tickFormatter:o=>`${o}%`,width:40}),jsxRuntime.jsx(recharts.Tooltip,{cursor:{stroke:"hsl(var(--heroui-default-300))"},content:({active:o,payload:l})=>{if(!o||!l?.length)return null;let a=l[0].payload,u=Math.round(a.value);return jsxRuntime.jsxs("div",{className:"rounded-lg border border-default-200 bg-content1 px-3 py-2 shadow-md",children:[jsxRuntime.jsxs("div",{className:"text-lg font-semibold text-primary",children:["Yes ",u,"\xA2"]}),jsxRuntime.jsxs("div",{className:"text-sm text-neutral",children:["Vol ",Ja(a.volume)," \xB7"," ",Fr(a.timestamp,r)]})]})}}),jsxRuntime.jsx(recharts.Line,{type:"monotone",dataKey:"value",stroke:ja,strokeWidth:2,isAnimationActive:false,dot:o=>jsxRuntime.jsx(Za,{...o,dataLength:s.length},`dot-${o.index}`),activeDot:false})]})})}),jsxRuntime.jsx(kt,{chartRange:r,onRangeChange:n})]})}function kt({chartRange:e,onRangeChange:t}){return jsxRuntime.jsx("div",{className:"flex items-center justify-end gap-x-1",children:Xa.map(r=>{let n=e===r.value;return jsxRuntime.jsx("button",{type:"button",className:`px-3 py-1 text-xs rounded-md transition-colors cursor-pointer ${n?"bg-primary text-primary-foreground":"bg-default-100 text-default-600 hover:bg-default-200"}`,onClick:()=>t?.(r.value),children:r.label},r.value)})})}function qr({marketTicker:e}){let{data:t,isLoading:r,error:n}=he(e,{enabled:!!e});return {orderbook:react.useMemo(()=>{if(!t)return null;let{yesBids:i,yesAsks:o,noBids:l,noAsks:a}=t;return {yesBids:i,yesAsks:o,noBids:l,noAsks:a,bestYesBid:i.length>0?i[0].price:null,bestYesAsk:o.length>0?o[0].price:null,bestNoBid:l.length>0?l[0].price:null,bestNoAsk:a.length>0?a[0].price:null,sequence:t.sequence??null}},[t]),isOrderbookLoading:r,orderbookError:n}}function Hr(e,t){let r=e.slice(0,t),n=0;return r.map(s=>(n+=s.quantity,{...s,cumulative:n,depth:0,total:s.price*s.quantity}))}function Kr(e,t){for(let r of e)r.depth=t>0?r.cumulative/t:0;}function Gr(e){return `${Math.round(e*100)}\xA2`}function ni(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function si(e){return e>=1e6?`$${(e/1e6).toFixed(2)}M`:e>=1e3?`$${(e/1e3).toFixed(2)}K`:e>=1?`$${e.toFixed(2)}`:`$${e.toFixed(4)}`}function $r({row:e,side:t,showType:r=false,onClick:n}){let{t:s}=i18n.useTranslation(),i=t==="ask",o=i?"bg-bullish/10":"bg-bearish/10",l=i?"text-bullish":"text-bearish";return jsxRuntime.jsxs("button",{type:"button",className:"relative grid w-full grid-cols-4 px-2 py-2.5 text-xs cursor-pointer hover:bg-default-100 transition-colors",onClick:()=>n?.(e.price,t),children:[jsxRuntime.jsx("div",{className:`absolute inset-y-0 left-0 ${o} transition-[width] duration-200`,style:{width:`${e.depth*100}%`}}),jsxRuntime.jsx("span",{className:`relative z-10 font-mono font-medium ${l} text-left`,children:r?s(i?"predict.trade.bestAsk":"predict.trade.bestBid"):""}),jsxRuntime.jsx("span",{className:"relative z-10 font-mono text-foreground text-right",children:Gr(e.price)}),jsxRuntime.jsx("span",{className:"relative z-10 font-mono text-foreground text-right",children:ni(e.quantity)}),jsxRuntime.jsx("span",{className:"relative z-10 font-mono text-foreground text-right",children:si(e.total)})]})}function Vr({index:e}){let t=["60%","45%","75%","55%","65%","50%","70%","40%"];return jsxRuntime.jsxs("div",{className:"grid grid-cols-4 gap-x-2 px-2 py-2.5",children:[jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100",style:{width:t[e%t.length]}}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-3/4"}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-3/4"}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-3/4"})]})}function oi(){return jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsxs("div",{className:"grid grid-cols-4 gap-x-2 px-2 py-2.5",children:[jsxRuntime.jsx("div",{}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-1/2"}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-1/2"}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-1/2"})]}),Array.from({length:ht}).map((e,t)=>jsxRuntime.jsx(Vr,{index:t},`ask-${t}`)),jsxRuntime.jsx("div",{className:"flex justify-center border-y border-default-200 px-2 py-2.5",children:jsxRuntime.jsx("div",{className:"h-4 w-24 animate-pulse rounded bg-default-100"})}),Array.from({length:ht}).map((e,t)=>jsxRuntime.jsx(Vr,{index:t+3},`bid-${t}`))]})}var ht=8;function Pt({bids:e,asks:t,isLoading:r=false,maxLevels:n=ht,onPriceClick:s}){let{t:i}=i18n.useTranslation(),{bidRows:o,askRows:l,spread:a,spreadPercent:u}=react.useMemo(()=>{let m=Hr(e,n),p=Hr(t,n),f=Math.max(m[m.length-1]?.cumulative??0,p[p.length-1]?.cumulative??0);Kr(m,f),Kr(p,f);let c=m[0]?.price??null,b=p[0]?.price??null,x=null,g=null;if(c!=null&&b!=null){x=b-c;let k=(c+b)/2;k>0&&(g=Math.round(x/k*1e4)/100);}return {bidRows:m,askRows:p,spread:x,spreadPercent:g}},[e,t,n]);return r?jsxRuntime.jsx(oi,{}):o.length===0&&l.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-6 text-sm text-neutral",children:i("predict.orderBook.empty")}):jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsxs("div",{className:"grid grid-cols-4 px-2 py-2.5 text-xs text-neutral",children:[jsxRuntime.jsx("span",{}),jsxRuntime.jsx("span",{className:"text-right",children:i("predict.orderBook.price")}),jsxRuntime.jsx("span",{className:"text-right",children:i("predict.orderBook.contracts")}),jsxRuntime.jsx("span",{className:"text-right",children:i("predict.orderBook.total")})]}),jsxRuntime.jsx("div",{className:"flex flex-col-reverse",children:l.map((m,p)=>jsxRuntime.jsx($r,{row:m,side:"ask",showType:p===0,onClick:s},m.price))}),a!=null&&jsxRuntime.jsxs("div",{className:"flex items-center justify-center gap-x-2 border-y border-default-200 px-2 py-2.5 text-xs text-default-500",children:[jsxRuntime.jsxs("span",{children:[i("predict.orderBook.spread"),": ",Gr(a)]}),u!=null&&jsxRuntime.jsxs("span",{className:"text-default-400",children:["(",u,"%)"]})]}),jsxRuntime.jsx("div",{className:"flex flex-col",children:o.map((m,p)=>jsxRuntime.jsx($r,{row:m,side:"bid",showType:p===0,onClick:s},m.price))})]})}function Xr({market:e,onTradeAction:t}){let{t:r}=i18n.useTranslation(),[n,s]=react.useState("trade-yes"),[i,o]=react.useState(ce),{orderbook:l,isOrderbookLoading:a}=qr({marketTicker:e.ticker}),{candlesticks:u,isFetching:d}=Dr({marketTicker:e.ticker,openTime:e.openTime,chartRange:i}),m=react.useCallback((f,c)=>{t?.(e,"yes",c==="ask"?"buy":"sell");},[e,t]),p=react.useCallback((f,c)=>{t?.(e,"no",c==="ask"?"buy":"sell");},[e,t]);return jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-3",children:[jsxRuntime.jsxs(ui.Tabs,{variant:"underlined",selectedKey:n,onSelectionChange:f=>s(f),classNames:{tabList:"gap-x-4",tab:"px-0"},children:[jsxRuntime.jsx(ui.Tab,{title:r("predict.market.tradeYes")},"trade-yes"),jsxRuntime.jsx(ui.Tab,{title:r("predict.market.tradeNo")},"trade-no"),jsxRuntime.jsx(ui.Tab,{title:r("predict.market.graph")},"graph")]}),jsxRuntime.jsxs("div",{className:"min-h-[120px]",children:[n==="trade-yes"&&jsxRuntime.jsx(Pt,{bids:l?.yesBids??[],asks:l?.yesAsks??[],isLoading:a,onPriceClick:m}),n==="trade-no"&&jsxRuntime.jsx(Pt,{bids:l?.noBids??[],asks:l?.noAsks??[],isLoading:a,onPriceClick:p}),n==="graph"&&jsxRuntime.jsx(Wr,{candlesticks:u,isLoading:d,chartRange:i,onRangeChange:o})]})]})}var wt=4;function ci(e){let t=e.yesAsk?Math.round(parseFloat(e.yesAsk)*100):null,r=e.noAsk?Math.round(parseFloat(e.noAsk)*100):null;return {yesCents:t,noCents:r}}function sn({markets:e,renderMarketDetail:t,onTradeAction:r,marketHoldings:n}){let{t:s}=i18n.useTranslation(),[i,o]=react.useState(false),[l,a]=react.useState(null);if(e.length===0)return null;let u=e.length>wt,d=i?e:e.slice(0,wt),m=p=>{a(f=>f===p?null:p);};return jsxRuntime.jsxs("div",{className:"flex flex-col divide-y divide-default-200",children:[d.map(p=>{let{yesCents:f,noCents:c}=ci(p),b=l===p.ticker;return jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-x-3 px-2 py-3 transition-colors hover:bg-content2 lg:gap-x-4 cursor-pointer",onClick:()=>m(p.ticker),role:"button",tabIndex:0,onKeyDown:x=>{(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),m(p.ticker));},children:[jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-1 min-w-0 flex-1",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium truncate lg:text-base",children:p.yesSubTitle}),(()=>{let x=n?.get(p.ticker);if(!x)return null;let{yesShares:g,noShares:k}=x;return g<=0&&k<=0?null:jsxRuntime.jsxs("div",{className:"flex items-center gap-x-1.5",children:[g>0&&jsxRuntime.jsx(ui.Chip,{size:"sm",variant:"flat",color:"primary",classNames:{base:"h-5",content:"text-[10px] font-medium px-1"},children:s("predict.market.sharesYes",{shares:g%1===0?g:g.toFixed(2)})}),k>0&&jsxRuntime.jsx(ui.Chip,{size:"sm",variant:"flat",color:"secondary",classNames:{base:"h-5",content:"text-[10px] font-medium px-1"},children:s("predict.market.sharesNo",{shares:k%1===0?k:k.toFixed(2)})})]})})()]}),(()=>{let x=f!=null,g=c!=null;return x&&!g&&f<=1?jsxRuntime.jsx("span",{className:"text-lg font-bold shrink-0 text-center text-default-400 lg:text-xl",children:"< 1%"}):g&&!x&&c<=1?jsxRuntime.jsx("span",{className:"text-lg font-bold shrink-0 text-center text-default-400 lg:text-xl",children:"> 99%"}):!x&&!g?jsxRuntime.jsx("span",{className:"text-lg font-bold shrink-0 text-center text-default-400 lg:text-xl",children:"0%"}):jsxRuntime.jsx("span",{className:"text-lg font-bold shrink-0 text-center lg:text-xl",children:`${f}%`})})(),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2 flex-1 justify-end",children:[jsxRuntime.jsx(ui.Button,{size:"sm",color:"primary",className:"w-20 bg-primary-100 text-primary",onPress:()=>r?.(p,"yes","buy"),children:f!=null?s("predict.market.action.yes",{price:f}):s("predict.market.yes")}),jsxRuntime.jsx(ui.Button,{size:"sm",color:"secondary",className:"w-20 bg-secondary-100 text-secondary",onPress:()=>r?.(p,"no","buy"),children:c!=null?s("predict.market.action.no",{price:c}):s("predict.market.no")})]}),b?jsxRuntime.jsx(ui.ChevronUpIcon,{className:"h-4 w-4 shrink-0 text-default-400"}):jsxRuntime.jsx(ui.ChevronDownIcon,{className:"h-4 w-4 shrink-0 text-default-400"})]}),b&&t&&jsxRuntime.jsx("div",{className:"max-h-100 overflow-y-auto px-2 pb-3",children:t(p)})]},p.ticker)}),u&&jsxRuntime.jsx("button",{type:"button",onClick:()=>o(p=>!p),className:"flex items-center justify-center gap-x-1.5 px-2 py-2.5 text-sm text-default-500 transition-colors cursor-pointer hover:text-primary",children:i?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{children:s("predict.event.rules.collapse")}),jsxRuntime.jsx(ui.ChevronUpIcon,{className:"h-4 w-4"})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{children:s("predict.event.moreMarkets",{count:e.length-wt})}),jsxRuntime.jsx(ui.ChevronDownIcon,{className:"h-4 w-4"})]})})]})}var yi=new Set(["closed","determined","finalized"]);function $e(e){let t=new Date(e*1e3),r=t.toLocaleString("default",{month:"short"}),n=t.getDate(),s=t.getFullYear(),i=t.getHours().toString().padStart(2,"0"),o=t.getMinutes().toString().padStart(2,"0");return `${r} ${n}, ${s} ${i}:${o}`}function fi({market:e}){let t=yi.has(e.status),r=react.useMemo(()=>{let s={label:"Market Open",value:$e(e.openTime),isActive:true},i={label:"Market Closes",value:t?$e(e.closeTime):"After the outcome occurs",isActive:t},o={label:"Projected Payout",value:"30 minutes after closing",isActive:e.status==="finalized"};return [s,i,o]},[e.openTime,e.closeTime,e.status,t]),n=react.useMemo(()=>t?null:e.canCloseEarly&&e.earlyCloseCondition?`${e.earlyCloseCondition} Otherwise, it closes by ${$e(e.expirationTime)}.`:`This market closes by ${$e(e.expirationTime)}.`,[t,e.canCloseEarly,e.earlyCloseCondition,e.expirationTime]);return jsxRuntime.jsxs("div",{className:"flex flex-col",children:[r.map((s,i)=>jsxRuntime.jsxs("div",{className:"flex items-stretch gap-x-3",children:[jsxRuntime.jsxs("div",{className:"flex flex-col items-center w-3",children:[jsxRuntime.jsx("div",{className:`h-3 w-3 shrink-0 rounded-full border-2 mt-0.5 ${s.isActive?"border-primary bg-primary":"border-default-300 bg-transparent"}`}),i<r.length-1&&jsxRuntime.jsx("div",{className:"w-px flex-1 bg-default-200"})]}),jsxRuntime.jsxs("div",{className:`flex flex-col ${i<r.length-1?"pb-4":""}`,children:[jsxRuntime.jsx("span",{className:"text-xs font-medium text-foreground lg:text-sm",children:s.label}),jsxRuntime.jsx("span",{className:"text-xs text-default-500 lg:text-sm",children:s.value})]})]},s.label)),n&&jsxRuntime.jsx("p",{className:"text-xs text-default-500 mt-3 lg:text-sm",children:n})]})}function an({markets:e,event:t,series:r}){let{t:n}=i18n.useTranslation(),[s,i]=react.useState(null),o=e.filter(a=>a.rulesPrimary);if(o.length===0)return null;let l=o.find(a=>a.ticker===s)??o[0];return l?.rulesPrimary?jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-2",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium lg:text-base",children:n("predict.event.rules")}),o.length>1&&jsxRuntime.jsx(ui.Select,{size:"sm","aria-label":"Select market rules",className:"max-w-48",classNames:{trigger:"min-h-8 h-8",value:"text-xs"},selectedKeys:new Set([l.ticker]),onSelectionChange:a=>{if(a==="all")return;let u=Array.from(a);u.length>0&&i(u[0]);},children:o.map(a=>jsxRuntime.jsx(ui.SelectItem,{textValue:a.yesSubTitle,children:jsxRuntime.jsx("span",{className:"text-xs truncate",children:a.yesSubTitle})},a.ticker))}),jsxRuntime.jsx("div",{className:"text-xs text-foreground lg:text-sm",children:l.rulesPrimary}),jsxRuntime.jsx("span",{className:"text-xs font-medium text-default-500 mt-2 lg:text-sm",children:"Timeline and payout"}),jsxRuntime.jsx(fi,{market:l}),jsxRuntime.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 text-xxs text-default-400 mt-2 lg:text-xs",children:[r?.ticker&&jsxRuntime.jsxs("span",{children:[jsxRuntime.jsx("span",{className:"text-default-500",children:"Series:"})," ",jsxRuntime.jsx("span",{className:"text-foreground",children:r.ticker})]}),t.ticker&&jsxRuntime.jsxs("span",{children:[jsxRuntime.jsx("span",{className:"text-default-500",children:"Event:"})," ",jsxRuntime.jsx("span",{className:"text-foreground",children:t.ticker})]}),jsxRuntime.jsxs("span",{children:[jsxRuntime.jsx("span",{className:"text-default-500",children:"Market:"})," ",jsxRuntime.jsx("span",{className:"text-foreground",children:l.ticker})]})]})]}):null}var Si=[{value:w.ONE_DAY,label:"1D"},{value:w.ONE_WEEK,label:"1W"},{value:w.ONE_MONTH,label:"1M"},{value:w.ALL,label:"ALL"}];function cn({event:e,series:t,candlesticks:r,chartRange:n=w.ONE_DAY,periodInterval:s,isCandlesticksLoading:i,onRangeChange:o,selectedMarketTickers:l,onMarketSelectionChange:a,onTradeAction:u}){let{t:d}=i18n.useTranslation(),[m,p]=react.useState(Ur()),[f,c]=react.useState(false),b=react.useRef(null);react.useEffect(()=>{let y=b.current;if(!y)return;let P=false,T=0,U=()=>{let{bottom:C}=y.getBoundingClientRect(),Q=P?C<0:C<-20;Q!==P&&(P=Q,c(Q));},j=()=>{cancelAnimationFrame(T),T=requestAnimationFrame(U);};return window.addEventListener("scroll",j,{passive:true,capture:true}),U(),()=>{cancelAnimationFrame(T),window.removeEventListener("scroll",j,{capture:true});}},[]);let x=react.useMemo(()=>[...e.markets||[]].sort((y,P)=>Number(P.yesAsk??0)-Number(y.yesAsk??0)),[e.markets]),{holdings:g}=Qr(x),k=react.useMemo(()=>utils.formatAmountUSDCompact((e.volume??0)/100),[e.volume]),h=react.useMemo(()=>{if(!e.strikeDate)return null;let y=new Date(e.strikeDate*1e3),P=y.toLocaleString("default",{month:"short"}),T=y.getDate(),U=y.getFullYear();return `${P} ${T}, ${U}`},[e.strikeDate]);return jsxRuntime.jsxs("div",{className:"w-full flex flex-col gap-4 lg:gap-y-6 px-1 pb-8 lg:px-4 lg:pb-12 lg:max-w-3xl",children:[jsxRuntime.jsx("div",{ref:b,className:"h-0 w-0"}),jsxRuntime.jsxs("div",{className:`sticky top-0 z-30 flex items-center bg-background/80 backdrop-blur-md transition-all duration-300 ${f?"gap-x-2 py-2 px-1 lg:px-4 -mx-1 lg:-mx-4 shadow-sm":"gap-x-2 lg:gap-x-4"}`,children:[jsxRuntime.jsx(ui.Avatar,{src:e.imageUrl||void 0,name:e.title||"Event",radius:"lg",className:`flex-shrink-0 transition-all duration-300 ${f?"!h-8 !w-8 lg:!h-10 lg:!w-10":"!h-14 !w-14 lg:!h-18 lg:!w-18"}`}),jsxRuntime.jsxs("div",{className:"flex flex-col min-w-0",children:[!f&&(t?.category||t?.tags&&t.tags.length>0)&&jsxRuntime.jsxs("span",{className:"text-xs text-default-500 lg:text-sm truncate",children:[t.category,t.category&&t.tags?.length>0&&" \xB7 ",t.tags?.join(", ")]}),jsxRuntime.jsx("span",{className:`font-semibold truncate transition-all duration-300 ${f?"text-sm lg:text-base":"text-lg lg:text-xl"}`,children:e.title})]})]}),jsxRuntime.jsx("div",{className:"flex flex-col gap-y-4",children:jsxRuntime.jsxs("div",{className:"flex flex-col",children:[m&&m.markets.length>0&&jsxRuntime.jsx("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2 text-xs lg:text-sm",children:m.markets.map(y=>jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2",children:[jsxRuntime.jsx("div",{className:"h-3 w-3 shrink-0 rounded-full",style:{backgroundColor:y.color}}),jsxRuntime.jsx("span",{className:"text-default-600",children:y.label})]},y.id))}),jsxRuntime.jsx(Lr,{candlesticks:r,chartRange:n,markets:x,isLoading:i,onDataChange:y=>p(y)}),jsxRuntime.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-4 gap-y-2 mt-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-x-3 text-xs text-default-500 lg:text-sm",children:[jsxRuntime.jsxs("span",{children:[k," ",d("predict.event.volume")]}),h&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{className:"text-default-300",children:"\xB7"}),jsxRuntime.jsx("span",{children:d("predict.event.endDate",{date:h})})]})]}),jsxRuntime.jsx("div",{className:"flex items-center gap-x-1",children:Si.map(y=>jsxRuntime.jsx("button",{type:"button",onClick:()=>o?.(y.value),className:`px-2 lg:px-3 py-1 text-xs rounded-md transition-colors cursor-pointer ${n===y.value?"bg-primary text-primary-foreground":"bg-default-100 text-default-600 hover:bg-default-200"}`,children:y.label},y.value))}),x.length>1&&jsxRuntime.jsx(ui.Select,{size:"sm",selectionMode:"multiple",placeholder:"Markets","aria-label":"Select markets",className:"min-w-28 max-w-48",classNames:{trigger:"min-h-8 h-8",value:"text-xs"},selectedKeys:l?new Set(l):void 0,onSelectionChange:y=>{if(y==="all")return;let P=Array.from(y);P.length<=4&&a?.(P);},children:jsxRuntime.jsx(ui.SelectSection,{title:`Pick up to ${4} markets`,classNames:{heading:"text-xs text-default-400 px-2 py-1"},children:x.map(y=>jsxRuntime.jsx(ui.SelectItem,{textValue:y.yesSubTitle,children:jsxRuntime.jsx("span",{className:"text-xs truncate",children:y.yesSubTitle})},y.ticker))})})]})]})}),jsxRuntime.jsx(sn,{markets:x,onTradeAction:u,marketHoldings:g,renderMarketDetail:y=>jsxRuntime.jsx(Xr,{market:y,onTradeAction:u})}),jsxRuntime.jsx(an,{markets:x,event:e,series:t})]})}function Tt({eventId:e,initialMarketTickers:t,initialChartRange:r=ce,onTradeAction:n}){let[s,i]=react.useState(r),[o,l]=react.useState(t),{event:a,isEventLoading:u,eventError:d,series:m,isSeriesLoading:p,periodInterval:f,candlesticks:c,isCandlesticksLoading:b,candlestickErrors:x}=Ir({eventId:e,candlestickMarketTickers:o,chartRange:s}),g=react.useRef(!!t);react.useEffect(()=>{if(a?.markets&&!g.current){g.current=true;let y=[...a.markets].sort((P,T)=>Number(T.yesAsk??0)-Number(P.yesAsk??0)).slice(0,4).map(P=>P.ticker);l(y);}},[a?.markets]);let k=react.useMemo(()=>y=>{i(y);},[]),h=react.useMemo(()=>y=>{l(y);},[]);return u||p?jsxRuntime.jsx(Ne,{}):d||!a?jsxRuntime.jsx("div",{className:"flex w-full items-center justify-center py-20 text-danger",children:d?.message||"Event not found"}):jsxRuntime.jsx(cn,{event:a,series:m,candlesticks:c,chartRange:s,periodInterval:f,isCandlesticksLoading:b,candlestickErrors:x,onRangeChange:k,selectedMarketTickers:o,onMarketSelectionChange:h,onTradeAction:n})}function Ny({eventId:e,chain:t,...r}){let{t:n}=i18n.useTranslation(),{isMobile:s}=ui.useScreen(),{isOpen:i,onOpen:o,onClose:l}=ui.useDisclosure(),{data:a,isLoading:u}=Le({id:e,withNestedMarkets:true}),d=react.useMemo(()=>[...a?.markets||[]].sort((x,g)=>Number(g.yesAsk??0)-Number(x.yesAsk??0)),[a?.markets]),[m,p]=react.useState(null),f=react.useCallback((x,g,k)=>{p(h=>({market:x,outcome:g,side:k,version:(h?.version??0)+1})),s&&o();},[s,o]),c=m?.market??d[0];if(u)return s?jsxRuntime.jsx(Ne,{}):jsxRuntime.jsxs("div",{className:"flex w-full max-w-6xl mx-auto gap-x-4 lg:gap-x-6",children:[jsxRuntime.jsx("div",{className:"min-w-0 flex-1 max-w-3xl",children:jsxRuntime.jsx(Ne,{})}),jsxRuntime.jsx("aside",{className:"hidden lg:block w-[340px] xl:w-[380px] shrink-0",children:jsxRuntime.jsx("div",{className:"sticky top-4",children:jsxRuntime.jsx(Or,{})})})]});let b=m?`${m.market.ticker}-${m.version}`:c?.ticker??"default";return s?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"w-full pb-20",children:jsxRuntime.jsx(Tt,{eventId:e,onTradeAction:f,...r})}),c&&jsxRuntime.jsx("div",{className:"fixed inset-x-0 bottom-0 z-40 flex justify-center p-3 bg-gradient-to-t from-background via-background/90 to-transparent",children:jsxRuntime.jsx(ui.Button,{color:"primary",size:"lg",className:"w-full max-w-md font-semibold",onPress:o,children:n("predict.trade.action")})}),jsxRuntime.jsx(ui.Drawer,{isOpen:i,onClose:l,placement:"bottom",size:"lg",hideCloseButton:true,classNames:{base:"max-h-[85dvh] rounded-t-2xl",body:"p-0"},children:jsxRuntime.jsx(ui.DrawerContent,{children:jsxRuntime.jsx(ui.DrawerBody,{children:c&&jsxRuntime.jsx(ft,{event:a,market:c,initialSide:m?.side,initialOutcome:m?.outcome,chain:t},b)})})})]}):jsxRuntime.jsxs("div",{className:"flex w-full max-w-6xl mx-auto gap-x-4 lg:gap-x-6",children:[jsxRuntime.jsx("div",{className:"min-w-0 flex-1 max-w-3xl",children:jsxRuntime.jsx(Tt,{eventId:e,onTradeAction:f,...r})}),c&&jsxRuntime.jsx("aside",{className:"hidden lg:block w-[340px] xl:w-[380px] shrink-0",children:jsxRuntime.jsx("div",{className:"sticky top-4 flex flex-col gap-y-4",children:jsxRuntime.jsx(ft,{event:a,market:c,initialSide:m?.side,initialOutcome:m?.outcome,chain:t},b)})})]})}function pn(e,t){if(!e)return [];let r=e.slice(0,t),n=0,s=r.map(o=>(n+=o.quantity,{...o,cumulative:n,depth:0})),i=s[s.length-1]?.cumulative??1;for(let o of s)o.depth=o.cumulative/i;return s}function mn({marketTicker:e,maxLevels:t=10,refetchInterval:r=5e3,outcome:n="yes"}){let{data:s,isLoading:i,isFetching:o}=he(e,{refetchInterval:r||void 0}),l=react.useMemo(()=>n==="yes"?s?.yesBids:s?.noBids,[s,n]),a=react.useMemo(()=>n==="yes"?s?.yesAsks:s?.noAsks,[s,n]),u=react.useMemo(()=>pn(l,t),[l,t]),d=react.useMemo(()=>pn(a,t),[a,t]),m=react.useMemo(()=>u.length===0||d.length===0?null:d[0].price-u[0].price,[u,d]),p=react.useMemo(()=>u.length===0||d.length===0?null:(u[0].price+d[0].price)/2,[u,d]),f=react.useMemo(()=>m===null||p===null||p===0?null:Math.round(m/p*1e4)/100,[m,p]);return {bids:u,asks:d,spread:m,spreadPercent:f,midpoint:p,isLoading:i,isFetching:o}}function yn({row:e,side:t,onClick:r}){let n=t==="bid",s=n?"bg-primary/10":"bg-danger/10",i=n?"text-primary":"text-danger";return jsxRuntime.jsxs("button",{type:"button",className:"relative flex w-full items-center justify-between px-3 py-1 text-xs hover:bg-default-100 cursor-pointer",onClick:()=>r?.(e.price),children:[jsxRuntime.jsx("div",{className:`absolute inset-y-0 ${n?"right-0":"left-0"} ${s}`,style:{width:`${e.depth*100}%`}}),jsxRuntime.jsxs("span",{className:`relative z-10 font-medium ${i}`,children:[e.price,"\xA2"]}),jsxRuntime.jsx("span",{className:"relative z-10 text-default-600",children:e.quantity}),jsxRuntime.jsx("span",{className:"relative z-10 text-default-400",children:e.cumulative})]})}function fn(){return jsxRuntime.jsx("div",{className:"flex flex-col gap-y-1 py-2",children:Array.from({length:5}).map((e,t)=>jsxRuntime.jsx("div",{className:"mx-3 h-4 animate-pulse rounded bg-default-100"},t))})}function gn({bids:e,asks:t,spread:r,spreadPercent:n,isLoading:s,onPriceClick:i}){let{t:o}=i18n.useTranslation();if(s)return jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsx("div",{className:"border-b border-default-200 px-3 py-2 text-sm font-medium",children:o("predict.orderBook.title")}),jsxRuntime.jsx(fn,{}),jsxRuntime.jsx(fn,{})]});let l=e.length===0&&t.length===0;return jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsx("div",{className:"flex items-center justify-between border-b border-default-200 px-3 py-2",children:jsxRuntime.jsx("span",{className:"text-sm font-medium",children:o("predict.orderBook.title")})}),l?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-default-400",children:o("predict.orderBook.empty")}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between px-3 py-1 text-xxs text-default-400",children:[jsxRuntime.jsx("span",{children:o("predict.orderBook.price")}),jsxRuntime.jsx("span",{children:o("predict.orderBook.qty")}),jsxRuntime.jsx("span",{children:o("predict.orderBook.total")})]}),jsxRuntime.jsx("div",{className:"flex flex-col-reverse",children:t.map(a=>jsxRuntime.jsx(yn,{row:a,side:"ask",onClick:i},a.price))}),r!==null&&jsxRuntime.jsxs("div",{className:"flex items-center justify-center gap-x-2 border-y border-default-200 py-1.5 text-xs text-default-500",children:[jsxRuntime.jsxs("span",{children:[o("predict.orderBook.spread"),": ",r,"\xA2"]}),n!==null&&jsxRuntime.jsxs("span",{className:"text-default-400",children:["(",n,"%)"]})]}),jsxRuntime.jsx("div",{className:"flex flex-col",children:e.map(a=>jsxRuntime.jsx(yn,{row:a,side:"bid",onClick:i},a.price))})]})]})}function Xy({marketTicker:e,maxLevels:t,refetchInterval:r,onPriceClick:n,outcome:s}){let{bids:i,asks:o,spread:l,spreadPercent:a,isLoading:u}=mn({marketTicker:e,maxLevels:t,refetchInterval:r,outcome:s});return jsxRuntime.jsx(gn,{bids:i,asks:o,spread:l,spreadPercent:a,isLoading:u,onPriceClick:n})}function bn(e={}){let[t,r]=react.useState(null),[n]=react.useState(null),s=react.useCallback(i=>{r(null);},[]);return {orders:[],isLoading:false,isFetching:false,cancellingOrderId:t,cancelOrder:s,cancelError:n}}function ji(e){return new Date(e).toLocaleString("default",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function vn({orders:e,isLoading:t,cancellingOrderId:r,onCancel:n}){let{t:s}=i18n.useTranslation(),i=react.useMemo(()=>e.map(o=>({key:o.id,side:o.side,outcome:o.outcome,type:o.type,price:o.price,filled:`${o.filledQuantity}/${o.quantity}`,status:o.status,createdAt:ji(o.createdAt),isCancelling:o.id===r,id:o.id})),[e,r]);return t?jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsx("div",{className:"border-b border-default-200 px-3 py-2 text-sm font-medium",children:s("predict.openOrders.title")}),jsxRuntime.jsx("div",{className:"flex flex-col gap-y-2 p-3",children:Array.from({length:3}).map((o,l)=>jsxRuntime.jsx("div",{className:"h-8 animate-pulse rounded bg-default-100"},l))})]}):jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsxs("div",{className:"border-b border-default-200 px-3 py-2 text-sm font-medium",children:[s("predict.openOrders.title"),e.length>0&&jsxRuntime.jsxs("span",{className:"ml-1 text-default-400",children:["(",e.length,")"]})]}),e.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-default-400",children:s("predict.openOrders.empty")}):jsxRuntime.jsx("div",{className:"w-full overflow-x-auto",children:jsxRuntime.jsxs(ui.StyledTable,{radius:"none","aria-label":"Open orders",className:"min-w-[600px]",children:[jsxRuntime.jsxs(ui.TableHeader,{children:[jsxRuntime.jsx(ui.TableColumn,{textValue:"Side",width:60,children:s("predict.openOrders.side")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Outcome",width:60,children:s("predict.openOrders.outcome")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Type",width:60,children:s("predict.openOrders.type")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Price",width:60,children:s("predict.openOrders.price")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Filled",width:80,children:s("predict.openOrders.filled")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Status",width:70,children:s("predict.openOrders.status")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Time",width:120,children:s("predict.openOrders.time")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Action",width:80,align:"end",children:" "})]}),jsxRuntime.jsx(ui.TableBody,{children:i.map(o=>jsxRuntime.jsxs(ui.TableRow,{children:[jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:`text-xs font-medium ${o.side==="buy"?"text-primary":"text-danger"}`,children:o.side==="buy"?s("predict.trade.buy"):s("predict.trade.sell")})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:`text-xs ${o.outcome==="yes"?"text-primary":"text-secondary"}`,children:o.outcome==="yes"?s("predict.trade.yes"):s("predict.trade.no")})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs capitalize",children:o.type})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("span",{className:"text-xs",children:[o.price,"\xA2"]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs",children:o.filled})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs capitalize",children:o.status})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs text-default-500",children:o.createdAt})}),jsxRuntime.jsx(ui.TableCell,{className:"text-right",children:jsxRuntime.jsx(ui.Button,{size:"sm",variant:"flat",color:"danger",isLoading:o.isCancelling,onPress:()=>n(o.id),children:s("predict.openOrders.cancel")})})]},o.key))})]})})]})}function yf({refetchInterval:e}={}){let{orders:t,isLoading:r,cancellingOrderId:n,cancelOrder:s}=bn({});return jsxRuntime.jsx(vn,{orders:t,isLoading:r,cancellingOrderId:n,onCancel:s})}function hn({ticker:e,pageSize:t=48}={}){let[r,n]=react.useState(1),[s,i]=react.useState([void 0]),o=s[r-1],l=react.useMemo(()=>({...e?{ticker:e}:{},limit:t,...o?{cursor:o}:{}}),[e,t,o]),{data:a,isLoading:u,isFetching:d}=Ft(l),m=a,p=m?.trades??[],f=!!m?.cursor,c=r>1,b=react.useCallback(k=>{k>=1&&k<=s.length&&n(k);},[s.length]),x=react.useCallback(()=>{f&&m?.cursor&&(i(k=>{let h=[...k];return h.length===r&&h.push(m.cursor),h}),n(k=>k+1));},[f,m?.cursor,r]),g=react.useCallback(()=>{c&&n(k=>k-1);},[c]);return {trades:p,isLoading:u,isFetching:d,page:r,pageSize:t,hasNextPage:f,hasPrevPage:c,goToPage:b,nextPage:x,prevPage:g}}function il(e){return new Date(e*1e3).toLocaleString("default",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function Cn({trades:e,isLoading:t,isFetching:r,page:n,hasNextPage:s,hasPrevPage:i,onNextPage:o,onPrevPage:l}){let{t:a}=i18n.useTranslation(),u=react.useMemo(()=>e.map(d=>({key:d.tradeId,ticker:d.ticker,takerSide:d.takerSide,price:d.price,yesPrice:d.yesPrice,noPrice:d.noPrice,count:d.count,createdAt:il(d.createdTime)})),[e]);return t?jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsx("div",{className:"border-b border-default-200 px-3 py-2 text-sm font-medium",children:a("predict.tradeHistory.title")}),jsxRuntime.jsx("div",{className:"flex flex-col gap-y-2 p-3",children:Array.from({length:3}).map((d,m)=>jsxRuntime.jsx("div",{className:"h-8 animate-pulse rounded bg-default-100"},m))})]}):jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsx("div",{className:"border-b border-default-200 px-3 py-2 text-sm font-medium",children:a("predict.tradeHistory.title")}),e.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-default-400",children:a("predict.tradeHistory.empty")}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:`w-full overflow-x-auto ${r?"opacity-60":""}`,children:jsxRuntime.jsxs(ui.StyledTable,{radius:"none","aria-label":"Trade history",className:"min-w-[480px]",children:[jsxRuntime.jsxs(ui.TableHeader,{children:[jsxRuntime.jsx(ui.TableColumn,{textValue:"Side",width:60,children:a("predict.tradeHistory.side")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Price",width:80,children:a("predict.tradeHistory.price")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Yes",width:60,children:a("predict.trade.yes")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"No",width:60,children:a("predict.trade.no")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Qty",width:60,children:a("predict.tradeHistory.qty")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Time",width:120,children:a("predict.tradeHistory.time")})]}),jsxRuntime.jsx(ui.TableBody,{children:u.map(d=>jsxRuntime.jsxs(ui.TableRow,{children:[jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:`text-xs font-medium ${d.takerSide==="yes"?"text-primary":"text-secondary"}`,children:d.takerSide==="yes"?a("predict.trade.yes"):a("predict.trade.no")})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("span",{className:"text-xs",children:[d.price,"\xA2"]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("span",{className:"text-xs text-primary",children:[d.yesPrice,"\xA2"]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("span",{className:"text-xs text-secondary",children:[d.noPrice,"\xA2"]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs",children:d.count})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs text-default-500",children:d.createdAt})})]},d.key))})]})}),(i||s)&&jsxRuntime.jsxs("div",{className:"flex items-center justify-between border-t border-default-200 px-3 py-2",children:[jsxRuntime.jsx(ui.Button,{size:"sm",variant:"flat",isDisabled:!i,onPress:l,startContent:jsxRuntime.jsx(ui.ChevronLeftIcon,{className:"h-3 w-3"}),children:a("predict.pagination.prev")}),jsxRuntime.jsx("span",{className:"text-xs text-default-500",children:a("predict.pagination.page",{page:n})}),jsxRuntime.jsx(ui.Button,{size:"sm",variant:"flat",isDisabled:!s,onPress:o,endContent:jsxRuntime.jsx(ui.ChevronRightIcon,{className:"h-3 w-3"}),children:a("predict.pagination.next")})]})]})]})}function If({ticker:e,pageSize:t}={}){let{trades:r,isLoading:n,isFetching:s,page:i,hasNextPage:o,hasPrevPage:l,nextPage:a,prevPage:u}=hn({ticker:e,pageSize:t});return jsxRuntime.jsx(Cn,{trades:r,isLoading:n,isFetching:s,page:i,hasNextPage:o,hasPrevPage:l,onNextPage:a,onPrevPage:u})}function Sn(e={}){let t=react.useMemo(()=>({totalValue:0,totalUnrealizedPnl:0,totalRealizedPnl:0,count:0}),[]);return {positions:[],isLoading:false,isFetching:false,summary:t}}var Ve=e=>utils.formatAmountUSDCompact(e/100);function Ot({value:e}){if(e===0)return jsxRuntime.jsx("span",{className:"text-default-500",children:Ve(0)});let t=e>0;return jsxRuntime.jsxs("span",{className:t?"text-success":"text-danger",children:[t?"+":"",Ve(e)]})}function wn({positions:e,isLoading:t,summary:r,onSell:n}){let{t:s}=i18n.useTranslation(),i=react.useMemo(()=>e.map(o=>({key:`${o.marketId}-${o.outcome}`,marketTitle:o.marketTitle,outcome:o.outcome,quantity:o.quantity,avgCost:o.avgCostBasis,currentPrice:o.currentPrice,value:o.currentPrice*o.quantity,unrealizedPnl:o.unrealizedPnl,position:o})),[e]);return t?jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsx("div",{className:"border-b border-default-200 px-3 py-2 text-sm font-medium",children:s("predict.positions.title")}),jsxRuntime.jsx("div",{className:"flex flex-col gap-y-2 p-3",children:Array.from({length:3}).map((o,l)=>jsxRuntime.jsx("div",{className:"h-8 animate-pulse rounded bg-default-100"},l))})]}):jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsx("div",{className:"flex items-center justify-between border-b border-default-200 px-3 py-2",children:jsxRuntime.jsxs("span",{className:"text-sm font-medium",children:[s("predict.positions.title"),e.length>0&&jsxRuntime.jsxs("span",{className:"ml-1 text-default-400",children:["(",e.length,")"]})]})}),e.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-default-400",children:s("predict.positions.empty")}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"w-full overflow-x-auto",children:jsxRuntime.jsxs(ui.StyledTable,{radius:"none","aria-label":"Positions",className:"min-w-[640px]",children:[jsxRuntime.jsxs(ui.TableHeader,{children:[jsxRuntime.jsx(ui.TableColumn,{textValue:"Market",width:200,children:s("predict.positions.market")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Outcome",width:60,children:s("predict.positions.outcome")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Qty",width:50,children:s("predict.positions.qty")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Avg Cost",width:70,children:s("predict.positions.avgCost")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Price",width:60,children:s("predict.positions.currentPrice")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Value",width:80,children:s("predict.positions.value")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"PnL",width:80,children:s("predict.positions.pnl")})]}),jsxRuntime.jsx(ui.TableBody,{children:i.map(o=>jsxRuntime.jsxs(ui.TableRow,{className:n?"cursor-pointer hover:bg-default-50":"",onClick:()=>n?.(o.position),children:[jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs font-medium line-clamp-1",children:o.marketTitle})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:`text-xs font-medium ${o.outcome==="yes"?"text-primary":"text-secondary"}`,children:o.outcome==="yes"?s("predict.trade.yes"):s("predict.trade.no")})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs",children:o.quantity})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("span",{className:"text-xs",children:[o.avgCost,"\xA2"]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("span",{className:"text-xs",children:[o.currentPrice,"\xA2"]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs",children:Ve(o.value)})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs",children:jsxRuntime.jsx(Ot,{value:o.unrealizedPnl})})})]},o.key))})]})}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between border-t border-default-200 px-3 py-2 text-xs",children:[jsxRuntime.jsx("div",{className:"flex items-center gap-x-4",children:jsxRuntime.jsxs("span",{className:"text-default-500",children:[s("predict.positions.totalValue"),":"," ",jsxRuntime.jsx("span",{className:"font-medium text-foreground",children:Ve(r.totalValue)})]})}),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-4",children:[jsxRuntime.jsxs("span",{className:"text-default-500",children:[s("predict.positions.unrealizedPnl"),":"," ",jsxRuntime.jsx(Ot,{value:r.totalUnrealizedPnl})]}),jsxRuntime.jsxs("span",{className:"text-default-500",children:[s("predict.positions.realizedPnl"),":"," ",jsxRuntime.jsx(Ot,{value:r.totalRealizedPnl})]})]})]})]})]})}function Yf({refetchInterval:e,onSell:t}={}){let{positions:r,isLoading:n,summary:s}=Sn({});return jsxRuntime.jsx(wn,{positions:r,isLoading:n,summary:s,onSell:t})}function xg({client:e,wsClient:t=null,children:r}){let n=react.useMemo(()=>({client:e,wsClient:t}),[e,t]);return jsxRuntime.jsx(ke.Provider,{value:n,children:r})}function Rn(e,t){let r=new URLSearchParams;t&&r.set("provider",t);for(let[s,i]of Object.entries(e))i!=null&&(typeof i=="object"?r.set(s,JSON.stringify(i)):r.set(s,String(i)));let n=r.toString();return n?`?${n}`:""}function Mn(e){return e}var Oe=class{constructor(t,r){this.endpoint=t;this.provider=r;}buildUrl(t,r){let n=Rn(r??{},this.provider);return `${this.endpoint}${t}${n}`}async fetch(t,r){let n=this.buildUrl(t,r);return await utils.httpGet(n)}async postRequest(t,r,n){let s=this.buildUrl(t,n);return await utils.httpPost(s,r)}};function ze(e,t){if(!e)return [];let r=Object.entries(e).map(([n,s])=>({price:parseFloat(n),quantity:s}));return r.sort((n,s)=>t==="desc"?s.price-n.price:n.price-s.price),r}function Tn(e){return {yesBids:ze(e.yes_bids,"desc"),yesAsks:ze(e.yes_asks,"asc"),noBids:ze(e.no_bids,"desc"),noAsks:ze(e.no_asks,"asc"),sequence:e.sequence}}var Ge=class extends Oe{constructor(t){super(t,"dflow");}async getEvents(t){return await this.fetch("/v2/event",t??{})}async getEventById(t,r){return await this.fetch(`/v2/event/${t}`,{withNestedMarkets:r})}async getEventCandlesticks(t,r){return await this.fetch(`/v2/event/${t}/candlesticks`,r)}async getEventForecastPercentileHistory(t){let{seriesTicker:r,eventId:n,...s}=t;return await this.fetch(`/v2/event/${r}/${n}/forecast_percentile_history`,s)}async getEventForecastPercentileHistoryByMint(t){let{mintAddress:r,...n}=t;return await this.fetch(`/v2/event/by-mint/${r}/forecast_percentile_history`,n)}async getMarkets(t){return await this.fetch("/v2/market",t??{})}async getMarketById(t){return await this.fetch(`/v2/market/${t}`)}async getMarketByMint(t){return await this.fetch(`/v2/market/by-mint/${t}`)}async getMarketsBatch(t){return await this.postRequest("/v2/market/batch",t)}async getMarketCandlesticks(t,r){return await this.fetch(`/v2/market/${t}/candlesticks`,r)}async getMarketCandlesticksByMint(t,r){return await this.fetch(`/v2/market/by-mint/${t}/candlesticks`,r)}async getOrderbook(t){let r=await this.fetch(`/v2/orderbook/${t}`);return Tn(r)}async getOrderbookByMint(t){let r=await this.fetch(`/v2/orderbook/by-mint/${t}`);return Tn(r)}async getTrades(t){return await this.fetch("/v2/trades",t??{})}async getTradesByMint(t){let{mintAddress:r,...n}=t;return await this.fetch(`/v2/trades/by-mint/${r}`,n)}async getLiveData(t){return await this.fetch("/v2/live",{milestoneIds:t.milestoneIds.join(",")})}async getLiveDataByEvent(t){let{eventTicker:r,...n}=t;return await this.fetch(`/v2/live/event/${r}`,n)}async getLiveDataByMint(t){let{mintAddress:r,...n}=t;return await this.fetch(`/v2/live/by-mint/${r}`,n)}async getSeries(t){return await this.fetch("/v2/series",t??{})}async getSeriesByTicker(t){return await this.fetch(`/v2/series/${t}`)}async getTagsByCategories(){return await this.fetch("/v2/tags/by_categories")}async getFiltersBySports(){return await this.fetch("/v2/sports/filters")}async search(t){return await this.fetch("/v2/search",t)}async getOutcomeMints(t){return await this.fetch("/v2/outcome_mints",t??{})}async filterOutcomeMints(t){return await this.postRequest("/v2/filter_outcome_mints",t)}async getQuote(t){return await this.fetch("/v2/swap/quote",t)}async createSwap(t){return await this.postRequest("/v2/swap",t)}async createSwapInstructions(t){return await this.postRequest("/v2/swap/instructions",t)}async getOrder(t){return await this.fetch("/v2/order",t)}async getOrderStatus(t){return await this.fetch("/v2/order/status",t)}async getIntentQuote(t){return await this.fetch("/v2/intent/quote",t)}async submitIntentSwap(t){return await this.postRequest("/v2/intent/swap",t)}async initPredictionMarket(t){return await this.fetch("/v2/prediction-market/init",t)}async getTokens(){return await this.fetch("/v2/tokens")}async getTokensWithDecimals(){return await this.fetch("/v2/tokens/decimals")}async getVenues(){return await this.fetch("/v2/venues")}};
2
- exports.BasePredictClient=Oe;exports.CHART_RANGE_DURATION=We;exports.CHART_RANGE_PERIOD=_e;exports.CHART_RANGE_SAMPLE_INTERVAL=Fe;exports.CandlestickPeriod=De;exports.CategoriesSkeleton=cr;exports.CategoriesUI=lr;exports.CategoriesWidget=mr;exports.ChartRange=w;exports.DEFAULT_CHART_RANGE=ce;exports.DEFAULT_PAGE_SIZE=fe;exports.DEFAULT_PRICE_HISTORY_INTERVAL=Dd;exports.DflowPredictClient=Ge;exports.DflowPredictWsClient=Me;exports.EventDetailPage=Ny;exports.EventDetailSkeleton=Ne;exports.EventDetailUI=cn;exports.EventDetailWidget=Tt;exports.EventItemSkeleton=Oo;exports.EventItemUI=vr;exports.EventMarketDetailWidget=Xr;exports.EventsPage=kp;exports.EventsSkeleton=fr;exports.EventsUI=Pr;exports.EventsWidget=Sr;exports.MAX_PRICE_HISTORY_MARKETS=le;exports.ORDER_MAX_PRICE=Ad;exports.ORDER_MIN_PRICE=Ud;exports.ORDER_MIN_QUANTITY=ct;exports.ORDER_PRICE_STEP=Ld;exports.OpenOrdersUI=vn;exports.OpenOrdersWidget=yf;exports.OrderBookUI=gn;exports.OrderBookWidget=Xy;exports.PRICE_HISTORY_SAMPLE_INTERVAL=_d;exports.PositionsUI=wn;exports.PositionsWidget=Yf;exports.PredictClient=Ge;exports.PredictContext=ke;exports.PredictProvider=xg;exports.PredictWsClient=Me;exports.PriceHistoryInterval=Pe;exports.TradeFormSkeleton=Or;exports.TradeFormUI=Er;exports.TradeFormWidget=ft;exports.TradeHistoryUI=Cn;exports.TradeHistoryWidget=If;exports.buildQuery=Rn;exports.createDflowPredictWsClient=Ue;exports.createPredictWsClient=Ue;exports.createSwap=js;exports.createSwapInstructions=Xs;exports.eventByIdQueryKey=Yn;exports.eventCandlesticksQueryKey=xs;exports.eventsInfiniteQueryKey=zn;exports.eventsQueryKey=$n;exports.fetchEventById=jn;exports.fetchEventCandlesticks=bs;exports.fetchEvents=tt;exports.fetchFiltersBySports=Ds;exports.fetchForecastPercentileHistory=Ps;exports.fetchForecastPercentileHistoryByMint=Ss;exports.fetchIntentQuote=oo;exports.fetchLiveData=Rs;exports.fetchLiveDataByEvent=Ts;exports.fetchLiveDataByMint=Es;exports.fetchMarketById=rs;exports.fetchMarketByMint=os;exports.fetchMarketCandlesticks=st;exports.fetchMarketCandlesticksByMint=ks;exports.fetchMarkets=Jn;exports.fetchMarketsBatch=ls;exports.fetchOrder=Js;exports.fetchOrderBook=us;exports.fetchOrderBookByMint=ps;exports.fetchOrderStatus=to;exports.fetchOutcomeMints=$s;exports.fetchQuote=Ys;exports.fetchSearch=Ws;exports.fetchSeries=Is;exports.fetchSeriesByTicker=Bs;exports.fetchTagsByCategories=Us;exports.fetchTokens=uo;exports.fetchTokensWithDecimals=mo;exports.fetchTrades=ys;exports.fetchTradesByMint=gs;exports.fetchVenues=go;exports.filterOutcomeMints=Vs;exports.filtersBySportsQueryKey=As;exports.forecastPercentileHistoryByMintQueryKey=Cs;exports.forecastPercentileHistoryQueryKey=hs;exports.initPredictionMarket=lo;exports.intentQuoteQueryKey=so;exports.liveDataByEventQueryKey=Ms;exports.liveDataByMintQueryKey=Ns;exports.liveDataQueryKey=ws;exports.marketByIdQueryKey=ts;exports.marketByMintQueryKey=ss;exports.marketCandlesticksByMintQueryKey=vs;exports.marketCandlesticksQueryKey=nt;exports.marketsBatchQueryKey=is;exports.marketsQueryKey=Zn;exports.orderBookByMintQueryKey=ds;exports.orderBookQueryKey=cs;exports.orderQueryKey=Zs;exports.orderStatusQueryKey=eo;exports.outcomeMintsQueryKey=Ks;exports.quoteQueryKey=Gs;exports.searchQueryKey=Fs;exports.seriesByTickerQueryKey=Qs;exports.seriesQueryKey=Os;exports.submitIntentSwap=ao;exports.tagsByCategoriesQueryKey=Ls;exports.toRecord=Mn;exports.tokensQueryKey=co;exports.tokensWithDecimalsQueryKey=po;exports.tradesByMintQueryKey=fs;exports.tradesQueryKey=ms;exports.useCategoriesQuery=Dc;exports.useCreateSwapInstructionsMutation=ru;exports.useCreateSwapMutation=tu;exports.useEventByIdQuery=Le;exports.useEventCandlesticksQuery=xc;exports.useEventDetail=Ir;exports.useEvents=yr;exports.useEventsCategories=or;exports.useEventsInfiniteQuery=At;exports.useEventsQuery=Ul;exports.useFilterOutcomeMintsMutation=zc;exports.useFiltersBySportsQuery=Ac;exports.useForecastPercentileHistoryByMintQuery=Sc;exports.useForecastPercentileHistoryQuery=Cc;exports.useInitPredictionMarketMutation=fu;exports.useIntentQuoteQuery=uu;exports.useLiveDataByEventQuery=Nc;exports.useLiveDataByMintQuery=Ec;exports.useLiveDataQuery=Tc;exports.useMarketByIdQuery=Xl;exports.useMarketByMintQuery=tc;exports.useMarketCandlesticksByMintQuery=bc;exports.useMarketCandlesticksQuery=ot;exports.useMarketsBatchQuery=oc;exports.useMarketsQuery=zl;exports.useOpenOrders=bn;exports.useOrderBook=mn;exports.useOrderBookByMintQuery=cc;exports.useOrderBookQuery=he;exports.useOrderQuery=Gt;exports.useOrderStatusQuery=au;exports.useOrderbookSubscription=Hu;exports.useOutcomeMintsQuery=Vc;exports.usePositions=Sn;exports.usePredictClient=v;exports.usePredictContext=Ut;exports.usePriceHistoryQuery=vc;exports.usePricesSubscription=Au;exports.useQuoteQuery=Xc;exports.useSearchQuery=qc;exports.useSeriesByTickerQuery=Kt;exports.useSeriesQuery=Ht;exports.useSubmitIntentSwapMutation=du;exports.useTagsByCategoriesQuery=it;exports.useTokensQuery=vu;exports.useTokensWithDecimalsQuery=ku;exports.useTradeForm=Rr;exports.useTradeHistory=hn;exports.useTradesByMintQuery=mc;exports.useTradesQuery=Ft;exports.useTradesSubscription=Fu;exports.useVenuesQuery=Su;exports.useWsClient=Bu;exports.useWsConnection=Eu;exports.venuesQueryKey=fo;exports.version=Wn;//# sourceMappingURL=index.js.map
1
+ 'use strict';var react=require('react'),reactQuery=require('@tanstack/react-query'),i18n=require('@liberfi.io/i18n'),ui=require('@liberfi.io/ui'),jsxRuntime=require('react/jsx-runtime'),reactWindow=require('react-window'),reactWindowInfiniteLoader=require('react-window-infinite-loader'),hooks=require('@liberfi.io/hooks'),utils=require('@liberfi.io/utils'),walletConnector=require('@liberfi.io/wallet-connector'),Tt=require('canvas-confetti'),react$1=require('@liberfi.io/react'),types=require('@liberfi.io/types'),recharts=require('recharts');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var Tt__default=/*#__PURE__*/_interopDefault(Tt);typeof window<"u"&&(window.__LIBERFI_VERSION__=window.__LIBERFI_VERSION__||{},window.__LIBERFI_VERSION__["@liberfi.io/ui-predict"]="0.1.48");var ss="0.1.48";var Te=react.createContext({});var Me=react.createContext(null);function zt(){let e=react.useContext(Te);if(!e)throw new Error("usePredictContext must be used within a PredictProvider");return e}function h(){let{client:e}=zt();return e}function cs(e){return ["predict","events",e??{}]}async function it(e,t){return await e.getEvents(t)}function Nc(e,t={}){let r=h();return reactQuery.useQuery({queryKey:cs(e),queryFn:async()=>it(r,e),...t})}function ds(e){return ["predict","events","infinite",e??{}]}function Yt(e={},t={}){let r=h();return reactQuery.useInfiniteQuery({queryKey:ds(e),queryFn:async({pageParam:n})=>it(r,{...e,...n!==void 0?{cursor:n}:{}}),initialPageParam:void 0,getNextPageParam:n=>n.cursor??void 0,...t})}function ms(e){return ["predict","event","byId",e.id,e.withNestedMarkets]}async function ys(e,t){return await e.getEventById(t.id,t.withNestedMarkets)}function Fe(e,t={}){let r=h();return reactQuery.useQuery({queryKey:ms(e),queryFn:async()=>ys(r,e),...t})}function gs(e){return ["predict","markets",e??{}]}async function xs(e,t){return await e.getMarkets(t)}function Fc(e,t={}){let r=h();return reactQuery.useQuery({queryKey:gs(e),queryFn:async()=>xs(r,e),...t})}function bs(e){return ["predict","market","byId",e.id]}async function vs(e,t){return await e.getMarketById(t.id)}function $c(e,t={}){let r=h();return reactQuery.useQuery({queryKey:bs(e),queryFn:async()=>vs(r,e),...t})}function Ps(e){return ["predict","market","byMint",e]}async function Cs(e,t){return await e.getMarketByMint(t)}function Gc(e,t={}){let r=h();return reactQuery.useQuery({queryKey:Ps(e),queryFn:async()=>Cs(r,e),...t})}function Ts(e){return ["predict","markets","batch",e]}async function Ms(e,t){return await e.getMarketsBatch(t)}function Jc(e,t={}){let r=h();return reactQuery.useQuery({queryKey:Ts(e),queryFn:async()=>Ms(r,e),enabled:!!(e.tickers?.length||e.mints?.length),...t})}function ws(e){return ["predict","orderBook",e]}async function Rs(e,t){return await e.getOrderbook(t)}function we(e,t={}){let r=h();return reactQuery.useQuery({queryKey:ws(e),queryFn:async()=>Rs(r,e),...t})}function Os(e){return ["predict","orderBook","byMint",e]}async function Ns(e,t){return await e.getOrderbookByMint(t)}function nu(e,t={}){let r=h();return reactQuery.useQuery({queryKey:Os(e),queryFn:async()=>Ns(r,e),...t})}function Es(e){return ["predict","trades",e??{}]}async function Is(e,t){return await e.getTrades(t)}function Xt(e,t={}){let r=h();return reactQuery.useQuery({queryKey:Es(e),queryFn:async()=>Is(r,e),...t})}function Qs(e){return ["predict","trades","byMint",e]}async function Bs(e,t){return await e.getTradesByMint(t)}function iu(e,t={}){let r=h();return reactQuery.useQuery({queryKey:Qs(e),queryFn:async()=>Bs(r,e),...t})}function Ls(e){return ["predict","onchainTrades","byWallet",e]}async function ct(e,t){return await e.getOnchainTradesByWallet(t)}function Zt(e,t={}){let r=h();return reactQuery.useQuery({queryKey:Ls(e),queryFn:async()=>ct(r,e),...t})}function Us(e){return ["predict","onchainTrades","byEvent",e]}async function ut(e,t){return await e.getOnchainTradesByEvent(t)}function du(e,t={}){let r=h();return reactQuery.useQuery({queryKey:Us(e),queryFn:async()=>ut(r,e),...t})}function As(e){return ["predict","onchainTrades","byMarket",e]}async function dt(e,t){return await e.getOnchainTradesByMarket(t)}function pu(e,t={}){let r=h();return reactQuery.useQuery({queryKey:As(e),queryFn:async()=>dt(r,e),...t})}function mt(e){return e.cursor??void 0}function Ds(e){return ["predict","onchainTrades","byWallet","infinite",e]}function xu(e,t={}){let r=h();return reactQuery.useInfiniteQuery({queryKey:Ds(e),queryFn:async({pageParam:n})=>ct(r,{...e,...n!==void 0?{cursor:n}:{}}),initialPageParam:void 0,getNextPageParam:mt,...t})}function Ws(e){return ["predict","onchainTrades","byEvent","infinite",e]}function hu(e,t={}){let r=h();return reactQuery.useInfiniteQuery({queryKey:Ws(e),queryFn:async({pageParam:n})=>ut(r,{...e,...n!==void 0?{cursor:n}:{}}),initialPageParam:void 0,getNextPageParam:mt,...t})}function _s(e){return ["predict","onchainTrades","byMarket","infinite",e]}function bu(e,t={}){let r=h();return reactQuery.useInfiniteQuery({queryKey:_s(e),queryFn:async({pageParam:n})=>dt(r,{...e,...n!==void 0?{cursor:n}:{}}),initialPageParam:void 0,getNextPageParam:mt,...t})}function Fs(e){return ["predict","candlesticks","event",e]}async function qs(e,t){let{ticker:r,...n}=t;return await e.getEventCandlesticks(r,n)}function Cu(e,t={}){let r=h();return reactQuery.useQuery({queryKey:Fs(e),queryFn:async()=>qs(r,e),...t})}function ft(e){return ["predict","candlesticks","market",e]}async function gt(e,t){let{ticker:r,...n}=t;return await e.getMarketCandlesticks(r,n)}function xt(e,t={}){let r=h();return reactQuery.useQuery({queryKey:ft(e),queryFn:async()=>gt(r,e),...t})}function Ks(e){return ["predict","candlesticks","market","byMint",e]}async function Hs(e,t){let{mintAddress:r,...n}=t;return await e.getMarketCandlesticksByMint(r,n)}function Su(e,t={}){let r=h();return reactQuery.useQuery({queryKey:Ks(e),queryFn:async()=>Hs(r,e),...t})}var Tu=xt;function $s(e){return ["predict","forecast","percentileHistory",e]}async function Vs(e,t){return await e.getEventForecastPercentileHistory(t)}function Ou(e,t={}){let r=h();return reactQuery.useQuery({queryKey:$s(e),queryFn:async()=>Vs(r,e),...t})}function zs(e){return ["predict","forecast","percentileHistory","byMint",e]}async function Ys(e,t){return await e.getEventForecastPercentileHistoryByMint(t)}function Nu(e,t={}){let r=h();return reactQuery.useQuery({queryKey:zs(e),queryFn:async()=>Ys(r,e),...t})}function Gs(e){return ["predict","liveData",e]}async function js(e,t){return await e.getLiveData(t)}function Bu(e,t={}){let r=h();return reactQuery.useQuery({queryKey:Gs(e),queryFn:async()=>js(r,e),enabled:e.milestoneIds.length>0,...t})}function Xs(e){return ["predict","liveData","byEvent",e]}async function Zs(e,t){return await e.getLiveDataByEvent(t)}function Lu(e,t={}){let r=h();return reactQuery.useQuery({queryKey:Xs(e),queryFn:async()=>Zs(r,e),enabled:!!e.eventTicker,...t})}function Js(e){return ["predict","liveData","byMint",e]}async function eo(e,t){return await e.getLiveDataByMint(t)}function Uu(e,t={}){let r=h();return reactQuery.useQuery({queryKey:Js(e),queryFn:async()=>eo(r,e),enabled:!!e.mintAddress,...t})}function to(e){return ["predict","series",e??{}]}async function ro(e,t){return await e.getSeries(t)}function tr(e,t={}){let r=h();return reactQuery.useQuery({queryKey:to(e),queryFn:async()=>ro(r,e),...t})}function no(e){return ["predict","series","byTicker",e]}async function so(e,t){return await e.getSeriesByTicker(t)}function rr(e,t={}){let r=h();return reactQuery.useQuery({queryKey:no(e),queryFn:async()=>so(r,e),...t})}function oo(){return ["predict","tags","byCategories"]}async function ao(e){return await e.getTagsByCategories()}function bt(e={}){let t=h();return reactQuery.useQuery({queryKey:oo(),queryFn:async()=>ao(t),...e})}function io(){return ["predict","filters","bySports"]}async function lo(e){return await e.getFiltersBySports()}function Ku(e={}){let t=h();return reactQuery.useQuery({queryKey:io(),queryFn:async()=>lo(t),...e})}var Hu=bt;function uo(e){return ["predict","search",e]}async function po(e,t){return await e.search(t)}function Yu(e,t={}){let r=h();return reactQuery.useQuery({queryKey:uo(e),queryFn:async()=>po(r,e),...t})}function yo(e){return ["predict","positions","byWallet",e]}async function fo(e,t){return await e.getPositionsByWallet(t)}function sr(e,t={}){let r=h();return reactQuery.useQuery({queryKey:yo(e),queryFn:async()=>fo(r,e),...t})}function td(){let e=react.useContext(Me);if(!e)throw new Error("useUserPredictContext must be used within a UserPredictProvider");return e}function or(e){let t=react.useContext(Me);return react.useMemo(()=>t?{positions:t.positions.filter(n=>n.market?.ticker===e.ticker),isLoading:t.isLoading,isAvailable:true}:{positions:[],isLoading:false,isAvailable:false},[t,e.ticker])}function ko(e){return ["predict","outcomeMints",e??{}]}async function Po(e,t){return await e.getOutcomeMints(t)}function ld(e,t={}){let r=h();return reactQuery.useQuery({queryKey:ko(e),queryFn:async()=>Po(r,e),...t})}async function Co(e,t){return await e.filterOutcomeMints(t)}function cd(e={}){let t=h();return reactQuery.useMutation({mutationFn:async r=>Co(t,r),...e})}function To(e){return ["predict","quote",e]}async function Mo(e,t){return await e.getQuote(t)}function md(e,t={}){let r=h();return reactQuery.useQuery({queryKey:To(e),queryFn:async()=>Mo(r,e),enabled:!!(e.inputMint&&e.outputMint&&e.amount>0),staleTime:1e4,gcTime:3e4,...t})}async function wo(e,t){return await e.createSwap(t)}function xd(e={}){let t=h();return reactQuery.useMutation({mutationFn:async r=>wo(t,r),...e})}async function Ro(e,t){return await e.createSwapInstructions(t)}function hd(e={}){let t=h();return reactQuery.useMutation({mutationFn:async r=>Ro(t,r),...e})}function Oo(e){return ["predict","order",e]}async function No(e,t){return await e.getOrder(t)}function lr(e,t={}){let r=h();return reactQuery.useQuery({queryKey:Oo(e),queryFn:async()=>No(r,e),enabled:!!(e.inputMint&&e.outputMint&&e.amount>0),staleTime:1e4,gcTime:3e4,...t})}function Eo(e){return ["predict","order","status",e.signature]}async function Io(e,t){return await e.getOrderStatus(t)}function Pd(e,t={}){let r=h();return reactQuery.useQuery({queryKey:Eo(e),queryFn:async()=>Io(r,e),enabled:!!e.signature,refetchInterval:t.refetchInterval??3e3,...t})}function Lo(e){return ["predict","intent","quote",e]}async function Uo(e,t){return await e.getIntentQuote(t)}function Md(e,t={}){let r=h();return reactQuery.useQuery({queryKey:Lo(e),queryFn:async()=>Uo(r,e),enabled:!!(e.inputMint&&e.outputMint&&e.amount>0),staleTime:1e4,gcTime:3e4,...t})}async function Ao(e,t){return await e.submitIntentSwap(t)}function wd(e={}){let t=h();return reactQuery.useMutation({mutationFn:async r=>Ao(t,r),...e})}async function Wo(e,t){return await e.initPredictionMarket(t)}function Ed(e={}){let t=h();return reactQuery.useMutation({mutationFn:async r=>Wo(t,r),...e})}function _o(){return ["predict","tokens"]}async function Fo(e){return await e.getTokens()}function Ld(e={}){let t=h();return reactQuery.useQuery({queryKey:_o(),queryFn:async()=>Fo(t),staleTime:300*1e3,gcTime:1800*1e3,...e})}function qo(){return ["predict","tokens","decimals"]}async function Ko(e){return await e.getTokensWithDecimals()}function Ud(e={}){let t=h();return reactQuery.useQuery({queryKey:qo(),queryFn:async()=>Ko(t),staleTime:300*1e3,gcTime:1800*1e3,...e})}function $o(){return ["predict","venues"]}async function Vo(e){return await e.getVenues()}function _d(e={}){let t=h();return reactQuery.useQuery({queryKey:$o(),queryFn:async()=>Vo(t),staleTime:300*1e3,gcTime:1800*1e3,...e})}var Ie=class{ws=null;wsUrl;autoReconnect;reconnectIntervalBase;reconnectMaxInterval;pingInterval;status="disconnected";reconnectAttempts=0;reconnectTimeout=null;pingIntervalId=null;shouldReconnect=true;listeners={connect:[],disconnect:[],reconnecting:[],error:[],price:[],trade:[],orderbook:[],status:[],subscribed:[],unsubscribed:[]};subscriptions={prices:{all:false,tickers:new Set},trades:{all:false,tickers:new Set},orderbook:{all:false,tickers:new Set}};constructor(t){this.wsUrl=t.wsUrl,this.autoReconnect=t.autoReconnect??true,this.reconnectIntervalBase=t.reconnectIntervalBase??1e3,this.reconnectMaxInterval=t.reconnectMaxInterval??3e4,this.pingInterval=t.pingInterval??3e4,t.autoConnect!==false&&this.connect();}connect(){if(!(this.ws&&(this.ws.readyState===WebSocket.OPEN||this.ws.readyState===WebSocket.CONNECTING))){this.shouldReconnect=true,this.setStatus("connecting");try{this.ws=new WebSocket(this.wsUrl),this.ws.onopen=()=>{this.reconnectAttempts=0,this.setStatus("connected"),this.emit("connect",void 0),this.restoreSubscriptions(),this.startPingInterval();},this.ws.onmessage=t=>{this.handleMessage(t.data);},this.ws.onerror=t=>{let r=new Error("WebSocket error");this.emit("error",r);},this.ws.onclose=t=>{this.stopPingInterval(),this.setStatus("disconnected"),this.emit("disconnect",{code:t.code,reason:t.reason}),this.shouldReconnect&&this.autoReconnect&&this.scheduleReconnect();};}catch(t){this.emit("error",t instanceof Error?t:new Error(String(t))),this.shouldReconnect&&this.autoReconnect&&this.scheduleReconnect();}}}disconnect(){this.shouldReconnect=false,this.stopPingInterval(),this.reconnectTimeout&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=null),this.ws&&(this.ws.close(),this.ws=null),this.setStatus("disconnected");}isConnected(){return this.ws!==null&&this.ws.readyState===WebSocket.OPEN}getStatus(){return this.status}subscribePrices(t,r){this.subscribeChannel("prices",t);let n=this.on("price",r);return ()=>{n(),this.unsubscribeChannel("prices",t);}}subscribeTrades(t,r){this.subscribeChannel("trades",t);let n=this.on("trade",r);return ()=>{n(),this.unsubscribeChannel("trades",t);}}subscribeOrderbook(t,r){this.subscribeChannel("orderbook",t);let n=this.on("orderbook",r);return ()=>{n(),this.unsubscribeChannel("orderbook",t);}}onStatusChange(t){return this.on("status",t)}on(t,r){return this.listeners[t].push(r),()=>{this.off(t,r);}}off(t,r){let n=this.listeners[t],s=n.indexOf(r);s!==-1&&n.splice(s,1);}removeAllListeners(t){if(t)this.listeners[t].length=0;else for(let r of Object.keys(this.listeners))this.listeners[r].length=0;}subscribeChannel(t,r){let n=this.subscriptions[t];if(r.all)n.all=true,n.tickers.clear();else if(r.tickers&&r.tickers.length>0){n.all=false;for(let s of r.tickers)n.tickers.add(s);}this.sendSubscription("subscribe",t,r);}unsubscribeChannel(t,r){let n=this.subscriptions[t];if(r.all)n.all=false,n.tickers.clear();else if(r.tickers&&r.tickers.length>0)for(let s of r.tickers)n.tickers.delete(s);this.sendSubscription("unsubscribe",t,r);}setStatus(t){this.status!==t&&(this.status=t,this.emit("status",t));}emit(t,r){let n=this.listeners[t];for(let s of n)try{s(r);}catch{}}send(t){if(!this.ws||this.ws.readyState!==WebSocket.OPEN)return false;try{return this.ws.send(JSON.stringify(t)),!0}catch{return false}}sendSubscription(t,r,n){this.send({type:t,channel:r,all:n.all,tickers:n.tickers});}handleMessage(t){try{let r=JSON.parse(t);switch(r.type){case "ticker":this.emit("price",r);break;case "trade":this.emit("trade",r);break;case "orderbook":this.emit("orderbook",r);break;case "status":break;case "subscribed":this.emit("subscribed",{channel:r.channel,all:r.all,tickers:r.tickers});break;case "unsubscribed":this.emit("unsubscribed",{channel:r.channel,all:r.all,tickers:r.tickers});break;case "pong":break;case "error":this.emit("error",new Error(r.message));break;default:if("channel"in r){let n=r;switch(n.channel){case "prices":this.emit("price",n);break;case "trades":this.emit("trade",n);break;case "orderbook":this.emit("orderbook",n);break}}}}catch{}}scheduleReconnect(){if(this.reconnectTimeout)return;let t=Math.min(this.reconnectIntervalBase*Math.pow(2,this.reconnectAttempts),this.reconnectMaxInterval);this.setStatus("reconnecting"),this.emit("reconnecting",{attempt:this.reconnectAttempts+1,delay:t}),this.reconnectTimeout=setTimeout(()=>{this.reconnectTimeout=null,this.reconnectAttempts++,this.connect();},t);}restoreSubscriptions(){for(let t of ["prices","trades","orderbook"]){let r=this.subscriptions[t];r.all?this.sendSubscription("subscribe",t,{all:true}):r.tickers.size>0&&this.sendSubscription("subscribe",t,{tickers:Array.from(r.tickers)});}}startPingInterval(){this.stopPingInterval(),this.pingIntervalId=setInterval(()=>{this.send({type:"ping"});},this.pingInterval);}stopPingInterval(){this.pingIntervalId&&(clearInterval(this.pingIntervalId),this.pingIntervalId=null);}};function qe(e){return new Ie(e)}function Vd({wsEndpoint:e,autoConnect:t=true,autoReconnect:r=true,enabled:n=true}){let[s,i]=react.useState("disconnected"),[o,l]=react.useState(null),a=react.useRef(null);react.useEffect(()=>{if(!n){a.current&&(a.current.disconnect(),a.current=null),i("disconnected");return}let p=qe({wsUrl:e,autoConnect:t,autoReconnect:r});a.current=p;let f=p.on("status",g=>{i(g);}),d=p.on("error",g=>{l(g);}),b=p.on("connect",()=>{l(null);});return ()=>{f(),d(),b(),p.disconnect(),a.current=null;}},[e,t,r,n]);let c=react.useCallback(()=>{a.current?.connect();},[]),u=react.useCallback(()=>{a.current?.disconnect();},[]);return {client:a.current,status:s,isConnected:s==="connected",connect:c,disconnect:u,error:o}}function jd(){let e=react.useContext(Te);if(!e)throw new Error("useWsClient must be used within a PredictProvider");let{wsClient:t}=e,[r,n]=react.useState(t?.getStatus()??"disconnected");return react.useEffect(()=>{if(!t){n("disconnected");return}return n(t.getStatus()),t.onStatusChange(n)},[t]),{wsClient:t,wsStatus:r,isWsConnected:r==="connected"}}function Jd({client:e,all:t=false,tickers:r=[],enabled:n=true,onUpdate:s}){let[i,o]=react.useState(new Map),[l,a]=react.useState(false),c=react.useRef(s);return react.useEffect(()=>{c.current=s;},[s]),react.useEffect(()=>{if(!e||!n){a(false);return}if(!t&&r.length===0)return;let u=t?{all:true}:{tickers:r},m=e.subscribePrices(u,p=>{o(f=>{let d=new Map(f);return d.set(p.market_ticker,{yesBid:p.yes_bid,yesAsk:p.yes_ask,noBid:p.no_bid,noAsk:p.no_ask,updatedAt:Date.now()}),d}),c.current?.(p);});return a(true),()=>{m(),a(false);}},[e,t,r.join(","),n]),{prices:i,isSubscribed:l}}function rp({client:e,all:t=false,tickers:r=[],enabled:n=true,maxHistory:s=100,onUpdate:i}){let[o,l]=react.useState([]),[a,c]=react.useState(false),u=react.useRef(i);react.useEffect(()=>{u.current=i;},[i]),react.useEffect(()=>{if(!e||!n){c(false);return}if(!t&&r.length===0)return;let p=t?{all:true}:{tickers:r},f=e.subscribeTrades(p,d=>{let b={tradeId:d.trade_id,marketTicker:d.market_ticker,price:d.price,count:d.count,yesPrice:d.yes_price,noPrice:d.no_price,takerSide:d.taker_side,createdTime:d.created_time};l(g=>{let x=[b,...g];return x.length>s?x.slice(0,s):x}),u.current?.(d);});return c(true),()=>{f(),c(false);}},[e,t,r.join(","),n,s]);let m=react.useCallback(()=>{l([]);},[]);return {trades:o,isSubscribed:a,clearHistory:m}}function op({client:e,all:t=false,tickers:r=[],enabled:n=true,onUpdate:s}){let[i,o]=react.useState(new Map),[l,a]=react.useState(false),c=react.useRef(s);react.useEffect(()=>{c.current=s;},[s]),react.useEffect(()=>{if(!e||!n){a(false);return}if(!t&&r.length===0)return;let m=t?{all:true}:{tickers:r},p=e.subscribeOrderbook(m,f=>{o(d=>{let b=new Map(d);return b.set(f.market_ticker,{yesBids:f.yes_bids,yesAsks:f.yes_asks,noBids:f.no_bids,noAsks:f.no_asks,updatedAt:Date.now()}),b}),c.current?.(f);});return a(true),()=>{p(),a(false);}},[e,t,r.join(","),n]);let u=react.useCallback(m=>i.get(m),[i]);return {orderbooks:i,isSubscribed:l,getOrderbook:u}}var hr=["Politics","Sports","Culture","Crypto","Climate","Economics","Mentions","Companies","Financials","Tech & Science"];function br(){let{data:e,isLoading:t,isError:r,error:n}=bt();return {data:react.useMemo(()=>{if(!e?.tagsByCategories)return [];let i=o=>{let l=hr.indexOf(o);return l===-1?hr.length:l};return Object.entries(e.tagsByCategories).map(([o,l])=>({category:o,tags:l})).sort((o,l)=>i(o.category)-i(l.category))},[e]),isLoading:t,isError:r,error:n??null}}function Pr({categories:e,selectedCategory:t,selectedTag:r,activeTags:n,onCategorySelect:s,onTagSelect:i,className:o}){let{t:l}=i18n.useTranslation(),a=react.useCallback(()=>{s(null);},[s]);return jsxRuntime.jsxs("div",{className:ui.cn("flex w-full flex-col gap-2",o),children:[jsxRuntime.jsx(ui.HorizontalScrollContainer,{children:jsxRuntime.jsxs("div",{className:"flex items-center gap-2 px-0.5 py-1",children:[jsxRuntime.jsx(Ke,{label:l("predict.categories.trending"),isSelected:t===null,onPress:a}),e.map(c=>jsxRuntime.jsx(Ke,{label:c.category,isSelected:t===c.category,onPress:()=>s(c.category)},c.category))]})}),t&&n.length>0&&jsxRuntime.jsx(ui.HorizontalScrollContainer,{children:jsxRuntime.jsxs("div",{className:"flex items-center gap-2 px-0.5 py-1",children:[jsxRuntime.jsx(Ke,{label:l("predict.categories.allMarkets"),isSelected:r===null,onPress:()=>i(null),variant:"secondary"}),n.map(c=>jsxRuntime.jsx(Ke,{label:c,isSelected:r===c,onPress:()=>i(c),variant:"secondary"},c))]})})]})}function Ke({label:e,isSelected:t,onPress:r,variant:n="primary"}){return jsxRuntime.jsx("button",{type:"button",onClick:r,className:ui.cn("shrink-0 rounded-full px-3 py-1.5 text-xs font-medium transition-colors duration-150 cursor-pointer","border whitespace-nowrap",n==="primary"?t?"bg-foreground text-background border-foreground":"bg-content1 text-foreground/70 border-default-200 hover:bg-default-100 hover:text-foreground":t?"bg-primary/15 text-primary border-primary/40":"bg-content1 text-foreground/50 border-default-100 hover:bg-default-50 hover:text-foreground/70"),children:e})}function Cr({count:e=6}){return jsxRuntime.jsx("div",{className:"flex items-center gap-2 px-0.5 py-1",children:Array.from({length:e}).map((t,r)=>jsxRuntime.jsx(ui.Skeleton,{className:"h-8 shrink-0 rounded-full",style:{width:`${60+Math.random()*40}px`}},r))})}function wr({onSelect:e,className:t}){let{data:r,isLoading:n}=br(),[s,i]=react.useState(null),[o,l]=react.useState(null),a=react.useCallback(m=>{if(i(m),l(null),!m)e?.({category:null,tags:null});else {let p=r.find(f=>f.category===m);e?.({category:m,tags:p?.tags??null});}},[r,e]),c=react.useCallback(m=>{if(l(m),m)e?.({category:s,tags:[m]});else {let p=r.find(f=>f.category===s);e?.({category:s,tags:p?.tags??null});}},[r,s,e]);if(n)return jsxRuntime.jsx(Cr,{});let u=r.find(m=>m.category===s)?.tags??[];return jsxRuntime.jsx(Pr,{categories:r,selectedCategory:s,selectedTag:o,activeTags:u,onCategorySelect:a,onTagSelect:c,className:t})}var be=48,de=4,He={ONE_MINUTE:1,ONE_HOUR:60,ONE_DAY:1440},M={ONE_DAY:"1d",ONE_WEEK:"1w",ONE_MONTH:"1m",ALL:"all"},pe=M.ALL,$e={[M.ONE_DAY]:He.ONE_MINUTE,[M.ONE_WEEK]:He.ONE_HOUR,[M.ONE_MONTH]:He.ONE_HOUR,[M.ALL]:He.ONE_DAY},Ve={[M.ONE_DAY]:300,[M.ONE_WEEK]:3600,[M.ONE_MONTH]:10800,[M.ALL]:1440*60},ze={[M.ONE_DAY]:1440*60,[M.ONE_WEEK]:10080*60,[M.ONE_MONTH]:720*60*60,[M.ALL]:null},kt=1,rm=1,nm=1,sm=99,Re={ONE_HOUR:"1h",SIX_HOURS:"6h",ONE_DAY:"1d",ONE_WEEK:"1w",MAX:"max"},om=Re.ONE_WEEK,am={[Re.ONE_HOUR]:60,[Re.SIX_HOURS]:60,[Re.ONE_DAY]:300,[Re.ONE_WEEK]:1800,[Re.MAX]:1800};function Rr(e={}){let{category:t,tags:r,...n}=e,s=!!t||!!r&&r.length>0,{data:i,isFetching:o,isError:l,error:a}=tr({...t?{category:t}:{},...r&&r.length>0?{tags:r.join(",")}:{},isInitialized:true,status:"active"},{enabled:s}),c=react.useMemo(()=>{if(!s||!i?.series)return;let A=i.series.map(P=>P.ticker).slice(0,25);return A.length>0?A.join(","):void 0},[s,i]),u=react.useMemo(()=>({status:"active",withNestedMarkets:true,sort:"volume24h",order:"desc",limit:48,...n,...c!==void 0?{seriesTickers:c}:{}}),[n,c]),{data:m,isLoading:p,isFetching:f,isFetchingNextPage:d,isError:b,error:g,hasNextPage:x,fetchNextPage:v,refetch:k}=Yt(u),y=react.useMemo(()=>m?.pages.flatMap(A=>A.events)??[],[m]),C=s&&!i&&!l;return {data:y,isLoading:C||p,isFetching:o||C||f&&!d,isFetchingMore:d,isError:l||b,error:a??g,hasMore:x,fetchMore:v,refetch:k}}function ia({className:e}){return jsxRuntime.jsxs("div",{className:`flex h-full w-full flex-col justify-between gap-y-1.5 rounded-xl border border-border bg-content1 p-3 @5xl:gap-y-3 @5xl:p-4 ${e??""}`,children:[jsxRuntime.jsxs("div",{className:"flex w-full flex-1 flex-col gap-y-1.5 @5xl:gap-y-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-4",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-8 w-8 flex-shrink-0 rounded-lg @5xl:h-12 @5xl:w-12"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-10 flex-1 rounded-md @5xl:h-12"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-8 w-12 flex-shrink-0 rounded-lg @5xl:h-10 @5xl:w-14"})]}),jsxRuntime.jsxs("div",{className:"flex w-full flex-col gap-y-0.5 @5xl:gap-y-1",children:[jsxRuntime.jsxs("div",{className:"flex min-h-8 w-full items-center justify-between gap-x-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-2/3 rounded-md"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-8 rounded-md"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-6 w-16 rounded-lg"})]})]}),jsxRuntime.jsxs("div",{className:"flex min-h-8 w-full items-center justify-between gap-x-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-1/2 rounded-md"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-8 rounded-md"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-6 w-16 rounded-lg"})]})]})]})]}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between gap-x-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-3 w-16 rounded-md @5xl:h-4"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-3 w-20 rounded-md @5xl:h-4"})]})]})}function Or({count:e=8}){return jsxRuntime.jsx("div",{className:"@container w-full h-full",children:jsxRuntime.jsx("div",{className:"grid grid-cols-1 gap-4 @[640px]:grid-cols-2 @[1024px]:grid-cols-3 @[1280px]:grid-cols-4",children:Array.from({length:e}).map((t,r)=>jsxRuntime.jsx(ia,{className:"min-h-44 @5xl:min-h-56"},r))})})}function Nr({value:e,showLabel:t=true}){let r=e/100;return jsxRuntime.jsx("div",{className:"flex-shrink-0 flex flex-col items-center",children:jsxRuntime.jsxs("div",{className:"relative w-16 h-12 lg:w-20 lg:h-14",children:[jsxRuntime.jsxs("svg",{className:"w-full h-full",viewBox:"0 0 100 70",children:[jsxRuntime.jsx("path",{d:"M 10 55 A 40 40 0 0 1 90 55",fill:"none",className:"stroke-default-200",strokeWidth:"6",strokeLinecap:"round"}),jsxRuntime.jsx("path",{d:"M 10 55 A 40 40 0 0 1 90 55",fill:"none",className:"stroke-primary",strokeWidth:"6",strokeLinecap:"round",strokeDasharray:`${r*125.6} 125.6`,style:{transition:"stroke-dasharray 0.5s ease-in-out"}})]}),t&&jsxRuntime.jsx("div",{className:"absolute inset-0 flex items-center justify-center pt-3 lg:pt-4",children:jsxRuntime.jsxs("span",{className:"text-sm font-bold text-foreground lg:text-base leading-none",children:[e.toFixed(0),"%"]})})]})})}function Qr({event:e,onSelect:t,onSelectOutcome:r}){let{t:n}=i18n.useTranslation(),[s,i]=react.useState(null),o=e.markets||[],l=o.length>2?[...o].sort((P,E)=>Number(E.yesAsk??0)-Number(P.yesAsk??0)):o,a=l.filter(P=>P.status==="active"),c=l.length===1,u=c?l[0]:s,m=react.useMemo(()=>utils.formatAmountUSDCompact((e.volume??0)/100),[e.volume]),p=P=>P.yesAsk?parseFloat(P.yesAsk)*100:null,f=P=>P.noAsk?parseFloat(P.noAsk)*100:null,d=P=>{let E=p(P),O=f(P);return E!=null?O==null&&E<=1?"< 1%":g(E):O!=null?O<=1?"> 99%":g(100-O):"0%"},b=P=>{let E=p(P),O=f(P);return O!=null?E==null&&O<=1?"< 1%":g(O):E!=null?E<=1?"> 99%":g(100-E):"0%"},g=P=>P!=null?`${P.toFixed(0)}%`:"--",x=react.useMemo(()=>{let P=l.some(O=>O.status==="active");return l.every(O=>O.status==="closed"||O.status==="determined")?{label:n("predict.event.status.closed"),color:"bg-danger-100/50 text-danger"}:P?{label:n("predict.event.status.live"),color:"bg-primary-100/50 text-primary"}:{label:n("predict.event.status.pending"),color:"bg-warning-100/50 text-warning"}},[l,n]),v=P=>{i(P);},k=()=>{i(null);},y=()=>{u&&r&&r(e,u,"yes");},C=()=>{u&&r&&r(e,u,"no");},R=()=>{t&&t(e);},S=a.slice(0,2),A=a.length>2;return jsxRuntime.jsxs("div",{className:"flex h-full w-full flex-col justify-between gap-y-1.5 rounded-xl border border-border bg-content1 p-3 transition-all duration-300 cursor-pointer hover:border-primary hover:ring-2 hover:ring-primary/20 focus-within:border-primary focus-within:bg-content2 focus-within:ring-2 focus-within:ring-primary/20 @5xl:gap-y-3 @5xl:p-4",onClick:R,children:[jsxRuntime.jsxs("div",{className:"flex w-full flex-1 flex-col gap-y-1.5 @5xl:gap-y-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-4",children:[jsxRuntime.jsx(ui.Avatar,{src:e.imageUrl||void 0,name:e.title||"Event",radius:"md",className:"h-8 w-8 flex-shrink-0 transition-transform duration-300 group-hover:scale-110 @5xl:h-12 @5xl:w-12"}),jsxRuntime.jsx(ui.StyledTooltip,{content:e.title,placement:"bottom",children:jsxRuntime.jsx("p",{className:"flex-1 min-w-0 h-10 @5xl:h-12 text-sm font-semibold @5xl:text-base line-clamp-2",children:e.title})}),c?jsxRuntime.jsx(Nr,{value:p(l[0])??50}):x.label!==n("predict.event.status.live")&&jsxRuntime.jsx("div",{className:`flex-shrink-0 flex items-center gap-x-2 rounded-lg px-2 py-1 text-sm @5xl:px-4 @5xl:py-2 ${x.color}`,children:jsxRuntime.jsx("span",{children:x.label})})]}),u&&!c&&jsxRuntime.jsxs("button",{type:"button",className:"flex min-h-9 w-full items-center justify-between gap-x-2 transition-opacity hover:cursor-pointer hover:opacity-80",onClick:P=>{P.stopPropagation(),k();},children:[jsxRuntime.jsx("span",{className:"text-left text-xs text-foreground @5xl:text-sm line-clamp-1",children:u.yesSubTitle}),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2",children:[jsxRuntime.jsx("span",{className:"text-sm font-semibold text-foreground @5xl:text-lg",children:d(u)}),jsxRuntime.jsx(ui.ChevronUpIcon,{className:"w-3 h-3 text-default-500 @5xl:w-4 @5xl:h-4"})]})]}),!u&&!c&&S.length>0&&jsxRuntime.jsxs("div",{className:"flex w-full flex-col gap-y-0.5 text-xs @5xl:gap-y-1 @5xl:text-sm",children:[S.map(P=>jsxRuntime.jsxs("button",{type:"button",className:"flex min-h-8 w-full items-center justify-between gap-x-2 transition-opacity hover:cursor-pointer hover:opacity-80",onClick:E=>{E.stopPropagation(),v(P);},children:[jsxRuntime.jsx("span",{className:"text-left text-xs text-foreground @5xl:text-sm line-clamp-1",children:P.yesSubTitle}),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2",children:[jsxRuntime.jsx("span",{className:"text-xs text-foreground @5xl:text-base",children:d(P)}),jsxRuntime.jsxs("div",{className:"flex h-full items-center gap-x-3 rounded-lg p-1 @5xl:p-1.5 bg-gradient-to-r from-primary-50/20 via-primary-50/20 to-secondary-50/20",children:[jsxRuntime.jsx("span",{className:"text-primary",children:n("predict.market.yes")}),jsxRuntime.jsx("span",{className:"text-default-400",children:"/"}),jsxRuntime.jsx("span",{className:"text-secondary",children:n("predict.market.no")})]})]})]},P.ticker)),A&&jsxRuntime.jsx("span",{className:"text-xxs text-default-500 @5xl:text-xs",children:n("predict.event.moreMarkets",{count:a.length-2})})]}),u&&jsxRuntime.jsxs("div",{className:`flex items-center gap-x-2 text-sm @5xl:text-base ${c?"mt-3":""}`,children:[jsxRuntime.jsxs(ui.Button,{color:"primary",fullWidth:true,className:"group/yes bg-primary-100 text-primary @3xl:!h-12 @3xl:!text-base",size:"sm",onPress:y,children:[jsxRuntime.jsx("span",{className:"group-hover/yes:hidden",children:n("predict.market.yes")}),jsxRuntime.jsx("span",{className:"hidden group-hover/yes:inline",children:d(u)})]}),jsxRuntime.jsxs(ui.Button,{color:"secondary",fullWidth:true,className:"group/no bg-secondary-100 text-secondary @3xl:!h-12 @3xl:!text-base",size:"sm",onPress:C,children:[jsxRuntime.jsx("span",{className:"group-hover/no:hidden",children:n("predict.market.no")}),jsxRuntime.jsx("span",{className:"hidden group-hover/no:inline",children:b(u)})]})]})]}),!u||c?jsxRuntime.jsxs("div",{className:"flex items-center justify-between gap-x-2",children:[jsxRuntime.jsxs("button",{type:"button",className:"flex items-center gap-x-1 text-xxs text-default-600 hover:text-foreground @5xl:text-xs",onClick:P=>{P.stopPropagation(),R();},children:[jsxRuntime.jsx("span",{children:n("predict.event.showMore")}),jsxRuntime.jsx(ui.ChevronRightIcon,{className:"h-3 w-3 @5xl:h-4 @5xl:w-4"})]}),jsxRuntime.jsxs("span",{className:"text-xxs text-default-600 @5xl:text-xs",children:[m," ",n("predict.event.volume")]})]}):jsxRuntime.jsxs("button",{type:"button",className:"flex items-center cursor-pointer gap-x-1 text-xxs text-default-600 hover:text-foreground @5xl:text-xs",onClick:P=>{P.stopPropagation(),k();},children:[jsxRuntime.jsx(ui.ChevronLeftIcon,{className:"h-3 w-3 @5xl:h-4 @5xl:w-4"}),jsxRuntime.jsx("span",{children:n("predict.event.back")})]})]})}var ka=640,Pa=768,Lr=1024,Ca=1280,Sa=16,Ta=192,Ma=228,wa=244;function Ra(e){return e>=Ca?4:e>=Lr?3:e>=ka?2:1}function Oa(e){return e>=Lr?wa:e>=Pa?Ma:Ta}function Ur({events:e,hasMore:t=false,onFetchMore:r,onSelect:n,onSelectOutcome:s}){let i=react.useRef(null),{width:o=0,height:l=0}=hooks.useResizeObserver({ref:i}),a=Ra(o),c=Oa(o),u=Math.ceil(e.length/a)||0,m=t?u+1:u,p=react.useCallback(b=>b<u,[u]),f=react.useCallback(async()=>{r?.();},[r]),d=reactWindowInfiniteLoader.useInfiniteLoader({isRowLoaded:p,loadMoreRows:f,rowCount:m,threshold:3});return jsxRuntime.jsx("div",{ref:i,className:"@container w-full h-full",children:l>0&&jsxRuntime.jsx(reactWindow.List,{style:{height:l},onRowsRendered:d,rowComponent:Na,rowCount:m,rowHeight:c,rowProps:{events:e,columnCount:a,dataRowCount:u,gap:Sa,onSelect:n,onSelectOutcome:s}})})}function Na({index:e,style:t,events:r,columnCount:n,dataRowCount:s,gap:i,onSelect:o,onSelectOutcome:l}){if(e>=s)return jsxRuntime.jsx("div",{style:t,className:"flex justify-center items-start pt-4",children:jsxRuntime.jsx(ui.Spinner,{size:"sm"})});let a=e*n,c=r.slice(a,a+n),u=n-c.length,m={display:"flex",gap:i,height:`calc(100% - ${i}px)`};return jsxRuntime.jsx("div",{style:t,children:jsxRuntime.jsxs("div",{style:m,children:[c.map(p=>jsxRuntime.jsx("div",{style:{flex:1,minWidth:0},children:jsxRuntime.jsx(Qr,{event:p,onSelect:o,onSelectOutcome:l})},p.ticker)),u>0&&Array.from({length:u}).map((p,f)=>jsxRuntime.jsx("div",{style:{flex:1,minWidth:0}},`spacer-${f}`))]})})}function Dr({onSelect:e,onSelectOutcome:t,...r}){let{data:n,hasMore:s,fetchMore:i,isFetching:o}=Rr({limit:48,...r});return o?jsxRuntime.jsx(Or,{count:48}):jsxRuntime.jsx(Ur,{events:n,hasMore:s,onFetchMore:i,onSelect:e,onSelectOutcome:t})}function Fm({onSelect:e,onSelectOutcome:t}){let[r,n]=react.useState({category:null,tags:null}),s=react.useCallback(i=>{n(i);},[]);return jsxRuntime.jsxs("div",{className:"flex h-full w-full flex-col gap-y-3",children:[jsxRuntime.jsx(wr,{onSelect:s}),jsxRuntime.jsx("div",{className:"min-h-0 flex-1",children:jsxRuntime.jsx(Dr,{category:r.category,tags:r.tags,onSelect:e,onSelectOutcome:t})})]})}function Mt(e,t,r){let n=e[t];return n?r==="yes"?n.yesMint:n.noMint:null}var Oe=utils.SOLANA_TOKENS.stablecoins.USDC.address;function Ka(){let e={startVelocity:30,spread:360,ticks:60,zIndex:9999};Tt__default.default({...e,particleCount:80,origin:{x:.5,y:.4}}),setTimeout(()=>{Tt__default.default({...e,particleCount:40,origin:{x:.3,y:.6}});},150),setTimeout(()=>{Tt__default.default({...e,particleCount:40,origin:{x:.7,y:.6}});},300);}function _r({market:e,chain:t="solana",initialOutcome:r="yes",initialSide:n="buy"}){let{t:s}=i18n.useTranslation(),{status:i}=walletConnector.useAuth(),l=walletConnector.useWallets().find(T=>T.chainNamespace===types.ChainNamespace.SOLANA&&T.isConnected),a=i==="authenticated",c=l?.address,[u,m]=react.useState(r),[p,f]=react.useState(n),[d,b]=react.useState(NaN),g=react.useMemo(()=>Mt(e.accounts,Oe,u),[e.accounts,u]),{inputMint:x,outputMint:v}=react.useMemo(()=>p==="buy"?{inputMint:Oe,outputMint:g}:{inputMint:g,outputMint:Oe},[p,g]),k=!!x&&!!v&&d>0,y=react.useMemo(()=>Number(u==="yes"?e.yesAsk??.5:e.noAsk??.5),[u,e.yesAsk,e.noAsk]),C=react.useMemo(()=>isNaN(d)||d<=0?0:p==="buy"?y>0?d/y:0:d,[p,d,y]),R=react.useMemo(()=>isNaN(d)||d<=0?0:Math.round(d*1e6),[d]),{data:S,isLoading:A,error:P,refetch:E}=lr({userPublicKey:c??void 0,inputMint:x??"",outputMint:v??"",amount:R,slippageBps:100},{enabled:k}),{data:O,isLoading:Ce,refetch:he}=react$1.useWalletPortfoliosQuery({chain:types.Chain.SOLANA,address:c??""},{enabled:a&&!!c,refetchInterval:1e4}),Kt=react.useMemo(()=>{if(!O?.portfolios)return null;let T=O.portfolios.find(J=>J.address===Oe);return T?parseFloat(T.amount):0},[O]),We=react.useMemo(()=>{if(!O?.portfolios||!g)return null;let T=O.portfolios.find(J=>J.address===g);return T?parseFloat(T.amount):0},[O,g]),rt=react.useMemo(()=>Mt(e.accounts,Oe,"yes"),[e.accounts]),nt=react.useMemo(()=>Mt(e.accounts,Oe,"no"),[e.accounts]),Vn=react.useMemo(()=>{if(!O?.portfolios||!rt)return null;let T=O.portfolios.find(J=>J.address===rt);return T?parseFloat(T.amount):0},[O,rt]),zn=react.useMemo(()=>{if(!O?.portfolios||!nt)return null;let T=O.portfolios.find(J=>J.address===nt);return T?parseFloat(T.amount):0},[O,nt]),{data:Se}=we(e.ticker,{refetchInterval:5e3}),Yn=react.useMemo(()=>(u==="yes"?Se?.yesBids:Se?.noBids)?.[0]?.price??null,[Se,u]),Gn=react.useMemo(()=>(u==="yes"?Se?.yesAsks:Se?.noAsks)?.[0]?.price??null,[Se,u]),jn=react.useMemo(()=>S?.priceImpactPct?parseFloat(S.priceImpactPct):null,[S]),_e=react.useMemo(()=>{if(isNaN(d)||d<=0)return 0;if(S)return parseInt(S.inAmount)/1e6;if(p==="buy")return d;let T=Number(u==="yes"?e.yesBid??0:e.noBid??0);return d*T},[S,p,u,d,e.yesBid,e.noBid]),Ht=react.useMemo(()=>isNaN(d)||d<=0?0:p==="buy"?C*1:_e,[p,C,_e,d]),Xn=Ht-_e,Zn=react.useCallback(T=>{f(T),b(NaN);},[]),Jn=react.useCallback(T=>{if(isNaN(T)){b(NaN);return}let J=Math.max(0,T),at=p==="buy"?Math.round(J*100)/100:Math.round(J);b(at);},[p]);react.useEffect(()=>{k&&E();},[d,u,p,k,E]);let st=react.useMemo(()=>{let T=[];return (isNaN(d)||d<kt)&&T.push(`Minimum quantity is ${kt}`),e.status!=="active"&&T.push("Market is not active"),p==="sell"&&We!=null&&!isNaN(d)&&d>0&&d>We&&T.push("Insufficient shares"),{isValid:T.length===0,errors:T}},[d,e.status,p,Kt,We]),[es,ot]=react.useState(null),[ts,$t]=react.useState(false),rs=react.useCallback(async()=>{if(!(!st.isValid||!a||!c||!l||Ce)){ot(null),$t(true);try{let T=S;if(T?.transaction||(T=(await E()).data),!T?.transaction)return;let J=Uint8Array.from(atob(T.transaction),Vt=>Vt.charCodeAt(0)),at=await l.sendTransaction(J);ot(at),ui.toast.success(s("predict.trade.submitSuccess")),Ka(),b(NaN),he();}catch{ui.toast.error(s("predict.trade.submitError"));}finally{$t(false);}}},[st.isValid,a,c,l,S,Ce,E,he,s]),ns=react.useCallback(()=>{m(r),f(n),b(NaN),ot(null);},[r,n]);return {outcome:u,side:p,quantity:d,shares:C,estimatedCost:_e,potentialPayout:Ht,potentialProfit:Xn,isAuthenticated:a,bestBid:Yn,bestAsk:Gn,order:S??null,priceImpact:jn,usdcBalance:Kt,outcomeTokenBalance:We,yesTokenBalance:Vn,noTokenBalance:zn,isBalanceLoading:Ce,isQuoteLoading:A,isSubmitting:ts,quoteError:P??null,txHash:es,validation:st,setOutcome:m,setSide:Zn,setQuantity:Jn,submit:rs,reset:ns}}function Hr({event:e,market:t,outcome:r,side:n,quantity:s,potentialProfit:i,estimatedCost:o,usdcBalance:l,yesTokenBalance:a,noTokenBalance:c,isBalanceLoading:u,isSubmitting:m,isValid:p,onOutcomeChange:f,onSideChange:d,onQuantityChange:b,onSubmit:g}){let{t:x}=i18n.useTranslation(),v=react.useMemo(()=>{if(m)return x("predict.trade.submitting");let y=x(n==="buy"?"predict.trade.buy":"predict.trade.sell"),C=x(r==="yes"?"predict.trade.yes":"predict.trade.no");return `${y} ${C}`},[m,n,r,x]),k=react.useMemo(()=>r==="yes"?"primary":"secondary",[r]);return jsxRuntime.jsxs("div",{className:"flex w-full flex-col gap-y-4 rounded-xl border border-default-200 bg-content1 p-4",children:[e&&jsxRuntime.jsxs("div",{className:"flex items-center gap-x-3",children:[e.imageUrl&&jsxRuntime.jsx("img",{src:e.imageUrl,alt:e.title,className:"h-10 w-10 shrink-0 rounded-lg object-cover"}),jsxRuntime.jsxs("div",{className:"flex min-w-0 flex-col gap-y-0.5",children:[jsxRuntime.jsx("span",{className:"text-sm text-neutral-500 leading-tight line-clamp-1",children:e.title}),jsxRuntime.jsxs("span",{className:"text-base font-semibold leading-tight line-clamp-1",children:[jsxRuntime.jsxs("span",{className:r==="yes"?"text-bullish":"text-bearish",children:[x(n==="buy"?"predict.trade.buy":"predict.trade.sell")," ",x(r==="yes"?"predict.trade.yes":"predict.trade.no")]}),jsxRuntime.jsxs("span",{className:"text-foreground",children:[" \xB7 ",r==="yes"?t.yesSubTitle:t.noSubTitle]})]})]})]}),jsxRuntime.jsxs(ui.Tabs,{variant:"underlined",selectedKey:n,onSelectionChange:y=>d(y),classNames:{tabList:"gap-x-4",tab:"px-0"},children:[jsxRuntime.jsx(ui.Tab,{title:x("predict.trade.buy")},"buy"),jsxRuntime.jsx(ui.Tab,{title:x("predict.trade.sell")},"sell")]}),jsxRuntime.jsx("div",{className:"flex gap-x-2",children:["yes","no"].map(y=>{let C=y==="yes"?a:c;return jsxRuntime.jsxs("div",{className:"flex flex-1 flex-col gap-y-1",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>f(y),className:`w-full rounded-lg border py-2 text-sm font-medium transition-colors cursor-pointer ${r===y?y==="yes"?"border-primary bg-primary-50 text-primary":"border-secondary bg-secondary-50 text-secondary":"border-default-400 text-foreground hover:border-default-500"}`,children:[jsxRuntime.jsx("span",{children:x(y==="yes"?"predict.trade.yes":"predict.trade.no")}),(()=>{let R=n==="buy"?y==="yes"?t.yesAsk:t.noAsk:y==="yes"?t.yesBid:t.noBid;return R!=null?jsxRuntime.jsxs("span",{className:"ml-1 opacity-70",children:[Math.round(Number(R)*100),"\xA2"]}):null})()]}),n==="sell"&&r===y&&jsxRuntime.jsx("span",{className:"text-center text-xs text-foreground",children:u?"\u2013":`${C??0} shares`})]},y)})}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-1.5",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium text-foreground",children:x(n==="buy"?"predict.trade.amount":"predict.trade.contracts")}),jsxRuntime.jsx(ui.StyledNumberInput,{fullWidth:true,placeholder:"0",radius:"lg",size:"lg",value:isNaN(s)?void 0:s,onValueChange:y=>{b(y);},minValue:0,step:n==="buy"?.01:1,formatOptions:n==="buy"?{maximumFractionDigits:2}:{maximumFractionDigits:0},startContent:n==="buy"?jsxRuntime.jsx("span",{className:"text-default-600 text-xl",children:"$"}):void 0,classNames:{inputWrapper:"bg-content2 data-[hover=true]:bg-content2 group-data-[focus=true]:bg-content2 h-14 min-h-14",input:"text-lg"}},n),jsxRuntime.jsx("div",{className:"flex gap-x-2 justify-end",children:n==="buy"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[[1,5,10,100].map(y=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>b(Math.round(((isNaN(s)?0:s)+y)*100)/100),className:"rounded-md bg-content2 px-2.5 py-1 text-xs font-medium text-default-600 transition-colors hover:bg-content3 cursor-pointer",children:["+",y,"$"]},y)),jsxRuntime.jsx("button",{type:"button",onClick:()=>{},className:"rounded-md bg-content2 px-2.5 py-1 text-xs font-medium text-default-600 transition-colors hover:bg-content3 cursor-pointer",children:x("common.all")})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[[25,50].map(y=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>{},className:"rounded-md bg-content2 px-2.5 py-1 text-xs font-medium text-default-600 transition-colors hover:bg-content3 cursor-pointer",children:[y,"%"]},y)),jsxRuntime.jsx("button",{type:"button",onClick:()=>{},className:"rounded-md bg-content2 px-2.5 py-1 text-xs font-medium text-default-600 transition-colors hover:bg-content3 cursor-pointer",children:x("common.all")})]})})]}),!isNaN(s)&&s>0&&jsxRuntime.jsxs("div",{className:"flex flex-col items-end gap-y-0.5",children:[jsxRuntime.jsx("span",{className:"text-sm text-foreground",children:x(n==="buy"?"predict.trade.potentialWin":"predict.trade.estimatedReceive")}),jsxRuntime.jsxs("span",{className:"text-xl font-semibold text-bullish",children:["$",(n==="buy"?i:o).toFixed(2)]})]}),jsxRuntime.jsx(ui.Button,{color:k,fullWidth:true,radius:"lg",size:"lg",isDisabled:!p||m,isLoading:m,onPress:g,children:v})]})}function wt({event:e,market:t,initialSide:r,initialOutcome:n,chain:s}){let{outcome:i,side:o,quantity:l,estimatedCost:a,potentialPayout:c,potentialProfit:u,usdcBalance:m,yesTokenBalance:p,noTokenBalance:f,isBalanceLoading:d,isSubmitting:b,validation:g,setOutcome:x,setSide:v,setQuantity:k,submit:y}=_r({market:t,initialSide:r,initialOutcome:n,chain:s}),C=walletConnector.useAuthCallback(y);return jsxRuntime.jsx(Hr,{event:e,market:t,outcome:i,side:o,quantity:l,estimatedCost:a,potentialPayout:c,potentialProfit:u,usdcBalance:m,yesTokenBalance:p,noTokenBalance:f,isBalanceLoading:d,isSubmitting:b,isValid:g.isValid,validationErrors:g.errors,onOutcomeChange:x,onSideChange:v,onQuantityChange:k,onSubmit:C})}function ja(){return jsxRuntime.jsxs("div",{className:"flex items-center gap-x-3 px-2 py-3 lg:gap-x-4",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-4 flex-1 rounded-md"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-10 shrink-0 rounded-md"}),jsxRuntime.jsxs("div",{className:"flex gap-x-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-8 w-16 rounded-lg"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-8 w-16 rounded-lg"})]})]})}function Be({marketCount:e=4}){return jsxRuntime.jsxs("div",{className:"w-full flex flex-col gap-4 lg:gap-y-6 px-1 lg:px-4 lg:max-w-3xl animate-pulse",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-x-3 lg:gap-x-4",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-14 w-14 shrink-0 rounded-lg lg:h-18 lg:w-18"}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-1.5 min-w-0 flex-1",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-3 w-24 rounded-md lg:w-32"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-5 w-48 rounded-md lg:h-6 lg:w-72"})]})]}),jsxRuntime.jsx(ui.Skeleton,{className:"h-[200px] w-full rounded-xl lg:h-[280px]"}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-3 w-32 rounded-md"}),jsxRuntime.jsx("div",{className:"flex gap-x-1",children:Array.from({length:4}).map((t,r)=>jsxRuntime.jsx(ui.Skeleton,{className:"h-7 w-10 rounded-md"},r))})]}),jsxRuntime.jsx("div",{className:"flex flex-col divide-y divide-default-200",children:Array.from({length:e}).map((t,r)=>jsxRuntime.jsx(ja,{},r))})]})}function $r(){return jsxRuntime.jsxs("div",{className:"flex w-full flex-col gap-y-4 rounded-xl border border-default-200 bg-content1 p-4 animate-pulse",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-x-3",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-10 w-10 shrink-0 rounded-lg"}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-1 flex-1",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-3 w-28 rounded-md"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-40 rounded-md"})]})]}),jsxRuntime.jsxs("div",{className:"flex gap-x-4",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-12 rounded-md"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-4 w-12 rounded-md"})]}),jsxRuntime.jsxs("div",{className:"flex gap-x-2",children:[jsxRuntime.jsx(ui.Skeleton,{className:"h-10 flex-1 rounded-lg"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-10 flex-1 rounded-lg"})]}),jsxRuntime.jsx(ui.Skeleton,{className:"h-14 w-full rounded-lg"}),jsxRuntime.jsx(ui.Skeleton,{className:"h-12 w-full rounded-lg"})]})}var Vr=e=>{let{candlestickMarketTickers:t,chartRange:r=pe}=e,n=$e[r],s=ze[r],i=react.useMemo(()=>Math.floor(Date.now()/1e3),[r]),o=h(),{data:l,isLoading:a,error:c}=Fe({id:e.eventId,withNestedMarkets:true}),u=react.useMemo(()=>{if(s!=null)return i-s;let k=l?.markets;return k?.length?Math.min(...k.map(y=>y.openTime)):i},[i,s,l?.markets]),{data:m,isLoading:p,error:f}=rr(l?.seriesTicker??"",{enabled:!!l?.seriesTicker}),d=react.useMemo(()=>l?.markets?(t&&t.length>0?t.slice(0,4).map(y=>l.markets.find(C=>C.ticker===y)).filter(y=>y!==void 0):[...l.markets].sort((y,C)=>Number(C.yesAsk??0)-Number(y.yesAsk??0)).slice(0,4)).map(y=>y.ticker):[],[t,l?.markets]),b=reactQuery.useQueries({queries:d.map(k=>({queryKey:ft({ticker:k,startTs:u,endTs:i,periodInterval:n}),queryFn:()=>gt(o,{ticker:k,startTs:u,endTs:i,periodInterval:n}),enabled:d.length>0}))}),g=b.some(k=>k.isLoading),x=react.useMemo(()=>{let k=new Map;return d.forEach((y,C)=>{let R=b[C]?.error;R&&k.set(y,R);}),k},[d,b]),v=react.useMemo(()=>{let k=new Map;return d.forEach((y,C)=>{let R=b[C]?.data;R&&k.set(y,R);}),k},[d,b]);return {event:l,isEventLoading:a,eventError:c,series:m,isSeriesLoading:p,seriesError:f,periodInterval:n,candlesticks:v,isCandlesticksLoading:g,candlestickErrors:x}};var oi=utils.SOLANA_TOKENS.stablecoins.USDC.address;function zr(e){let{status:t}=walletConnector.useAuth(),n=walletConnector.useWallets().find(c=>c.chainNamespace===types.ChainNamespace.SOLANA&&c.isConnected),s=t==="authenticated",i=n?.address,{data:o,isLoading:l}=react$1.useWalletPortfoliosQuery({chain:types.Chain.SOLANA,address:i??""},{enabled:s&&!!i,refetchInterval:1e4});return {holdings:react.useMemo(()=>{let c=new Map;if(!o?.portfolios||e.length===0)return c;let u=new Map;for(let m of o.portfolios)u.set(m.address,parseFloat(m.amount));for(let m of e){let p=m.accounts[oi];if(!p)continue;let f=u.get(p.yesMint)??0,d=u.get(p.noMint)??0;(f>0||d>0)&&c.set(m.ticker,{yesShares:f,noShares:d});}return c},[o,e]),isLoading:l}}function fi(e){let{cx:t,cy:r,index:n,dataLength:s,stroke:i}=e;return n!==s-1||t==null||r==null?null:jsxRuntime.jsxs("g",{children:[jsxRuntime.jsxs("circle",{cx:t,cy:r,r:6,fill:i,opacity:.3,children:[jsxRuntime.jsx("animate",{attributeName:"r",values:"4;8;4",dur:"2s",repeatCount:"indefinite"}),jsxRuntime.jsx("animate",{attributeName:"opacity",values:"0.4;0.1;0.4",dur:"2s",repeatCount:"indefinite"})]}),jsxRuntime.jsx("circle",{cx:t,cy:r,r:3,fill:i})]})}var je=[{stroke:"hsl(var(--heroui-primary))",id:"colorMarket0"},{stroke:"hsl(var(--heroui-secondary))",id:"colorMarket1"},{stroke:"hsl(var(--heroui-success))",id:"colorMarket2"},{stroke:"hsl(var(--heroui-warning))",id:"colorMarket3"}];function Yr(e,t){let r=new Date(e*1e3);switch(t){case M.ONE_DAY:return r.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:false});case M.ONE_WEEK:case M.ONE_MONTH:return r.toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:false});case M.ALL:default:return r.toLocaleDateString("en-US",{month:"short",day:"numeric"})}}function gi(e,t,r){let n=Ve[r],s=new Map;e.forEach((a,c)=>{let u=new Map;(a.candlesticks??[]).forEach(p=>{let f=p.end_period_ts-p.end_period_ts%n;u.set(f,p.yes_ask.close);}),s.set(c,u);});let i=new Set;for(let a of s.values())for(let c of a.keys())i.add(c);let o=Array.from(i).sort((a,c)=>a-c),l=new Map;return o.map(a=>{let u={date:new Date(a*1e3).toLocaleDateString("en-US",{month:"short",day:"numeric"}),timestamp:a};return t.forEach(m=>{let p=s.get(m)?.get(a);if(p!==void 0)u[m]=Math.round(p*100)/100,l.set(m,u[m]);else {let f=l.get(m);f!==void 0&&(u[m]=f);}}),u})}function Gr({candlesticks:e,markets:t=[],isLoading:r,chartRange:n=M.ALL,onDataChange:s}){let[i,o]=react.useState(null),l=react.useRef(s);react.useEffect(()=>{l.current=s;});let a=react.useMemo(()=>e?Array.from(e.keys()).slice(0,4):[],[e]),c=react.useMemo(()=>!e||e.size===0?[]:gi(e,a,n),[e,a,n]),u=react.useMemo(()=>{if(c.length===0||a.length===0)return [0,100];let d=1/0,b=-1/0;if(c.forEach(y=>{a.forEach(C=>{let R=y[C];R!==void 0&&(d=Math.min(d,R),b=Math.max(b,R));});}),d===1/0||b===-1/0)return [0,100];let g=b-d,x=Math.max(g*.2,5),v=Math.max(0,Math.floor(d-x)),k=Math.min(100,Math.ceil(b+x));return [v,k]},[c,a]),m=react.useCallback(d=>{if(c.length===0)return null;let b=d!==null?c[d]:c[c.length-1];return b?{timestamp:b.timestamp,date:b.date,markets:a.map((g,x)=>{let v=t.find(k=>k.ticker===g);return {id:g,label:v?.yesSubTitle||`Market ${x+1}`,value:b[g]??0,color:je[x%je.length].stroke}})}:null},[c,a,t]);react.useEffect(()=>{l.current&&c.length>0&&l.current(m(null));},[c,m]),react.useEffect(()=>{l.current&&l.current(m(i));},[i,m]);let p=react.useCallback(d=>{typeof d?.activeTooltipIndex=="number"&&o(d.activeTooltipIndex);},[]),f=react.useCallback(()=>{o(null);},[]);return r?jsxRuntime.jsx("div",{className:"h-[200px] w-full lg:h-[300px] flex items-center justify-center",children:jsxRuntime.jsx("div",{className:"text-default-400 text-sm",children:"Loading chart..."})}):c.length===0?jsxRuntime.jsx("div",{className:"h-[200px] w-full lg:h-[300px] flex items-center justify-center",children:jsxRuntime.jsx("div",{className:"text-default-400 text-sm",children:"No price history data"})}):jsxRuntime.jsx("div",{className:"h-[200px] w-full lg:h-[300px]",children:jsxRuntime.jsx(recharts.ResponsiveContainer,{width:"100%",height:"100%",children:jsxRuntime.jsxs(recharts.LineChart,{data:c,margin:{top:10,right:16,left:16,bottom:0},onMouseMove:p,onMouseLeave:f,children:[jsxRuntime.jsx(recharts.XAxis,{dataKey:"timestamp",tick:d=>{let{x:b,y:g,payload:x,index:v}=d,k=c.length,C=Math.max(1,Math.ceil(k/6)),R=v===0,S=v===k-1,A=v%C===0;return !R&&!S&&!A?null:jsxRuntime.jsx("text",{x:b,y:g+10,textAnchor:"middle",fill:"hsl(var(--heroui-default-500))",fontSize:10,children:Yr(x.value,n)})},tickLine:false,axisLine:false,interval:0}),jsxRuntime.jsx(recharts.CartesianGrid,{horizontal:true,vertical:false,strokeDasharray:"3 3",stroke:"hsl(var(--heroui-default-200))"}),jsxRuntime.jsx(recharts.YAxis,{domain:u,tickLine:false,axisLine:false,tick:{fontSize:10,fill:"hsl(var(--heroui-default-500))"},tickFormatter:d=>`${d}%`,width:40}),jsxRuntime.jsx(recharts.Tooltip,{contentStyle:{backgroundColor:"hsl(var(--heroui-content1))",border:"1px solid hsl(var(--heroui-default-200))",borderRadius:"8px",fontSize:"12px"},labelFormatter:d=>Yr(d,n),formatter:(d,b)=>{let x=t.find(v=>v.ticker===b)?.yesSubTitle||b;return [`${d.toFixed(2)}%`,x]}}),a.map((d,b)=>jsxRuntime.jsx(recharts.Line,{type:"monotone",dataKey:d,stroke:je[b%je.length].stroke,strokeWidth:2,isAnimationActive:false,dot:g=>jsxRuntime.jsx(fi,{...g,dataLength:c.length},`dot-${d}-${g.index}`),activeDot:false},d))]})})})}function jr(){return {timestamp:Date.now()/1e3,date:new Date().toLocaleDateString("en-US",{month:"short",day:"numeric"}),markets:[]}}function Zr({marketTicker:e,openTime:t,chartRange:r=pe}){let n=$e[r],s=ze[r],i=react.useMemo(()=>Math.floor(Date.now()/1e3),[r]),o=react.useMemo(()=>s!=null?i-s:t??i,[i,s,t]),{data:l,isLoading:a,isFetching:c,error:u}=xt({ticker:e,startTs:o,endTs:i,periodInterval:n},{enabled:!!e});return {candlesticks:l,isLoading:a,isFetching:c,error:u,periodInterval:n}}var Si="hsl(var(--heroui-primary))",Ti=[{value:M.ONE_DAY,label:"1D"},{value:M.ONE_WEEK,label:"1W"},{value:M.ONE_MONTH,label:"1M"},{value:M.ALL,label:"ALL"}];function Mi(e){let{cx:t,cy:r,index:n,dataLength:s,stroke:i}=e;return n!==s-1||t==null||r==null?null:jsxRuntime.jsxs("g",{children:[jsxRuntime.jsxs("circle",{cx:t,cy:r,r:6,fill:i,opacity:.3,children:[jsxRuntime.jsx("animate",{attributeName:"r",values:"4;8;4",dur:"2s",repeatCount:"indefinite"}),jsxRuntime.jsx("animate",{attributeName:"opacity",values:"0.4;0.1;0.4",dur:"2s",repeatCount:"indefinite"})]}),jsxRuntime.jsx("circle",{cx:t,cy:r,r:3,fill:i})]})}function en(e,t){let r=new Date(e*1e3);switch(t){case M.ONE_DAY:return r.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:false});case M.ONE_WEEK:case M.ONE_MONTH:return r.toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:false});case M.ALL:default:return r.toLocaleDateString("en-US",{month:"short",day:"numeric"})}}function wi(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toFixed(0)}function Ri(e,t){let r=Ve[t],n=e.candlesticks??[],s=new Map;for(let o of n){let l=o.end_period_ts-o.end_period_ts%r,a=s.get(l);s.set(l,{close:o.yes_ask.close,volume:(a?.volume??0)+(o.volume??0)});}return Array.from(s.entries()).sort((o,l)=>o[0]-l[0]).map(([o,{close:l,volume:a}])=>({timestamp:o,date:new Date(o*1e3).toLocaleDateString("en-US",{month:"short",day:"numeric"}),value:Math.round(l*100)/100,volume:a}))}function tn({candlesticks:e,isLoading:t,chartRange:r,onRangeChange:n}){let s=react.useMemo(()=>e?Ri(e,r):[],[e,r]),i=react.useMemo(()=>{if(s.length===0)return [0,100];let o=1/0,l=-1/0;for(let p of s)p.value<o&&(o=p.value),p.value>l&&(l=p.value);if(o===1/0||l===-1/0)return [0,100];let a=l-o,c=Math.max(a*.2,5),u=Math.max(0,Math.floor(o-c)),m=Math.min(100,Math.ceil(l+c));return [u,m]},[s]);return t?jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-2",children:[jsxRuntime.jsx("div",{className:"h-[200px] w-full flex items-center justify-center",children:jsxRuntime.jsx("div",{className:"text-neutral text-sm",children:"Loading chart..."})}),jsxRuntime.jsx(It,{chartRange:r,onRangeChange:n})]}):s.length===0?jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-2",children:[jsxRuntime.jsx("div",{className:"h-[200px] w-full flex items-center justify-center",children:jsxRuntime.jsx("div",{className:"text-neutral text-sm",children:"No price history data"})}),jsxRuntime.jsx(It,{chartRange:r,onRangeChange:n})]}):jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-2",children:[jsxRuntime.jsx("div",{className:"h-[200px] w-full",children:jsxRuntime.jsx(recharts.ResponsiveContainer,{width:"100%",height:"100%",children:jsxRuntime.jsxs(recharts.LineChart,{data:s,margin:{top:10,right:16,left:16,bottom:0},children:[jsxRuntime.jsx(recharts.XAxis,{dataKey:"timestamp",tick:o=>{let{x:l,y:a,payload:c,index:u}=o,m=s.length,f=Math.max(1,Math.ceil(m/6)),d=u===0,b=u===m-1,g=u%f===0;return !d&&!b&&!g?null:jsxRuntime.jsx("text",{x:l,y:a+10,textAnchor:"middle",fill:"hsl(var(--heroui-default-500))",fontSize:10,children:en(c.value,r)})},tickLine:false,axisLine:false,interval:0}),jsxRuntime.jsx(recharts.CartesianGrid,{horizontal:true,vertical:false,strokeDasharray:"3 3",stroke:"hsl(var(--heroui-default-200))"}),jsxRuntime.jsx(recharts.YAxis,{domain:i,tickLine:false,axisLine:false,tick:{fontSize:10,fill:"hsl(var(--heroui-default-500))"},tickFormatter:o=>`${o}%`,width:40}),jsxRuntime.jsx(recharts.Tooltip,{cursor:{stroke:"hsl(var(--heroui-default-300))"},content:({active:o,payload:l})=>{if(!o||!l?.length)return null;let a=l[0].payload,c=Math.round(a.value);return jsxRuntime.jsxs("div",{className:"rounded-lg border border-default-200 bg-content1 px-3 py-2 shadow-md",children:[jsxRuntime.jsxs("div",{className:"text-lg font-semibold text-primary",children:["Yes ",c,"\xA2"]}),jsxRuntime.jsxs("div",{className:"text-sm text-neutral",children:["Vol ",wi(a.volume)," \xB7"," ",en(a.timestamp,r)]})]})}}),jsxRuntime.jsx(recharts.Line,{type:"monotone",dataKey:"value",stroke:Si,strokeWidth:2,isAnimationActive:false,dot:o=>jsxRuntime.jsx(Mi,{...o,dataLength:s.length},`dot-${o.index}`),activeDot:false})]})})}),jsxRuntime.jsx(It,{chartRange:r,onRangeChange:n})]})}function It({chartRange:e,onRangeChange:t}){return jsxRuntime.jsx("div",{className:"flex items-center justify-end gap-x-1",children:Ti.map(r=>{let n=e===r.value;return jsxRuntime.jsx("button",{type:"button",className:`px-3 py-1 text-xs rounded-md transition-colors cursor-pointer ${n?"bg-primary text-primary-foreground":"bg-default-100 text-default-600 hover:bg-default-200"}`,onClick:()=>t?.(r.value),children:r.label},r.value)})})}function rn({marketTicker:e}){let{data:t,isLoading:r,error:n}=we(e,{enabled:!!e});return {orderbook:react.useMemo(()=>{if(!t)return null;let{yesBids:i,yesAsks:o,noBids:l,noAsks:a}=t;return {yesBids:i,yesAsks:o,noBids:l,noAsks:a,bestYesBid:i.length>0?i[0].price:null,bestYesAsk:o.length>0?o[0].price:null,bestNoBid:l.length>0?l[0].price:null,bestNoAsk:a.length>0?a[0].price:null,sequence:t.sequence??null}},[t]),isOrderbookLoading:r,orderbookError:n}}function nn(e,t){let r=e.slice(0,t),n=0;return r.map(s=>(n+=s.quantity,{...s,cumulative:n,depth:0,total:s.price*s.quantity}))}function sn(e,t){for(let r of e)r.depth=t>0?r.cumulative/t:0;}function cn(e){return `${Math.round(e*100)}\xA2`}function Ei(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function Ii(e){return e>=1e6?`$${(e/1e6).toFixed(2)}M`:e>=1e3?`$${(e/1e3).toFixed(2)}K`:e>=1?`$${e.toFixed(2)}`:`$${e.toFixed(4)}`}function on({row:e,side:t,showType:r=false,onClick:n}){let{t:s}=i18n.useTranslation(),i=t==="ask",o=i?"bg-bullish/10":"bg-bearish/10",l=i?"text-bullish":"text-bearish";return jsxRuntime.jsxs("button",{type:"button",className:"relative grid w-full grid-cols-4 px-2 py-2.5 text-xs cursor-pointer hover:bg-default-100 transition-colors",onClick:()=>n?.(e.price,t),children:[jsxRuntime.jsx("div",{className:`absolute inset-y-0 left-0 ${o} transition-[width] duration-200`,style:{width:`${e.depth*100}%`}}),jsxRuntime.jsx("span",{className:`relative z-10 font-mono font-medium ${l} text-left`,children:r?s(i?"predict.trade.bestAsk":"predict.trade.bestBid"):""}),jsxRuntime.jsx("span",{className:"relative z-10 font-mono text-foreground text-right",children:cn(e.price)}),jsxRuntime.jsx("span",{className:"relative z-10 font-mono text-foreground text-right",children:Ei(e.quantity)}),jsxRuntime.jsx("span",{className:"relative z-10 font-mono text-foreground text-right",children:Ii(e.total)})]})}function an({index:e}){let t=["60%","45%","75%","55%","65%","50%","70%","40%"];return jsxRuntime.jsxs("div",{className:"grid grid-cols-4 gap-x-2 px-2 py-2.5",children:[jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100",style:{width:t[e%t.length]}}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-3/4"}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-3/4"}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-3/4"})]})}function Qi(){return jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsxs("div",{className:"grid grid-cols-4 gap-x-2 px-2 py-2.5",children:[jsxRuntime.jsx("div",{}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-1/2"}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-1/2"}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-1/2"})]}),Array.from({length:Qt}).map((e,t)=>jsxRuntime.jsx(an,{index:t},`ask-${t}`)),jsxRuntime.jsx("div",{className:"flex justify-center border-y border-default-200 px-2 py-2.5",children:jsxRuntime.jsx("div",{className:"h-4 w-24 animate-pulse rounded bg-default-100"})}),Array.from({length:Qt}).map((e,t)=>jsxRuntime.jsx(an,{index:t+3},`bid-${t}`))]})}var Qt=8;function Bt({bids:e,asks:t,isLoading:r=false,maxLevels:n=Qt,onPriceClick:s}){let{t:i}=i18n.useTranslation(),{bidRows:o,askRows:l,spread:a,spreadPercent:c}=react.useMemo(()=>{let m=nn(e,n),p=nn(t,n),f=Math.max(m[m.length-1]?.cumulative??0,p[p.length-1]?.cumulative??0);sn(m,f),sn(p,f);let d=m[0]?.price??null,b=p[0]?.price??null,g=null,x=null;if(d!=null&&b!=null){g=b-d;let v=(d+b)/2;v>0&&(x=Math.round(g/v*1e4)/100);}return {bidRows:m,askRows:p,spread:g,spreadPercent:x}},[e,t,n]);return r?jsxRuntime.jsx(Qi,{}):o.length===0&&l.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-6 text-sm text-neutral",children:i("predict.orderBook.empty")}):jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsxs("div",{className:"grid grid-cols-4 px-2 py-2.5 text-xs text-neutral",children:[jsxRuntime.jsx("span",{}),jsxRuntime.jsx("span",{className:"text-right",children:i("predict.orderBook.price")}),jsxRuntime.jsx("span",{className:"text-right",children:i("predict.orderBook.contracts")}),jsxRuntime.jsx("span",{className:"text-right",children:i("predict.orderBook.total")})]}),jsxRuntime.jsx("div",{className:"flex flex-col-reverse",children:l.map((m,p)=>jsxRuntime.jsx(on,{row:m,side:"ask",showType:p===0,onClick:s},m.price))}),a!=null&&jsxRuntime.jsxs("div",{className:"flex items-center justify-center gap-x-2 border-y border-default-200 px-2 py-2.5 text-xs text-default-500",children:[jsxRuntime.jsxs("span",{children:[i("predict.orderBook.spread"),": ",cn(a)]}),c!=null&&jsxRuntime.jsxs("span",{className:"text-default-400",children:["(",c,"%)"]})]}),jsxRuntime.jsx("div",{className:"flex flex-col",children:o.map((m,p)=>jsxRuntime.jsx(on,{row:m,side:"bid",showType:p===0,onClick:s},m.price))})]})}function Ui(e){return e>=1e6?`${(e/1e6).toFixed(2)}M`:e>=1e3?`${(e/1e3).toFixed(2)}K`:e.toLocaleString(void 0,{maximumFractionDigits:2})}function Ai(e){let t=Math.abs(e),r=e>=0?"+":"-";return t>=1e3?`${r}$${(t/1e3).toFixed(1)}K`:t>=1?`${r}$${t.toFixed(2)}`:`${r}$${t.toFixed(4)}`}function un({positions:e,isLoading:t=false}){let{t:r}=i18n.useTranslation();return t?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8",children:jsxRuntime.jsx(ui.Spinner,{size:"sm"})}):e.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-6 text-sm text-neutral",children:r("predict.positions.empty")}):jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsxs("div",{className:"grid grid-cols-5 px-2 py-2.5 text-xs text-neutral",children:[jsxRuntime.jsx("span",{children:r("predict.positions.outcome")}),jsxRuntime.jsx("span",{className:"text-right",children:r("predict.positions.qty")}),jsxRuntime.jsx("span",{className:"text-right",children:r("predict.positions.avgCost")}),jsxRuntime.jsx("span",{className:"text-right",children:r("predict.positions.currentPrice")}),jsxRuntime.jsx("span",{className:"text-right",children:r("predict.positions.pnl")})]}),e.map(n=>{let s=n.position==="YES",i=s?"text-bullish":"text-bearish",o=r(s?"predict.market.yes":"predict.market.no"),l=n.avgCost!=null?`${Math.round(n.avgCost*100)}\xA2`:"\u2014",a=n.currentPrice!=null?`${Math.round(n.currentPrice*100)}\xA2`:"\u2014",c=n.pnl!=null&&n.pnlPercent!=null,u=c&&n.pnl>0?"text-bullish":c&&n.pnl<0?"text-bearish":"text-foreground";return jsxRuntime.jsxs("div",{className:"grid grid-cols-5 px-2 py-2.5 text-xs hover:bg-default-100 transition-colors",children:[jsxRuntime.jsx("span",{className:`font-medium ${i}`,children:o}),jsxRuntime.jsx("span",{className:"text-right font-mono text-foreground",children:Ui(n.balance)}),jsxRuntime.jsx("span",{className:"text-right font-mono text-foreground",children:l}),jsxRuntime.jsx("span",{className:"text-right font-mono text-foreground",children:a}),jsxRuntime.jsx("span",{className:`text-right font-mono ${u}`,children:c?jsxRuntime.jsxs("span",{className:"flex flex-col items-end",children:[jsxRuntime.jsx("span",{children:Ai(n.pnl)}),jsxRuntime.jsxs("span",{className:"text-[10px] opacity-70",children:[n.pnlPercent>=0?"+":"",n.pnlPercent.toFixed(1),"%"]})]}):"\u2014"})]},n.mint)})]})}function Wi(e){let t=e/1e6;return t>=1e6?`${(t/1e6).toFixed(2)}M`:t>=1e3?`${(t/1e3).toFixed(2)}K`:t.toLocaleString(void 0,{maximumFractionDigits:2})}function _i(e){return e==null?"\u2014":`${Math.round(e*100)}\xA2`}function Fi(e){let t=new Date(e*1e3),r=t.toLocaleString("default",{month:"short"}),n=t.getDate(),s=t.getHours().toString().padStart(2,"0"),i=t.getMinutes().toString().padStart(2,"0");return `${r} ${n} ${s}:${i}`}function qi({index:e}){let t=["60%","45%","75%","55%","65%"];return jsxRuntime.jsxs("div",{className:"grid grid-cols-4 gap-x-2 px-2 py-2.5",children:[jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100",style:{width:t[e%t.length]}}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-3/4"}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-3/4"}),jsxRuntime.jsx("div",{className:"h-4 animate-pulse rounded bg-default-100 ml-auto w-3/4"})]})}function dn({trades:e,isLoading:t=false}){let{t:r}=i18n.useTranslation();return t?jsxRuntime.jsx("div",{className:"flex flex-col",children:Array.from({length:6}).map((n,s)=>jsxRuntime.jsx(qi,{index:s},s))}):e.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-6 text-sm text-neutral",children:r("predict.tradeHistory.empty")}):jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsxs("div",{className:"grid grid-cols-4 px-2 py-2.5 text-xs text-neutral",children:[jsxRuntime.jsx("span",{children:r("predict.tradeHistory.side")}),jsxRuntime.jsx("span",{className:"text-right",children:r("predict.tradeHistory.price")}),jsxRuntime.jsx("span",{className:"text-right",children:r("predict.tradeHistory.qty")}),jsxRuntime.jsx("span",{className:"text-right",children:r("predict.tradeHistory.time")})]}),e.map(n=>{let s=n.side==="yes",i=s?"text-bullish":"text-bearish",o=n.side?r(s?"predict.trade.yes":"predict.trade.no"):"\u2014";return jsxRuntime.jsxs("div",{className:"grid grid-cols-4 px-2 py-2.5 text-xs hover:bg-default-100 transition-colors",children:[jsxRuntime.jsx("span",{className:`font-medium ${i}`,children:o}),jsxRuntime.jsx("span",{className:"text-right font-mono text-foreground",children:_i(n.usdPricePerContract)}),jsxRuntime.jsx("span",{className:"text-right font-mono text-foreground",children:Wi(n.outputAmount)}),jsxRuntime.jsx("span",{className:"text-right text-default-500",children:Fi(n.createdAt)})]},n.id)})]})}function fn({market:e,onTradeAction:t}){let{t:r}=i18n.useTranslation(),[n,s]=react.useState("trade-yes"),[i,o]=react.useState(pe),{orderbook:l,isOrderbookLoading:a}=rn({marketTicker:e.ticker}),{candlesticks:c,isFetching:u}=Zr({marketTicker:e.ticker,openTime:e.openTime,chartRange:i}),{positions:m,isLoading:p}=or(e),{status:f}=walletConnector.useAuth(),g=walletConnector.useWallets().find(S=>S.chainNamespace===types.ChainNamespace.SOLANA&&S.isConnected)?.address,{data:x,isLoading:v}=Zt({walletAddress:g??""},{enabled:(n==="trade-history"||n==="positions")&&f==="authenticated"&&!!g}),k=(x?.trades??[]).filter(S=>S.marketTicker===e.ticker),y=react.useMemo(()=>m.map(S=>{let A=k.filter(he=>he.outputMint===S.mint&&he.usdPricePerContract!=null&&he.contracts!=null&&he.contracts>0),P=Gi(A),E=S.position==="YES"?yn(S.market?.yesAsk):yn(S.market?.noAsk),O=null,Ce=null;return P!=null&&E!=null&&(O=(E-P)*S.balance,Ce=P>0?(E-P)/P*100:null),{...S,avgCost:P,currentPrice:E,pnl:O,pnlPercent:Ce}}),[m,k]),C=react.useCallback((S,A)=>{t?.(e,"yes",A==="ask"?"buy":"sell");},[e,t]),R=react.useCallback((S,A)=>{t?.(e,"no",A==="ask"?"buy":"sell");},[e,t]);return jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-3",children:[jsxRuntime.jsxs(ui.Tabs,{variant:"underlined",selectedKey:n,onSelectionChange:S=>s(S),classNames:{tabList:"gap-x-4",tab:"px-0"},children:[jsxRuntime.jsx(ui.Tab,{title:r("predict.market.tradeYes")},"trade-yes"),jsxRuntime.jsx(ui.Tab,{title:r("predict.market.tradeNo")},"trade-no"),jsxRuntime.jsx(ui.Tab,{title:r("predict.market.graph")},"graph"),jsxRuntime.jsx(ui.Tab,{title:r("predict.positions.title")},"positions"),jsxRuntime.jsx(ui.Tab,{title:r("predict.tradeHistory.title")},"trade-history")]}),jsxRuntime.jsxs("div",{className:"min-h-[120px]",children:[n==="trade-yes"&&jsxRuntime.jsx(Bt,{bids:l?.yesBids??[],asks:l?.yesAsks??[],isLoading:a,onPriceClick:C}),n==="trade-no"&&jsxRuntime.jsx(Bt,{bids:l?.noBids??[],asks:l?.noAsks??[],isLoading:a,onPriceClick:R}),n==="graph"&&jsxRuntime.jsx(tn,{candlesticks:c,isLoading:u,chartRange:i,onRangeChange:o}),n==="positions"&&jsxRuntime.jsx(un,{positions:y,isLoading:p}),n==="trade-history"&&jsxRuntime.jsx(dn,{trades:k,isLoading:v})]})]})}function Gi(e){if(e.length===0)return null;let t=0,r=0;for(let n of e)t+=n.contracts,r+=n.usdPricePerContract*n.contracts;return t>0?r/t:null}function yn(e){if(e==null)return null;let t=Number(e);return Number.isFinite(t)?t:null}var Ut=4;function Xi(e){let t=e.yesAsk?Math.round(parseFloat(e.yesAsk)*100):null,r=e.noAsk?Math.round(parseFloat(e.noAsk)*100):null;return {yesCents:t,noCents:r}}function Pn({markets:e,renderMarketDetail:t,onTradeAction:r,marketHoldings:n}){let{t:s}=i18n.useTranslation(),[i,o]=react.useState(false),[l,a]=react.useState(null);if(e.length===0)return null;let c=e.length>Ut,u=i?e:e.slice(0,Ut),m=p=>{a(f=>f===p?null:p);};return jsxRuntime.jsxs("div",{className:"flex flex-col divide-y divide-default-200",children:[u.map(p=>{let{yesCents:f,noCents:d}=Xi(p),b=l===p.ticker;return jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-x-3 px-2 py-3 transition-colors hover:bg-content2 lg:gap-x-4 cursor-pointer",onClick:()=>m(p.ticker),role:"button",tabIndex:0,onKeyDown:g=>{(g.key==="Enter"||g.key===" ")&&(g.preventDefault(),m(p.ticker));},children:[jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-1 min-w-0 flex-1",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium truncate lg:text-base",children:p.yesSubTitle}),(()=>{let g=n?.get(p.ticker);if(!g)return null;let{yesShares:x,noShares:v}=g;return x<=0&&v<=0?null:jsxRuntime.jsxs("div",{className:"flex items-center gap-x-1.5",children:[x>0&&jsxRuntime.jsx(ui.Chip,{size:"sm",variant:"flat",color:"primary",classNames:{base:"h-5",content:"text-[10px] font-medium px-1"},children:s("predict.market.sharesYes",{shares:x%1===0?x:x.toFixed(2)})}),v>0&&jsxRuntime.jsx(ui.Chip,{size:"sm",variant:"flat",color:"secondary",classNames:{base:"h-5",content:"text-[10px] font-medium px-1"},children:s("predict.market.sharesNo",{shares:v%1===0?v:v.toFixed(2)})})]})})()]}),(()=>{let g=f!=null,x=d!=null;return g&&!x&&f<=1?jsxRuntime.jsx("span",{className:"text-lg font-bold shrink-0 text-center text-default-400 lg:text-xl",children:"< 1%"}):x&&!g&&d<=1?jsxRuntime.jsx("span",{className:"text-lg font-bold shrink-0 text-center text-default-400 lg:text-xl",children:"> 99%"}):!g&&!x?jsxRuntime.jsx("span",{className:"text-lg font-bold shrink-0 text-center text-default-400 lg:text-xl",children:"0%"}):jsxRuntime.jsx("span",{className:"text-lg font-bold shrink-0 text-center lg:text-xl",children:`${f}%`})})(),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2 flex-1 justify-end",children:[jsxRuntime.jsx(ui.Button,{size:"sm",color:"primary",className:"w-20 bg-primary-100 text-primary",onPress:()=>r?.(p,"yes","buy"),children:f!=null?s("predict.market.action.yes",{price:f}):s("predict.market.yes")}),jsxRuntime.jsx(ui.Button,{size:"sm",color:"secondary",className:"w-20 bg-secondary-100 text-secondary",onPress:()=>r?.(p,"no","buy"),children:d!=null?s("predict.market.action.no",{price:d}):s("predict.market.no")})]}),b?jsxRuntime.jsx(ui.ChevronUpIcon,{className:"h-4 w-4 shrink-0 text-default-400"}):jsxRuntime.jsx(ui.ChevronDownIcon,{className:"h-4 w-4 shrink-0 text-default-400"})]}),b&&t&&jsxRuntime.jsx("div",{className:"max-h-100 overflow-y-auto px-2 pb-3",children:t(p)})]},p.ticker)}),c&&jsxRuntime.jsx("button",{type:"button",onClick:()=>o(p=>!p),className:"flex items-center justify-center gap-x-1.5 px-2 py-2.5 text-sm text-default-500 transition-colors cursor-pointer hover:text-primary",children:i?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{children:s("predict.event.rules.collapse")}),jsxRuntime.jsx(ui.ChevronUpIcon,{className:"h-4 w-4"})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{children:s("predict.event.moreMarkets",{count:e.length-Ut})}),jsxRuntime.jsx(ui.ChevronDownIcon,{className:"h-4 w-4"})]})})]})}var rl=new Set(["closed","determined","finalized"]);function Ze(e){let t=new Date(e*1e3),r=t.toLocaleString("default",{month:"short"}),n=t.getDate(),s=t.getFullYear(),i=t.getHours().toString().padStart(2,"0"),o=t.getMinutes().toString().padStart(2,"0");return `${r} ${n}, ${s} ${i}:${o}`}function nl({market:e}){let t=rl.has(e.status),r=react.useMemo(()=>{let s={label:"Market Open",value:Ze(e.openTime),isActive:true},i={label:"Market Closes",value:t?Ze(e.closeTime):"After the outcome occurs",isActive:t},o={label:"Projected Payout",value:"30 minutes after closing",isActive:e.status==="finalized"};return [s,i,o]},[e.openTime,e.closeTime,e.status,t]),n=react.useMemo(()=>t?null:e.canCloseEarly&&e.earlyCloseCondition?`${e.earlyCloseCondition} Otherwise, it closes by ${Ze(e.expirationTime)}.`:`This market closes by ${Ze(e.expirationTime)}.`,[t,e.canCloseEarly,e.earlyCloseCondition,e.expirationTime]);return jsxRuntime.jsxs("div",{className:"flex flex-col",children:[r.map((s,i)=>jsxRuntime.jsxs("div",{className:"flex items-stretch gap-x-3",children:[jsxRuntime.jsxs("div",{className:"flex flex-col items-center w-3",children:[jsxRuntime.jsx("div",{className:`h-3 w-3 shrink-0 rounded-full border-2 mt-0.5 ${s.isActive?"border-primary bg-primary":"border-default-300 bg-transparent"}`}),i<r.length-1&&jsxRuntime.jsx("div",{className:"w-px flex-1 bg-default-200"})]}),jsxRuntime.jsxs("div",{className:`flex flex-col ${i<r.length-1?"pb-4":""}`,children:[jsxRuntime.jsx("span",{className:"text-xs font-medium text-foreground lg:text-sm",children:s.label}),jsxRuntime.jsx("span",{className:"text-xs text-default-500 lg:text-sm",children:s.value})]})]},s.label)),n&&jsxRuntime.jsx("p",{className:"text-xs text-default-500 mt-3 lg:text-sm",children:n})]})}function Sn({markets:e,event:t,series:r}){let{t:n}=i18n.useTranslation(),[s,i]=react.useState(null),o=e.filter(a=>a.rulesPrimary);if(o.length===0)return null;let l=o.find(a=>a.ticker===s)??o[0];return l?.rulesPrimary?jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-2",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium lg:text-base",children:n("predict.event.rules")}),o.length>1&&jsxRuntime.jsx(ui.Select,{size:"sm","aria-label":"Select market rules",className:"max-w-48",classNames:{trigger:"min-h-8 h-8",value:"text-xs"},selectedKeys:new Set([l.ticker]),onSelectionChange:a=>{if(a==="all")return;let c=Array.from(a);c.length>0&&i(c[0]);},children:o.map(a=>jsxRuntime.jsx(ui.SelectItem,{textValue:a.yesSubTitle,children:jsxRuntime.jsx("span",{className:"text-xs truncate",children:a.yesSubTitle})},a.ticker))}),jsxRuntime.jsx("div",{className:"text-xs text-foreground lg:text-sm",children:l.rulesPrimary}),jsxRuntime.jsx("span",{className:"text-xs font-medium text-default-500 mt-2 lg:text-sm",children:"Timeline and payout"}),jsxRuntime.jsx(nl,{market:l}),jsxRuntime.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 text-xxs text-default-400 mt-2 lg:text-xs",children:[r?.ticker&&jsxRuntime.jsxs("span",{children:[jsxRuntime.jsx("span",{className:"text-default-500",children:"Series:"})," ",jsxRuntime.jsx("span",{className:"text-foreground",children:r.ticker})]}),t.ticker&&jsxRuntime.jsxs("span",{children:[jsxRuntime.jsx("span",{className:"text-default-500",children:"Event:"})," ",jsxRuntime.jsx("span",{className:"text-foreground",children:t.ticker})]}),jsxRuntime.jsxs("span",{children:[jsxRuntime.jsx("span",{className:"text-default-500",children:"Market:"})," ",jsxRuntime.jsx("span",{className:"text-foreground",children:l.ticker})]})]})]}):null}var pl=[{value:M.ONE_DAY,label:"1D"},{value:M.ONE_WEEK,label:"1W"},{value:M.ONE_MONTH,label:"1M"},{value:M.ALL,label:"ALL"}];function Mn({event:e,series:t,candlesticks:r,chartRange:n=M.ONE_DAY,periodInterval:s,isCandlesticksLoading:i,onRangeChange:o,selectedMarketTickers:l,onMarketSelectionChange:a,onTradeAction:c}){let{t:u}=i18n.useTranslation(),[m,p]=react.useState(jr()),[f,d]=react.useState(false),b=react.useRef(null);react.useEffect(()=>{let y=b.current;if(!y)return;let C=false,R=0,S=()=>{let{bottom:P}=y.getBoundingClientRect(),E=C?P<0:P<-20;E!==C&&(C=E,d(E));},A=()=>{cancelAnimationFrame(R),R=requestAnimationFrame(S);};return window.addEventListener("scroll",A,{passive:true,capture:true}),S(),()=>{cancelAnimationFrame(R),window.removeEventListener("scroll",A,{capture:true});}},[]);let g=react.useMemo(()=>[...e.markets||[]].sort((y,C)=>Number(C.yesAsk??0)-Number(y.yesAsk??0)),[e.markets]),{holdings:x}=zr(g),v=react.useMemo(()=>utils.formatAmountUSDCompact((e.volume??0)/100),[e.volume]),k=react.useMemo(()=>{if(!e.strikeDate)return null;let y=new Date(e.strikeDate*1e3),C=y.toLocaleString("default",{month:"short"}),R=y.getDate(),S=y.getFullYear();return `${C} ${R}, ${S}`},[e.strikeDate]);return jsxRuntime.jsxs("div",{className:"w-full flex flex-col gap-4 lg:gap-y-6 px-1 pb-8 lg:px-4 lg:pb-12 lg:max-w-3xl",children:[jsxRuntime.jsx("div",{ref:b,className:"h-0 w-0"}),jsxRuntime.jsxs("div",{className:`sticky top-0 z-30 flex items-center bg-background/80 backdrop-blur-md transition-all duration-300 ${f?"gap-x-2 py-2 px-1 lg:px-4 -mx-1 lg:-mx-4 shadow-sm":"gap-x-2 lg:gap-x-4"}`,children:[jsxRuntime.jsx(ui.Avatar,{src:e.imageUrl||void 0,name:e.title||"Event",radius:"lg",className:`flex-shrink-0 transition-all duration-300 ${f?"!h-8 !w-8 lg:!h-10 lg:!w-10":"!h-14 !w-14 lg:!h-18 lg:!w-18"}`}),jsxRuntime.jsxs("div",{className:"flex flex-col min-w-0",children:[!f&&(t?.category||t?.tags&&t.tags.length>0)&&jsxRuntime.jsxs("span",{className:"text-xs text-default-500 lg:text-sm truncate",children:[t.category,t.category&&t.tags?.length>0&&" \xB7 ",t.tags?.join(", ")]}),jsxRuntime.jsx("span",{className:`font-semibold truncate transition-all duration-300 ${f?"text-sm lg:text-base":"text-lg lg:text-xl"}`,children:e.title})]})]}),jsxRuntime.jsx("div",{className:"flex flex-col gap-y-4",children:jsxRuntime.jsxs("div",{className:"flex flex-col",children:[m&&m.markets.length>0&&jsxRuntime.jsx("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2 text-xs lg:text-sm",children:m.markets.map(y=>jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2",children:[jsxRuntime.jsx("div",{className:"h-3 w-3 shrink-0 rounded-full",style:{backgroundColor:y.color}}),jsxRuntime.jsx("span",{className:"text-default-600",children:y.label})]},y.id))}),jsxRuntime.jsx(Gr,{candlesticks:r,chartRange:n,markets:g,isLoading:i,onDataChange:y=>p(y)}),jsxRuntime.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-4 gap-y-2 mt-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-x-3 text-xs text-default-500 lg:text-sm",children:[jsxRuntime.jsxs("span",{children:[v," ",u("predict.event.volume")]}),k&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{className:"text-default-300",children:"\xB7"}),jsxRuntime.jsx("span",{children:u("predict.event.endDate",{date:k})})]})]}),jsxRuntime.jsx("div",{className:"flex items-center gap-x-1",children:pl.map(y=>jsxRuntime.jsx("button",{type:"button",onClick:()=>o?.(y.value),className:`px-2 lg:px-3 py-1 text-xs rounded-md transition-colors cursor-pointer ${n===y.value?"bg-primary text-primary-foreground":"bg-default-100 text-default-600 hover:bg-default-200"}`,children:y.label},y.value))}),g.length>1&&jsxRuntime.jsx(ui.Select,{size:"sm",selectionMode:"multiple",placeholder:"Markets","aria-label":"Select markets",className:"min-w-28 max-w-48",classNames:{trigger:"min-h-8 h-8",value:"text-xs"},selectedKeys:l?new Set(l):void 0,onSelectionChange:y=>{if(y==="all")return;let C=Array.from(y);C.length<=4&&a?.(C);},children:jsxRuntime.jsx(ui.SelectSection,{title:`Pick up to ${4} markets`,classNames:{heading:"text-xs text-default-400 px-2 py-1"},children:g.map(y=>jsxRuntime.jsx(ui.SelectItem,{textValue:y.yesSubTitle,children:jsxRuntime.jsx("span",{className:"text-xs truncate",children:y.yesSubTitle})},y.ticker))})})]})]})}),jsxRuntime.jsx(Pn,{markets:g,onTradeAction:c,marketHoldings:x,renderMarketDetail:y=>jsxRuntime.jsx(fn,{market:y,onTradeAction:c})}),jsxRuntime.jsx(Sn,{markets:g,event:e,series:t})]})}function Wt({eventId:e,initialMarketTickers:t,initialChartRange:r=pe,onTradeAction:n}){let[s,i]=react.useState(r),[o,l]=react.useState(t),{event:a,isEventLoading:c,eventError:u,series:m,isSeriesLoading:p,periodInterval:f,candlesticks:d,isCandlesticksLoading:b,candlestickErrors:g}=Vr({eventId:e,candlestickMarketTickers:o,chartRange:s}),x=react.useRef(!!t);react.useEffect(()=>{if(a?.markets&&!x.current){x.current=true;let y=[...a.markets].sort((C,R)=>Number(R.yesAsk??0)-Number(C.yesAsk??0)).slice(0,4).map(C=>C.ticker);l(y);}},[a?.markets]);let v=react.useMemo(()=>y=>{i(y);},[]),k=react.useMemo(()=>y=>{l(y);},[]);return c||p?jsxRuntime.jsx(Be,{}):u||!a?jsxRuntime.jsx("div",{className:"flex w-full items-center justify-center py-20 text-danger",children:u?.message||"Event not found"}):jsxRuntime.jsx(Mn,{event:a,series:m,candlesticks:d,chartRange:s,periodInterval:f,isCandlesticksLoading:b,candlestickErrors:g,onRangeChange:v,selectedMarketTickers:o,onMarketSelectionChange:k,onTradeAction:n})}function cg({eventId:e,chain:t,...r}){let{t:n}=i18n.useTranslation(),{isMobile:s}=ui.useScreen(),{isOpen:i,onOpen:o,onClose:l}=ui.useDisclosure(),{data:a,isLoading:c}=Fe({id:e,withNestedMarkets:true}),u=react.useMemo(()=>[...a?.markets||[]].sort((g,x)=>Number(x.yesAsk??0)-Number(g.yesAsk??0)),[a?.markets]),[m,p]=react.useState(null),f=react.useCallback((g,x,v)=>{p(k=>({market:g,outcome:x,side:v,version:(k?.version??0)+1})),s&&o();},[s,o]),d=m?.market??u[0];if(c)return s?jsxRuntime.jsx(Be,{}):jsxRuntime.jsxs("div",{className:"flex w-full max-w-6xl mx-auto gap-x-4 lg:gap-x-6",children:[jsxRuntime.jsx("div",{className:"min-w-0 flex-1 max-w-3xl",children:jsxRuntime.jsx(Be,{})}),jsxRuntime.jsx("aside",{className:"hidden lg:block w-[340px] xl:w-[380px] shrink-0",children:jsxRuntime.jsx("div",{className:"sticky top-4",children:jsxRuntime.jsx($r,{})})})]});let b=m?`${m.market.ticker}-${m.version}`:d?.ticker??"default";return s?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"w-full pb-20",children:jsxRuntime.jsx(Wt,{eventId:e,onTradeAction:f,...r})}),d&&jsxRuntime.jsx("div",{className:"fixed inset-x-0 bottom-0 z-40 flex justify-center p-3 bg-gradient-to-t from-background via-background/90 to-transparent",children:jsxRuntime.jsx(ui.Button,{color:"primary",size:"lg",className:"w-full max-w-md font-semibold",onPress:o,children:n("predict.trade.action")})}),jsxRuntime.jsx(ui.Drawer,{isOpen:i,onClose:l,placement:"bottom",size:"lg",hideCloseButton:true,classNames:{base:"max-h-[85dvh] rounded-t-2xl",body:"p-0"},children:jsxRuntime.jsx(ui.DrawerContent,{children:jsxRuntime.jsx(ui.DrawerBody,{children:d&&jsxRuntime.jsx(wt,{event:a,market:d,initialSide:m?.side,initialOutcome:m?.outcome,chain:t},b)})})})]}):jsxRuntime.jsxs("div",{className:"flex w-full max-w-6xl mx-auto gap-x-4 lg:gap-x-6",children:[jsxRuntime.jsx("div",{className:"min-w-0 flex-1 max-w-3xl",children:jsxRuntime.jsx(Wt,{eventId:e,onTradeAction:f,...r})}),d&&jsxRuntime.jsx("aside",{className:"hidden lg:block w-[340px] xl:w-[380px] shrink-0",children:jsxRuntime.jsx("div",{className:"sticky top-4 flex flex-col gap-y-4",children:jsxRuntime.jsx(wt,{event:a,market:d,initialSide:m?.side,initialOutcome:m?.outcome,chain:t},b)})})]})}function On(e,t){if(!e)return [];let r=e.slice(0,t),n=0,s=r.map(o=>(n+=o.quantity,{...o,cumulative:n,depth:0})),i=s[s.length-1]?.cumulative??1;for(let o of s)o.depth=o.cumulative/i;return s}function Nn({marketTicker:e,maxLevels:t=10,refetchInterval:r=5e3,outcome:n="yes"}){let{data:s,isLoading:i,isFetching:o}=we(e,{refetchInterval:r||void 0}),l=react.useMemo(()=>n==="yes"?s?.yesBids:s?.noBids,[s,n]),a=react.useMemo(()=>n==="yes"?s?.yesAsks:s?.noAsks,[s,n]),c=react.useMemo(()=>On(l,t),[l,t]),u=react.useMemo(()=>On(a,t),[a,t]),m=react.useMemo(()=>c.length===0||u.length===0?null:u[0].price-c[0].price,[c,u]),p=react.useMemo(()=>c.length===0||u.length===0?null:(c[0].price+u[0].price)/2,[c,u]),f=react.useMemo(()=>m===null||p===null||p===0?null:Math.round(m/p*1e4)/100,[m,p]);return {bids:c,asks:u,spread:m,spreadPercent:f,midpoint:p,isLoading:i,isFetching:o}}function En({row:e,side:t,onClick:r}){let n=t==="bid",s=n?"bg-primary/10":"bg-danger/10",i=n?"text-primary":"text-danger";return jsxRuntime.jsxs("button",{type:"button",className:"relative flex w-full items-center justify-between px-3 py-1 text-xs hover:bg-default-100 cursor-pointer",onClick:()=>r?.(e.price),children:[jsxRuntime.jsx("div",{className:`absolute inset-y-0 ${n?"right-0":"left-0"} ${s}`,style:{width:`${e.depth*100}%`}}),jsxRuntime.jsxs("span",{className:`relative z-10 font-medium ${i}`,children:[e.price,"\xA2"]}),jsxRuntime.jsx("span",{className:"relative z-10 text-default-600",children:e.quantity}),jsxRuntime.jsx("span",{className:"relative z-10 text-default-400",children:e.cumulative})]})}function In(){return jsxRuntime.jsx("div",{className:"flex flex-col gap-y-1 py-2",children:Array.from({length:5}).map((e,t)=>jsxRuntime.jsx("div",{className:"mx-3 h-4 animate-pulse rounded bg-default-100"},t))})}function Qn({bids:e,asks:t,spread:r,spreadPercent:n,isLoading:s,onPriceClick:i}){let{t:o}=i18n.useTranslation();if(s)return jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsx("div",{className:"border-b border-default-200 px-3 py-2 text-sm font-medium",children:o("predict.orderBook.title")}),jsxRuntime.jsx(In,{}),jsxRuntime.jsx(In,{})]});let l=e.length===0&&t.length===0;return jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsx("div",{className:"flex items-center justify-between border-b border-default-200 px-3 py-2",children:jsxRuntime.jsx("span",{className:"text-sm font-medium",children:o("predict.orderBook.title")})}),l?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-default-400",children:o("predict.orderBook.empty")}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between px-3 py-1 text-xxs text-default-400",children:[jsxRuntime.jsx("span",{children:o("predict.orderBook.price")}),jsxRuntime.jsx("span",{children:o("predict.orderBook.qty")}),jsxRuntime.jsx("span",{children:o("predict.orderBook.total")})]}),jsxRuntime.jsx("div",{className:"flex flex-col-reverse",children:t.map(a=>jsxRuntime.jsx(En,{row:a,side:"ask",onClick:i},a.price))}),r!==null&&jsxRuntime.jsxs("div",{className:"flex items-center justify-center gap-x-2 border-y border-default-200 py-1.5 text-xs text-default-500",children:[jsxRuntime.jsxs("span",{children:[o("predict.orderBook.spread"),": ",r,"\xA2"]}),n!==null&&jsxRuntime.jsxs("span",{className:"text-default-400",children:["(",n,"%)"]})]}),jsxRuntime.jsx("div",{className:"flex flex-col",children:e.map(a=>jsxRuntime.jsx(En,{row:a,side:"bid",onClick:i},a.price))})]})]})}function Eg({marketTicker:e,maxLevels:t,refetchInterval:r,onPriceClick:n,outcome:s}){let{bids:i,asks:o,spread:l,spreadPercent:a,isLoading:c}=Nn({marketTicker:e,maxLevels:t,refetchInterval:r,outcome:s});return jsxRuntime.jsx(Qn,{bids:i,asks:o,spread:l,spreadPercent:a,isLoading:c,onPriceClick:n})}function Ln(e={}){let[t,r]=react.useState(null),[n]=react.useState(null),s=react.useCallback(i=>{r(null);},[]);return {orders:[],isLoading:false,isFetching:false,cancellingOrderId:t,cancelOrder:s,cancelError:n}}function Dl(e){return new Date(e).toLocaleString("default",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function Un({orders:e,isLoading:t,cancellingOrderId:r,onCancel:n}){let{t:s}=i18n.useTranslation(),i=react.useMemo(()=>e.map(o=>({key:o.id,side:o.side,outcome:o.outcome,type:o.type,price:o.price,filled:`${o.filledQuantity}/${o.quantity}`,status:o.status,createdAt:Dl(o.createdAt),isCancelling:o.id===r,id:o.id})),[e,r]);return t?jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsx("div",{className:"border-b border-default-200 px-3 py-2 text-sm font-medium",children:s("predict.openOrders.title")}),jsxRuntime.jsx("div",{className:"flex flex-col gap-y-2 p-3",children:Array.from({length:3}).map((o,l)=>jsxRuntime.jsx("div",{className:"h-8 animate-pulse rounded bg-default-100"},l))})]}):jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsxs("div",{className:"border-b border-default-200 px-3 py-2 text-sm font-medium",children:[s("predict.openOrders.title"),e.length>0&&jsxRuntime.jsxs("span",{className:"ml-1 text-default-400",children:["(",e.length,")"]})]}),e.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-default-400",children:s("predict.openOrders.empty")}):jsxRuntime.jsx("div",{className:"w-full overflow-x-auto",children:jsxRuntime.jsxs(ui.StyledTable,{radius:"none","aria-label":"Open orders",className:"min-w-[600px]",children:[jsxRuntime.jsxs(ui.TableHeader,{children:[jsxRuntime.jsx(ui.TableColumn,{textValue:"Side",width:60,children:s("predict.openOrders.side")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Outcome",width:60,children:s("predict.openOrders.outcome")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Type",width:60,children:s("predict.openOrders.type")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Price",width:60,children:s("predict.openOrders.price")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Filled",width:80,children:s("predict.openOrders.filled")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Status",width:70,children:s("predict.openOrders.status")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Time",width:120,children:s("predict.openOrders.time")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Action",width:80,align:"end",children:" "})]}),jsxRuntime.jsx(ui.TableBody,{children:i.map(o=>jsxRuntime.jsxs(ui.TableRow,{children:[jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:`text-xs font-medium ${o.side==="buy"?"text-primary":"text-danger"}`,children:o.side==="buy"?s("predict.trade.buy"):s("predict.trade.sell")})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:`text-xs ${o.outcome==="yes"?"text-primary":"text-secondary"}`,children:o.outcome==="yes"?s("predict.trade.yes"):s("predict.trade.no")})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs capitalize",children:o.type})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("span",{className:"text-xs",children:[o.price,"\xA2"]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs",children:o.filled})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs capitalize",children:o.status})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs text-default-500",children:o.createdAt})}),jsxRuntime.jsx(ui.TableCell,{className:"text-right",children:jsxRuntime.jsx(ui.Button,{size:"sm",variant:"flat",color:"danger",isLoading:o.isCancelling,onPress:()=>n(o.id),children:s("predict.openOrders.cancel")})})]},o.key))})]})})]})}function zg({refetchInterval:e}={}){let{orders:t,isLoading:r,cancellingOrderId:n,cancelOrder:s}=Ln({});return jsxRuntime.jsx(Un,{orders:t,isLoading:r,cancellingOrderId:n,onCancel:s})}function Dn({ticker:e,pageSize:t=48}={}){let[r,n]=react.useState(1),[s,i]=react.useState([void 0]),o=s[r-1],l=react.useMemo(()=>({...e?{ticker:e}:{},limit:t,...o?{cursor:o}:{}}),[e,t,o]),{data:a,isLoading:c,isFetching:u}=Xt(l),m=a,p=m?.trades??[],f=!!m?.cursor,d=r>1,b=react.useCallback(v=>{v>=1&&v<=s.length&&n(v);},[s.length]),g=react.useCallback(()=>{f&&m?.cursor&&(i(v=>{let k=[...v];return k.length===r&&k.push(m.cursor),k}),n(v=>v+1));},[f,m?.cursor,r]),x=react.useCallback(()=>{d&&n(v=>v-1);},[d]);return {trades:p,isLoading:c,isFetching:u,page:r,pageSize:t,hasNextPage:f,hasPrevPage:d,goToPage:b,nextPage:g,prevPage:x}}function Gl(e){return new Date(e*1e3).toLocaleString("default",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function _n({trades:e,isLoading:t,isFetching:r,page:n,hasNextPage:s,hasPrevPage:i,onNextPage:o,onPrevPage:l}){let{t:a}=i18n.useTranslation(),c=react.useMemo(()=>e.map(u=>({key:u.tradeId,ticker:u.ticker,takerSide:u.takerSide,price:u.price,yesPrice:u.yesPrice,noPrice:u.noPrice,count:u.count,createdAt:Gl(u.createdTime)})),[e]);return t?jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsx("div",{className:"border-b border-default-200 px-3 py-2 text-sm font-medium",children:a("predict.tradeHistory.title")}),jsxRuntime.jsx("div",{className:"flex flex-col gap-y-2 p-3",children:Array.from({length:3}).map((u,m)=>jsxRuntime.jsx("div",{className:"h-8 animate-pulse rounded bg-default-100"},m))})]}):jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsx("div",{className:"border-b border-default-200 px-3 py-2 text-sm font-medium",children:a("predict.tradeHistory.title")}),e.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-default-400",children:a("predict.tradeHistory.empty")}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:`w-full overflow-x-auto ${r?"opacity-60":""}`,children:jsxRuntime.jsxs(ui.StyledTable,{radius:"none","aria-label":"Trade history",className:"min-w-[480px]",children:[jsxRuntime.jsxs(ui.TableHeader,{children:[jsxRuntime.jsx(ui.TableColumn,{textValue:"Side",width:60,children:a("predict.tradeHistory.side")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Price",width:80,children:a("predict.tradeHistory.price")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Yes",width:60,children:a("predict.trade.yes")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"No",width:60,children:a("predict.trade.no")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Qty",width:60,children:a("predict.tradeHistory.qty")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Time",width:120,children:a("predict.tradeHistory.time")})]}),jsxRuntime.jsx(ui.TableBody,{children:c.map(u=>jsxRuntime.jsxs(ui.TableRow,{children:[jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:`text-xs font-medium ${u.takerSide==="yes"?"text-primary":"text-secondary"}`,children:u.takerSide==="yes"?a("predict.trade.yes"):a("predict.trade.no")})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("span",{className:"text-xs",children:[u.price,"\xA2"]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("span",{className:"text-xs text-primary",children:[u.yesPrice,"\xA2"]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("span",{className:"text-xs text-secondary",children:[u.noPrice,"\xA2"]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs",children:u.count})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs text-default-500",children:u.createdAt})})]},u.key))})]})}),(i||s)&&jsxRuntime.jsxs("div",{className:"flex items-center justify-between border-t border-default-200 px-3 py-2",children:[jsxRuntime.jsx(ui.Button,{size:"sm",variant:"flat",isDisabled:!i,onPress:l,startContent:jsxRuntime.jsx(ui.ChevronLeftIcon,{className:"h-3 w-3"}),children:a("predict.pagination.prev")}),jsxRuntime.jsx("span",{className:"text-xs text-default-500",children:a("predict.pagination.page",{page:n})}),jsxRuntime.jsx(ui.Button,{size:"sm",variant:"flat",isDisabled:!s,onPress:o,endContent:jsxRuntime.jsx(ui.ChevronRightIcon,{className:"h-3 w-3"}),children:a("predict.pagination.next")})]})]})]})}function dx({ticker:e,pageSize:t}={}){let{trades:r,isLoading:n,isFetching:s,page:i,hasNextPage:o,hasPrevPage:l,nextPage:a,prevPage:c}=Dn({ticker:e,pageSize:t});return jsxRuntime.jsx(_n,{trades:r,isLoading:n,isFetching:s,page:i,hasNextPage:o,hasPrevPage:l,onNextPage:a,onPrevPage:c})}function Fn(e={}){let t=react.useMemo(()=>({totalValue:0,totalUnrealizedPnl:0,totalRealizedPnl:0,count:0}),[]);return {positions:[],isLoading:false,isFetching:false,summary:t}}var Je=e=>utils.formatAmountUSDCompact(e/100);function qt({value:e}){if(e===0)return jsxRuntime.jsx("span",{className:"text-default-500",children:Je(0)});let t=e>0;return jsxRuntime.jsxs("span",{className:t?"text-success":"text-danger",children:[t?"+":"",Je(e)]})}function qn({positions:e,isLoading:t,summary:r,onSell:n}){let{t:s}=i18n.useTranslation(),i=react.useMemo(()=>e.map(o=>({key:`${o.marketId}-${o.outcome}`,marketTitle:o.marketTitle,outcome:o.outcome,quantity:o.quantity,avgCost:o.avgCostBasis,currentPrice:o.currentPrice,value:o.currentPrice*o.quantity,unrealizedPnl:o.unrealizedPnl,position:o})),[e]);return t?jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsx("div",{className:"border-b border-default-200 px-3 py-2 text-sm font-medium",children:s("predict.positions.title")}),jsxRuntime.jsx("div",{className:"flex flex-col gap-y-2 p-3",children:Array.from({length:3}).map((o,l)=>jsxRuntime.jsx("div",{className:"h-8 animate-pulse rounded bg-default-100"},l))})]}):jsxRuntime.jsxs("div",{className:"flex w-full flex-col rounded-xl border border-default-200 bg-content1",children:[jsxRuntime.jsx("div",{className:"flex items-center justify-between border-b border-default-200 px-3 py-2",children:jsxRuntime.jsxs("span",{className:"text-sm font-medium",children:[s("predict.positions.title"),e.length>0&&jsxRuntime.jsxs("span",{className:"ml-1 text-default-400",children:["(",e.length,")"]})]})}),e.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-default-400",children:s("predict.positions.empty")}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"w-full overflow-x-auto",children:jsxRuntime.jsxs(ui.StyledTable,{radius:"none","aria-label":"Positions",className:"min-w-[640px]",children:[jsxRuntime.jsxs(ui.TableHeader,{children:[jsxRuntime.jsx(ui.TableColumn,{textValue:"Market",width:200,children:s("predict.positions.market")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Outcome",width:60,children:s("predict.positions.outcome")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Qty",width:50,children:s("predict.positions.qty")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Avg Cost",width:70,children:s("predict.positions.avgCost")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Price",width:60,children:s("predict.positions.currentPrice")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Value",width:80,children:s("predict.positions.value")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"PnL",width:80,children:s("predict.positions.pnl")})]}),jsxRuntime.jsx(ui.TableBody,{children:i.map(o=>jsxRuntime.jsxs(ui.TableRow,{className:n?"cursor-pointer hover:bg-default-50":"",onClick:()=>n?.(o.position),children:[jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs font-medium line-clamp-1",children:o.marketTitle})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:`text-xs font-medium ${o.outcome==="yes"?"text-primary":"text-secondary"}`,children:o.outcome==="yes"?s("predict.trade.yes"):s("predict.trade.no")})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs",children:o.quantity})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("span",{className:"text-xs",children:[o.avgCost,"\xA2"]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsxs("span",{className:"text-xs",children:[o.currentPrice,"\xA2"]})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs",children:Je(o.value)})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs",children:jsxRuntime.jsx(qt,{value:o.unrealizedPnl})})})]},o.key))})]})}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between border-t border-default-200 px-3 py-2 text-xs",children:[jsxRuntime.jsx("div",{className:"flex items-center gap-x-4",children:jsxRuntime.jsxs("span",{className:"text-default-500",children:[s("predict.positions.totalValue"),":"," ",jsxRuntime.jsx("span",{className:"font-medium text-foreground",children:Je(r.totalValue)})]})}),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-4",children:[jsxRuntime.jsxs("span",{className:"text-default-500",children:[s("predict.positions.unrealizedPnl"),":"," ",jsxRuntime.jsx(qt,{value:r.totalUnrealizedPnl})]}),jsxRuntime.jsxs("span",{className:"text-default-500",children:[s("predict.positions.realizedPnl"),":"," ",jsxRuntime.jsx(qt,{value:r.totalRealizedPnl})]})]})]})]})]})}function Rx({refetchInterval:e,onSell:t}={}){let{positions:r,isLoading:n,summary:s}=Fn({});return jsxRuntime.jsx(qn,{positions:r,isLoading:n,summary:s,onSell:t})}function jx({client:e,wsClient:t=null,children:r}){let n=react.useMemo(()=>({client:e,wsClient:t}),[e,t]);return jsxRuntime.jsx(Te.Provider,{value:n,children:r})}var dc=3e4;function rh({walletAddress:e,pollingInterval:t=dc,enabled:r=true,children:n}){let{data:s,isLoading:i,error:o,refetch:l}=sr({walletAddress:e},{enabled:r&&!!e,refetchInterval:t}),a=react.useMemo(()=>({positions:s?.positions??[],isLoading:i,error:o??null,refetch:l}),[s?.positions,i,o,l]);return jsxRuntime.jsx(Me.Provider,{value:a,children:n})}function Kn(e,t){let r=new URLSearchParams;t&&r.set("provider",t);for(let[s,i]of Object.entries(e))i!=null&&(typeof i=="object"?r.set(s,JSON.stringify(i)):r.set(s,String(i)));let n=r.toString();return n?`?${n}`:""}function Hn(e){return e}var De=class{constructor(t,r){this.endpoint=t;this.provider=r;}buildUrl(t,r){let n=Kn(r??{},this.provider);return `${this.endpoint}${t}${n}`}async fetch(t,r){let n=this.buildUrl(t,r);return await utils.httpGet(n)}async postRequest(t,r,n){let s=this.buildUrl(t,n);return await utils.httpPost(s,r)}};function et(e,t){if(!e)return [];let r=Object.entries(e).map(([n,s])=>({price:parseFloat(n),quantity:s}));return r.sort((n,s)=>t==="desc"?s.price-n.price:n.price-s.price),r}function $n(e){return {yesBids:et(e.yes_bids,"desc"),yesAsks:et(e.yes_asks,"asc"),noBids:et(e.no_bids,"desc"),noAsks:et(e.no_asks,"asc"),sequence:e.sequence}}var tt=class extends De{constructor(t){super(t,"dflow");}async getEvents(t){return await this.fetch("/v2/event",t??{})}async getEventById(t,r){return await this.fetch(`/v2/event/${t}`,{withNestedMarkets:r})}async getEventCandlesticks(t,r){return await this.fetch(`/v2/event/${t}/candlesticks`,r)}async getEventForecastPercentileHistory(t){let{seriesTicker:r,eventId:n,...s}=t;return await this.fetch(`/v2/event/${r}/${n}/forecast_percentile_history`,s)}async getEventForecastPercentileHistoryByMint(t){let{mintAddress:r,...n}=t;return await this.fetch(`/v2/event/by-mint/${r}/forecast_percentile_history`,n)}async getMarkets(t){return await this.fetch("/v2/market",t??{})}async getMarketById(t){return await this.fetch(`/v2/market/${t}`)}async getMarketByMint(t){return await this.fetch(`/v2/market/by-mint/${t}`)}async getMarketsBatch(t){return await this.postRequest("/v2/market/batch",t)}async getMarketCandlesticks(t,r){return await this.fetch(`/v2/market/${t}/candlesticks`,r)}async getMarketCandlesticksByMint(t,r){return await this.fetch(`/v2/market/by-mint/${t}/candlesticks`,r)}async getOrderbook(t){let r=await this.fetch(`/v2/orderbook/${t}`);return $n(r)}async getOrderbookByMint(t){let r=await this.fetch(`/v2/orderbook/by-mint/${t}`);return $n(r)}async getTrades(t){return await this.fetch("/v2/trades",t??{})}async getTradesByMint(t){let{mintAddress:r,...n}=t;return await this.fetch(`/v2/trades/by-mint/${r}`,n)}async getOnchainTradesByWallet(t){let{walletAddress:r,...n}=t;return await this.fetch(`/v2/trades/onchain/by-wallet/${r}`,n)}async getOnchainTradesByEvent(t){let{eventTicker:r,...n}=t;return await this.fetch(`/v2/trades/onchain/by-event/${r}`,n)}async getOnchainTradesByMarket(t){let{marketTicker:r,...n}=t;return await this.fetch(`/v2/trades/onchain/by-market/${r}`,n)}async getLiveData(t){return await this.fetch("/v2/live",{milestoneIds:t.milestoneIds.join(",")})}async getLiveDataByEvent(t){let{eventTicker:r,...n}=t;return await this.fetch(`/v2/live/event/${r}`,n)}async getLiveDataByMint(t){let{mintAddress:r,...n}=t;return await this.fetch(`/v2/live/by-mint/${r}`,n)}async getSeries(t){return await this.fetch("/v2/series",t??{})}async getSeriesByTicker(t){return await this.fetch(`/v2/series/${t}`)}async getTagsByCategories(){return await this.fetch("/v2/tags/by_categories")}async getFiltersBySports(){return await this.fetch("/v2/sports/filters")}async search(t){return await this.fetch("/v2/search",t)}async getPositionsByWallet(t){let{walletAddress:r}=t;return await this.fetch(`/v2/positions/by-wallet/${r}`)}async getOutcomeMints(t){return await this.fetch("/v2/outcome_mints",t??{})}async filterOutcomeMints(t){return await this.postRequest("/v2/filter_outcome_mints",t)}async getQuote(t){return await this.fetch("/v2/swap/quote",t)}async createSwap(t){return await this.postRequest("/v2/swap",t)}async createSwapInstructions(t){return await this.postRequest("/v2/swap/instructions",t)}async getOrder(t){return await this.fetch("/v2/order",t)}async getOrderStatus(t){return await this.fetch("/v2/order/status",t)}async getIntentQuote(t){return await this.fetch("/v2/intent/quote",t)}async submitIntentSwap(t){return await this.postRequest("/v2/intent/swap",t)}async initPredictionMarket(t){return await this.fetch("/v2/prediction-market/init",t)}async getTokens(){return await this.fetch("/v2/tokens")}async getTokensWithDecimals(){return await this.fetch("/v2/tokens/decimals")}async getVenues(){return await this.fetch("/v2/venues")}};exports.BasePredictClient=De;exports.CHART_RANGE_DURATION=ze;exports.CHART_RANGE_PERIOD=$e;exports.CHART_RANGE_SAMPLE_INTERVAL=Ve;exports.CandlestickPeriod=He;exports.CategoriesSkeleton=Cr;exports.CategoriesUI=Pr;exports.CategoriesWidget=wr;exports.ChartRange=M;exports.DEFAULT_CHART_RANGE=pe;exports.DEFAULT_PAGE_SIZE=be;exports.DEFAULT_PRICE_HISTORY_INTERVAL=om;exports.DflowPredictClient=tt;exports.DflowPredictWsClient=Ie;exports.EventDetailPage=cg;exports.EventDetailSkeleton=Be;exports.EventDetailUI=Mn;exports.EventDetailWidget=Wt;exports.EventItemSkeleton=ia;exports.EventItemUI=Qr;exports.EventMarketDetailWidget=fn;exports.EventsPage=Fm;exports.EventsSkeleton=Or;exports.EventsUI=Ur;exports.EventsWidget=Dr;exports.MAX_PRICE_HISTORY_MARKETS=de;exports.ORDER_MAX_PRICE=sm;exports.ORDER_MIN_PRICE=nm;exports.ORDER_MIN_QUANTITY=kt;exports.ORDER_PRICE_STEP=rm;exports.OpenOrdersUI=Un;exports.OpenOrdersWidget=zg;exports.OrderBookUI=Qn;exports.OrderBookWidget=Eg;exports.PRICE_HISTORY_SAMPLE_INTERVAL=am;exports.PositionsUI=qn;exports.PositionsWidget=Rx;exports.PredictClient=tt;exports.PredictContext=Te;exports.PredictProvider=jx;exports.PredictWsClient=Ie;exports.PriceHistoryInterval=Re;exports.TradeFormSkeleton=$r;exports.TradeFormUI=Hr;exports.TradeFormWidget=wt;exports.TradeHistoryUI=_n;exports.TradeHistoryWidget=dx;exports.UserPredictContext=Me;exports.UserPredictProvider=rh;exports.buildQuery=Kn;exports.createDflowPredictWsClient=qe;exports.createPredictWsClient=qe;exports.createSwap=wo;exports.createSwapInstructions=Ro;exports.eventByIdQueryKey=ms;exports.eventCandlesticksQueryKey=Fs;exports.eventsInfiniteQueryKey=ds;exports.eventsQueryKey=cs;exports.fetchEventById=ys;exports.fetchEventCandlesticks=qs;exports.fetchEvents=it;exports.fetchFiltersBySports=lo;exports.fetchForecastPercentileHistory=Vs;exports.fetchForecastPercentileHistoryByMint=Ys;exports.fetchIntentQuote=Uo;exports.fetchLiveData=js;exports.fetchLiveDataByEvent=Zs;exports.fetchLiveDataByMint=eo;exports.fetchMarketById=vs;exports.fetchMarketByMint=Cs;exports.fetchMarketCandlesticks=gt;exports.fetchMarketCandlesticksByMint=Hs;exports.fetchMarkets=xs;exports.fetchMarketsBatch=Ms;exports.fetchOnchainTradesByEvent=ut;exports.fetchOnchainTradesByMarket=dt;exports.fetchOnchainTradesByWallet=ct;exports.fetchOrder=No;exports.fetchOrderBook=Rs;exports.fetchOrderBookByMint=Ns;exports.fetchOrderStatus=Io;exports.fetchOutcomeMints=Po;exports.fetchPositionsByWallet=fo;exports.fetchQuote=Mo;exports.fetchSearch=po;exports.fetchSeries=ro;exports.fetchSeriesByTicker=so;exports.fetchTagsByCategories=ao;exports.fetchTokens=Fo;exports.fetchTokensWithDecimals=Ko;exports.fetchTrades=Is;exports.fetchTradesByMint=Bs;exports.fetchVenues=Vo;exports.filterOutcomeMints=Co;exports.filtersBySportsQueryKey=io;exports.forecastPercentileHistoryByMintQueryKey=zs;exports.forecastPercentileHistoryQueryKey=$s;exports.initPredictionMarket=Wo;exports.intentQuoteQueryKey=Lo;exports.liveDataByEventQueryKey=Xs;exports.liveDataByMintQueryKey=Js;exports.liveDataQueryKey=Gs;exports.marketByIdQueryKey=bs;exports.marketByMintQueryKey=Ps;exports.marketCandlesticksByMintQueryKey=Ks;exports.marketCandlesticksQueryKey=ft;exports.marketsBatchQueryKey=Ts;exports.marketsQueryKey=gs;exports.onchainTradesByEventInfiniteQueryKey=Ws;exports.onchainTradesByEventQueryKey=Us;exports.onchainTradesByMarketInfiniteQueryKey=_s;exports.onchainTradesByMarketQueryKey=As;exports.onchainTradesByWalletInfiniteQueryKey=Ds;exports.onchainTradesByWalletQueryKey=Ls;exports.orderBookByMintQueryKey=Os;exports.orderBookQueryKey=ws;exports.orderQueryKey=Oo;exports.orderStatusQueryKey=Eo;exports.outcomeMintsQueryKey=ko;exports.positionsByWalletQueryKey=yo;exports.quoteQueryKey=To;exports.searchQueryKey=uo;exports.seriesByTickerQueryKey=no;exports.seriesQueryKey=to;exports.submitIntentSwap=Ao;exports.tagsByCategoriesQueryKey=oo;exports.toRecord=Hn;exports.tokensQueryKey=_o;exports.tokensWithDecimalsQueryKey=qo;exports.tradesByMintQueryKey=Qs;exports.tradesQueryKey=Es;exports.useCategoriesQuery=Hu;exports.useCreateSwapInstructionsMutation=hd;exports.useCreateSwapMutation=xd;exports.useEventByIdQuery=Fe;exports.useEventCandlesticksQuery=Cu;exports.useEventDetail=Vr;exports.useEvents=Rr;exports.useEventsCategories=br;exports.useEventsInfiniteQuery=Yt;exports.useEventsQuery=Nc;exports.useFilterOutcomeMintsMutation=cd;exports.useFiltersBySportsQuery=Ku;exports.useForecastPercentileHistoryByMintQuery=Nu;exports.useForecastPercentileHistoryQuery=Ou;exports.useInitPredictionMarketMutation=Ed;exports.useIntentQuoteQuery=Md;exports.useLiveDataByEventQuery=Lu;exports.useLiveDataByMintQuery=Uu;exports.useLiveDataQuery=Bu;exports.useMarketByIdQuery=$c;exports.useMarketByMintQuery=Gc;exports.useMarketCandlesticksByMintQuery=Su;exports.useMarketCandlesticksQuery=xt;exports.useMarketPositions=or;exports.useMarketsBatchQuery=Jc;exports.useMarketsQuery=Fc;exports.useOnchainTradesByEventInfiniteQuery=hu;exports.useOnchainTradesByEventQuery=du;exports.useOnchainTradesByMarketInfiniteQuery=bu;exports.useOnchainTradesByMarketQuery=pu;exports.useOnchainTradesByWalletInfiniteQuery=xu;exports.useOnchainTradesByWalletQuery=Zt;exports.useOpenOrders=Ln;exports.useOrderBook=Nn;exports.useOrderBookByMintQuery=nu;exports.useOrderBookQuery=we;exports.useOrderQuery=lr;exports.useOrderStatusQuery=Pd;exports.useOrderbookSubscription=op;exports.useOutcomeMintsQuery=ld;exports.usePositions=Fn;exports.usePositionsByWalletQuery=sr;exports.usePredictClient=h;exports.usePredictContext=zt;exports.usePriceHistoryQuery=Tu;exports.usePricesSubscription=Jd;exports.useQuoteQuery=md;exports.useSearchQuery=Yu;exports.useSeriesByTickerQuery=rr;exports.useSeriesQuery=tr;exports.useSubmitIntentSwapMutation=wd;exports.useTagsByCategoriesQuery=bt;exports.useTokensQuery=Ld;exports.useTokensWithDecimalsQuery=Ud;exports.useTradeForm=_r;exports.useTradeHistory=Dn;exports.useTradesByMintQuery=iu;exports.useTradesQuery=Xt;exports.useTradesSubscription=rp;exports.useUserPredictContext=td;exports.useVenuesQuery=_d;exports.useWsClient=jd;exports.useWsConnection=Vd;exports.venuesQueryKey=$o;exports.version=ss;//# sourceMappingURL=index.js.map
3
2
  //# sourceMappingURL=index.js.map