@liberfi.io/ui-predict 0.1.3 → 0.1.4

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.d.mts CHANGED
@@ -13,7 +13,7 @@ declare global {
13
13
  };
14
14
  }
15
15
  }
16
- declare const _default: "0.1.3";
16
+ declare const _default: "0.1.4";
17
17
 
18
18
  interface EventsPageProps {
19
19
  /** Callback when an event is selected */
package/dist/index.d.ts CHANGED
@@ -13,7 +13,7 @@ declare global {
13
13
  };
14
14
  }
15
15
  }
16
- declare const _default: "0.1.3";
16
+ declare const _default: "0.1.4";
17
17
 
18
18
  interface EventsPageProps {
19
19
  /** Callback when an event is selected */
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'),hooks=require('@liberfi.io/hooks'),utils=require('@liberfi.io/utils'),walletConnector=require('@liberfi.io/wallet-connector'),pt=require('canvas-confetti'),client=require('@liberfi.io/client'),types=require('@liberfi.io/types'),recharts=require('recharts');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var pt__default=/*#__PURE__*/_interopDefault(pt);typeof window<"u"&&(window.__LIBERFI_VERSION__=window.__LIBERFI_VERSION__||{},window.__LIBERFI_VERSION__["@liberfi.io/ui-predict"]="0.1.3");var qn="0.1.3";var ke=react.createContext({});function Lt(){let e=react.useContext(ke);if(!e)throw new Error("usePredictContext must be used within a PredictProvider");return e}function v(){let{client:e}=Lt();return e}function Vn(e){return ["predict","events",e??{}]}async function et(e,t){return await e.getEvents(t)}function Ql(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Vn(e),queryFn:async()=>et(r,e),...t})}function Gn(e){return ["predict","events","infinite",e??{}]}function Ut(e={},t={}){let r=v();return reactQuery.useInfiniteQuery({queryKey:Gn(e),queryFn:async({pageParam:n})=>et(r,{...e,...n!==void 0?{cursor:n}:{}}),initialPageParam:void 0,getNextPageParam:n=>n.cursor??void 0,...t})}function jn(e){return ["predict","event","byId",e.id,e.withNestedMarkets]}async function Xn(e,t){return await e.getEventById(t.id,t.withNestedMarkets)}function Le(e,t={}){let r=v();return reactQuery.useQuery({queryKey:jn(e),queryFn:async()=>Xn(r,e),...t})}function Jn(e){return ["predict","markets",e??{}]}async function es(e,t){return await e.getMarkets(t)}function Kl(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Jn(e),queryFn:async()=>es(r,e),...t})}function rs(e){return ["predict","market","byId",e.id]}async function ns(e,t){return await e.getMarketById(t.id)}function Gl(e,t={}){let r=v();return reactQuery.useQuery({queryKey:rs(e),queryFn:async()=>ns(r,e),...t})}function os(e){return ["predict","market","byMint",e]}async function as(e,t){return await e.getMarketByMint(t)}function Zl(e,t={}){let r=v();return reactQuery.useQuery({queryKey:os(e),queryFn:async()=>as(r,e),...t})}function ls(e){return ["predict","markets","batch",e]}async function cs(e,t){return await e.getMarketsBatch(t)}function rc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:ls(e),queryFn:async()=>cs(r,e),enabled:!!(e.tickers?.length||e.mints?.length),...t})}function us(e){return ["predict","orderBook",e]}async function ds(e,t){return await e.getOrderbook(t)}function he(e,t={}){let r=v();return reactQuery.useQuery({queryKey:us(e),queryFn:async()=>ds(r,e),...t})}function ps(e){return ["predict","orderBook","byMint",e]}async function ms(e,t){return await e.getOrderbookByMint(t)}function ac(e,t={}){let r=v();return reactQuery.useQuery({queryKey:ps(e),queryFn:async()=>ms(r,e),...t})}function ys(e){return ["predict","trades",e??{}]}async function fs(e,t){return await e.getTrades(t)}function _t(e,t={}){let r=v();return reactQuery.useQuery({queryKey:ys(e),queryFn:async()=>fs(r,e),...t})}function gs(e){return ["predict","trades","byMint",e]}async function xs(e,t){return await e.getTradesByMint(t)}function uc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:gs(e),queryFn:async()=>xs(r,e),...t})}function bs(e){return ["predict","candlesticks","event",e]}async function vs(e,t){let{ticker:r,...n}=t;return await e.getEventCandlesticks(r,n)}function yc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:bs(e),queryFn:async()=>vs(r,e),...t})}function rt(e){return ["predict","candlesticks","market",e]}async function nt(e,t){let{ticker:r,...n}=t;return await e.getMarketCandlesticks(r,n)}function st(e,t={}){let r=v();return reactQuery.useQuery({queryKey:rt(e),queryFn:async()=>nt(r,e),...t})}function ks(e){return ["predict","candlesticks","market","byMint",e]}async function hs(e,t){let{mintAddress:r,...n}=t;return await e.getMarketCandlesticksByMint(r,n)}function fc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:ks(e),queryFn:async()=>hs(r,e),...t})}var gc=st;function Ps(e){return ["predict","forecast","percentileHistory",e]}async function Cs(e,t){return await e.getEventForecastPercentileHistory(t)}function kc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Ps(e),queryFn:async()=>Cs(r,e),...t})}function Ss(e){return ["predict","forecast","percentileHistory","byMint",e]}async function ws(e,t){return await e.getEventForecastPercentileHistoryByMint(t)}function hc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Ss(e),queryFn:async()=>ws(r,e),...t})}function Rs(e){return ["predict","liveData",e]}async function Ms(e,t){return await e.getLiveData(t)}function wc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Rs(e),queryFn:async()=>Ms(r,e),enabled:e.milestoneIds.length>0,...t})}function Ts(e){return ["predict","liveData","byEvent",e]}async function Ns(e,t){return await e.getLiveDataByEvent(t)}function Rc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Ts(e),queryFn:async()=>Ns(r,e),enabled:!!e.eventTicker,...t})}function Es(e){return ["predict","liveData","byMint",e]}async function Os(e,t){return await e.getLiveDataByMint(t)}function Mc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Es(e),queryFn:async()=>Os(r,e),enabled:!!e.mintAddress,...t})}function Is(e){return ["predict","series",e??{}]}async function Qs(e,t){return await e.getSeries(t)}function qt(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Is(e),queryFn:async()=>Qs(r,e),...t})}function Bs(e){return ["predict","series","byTicker",e]}async function Ls(e,t){return await e.getSeriesByTicker(t)}function Ht(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Bs(e),queryFn:async()=>Ls(r,e),...t})}function Us(){return ["predict","tags","byCategories"]}async function Ds(e){return await e.getTagsByCategories()}function at(e={}){let t=v();return reactQuery.useQuery({queryKey:Us(),queryFn:async()=>Ds(t),...e})}function As(){return ["predict","filters","bySports"]}async function _s(e){return await e.getFiltersBySports()}function Bc(e={}){let t=v();return reactQuery.useQuery({queryKey:As(),queryFn:async()=>_s(t),...e})}var Lc=at;function Ws(e){return ["predict","search",e]}async function qs(e,t){return await e.search(t)}function _c(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Ws(e),queryFn:async()=>qs(r,e),...t})}function $s(e){return ["predict","outcomeMints",e??{}]}async function Vs(e,t){return await e.getOutcomeMints(t)}function Hc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:$s(e),queryFn:async()=>Vs(r,e),...t})}async function zs(e,t){return await e.filterOutcomeMints(t)}function Kc(e={}){let t=v();return reactQuery.useMutation({mutationFn:async r=>zs(t,r),...e})}function Ys(e){return ["predict","quote",e]}async function js(e,t){return await e.getQuote(t)}function Gc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Ys(e),queryFn:async()=>js(r,e),enabled:!!(e.inputMint&&e.outputMint&&e.amount>0),staleTime:1e4,gcTime:3e4,...t})}async function Xs(e,t){return await e.createSwap(t)}function Zc(e={}){let t=v();return reactQuery.useMutation({mutationFn:async r=>Xs(t,r),...e})}async function Zs(e,t){return await e.createSwapInstructions(t)}function Jc(e={}){let t=v();return reactQuery.useMutation({mutationFn:async r=>Zs(t,r),...e})}function Js(e){return ["predict","order",e]}async function eo(e,t){return await e.getOrder(t)}function zt(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Js(e),queryFn:async()=>eo(r,e),enabled:!!(e.inputMint&&e.outputMint&&e.amount>0),staleTime:1e4,gcTime:3e4,...t})}function to(e){return ["predict","order","status",e.signature]}async function ro(e,t){return await e.getOrderStatus(t)}function nu(e,t={}){let r=v();return reactQuery.useQuery({queryKey:to(e),queryFn:async()=>ro(r,e),enabled:!!e.signature,refetchInterval:t.refetchInterval??3e3,...t})}function oo(e){return ["predict","intent","quote",e]}async function ao(e,t){return await e.getIntentQuote(t)}function iu(e,t={}){let r=v();return reactQuery.useQuery({queryKey:oo(e),queryFn:async()=>ao(r,e),enabled:!!(e.inputMint&&e.outputMint&&e.amount>0),staleTime:1e4,gcTime:3e4,...t})}async function io(e,t){return await e.submitIntentSwap(t)}function lu(e={}){let t=v();return reactQuery.useMutation({mutationFn:async r=>io(t,r),...e})}async function co(e,t){return await e.initPredictionMarket(t)}function pu(e={}){let t=v();return reactQuery.useMutation({mutationFn:async r=>co(t,r),...e})}function uo(){return ["predict","tokens"]}async function po(e){return await e.getTokens()}function gu(e={}){let t=v();return reactQuery.useQuery({queryKey:uo(),queryFn:async()=>po(t),staleTime:300*1e3,gcTime:1800*1e3,...e})}function mo(){return ["predict","tokens","decimals"]}async function yo(e){return await e.getTokensWithDecimals()}function xu(e={}){let t=v();return reactQuery.useQuery({queryKey:mo(),queryFn:async()=>yo(t),staleTime:300*1e3,gcTime:1800*1e3,...e})}function go(){return ["predict","venues"]}async function xo(e){return await e.getVenues()}function hu(e={}){let t=v();return reactQuery.useQuery({queryKey:go(),queryFn:async()=>xo(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 Mu({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 m=Ue({wsUrl:e,autoConnect:t,autoReconnect:r});a.current=m;let p=m.on("status",b=>{i(b);}),y=m.on("error",b=>{l(b);}),x=m.on("connect",()=>{l(null);});return ()=>{p(),y(),x(),m.disconnect(),a.current=null;}},[e,t,r,n]);let c=react.useCallback(()=>{a.current?.connect();},[]),d=react.useCallback(()=>{a.current?.disconnect();},[]);return {client:a.current,status:s,isConnected:s==="connected",connect:c,disconnect:d,error:o}}function Ou(){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 Bu({client:e,all:t=false,tickers:r=[],enabled:n=true,onUpdate:s}){let[i,o]=react.useState(new Map),[l,a]=react.useState(false),c=react.useRef(s);return react.useEffect(()=>{c.current=s;},[s]),react.useEffect(()=>{if(!e||!n){a(false);return}if(!t&&r.length===0)return;let d=t?{all:true}:{tickers:r},u=e.subscribePrices(d,m=>{o(p=>{let y=new Map(p);return y.set(m.market_ticker,{yesBid:m.yes_bid,yesAsk:m.yes_ask,noBid:m.no_bid,noAsk:m.no_ask,updatedAt:Date.now()}),y}),c.current?.(m);});return a(true),()=>{u(),a(false);}},[e,t,r.join(","),n]),{prices:i,isSubscribed:l}}function Du({client:e,all:t=false,tickers:r=[],enabled:n=true,maxHistory:s=100,onUpdate:i}){let[o,l]=react.useState([]),[a,c]=react.useState(false),d=react.useRef(i);react.useEffect(()=>{d.current=i;},[i]),react.useEffect(()=>{if(!e||!n){c(false);return}if(!t&&r.length===0)return;let m=t?{all:true}:{tickers:r},p=e.subscribeTrades(m,y=>{let x={tradeId:y.trade_id,marketTicker:y.market_ticker,price:y.price,count:y.count,yesPrice:y.yes_price,noPrice:y.no_price,takerSide:y.taker_side,createdTime:y.created_time};l(b=>{let g=[x,...b];return g.length>s?g.slice(0,s):g}),d.current?.(y);});return c(true),()=>{p(),c(false);}},[e,t,r.join(","),n,s]);let u=react.useCallback(()=>{l([]);},[]);return {trades:o,isSubscribed:a,clearHistory:u}}function Fu({client:e,all:t=false,tickers:r=[],enabled:n=true,onUpdate:s}){let[i,o]=react.useState(new Map),[l,a]=react.useState(false),c=react.useRef(s);react.useEffect(()=>{c.current=s;},[s]),react.useEffect(()=>{if(!e||!n){a(false);return}if(!t&&r.length===0)return;let u=t?{all:true}:{tickers:r},m=e.subscribeOrderbook(u,p=>{o(y=>{let x=new Map(y);return x.set(p.market_ticker,{yesBids:p.yes_bids,yesAsks:p.yes_asks,noBids:p.no_bids,noAsks:p.no_asks,updatedAt:Date.now()}),x}),c.current?.(p);});return a(true),()=>{m(),a(false);}},[e,t,r.join(","),n]);let d=react.useCallback(u=>i.get(u),[i]);return {orderbooks:i,isSubscribed:l,getOrderbook:d}}var nr=["Politics","Sports","Culture","Crypto","Climate","Economics","Mentions","Companies","Financials","Tech & Science"];function sr(){let{data:e,isLoading:t,isError:r,error:n}=at();return {data:react.useMemo(()=>{if(!e?.tagsByCategories)return [];let i=o=>{let l=nr.indexOf(o);return l===-1?nr.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 ir({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.clsx("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(De,{label:l("predict.categories.trending"),isSelected:t===null,onPress:a}),e.map(c=>jsxRuntime.jsx(De,{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(De,{label:l("predict.categories.allMarkets"),isSelected:r===null,onPress:()=>i(null),variant:"secondary"}),n.map(c=>jsxRuntime.jsx(De,{label:c,isSelected:r===c,onPress:()=>i(c),variant:"secondary"},c))]})})]})}function De({label:e,isSelected:t,onPress:r,variant:n="primary"}){return jsxRuntime.jsx("button",{type:"button",onClick:r,className:ui.clsx("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 lr({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 pr({onSelect:e,className:t}){let{data:r,isLoading:n}=sr(),[s,i]=react.useState(null),[o,l]=react.useState(null),a=react.useCallback(u=>{if(i(u),l(null),!u)e?.({category:null,tags:null});else {let m=r.find(p=>p.category===u);e?.({category:u,tags:m?.tags??null});}},[r,e]),c=react.useCallback(u=>{if(l(u),u)e?.({category:s,tags:[u]});else {let m=r.find(p=>p.category===s);e?.({category:s,tags:m?.tags??null});}},[r,s,e]);if(n)return jsxRuntime.jsx(lr,{});let d=r.find(u=>u.category===s)?.tags??[];return jsxRuntime.jsx(ir,{categories:r,selectedCategory:s,selectedTag:o,activeTags:d,onCategorySelect:a,onTagSelect:c,className:t})}var fe=48,le=4,Ae={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]:Ae.ONE_MINUTE,[w.ONE_WEEK]:Ae.ONE_HOUR,[w.ONE_MONTH]:Ae.ONE_HOUR,[w.ALL]:Ae.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},lt=1,Id=1,Qd=1,Bd=99,Pe={ONE_HOUR:"1h",SIX_HOURS:"6h",ONE_DAY:"1d",ONE_WEEK:"1w",MAX:"max"},Ld=Pe.ONE_WEEK,Ud={[Pe.ONE_HOUR]:60,[Pe.SIX_HOURS]:60,[Pe.ONE_DAY]:300,[Pe.ONE_WEEK]:1800,[Pe.MAX]:1800};function mr(e={}){let{category:t,tags:r,...n}=e,s=!!t||!!r&&r.length>0,{data:i,isFetching:o,isError:l,error:a}=qt({...t?{category:t}:{},...r&&r.length>0?{tags:r.join(",")}:{},isInitialized:true,status:"active"},{enabled:s}),c=react.useMemo(()=>{if(!s||!i?.series)return;let Y=i.series.map(P=>P.ticker).slice(0,25);return Y.length>0?Y.join(","):void 0},[s,i]),d=react.useMemo(()=>({status:"active",withNestedMarkets:true,sort:"volume24h",order:"desc",limit:48,...n,...c!==void 0?{seriesTickers:c}:{}}),[n,c]),{data:u,isLoading:m,isFetching:p,isFetchingNextPage:y,isError:x,error:b,hasNextPage:g,fetchNextPage:k,refetch:h}=Ut(d),f=react.useMemo(()=>u?.pages.flatMap(Y=>Y.events)??[],[u]),C=s&&!i&&!l;return {data:f,isLoading:C||m,isFetching:o||C||p&&!y,isFetchingMore:y,isError:l||x,error:a??b,hasMore:g,fetchMore:k,refetch:h}}function Io({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 yr({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(Io,{className:"min-h-44 @5xl:min-h-56"},r))})})}function fr({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,i]=react.useState(null),o=e.markets||[],l=o.length>2?[...o].sort((P,T)=>Number(T.yesAsk??0)-Number(P.yesAsk??0)):o,a=l.filter(P=>P.status==="active"),c=l.length===1,d=c?l[0]:s,u=react.useMemo(()=>utils.formatAmountUSD3((e.volume??0)/100),[e.volume]),m=P=>P.yesAsk?parseFloat(P.yesAsk)*100:null,p=P=>P.noAsk?parseFloat(P.noAsk)*100:null,y=P=>{let T=m(P),W=p(P);return T!=null?W==null&&T<=1?"< 1%":b(T):W!=null?W<=1?"> 99%":b(100-W):"0%"},x=P=>{let T=m(P),W=p(P);return W!=null?T==null&&W<=1?"< 1%":b(W):T!=null?T<=1?"> 99%":b(100-T):"0%"},b=P=>P!=null?`${P.toFixed(0)}%`:"--",g=react.useMemo(()=>{let P=l.some(W=>W.status==="active");return l.every(W=>W.status==="closed"||W.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]),k=P=>{i(P);},h=()=>{i(null);},f=()=>{d&&r&&r(e,d,"yes");},C=()=>{d&&r&&r(e,d,"no");},S=()=>{t&&t(e);},j=a.slice(0,2),Y=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:S,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,closeDelay:0,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(fr,{value:m(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(),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:y(d)}),jsxRuntime.jsx(ui.ChevronUpIcon,{className:"w-3 h-3 text-default-500 @5xl:w-4 @5xl:h-4"})]})]}),!d&&!c&&j.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:[j.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:T=>{T.stopPropagation(),k(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:y(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)),Y&&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 ${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:f,children:[jsxRuntime.jsx("span",{className:"group-hover/yes:hidden",children:n("predict.market.yes")}),jsxRuntime.jsx("span",{className:"hidden group-hover/yes:inline",children:y(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:x(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(),S();},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(),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 Vo=640,zo=768,kr=1024,Go=1280,Yo=16,jo=192,Xo=228,Zo=244;function Jo(e){return e>=Go?4:e>=kr?3:e>=Vo?2:1}function ea(e){return e>=kr?Zo:e>=zo?Xo:jo}function hr({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=Jo(o),c=ea(o),d=Math.ceil(e.length/a)||0,u=t?d+1:d,m=react.useCallback(x=>x<d,[d]),p=react.useCallback(async()=>{r?.();},[r]),y=ui.useInfiniteLoader({isRowLoaded:m,loadMoreRows:p,rowCount:u,threshold:3});return jsxRuntime.jsx("div",{ref:i,className:"@container w-full h-full",children:l>0&&jsxRuntime.jsx(ui.List,{style:{height:l},onRowsRendered:y,rowComponent:ta,rowCount:u,rowHeight:c,rowProps:{events:e,columnCount:a,dataRowCount:d,gap:Yo,onSelect:n,onSelectOutcome:s}})})}function ta({index:e,style:t,events:r,columnCount:n,dataRowCount:s,gap:i,onSelect:o,onSelectOutcome:l}){if(e>=s)return jsxRuntime.jsx("div",{style:t,className:"flex justify-center items-start pt-4",children:jsxRuntime.jsx(ui.Spinner,{size:"sm"})});let a=e*n,c=r.slice(a,a+n),d=n-c.length,u={display:"flex",gap:i,height:`calc(100% - ${i}px)`};return jsxRuntime.jsx("div",{style:t,children:jsxRuntime.jsxs("div",{style:u,children:[c.map(m=>jsxRuntime.jsx("div",{style:{flex:1,minWidth:0},children:jsxRuntime.jsx(br,{event:m,onSelect:o,onSelectOutcome:l})},m.ticker)),d>0&&Array.from({length:d}).map((m,p)=>jsxRuntime.jsx("div",{style:{flex:1,minWidth:0}},`spacer-${p}`))]})})}function Cr({onSelect:e,onSelectOutcome:t,...r}){let{data:n,hasMore:s,fetchMore:i,isFetching:o}=mr({limit:48,...r});return o?jsxRuntime.jsx(yr,{count:48}):jsxRuntime.jsx(hr,{events:n,hasMore:s,onFetchMore:i,onSelect:e,onSelectOutcome:t})}function fp({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(pr,{onSelect:s}),jsxRuntime.jsx("div",{className:"min-h-0 flex-1",children:jsxRuntime.jsx(Cr,{category:r.category,tags:r.tags,onSelect:e,onSelectOutcome:t})})]})}function mt(e,t,r){let n=e[t];return n?r==="yes"?n.yesMint:n.noMint:null}var Ce=utils.SOL_USDC_TOKEN_ADDRESS;function pa(){let e={startVelocity:30,spread:360,ticks:60,zIndex:9999};pt__default.default({...e,particleCount:80,origin:{x:.5,y:.4}}),setTimeout(()=>{pt__default.default({...e,particleCount:40,origin:{x:.3,y:.6}});},150),setTimeout(()=>{pt__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(),o=walletConnector.useWallet(types.Chain.SOLANA),l=i==="authenticated",a=o?.address,[c,d]=react.useState(r),[u,m]=react.useState(n),[p,y]=react.useState(NaN),x=react.useMemo(()=>mt(e.accounts,Ce,c),[e.accounts,c]),{inputMint:b,outputMint:g}=react.useMemo(()=>u==="buy"?{inputMint:Ce,outputMint:x}:{inputMint:x,outputMint:Ce},[u,x]),k=!!b&&!!g&&p>0,h=react.useMemo(()=>Number(c==="yes"?e.yesAsk??.5:e.noAsk??.5),[c,e.yesAsk,e.noAsk]),f=react.useMemo(()=>isNaN(p)||p<=0?0:u==="buy"?h>0?p/h:0:p,[u,p,h]),C=react.useMemo(()=>isNaN(p)||p<=0?0:Math.round(p*1e6),[p]),{data:S,isLoading:j,error:Y,refetch:P}=zt({userPublicKey:a??void 0,inputMint:b??"",outputMint:g??"",amount:C,slippageBps:100},{enabled:k}),{data:T,isLoading:W,refetch:Ot}=client.useWalletPortfoliosQuery({chain:types.Chain.SOLANA,address:a??""},{enabled:l&&!!a,refetchInterval:1e4}),Ie=react.useMemo(()=>{if(!T?.portfolios)return null;let R=T.portfolios.find(X=>X.address===Ce);return R?parseFloat(R.amount):0},[T]),Qe=react.useMemo(()=>{if(!T?.portfolios||!x)return null;let R=T.portfolios.find(X=>X.address===x);return R?parseFloat(R.amount):0},[T,x]),Ye=react.useMemo(()=>mt(e.accounts,Ce,"yes"),[e.accounts]),je=react.useMemo(()=>mt(e.accounts,Ce,"no"),[e.accounts]),En=react.useMemo(()=>{if(!T?.portfolios||!Ye)return null;let R=T.portfolios.find(X=>X.address===Ye);return R?parseFloat(R.amount):0},[T,Ye]),On=react.useMemo(()=>{if(!T?.portfolios||!je)return null;let R=T.portfolios.find(X=>X.address===je);return R?parseFloat(R.amount):0},[T,je]),{data:ve}=he(e.ticker,{refetchInterval:5e3}),In=react.useMemo(()=>(c==="yes"?ve?.yesBids:ve?.noBids)?.[0]?.price??null,[ve,c]),Qn=react.useMemo(()=>(c==="yes"?ve?.yesAsks:ve?.noAsks)?.[0]?.price??null,[ve,c]),Bn=react.useMemo(()=>S?.priceImpactPct?parseFloat(S.priceImpactPct):null,[S]),Be=react.useMemo(()=>{if(isNaN(p)||p<=0)return 0;if(S)return parseInt(S.inAmount)/1e6;if(u==="buy")return p;let R=Number(c==="yes"?e.yesBid??0:e.noBid??0);return p*R},[S,u,c,p,e.yesBid,e.noBid]),It=react.useMemo(()=>isNaN(p)||p<=0?0:u==="buy"?f*1:Be,[u,f,Be,p]),Ln=It-Be,Un=react.useCallback(R=>{m(R),y(NaN);},[]),Dn=react.useCallback(R=>{if(isNaN(R)){y(NaN);return}let X=Math.max(0,R),Je=u==="buy"?Math.round(X*100)/100:Math.round(X);y(Je);},[u]);react.useEffect(()=>{k&&P();},[p,c,u,k,P]);let Xe=react.useMemo(()=>{let R=[];return (isNaN(p)||p<lt)&&R.push(`Minimum quantity is ${lt}`),e.status!=="active"&&R.push("Market is not active"),u==="buy"&&Ie!=null&&!isNaN(p)&&p>0&&p>Ie&&R.push("Insufficient USDC balance"),u==="sell"&&Qe!=null&&!isNaN(p)&&p>0&&p>Qe&&R.push("Insufficient shares"),{isValid:R.length===0,errors:R}},[p,e.status,u,Ie,Qe]),[An,Ze]=react.useState(null),[_n,Qt]=react.useState(false),Fn=react.useCallback(async()=>{if(!(!Xe.isValid||!l||!a||!o||W)){Ze(null),Qt(true);try{let R=S;if(R?.transaction||(R=(await P()).data),!R?.transaction)return;let X=Uint8Array.from(atob(R.transaction),Bt=>Bt.charCodeAt(0)),Je=await o.sendTransaction(X);Ze(Je),ui.toast.success(s("predict.trade.submitSuccess")),pa(),y(NaN),Ot();}catch{ui.toast.error(s("predict.trade.submitError"));}finally{Qt(false);}}},[Xe.isValid,l,a,o,S,W,P,Ot,s]),Wn=react.useCallback(()=>{d(r),m(n),y(NaN),Ze(null);},[r,n]);return {outcome:c,side:u,quantity:p,shares:f,estimatedCost:Be,potentialPayout:It,potentialProfit:Ln,isAuthenticated:l,bestBid:In,bestAsk:Qn,order:S??null,priceImpact:Bn,usdcBalance:Ie,outcomeTokenBalance:Qe,yesTokenBalance:En,noTokenBalance:On,isBalanceLoading:W,isQuoteLoading:j,isSubmitting:_n,quoteError:Y??null,txHash:An,validation:Xe,setOutcome:d,setSide:Un,setQuantity:Dn,submit:Fn,reset:Wn}}var ba=`https://s1.chainstream.io/chains/sol/tokens/${utils.SOL_USDC_TOKEN_ADDRESS}/image.png`;function Er({event:e,market:t,outcome:r,side:n,quantity:s,potentialProfit:i,estimatedCost:o,usdcBalance:l,yesTokenBalance:a,noTokenBalance:c,isBalanceLoading:d,isSubmitting:u,isValid:m,onOutcomeChange:p,onSideChange:y,onQuantityChange:x,onSubmit:b}){let{t:g}=i18n.useTranslation(),k=react.useMemo(()=>{if(u)return g("predict.trade.submitting");let f=g(n==="buy"?"predict.trade.buy":"predict.trade.sell"),C=g(r==="yes"?"predict.trade.yes":"predict.trade.no");return `${f} ${C}`},[u,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:f=>y(f),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(f=>{let C=f==="yes"?a:c;return jsxRuntime.jsxs("div",{className:"flex flex-1 flex-col gap-y-1",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>p(f),className:`w-full rounded-lg border py-2 text-sm font-medium transition-colors cursor-pointer ${r===f?f==="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(f==="yes"?"predict.trade.yes":"predict.trade.no")}),(()=>{let S=n==="buy"?f==="yes"?t.yesAsk:t.noAsk:f==="yes"?t.yesBid:t.noBid;return S!=null?jsxRuntime.jsxs("span",{className:"ml-1 opacity-70",children:[Math.round(Number(S)*100),"\xA2"]}):null})()]}),n==="sell"&&r===f&&jsxRuntime.jsx("span",{className:"text-center text-xs text-foreground",children:d?"\u2013":`${C??0} shares`})]},f)})}),n==="buy"&&jsxRuntime.jsxs("div",{className:"flex items-center justify-end gap-x-1 text-xs text-default-500",children:[jsxRuntime.jsx("img",{src:ba,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:f=>{x(f);},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(f=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>x(Math.round(((isNaN(s)?0:s)+f)*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:["+",f,"$"]},f)),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(f=>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:[f,"%"]},f)),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:!m||u,isLoading:u,onPress:b,children:k})]})}function yt({event:e,market:t,initialSide:r,initialOutcome:n,chain:s}){let{outcome:i,side:o,quantity:l,estimatedCost:a,potentialPayout:c,potentialProfit:d,usdcBalance:u,yesTokenBalance:m,noTokenBalance:p,isBalanceLoading:y,isSubmitting:x,validation:b,setOutcome:g,setSide:k,setQuantity:h,submit:f}=Rr({market:t,initialSide:r,initialOutcome:n,chain:s}),C=walletConnector.useAuthCallback(f);return jsxRuntime.jsx(Er,{event:e,market:t,outcome:i,side:o,quantity:l,estimatedCost:a,potentialPayout:c,potentialProfit:d,usdcBalance:u,yesTokenBalance:m,noTokenBalance:p,isBalanceLoading:y,isSubmitting:x,isValid:b.isValid,validationErrors:b.errors,onOutcomeChange:g,onSideChange:k,onQuantityChange:h,onSubmit:C})}function ha(){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(ha,{},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:c}=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(f=>f.openTime)):i},[i,s,l?.markets]),{data:u,isLoading:m,error:p}=Ht(l?.seriesTicker??"",{enabled:!!l?.seriesTicker}),y=react.useMemo(()=>l?.markets?(t&&t.length>0?t.slice(0,4).map(f=>l.markets.find(C=>C.ticker===f)).filter(f=>f!==void 0):[...l.markets].sort((f,C)=>Number(C.yesAsk??0)-Number(f.yesAsk??0)).slice(0,4)).map(f=>f.ticker):[],[t,l?.markets]),x=reactQuery.useQueries({queries:y.map(h=>({queryKey:rt({ticker:h,startTs:d,endTs:i,periodInterval:n}),queryFn:()=>nt(o,{ticker:h,startTs:d,endTs:i,periodInterval:n}),enabled:y.length>0}))}),b=x.some(h=>h.isLoading),g=react.useMemo(()=>{let h=new Map;return y.forEach((f,C)=>{let S=x[C]?.error;S&&h.set(f,S);}),h},[y,x]),k=react.useMemo(()=>{let h=new Map;return y.forEach((f,C)=>{let S=x[C]?.data;S&&h.set(f,S);}),h},[y,x]);return {event:l,isEventLoading:a,eventError:c,series:u,isSeriesLoading:m,seriesError:p,periodInterval:n,candlesticks:k,isCandlesticksLoading:b,candlestickErrors:g}};var Ta=utils.SOL_USDC_TOKEN_ADDRESS;function Br(e){let{status:t}=walletConnector.useAuth(),r=walletConnector.useWallet(types.Chain.SOLANA),n=t==="authenticated",s=r?.address,{data:i,isLoading:o}=client.useWalletPortfoliosQuery({chain:types.Chain.SOLANA,address:s??""},{enabled:n&&!!s,refetchInterval:1e4});return {holdings:react.useMemo(()=>{let a=new Map;if(!i?.portfolios||e.length===0)return a;let c=new Map;for(let d of i.portfolios)c.set(d.address,parseFloat(d.amount));for(let d of e){let u=d.accounts[Ta];if(!u)continue;let m=c.get(u.yesMint)??0,p=c.get(u.noMint)??0;(m>0||p>0)&&a.set(d.ticker,{yesShares:m,noShares:p});}return a},[i,e]),isLoading:o}}function Aa(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 Lr(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 _a(e,t,r){let n=Fe[r],s=new Map;e.forEach((a,c)=>{let d=new Map;(a.candlesticks??[]).forEach(m=>{let p=m.end_period_ts-m.end_period_ts%n;d.set(p,m.yes_ask.close);}),s.set(c,d);});let i=new Set;for(let a of s.values())for(let c of a.keys())i.add(c);let o=Array.from(i).sort((a,c)=>a-c),l=new Map;return o.map(a=>{let d={date:new Date(a*1e3).toLocaleDateString("en-US",{month:"short",day:"numeric"}),timestamp:a};return t.forEach(u=>{let m=s.get(u)?.get(a);if(m!==void 0)d[u]=Math.round(m*100)/100,l.set(u,d[u]);else {let p=l.get(u);p!==void 0&&(d[u]=p);}}),d})}function Ur({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]),c=react.useMemo(()=>!e||e.size===0?[]:_a(e,a,n),[e,a,n]),d=react.useMemo(()=>{if(c.length===0||a.length===0)return [0,100];let y=1/0,x=-1/0;if(c.forEach(f=>{a.forEach(C=>{let S=f[C];S!==void 0&&(y=Math.min(y,S),x=Math.max(x,S));});}),y===1/0||x===-1/0)return [0,100];let b=x-y,g=Math.max(b*.2,5),k=Math.max(0,Math.floor(y-g)),h=Math.min(100,Math.ceil(x+g));return [k,h]},[c,a]),u=react.useCallback(y=>{if(c.length===0)return null;let x=y!==null?c[y]:c[c.length-1];return x?{timestamp:x.timestamp,date:x.date,markets:a.map((b,g)=>{let k=t.find(h=>h.ticker===b);return {id:b,label:k?.yesSubTitle||`Market ${g+1}`,value:x[b]??0,color:Ke[g%Ke.length].stroke}})}:null},[c,a,t]);react.useEffect(()=>{l.current&&c.length>0&&l.current(u(null));},[c,u]),react.useEffect(()=>{l.current&&l.current(u(i));},[i,u]);let m=react.useCallback(y=>{typeof y?.activeTooltipIndex=="number"&&o(y.activeTooltipIndex);},[]),p=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:m,onMouseLeave:p,children:[jsxRuntime.jsx(recharts.XAxis,{dataKey:"timestamp",tick:y=>{let{x,y:b,payload:g,index:k}=y,h=c.length,C=Math.max(1,Math.ceil(h/6)),S=k===0,j=k===h-1,Y=k%C===0;return !S&&!j&&!Y?null:jsxRuntime.jsx("text",{x,y:b+10,textAnchor:"middle",fill:"hsl(var(--heroui-default-500))",fontSize:10,children:Lr(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:y=>`${y}%`,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:y=>Lr(y,n),formatter:(y,x)=>{let g=t.find(k=>k.ticker===x)?.yesSubTitle||x;return [`${y.toFixed(2)}%`,g]}}),a.map((y,x)=>jsxRuntime.jsx(recharts.Line,{type:"monotone",dataKey:y,stroke:Ke[x%Ke.length].stroke,strokeWidth:2,isAnimationActive:false,dot:b=>jsxRuntime.jsx(Aa,{...b,dataLength:c.length},`dot-${y}-${b.index}`),activeDot:false},y))]})})})}function Dr(){return {timestamp:Date.now()/1e3,date:new Date().toLocaleDateString("en-US",{month:"short",day:"numeric"}),markets:[]}}function _r({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:c,error:d}=st({ticker:e,startTs:o,endTs:i,periodInterval:n},{enabled:!!e});return {candlesticks:l,isLoading:a,isFetching:c,error:d,periodInterval:n}}var za="hsl(var(--heroui-primary))",Ga=[{value:w.ONE_DAY,label:"1D"},{value:w.ONE_WEEK,label:"1W"},{value:w.ONE_MONTH,label:"1M"},{value:w.ALL,label:"ALL"}];function Ya(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 Wr(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 Xa(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 qr({candlesticks:e,isLoading:t,chartRange:r,onRangeChange:n}){let s=react.useMemo(()=>e?Xa(e,r):[],[e,r]),i=react.useMemo(()=>{if(s.length===0)return [0,100];let o=1/0,l=-1/0;for(let m of s)m.value<o&&(o=m.value),m.value>l&&(l=m.value);if(o===1/0||l===-1/0)return [0,100];let a=l-o,c=Math.max(a*.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(vt,{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(vt,{chartRange:r,onRangeChange:n})]}):jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-2",children:[jsxRuntime.jsx("div",{className:"h-[200px] w-full",children:jsxRuntime.jsx(recharts.ResponsiveContainer,{width:"100%",height:"100%",children:jsxRuntime.jsxs(recharts.LineChart,{data:s,margin:{top:10,right:16,left:16,bottom:0},children:[jsxRuntime.jsx(recharts.XAxis,{dataKey:"timestamp",tick:o=>{let{x:l,y:a,payload:c,index:d}=o,u=s.length,p=Math.max(1,Math.ceil(u/6)),y=d===0,x=d===u-1,b=d%p===0;return !y&&!x&&!b?null:jsxRuntime.jsx("text",{x:l,y:a+10,textAnchor:"middle",fill:"hsl(var(--heroui-default-500))",fontSize:10,children:Wr(c.value,r)})},tickLine:false,axisLine:false,interval:0}),jsxRuntime.jsx(recharts.CartesianGrid,{horizontal:true,vertical:false,strokeDasharray:"3 3",stroke:"hsl(var(--heroui-default-200))"}),jsxRuntime.jsx(recharts.YAxis,{domain:i,tickLine:false,axisLine:false,tick:{fontSize:10,fill:"hsl(var(--heroui-default-500))"},tickFormatter:o=>`${o}%`,width:40}),jsxRuntime.jsx(recharts.Tooltip,{cursor:{stroke:"hsl(var(--heroui-default-300))"},content:({active:o,payload:l})=>{if(!o||!l?.length)return null;let a=l[0].payload,c=Math.round(a.value);return jsxRuntime.jsxs("div",{className:"rounded-lg border border-default-200 bg-content1 px-3 py-2 shadow-md",children:[jsxRuntime.jsxs("div",{className:"text-lg font-semibold text-primary",children:["Yes ",c,"\xA2"]}),jsxRuntime.jsxs("div",{className:"text-sm text-neutral",children:["Vol ",ja(a.volume)," \xB7"," ",Wr(a.timestamp,r)]})]})}}),jsxRuntime.jsx(recharts.Line,{type:"monotone",dataKey:"value",stroke:za,strokeWidth:2,isAnimationActive:false,dot:o=>jsxRuntime.jsx(Ya,{...o,dataLength:s.length},`dot-${o.index}`),activeDot:false})]})})}),jsxRuntime.jsx(vt,{chartRange:r,onRangeChange:n})]})}function vt({chartRange:e,onRangeChange:t}){return jsxRuntime.jsx("div",{className:"flex items-center justify-end gap-x-1",children:Ga.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 Hr({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 Kr(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 $r(e,t){for(let r of e)r.depth=t>0?r.cumulative/t:0;}function Yr(e){return `${Math.round(e*100)}\xA2`}function ei(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function ti(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 Vr({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:Yr(e.price)}),jsxRuntime.jsx("span",{className:"relative z-10 font-mono text-foreground text-right",children:ei(e.quantity)}),jsxRuntime.jsx("span",{className:"relative z-10 font-mono text-foreground text-right",children:ti(e.total)})]})}function zr({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 ri(){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:kt}).map((e,t)=>jsxRuntime.jsx(zr,{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:kt}).map((e,t)=>jsxRuntime.jsx(zr,{index:t+3},`bid-${t}`))]})}var kt=8;function ht({bids:e,asks:t,isLoading:r=false,maxLevels:n=kt,onPriceClick:s}){let{t:i}=i18n.useTranslation(),{bidRows:o,askRows:l,spread:a,spreadPercent:c}=react.useMemo(()=>{let u=Kr(e,n),m=Kr(t,n),p=Math.max(u[u.length-1]?.cumulative??0,m[m.length-1]?.cumulative??0);$r(u,p),$r(m,p);let y=u[0]?.price??null,x=m[0]?.price??null,b=null,g=null;if(y!=null&&x!=null){b=x-y;let k=(y+x)/2;k>0&&(g=Math.round(b/k*1e4)/100);}return {bidRows:u,askRows:m,spread:b,spreadPercent:g}},[e,t,n]);return r?jsxRuntime.jsx(ri,{}):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((u,m)=>jsxRuntime.jsx(Vr,{row:u,side:"ask",showType:m===0,onClick:s},u.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"),": ",Yr(a)]}),c!=null&&jsxRuntime.jsxs("span",{className:"text-default-400",children:["(",c,"%)"]})]}),jsxRuntime.jsx("div",{className:"flex flex-col",children:o.map((u,m)=>jsxRuntime.jsx(Vr,{row:u,side:"bid",showType:m===0,onClick:s},u.price))})]})}function Zr({market:e,onTradeAction:t}){let{t:r}=i18n.useTranslation(),[n,s]=react.useState("trade-yes"),[i,o]=react.useState(ce),{orderbook:l,isOrderbookLoading:a}=Hr({marketTicker:e.ticker}),{candlesticks:c,isFetching:d}=_r({marketTicker:e.ticker,openTime:e.openTime,chartRange:i}),u=react.useCallback((p,y)=>{t?.(e,"yes",y==="ask"?"buy":"sell");},[e,t]),m=react.useCallback((p,y)=>{t?.(e,"no",y==="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:p=>s(p),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(ht,{bids:l?.yesBids??[],asks:l?.yesAsks??[],isLoading:a,onPriceClick:u}),n==="trade-no"&&jsxRuntime.jsx(ht,{bids:l?.noBids??[],asks:l?.noAsks??[],isLoading:a,onPriceClick:m}),n==="graph"&&jsxRuntime.jsx(qr,{candlesticks:c,isLoading:d,chartRange:i,onRangeChange:o})]})]})}var St=4;function ai(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 on({markets:e,renderMarketDetail:t,onTradeAction:r,marketHoldings:n}){let{t:s}=i18n.useTranslation(),[i,o]=react.useState(false),[l,a]=react.useState(null);if(e.length===0)return null;let c=e.length>St,d=i?e:e.slice(0,St),u=m=>{a(p=>p===m?null:m);};return jsxRuntime.jsxs("div",{className:"flex flex-col divide-y divide-default-200",children:[d.map(m=>{let{yesCents:p,noCents:y}=ai(m),x=l===m.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(m.ticker),role:"button",tabIndex:0,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),u(m.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:m.yesSubTitle}),(()=>{let b=n?.get(m.ticker);if(!b)return null;let{yesShares:g,noShares:k}=b;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 b=p!=null,g=y!=null;return b&&!g&&p<=1?jsxRuntime.jsx("span",{className:"text-lg font-bold shrink-0 text-center text-default-400 lg:text-xl",children:"< 1%"}):g&&!b&&y<=1?jsxRuntime.jsx("span",{className:"text-lg font-bold shrink-0 text-center text-default-400 lg:text-xl",children:"> 99%"}):!b&&!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:`${p}%`})})(),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?.(m,"yes","buy"),children:p!=null?s("predict.market.action.yes",{price:p}):s("predict.market.yes")}),jsxRuntime.jsx(ui.Button,{size:"sm",color:"secondary",className:"w-20 bg-secondary-100 text-secondary",onPress:()=>r?.(m,"no","buy"),children:y!=null?s("predict.market.action.no",{price:y}):s("predict.market.no")})]}),x?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"})]}),x&&t&&jsxRuntime.jsx("div",{className:"max-h-100 overflow-y-auto px-2 pb-3",children:t(m)})]},m.ticker)}),c&&jsxRuntime.jsx("button",{type:"button",onClick:()=>o(m=>!m),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-St})}),jsxRuntime.jsx(ui.ChevronDownIcon,{className:"h-4 w-4"})]})})]})}var di=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 pi({market:e}){let t=di.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 ln({markets:e,event:t,series:r}){let{t:n}=i18n.useTranslation(),[s,i]=react.useState(null),o=e.filter(a=>a.rulesPrimary);if(o.length===0)return null;let l=o.find(a=>a.ticker===s)??o[0];return l?.rulesPrimary?jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-2",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium lg:text-base",children:n("predict.event.rules")}),o.length>1&&jsxRuntime.jsx(ui.Select,{size:"sm","aria-label":"Select market rules",className:"max-w-48",classNames:{trigger:"min-h-8 h-8",value:"text-xs"},selectedKeys:new Set([l.ticker]),onSelectionChange:a=>{if(a==="all")return;let c=Array.from(a);c.length>0&&i(c[0]);},children:o.map(a=>jsxRuntime.jsx(ui.SelectItem,{textValue:a.yesSubTitle,children:jsxRuntime.jsx("span",{className:"text-xs truncate",children:a.yesSubTitle})},a.ticker))}),jsxRuntime.jsx("div",{className:"text-xs text-foreground lg:text-sm",children:l.rulesPrimary}),jsxRuntime.jsx("span",{className:"text-xs font-medium text-default-500 mt-2 lg:text-sm",children:"Timeline and payout"}),jsxRuntime.jsx(pi,{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 hi=[{value:w.ONE_DAY,label:"1D"},{value:w.ONE_WEEK,label:"1W"},{value:w.ONE_MONTH,label:"1M"},{value:w.ALL,label:"ALL"}];function un({event:e,series:t,candlesticks:r,chartRange:n=w.ONE_DAY,periodInterval:s,isCandlesticksLoading:i,onRangeChange:o,selectedMarketTickers:l,onMarketSelectionChange:a,onTradeAction:c}){let{t:d}=i18n.useTranslation(),[u,m]=react.useState(Dr()),[p,y]=react.useState(false),x=react.useRef(null);react.useEffect(()=>{let f=x.current;if(!f)return;let C=false,S=0,j=()=>{let{bottom:P}=f.getBoundingClientRect(),T=C?P<0:P<-20;T!==C&&(C=T,y(T));},Y=()=>{cancelAnimationFrame(S),S=requestAnimationFrame(j);};return window.addEventListener("scroll",Y,{passive:true,capture:true}),j(),()=>{cancelAnimationFrame(S),window.removeEventListener("scroll",Y,{capture:true});}},[]);let b=react.useMemo(()=>[...e.markets||[]].sort((f,C)=>Number(C.yesAsk??0)-Number(f.yesAsk??0)),[e.markets]),{holdings:g}=Br(b),k=react.useMemo(()=>utils.formatAmountUSD3((e.volume??0)/100),[e.volume]),h=react.useMemo(()=>{if(!e.strikeDate)return null;let f=new Date(e.strikeDate*1e3),C=f.toLocaleString("default",{month:"short"}),S=f.getDate(),j=f.getFullYear();return `${C} ${S}, ${j}`},[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:x,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 ${p?"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 ${p?"!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:[!p&&(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 ${p?"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(f=>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:f.color}}),jsxRuntime.jsx("span",{className:"text-default-600",children:f.label})]},f.id))}),jsxRuntime.jsx(Ur,{candlesticks:r,chartRange:n,markets:b,isLoading:i,onDataChange:f=>m(f)}),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:hi.map(f=>jsxRuntime.jsx("button",{type:"button",onClick:()=>o?.(f.value),className:`px-2 lg:px-3 py-1 text-xs rounded-md transition-colors cursor-pointer ${n===f.value?"bg-primary text-primary-foreground":"bg-default-100 text-default-600 hover:bg-default-200"}`,children:f.label},f.value))}),b.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:f=>{if(f==="all")return;let C=Array.from(f);C.length<=4&&a?.(C);},children:jsxRuntime.jsx(ui.SelectSection,{title:`Pick up to ${4} markets`,classNames:{heading:"text-xs text-default-400 px-2 py-1"},children:b.map(f=>jsxRuntime.jsx(ui.SelectItem,{textValue:f.yesSubTitle,children:jsxRuntime.jsx("span",{className:"text-xs truncate",children:f.yesSubTitle})},f.ticker))})})]})]})}),jsxRuntime.jsx(on,{markets:b,onTradeAction:c,marketHoldings:g,renderMarketDetail:f=>jsxRuntime.jsx(Zr,{market:f,onTradeAction:c})}),jsxRuntime.jsx(ln,{markets:b,event:e,series:t})]})}function Mt({eventId:e,initialMarketTickers:t,initialChartRange:r=ce,onTradeAction:n}){let[s,i]=react.useState(r),[o,l]=react.useState(t),{event:a,isEventLoading:c,eventError:d,series:u,isSeriesLoading:m,periodInterval:p,candlesticks:y,isCandlesticksLoading:x,candlestickErrors:b}=Ir({eventId:e,candlestickMarketTickers:o,chartRange:s}),g=react.useRef(!!t);react.useEffect(()=>{if(a?.markets&&!g.current){g.current=true;let f=[...a.markets].sort((C,S)=>Number(S.yesAsk??0)-Number(C.yesAsk??0)).slice(0,4).map(C=>C.ticker);l(f);}},[a?.markets]);let k=react.useMemo(()=>f=>{i(f);},[]),h=react.useMemo(()=>f=>{l(f);},[]);return c||m?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(un,{event:a,series:u,candlesticks:y,chartRange:s,periodInterval:p,isCandlesticksLoading:x,candlestickErrors:b,onRangeChange:k,selectedMarketTickers:o,onMarketSelectionChange:h,onTradeAction:n})}function Sy({eventId:e,chain:t,...r}){let{t:n}=i18n.useTranslation(),{isMobile:s}=ui.useScreen(),{isOpen:i,onOpen:o,onClose:l}=ui.useDisclosure(),{data:a,isLoading:c}=Le({id:e,withNestedMarkets:true}),d=react.useMemo(()=>[...a?.markets||[]].sort((b,g)=>Number(g.yesAsk??0)-Number(b.yesAsk??0)),[a?.markets]),[u,m]=react.useState(null),p=react.useCallback((b,g,k)=>{m(h=>({market:b,outcome:g,side:k,version:(h?.version??0)+1})),s&&o();},[s,o]),y=u?.market??d[0];if(c)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 x=u?`${u.market.ticker}-${u.version}`:y?.ticker??"default";return s?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"w-full pb-20",children:jsxRuntime.jsx(Mt,{eventId:e,onTradeAction:p,...r})}),y&&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:y&&jsxRuntime.jsx(yt,{event:a,market:y,initialSide:u?.side,initialOutcome:u?.outcome,chain:t},x)})})})]}):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(Mt,{eventId:e,onTradeAction:p,...r})}),y&&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(yt,{event:a,market:y,initialSide:u?.side,initialOutcome:u?.outcome,chain:t},x)})})]})}function mn(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 yn({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]),c=react.useMemo(()=>mn(l,t),[l,t]),d=react.useMemo(()=>mn(a,t),[a,t]),u=react.useMemo(()=>c.length===0||d.length===0?null:d[0].price-c[0].price,[c,d]),m=react.useMemo(()=>c.length===0||d.length===0?null:(c[0].price+d[0].price)/2,[c,d]),p=react.useMemo(()=>u===null||m===null||m===0?null:Math.round(u/m*1e4)/100,[u,m]);return {bids:c,asks:d,spread:u,spreadPercent:p,midpoint:m,isLoading:i,isFetching:o}}function fn({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 gn(){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 xn({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(gn,{}),jsxRuntime.jsx(gn,{})]});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(fn,{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(fn,{row:a,side:"bid",onClick:i},a.price))})]})]})}function Vy({marketTicker:e,maxLevels:t,refetchInterval:r,onPriceClick:n,outcome:s}){let{bids:i,asks:o,spread:l,spreadPercent:a,isLoading:c}=yn({marketTicker:e,maxLevels:t,refetchInterval:r,outcome:s});return jsxRuntime.jsx(xn,{bids:i,asks:o,spread:l,spreadPercent:a,isLoading:c,onPriceClick:n})}function vn(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 zi(e){return new Date(e).toLocaleString("default",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function kn({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:zi(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 cf({refetchInterval:e}={}){let{orders:t,isLoading:r,cancellingOrderId:n,cancelOrder:s}=vn({});return jsxRuntime.jsx(kn,{orders:t,isLoading:r,cancellingOrderId:n,onCancel:s})}function Pn({ticker:e,pageSize:t=48}={}){let[r,n]=react.useState(1),[s,i]=react.useState([void 0]),o=s[r-1],l=react.useMemo(()=>({...e?{ticker:e}:{},limit:t,...o?{cursor:o}:{}}),[e,t,o]),{data:a,isLoading:c,isFetching:d}=_t(l),u=a,m=u?.trades??[],p=!!u?.cursor,y=r>1,x=react.useCallback(k=>{k>=1&&k<=s.length&&n(k);},[s.length]),b=react.useCallback(()=>{p&&u?.cursor&&(i(k=>{let h=[...k];return h.length===r&&h.push(u.cursor),h}),n(k=>k+1));},[p,u?.cursor,r]),g=react.useCallback(()=>{y&&n(k=>k-1);},[y]);return {trades:m,isLoading:c,isFetching:d,page:r,pageSize:t,hasNextPage:p,hasPrevPage:y,goToPage:x,nextPage:b,prevPage:g}}function sl(e){return new Date(e*1e3).toLocaleString("default",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function Sn({trades:e,isLoading:t,isFetching:r,page:n,hasNextPage:s,hasPrevPage:i,onNextPage:o,onPrevPage:l}){let{t:a}=i18n.useTranslation(),c=react.useMemo(()=>e.map(d=>({key:d.tradeId,ticker:d.ticker,takerSide:d.takerSide,price:d.price,yesPrice:d.yesPrice,noPrice:d.noPrice,count:d.count,createdAt:sl(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,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:a("predict.tradeHistory.title")}),e.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-default-400",children:a("predict.tradeHistory.empty")}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:`w-full overflow-x-auto ${r?"opacity-60":""}`,children:jsxRuntime.jsxs(ui.StyledTable,{radius:"none","aria-label":"Trade history",className:"min-w-[480px]",children:[jsxRuntime.jsxs(ui.TableHeader,{children:[jsxRuntime.jsx(ui.TableColumn,{textValue:"Side",width:60,children:a("predict.tradeHistory.side")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Price",width:80,children:a("predict.tradeHistory.price")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Yes",width:60,children:a("predict.trade.yes")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"No",width:60,children:a("predict.trade.no")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Qty",width:60,children:a("predict.tradeHistory.qty")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Time",width:120,children:a("predict.tradeHistory.time")})]}),jsxRuntime.jsx(ui.TableBody,{children:c.map(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 Mf({ticker:e,pageSize:t}={}){let{trades:r,isLoading:n,isFetching:s,page:i,hasNextPage:o,hasPrevPage:l,nextPage:a,prevPage:c}=Pn({ticker:e,pageSize:t});return jsxRuntime.jsx(Sn,{trades:r,isLoading:n,isFetching:s,page:i,hasNextPage:o,hasPrevPage:l,onNextPage:a,onPrevPage:c})}function wn(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.formatAmountUSD3(e/100);function Et({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 Rn({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(Et,{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(Et,{value:r.totalUnrealizedPnl})]}),jsxRuntime.jsxs("span",{className:"text-default-500",children:[s("predict.positions.realizedPnl"),":"," ",jsxRuntime.jsx(Et,{value:r.totalRealizedPnl})]})]})]})]})]})}function Kf({refetchInterval:e,onSell:t}={}){let{positions:r,isLoading:n,summary:s}=wn({});return jsxRuntime.jsx(Rn,{positions:r,isLoading:n,summary:s,onSell:t})}function pg({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 Mn(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 Tn(e){return e}var Oe=class{constructor(t,r){this.endpoint=t;this.provider=r;}buildUrl(t,r){let n=Mn(r??{},this.provider);return `${this.endpoint}${t}${n}`}async fetch(t,r){let n=this.buildUrl(t,r);return await utils.get(n)}async postRequest(t,r,n){let s=this.buildUrl(t,n);return await utils.post(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 Nn(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 Nn(r)}async getOrderbookByMint(t){let r=await this.fetch(`/v2/orderbook/by-mint/${t}`);return Nn(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")}};
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'),hooks=require('@liberfi.io/hooks'),utils=require('@liberfi.io/utils'),walletConnector=require('@liberfi.io/wallet-connector'),pt=require('canvas-confetti'),client=require('@liberfi.io/client'),types=require('@liberfi.io/types'),recharts=require('recharts');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var pt__default=/*#__PURE__*/_interopDefault(pt);typeof window<"u"&&(window.__LIBERFI_VERSION__=window.__LIBERFI_VERSION__||{},window.__LIBERFI_VERSION__["@liberfi.io/ui-predict"]="0.1.4");var qn="0.1.4";var ke=react.createContext({});function Lt(){let e=react.useContext(ke);if(!e)throw new Error("usePredictContext must be used within a PredictProvider");return e}function v(){let{client:e}=Lt();return e}function Vn(e){return ["predict","events",e??{}]}async function et(e,t){return await e.getEvents(t)}function Ql(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Vn(e),queryFn:async()=>et(r,e),...t})}function Gn(e){return ["predict","events","infinite",e??{}]}function Ut(e={},t={}){let r=v();return reactQuery.useInfiniteQuery({queryKey:Gn(e),queryFn:async({pageParam:n})=>et(r,{...e,...n!==void 0?{cursor:n}:{}}),initialPageParam:void 0,getNextPageParam:n=>n.cursor??void 0,...t})}function jn(e){return ["predict","event","byId",e.id,e.withNestedMarkets]}async function Xn(e,t){return await e.getEventById(t.id,t.withNestedMarkets)}function Le(e,t={}){let r=v();return reactQuery.useQuery({queryKey:jn(e),queryFn:async()=>Xn(r,e),...t})}function Jn(e){return ["predict","markets",e??{}]}async function es(e,t){return await e.getMarkets(t)}function Kl(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Jn(e),queryFn:async()=>es(r,e),...t})}function rs(e){return ["predict","market","byId",e.id]}async function ns(e,t){return await e.getMarketById(t.id)}function Gl(e,t={}){let r=v();return reactQuery.useQuery({queryKey:rs(e),queryFn:async()=>ns(r,e),...t})}function os(e){return ["predict","market","byMint",e]}async function as(e,t){return await e.getMarketByMint(t)}function Zl(e,t={}){let r=v();return reactQuery.useQuery({queryKey:os(e),queryFn:async()=>as(r,e),...t})}function ls(e){return ["predict","markets","batch",e]}async function cs(e,t){return await e.getMarketsBatch(t)}function rc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:ls(e),queryFn:async()=>cs(r,e),enabled:!!(e.tickers?.length||e.mints?.length),...t})}function us(e){return ["predict","orderBook",e]}async function ds(e,t){return await e.getOrderbook(t)}function he(e,t={}){let r=v();return reactQuery.useQuery({queryKey:us(e),queryFn:async()=>ds(r,e),...t})}function ps(e){return ["predict","orderBook","byMint",e]}async function ms(e,t){return await e.getOrderbookByMint(t)}function ac(e,t={}){let r=v();return reactQuery.useQuery({queryKey:ps(e),queryFn:async()=>ms(r,e),...t})}function ys(e){return ["predict","trades",e??{}]}async function fs(e,t){return await e.getTrades(t)}function _t(e,t={}){let r=v();return reactQuery.useQuery({queryKey:ys(e),queryFn:async()=>fs(r,e),...t})}function gs(e){return ["predict","trades","byMint",e]}async function xs(e,t){return await e.getTradesByMint(t)}function uc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:gs(e),queryFn:async()=>xs(r,e),...t})}function bs(e){return ["predict","candlesticks","event",e]}async function vs(e,t){let{ticker:r,...n}=t;return await e.getEventCandlesticks(r,n)}function yc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:bs(e),queryFn:async()=>vs(r,e),...t})}function rt(e){return ["predict","candlesticks","market",e]}async function nt(e,t){let{ticker:r,...n}=t;return await e.getMarketCandlesticks(r,n)}function st(e,t={}){let r=v();return reactQuery.useQuery({queryKey:rt(e),queryFn:async()=>nt(r,e),...t})}function ks(e){return ["predict","candlesticks","market","byMint",e]}async function hs(e,t){let{mintAddress:r,...n}=t;return await e.getMarketCandlesticksByMint(r,n)}function fc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:ks(e),queryFn:async()=>hs(r,e),...t})}var gc=st;function Ps(e){return ["predict","forecast","percentileHistory",e]}async function Cs(e,t){return await e.getEventForecastPercentileHistory(t)}function kc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Ps(e),queryFn:async()=>Cs(r,e),...t})}function Ss(e){return ["predict","forecast","percentileHistory","byMint",e]}async function ws(e,t){return await e.getEventForecastPercentileHistoryByMint(t)}function hc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Ss(e),queryFn:async()=>ws(r,e),...t})}function Rs(e){return ["predict","liveData",e]}async function Ms(e,t){return await e.getLiveData(t)}function wc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Rs(e),queryFn:async()=>Ms(r,e),enabled:e.milestoneIds.length>0,...t})}function Ts(e){return ["predict","liveData","byEvent",e]}async function Ns(e,t){return await e.getLiveDataByEvent(t)}function Rc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Ts(e),queryFn:async()=>Ns(r,e),enabled:!!e.eventTicker,...t})}function Es(e){return ["predict","liveData","byMint",e]}async function Os(e,t){return await e.getLiveDataByMint(t)}function Mc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Es(e),queryFn:async()=>Os(r,e),enabled:!!e.mintAddress,...t})}function Is(e){return ["predict","series",e??{}]}async function Qs(e,t){return await e.getSeries(t)}function qt(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Is(e),queryFn:async()=>Qs(r,e),...t})}function Bs(e){return ["predict","series","byTicker",e]}async function Ls(e,t){return await e.getSeriesByTicker(t)}function Ht(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Bs(e),queryFn:async()=>Ls(r,e),...t})}function Us(){return ["predict","tags","byCategories"]}async function Ds(e){return await e.getTagsByCategories()}function at(e={}){let t=v();return reactQuery.useQuery({queryKey:Us(),queryFn:async()=>Ds(t),...e})}function As(){return ["predict","filters","bySports"]}async function _s(e){return await e.getFiltersBySports()}function Bc(e={}){let t=v();return reactQuery.useQuery({queryKey:As(),queryFn:async()=>_s(t),...e})}var Lc=at;function Ws(e){return ["predict","search",e]}async function qs(e,t){return await e.search(t)}function _c(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Ws(e),queryFn:async()=>qs(r,e),...t})}function $s(e){return ["predict","outcomeMints",e??{}]}async function Vs(e,t){return await e.getOutcomeMints(t)}function Hc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:$s(e),queryFn:async()=>Vs(r,e),...t})}async function zs(e,t){return await e.filterOutcomeMints(t)}function Kc(e={}){let t=v();return reactQuery.useMutation({mutationFn:async r=>zs(t,r),...e})}function Ys(e){return ["predict","quote",e]}async function js(e,t){return await e.getQuote(t)}function Gc(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Ys(e),queryFn:async()=>js(r,e),enabled:!!(e.inputMint&&e.outputMint&&e.amount>0),staleTime:1e4,gcTime:3e4,...t})}async function Xs(e,t){return await e.createSwap(t)}function Zc(e={}){let t=v();return reactQuery.useMutation({mutationFn:async r=>Xs(t,r),...e})}async function Zs(e,t){return await e.createSwapInstructions(t)}function Jc(e={}){let t=v();return reactQuery.useMutation({mutationFn:async r=>Zs(t,r),...e})}function Js(e){return ["predict","order",e]}async function eo(e,t){return await e.getOrder(t)}function zt(e,t={}){let r=v();return reactQuery.useQuery({queryKey:Js(e),queryFn:async()=>eo(r,e),enabled:!!(e.inputMint&&e.outputMint&&e.amount>0),staleTime:1e4,gcTime:3e4,...t})}function to(e){return ["predict","order","status",e.signature]}async function ro(e,t){return await e.getOrderStatus(t)}function nu(e,t={}){let r=v();return reactQuery.useQuery({queryKey:to(e),queryFn:async()=>ro(r,e),enabled:!!e.signature,refetchInterval:t.refetchInterval??3e3,...t})}function oo(e){return ["predict","intent","quote",e]}async function ao(e,t){return await e.getIntentQuote(t)}function iu(e,t={}){let r=v();return reactQuery.useQuery({queryKey:oo(e),queryFn:async()=>ao(r,e),enabled:!!(e.inputMint&&e.outputMint&&e.amount>0),staleTime:1e4,gcTime:3e4,...t})}async function io(e,t){return await e.submitIntentSwap(t)}function lu(e={}){let t=v();return reactQuery.useMutation({mutationFn:async r=>io(t,r),...e})}async function co(e,t){return await e.initPredictionMarket(t)}function pu(e={}){let t=v();return reactQuery.useMutation({mutationFn:async r=>co(t,r),...e})}function uo(){return ["predict","tokens"]}async function po(e){return await e.getTokens()}function gu(e={}){let t=v();return reactQuery.useQuery({queryKey:uo(),queryFn:async()=>po(t),staleTime:300*1e3,gcTime:1800*1e3,...e})}function mo(){return ["predict","tokens","decimals"]}async function yo(e){return await e.getTokensWithDecimals()}function xu(e={}){let t=v();return reactQuery.useQuery({queryKey:mo(),queryFn:async()=>yo(t),staleTime:300*1e3,gcTime:1800*1e3,...e})}function go(){return ["predict","venues"]}async function xo(e){return await e.getVenues()}function hu(e={}){let t=v();return reactQuery.useQuery({queryKey:go(),queryFn:async()=>xo(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 Mu({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 m=Ue({wsUrl:e,autoConnect:t,autoReconnect:r});a.current=m;let p=m.on("status",b=>{i(b);}),y=m.on("error",b=>{l(b);}),x=m.on("connect",()=>{l(null);});return ()=>{p(),y(),x(),m.disconnect(),a.current=null;}},[e,t,r,n]);let c=react.useCallback(()=>{a.current?.connect();},[]),d=react.useCallback(()=>{a.current?.disconnect();},[]);return {client:a.current,status:s,isConnected:s==="connected",connect:c,disconnect:d,error:o}}function Ou(){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 Bu({client:e,all:t=false,tickers:r=[],enabled:n=true,onUpdate:s}){let[i,o]=react.useState(new Map),[l,a]=react.useState(false),c=react.useRef(s);return react.useEffect(()=>{c.current=s;},[s]),react.useEffect(()=>{if(!e||!n){a(false);return}if(!t&&r.length===0)return;let d=t?{all:true}:{tickers:r},u=e.subscribePrices(d,m=>{o(p=>{let y=new Map(p);return y.set(m.market_ticker,{yesBid:m.yes_bid,yesAsk:m.yes_ask,noBid:m.no_bid,noAsk:m.no_ask,updatedAt:Date.now()}),y}),c.current?.(m);});return a(true),()=>{u(),a(false);}},[e,t,r.join(","),n]),{prices:i,isSubscribed:l}}function Du({client:e,all:t=false,tickers:r=[],enabled:n=true,maxHistory:s=100,onUpdate:i}){let[o,l]=react.useState([]),[a,c]=react.useState(false),d=react.useRef(i);react.useEffect(()=>{d.current=i;},[i]),react.useEffect(()=>{if(!e||!n){c(false);return}if(!t&&r.length===0)return;let m=t?{all:true}:{tickers:r},p=e.subscribeTrades(m,y=>{let x={tradeId:y.trade_id,marketTicker:y.market_ticker,price:y.price,count:y.count,yesPrice:y.yes_price,noPrice:y.no_price,takerSide:y.taker_side,createdTime:y.created_time};l(b=>{let g=[x,...b];return g.length>s?g.slice(0,s):g}),d.current?.(y);});return c(true),()=>{p(),c(false);}},[e,t,r.join(","),n,s]);let u=react.useCallback(()=>{l([]);},[]);return {trades:o,isSubscribed:a,clearHistory:u}}function Fu({client:e,all:t=false,tickers:r=[],enabled:n=true,onUpdate:s}){let[i,o]=react.useState(new Map),[l,a]=react.useState(false),c=react.useRef(s);react.useEffect(()=>{c.current=s;},[s]),react.useEffect(()=>{if(!e||!n){a(false);return}if(!t&&r.length===0)return;let u=t?{all:true}:{tickers:r},m=e.subscribeOrderbook(u,p=>{o(y=>{let x=new Map(y);return x.set(p.market_ticker,{yesBids:p.yes_bids,yesAsks:p.yes_asks,noBids:p.no_bids,noAsks:p.no_asks,updatedAt:Date.now()}),x}),c.current?.(p);});return a(true),()=>{m(),a(false);}},[e,t,r.join(","),n]);let d=react.useCallback(u=>i.get(u),[i]);return {orderbooks:i,isSubscribed:l,getOrderbook:d}}var nr=["Politics","Sports","Culture","Crypto","Climate","Economics","Mentions","Companies","Financials","Tech & Science"];function sr(){let{data:e,isLoading:t,isError:r,error:n}=at();return {data:react.useMemo(()=>{if(!e?.tagsByCategories)return [];let i=o=>{let l=nr.indexOf(o);return l===-1?nr.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 ir({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.clsx("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(De,{label:l("predict.categories.trending"),isSelected:t===null,onPress:a}),e.map(c=>jsxRuntime.jsx(De,{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(De,{label:l("predict.categories.allMarkets"),isSelected:r===null,onPress:()=>i(null),variant:"secondary"}),n.map(c=>jsxRuntime.jsx(De,{label:c,isSelected:r===c,onPress:()=>i(c),variant:"secondary"},c))]})})]})}function De({label:e,isSelected:t,onPress:r,variant:n="primary"}){return jsxRuntime.jsx("button",{type:"button",onClick:r,className:ui.clsx("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 lr({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 pr({onSelect:e,className:t}){let{data:r,isLoading:n}=sr(),[s,i]=react.useState(null),[o,l]=react.useState(null),a=react.useCallback(u=>{if(i(u),l(null),!u)e?.({category:null,tags:null});else {let m=r.find(p=>p.category===u);e?.({category:u,tags:m?.tags??null});}},[r,e]),c=react.useCallback(u=>{if(l(u),u)e?.({category:s,tags:[u]});else {let m=r.find(p=>p.category===s);e?.({category:s,tags:m?.tags??null});}},[r,s,e]);if(n)return jsxRuntime.jsx(lr,{});let d=r.find(u=>u.category===s)?.tags??[];return jsxRuntime.jsx(ir,{categories:r,selectedCategory:s,selectedTag:o,activeTags:d,onCategorySelect:a,onTagSelect:c,className:t})}var fe=48,le=4,Ae={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]:Ae.ONE_MINUTE,[w.ONE_WEEK]:Ae.ONE_HOUR,[w.ONE_MONTH]:Ae.ONE_HOUR,[w.ALL]:Ae.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},lt=1,Id=1,Qd=1,Bd=99,Pe={ONE_HOUR:"1h",SIX_HOURS:"6h",ONE_DAY:"1d",ONE_WEEK:"1w",MAX:"max"},Ld=Pe.ONE_WEEK,Ud={[Pe.ONE_HOUR]:60,[Pe.SIX_HOURS]:60,[Pe.ONE_DAY]:300,[Pe.ONE_WEEK]:1800,[Pe.MAX]:1800};function mr(e={}){let{category:t,tags:r,...n}=e,s=!!t||!!r&&r.length>0,{data:i,isFetching:o,isError:l,error:a}=qt({...t?{category:t}:{},...r&&r.length>0?{tags:r.join(",")}:{},isInitialized:true,status:"active"},{enabled:s}),c=react.useMemo(()=>{if(!s||!i?.series)return;let Y=i.series.map(P=>P.ticker).slice(0,25);return Y.length>0?Y.join(","):void 0},[s,i]),d=react.useMemo(()=>({status:"active",withNestedMarkets:true,sort:"volume24h",order:"desc",limit:48,...n,...c!==void 0?{seriesTickers:c}:{}}),[n,c]),{data:u,isLoading:m,isFetching:p,isFetchingNextPage:y,isError:x,error:b,hasNextPage:g,fetchNextPage:k,refetch:h}=Ut(d),f=react.useMemo(()=>u?.pages.flatMap(Y=>Y.events)??[],[u]),C=s&&!i&&!l;return {data:f,isLoading:C||m,isFetching:o||C||p&&!y,isFetchingMore:y,isError:l||x,error:a??b,hasMore:g,fetchMore:k,refetch:h}}function Io({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 yr({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(Io,{className:"min-h-44 @5xl:min-h-56"},r))})})}function fr({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,i]=react.useState(null),o=e.markets||[],l=o.length>2?[...o].sort((P,T)=>Number(T.yesAsk??0)-Number(P.yesAsk??0)):o,a=l.filter(P=>P.status==="active"),c=l.length===1,d=c?l[0]:s,u=react.useMemo(()=>utils.formatAmountUSD3((e.volume??0)/100),[e.volume]),m=P=>P.yesAsk?parseFloat(P.yesAsk)*100:null,p=P=>P.noAsk?parseFloat(P.noAsk)*100:null,y=P=>{let T=m(P),W=p(P);return T!=null?W==null&&T<=1?"< 1%":b(T):W!=null?W<=1?"> 99%":b(100-W):"0%"},x=P=>{let T=m(P),W=p(P);return W!=null?T==null&&W<=1?"< 1%":b(W):T!=null?T<=1?"> 99%":b(100-T):"0%"},b=P=>P!=null?`${P.toFixed(0)}%`:"--",g=react.useMemo(()=>{let P=l.some(W=>W.status==="active");return l.every(W=>W.status==="closed"||W.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]),k=P=>{i(P);},h=()=>{i(null);},f=()=>{d&&r&&r(e,d,"yes");},C=()=>{d&&r&&r(e,d,"no");},S=()=>{t&&t(e);},j=a.slice(0,2),Y=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:S,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,closeDelay:0,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(fr,{value:m(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(),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:y(d)}),jsxRuntime.jsx(ui.ChevronUpIcon,{className:"w-3 h-3 text-default-500 @5xl:w-4 @5xl:h-4"})]})]}),!d&&!c&&j.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:[j.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:T=>{T.stopPropagation(),k(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:y(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)),Y&&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 ${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:f,children:[jsxRuntime.jsx("span",{className:"group-hover/yes:hidden",children:n("predict.market.yes")}),jsxRuntime.jsx("span",{className:"hidden group-hover/yes:inline",children:y(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:x(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(),S();},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(),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 Vo=640,zo=768,kr=1024,Go=1280,Yo=16,jo=192,Xo=228,Zo=244;function Jo(e){return e>=Go?4:e>=kr?3:e>=Vo?2:1}function ea(e){return e>=kr?Zo:e>=zo?Xo:jo}function hr({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=Jo(o),c=ea(o),d=Math.ceil(e.length/a)||0,u=t?d+1:d,m=react.useCallback(x=>x<d,[d]),p=react.useCallback(async()=>{r?.();},[r]),y=ui.useInfiniteLoader({isRowLoaded:m,loadMoreRows:p,rowCount:u,threshold:3});return jsxRuntime.jsx("div",{ref:i,className:"@container w-full h-full",children:l>0&&jsxRuntime.jsx(ui.List,{style:{height:l},onRowsRendered:y,rowComponent:ta,rowCount:u,rowHeight:c,rowProps:{events:e,columnCount:a,dataRowCount:d,gap:Yo,onSelect:n,onSelectOutcome:s}})})}function ta({index:e,style:t,events:r,columnCount:n,dataRowCount:s,gap:i,onSelect:o,onSelectOutcome:l}){if(e>=s)return jsxRuntime.jsx("div",{style:t,className:"flex justify-center items-start pt-4",children:jsxRuntime.jsx(ui.Spinner,{size:"sm"})});let a=e*n,c=r.slice(a,a+n),d=n-c.length,u={display:"flex",gap:i,height:`calc(100% - ${i}px)`};return jsxRuntime.jsx("div",{style:t,children:jsxRuntime.jsxs("div",{style:u,children:[c.map(m=>jsxRuntime.jsx("div",{style:{flex:1,minWidth:0},children:jsxRuntime.jsx(br,{event:m,onSelect:o,onSelectOutcome:l})},m.ticker)),d>0&&Array.from({length:d}).map((m,p)=>jsxRuntime.jsx("div",{style:{flex:1,minWidth:0}},`spacer-${p}`))]})})}function Cr({onSelect:e,onSelectOutcome:t,...r}){let{data:n,hasMore:s,fetchMore:i,isFetching:o}=mr({limit:48,...r});return o?jsxRuntime.jsx(yr,{count:48}):jsxRuntime.jsx(hr,{events:n,hasMore:s,onFetchMore:i,onSelect:e,onSelectOutcome:t})}function fp({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(pr,{onSelect:s}),jsxRuntime.jsx("div",{className:"min-h-0 flex-1",children:jsxRuntime.jsx(Cr,{category:r.category,tags:r.tags,onSelect:e,onSelectOutcome:t})})]})}function mt(e,t,r){let n=e[t];return n?r==="yes"?n.yesMint:n.noMint:null}var Ce=utils.SOL_USDC_TOKEN_ADDRESS;function pa(){let e={startVelocity:30,spread:360,ticks:60,zIndex:9999};pt__default.default({...e,particleCount:80,origin:{x:.5,y:.4}}),setTimeout(()=>{pt__default.default({...e,particleCount:40,origin:{x:.3,y:.6}});},150),setTimeout(()=>{pt__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(),o=walletConnector.useWallet(types.Chain.SOLANA),l=i==="authenticated",a=o?.address,[c,d]=react.useState(r),[u,m]=react.useState(n),[p,y]=react.useState(NaN),x=react.useMemo(()=>mt(e.accounts,Ce,c),[e.accounts,c]),{inputMint:b,outputMint:g}=react.useMemo(()=>u==="buy"?{inputMint:Ce,outputMint:x}:{inputMint:x,outputMint:Ce},[u,x]),k=!!b&&!!g&&p>0,h=react.useMemo(()=>Number(c==="yes"?e.yesAsk??.5:e.noAsk??.5),[c,e.yesAsk,e.noAsk]),f=react.useMemo(()=>isNaN(p)||p<=0?0:u==="buy"?h>0?p/h:0:p,[u,p,h]),C=react.useMemo(()=>isNaN(p)||p<=0?0:Math.round(p*1e6),[p]),{data:S,isLoading:j,error:Y,refetch:P}=zt({userPublicKey:a??void 0,inputMint:b??"",outputMint:g??"",amount:C,slippageBps:100},{enabled:k}),{data:T,isLoading:W,refetch:Ot}=client.useWalletPortfoliosQuery({chain:types.Chain.SOLANA,address:a??""},{enabled:l&&!!a,refetchInterval:1e4}),Ie=react.useMemo(()=>{if(!T?.portfolios)return null;let R=T.portfolios.find(X=>X.address===Ce);return R?parseFloat(R.amount):0},[T]),Qe=react.useMemo(()=>{if(!T?.portfolios||!x)return null;let R=T.portfolios.find(X=>X.address===x);return R?parseFloat(R.amount):0},[T,x]),Ye=react.useMemo(()=>mt(e.accounts,Ce,"yes"),[e.accounts]),je=react.useMemo(()=>mt(e.accounts,Ce,"no"),[e.accounts]),En=react.useMemo(()=>{if(!T?.portfolios||!Ye)return null;let R=T.portfolios.find(X=>X.address===Ye);return R?parseFloat(R.amount):0},[T,Ye]),On=react.useMemo(()=>{if(!T?.portfolios||!je)return null;let R=T.portfolios.find(X=>X.address===je);return R?parseFloat(R.amount):0},[T,je]),{data:ve}=he(e.ticker,{refetchInterval:5e3}),In=react.useMemo(()=>(c==="yes"?ve?.yesBids:ve?.noBids)?.[0]?.price??null,[ve,c]),Qn=react.useMemo(()=>(c==="yes"?ve?.yesAsks:ve?.noAsks)?.[0]?.price??null,[ve,c]),Bn=react.useMemo(()=>S?.priceImpactPct?parseFloat(S.priceImpactPct):null,[S]),Be=react.useMemo(()=>{if(isNaN(p)||p<=0)return 0;if(S)return parseInt(S.inAmount)/1e6;if(u==="buy")return p;let R=Number(c==="yes"?e.yesBid??0:e.noBid??0);return p*R},[S,u,c,p,e.yesBid,e.noBid]),It=react.useMemo(()=>isNaN(p)||p<=0?0:u==="buy"?f*1:Be,[u,f,Be,p]),Ln=It-Be,Un=react.useCallback(R=>{m(R),y(NaN);},[]),Dn=react.useCallback(R=>{if(isNaN(R)){y(NaN);return}let X=Math.max(0,R),Je=u==="buy"?Math.round(X*100)/100:Math.round(X);y(Je);},[u]);react.useEffect(()=>{k&&P();},[p,c,u,k,P]);let Xe=react.useMemo(()=>{let R=[];return (isNaN(p)||p<lt)&&R.push(`Minimum quantity is ${lt}`),e.status!=="active"&&R.push("Market is not active"),u==="buy"&&Ie!=null&&!isNaN(p)&&p>0&&p>Ie&&R.push("Insufficient USDC balance"),u==="sell"&&Qe!=null&&!isNaN(p)&&p>0&&p>Qe&&R.push("Insufficient shares"),{isValid:R.length===0,errors:R}},[p,e.status,u,Ie,Qe]),[An,Ze]=react.useState(null),[_n,Qt]=react.useState(false),Fn=react.useCallback(async()=>{if(!(!Xe.isValid||!l||!a||!o||W)){Ze(null),Qt(true);try{let R=S;if(R?.transaction||(R=(await P()).data),!R?.transaction)return;let X=Uint8Array.from(atob(R.transaction),Bt=>Bt.charCodeAt(0)),Je=await o.sendTransaction(X);Ze(Je),ui.toast.success(s("predict.trade.submitSuccess")),pa(),y(NaN),Ot();}catch{ui.toast.error(s("predict.trade.submitError"));}finally{Qt(false);}}},[Xe.isValid,l,a,o,S,W,P,Ot,s]),Wn=react.useCallback(()=>{d(r),m(n),y(NaN),Ze(null);},[r,n]);return {outcome:c,side:u,quantity:p,shares:f,estimatedCost:Be,potentialPayout:It,potentialProfit:Ln,isAuthenticated:l,bestBid:In,bestAsk:Qn,order:S??null,priceImpact:Bn,usdcBalance:Ie,outcomeTokenBalance:Qe,yesTokenBalance:En,noTokenBalance:On,isBalanceLoading:W,isQuoteLoading:j,isSubmitting:_n,quoteError:Y??null,txHash:An,validation:Xe,setOutcome:d,setSide:Un,setQuantity:Dn,submit:Fn,reset:Wn}}var ba=`https://s1.chainstream.io/chains/sol/tokens/${utils.SOL_USDC_TOKEN_ADDRESS}/image.png`;function Er({event:e,market:t,outcome:r,side:n,quantity:s,potentialProfit:i,estimatedCost:o,usdcBalance:l,yesTokenBalance:a,noTokenBalance:c,isBalanceLoading:d,isSubmitting:u,isValid:m,onOutcomeChange:p,onSideChange:y,onQuantityChange:x,onSubmit:b}){let{t:g}=i18n.useTranslation(),k=react.useMemo(()=>{if(u)return g("predict.trade.submitting");let f=g(n==="buy"?"predict.trade.buy":"predict.trade.sell"),C=g(r==="yes"?"predict.trade.yes":"predict.trade.no");return `${f} ${C}`},[u,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:f=>y(f),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(f=>{let C=f==="yes"?a:c;return jsxRuntime.jsxs("div",{className:"flex flex-1 flex-col gap-y-1",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>p(f),className:`w-full rounded-lg border py-2 text-sm font-medium transition-colors cursor-pointer ${r===f?f==="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(f==="yes"?"predict.trade.yes":"predict.trade.no")}),(()=>{let S=n==="buy"?f==="yes"?t.yesAsk:t.noAsk:f==="yes"?t.yesBid:t.noBid;return S!=null?jsxRuntime.jsxs("span",{className:"ml-1 opacity-70",children:[Math.round(Number(S)*100),"\xA2"]}):null})()]}),n==="sell"&&r===f&&jsxRuntime.jsx("span",{className:"text-center text-xs text-foreground",children:d?"\u2013":`${C??0} shares`})]},f)})}),n==="buy"&&jsxRuntime.jsxs("div",{className:"flex items-center justify-end gap-x-1 text-xs text-default-500",children:[jsxRuntime.jsx("img",{src:ba,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:f=>{x(f);},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(f=>jsxRuntime.jsxs("button",{type:"button",onClick:()=>x(Math.round(((isNaN(s)?0:s)+f)*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:["+",f,"$"]},f)),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(f=>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:[f,"%"]},f)),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:!m||u,isLoading:u,onPress:b,children:k})]})}function yt({event:e,market:t,initialSide:r,initialOutcome:n,chain:s}){let{outcome:i,side:o,quantity:l,estimatedCost:a,potentialPayout:c,potentialProfit:d,usdcBalance:u,yesTokenBalance:m,noTokenBalance:p,isBalanceLoading:y,isSubmitting:x,validation:b,setOutcome:g,setSide:k,setQuantity:h,submit:f}=Rr({market:t,initialSide:r,initialOutcome:n,chain:s}),C=walletConnector.useAuthCallback(f);return jsxRuntime.jsx(Er,{event:e,market:t,outcome:i,side:o,quantity:l,estimatedCost:a,potentialPayout:c,potentialProfit:d,usdcBalance:u,yesTokenBalance:m,noTokenBalance:p,isBalanceLoading:y,isSubmitting:x,isValid:b.isValid,validationErrors:b.errors,onOutcomeChange:g,onSideChange:k,onQuantityChange:h,onSubmit:C})}function ha(){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(ha,{},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:c}=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(f=>f.openTime)):i},[i,s,l?.markets]),{data:u,isLoading:m,error:p}=Ht(l?.seriesTicker??"",{enabled:!!l?.seriesTicker}),y=react.useMemo(()=>l?.markets?(t&&t.length>0?t.slice(0,4).map(f=>l.markets.find(C=>C.ticker===f)).filter(f=>f!==void 0):[...l.markets].sort((f,C)=>Number(C.yesAsk??0)-Number(f.yesAsk??0)).slice(0,4)).map(f=>f.ticker):[],[t,l?.markets]),x=reactQuery.useQueries({queries:y.map(h=>({queryKey:rt({ticker:h,startTs:d,endTs:i,periodInterval:n}),queryFn:()=>nt(o,{ticker:h,startTs:d,endTs:i,periodInterval:n}),enabled:y.length>0}))}),b=x.some(h=>h.isLoading),g=react.useMemo(()=>{let h=new Map;return y.forEach((f,C)=>{let S=x[C]?.error;S&&h.set(f,S);}),h},[y,x]),k=react.useMemo(()=>{let h=new Map;return y.forEach((f,C)=>{let S=x[C]?.data;S&&h.set(f,S);}),h},[y,x]);return {event:l,isEventLoading:a,eventError:c,series:u,isSeriesLoading:m,seriesError:p,periodInterval:n,candlesticks:k,isCandlesticksLoading:b,candlestickErrors:g}};var Ta=utils.SOL_USDC_TOKEN_ADDRESS;function Br(e){let{status:t}=walletConnector.useAuth(),r=walletConnector.useWallet(types.Chain.SOLANA),n=t==="authenticated",s=r?.address,{data:i,isLoading:o}=client.useWalletPortfoliosQuery({chain:types.Chain.SOLANA,address:s??""},{enabled:n&&!!s,refetchInterval:1e4});return {holdings:react.useMemo(()=>{let a=new Map;if(!i?.portfolios||e.length===0)return a;let c=new Map;for(let d of i.portfolios)c.set(d.address,parseFloat(d.amount));for(let d of e){let u=d.accounts[Ta];if(!u)continue;let m=c.get(u.yesMint)??0,p=c.get(u.noMint)??0;(m>0||p>0)&&a.set(d.ticker,{yesShares:m,noShares:p});}return a},[i,e]),isLoading:o}}function Aa(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 Lr(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 _a(e,t,r){let n=Fe[r],s=new Map;e.forEach((a,c)=>{let d=new Map;(a.candlesticks??[]).forEach(m=>{let p=m.end_period_ts-m.end_period_ts%n;d.set(p,m.yes_ask.close);}),s.set(c,d);});let i=new Set;for(let a of s.values())for(let c of a.keys())i.add(c);let o=Array.from(i).sort((a,c)=>a-c),l=new Map;return o.map(a=>{let d={date:new Date(a*1e3).toLocaleDateString("en-US",{month:"short",day:"numeric"}),timestamp:a};return t.forEach(u=>{let m=s.get(u)?.get(a);if(m!==void 0)d[u]=Math.round(m*100)/100,l.set(u,d[u]);else {let p=l.get(u);p!==void 0&&(d[u]=p);}}),d})}function Ur({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]),c=react.useMemo(()=>!e||e.size===0?[]:_a(e,a,n),[e,a,n]),d=react.useMemo(()=>{if(c.length===0||a.length===0)return [0,100];let y=1/0,x=-1/0;if(c.forEach(f=>{a.forEach(C=>{let S=f[C];S!==void 0&&(y=Math.min(y,S),x=Math.max(x,S));});}),y===1/0||x===-1/0)return [0,100];let b=x-y,g=Math.max(b*.2,5),k=Math.max(0,Math.floor(y-g)),h=Math.min(100,Math.ceil(x+g));return [k,h]},[c,a]),u=react.useCallback(y=>{if(c.length===0)return null;let x=y!==null?c[y]:c[c.length-1];return x?{timestamp:x.timestamp,date:x.date,markets:a.map((b,g)=>{let k=t.find(h=>h.ticker===b);return {id:b,label:k?.yesSubTitle||`Market ${g+1}`,value:x[b]??0,color:Ke[g%Ke.length].stroke}})}:null},[c,a,t]);react.useEffect(()=>{l.current&&c.length>0&&l.current(u(null));},[c,u]),react.useEffect(()=>{l.current&&l.current(u(i));},[i,u]);let m=react.useCallback(y=>{typeof y?.activeTooltipIndex=="number"&&o(y.activeTooltipIndex);},[]),p=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:m,onMouseLeave:p,children:[jsxRuntime.jsx(recharts.XAxis,{dataKey:"timestamp",tick:y=>{let{x,y:b,payload:g,index:k}=y,h=c.length,C=Math.max(1,Math.ceil(h/6)),S=k===0,j=k===h-1,Y=k%C===0;return !S&&!j&&!Y?null:jsxRuntime.jsx("text",{x,y:b+10,textAnchor:"middle",fill:"hsl(var(--heroui-default-500))",fontSize:10,children:Lr(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:y=>`${y}%`,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:y=>Lr(y,n),formatter:(y,x)=>{let g=t.find(k=>k.ticker===x)?.yesSubTitle||x;return [`${y.toFixed(2)}%`,g]}}),a.map((y,x)=>jsxRuntime.jsx(recharts.Line,{type:"monotone",dataKey:y,stroke:Ke[x%Ke.length].stroke,strokeWidth:2,isAnimationActive:false,dot:b=>jsxRuntime.jsx(Aa,{...b,dataLength:c.length},`dot-${y}-${b.index}`),activeDot:false},y))]})})})}function Dr(){return {timestamp:Date.now()/1e3,date:new Date().toLocaleDateString("en-US",{month:"short",day:"numeric"}),markets:[]}}function _r({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:c,error:d}=st({ticker:e,startTs:o,endTs:i,periodInterval:n},{enabled:!!e});return {candlesticks:l,isLoading:a,isFetching:c,error:d,periodInterval:n}}var za="hsl(var(--heroui-primary))",Ga=[{value:w.ONE_DAY,label:"1D"},{value:w.ONE_WEEK,label:"1W"},{value:w.ONE_MONTH,label:"1M"},{value:w.ALL,label:"ALL"}];function Ya(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 Wr(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 Xa(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 qr({candlesticks:e,isLoading:t,chartRange:r,onRangeChange:n}){let s=react.useMemo(()=>e?Xa(e,r):[],[e,r]),i=react.useMemo(()=>{if(s.length===0)return [0,100];let o=1/0,l=-1/0;for(let m of s)m.value<o&&(o=m.value),m.value>l&&(l=m.value);if(o===1/0||l===-1/0)return [0,100];let a=l-o,c=Math.max(a*.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(vt,{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(vt,{chartRange:r,onRangeChange:n})]}):jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-2",children:[jsxRuntime.jsx("div",{className:"h-[200px] w-full",children:jsxRuntime.jsx(recharts.ResponsiveContainer,{width:"100%",height:"100%",children:jsxRuntime.jsxs(recharts.LineChart,{data:s,margin:{top:10,right:16,left:16,bottom:0},children:[jsxRuntime.jsx(recharts.XAxis,{dataKey:"timestamp",tick:o=>{let{x:l,y:a,payload:c,index:d}=o,u=s.length,p=Math.max(1,Math.ceil(u/6)),y=d===0,x=d===u-1,b=d%p===0;return !y&&!x&&!b?null:jsxRuntime.jsx("text",{x:l,y:a+10,textAnchor:"middle",fill:"hsl(var(--heroui-default-500))",fontSize:10,children:Wr(c.value,r)})},tickLine:false,axisLine:false,interval:0}),jsxRuntime.jsx(recharts.CartesianGrid,{horizontal:true,vertical:false,strokeDasharray:"3 3",stroke:"hsl(var(--heroui-default-200))"}),jsxRuntime.jsx(recharts.YAxis,{domain:i,tickLine:false,axisLine:false,tick:{fontSize:10,fill:"hsl(var(--heroui-default-500))"},tickFormatter:o=>`${o}%`,width:40}),jsxRuntime.jsx(recharts.Tooltip,{cursor:{stroke:"hsl(var(--heroui-default-300))"},content:({active:o,payload:l})=>{if(!o||!l?.length)return null;let a=l[0].payload,c=Math.round(a.value);return jsxRuntime.jsxs("div",{className:"rounded-lg border border-default-200 bg-content1 px-3 py-2 shadow-md",children:[jsxRuntime.jsxs("div",{className:"text-lg font-semibold text-primary",children:["Yes ",c,"\xA2"]}),jsxRuntime.jsxs("div",{className:"text-sm text-neutral",children:["Vol ",ja(a.volume)," \xB7"," ",Wr(a.timestamp,r)]})]})}}),jsxRuntime.jsx(recharts.Line,{type:"monotone",dataKey:"value",stroke:za,strokeWidth:2,isAnimationActive:false,dot:o=>jsxRuntime.jsx(Ya,{...o,dataLength:s.length},`dot-${o.index}`),activeDot:false})]})})}),jsxRuntime.jsx(vt,{chartRange:r,onRangeChange:n})]})}function vt({chartRange:e,onRangeChange:t}){return jsxRuntime.jsx("div",{className:"flex items-center justify-end gap-x-1",children:Ga.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 Hr({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 Kr(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 $r(e,t){for(let r of e)r.depth=t>0?r.cumulative/t:0;}function Yr(e){return `${Math.round(e*100)}\xA2`}function ei(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function ti(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 Vr({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:Yr(e.price)}),jsxRuntime.jsx("span",{className:"relative z-10 font-mono text-foreground text-right",children:ei(e.quantity)}),jsxRuntime.jsx("span",{className:"relative z-10 font-mono text-foreground text-right",children:ti(e.total)})]})}function zr({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 ri(){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:kt}).map((e,t)=>jsxRuntime.jsx(zr,{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:kt}).map((e,t)=>jsxRuntime.jsx(zr,{index:t+3},`bid-${t}`))]})}var kt=8;function ht({bids:e,asks:t,isLoading:r=false,maxLevels:n=kt,onPriceClick:s}){let{t:i}=i18n.useTranslation(),{bidRows:o,askRows:l,spread:a,spreadPercent:c}=react.useMemo(()=>{let u=Kr(e,n),m=Kr(t,n),p=Math.max(u[u.length-1]?.cumulative??0,m[m.length-1]?.cumulative??0);$r(u,p),$r(m,p);let y=u[0]?.price??null,x=m[0]?.price??null,b=null,g=null;if(y!=null&&x!=null){b=x-y;let k=(y+x)/2;k>0&&(g=Math.round(b/k*1e4)/100);}return {bidRows:u,askRows:m,spread:b,spreadPercent:g}},[e,t,n]);return r?jsxRuntime.jsx(ri,{}):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((u,m)=>jsxRuntime.jsx(Vr,{row:u,side:"ask",showType:m===0,onClick:s},u.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"),": ",Yr(a)]}),c!=null&&jsxRuntime.jsxs("span",{className:"text-default-400",children:["(",c,"%)"]})]}),jsxRuntime.jsx("div",{className:"flex flex-col",children:o.map((u,m)=>jsxRuntime.jsx(Vr,{row:u,side:"bid",showType:m===0,onClick:s},u.price))})]})}function Zr({market:e,onTradeAction:t}){let{t:r}=i18n.useTranslation(),[n,s]=react.useState("trade-yes"),[i,o]=react.useState(ce),{orderbook:l,isOrderbookLoading:a}=Hr({marketTicker:e.ticker}),{candlesticks:c,isFetching:d}=_r({marketTicker:e.ticker,openTime:e.openTime,chartRange:i}),u=react.useCallback((p,y)=>{t?.(e,"yes",y==="ask"?"buy":"sell");},[e,t]),m=react.useCallback((p,y)=>{t?.(e,"no",y==="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:p=>s(p),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(ht,{bids:l?.yesBids??[],asks:l?.yesAsks??[],isLoading:a,onPriceClick:u}),n==="trade-no"&&jsxRuntime.jsx(ht,{bids:l?.noBids??[],asks:l?.noAsks??[],isLoading:a,onPriceClick:m}),n==="graph"&&jsxRuntime.jsx(qr,{candlesticks:c,isLoading:d,chartRange:i,onRangeChange:o})]})]})}var St=4;function ai(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 on({markets:e,renderMarketDetail:t,onTradeAction:r,marketHoldings:n}){let{t:s}=i18n.useTranslation(),[i,o]=react.useState(false),[l,a]=react.useState(null);if(e.length===0)return null;let c=e.length>St,d=i?e:e.slice(0,St),u=m=>{a(p=>p===m?null:m);};return jsxRuntime.jsxs("div",{className:"flex flex-col divide-y divide-default-200",children:[d.map(m=>{let{yesCents:p,noCents:y}=ai(m),x=l===m.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(m.ticker),role:"button",tabIndex:0,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),u(m.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:m.yesSubTitle}),(()=>{let b=n?.get(m.ticker);if(!b)return null;let{yesShares:g,noShares:k}=b;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 b=p!=null,g=y!=null;return b&&!g&&p<=1?jsxRuntime.jsx("span",{className:"text-lg font-bold shrink-0 text-center text-default-400 lg:text-xl",children:"< 1%"}):g&&!b&&y<=1?jsxRuntime.jsx("span",{className:"text-lg font-bold shrink-0 text-center text-default-400 lg:text-xl",children:"> 99%"}):!b&&!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:`${p}%`})})(),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?.(m,"yes","buy"),children:p!=null?s("predict.market.action.yes",{price:p}):s("predict.market.yes")}),jsxRuntime.jsx(ui.Button,{size:"sm",color:"secondary",className:"w-20 bg-secondary-100 text-secondary",onPress:()=>r?.(m,"no","buy"),children:y!=null?s("predict.market.action.no",{price:y}):s("predict.market.no")})]}),x?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"})]}),x&&t&&jsxRuntime.jsx("div",{className:"max-h-100 overflow-y-auto px-2 pb-3",children:t(m)})]},m.ticker)}),c&&jsxRuntime.jsx("button",{type:"button",onClick:()=>o(m=>!m),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-St})}),jsxRuntime.jsx(ui.ChevronDownIcon,{className:"h-4 w-4"})]})})]})}var di=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 pi({market:e}){let t=di.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 ln({markets:e,event:t,series:r}){let{t:n}=i18n.useTranslation(),[s,i]=react.useState(null),o=e.filter(a=>a.rulesPrimary);if(o.length===0)return null;let l=o.find(a=>a.ticker===s)??o[0];return l?.rulesPrimary?jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-2",children:[jsxRuntime.jsx("span",{className:"text-sm font-medium lg:text-base",children:n("predict.event.rules")}),o.length>1&&jsxRuntime.jsx(ui.Select,{size:"sm","aria-label":"Select market rules",className:"max-w-48",classNames:{trigger:"min-h-8 h-8",value:"text-xs"},selectedKeys:new Set([l.ticker]),onSelectionChange:a=>{if(a==="all")return;let c=Array.from(a);c.length>0&&i(c[0]);},children:o.map(a=>jsxRuntime.jsx(ui.SelectItem,{textValue:a.yesSubTitle,children:jsxRuntime.jsx("span",{className:"text-xs truncate",children:a.yesSubTitle})},a.ticker))}),jsxRuntime.jsx("div",{className:"text-xs text-foreground lg:text-sm",children:l.rulesPrimary}),jsxRuntime.jsx("span",{className:"text-xs font-medium text-default-500 mt-2 lg:text-sm",children:"Timeline and payout"}),jsxRuntime.jsx(pi,{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 hi=[{value:w.ONE_DAY,label:"1D"},{value:w.ONE_WEEK,label:"1W"},{value:w.ONE_MONTH,label:"1M"},{value:w.ALL,label:"ALL"}];function un({event:e,series:t,candlesticks:r,chartRange:n=w.ONE_DAY,periodInterval:s,isCandlesticksLoading:i,onRangeChange:o,selectedMarketTickers:l,onMarketSelectionChange:a,onTradeAction:c}){let{t:d}=i18n.useTranslation(),[u,m]=react.useState(Dr()),[p,y]=react.useState(false),x=react.useRef(null);react.useEffect(()=>{let f=x.current;if(!f)return;let C=false,S=0,j=()=>{let{bottom:P}=f.getBoundingClientRect(),T=C?P<0:P<-20;T!==C&&(C=T,y(T));},Y=()=>{cancelAnimationFrame(S),S=requestAnimationFrame(j);};return window.addEventListener("scroll",Y,{passive:true,capture:true}),j(),()=>{cancelAnimationFrame(S),window.removeEventListener("scroll",Y,{capture:true});}},[]);let b=react.useMemo(()=>[...e.markets||[]].sort((f,C)=>Number(C.yesAsk??0)-Number(f.yesAsk??0)),[e.markets]),{holdings:g}=Br(b),k=react.useMemo(()=>utils.formatAmountUSD3((e.volume??0)/100),[e.volume]),h=react.useMemo(()=>{if(!e.strikeDate)return null;let f=new Date(e.strikeDate*1e3),C=f.toLocaleString("default",{month:"short"}),S=f.getDate(),j=f.getFullYear();return `${C} ${S}, ${j}`},[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:x,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 ${p?"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 ${p?"!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:[!p&&(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 ${p?"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(f=>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:f.color}}),jsxRuntime.jsx("span",{className:"text-default-600",children:f.label})]},f.id))}),jsxRuntime.jsx(Ur,{candlesticks:r,chartRange:n,markets:b,isLoading:i,onDataChange:f=>m(f)}),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:hi.map(f=>jsxRuntime.jsx("button",{type:"button",onClick:()=>o?.(f.value),className:`px-2 lg:px-3 py-1 text-xs rounded-md transition-colors cursor-pointer ${n===f.value?"bg-primary text-primary-foreground":"bg-default-100 text-default-600 hover:bg-default-200"}`,children:f.label},f.value))}),b.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:f=>{if(f==="all")return;let C=Array.from(f);C.length<=4&&a?.(C);},children:jsxRuntime.jsx(ui.SelectSection,{title:`Pick up to ${4} markets`,classNames:{heading:"text-xs text-default-400 px-2 py-1"},children:b.map(f=>jsxRuntime.jsx(ui.SelectItem,{textValue:f.yesSubTitle,children:jsxRuntime.jsx("span",{className:"text-xs truncate",children:f.yesSubTitle})},f.ticker))})})]})]})}),jsxRuntime.jsx(on,{markets:b,onTradeAction:c,marketHoldings:g,renderMarketDetail:f=>jsxRuntime.jsx(Zr,{market:f,onTradeAction:c})}),jsxRuntime.jsx(ln,{markets:b,event:e,series:t})]})}function Mt({eventId:e,initialMarketTickers:t,initialChartRange:r=ce,onTradeAction:n}){let[s,i]=react.useState(r),[o,l]=react.useState(t),{event:a,isEventLoading:c,eventError:d,series:u,isSeriesLoading:m,periodInterval:p,candlesticks:y,isCandlesticksLoading:x,candlestickErrors:b}=Ir({eventId:e,candlestickMarketTickers:o,chartRange:s}),g=react.useRef(!!t);react.useEffect(()=>{if(a?.markets&&!g.current){g.current=true;let f=[...a.markets].sort((C,S)=>Number(S.yesAsk??0)-Number(C.yesAsk??0)).slice(0,4).map(C=>C.ticker);l(f);}},[a?.markets]);let k=react.useMemo(()=>f=>{i(f);},[]),h=react.useMemo(()=>f=>{l(f);},[]);return c||m?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(un,{event:a,series:u,candlesticks:y,chartRange:s,periodInterval:p,isCandlesticksLoading:x,candlestickErrors:b,onRangeChange:k,selectedMarketTickers:o,onMarketSelectionChange:h,onTradeAction:n})}function Sy({eventId:e,chain:t,...r}){let{t:n}=i18n.useTranslation(),{isMobile:s}=ui.useScreen(),{isOpen:i,onOpen:o,onClose:l}=ui.useDisclosure(),{data:a,isLoading:c}=Le({id:e,withNestedMarkets:true}),d=react.useMemo(()=>[...a?.markets||[]].sort((b,g)=>Number(g.yesAsk??0)-Number(b.yesAsk??0)),[a?.markets]),[u,m]=react.useState(null),p=react.useCallback((b,g,k)=>{m(h=>({market:b,outcome:g,side:k,version:(h?.version??0)+1})),s&&o();},[s,o]),y=u?.market??d[0];if(c)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 x=u?`${u.market.ticker}-${u.version}`:y?.ticker??"default";return s?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"w-full pb-20",children:jsxRuntime.jsx(Mt,{eventId:e,onTradeAction:p,...r})}),y&&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:y&&jsxRuntime.jsx(yt,{event:a,market:y,initialSide:u?.side,initialOutcome:u?.outcome,chain:t},x)})})})]}):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(Mt,{eventId:e,onTradeAction:p,...r})}),y&&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(yt,{event:a,market:y,initialSide:u?.side,initialOutcome:u?.outcome,chain:t},x)})})]})}function mn(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 yn({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]),c=react.useMemo(()=>mn(l,t),[l,t]),d=react.useMemo(()=>mn(a,t),[a,t]),u=react.useMemo(()=>c.length===0||d.length===0?null:d[0].price-c[0].price,[c,d]),m=react.useMemo(()=>c.length===0||d.length===0?null:(c[0].price+d[0].price)/2,[c,d]),p=react.useMemo(()=>u===null||m===null||m===0?null:Math.round(u/m*1e4)/100,[u,m]);return {bids:c,asks:d,spread:u,spreadPercent:p,midpoint:m,isLoading:i,isFetching:o}}function fn({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 gn(){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 xn({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(gn,{}),jsxRuntime.jsx(gn,{})]});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(fn,{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(fn,{row:a,side:"bid",onClick:i},a.price))})]})]})}function Vy({marketTicker:e,maxLevels:t,refetchInterval:r,onPriceClick:n,outcome:s}){let{bids:i,asks:o,spread:l,spreadPercent:a,isLoading:c}=yn({marketTicker:e,maxLevels:t,refetchInterval:r,outcome:s});return jsxRuntime.jsx(xn,{bids:i,asks:o,spread:l,spreadPercent:a,isLoading:c,onPriceClick:n})}function vn(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 zi(e){return new Date(e).toLocaleString("default",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function kn({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:zi(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 cf({refetchInterval:e}={}){let{orders:t,isLoading:r,cancellingOrderId:n,cancelOrder:s}=vn({});return jsxRuntime.jsx(kn,{orders:t,isLoading:r,cancellingOrderId:n,onCancel:s})}function Pn({ticker:e,pageSize:t=48}={}){let[r,n]=react.useState(1),[s,i]=react.useState([void 0]),o=s[r-1],l=react.useMemo(()=>({...e?{ticker:e}:{},limit:t,...o?{cursor:o}:{}}),[e,t,o]),{data:a,isLoading:c,isFetching:d}=_t(l),u=a,m=u?.trades??[],p=!!u?.cursor,y=r>1,x=react.useCallback(k=>{k>=1&&k<=s.length&&n(k);},[s.length]),b=react.useCallback(()=>{p&&u?.cursor&&(i(k=>{let h=[...k];return h.length===r&&h.push(u.cursor),h}),n(k=>k+1));},[p,u?.cursor,r]),g=react.useCallback(()=>{y&&n(k=>k-1);},[y]);return {trades:m,isLoading:c,isFetching:d,page:r,pageSize:t,hasNextPage:p,hasPrevPage:y,goToPage:x,nextPage:b,prevPage:g}}function sl(e){return new Date(e*1e3).toLocaleString("default",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function Sn({trades:e,isLoading:t,isFetching:r,page:n,hasNextPage:s,hasPrevPage:i,onNextPage:o,onPrevPage:l}){let{t:a}=i18n.useTranslation(),c=react.useMemo(()=>e.map(d=>({key:d.tradeId,ticker:d.ticker,takerSide:d.takerSide,price:d.price,yesPrice:d.yesPrice,noPrice:d.noPrice,count:d.count,createdAt:sl(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,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:a("predict.tradeHistory.title")}),e.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8 text-xs text-default-400",children:a("predict.tradeHistory.empty")}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:`w-full overflow-x-auto ${r?"opacity-60":""}`,children:jsxRuntime.jsxs(ui.StyledTable,{radius:"none","aria-label":"Trade history",className:"min-w-[480px]",children:[jsxRuntime.jsxs(ui.TableHeader,{children:[jsxRuntime.jsx(ui.TableColumn,{textValue:"Side",width:60,children:a("predict.tradeHistory.side")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Price",width:80,children:a("predict.tradeHistory.price")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Yes",width:60,children:a("predict.trade.yes")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"No",width:60,children:a("predict.trade.no")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Qty",width:60,children:a("predict.tradeHistory.qty")}),jsxRuntime.jsx(ui.TableColumn,{textValue:"Time",width:120,children:a("predict.tradeHistory.time")})]}),jsxRuntime.jsx(ui.TableBody,{children:c.map(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 Mf({ticker:e,pageSize:t}={}){let{trades:r,isLoading:n,isFetching:s,page:i,hasNextPage:o,hasPrevPage:l,nextPage:a,prevPage:c}=Pn({ticker:e,pageSize:t});return jsxRuntime.jsx(Sn,{trades:r,isLoading:n,isFetching:s,page:i,hasNextPage:o,hasPrevPage:l,onNextPage:a,onPrevPage:c})}function wn(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.formatAmountUSD3(e/100);function Et({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 Rn({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(Et,{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(Et,{value:r.totalUnrealizedPnl})]}),jsxRuntime.jsxs("span",{className:"text-default-500",children:[s("predict.positions.realizedPnl"),":"," ",jsxRuntime.jsx(Et,{value:r.totalRealizedPnl})]})]})]})]})]})}function Kf({refetchInterval:e,onSell:t}={}){let{positions:r,isLoading:n,summary:s}=wn({});return jsxRuntime.jsx(Rn,{positions:r,isLoading:n,summary:s,onSell:t})}function pg({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 Mn(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 Tn(e){return e}var Oe=class{constructor(t,r){this.endpoint=t;this.provider=r;}buildUrl(t,r){let n=Mn(r??{},this.provider);return `${this.endpoint}${t}${n}`}async fetch(t,r){let n=this.buildUrl(t,r);return await utils.get(n)}async postRequest(t,r,n){let s=this.buildUrl(t,n);return await utils.post(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 Nn(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 Nn(r)}async getOrderbookByMint(t){let r=await this.fetch(`/v2/orderbook/by-mint/${t}`);return Nn(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
2
  exports.BasePredictClient=Oe;exports.CHART_RANGE_DURATION=We;exports.CHART_RANGE_PERIOD=_e;exports.CHART_RANGE_SAMPLE_INTERVAL=Fe;exports.CandlestickPeriod=Ae;exports.CategoriesSkeleton=lr;exports.CategoriesUI=ir;exports.CategoriesWidget=pr;exports.ChartRange=w;exports.DEFAULT_CHART_RANGE=ce;exports.DEFAULT_PAGE_SIZE=fe;exports.DEFAULT_PRICE_HISTORY_INTERVAL=Ld;exports.DflowPredictClient=Ge;exports.DflowPredictWsClient=Me;exports.EventDetailPage=Sy;exports.EventDetailSkeleton=Ne;exports.EventDetailUI=un;exports.EventDetailWidget=Mt;exports.EventItemSkeleton=Io;exports.EventItemUI=br;exports.EventMarketDetailWidget=Zr;exports.EventsPage=fp;exports.EventsSkeleton=yr;exports.EventsUI=hr;exports.EventsWidget=Cr;exports.MAX_PRICE_HISTORY_MARKETS=le;exports.ORDER_MAX_PRICE=Bd;exports.ORDER_MIN_PRICE=Qd;exports.ORDER_MIN_QUANTITY=lt;exports.ORDER_PRICE_STEP=Id;exports.OpenOrdersUI=kn;exports.OpenOrdersWidget=cf;exports.OrderBookUI=xn;exports.OrderBookWidget=Vy;exports.PRICE_HISTORY_SAMPLE_INTERVAL=Ud;exports.PositionsUI=Rn;exports.PositionsWidget=Kf;exports.PredictClient=Ge;exports.PredictContext=ke;exports.PredictProvider=pg;exports.PredictWsClient=Me;exports.PriceHistoryInterval=Pe;exports.TradeFormSkeleton=Or;exports.TradeFormUI=Er;exports.TradeFormWidget=yt;exports.TradeHistoryUI=Sn;exports.TradeHistoryWidget=Mf;exports.buildQuery=Mn;exports.createDflowPredictWsClient=Ue;exports.createPredictWsClient=Ue;exports.createSwap=Xs;exports.createSwapInstructions=Zs;exports.eventByIdQueryKey=jn;exports.eventCandlesticksQueryKey=bs;exports.eventsInfiniteQueryKey=Gn;exports.eventsQueryKey=Vn;exports.fetchEventById=Xn;exports.fetchEventCandlesticks=vs;exports.fetchEvents=et;exports.fetchFiltersBySports=_s;exports.fetchForecastPercentileHistory=Cs;exports.fetchForecastPercentileHistoryByMint=ws;exports.fetchIntentQuote=ao;exports.fetchLiveData=Ms;exports.fetchLiveDataByEvent=Ns;exports.fetchLiveDataByMint=Os;exports.fetchMarketById=ns;exports.fetchMarketByMint=as;exports.fetchMarketCandlesticks=nt;exports.fetchMarketCandlesticksByMint=hs;exports.fetchMarkets=es;exports.fetchMarketsBatch=cs;exports.fetchOrder=eo;exports.fetchOrderBook=ds;exports.fetchOrderBookByMint=ms;exports.fetchOrderStatus=ro;exports.fetchOutcomeMints=Vs;exports.fetchQuote=js;exports.fetchSearch=qs;exports.fetchSeries=Qs;exports.fetchSeriesByTicker=Ls;exports.fetchTagsByCategories=Ds;exports.fetchTokens=po;exports.fetchTokensWithDecimals=yo;exports.fetchTrades=fs;exports.fetchTradesByMint=xs;exports.fetchVenues=xo;exports.filterOutcomeMints=zs;exports.filtersBySportsQueryKey=As;exports.forecastPercentileHistoryByMintQueryKey=Ss;exports.forecastPercentileHistoryQueryKey=Ps;exports.initPredictionMarket=co;exports.intentQuoteQueryKey=oo;exports.liveDataByEventQueryKey=Ts;exports.liveDataByMintQueryKey=Es;exports.liveDataQueryKey=Rs;exports.marketByIdQueryKey=rs;exports.marketByMintQueryKey=os;exports.marketCandlesticksByMintQueryKey=ks;exports.marketCandlesticksQueryKey=rt;exports.marketsBatchQueryKey=ls;exports.marketsQueryKey=Jn;exports.orderBookByMintQueryKey=ps;exports.orderBookQueryKey=us;exports.orderQueryKey=Js;exports.orderStatusQueryKey=to;exports.outcomeMintsQueryKey=$s;exports.quoteQueryKey=Ys;exports.searchQueryKey=Ws;exports.seriesByTickerQueryKey=Bs;exports.seriesQueryKey=Is;exports.submitIntentSwap=io;exports.tagsByCategoriesQueryKey=Us;exports.toRecord=Tn;exports.tokensQueryKey=uo;exports.tokensWithDecimalsQueryKey=mo;exports.tradesByMintQueryKey=gs;exports.tradesQueryKey=ys;exports.useCategoriesQuery=Lc;exports.useCreateSwapInstructionsMutation=Jc;exports.useCreateSwapMutation=Zc;exports.useEventByIdQuery=Le;exports.useEventCandlesticksQuery=yc;exports.useEventDetail=Ir;exports.useEvents=mr;exports.useEventsCategories=sr;exports.useEventsInfiniteQuery=Ut;exports.useEventsQuery=Ql;exports.useFilterOutcomeMintsMutation=Kc;exports.useFiltersBySportsQuery=Bc;exports.useForecastPercentileHistoryByMintQuery=hc;exports.useForecastPercentileHistoryQuery=kc;exports.useInitPredictionMarketMutation=pu;exports.useIntentQuoteQuery=iu;exports.useLiveDataByEventQuery=Rc;exports.useLiveDataByMintQuery=Mc;exports.useLiveDataQuery=wc;exports.useMarketByIdQuery=Gl;exports.useMarketByMintQuery=Zl;exports.useMarketCandlesticksByMintQuery=fc;exports.useMarketCandlesticksQuery=st;exports.useMarketsBatchQuery=rc;exports.useMarketsQuery=Kl;exports.useOpenOrders=vn;exports.useOrderBook=yn;exports.useOrderBookByMintQuery=ac;exports.useOrderBookQuery=he;exports.useOrderQuery=zt;exports.useOrderStatusQuery=nu;exports.useOrderbookSubscription=Fu;exports.useOutcomeMintsQuery=Hc;exports.usePositions=wn;exports.usePredictClient=v;exports.usePredictContext=Lt;exports.usePriceHistoryQuery=gc;exports.usePricesSubscription=Bu;exports.useQuoteQuery=Gc;exports.useSearchQuery=_c;exports.useSeriesByTickerQuery=Ht;exports.useSeriesQuery=qt;exports.useSubmitIntentSwapMutation=lu;exports.useTagsByCategoriesQuery=at;exports.useTokensQuery=gu;exports.useTokensWithDecimalsQuery=xu;exports.useTradeForm=Rr;exports.useTradeHistory=Pn;exports.useTradesByMintQuery=uc;exports.useTradesQuery=_t;exports.useTradesSubscription=Du;exports.useVenuesQuery=hu;exports.useWsClient=Ou;exports.useWsConnection=Mu;exports.venuesQueryKey=go;exports.version=qn;//# sourceMappingURL=index.js.map
3
3
  //# sourceMappingURL=index.js.map