@liberfi.io/ui-predict 0.1.47 → 0.1.49

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,3 @@
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.47");var Wn="0.1.47";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'),Mt=require('canvas-confetti'),types=require('@liberfi.io/types'),react$1=require('@liberfi.io/react'),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.49");var os="0.1.49";var we=react.createContext({});var me=react.createContext(null);function Yt(){let e=react.useContext(we);if(!e)throw new Error("usePredictContext must be used within a PredictProvider");return e}function b(){let{client:e}=Yt();return e}function us(e){return ["predict","events",e??{}]}async function lt(e,t){return await e.getEvents(t)}function Ic(e,t={}){let r=b();return reactQuery.useQuery({queryKey:us(e),queryFn:async()=>lt(r,e),...t})}function ps(e){return ["predict","events","infinite",e??{}]}function Gt(e={},t={}){let r=b();return reactQuery.useInfiniteQuery({queryKey:ps(e),queryFn:async({pageParam:n})=>lt(r,{...e,...n!==void 0?{cursor:n}:{}}),initialPageParam:void 0,getNextPageParam:n=>n.cursor??void 0,...t})}function ys(e){return ["predict","event","byId",e.id,e.withNestedMarkets]}async function fs(e,t){return await e.getEventById(t.id,t.withNestedMarkets)}function qe(e,t={}){let r=b();return reactQuery.useQuery({queryKey:ys(e),queryFn:async()=>fs(r,e),...t})}function gs(e){return ["predict","markets",e??{}]}async function hs(e,t){return await e.getMarkets(t)}function Kc(e,t={}){let r=b();return reactQuery.useQuery({queryKey:gs(e),queryFn:async()=>hs(r,e),...t})}function vs(e){return ["predict","market","byId",e.id]}async function ks(e,t){return await e.getMarketById(t.id)}function zc(e,t={}){let r=b();return reactQuery.useQuery({queryKey:vs(e),queryFn:async()=>ks(r,e),...t})}function Cs(e){return ["predict","market","byMint",e]}async function Ss(e,t){return await e.getMarketByMint(t)}function Xc(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Cs(e),queryFn:async()=>Ss(r,e),...t})}function Ms(e){return ["predict","markets","batch",e]}async function ws(e,t){return await e.getMarketsBatch(t)}function tu(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Ms(e),queryFn:async()=>ws(r,e),enabled:!!(e.tickers?.length||e.mints?.length),...t})}function Os(e){return ["predict","orderBook",e]}async function Rs(e,t){return await e.getOrderbook(t)}function Oe(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Os(e),queryFn:async()=>Rs(r,e),...t})}function Ns(e){return ["predict","orderBook","byMint",e]}async function Es(e,t){return await e.getOrderbookByMint(t)}function ou(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Ns(e),queryFn:async()=>Es(r,e),...t})}function Is(e){return ["predict","trades",e??{}]}async function Qs(e,t){return await e.getTrades(t)}function Zt(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Is(e),queryFn:async()=>Qs(r,e),...t})}function Bs(e){return ["predict","trades","byMint",e]}async function Ls(e,t){return await e.getTradesByMint(t)}function cu(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Bs(e),queryFn:async()=>Ls(r,e),...t})}function Us(e){return ["predict","onchainTrades","byWallet",e]}async function ut(e,t){return await e.getOnchainTradesByWallet(t)}function Jt(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Us(e),queryFn:async()=>ut(r,e),...t})}function As(e){return ["predict","onchainTrades","byEvent",e]}async function dt(e,t){return await e.getOnchainTradesByEvent(t)}function mu(e,t={}){let r=b();return reactQuery.useQuery({queryKey:As(e),queryFn:async()=>dt(r,e),...t})}function Ds(e){return ["predict","onchainTrades","byMarket",e]}async function pt(e,t){return await e.getOnchainTradesByMarket(t)}function yu(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Ds(e),queryFn:async()=>pt(r,e),...t})}function yt(e){return e.cursor??void 0}function Ws(e){return ["predict","onchainTrades","byWallet","infinite",e]}function bu(e,t={}){let r=b();return reactQuery.useInfiniteQuery({queryKey:Ws(e),queryFn:async({pageParam:n})=>ut(r,{...e,...n!==void 0?{cursor:n}:{}}),initialPageParam:void 0,getNextPageParam:yt,...t})}function _s(e){return ["predict","onchainTrades","byEvent","infinite",e]}function vu(e,t={}){let r=b();return reactQuery.useInfiniteQuery({queryKey:_s(e),queryFn:async({pageParam:n})=>dt(r,{...e,...n!==void 0?{cursor:n}:{}}),initialPageParam:void 0,getNextPageParam:yt,...t})}function Fs(e){return ["predict","onchainTrades","byMarket","infinite",e]}function ku(e,t={}){let r=b();return reactQuery.useInfiniteQuery({queryKey:Fs(e),queryFn:async({pageParam:n})=>pt(r,{...e,...n!==void 0?{cursor:n}:{}}),initialPageParam:void 0,getNextPageParam:yt,...t})}function qs(e){return ["predict","candlesticks","event",e]}async function Ks(e,t){let{ticker:r,...n}=t;return await e.getEventCandlesticks(r,n)}function Tu(e,t={}){let r=b();return reactQuery.useQuery({queryKey:qs(e),queryFn:async()=>Ks(r,e),...t})}function xt(e){return ["predict","candlesticks","market",e]}async function gt(e,t){let{ticker:r,...n}=t;return await e.getMarketCandlesticks(r,n)}function ht(e,t={}){let r=b();return reactQuery.useQuery({queryKey:xt(e),queryFn:async()=>gt(r,e),...t})}function Hs(e){return ["predict","candlesticks","market","byMint",e]}async function $s(e,t){let{mintAddress:r,...n}=t;return await e.getMarketCandlesticksByMint(r,n)}function Mu(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Hs(e),queryFn:async()=>$s(r,e),...t})}var wu=ht;function Vs(e){return ["predict","forecast","percentileHistory",e]}async function zs(e,t){return await e.getEventForecastPercentileHistory(t)}function Eu(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Vs(e),queryFn:async()=>zs(r,e),...t})}function Ys(e){return ["predict","forecast","percentileHistory","byMint",e]}async function Gs(e,t){return await e.getEventForecastPercentileHistoryByMint(t)}function Iu(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Ys(e),queryFn:async()=>Gs(r,e),...t})}function js(e){return ["predict","liveData",e]}async function Xs(e,t){return await e.getLiveData(t)}function Uu(e,t={}){let r=b();return reactQuery.useQuery({queryKey:js(e),queryFn:async()=>Xs(r,e),enabled:e.milestoneIds.length>0,...t})}function Zs(e){return ["predict","liveData","byEvent",e]}async function Js(e,t){return await e.getLiveDataByEvent(t)}function Au(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Zs(e),queryFn:async()=>Js(r,e),enabled:!!e.eventTicker,...t})}function eo(e){return ["predict","liveData","byMint",e]}async function to(e,t){return await e.getLiveDataByMint(t)}function Du(e,t={}){let r=b();return reactQuery.useQuery({queryKey:eo(e),queryFn:async()=>to(r,e),enabled:!!e.mintAddress,...t})}function ro(e){return ["predict","series",e??{}]}async function no(e,t){return await e.getSeries(t)}function rr(e,t={}){let r=b();return reactQuery.useQuery({queryKey:ro(e),queryFn:async()=>no(r,e),...t})}function so(e){return ["predict","series","byTicker",e]}async function oo(e,t){return await e.getSeriesByTicker(t)}function nr(e,t={}){let r=b();return reactQuery.useQuery({queryKey:so(e),queryFn:async()=>oo(r,e),...t})}function ao(){return ["predict","tags","byCategories"]}async function io(e){return await e.getTagsByCategories()}function vt(e={}){let t=b();return reactQuery.useQuery({queryKey:ao(),queryFn:async()=>io(t),...e})}function lo(){return ["predict","filters","bySports"]}async function co(e){return await e.getFiltersBySports()}function $u(e={}){let t=b();return reactQuery.useQuery({queryKey:lo(),queryFn:async()=>co(t),...e})}var Vu=vt;function po(e){return ["predict","search",e]}async function mo(e,t){return await e.search(t)}function ju(e,t={}){let r=b();return reactQuery.useQuery({queryKey:po(e),queryFn:async()=>mo(r,e),...t})}function fo(e){return ["predict","positions","byWallet",e]}async function xo(e,t){return await e.getPositionsByWallet(t)}function or(e,t={}){let r=b();return reactQuery.useQuery({queryKey:fo(e),queryFn:async()=>xo(r,e),...t})}function nd(){let e=react.useContext(me);if(!e)throw new Error("useUserPredictContext must be used within a UserPredictProvider");return e}function ar(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 Po(e){return ["predict","outcomeMints",e??{}]}async function Co(e,t){return await e.getOutcomeMints(t)}function ud(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Po(e),queryFn:async()=>Co(r,e),...t})}async function So(e,t){return await e.filterOutcomeMints(t)}function dd(e={}){let t=b();return reactQuery.useMutation({mutationFn:async r=>So(t,r),...e})}function Mo(e){return ["predict","quote",e]}async function wo(e,t){return await e.getQuote(t)}function fd(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Mo(e),queryFn:async()=>wo(r,e),enabled:!!(e.inputMint&&e.outputMint&&e.amount>0),staleTime:1e4,gcTime:3e4,...t})}async function Oo(e,t){return await e.createSwap(t)}function bd(e={}){let t=b();return reactQuery.useMutation({mutationFn:async r=>Oo(t,r),...e})}async function Ro(e,t){return await e.createSwapInstructions(t)}function vd(e={}){let t=b();return reactQuery.useMutation({mutationFn:async r=>Ro(t,r),...e})}function No(e){return ["predict","order",e]}async function Eo(e,t){return await e.getOrder(t)}function cr(e,t={}){let r=b();return reactQuery.useQuery({queryKey:No(e),queryFn:async()=>Eo(r,e),enabled:!!(e.inputMint&&e.outputMint&&e.amount>0),staleTime:1e4,gcTime:3e4,...t})}function Io(e){return ["predict","order","status",e.signature]}async function Qo(e,t){return await e.getOrderStatus(t)}function Sd(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Io(e),queryFn:async()=>Qo(r,e),enabled:!!e.signature,refetchInterval:t.refetchInterval??3e3,...t})}function Uo(e){return ["predict","intent","quote",e]}async function Ao(e,t){return await e.getIntentQuote(t)}function Od(e,t={}){let r=b();return reactQuery.useQuery({queryKey:Uo(e),queryFn:async()=>Ao(r,e),enabled:!!(e.inputMint&&e.outputMint&&e.amount>0),staleTime:1e4,gcTime:3e4,...t})}async function Do(e,t){return await e.submitIntentSwap(t)}function Rd(e={}){let t=b();return reactQuery.useMutation({mutationFn:async r=>Do(t,r),...e})}async function _o(e,t){return await e.initPredictionMarket(t)}function Qd(e={}){let t=b();return reactQuery.useMutation({mutationFn:async r=>_o(t,r),...e})}function Fo(){return ["predict","tokens"]}async function qo(e){return await e.getTokens()}function Ad(e={}){let t=b();return reactQuery.useQuery({queryKey:Fo(),queryFn:async()=>qo(t),staleTime:300*1e3,gcTime:1800*1e3,...e})}function Ko(){return ["predict","tokens","decimals"]}async function Ho(e){return await e.getTokensWithDecimals()}function Dd(e={}){let t=b();return reactQuery.useQuery({queryKey:Ko(),queryFn:async()=>Ho(t),staleTime:300*1e3,gcTime:1800*1e3,...e})}function Vo(){return ["predict","venues"]}async function zo(e){return await e.getVenues()}function qd(e={}){let t=b();return reactQuery.useQuery({queryKey:Vo(),queryFn:async()=>zo(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 Ke(e){return new Ie(e)}function Yd({wsEndpoint:e,autoConnect:t=true,autoReconnect:r=true,enabled:n=true}){let[s,a]=react.useState("disconnected"),[o,l]=react.useState(null),i=react.useRef(null);react.useEffect(()=>{if(!n){i.current&&(i.current.disconnect(),i.current=null),a("disconnected");return}let p=Ke({wsUrl:e,autoConnect:t,autoReconnect:r});i.current=p;let f=p.on("status",h=>{a(h);}),m=p.on("error",h=>{l(h);}),y=p.on("connect",()=>{l(null);});return ()=>{f(),m(),y(),p.disconnect(),i.current=null;}},[e,t,r,n]);let c=react.useCallback(()=>{i.current?.connect();},[]),d=react.useCallback(()=>{i.current?.disconnect();},[]);return {client:i.current,status:s,isConnected:s==="connected",connect:c,disconnect:d,error:o}}function Zd(){let e=react.useContext(we);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 tp({client:e,all:t=false,tickers:r=[],enabled:n=true,onUpdate:s}){let[a,o]=react.useState(new Map),[l,i]=react.useState(false),c=react.useRef(s);return react.useEffect(()=>{c.current=s;},[s]),react.useEffect(()=>{if(!e||!n){i(false);return}if(!t&&r.length===0)return;let d=t?{all:true}:{tickers:r},u=e.subscribePrices(d,p=>{o(f=>{let m=new Map(f);return m.set(p.market_ticker,{yesBid:p.yes_bid,yesAsk:p.yes_ask,noBid:p.no_bid,noAsk:p.no_ask,updatedAt:Date.now()}),m}),c.current?.(p);});return i(true),()=>{u(),i(false);}},[e,t,r.join(","),n]),{prices:a,isSubscribed:l}}function sp({client:e,all:t=false,tickers:r=[],enabled:n=true,maxHistory:s=100,onUpdate:a}){let[o,l]=react.useState([]),[i,c]=react.useState(false),d=react.useRef(a);react.useEffect(()=>{d.current=a;},[a]),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,m=>{let y={tradeId:m.trade_id,marketTicker:m.market_ticker,price:m.price,count:m.count,yesPrice:m.yes_price,noPrice:m.no_price,takerSide:m.taker_side,createdTime:m.created_time};l(h=>{let g=[y,...h];return g.length>s?g.slice(0,s):g}),d.current?.(m);});return c(true),()=>{f(),c(false);}},[e,t,r.join(","),n,s]);let u=react.useCallback(()=>{l([]);},[]);return {trades:o,isSubscribed:i,clearHistory:u}}function ip({client:e,all:t=false,tickers:r=[],enabled:n=true,onUpdate:s}){let[a,o]=react.useState(new Map),[l,i]=react.useState(false),c=react.useRef(s);react.useEffect(()=>{c.current=s;},[s]),react.useEffect(()=>{if(!e||!n){i(false);return}if(!t&&r.length===0)return;let u=t?{all:true}:{tickers:r},p=e.subscribeOrderbook(u,f=>{o(m=>{let y=new Map(m);return y.set(f.market_ticker,{yesBids:f.yes_bids,yesAsks:f.yes_asks,noBids:f.no_bids,noAsks:f.no_asks,updatedAt:Date.now()}),y}),c.current?.(f);});return i(true),()=>{p(),i(false);}},[e,t,r.join(","),n]);let d=react.useCallback(u=>a.get(u),[a]);return {orderbooks:a,isSubscribed:l,getOrderbook:d}}var br=["Politics","Sports","Culture","Crypto","Climate","Economics","Mentions","Companies","Financials","Tech & Science"];function vr(){let{data:e,isLoading:t,isError:r,error:n}=vt();return {data:react.useMemo(()=>{if(!e?.tagsByCategories)return [];let a=o=>{let l=br.indexOf(o);return l===-1?br.length:l};return Object.entries(e.tagsByCategories).map(([o,l])=>({category:o,tags:l})).sort((o,l)=>a(o.category)-a(l.category))},[e]),isLoading:t,isError:r,error:n??null}}function Cr({categories:e,selectedCategory:t,selectedTag:r,activeTags:n,onCategorySelect:s,onTagSelect:a,className:o}){let{t:l}=i18n.useTranslation(),i=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(He,{label:l("predict.categories.trending"),isSelected:t===null,onPress:i}),e.map(c=>jsxRuntime.jsx(He,{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(He,{label:l("predict.categories.allMarkets"),isSelected:r===null,onPress:()=>a(null),variant:"secondary"}),n.map(c=>jsxRuntime.jsx(He,{label:c,isSelected:r===c,onPress:()=>a(c),variant:"secondary"},c))]})})]})}function He({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 Sr({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 Or({onSelect:e,className:t}){let{data:r,isLoading:n}=vr(),[s,a]=react.useState(null),[o,l]=react.useState(null),i=react.useCallback(u=>{if(a(u),l(null),!u)e?.({category:null,tags:null});else {let p=r.find(f=>f.category===u);e?.({category:u,tags:p?.tags??null});}},[r,e]),c=react.useCallback(u=>{if(l(u),u)e?.({category:s,tags:[u]});else {let p=r.find(f=>f.category===s);e?.({category:s,tags:p?.tags??null});}},[r,s,e]);if(n)return jsxRuntime.jsx(Sr,{});let d=r.find(u=>u.category===s)?.tags??[];return jsxRuntime.jsx(Cr,{categories:r,selectedCategory:s,selectedTag:o,activeTags:d,onCategorySelect:i,onTagSelect:c,className:t})}var Pe=48,ye=4,$e={ONE_MINUTE:1,ONE_HOUR:60,ONE_DAY:1440},S={ONE_DAY:"1d",ONE_WEEK:"1w",ONE_MONTH:"1m",ALL:"all"},fe=S.ALL,Ve={[S.ONE_DAY]:$e.ONE_MINUTE,[S.ONE_WEEK]:$e.ONE_HOUR,[S.ONE_MONTH]:$e.ONE_HOUR,[S.ALL]:$e.ONE_DAY},ze={[S.ONE_DAY]:300,[S.ONE_WEEK]:3600,[S.ONE_MONTH]:10800,[S.ALL]:1440*60},Ye={[S.ONE_DAY]:1440*60,[S.ONE_WEEK]:10080*60,[S.ONE_MONTH]:720*60*60,[S.ALL]:null},Pt=1,sm=1,om=1,am=99,Re={ONE_HOUR:"1h",SIX_HOURS:"6h",ONE_DAY:"1d",ONE_WEEK:"1w",MAX:"max"},im=Re.ONE_WEEK,lm={[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:a,isFetching:o,isError:l,error:i}=rr({...t?{category:t}:{},...r&&r.length>0?{tags:r.join(",")}:{},isInitialized:true,status:"active"},{enabled:s}),c=react.useMemo(()=>{if(!s||!a?.series)return;let N=a.series.map(P=>P.ticker).slice(0,25);return N.length>0?N.join(","):void 0},[s,a]),d=react.useMemo(()=>({status:"active",withNestedMarkets:true,sort:"volume24h",order:"desc",limit:48,...n,...c!==void 0?{seriesTickers:c}:{}}),[n,c]),{data:u,isLoading:p,isFetching:f,isFetchingNextPage:m,isError:y,error:h,hasNextPage:g,fetchNextPage:v,refetch:k}=Gt(d),x=react.useMemo(()=>u?.pages.flatMap(N=>N.events)??[],[u]),C=s&&!a&&!l;return {data:x,isLoading:C||p,isFetching:o||C||f&&!m,isFetchingMore:m,isError:l||y,error:i??h,hasMore:g,fetchMore:v,refetch:k}}function la({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 Nr({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(la,{className:"min-h-44 @5xl:min-h-56"},r))})})}function Er({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 Br({event:e,onSelect:t,onSelectOutcome:r}){let{t:n}=i18n.useTranslation(),[s,a]=react.useState(null),o=e.markets||[],l=o.length>2?[...o].sort((P,Q)=>Number(Q.yesAsk??0)-Number(P.yesAsk??0)):o,i=l.filter(P=>P.status==="active"),c=l.length===1,d=c?l[0]:s,u=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,m=P=>{let Q=p(P),U=f(P);return Q!=null?U==null&&Q<=1?"< 1%":h(Q):U!=null?U<=1?"> 99%":h(100-U):"0%"},y=P=>{let Q=p(P),U=f(P);return U!=null?Q==null&&U<=1?"< 1%":h(U):Q!=null?Q<=1?"> 99%":h(100-Q):"0%"},h=P=>P!=null?`${P.toFixed(0)}%`:"--",g=react.useMemo(()=>{let P=l.some(U=>U.status==="active");return l.every(U=>U.status==="closed"||U.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=>{a(P);},k=()=>{a(null);},x=()=>{d&&r&&r(e,d,"yes");},C=()=>{d&&r&&r(e,d,"no");},M=()=>{t&&t(e);},R=i.slice(0,2),N=i.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:M,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(Er,{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&&!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: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:m(d)}),jsxRuntime.jsx(ui.ChevronUpIcon,{className:"w-3 h-3 text-default-500 @5xl:w-4 @5xl:h-4"})]})]}),!d&&!c&&R.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:[R.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:Q=>{Q.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:m(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)),N&&jsxRuntime.jsx("span",{className:"text-xxs text-default-500 @5xl:text-xs",children:n("predict.event.moreMarkets",{count:i.length-2})})]}),d&&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:x,children:[jsxRuntime.jsx("span",{className:"group-hover/yes:hidden",children:n("predict.market.yes")}),jsxRuntime.jsx("span",{className:"hidden group-hover/yes:inline",children:m(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: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:y(d)})]})]})]}),!d||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(),M();},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:[u," ",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 Pa=640,Ca=768,Ur=1024,Sa=1280,Ta=16,Ma=192,wa=228,Oa=244;function Ra(e){return e>=Sa?4:e>=Ur?3:e>=Pa?2:1}function Na(e){return e>=Ur?Oa:e>=Ca?wa:Ma}function Ar({events:e,hasMore:t=false,onFetchMore:r,onSelect:n,onSelectOutcome:s}){let a=react.useRef(null),{width:o=0,height:l=0}=hooks.useResizeObserver({ref:a}),i=Ra(o),c=Na(o),d=Math.ceil(e.length/i)||0,u=t?d+1:d,p=react.useCallback(y=>y<d,[d]),f=react.useCallback(async()=>{r?.();},[r]),m=reactWindowInfiniteLoader.useInfiniteLoader({isRowLoaded:p,loadMoreRows:f,rowCount:u,threshold:3});return jsxRuntime.jsx("div",{ref:a,className:"@container w-full h-full",children:l>0&&jsxRuntime.jsx(reactWindow.List,{style:{height:l},onRowsRendered:m,rowComponent:Ea,rowCount:u,rowHeight:c,rowProps:{events:e,columnCount:i,dataRowCount:d,gap:Ta,onSelect:n,onSelectOutcome:s}})})}function Ea({index:e,style:t,events:r,columnCount:n,dataRowCount:s,gap:a,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 i=e*n,c=r.slice(i,i+n),d=n-c.length,u={display:"flex",gap:a,height:`calc(100% - ${a}px)`};return jsxRuntime.jsx("div",{style:t,children:jsxRuntime.jsxs("div",{style:u,children:[c.map(p=>jsxRuntime.jsx("div",{style:{flex:1,minWidth:0},children:jsxRuntime.jsx(Br,{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 Wr({onSelect:e,onSelectOutcome:t,...r}){let{data:n,hasMore:s,fetchMore:a,isFetching:o}=Rr({limit:48,...r});return o?jsxRuntime.jsx(Nr,{count:48}):jsxRuntime.jsx(Ar,{events:n,hasMore:s,onFetchMore:a,onSelect:e,onSelectOutcome:t})}function Km({onSelect:e,onSelectOutcome:t}){let[r,n]=react.useState({category:null,tags:null}),s=react.useCallback(a=>{n(a);},[]);return jsxRuntime.jsxs("div",{className:"flex h-full w-full flex-col gap-y-3",children:[jsxRuntime.jsx(Or,{onSelect:s}),jsxRuntime.jsx("div",{className:"min-h-0 flex-1",children:jsxRuntime.jsx(Wr,{category:r.category,tags:r.tags,onSelect:e,onSelectOutcome:t})})]})}function wt(e,t,r){let n=e[t];return n?r==="yes"?n.yesMint:n.noMint:null}var Be=utils.SOLANA_TOKENS.stablecoins.USDC.address;function Ka(){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 Fr({market:e,chain:t="solana",initialOutcome:r="yes",initialSide:n="buy"}){let{t:s}=i18n.useTranslation(),a=react.useContext(me),{status:o}=walletConnector.useAuth(),i=walletConnector.useWallets().find(T=>T.chainNamespace===types.ChainNamespace.SOLANA&&T.isConnected),c=o==="authenticated",d=i?.address,[u,p]=react.useState(r),[f,m]=react.useState(n),[y,h]=react.useState(NaN),g=react.useMemo(()=>wt(e.accounts,Be,u),[e.accounts,u]),{inputMint:v,outputMint:k}=react.useMemo(()=>f==="buy"?{inputMint:Be,outputMint:g}:{inputMint:g,outputMint:Be},[f,g]),x=!!v&&!!k&&y>0,C=react.useMemo(()=>Number(u==="yes"?e.yesAsk??.5:e.noAsk??.5),[u,e.yesAsk,e.noAsk]),M=react.useMemo(()=>isNaN(y)||y<=0?0:f==="buy"?C>0?y/C:0:y,[f,y,C]),R=react.useMemo(()=>isNaN(y)||y<=0?0:Math.round(y*1e6),[y]),{data:N,isLoading:P,error:Q,refetch:U}=cr({userPublicKey:d??void 0,inputMint:v??"",outputMint:k??"",amount:R,slippageBps:100},{enabled:x}),ke=a?.usdcBalance??null,pe=a?.isLoading??false,Ht=a?.refetch,oe=a?.positions,_e=react.useMemo(()=>{if(!oe||!g)return null;let T=oe.find(te=>te.mint===g);return T?T.balance:0},[oe,g]),nt=react.useMemo(()=>wt(e.accounts,Be,"yes"),[e.accounts]),st=react.useMemo(()=>wt(e.accounts,Be,"no"),[e.accounts]),zn=react.useMemo(()=>{if(!oe||!nt)return null;let T=oe.find(te=>te.mint===nt);return T?T.balance:0},[oe,nt]),Yn=react.useMemo(()=>{if(!oe||!st)return null;let T=oe.find(te=>te.mint===st);return T?T.balance:0},[oe,st]),{data:Me}=Oe(e.ticker,{refetchInterval:5e3}),Gn=react.useMemo(()=>(u==="yes"?Me?.yesBids:Me?.noBids)?.[0]?.price??null,[Me,u]),jn=react.useMemo(()=>(u==="yes"?Me?.yesAsks:Me?.noAsks)?.[0]?.price??null,[Me,u]),Xn=react.useMemo(()=>N?.priceImpactPct?parseFloat(N.priceImpactPct):null,[N]),Fe=react.useMemo(()=>{if(isNaN(y)||y<=0)return 0;if(N)return parseInt(N.inAmount)/1e6;if(f==="buy")return y;let T=Number(u==="yes"?e.yesBid??0:e.noBid??0);return y*T},[N,f,u,y,e.yesBid,e.noBid]),$t=react.useMemo(()=>isNaN(y)||y<=0?0:f==="buy"?M*1:Fe,[f,M,Fe,y]),Zn=$t-Fe,Jn=react.useCallback(T=>{m(T),h(NaN);},[]),es=react.useCallback(T=>{if(isNaN(T)){h(NaN);return}let te=Math.max(0,T),it=f==="buy"?Math.round(te*100)/100:Math.round(te);h(it);},[f]);react.useEffect(()=>{x&&U();},[y,u,f,x,U]);let ot=react.useMemo(()=>{let T=[];return (isNaN(y)||y<Pt)&&T.push(`Minimum quantity is ${Pt}`),e.status!=="active"&&T.push("Market is not active"),f==="buy"&&ke!=null&&!isNaN(y)&&y>0&&y>ke&&T.push("Insufficient USDC balance"),f==="sell"&&_e!=null&&!isNaN(y)&&y>0&&y>_e&&T.push("Insufficient shares"),{isValid:T.length===0,errors:T}},[y,e.status,f,ke,_e]),[ts,at]=react.useState(null),[rs,Vt]=react.useState(false),ns=react.useCallback(async()=>{if(!(!ot.isValid||!c||!d||!i||pe)){at(null),Vt(true);try{let T=N;if(T?.transaction||(T=(await U()).data),!T?.transaction)return;let te=Uint8Array.from(atob(T.transaction),zt=>zt.charCodeAt(0)),it=await i.sendTransaction(te);at(it),ui.toast.success(s("predict.trade.submitSuccess")),Ka(),h(NaN),Ht?.();}catch{ui.toast.error(s("predict.trade.submitError"));}finally{Vt(false);}}},[ot.isValid,c,d,i,N,pe,U,Ht,s]),ss=react.useCallback(()=>{p(r),m(n),h(NaN),at(null);},[r,n]);return {outcome:u,side:f,quantity:y,shares:M,estimatedCost:Fe,potentialPayout:$t,potentialProfit:Zn,isAuthenticated:c,bestBid:Gn,bestAsk:jn,order:N??null,priceImpact:Xn,usdcBalance:ke,outcomeTokenBalance:_e,yesTokenBalance:zn,noTokenBalance:Yn,isBalanceLoading:pe,isQuoteLoading:P,isSubmitting:rs,quoteError:Q??null,txHash:ts,validation:ot,setOutcome:p,setSide:Jn,setQuantity:es,submit:ns,reset:ss}}var Ga=`https://s1.chainstream.io/chains/sol/tokens/${utils.SOLANA_TOKENS.stablecoins.USDC.address}/image.png`;function $r({event:e,market:t,outcome:r,side:n,quantity:s,potentialProfit:a,estimatedCost:o,usdcBalance:l,yesTokenBalance:i,noTokenBalance:c,isBalanceLoading:d,isSubmitting:u,isValid:p,onOutcomeChange:f,onSideChange:m,onQuantityChange:y,onSubmit:h}){let{t:g}=i18n.useTranslation(),v=react.useMemo(()=>{if(u)return g("predict.trade.submitting");let x=g(n==="buy"?"predict.trade.buy":"predict.trade.sell"),C=g(r==="yes"?"predict.trade.yes":"predict.trade.no");return `${x} ${C}`},[u,n,r,g]),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:[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:x=>m(x),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(x=>{let C=x==="yes"?i:c;return jsxRuntime.jsxs("div",{className:"flex flex-1 flex-col gap-y-1",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>f(x),className:`w-full rounded-lg border py-2 text-sm font-medium transition-colors cursor-pointer ${r===x?x==="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(x==="yes"?"predict.trade.yes":"predict.trade.no")}),(()=>{let M=n==="buy"?x==="yes"?t.yesAsk:t.noAsk:x==="yes"?t.yesBid:t.noBid;return M!=null?jsxRuntime.jsxs("span",{className:"ml-1 opacity-70",children:[Math.round(Number(M)*100),"\xA2"]}):null})()]}),n==="sell"&&r===x&&jsxRuntime.jsx("span",{className:"text-center text-xs text-foreground",children:d?"\u2013":`${C??0} shares`})]},x)})}),n==="buy"&&jsxRuntime.jsxs("div",{className:"flex items-center justify-end gap-x-1 text-xs text-default-500",children:[jsxRuntime.jsx("img",{src:Ga,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: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:x=>{y(x);},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(x=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>y(Math.round(((isNaN(s)?0:s)+x)*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:["+",x,"$"]},x)),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(x=>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:[x,"%"]},x)),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"?a:o).toFixed(2)]})]}),jsxRuntime.jsx(ui.Button,{color:k,fullWidth:true,radius:"lg",size:"lg",isDisabled:!p||u,isLoading:u,onPress:h,children:v})]})}function Ot({event:e,market:t,initialSide:r,initialOutcome:n,chain:s}){let{outcome:a,side:o,quantity:l,estimatedCost:i,potentialPayout:c,potentialProfit:d,usdcBalance:u,yesTokenBalance:p,noTokenBalance:f,isBalanceLoading:m,isSubmitting:y,validation:h,setOutcome:g,setSide:v,setQuantity:k,submit:x}=Fr({market:t,initialSide:r,initialOutcome:n,chain:s}),C=walletConnector.useAuthCallback(x);return jsxRuntime.jsx($r,{event:e,market:t,outcome:a,side:o,quantity:l,estimatedCost:i,potentialPayout:c,potentialProfit:d,usdcBalance:u,yesTokenBalance:p,noTokenBalance:f,isBalanceLoading:m,isSubmitting:y,isValid:h.isValid,validationErrors:h.errors,onOutcomeChange:g,onSideChange:v,onQuantityChange:k,onSubmit:C})}function Za(){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 Le({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(Za,{},r))})]})}function Vr(){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 zr=e=>{let{candlestickMarketTickers:t,chartRange:r=fe}=e,n=Ve[r],s=Ye[r],a=react.useMemo(()=>Math.floor(Date.now()/1e3),[r]),o=b(),{data:l,isLoading:i,error:c}=qe({id:e.eventId,withNestedMarkets:true}),d=react.useMemo(()=>{if(s!=null)return a-s;let k=l?.markets;return k?.length?Math.min(...k.map(x=>x.openTime)):a},[a,s,l?.markets]),{data:u,isLoading:p,error:f}=nr(l?.seriesTicker??"",{enabled:!!l?.seriesTicker}),m=react.useMemo(()=>l?.markets?(t&&t.length>0?t.slice(0,4).map(x=>l.markets.find(C=>C.ticker===x)).filter(x=>x!==void 0):[...l.markets].sort((x,C)=>Number(C.yesAsk??0)-Number(x.yesAsk??0)).slice(0,4)).map(x=>x.ticker):[],[t,l?.markets]),y=reactQuery.useQueries({queries:m.map(k=>({queryKey:xt({ticker:k,startTs:d,endTs:a,periodInterval:n}),queryFn:()=>gt(o,{ticker:k,startTs:d,endTs:a,periodInterval:n}),enabled:m.length>0}))}),h=y.some(k=>k.isLoading),g=react.useMemo(()=>{let k=new Map;return m.forEach((x,C)=>{let M=y[C]?.error;M&&k.set(x,M);}),k},[m,y]),v=react.useMemo(()=>{let k=new Map;return m.forEach((x,C)=>{let M=y[C]?.data;M&&k.set(x,M);}),k},[m,y]);return {event:l,isEventLoading:i,eventError:c,series:u,isSeriesLoading:p,seriesError:f,periodInterval:n,candlesticks:v,isCandlesticksLoading:h,candlestickErrors:g}};var ii=utils.SOLANA_TOKENS.stablecoins.USDC.address;function Yr(e){let{status:t}=walletConnector.useAuth(),n=walletConnector.useWallets().find(c=>c.chainNamespace===types.ChainNamespace.SOLANA&&c.isConnected),s=t==="authenticated",a=n?.address,{data:o,isLoading:l}=react$1.useWalletPortfoliosQuery({chain:types.Chain.SOLANA,address:a??""},{enabled:s&&!!a,refetchInterval:1e4});return {holdings:react.useMemo(()=>{let c=new Map;if(!o?.portfolios||e.length===0)return c;let d=new Map;for(let u of o.portfolios)d.set(u.address,parseFloat(u.amount));for(let u of e){let p=u.accounts[ii];if(!p)continue;let f=d.get(p.yesMint)??0,m=d.get(p.noMint)??0;(f>0||m>0)&&c.set(u.ticker,{yesShares:f,noShares:m});}return c},[o,e]),isLoading:l}}function gi(e){let{cx:t,cy:r,index:n,dataLength:s,stroke:a}=e;return n!==s-1||t==null||r==null?null:jsxRuntime.jsxs("g",{children:[jsxRuntime.jsxs("circle",{cx:t,cy:r,r:6,fill:a,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:a})]})}var Xe=[{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 Gr(e,t){let r=new Date(e*1e3);switch(t){case S.ONE_DAY:return r.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:false});case S.ONE_WEEK:case S.ONE_MONTH:return r.toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:false});case S.ALL:default:return r.toLocaleDateString("en-US",{month:"short",day:"numeric"})}}function hi(e,t,r){let n=ze[r],s=new Map;e.forEach((i,c)=>{let d=new Map;(i.candlesticks??[]).forEach(p=>{let f=p.end_period_ts-p.end_period_ts%n;d.set(f,p.yes_ask.close);}),s.set(c,d);});let a=new Set;for(let i of s.values())for(let c of i.keys())a.add(c);let o=Array.from(a).sort((i,c)=>i-c),l=new Map;return o.map(i=>{let d={date:new Date(i*1e3).toLocaleDateString("en-US",{month:"short",day:"numeric"}),timestamp:i};return t.forEach(u=>{let p=s.get(u)?.get(i);if(p!==void 0)d[u]=Math.round(p*100)/100,l.set(u,d[u]);else {let f=l.get(u);f!==void 0&&(d[u]=f);}}),d})}function jr({candlesticks:e,markets:t=[],isLoading:r,chartRange:n=S.ALL,onDataChange:s}){let[a,o]=react.useState(null),l=react.useRef(s);react.useEffect(()=>{l.current=s;});let i=react.useMemo(()=>e?Array.from(e.keys()).slice(0,4):[],[e]),c=react.useMemo(()=>!e||e.size===0?[]:hi(e,i,n),[e,i,n]),d=react.useMemo(()=>{if(c.length===0||i.length===0)return [0,100];let m=1/0,y=-1/0;if(c.forEach(x=>{i.forEach(C=>{let M=x[C];M!==void 0&&(m=Math.min(m,M),y=Math.max(y,M));});}),m===1/0||y===-1/0)return [0,100];let h=y-m,g=Math.max(h*.2,5),v=Math.max(0,Math.floor(m-g)),k=Math.min(100,Math.ceil(y+g));return [v,k]},[c,i]),u=react.useCallback(m=>{if(c.length===0)return null;let y=m!==null?c[m]:c[c.length-1];return y?{timestamp:y.timestamp,date:y.date,markets:i.map((h,g)=>{let v=t.find(k=>k.ticker===h);return {id:h,label:v?.yesSubTitle||`Market ${g+1}`,value:y[h]??0,color:Xe[g%Xe.length].stroke}})}:null},[c,i,t]);react.useEffect(()=>{l.current&&c.length>0&&l.current(u(null));},[c,u]),react.useEffect(()=>{l.current&&l.current(u(a));},[a,u]);let p=react.useCallback(m=>{typeof m?.activeTooltipIndex=="number"&&o(m.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:m=>{let{x:y,y:h,payload:g,index:v}=m,k=c.length,C=Math.max(1,Math.ceil(k/6)),M=v===0,R=v===k-1,N=v%C===0;return !M&&!R&&!N?null:jsxRuntime.jsx("text",{x:y,y:h+10,textAnchor:"middle",fill:"hsl(var(--heroui-default-500))",fontSize:10,children:Gr(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:m=>`${m}%`,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:m=>Gr(m,n),formatter:(m,y)=>{let g=t.find(v=>v.ticker===y)?.yesSubTitle||y;return [`${m.toFixed(2)}%`,g]}}),i.map((m,y)=>jsxRuntime.jsx(recharts.Line,{type:"monotone",dataKey:m,stroke:Xe[y%Xe.length].stroke,strokeWidth:2,isAnimationActive:false,dot:h=>jsxRuntime.jsx(gi,{...h,dataLength:c.length},`dot-${m}-${h.index}`),activeDot:false},m))]})})})}function Xr(){return {timestamp:Date.now()/1e3,date:new Date().toLocaleDateString("en-US",{month:"short",day:"numeric"}),markets:[]}}function Jr({marketTicker:e,openTime:t,chartRange:r=fe}){let n=Ve[r],s=Ye[r],a=react.useMemo(()=>Math.floor(Date.now()/1e3),[r]),o=react.useMemo(()=>s!=null?a-s:t??a,[a,s,t]),{data:l,isLoading:i,isFetching:c,error:d}=ht({ticker:e,startTs:o,endTs:a,periodInterval:n},{enabled:!!e});return {candlesticks:l,isLoading:i,isFetching:c,error:d,periodInterval:n}}var Mi="hsl(var(--heroui-primary))",wi=[{value:S.ONE_DAY,label:"1D"},{value:S.ONE_WEEK,label:"1W"},{value:S.ONE_MONTH,label:"1M"},{value:S.ALL,label:"ALL"}];function Oi(e){let{cx:t,cy:r,index:n,dataLength:s,stroke:a}=e;return n!==s-1||t==null||r==null?null:jsxRuntime.jsxs("g",{children:[jsxRuntime.jsxs("circle",{cx:t,cy:r,r:6,fill:a,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:a})]})}function tn(e,t){let r=new Date(e*1e3);switch(t){case S.ONE_DAY:return r.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:false});case S.ONE_WEEK:case S.ONE_MONTH:return r.toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:false});case S.ALL:default:return r.toLocaleDateString("en-US",{month:"short",day:"numeric"})}}function Ri(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toFixed(0)}function Ni(e,t){let r=ze[t],n=e.candlesticks??[],s=new Map;for(let o of n){let l=o.end_period_ts-o.end_period_ts%r,i=s.get(l);s.set(l,{close:o.yes_ask.close,volume:(i?.volume??0)+(o.volume??0)});}return Array.from(s.entries()).sort((o,l)=>o[0]-l[0]).map(([o,{close:l,volume:i}])=>({timestamp:o,date:new Date(o*1e3).toLocaleDateString("en-US",{month:"short",day:"numeric"}),value:Math.round(l*100)/100,volume:i}))}function rn({candlesticks:e,isLoading:t,chartRange:r,onRangeChange:n}){let s=react.useMemo(()=>e?Ni(e,r):[],[e,r]),a=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 i=l-o,c=Math.max(i*.2,5),d=Math.max(0,Math.floor(o-c)),u=Math.min(100,Math.ceil(l+c));return [d,u]},[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(Qt,{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(Qt,{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:i,payload:c,index:d}=o,u=s.length,f=Math.max(1,Math.ceil(u/6)),m=d===0,y=d===u-1,h=d%f===0;return !m&&!y&&!h?null:jsxRuntime.jsx("text",{x:l,y:i+10,textAnchor:"middle",fill:"hsl(var(--heroui-default-500))",fontSize:10,children:tn(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:a,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 i=l[0].payload,c=Math.round(i.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 ",Ri(i.volume)," \xB7"," ",tn(i.timestamp,r)]})]})}}),jsxRuntime.jsx(recharts.Line,{type:"monotone",dataKey:"value",stroke:Mi,strokeWidth:2,isAnimationActive:false,dot:o=>jsxRuntime.jsx(Oi,{...o,dataLength:s.length},`dot-${o.index}`),activeDot:false})]})})}),jsxRuntime.jsx(Qt,{chartRange:r,onRangeChange:n})]})}function Qt({chartRange:e,onRangeChange:t}){return jsxRuntime.jsx("div",{className:"flex items-center justify-end gap-x-1",children:wi.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 nn({marketTicker:e}){let{data:t,isLoading:r,error:n}=Oe(e,{enabled:!!e});return {orderbook:react.useMemo(()=>{if(!t)return null;let{yesBids:a,yesAsks:o,noBids:l,noAsks:i}=t;return {yesBids:a,yesAsks:o,noBids:l,noAsks:i,bestYesBid:a.length>0?a[0].price:null,bestYesAsk:o.length>0?o[0].price:null,bestNoBid:l.length>0?l[0].price:null,bestNoAsk:i.length>0?i[0].price:null,sequence:t.sequence??null}},[t]),isOrderbookLoading:r,orderbookError:n}}function sn(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 on(e,t){for(let r of e)r.depth=t>0?r.cumulative/t:0;}function un(e){return `${Math.round(e*100)}\xA2`}function Qi(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function Bi(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 an({row:e,side:t,showType:r=false,onClick:n}){let{t:s}=i18n.useTranslation(),a=t==="ask",o=a?"bg-bullish/10":"bg-bearish/10",l=a?"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(a?"predict.trade.bestAsk":"predict.trade.bestBid"):""}),jsxRuntime.jsx("span",{className:"relative z-10 font-mono text-foreground text-right",children:un(e.price)}),jsxRuntime.jsx("span",{className:"relative z-10 font-mono text-foreground text-right",children:Qi(e.quantity)}),jsxRuntime.jsx("span",{className:"relative z-10 font-mono text-foreground text-right",children:Bi(e.total)})]})}function ln({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 Li(){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:Bt}).map((e,t)=>jsxRuntime.jsx(ln,{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:Bt}).map((e,t)=>jsxRuntime.jsx(ln,{index:t+3},`bid-${t}`))]})}var Bt=8;function Lt({bids:e,asks:t,isLoading:r=false,maxLevels:n=Bt,onPriceClick:s}){let{t:a}=i18n.useTranslation(),{bidRows:o,askRows:l,spread:i,spreadPercent:c}=react.useMemo(()=>{let u=sn(e,n),p=sn(t,n),f=Math.max(u[u.length-1]?.cumulative??0,p[p.length-1]?.cumulative??0);on(u,f),on(p,f);let m=u[0]?.price??null,y=p[0]?.price??null,h=null,g=null;if(m!=null&&y!=null){h=y-m;let v=(m+y)/2;v>0&&(g=Math.round(h/v*1e4)/100);}return {bidRows:u,askRows:p,spread:h,spreadPercent:g}},[e,t,n]);return r?jsxRuntime.jsx(Li,{}):o.length===0&&l.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-6 text-sm text-neutral",children:a("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:a("predict.orderBook.price")}),jsxRuntime.jsx("span",{className:"text-right",children:a("predict.orderBook.contracts")}),jsxRuntime.jsx("span",{className:"text-right",children:a("predict.orderBook.total")})]}),jsxRuntime.jsx("div",{className:"flex flex-col-reverse",children:l.map((u,p)=>jsxRuntime.jsx(an,{row:u,side:"ask",showType:p===0,onClick:s},u.price))}),i!=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:[a("predict.orderBook.spread"),": ",un(i)]}),c!=null&&jsxRuntime.jsxs("span",{className:"text-default-400",children:["(",c,"%)"]})]}),jsxRuntime.jsx("div",{className:"flex flex-col",children:o.map((u,p)=>jsxRuntime.jsx(an,{row:u,side:"bid",showType:p===0,onClick:s},u.price))})]})}function Di(e){return e>=1e6?`${(e/1e6).toFixed(2)}M`:e>=1e3?`${(e/1e3).toFixed(2)}K`:e.toLocaleString(void 0,{maximumFractionDigits:2})}function Wi(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 dn({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",a=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",i=n.currentPrice!=null?`${Math.round(n.currentPrice*100)}\xA2`:"\u2014",c=n.pnl!=null&&n.pnlPercent!=null,d=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 ${a}`,children:o}),jsxRuntime.jsx("span",{className:"text-right font-mono text-foreground",children:Di(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:i}),jsxRuntime.jsx("span",{className:`text-right font-mono ${d}`,children:c?jsxRuntime.jsxs("span",{className:"flex flex-col items-end",children:[jsxRuntime.jsx("span",{children:Wi(n.pnl)}),jsxRuntime.jsxs("span",{className:"text-[10px] opacity-70",children:[n.pnlPercent>=0?"+":"",n.pnlPercent.toFixed(1),"%"]})]}):"\u2014"})]},n.mint)})]})}function Fi(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 qi(e){return e==null?"\u2014":`${Math.round(e*100)}\xA2`}function Ki(e){let t=new Date(e*1e3),r=t.toLocaleString("default",{month:"short"}),n=t.getDate(),s=t.getHours().toString().padStart(2,"0"),a=t.getMinutes().toString().padStart(2,"0");return `${r} ${n} ${s}:${a}`}function Hi({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 pn({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(Hi,{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",a=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 ${a}`,children:o}),jsxRuntime.jsx("span",{className:"text-right font-mono text-foreground",children:qi(n.usdPricePerContract)}),jsxRuntime.jsx("span",{className:"text-right font-mono text-foreground",children:Fi(n.outputAmount)}),jsxRuntime.jsx("span",{className:"text-right text-default-500",children:Ki(n.createdAt)})]},n.id)})]})}function xn({market:e,onTradeAction:t}){let{t:r}=i18n.useTranslation(),[n,s]=react.useState("trade-yes"),[a,o]=react.useState(fe),{orderbook:l,isOrderbookLoading:i}=nn({marketTicker:e.ticker}),{candlesticks:c,isFetching:d}=Jr({marketTicker:e.ticker,openTime:e.openTime,chartRange:a}),{positions:u,isLoading:p}=ar(e),{status:f}=walletConnector.useAuth(),h=walletConnector.useWallets().find(R=>R.chainNamespace===types.ChainNamespace.SOLANA&&R.isConnected)?.address,{data:g,isLoading:v}=Jt({walletAddress:h??""},{enabled:(n==="trade-history"||n==="positions")&&f==="authenticated"&&!!h}),k=(g?.trades??[]).filter(R=>R.marketTicker===e.ticker),x=react.useMemo(()=>u.map(R=>{let N=k.filter(pe=>pe.outputMint===R.mint&&pe.usdPricePerContract!=null&&pe.contracts!=null&&pe.contracts>0),P=Xi(N),Q=R.position==="YES"?fn(R.market?.yesAsk):fn(R.market?.noAsk),U=null,ke=null;return P!=null&&Q!=null&&(U=(Q-P)*R.balance,ke=P>0?(Q-P)/P*100:null),{...R,avgCost:P,currentPrice:Q,pnl:U,pnlPercent:ke}}),[u,k]),C=react.useCallback((R,N)=>{t?.(e,"yes",N==="ask"?"buy":"sell");},[e,t]),M=react.useCallback((R,N)=>{t?.(e,"no",N==="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:R=>s(R),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(Lt,{bids:l?.yesBids??[],asks:l?.yesAsks??[],isLoading:i,onPriceClick:C}),n==="trade-no"&&jsxRuntime.jsx(Lt,{bids:l?.noBids??[],asks:l?.noAsks??[],isLoading:i,onPriceClick:M}),n==="graph"&&jsxRuntime.jsx(rn,{candlesticks:c,isLoading:d,chartRange:a,onRangeChange:o}),n==="positions"&&jsxRuntime.jsx(dn,{positions:x,isLoading:p}),n==="trade-history"&&jsxRuntime.jsx(pn,{trades:k,isLoading:v})]})]})}function Xi(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 fn(e){if(e==null)return null;let t=Number(e);return Number.isFinite(t)?t:null}var At=4;function Ji(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 Cn({markets:e,renderMarketDetail:t,onTradeAction:r,marketHoldings:n}){let{t:s}=i18n.useTranslation(),[a,o]=react.useState(false),[l,i]=react.useState(null);if(e.length===0)return null;let c=e.length>At,d=a?e:e.slice(0,At),u=p=>{i(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:m}=Ji(p),y=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:()=>u(p.ticker),role:"button",tabIndex:0,onKeyDown:h=>{(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),u(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 h=n?.get(p.ticker);if(!h)return null;let{yesShares:g,noShares:v}=h;return g<=0&&v<=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)})}),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 h=f!=null,g=m!=null;return h&&!g&&f<=1?jsxRuntime.jsx("span",{className:"text-lg font-bold shrink-0 text-center text-default-400 lg:text-xl",children:"< 1%"}):g&&!h&&m<=1?jsxRuntime.jsx("span",{className:"text-lg font-bold shrink-0 text-center text-default-400 lg:text-xl",children:"> 99%"}):!h&&!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:m!=null?s("predict.market.action.no",{price:m}):s("predict.market.no")})]}),y?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"})]}),y&&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:a?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-At})}),jsxRuntime.jsx(ui.ChevronDownIcon,{className:"h-4 w-4"})]})})]})}var sl=new Set(["closed","determined","finalized"]);function Je(e){let t=new Date(e*1e3),r=t.toLocaleString("default",{month:"short"}),n=t.getDate(),s=t.getFullYear(),a=t.getHours().toString().padStart(2,"0"),o=t.getMinutes().toString().padStart(2,"0");return `${r} ${n}, ${s} ${a}:${o}`}function ol({market:e}){let t=sl.has(e.status),r=react.useMemo(()=>{let s={label:"Market Open",value:Je(e.openTime),isActive:true},a={label:"Market Closes",value:t?Je(e.closeTime):"After the outcome occurs",isActive:t},o={label:"Projected Payout",value:"30 minutes after closing",isActive:e.status==="finalized"};return [s,a,o]},[e.openTime,e.closeTime,e.status,t]),n=react.useMemo(()=>t?null:e.canCloseEarly&&e.earlyCloseCondition?`${e.earlyCloseCondition} Otherwise, it closes by ${Je(e.expirationTime)}.`:`This market closes by ${Je(e.expirationTime)}.`,[t,e.canCloseEarly,e.earlyCloseCondition,e.expirationTime]);return jsxRuntime.jsxs("div",{className:"flex flex-col",children:[r.map((s,a)=>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"}`}),a<r.length-1&&jsxRuntime.jsx("div",{className:"w-px flex-1 bg-default-200"})]}),jsxRuntime.jsxs("div",{className:`flex flex-col ${a<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 Tn({markets:e,event:t,series:r}){let{t:n}=i18n.useTranslation(),[s,a]=react.useState(null),o=e.filter(i=>i.rulesPrimary);if(o.length===0)return null;let l=o.find(i=>i.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:i=>{if(i==="all")return;let c=Array.from(i);c.length>0&&a(c[0]);},children:o.map(i=>jsxRuntime.jsx(ui.SelectItem,{textValue:i.yesSubTitle,children:jsxRuntime.jsx("span",{className:"text-xs truncate",children:i.yesSubTitle})},i.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(ol,{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 yl=[{value:S.ONE_DAY,label:"1D"},{value:S.ONE_WEEK,label:"1W"},{value:S.ONE_MONTH,label:"1M"},{value:S.ALL,label:"ALL"}];function wn({event:e,series:t,candlesticks:r,chartRange:n=S.ONE_DAY,periodInterval:s,isCandlesticksLoading:a,onRangeChange:o,selectedMarketTickers:l,onMarketSelectionChange:i,onTradeAction:c}){let{t:d}=i18n.useTranslation(),[u,p]=react.useState(Xr()),[f,m]=react.useState(false),y=react.useRef(null);react.useEffect(()=>{let x=y.current;if(!x)return;let C=false,M=0,R=()=>{let{bottom:P}=x.getBoundingClientRect(),Q=C?P<0:P<-20;Q!==C&&(C=Q,m(Q));},N=()=>{cancelAnimationFrame(M),M=requestAnimationFrame(R);};return window.addEventListener("scroll",N,{passive:true,capture:true}),R(),()=>{cancelAnimationFrame(M),window.removeEventListener("scroll",N,{capture:true});}},[]);let h=react.useMemo(()=>[...e.markets||[]].sort((x,C)=>Number(C.yesAsk??0)-Number(x.yesAsk??0)),[e.markets]),{holdings:g}=Yr(h),v=react.useMemo(()=>utils.formatAmountUSDCompact((e.volume??0)/100),[e.volume]),k=react.useMemo(()=>{if(!e.strikeDate)return null;let x=new Date(e.strikeDate*1e3),C=x.toLocaleString("default",{month:"short"}),M=x.getDate(),R=x.getFullYear();return `${C} ${M}, ${R}`},[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:y,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:[u&&u.markets.length>0&&jsxRuntime.jsx("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2 text-xs lg:text-sm",children:u.markets.map(x=>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:x.color}}),jsxRuntime.jsx("span",{className:"text-default-600",children:x.label})]},x.id))}),jsxRuntime.jsx(jr,{candlesticks:r,chartRange:n,markets:h,isLoading:a,onDataChange:x=>p(x)}),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," ",d("predict.event.volume")]}),k&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{className:"text-default-300",children:"\xB7"}),jsxRuntime.jsx("span",{children:d("predict.event.endDate",{date:k})})]})]}),jsxRuntime.jsx("div",{className:"flex items-center gap-x-1",children:yl.map(x=>jsxRuntime.jsx("button",{type:"button",onClick:()=>o?.(x.value),className:`px-2 lg:px-3 py-1 text-xs rounded-md transition-colors cursor-pointer ${n===x.value?"bg-primary text-primary-foreground":"bg-default-100 text-default-600 hover:bg-default-200"}`,children:x.label},x.value))}),h.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:x=>{if(x==="all")return;let C=Array.from(x);C.length<=4&&i?.(C);},children:jsxRuntime.jsx(ui.SelectSection,{title:`Pick up to ${4} markets`,classNames:{heading:"text-xs text-default-400 px-2 py-1"},children:h.map(x=>jsxRuntime.jsx(ui.SelectItem,{textValue:x.yesSubTitle,children:jsxRuntime.jsx("span",{className:"text-xs truncate",children:x.yesSubTitle})},x.ticker))})})]})]})}),jsxRuntime.jsx(Cn,{markets:h,onTradeAction:c,marketHoldings:g,renderMarketDetail:x=>jsxRuntime.jsx(xn,{market:x,onTradeAction:c})}),jsxRuntime.jsx(Tn,{markets:h,event:e,series:t})]})}function _t({eventId:e,initialMarketTickers:t,initialChartRange:r=fe,onTradeAction:n}){let[s,a]=react.useState(r),[o,l]=react.useState(t),{event:i,isEventLoading:c,eventError:d,series:u,isSeriesLoading:p,periodInterval:f,candlesticks:m,isCandlesticksLoading:y,candlestickErrors:h}=zr({eventId:e,candlestickMarketTickers:o,chartRange:s}),g=react.useRef(!!t);react.useEffect(()=>{if(i?.markets&&!g.current){g.current=true;let x=[...i.markets].sort((C,M)=>Number(M.yesAsk??0)-Number(C.yesAsk??0)).slice(0,4).map(C=>C.ticker);l(x);}},[i?.markets]);let v=react.useMemo(()=>x=>{a(x);},[]),k=react.useMemo(()=>x=>{l(x);},[]);return c||p?jsxRuntime.jsx(Le,{}):d||!i?jsxRuntime.jsx("div",{className:"flex w-full items-center justify-center py-20 text-danger",children:d?.message||"Event not found"}):jsxRuntime.jsx(wn,{event:i,series:u,candlesticks:m,chartRange:s,periodInterval:f,isCandlesticksLoading:y,candlestickErrors:h,onRangeChange:v,selectedMarketTickers:o,onMarketSelectionChange:k,onTradeAction:n})}function px({eventId:e,chain:t,...r}){let{t:n}=i18n.useTranslation(),{isMobile:s}=ui.useScreen(),{isOpen:a,onOpen:o,onClose:l}=ui.useDisclosure(),{data:i,isLoading:c}=qe({id:e,withNestedMarkets:true}),d=react.useMemo(()=>[...i?.markets||[]].sort((h,g)=>Number(g.yesAsk??0)-Number(h.yesAsk??0)),[i?.markets]),[u,p]=react.useState(null),f=react.useCallback((h,g,v)=>{p(k=>({market:h,outcome:g,side:v,version:(k?.version??0)+1})),s&&o();},[s,o]),m=u?.market??d[0];if(c)return s?jsxRuntime.jsx(Le,{}):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(Le,{})}),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(Vr,{})})})]});let y=u?`${u.market.ticker}-${u.version}`:m?.ticker??"default";return s?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"w-full pb-20",children:jsxRuntime.jsx(_t,{eventId:e,onTradeAction:f,...r})}),m&&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:a,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:m&&jsxRuntime.jsx(Ot,{event:i,market:m,initialSide:u?.side,initialOutcome:u?.outcome,chain:t},y)})})})]}):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(_t,{eventId:e,onTradeAction:f,...r})}),m&&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(Ot,{event:i,market:m,initialSide:u?.side,initialOutcome:u?.outcome,chain:t},y)})})]})}function Nn(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})),a=s[s.length-1]?.cumulative??1;for(let o of s)o.depth=o.cumulative/a;return s}function En({marketTicker:e,maxLevels:t=10,refetchInterval:r=5e3,outcome:n="yes"}){let{data:s,isLoading:a,isFetching:o}=Oe(e,{refetchInterval:r||void 0}),l=react.useMemo(()=>n==="yes"?s?.yesBids:s?.noBids,[s,n]),i=react.useMemo(()=>n==="yes"?s?.yesAsks:s?.noAsks,[s,n]),c=react.useMemo(()=>Nn(l,t),[l,t]),d=react.useMemo(()=>Nn(i,t),[i,t]),u=react.useMemo(()=>c.length===0||d.length===0?null:d[0].price-c[0].price,[c,d]),p=react.useMemo(()=>c.length===0||d.length===0?null:(c[0].price+d[0].price)/2,[c,d]),f=react.useMemo(()=>u===null||p===null||p===0?null:Math.round(u/p*1e4)/100,[u,p]);return {bids:c,asks:d,spread:u,spreadPercent:f,midpoint:p,isLoading:a,isFetching:o}}function In({row:e,side:t,onClick:r}){let n=t==="bid",s=n?"bg-primary/10":"bg-danger/10",a=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 ${a}`,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 Qn(){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 Bn({bids:e,asks:t,spread:r,spreadPercent:n,isLoading:s,onPriceClick:a}){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(Qn,{}),jsxRuntime.jsx(Qn,{})]});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(i=>jsxRuntime.jsx(In,{row:i,side:"ask",onClick:a},i.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(i=>jsxRuntime.jsx(In,{row:i,side:"bid",onClick:a},i.price))})]})]})}function Bx({marketTicker:e,maxLevels:t,refetchInterval:r,onPriceClick:n,outcome:s}){let{bids:a,asks:o,spread:l,spreadPercent:i,isLoading:c}=En({marketTicker:e,maxLevels:t,refetchInterval:r,outcome:s});return jsxRuntime.jsx(Bn,{bids:a,asks:o,spread:l,spreadPercent:i,isLoading:c,onPriceClick:n})}function Un(e={}){let[t,r]=react.useState(null),[n]=react.useState(null),s=react.useCallback(a=>{r(null);},[]);return {orders:[],isLoading:false,isFetching:false,cancellingOrderId:t,cancelOrder:s,cancelError:n}}function _l(e){return new Date(e).toLocaleString("default",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function An({orders:e,isLoading:t,cancellingOrderId:r,onCancel:n}){let{t:s}=i18n.useTranslation(),a=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:_l(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:a.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 jx({refetchInterval:e}={}){let{orders:t,isLoading:r,cancellingOrderId:n,cancelOrder:s}=Un({});return jsxRuntime.jsx(An,{orders:t,isLoading:r,cancellingOrderId:n,onCancel:s})}function Wn({ticker:e,pageSize:t=48}={}){let[r,n]=react.useState(1),[s,a]=react.useState([void 0]),o=s[r-1],l=react.useMemo(()=>({...e?{ticker:e}:{},limit:t,...o?{cursor:o}:{}}),[e,t,o]),{data:i,isLoading:c,isFetching:d}=Zt(l),u=i,p=u?.trades??[],f=!!u?.cursor,m=r>1,y=react.useCallback(v=>{v>=1&&v<=s.length&&n(v);},[s.length]),h=react.useCallback(()=>{f&&u?.cursor&&(a(v=>{let k=[...v];return k.length===r&&k.push(u.cursor),k}),n(v=>v+1));},[f,u?.cursor,r]),g=react.useCallback(()=>{m&&n(v=>v-1);},[m]);return {trades:p,isLoading:c,isFetching:d,page:r,pageSize:t,hasNextPage:f,hasPrevPage:m,goToPage:y,nextPage:h,prevPage:g}}function Xl(e){return new Date(e*1e3).toLocaleString("default",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function Fn({trades:e,isLoading:t,isFetching:r,page:n,hasNextPage:s,hasPrevPage:a,onNextPage:o,onPrevPage:l}){let{t:i}=i18n.useTranslation(),c=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:Xl(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:i("predict.tradeHistory.title")}),jsxRuntime.jsx("div",{className:"flex flex-col gap-y-2 p-3",children:Array.from({length:3}).map((d,u)=>jsxRuntime.jsx("div",{className:"h-8 animate-pulse rounded bg-default-100"},u))})]}):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:i("predict.tradeHistory.title")}),e.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-default-400",children:i("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:i("predict.tradeHistory.side")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Price",width:80,children:i("predict.tradeHistory.price")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Yes",width:60,children:i("predict.trade.yes")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"No",width:60,children:i("predict.trade.no")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Qty",width:60,children:i("predict.tradeHistory.qty")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Time",width:120,children:i("predict.tradeHistory.time")})]}),jsxRuntime.jsx(ui.TableBody,{children:c.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"?i("predict.trade.yes"):i("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))})]})}),(a||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:!a,onPress:l,startContent:jsxRuntime.jsx(ui.ChevronLeftIcon,{className:"h-3 w-3"}),children:i("predict.pagination.prev")}),jsxRuntime.jsx("span",{className:"text-xs text-default-500",children:i("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:i("predict.pagination.next")})]})]})]})}function yg({ticker:e,pageSize:t}={}){let{trades:r,isLoading:n,isFetching:s,page:a,hasNextPage:o,hasPrevPage:l,nextPage:i,prevPage:c}=Wn({ticker:e,pageSize:t});return jsxRuntime.jsx(Fn,{trades:r,isLoading:n,isFetching:s,page:a,hasNextPage:o,hasPrevPage:l,onNextPage:i,onPrevPage:c})}function qn(e={}){let t=react.useMemo(()=>({totalValue:0,totalUnrealizedPnl:0,totalRealizedPnl:0,count:0}),[]);return {positions:[],isLoading:false,isFetching:false,summary:t}}var et=e=>utils.formatAmountUSDCompact(e/100);function Kt({value:e}){if(e===0)return jsxRuntime.jsx("span",{className:"text-default-500",children:et(0)});let t=e>0;return jsxRuntime.jsxs("span",{className:t?"text-success":"text-danger",children:[t?"+":"",et(e)]})}function Kn({positions:e,isLoading:t,summary:r,onSell:n}){let{t:s}=i18n.useTranslation(),a=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:a.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:et(o.value)})}),jsxRuntime.jsx(ui.TableCell,{children:jsxRuntime.jsx("span",{className:"text-xs",children:jsxRuntime.jsx(Kt,{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:et(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(Kt,{value:r.totalUnrealizedPnl})]}),jsxRuntime.jsxs("span",{className:"text-default-500",children:[s("predict.positions.realizedPnl"),":"," ",jsxRuntime.jsx(Kt,{value:r.totalRealizedPnl})]})]})]})]})]})}function Eg({refetchInterval:e,onSell:t}={}){let{positions:r,isLoading:n,summary:s}=qn({});return jsxRuntime.jsx(Kn,{positions:r,isLoading:n,summary:s,onSell:t})}function Jg({client:e,wsClient:t=null,children:r}){let n=react.useMemo(()=>({client:e,wsClient:t}),[e,t]);return jsxRuntime.jsx(we.Provider,{value:n,children:r})}var mc=3e4;function oh({walletAddress:e,pollingInterval:t=mc,enabled:r=true,children:n}){let{data:s,isLoading:a,error:o,refetch:l}=or({walletAddress:e},{enabled:r&&!!e,refetchInterval:t}),i=react.useMemo(()=>({positions:s?.positions??[],usdcBalance:s?.usdcBalance??0,isLoading:a,error:o??null,refetch:l}),[s?.positions,s?.usdcBalance,a,o,l]);return jsxRuntime.jsx(me.Provider,{value:i,children:n})}function Hn(e,t){let r=new URLSearchParams;t&&r.set("provider",t);for(let[s,a]of Object.entries(e))a!=null&&(typeof a=="object"?r.set(s,JSON.stringify(a)):r.set(s,String(a)));let n=r.toString();return n?`?${n}`:""}function $n(e){return e}var We=class{constructor(t,r){this.endpoint=t;this.provider=r;}buildUrl(t,r){let n=Hn(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 tt(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 Vn(e){return {yesBids:tt(e.yes_bids,"desc"),yesAsks:tt(e.yes_asks,"asc"),noBids:tt(e.no_bids,"desc"),noAsks:tt(e.no_asks,"asc"),sequence:e.sequence}}var rt=class extends We{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 Vn(r)}async getOrderbookByMint(t){let r=await this.fetch(`/v2/orderbook/by-mint/${t}`);return Vn(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")}};
2
+ exports.BasePredictClient=We;exports.CHART_RANGE_DURATION=Ye;exports.CHART_RANGE_PERIOD=Ve;exports.CHART_RANGE_SAMPLE_INTERVAL=ze;exports.CandlestickPeriod=$e;exports.CategoriesSkeleton=Sr;exports.CategoriesUI=Cr;exports.CategoriesWidget=Or;exports.ChartRange=S;exports.DEFAULT_CHART_RANGE=fe;exports.DEFAULT_PAGE_SIZE=Pe;exports.DEFAULT_PRICE_HISTORY_INTERVAL=im;exports.DflowPredictClient=rt;exports.DflowPredictWsClient=Ie;exports.EventDetailPage=px;exports.EventDetailSkeleton=Le;exports.EventDetailUI=wn;exports.EventDetailWidget=_t;exports.EventItemSkeleton=la;exports.EventItemUI=Br;exports.EventMarketDetailWidget=xn;exports.EventsPage=Km;exports.EventsSkeleton=Nr;exports.EventsUI=Ar;exports.EventsWidget=Wr;exports.MAX_PRICE_HISTORY_MARKETS=ye;exports.ORDER_MAX_PRICE=am;exports.ORDER_MIN_PRICE=om;exports.ORDER_MIN_QUANTITY=Pt;exports.ORDER_PRICE_STEP=sm;exports.OpenOrdersUI=An;exports.OpenOrdersWidget=jx;exports.OrderBookUI=Bn;exports.OrderBookWidget=Bx;exports.PRICE_HISTORY_SAMPLE_INTERVAL=lm;exports.PositionsUI=Kn;exports.PositionsWidget=Eg;exports.PredictClient=rt;exports.PredictContext=we;exports.PredictProvider=Jg;exports.PredictWsClient=Ie;exports.PriceHistoryInterval=Re;exports.TradeFormSkeleton=Vr;exports.TradeFormUI=$r;exports.TradeFormWidget=Ot;exports.TradeHistoryUI=Fn;exports.TradeHistoryWidget=yg;exports.UserPredictContext=me;exports.UserPredictProvider=oh;exports.buildQuery=Hn;exports.createDflowPredictWsClient=Ke;exports.createPredictWsClient=Ke;exports.createSwap=Oo;exports.createSwapInstructions=Ro;exports.eventByIdQueryKey=ys;exports.eventCandlesticksQueryKey=qs;exports.eventsInfiniteQueryKey=ps;exports.eventsQueryKey=us;exports.fetchEventById=fs;exports.fetchEventCandlesticks=Ks;exports.fetchEvents=lt;exports.fetchFiltersBySports=co;exports.fetchForecastPercentileHistory=zs;exports.fetchForecastPercentileHistoryByMint=Gs;exports.fetchIntentQuote=Ao;exports.fetchLiveData=Xs;exports.fetchLiveDataByEvent=Js;exports.fetchLiveDataByMint=to;exports.fetchMarketById=ks;exports.fetchMarketByMint=Ss;exports.fetchMarketCandlesticks=gt;exports.fetchMarketCandlesticksByMint=$s;exports.fetchMarkets=hs;exports.fetchMarketsBatch=ws;exports.fetchOnchainTradesByEvent=dt;exports.fetchOnchainTradesByMarket=pt;exports.fetchOnchainTradesByWallet=ut;exports.fetchOrder=Eo;exports.fetchOrderBook=Rs;exports.fetchOrderBookByMint=Es;exports.fetchOrderStatus=Qo;exports.fetchOutcomeMints=Co;exports.fetchPositionsByWallet=xo;exports.fetchQuote=wo;exports.fetchSearch=mo;exports.fetchSeries=no;exports.fetchSeriesByTicker=oo;exports.fetchTagsByCategories=io;exports.fetchTokens=qo;exports.fetchTokensWithDecimals=Ho;exports.fetchTrades=Qs;exports.fetchTradesByMint=Ls;exports.fetchVenues=zo;exports.filterOutcomeMints=So;exports.filtersBySportsQueryKey=lo;exports.forecastPercentileHistoryByMintQueryKey=Ys;exports.forecastPercentileHistoryQueryKey=Vs;exports.initPredictionMarket=_o;exports.intentQuoteQueryKey=Uo;exports.liveDataByEventQueryKey=Zs;exports.liveDataByMintQueryKey=eo;exports.liveDataQueryKey=js;exports.marketByIdQueryKey=vs;exports.marketByMintQueryKey=Cs;exports.marketCandlesticksByMintQueryKey=Hs;exports.marketCandlesticksQueryKey=xt;exports.marketsBatchQueryKey=Ms;exports.marketsQueryKey=gs;exports.onchainTradesByEventInfiniteQueryKey=_s;exports.onchainTradesByEventQueryKey=As;exports.onchainTradesByMarketInfiniteQueryKey=Fs;exports.onchainTradesByMarketQueryKey=Ds;exports.onchainTradesByWalletInfiniteQueryKey=Ws;exports.onchainTradesByWalletQueryKey=Us;exports.orderBookByMintQueryKey=Ns;exports.orderBookQueryKey=Os;exports.orderQueryKey=No;exports.orderStatusQueryKey=Io;exports.outcomeMintsQueryKey=Po;exports.positionsByWalletQueryKey=fo;exports.quoteQueryKey=Mo;exports.searchQueryKey=po;exports.seriesByTickerQueryKey=so;exports.seriesQueryKey=ro;exports.submitIntentSwap=Do;exports.tagsByCategoriesQueryKey=ao;exports.toRecord=$n;exports.tokensQueryKey=Fo;exports.tokensWithDecimalsQueryKey=Ko;exports.tradesByMintQueryKey=Bs;exports.tradesQueryKey=Is;exports.useCategoriesQuery=Vu;exports.useCreateSwapInstructionsMutation=vd;exports.useCreateSwapMutation=bd;exports.useEventByIdQuery=qe;exports.useEventCandlesticksQuery=Tu;exports.useEventDetail=zr;exports.useEvents=Rr;exports.useEventsCategories=vr;exports.useEventsInfiniteQuery=Gt;exports.useEventsQuery=Ic;exports.useFilterOutcomeMintsMutation=dd;exports.useFiltersBySportsQuery=$u;exports.useForecastPercentileHistoryByMintQuery=Iu;exports.useForecastPercentileHistoryQuery=Eu;exports.useInitPredictionMarketMutation=Qd;exports.useIntentQuoteQuery=Od;exports.useLiveDataByEventQuery=Au;exports.useLiveDataByMintQuery=Du;exports.useLiveDataQuery=Uu;exports.useMarketByIdQuery=zc;exports.useMarketByMintQuery=Xc;exports.useMarketCandlesticksByMintQuery=Mu;exports.useMarketCandlesticksQuery=ht;exports.useMarketPositions=ar;exports.useMarketsBatchQuery=tu;exports.useMarketsQuery=Kc;exports.useOnchainTradesByEventInfiniteQuery=vu;exports.useOnchainTradesByEventQuery=mu;exports.useOnchainTradesByMarketInfiniteQuery=ku;exports.useOnchainTradesByMarketQuery=yu;exports.useOnchainTradesByWalletInfiniteQuery=bu;exports.useOnchainTradesByWalletQuery=Jt;exports.useOpenOrders=Un;exports.useOrderBook=En;exports.useOrderBookByMintQuery=ou;exports.useOrderBookQuery=Oe;exports.useOrderQuery=cr;exports.useOrderStatusQuery=Sd;exports.useOrderbookSubscription=ip;exports.useOutcomeMintsQuery=ud;exports.usePositions=qn;exports.usePositionsByWalletQuery=or;exports.usePredictClient=b;exports.usePredictContext=Yt;exports.usePriceHistoryQuery=wu;exports.usePricesSubscription=tp;exports.useQuoteQuery=fd;exports.useSearchQuery=ju;exports.useSeriesByTickerQuery=nr;exports.useSeriesQuery=rr;exports.useSubmitIntentSwapMutation=Rd;exports.useTagsByCategoriesQuery=vt;exports.useTokensQuery=Ad;exports.useTokensWithDecimalsQuery=Dd;exports.useTradeForm=Fr;exports.useTradeHistory=Wn;exports.useTradesByMintQuery=cu;exports.useTradesQuery=Zt;exports.useTradesSubscription=sp;exports.useUserPredictContext=nd;exports.useVenuesQuery=qd;exports.useWsClient=Zd;exports.useWsConnection=Yd;exports.venuesQueryKey=Vo;exports.version=os;//# sourceMappingURL=index.js.map
3
3
  //# sourceMappingURL=index.js.map