@liberfi.io/ui-predict 0.1.90 → 0.1.92
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 +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -15
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {createContext,memo,useRef,useCallback,useState,useContext,useMemo,useEffect,Fragment as Fragment$1,Component}from'react';import {cn as cn$1,Skeleton,toast,useDisclosure,Tabs,Tab,StyledNumberInput,StyledSwitch,Select,SelectItem,ChevronDownIcon,Button,Modal,ModalContent,ModalHeader,ModalBody,ModalFooter,useScreen,StyledModal,RefreshIcon,TimerIcon,DropletIcon,ChartLineIcon,CalendarIcon,StyledBadge,FilterIcon,Linkable,Avatar,ChevronUpIcon,PolymarketIcon,KalshiIcon,Spinner,OrderbookTableIcon,OrderbookDepthIcon,Dropdown,DropdownTrigger,DropdownMenu,DropdownItem,ChevronRightIcon,ChevronLeftIcon,TrashIcon,Chip,StyledInput,XCloseIcon,Kbd,SearchIcon,EmptyIcon}from'@liberfi.io/ui';import {AsyncModal,useAsyncModal}from'@liberfi.io/ui-scaffold';import {useTranslation}from'@liberfi.io/i18n';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {useWallets,useAuth,useSwitchChain,useAuthCallback}from'@liberfi.io/wallet-connector';import {useQueryClient,useQueries}from'@tanstack/react-query';import Zt from'canvas-confetti';import {ChartRange,useBalance,usePredictClient,PolymarketContext,useDFlowQuote,usePositions,useDFlowSubmit,useOrder,buildCtfExchangeDomain,buildOrderMessage,CTF_ORDER_TYPES,buildSignedOrder,buildPolymarketL2Headers,resolveEventsParams,useInfiniteEvents,useInfiniteOrders,useCancelOrder,useInfiniteTrades,useOrderbook,useMarketHistory,useEvent,useSimilarEvents,candlesticksQueryKey,useSearchEvents}from'@liberfi.io/react-predict';export{PredictClient,PredictContext,PredictProvider,PredictWsClient,createPredictClient,createPredictWsClient,useBalance,useCancelOrder,useCandlesticks,useDFlowKYC,useDFlowQuote,useDFlowSubmit,useEvent,useEvents,useInfiniteEvents,useMarket,useMarketHistory,useMarketTrades,useOrder,useOrderbook,useOrders,usePositions,usePredictClient,usePriceHistory,useSearchEvents,useSimilarEvents,useTrades}from'@liberfi.io/react-predict';import {ChainNamespace,Chain}from'@liberfi.io/types';import {SOLANA_TOKENS,debounce}from'@liberfi.io/utils';import {List}from'react-window';import {useInfiniteLoader}from'react-window-infinite-loader';import {useResizeObserver,useScrollCollapse,useCallbackRef}from'@liberfi.io/hooks';import {ResponsiveContainer,LineChart,CartesianGrid,XAxis,YAxis,Tooltip,Line,ReferenceDot}from'recharts';import {useAtom}from'jotai';import {atomWithStorage}from'jotai/utils';typeof window<"u"&&(window.__LIBERFI_VERSION__=window.__LIBERFI_VERSION__||{},window.__LIBERFI_VERSION__["@liberfi.io/ui-predict"]="0.1.90");var Zo="0.1.90";var es={Weather:["Daily temperature","Snow and rain","Climate change","Natural disasters","Hurricanes"],Companies:["IPOs","Product launches","KPIs","Elon Musk","CEOs","Layoffs"],Crypto:["BTC","15 min","Hourly","ETH","SOL","DOGE","Pre-Market","XRP","BNB","HYPE"],Economics:["Growth","Fed","Inflation","Oil and energy","Employment","Housing","Jobs & Economy","Bankruptcy & Defaults","GDP","Global Central Banks"],Elections:["Primaries","International elections"],Entertainment:["Music","Movies","Music charts","Television","Awards","Video games","Oscars","Rotten Tomatoes"],Financials:["S&P","Nasdaq","Daily","Metals","Treasuries","Oil","EUR/USD","USD/JPY","WTI"],Mentions:["Politicians","Earnings","Entertainment"],Politics:["Trump","Congress","International","SCOTUS & courts","Local","Recurring","Iran","House"],Science:["AI","Energy","Space"],Social:null,Sports:["Soccer","Basketball","Baseball","Football","Hockey","Golf","Tennis","Motorsport","Esports","Boxing","MMA","Rugby","Lacrosse","Mentions","Chess","Cricket","Aussie Rules","Darts"],World:null},Hr=["Politics","Sports","Crypto","Economics","Financials","Elections","Entertainment","Companies","Science and Technology","Climate and Weather","Mentions","Social","World"],jt=(()=>{let e=t=>{let n=Hr.indexOf(t);return n===-1?Hr.length:n};return Object.entries(es).map(([t,n])=>({slug:t,label:t,tags:(n??[]).map(o=>({slug:o,label:o}))})).sort((t,n)=>e(t.slug)-e(n.slug))})();function Wr({categories:e,selectedCategory:t,selectedTag:n,activeTags:o,onCategorySelect:r,onTagSelect:i,trailing:s,pulsingTab:l="Trending",className:a}){let{t:c}=useTranslation(),d=useCallback(()=>{r(null);},[r]),p=c("predict.categories.trending");return jsxs("div",{className:cn$1("sticky top-0 z-30 flex w-full flex-col justify-between gap-2 px-4 py-1 lg:px-2 lg:py-1",a),children:[jsxs("div",{className:"flex w-full items-center gap-2",children:[jsx("div",{className:"hideScrollbar min-w-0 flex-1 overflow-x-auto overflow-y-hidden",children:jsxs("div",{className:"flex min-h-8 items-stretch gap-x-2 lg:min-h-9",children:[jsx(Ur,{label:p,isSelected:t===null,onPress:d,showPulse:p===l}),jsx(os,{}),e.map(u=>jsx(Ur,{label:u.category,isSelected:t===u.category,onPress:()=>r(u.category),badge:u.badge,showPulse:u.category===l},u.category))]})}),s&&jsx("div",{className:"flex-shrink-0",children:s})]}),t&&o.length>0&&jsx("div",{className:"hideScrollbar overflow-x-auto overflow-y-hidden flex items-center",children:jsxs("div",{className:"flex gap-x-1 pl-2 lg:w-full lg:gap-x-2",children:[jsx($r,{label:c("predict.categories.allMarkets"),isSelected:n===null,onPress:()=>i(null)}),o.map(u=>jsx($r,{label:u.label,icon:u.icon,isSelected:n===u.label,onPress:()=>i(u.label)},u.label))]})})]})}function Ur({label:e,isSelected:t,onPress:n,badge:o,showPulse:r}){return jsxs("button",{type:"button",onClick:n,className:cn$1("relative shrink-0 cursor-pointer whitespace-nowrap border-b p-1 text-base font-normal capitalize transition-colors",t?"border-primary/50 text-primary":"border-transparent text-neutral-500 hover:text-neutral-300"),children:[r?jsxs("span",{className:"flex items-center gap-x-1.5",children:[jsx("span",{className:"h-2 w-2 animate-pulse rounded-full bg-[rgb(240,68,56)]"}),jsx("span",{children:e})]}):e,o&&jsx("span",{className:"absolute -right-1 top-0 rounded bg-primary px-0.5 py-px text-[0.625rem] font-semibold leading-none text-neutral-950",children:o})]})}function os(){return jsx("span",{className:"flex items-center text-neutral-600","aria-hidden":"true",children:"|"})}function $r({label:e,icon:t,isSelected:n,onPress:o}){return jsxs("button",{type:"button",onClick:o,className:cn$1("flex shrink-0 items-center justify-center gap-x-1 min-w-14 rounded-2xl border px-2 py-1 text-sm font-medium uppercase transition-colors cursor-pointer",n?"border-transparent bg-primary text-black":"border-border/80 text-neutral-200 hover:bg-primary/10 hover:text-primary"),children:[t&&jsx("span",{className:cn$1("iconify size-4",t)}),e]})}function rd({count:e=6}){return jsx("div",{className:"flex w-full flex-col gap-2 px-4 py-1 lg:px-2 lg:py-1",children:jsx("div",{className:"flex min-h-8 items-center gap-x-2 lg:min-h-9",children:Array.from({length:e}).map((t,n)=>jsx(Skeleton,{className:"h-6 w-16 shrink-0 rounded"},n))})})}function ss(e){return e.map(t=>({category:t.label,tags:t.tags.map(n=>n.label)}))}function as(e){return e?e.tags.map(t=>({label:t.label,icon:t.icon})):[]}function Vr({onSelect:e,trailing:t,className:n}){let[o,r]=useState(null),[i,s]=useState(null),l=useCallback(u=>{r(u),s(null),e?.({categorySlug:u,tagSlug:null});},[e]),a=useCallback(u=>{s(u),e?.({categorySlug:o,tagSlug:u});},[o,e]),c=ss(jt),d=jt.find(u=>u.slug===o),p=as(d);return jsx(Wr,{categories:c,selectedCategory:o,selectedTag:i,activeTags:p,onCategorySelect:l,onTagSelect:a,trailing:t,className:n})}function Yr(e){return {title:e.title,imageUrl:e.image_url}}function qr(e){let t=e.outcomes[0],n=e.outcomes[1];return {question:e.question,yesAsk:t?.best_ask??t?.price,noAsk:n?.best_ask??n?.price,yesBid:t?.best_bid,noBid:n?.best_bid,yesSubTitle:t?.label??"Yes",noSubTitle:n?.label??"No"}}var Qe=48,Gt=4,xt={ONE_MINUTE:1,ONE_HOUR:60,ONE_DAY:1440},oe={ONE_DAY:"1d",ONE_WEEK:"1w",ONE_MONTH:"1m",ALL:"all"},ht=oe.ALL,ud={[oe.ONE_DAY]:xt.ONE_MINUTE,[oe.ONE_WEEK]:xt.ONE_HOUR,[oe.ONE_MONTH]:xt.ONE_HOUR,[oe.ALL]:xt.ONE_DAY},pd={[oe.ONE_DAY]:300,[oe.ONE_WEEK]:3600,[oe.ONE_MONTH]:10800,[oe.ALL]:1440*60},md={[oe.ONE_DAY]:1440*60,[oe.ONE_WEEK]:10080*60,[oe.ONE_MONTH]:720*60*60,[oe.ALL]:null},Xt=1,fd=1,gd=1,vd=99,Be={ONE_HOUR:"1h",SIX_HOURS:"6h",ONE_DAY:"1d",ONE_WEEK:"1w",MAX:"max"},xd=Be.ONE_WEEK,hd={[Be.ONE_HOUR]:60,[Be.SIX_HOURS]:60,[Be.ONE_DAY]:300,[Be.ONE_WEEK]:1800,[Be.MAX]:1800};var Xr=createContext(null);function Jt(){let e=useContext(Xr);if(!e)throw new Error("usePredictWallet must be used within a PredictWalletProvider");return e}var us=3e4;function ps({pollingInterval:e=us,enabled:t=true,children:n}){let o=useWallets(),r=useMemo(()=>o.find(m=>m.chainNamespace===ChainNamespace.SOLANA&&m.isConnected)?.address,[o]),i=useMemo(()=>o.find(m=>m.chainNamespace===ChainNamespace.EVM&&m.isConnected)?.address,[o]),{data:s,isLoading:l,error:a}=useBalance({source:"dflow",user:r??""},{enabled:t&&!!r,refetchInterval:e}),{data:c,isLoading:d,error:p}=useBalance({source:"polymarket",user:i??""},{enabled:t&&!!i,refetchInterval:e}),u=useMemo(()=>({solanaAddress:r,evmAddress:i,dflowUsdcBalance:s?Number(s.balance):0,polymarketUsdcBalance:c?Number(c.balance):0,isLoading:l||d,error:a??p??null}),[r,i,s,c,l,d,a,p]);return jsx(Xr.Provider,{value:u,children:n})}var Os={minutes:60,hours:3600,days:86400};function Is(e,t,n){let o=Math.floor(Date.now()/1e3);switch(e){case "5m":return o+300;case "1h":return o+3600;case "12h":return o+720*60;case "24h":return o+1440*60;case "eod":{let r=new Date;return r.setUTCHours(23,59,59,0),Math.floor(r.getTime()/1e3)}case "custom":return o+t*Os[n]}}function en(){let e={startVelocity:30,spread:360,ticks:60,zIndex:9999};Zt({...e,particleCount:80,origin:{x:.5,y:.4}}),setTimeout(()=>{Zt({...e,particleCount:40,origin:{x:.3,y:.6}});},150),setTimeout(()=>{Zt({...e,particleCount:40,origin:{x:.7,y:.6}});},300);}function tn({market:e,initialOutcome:t="yes",initialSide:n="buy"}){let{t:o}=useTranslation(),{status:r}=useAuth(),i=useWallets(),s=useSwitchChain(),l=usePredictClient(),a=useContext(PolymarketContext),c=useQueryClient(),d=e.source,p=d==="polymarket",u=i.find(N=>N.chainNamespace===ChainNamespace.SOLANA&&N.isConnected),m=i.find(N=>N.chainNamespace===ChainNamespace.EVM&&N.isConnected&&"switchChain"in N),f=r==="authenticated",g=u?.address,v=m?.address,[h,D]=useState(t),[T,M]=useState(n),[O,Z]=useState("market"),[R,ie]=useState(NaN),[K,fe]=useState(NaN),[Me,X]=useState(false),[Q,le]=useState(null),[he,be]=useState(false),[S,E]=useState(null),[I,y]=useState(false),[$,q]=useState("1h"),[z,Pe]=useState(30),[Re,Bt]=useState("minutes"),ye=null;try{let N=Jt();ye={dflowUsdcBalance:N.dflowUsdcBalance,polymarketUsdcBalance:N.polymarketUsdcBalance,isLoading:N.isLoading};}catch{}let ne=useMemo(()=>{let N=h==="yes"?0:1,B=e.outcomes[N];return T==="buy"?B?.best_ask??B?.price??.5:B?.best_bid??B?.price??.5},[e.outcomes,h,T]),Ht=useCallback(N=>{Z(N);},[]),Ut=useCallback(N=>{D(N),fe(NaN);},[]);useEffect(()=>{O==="limit"&&isNaN(K)&&fe(Math.round(ne*100)/100);},[O,K,ne]);let je=useMemo(()=>isNaN(R)||R<=0?0:T==="buy"?ne>0?R/ne:0:R,[T,R,ne]),Fe=useMemo(()=>isNaN(R)||R<=0?"0":String(Math.round(R*1e6)),[R]),C=e.provider_meta?.["dflow.yesMint"]??"",ce=e.provider_meta?.["dflow.noMint"]??"",Le=e.provider_meta?.["dflow.collateralMint"]||SOLANA_TOKENS.stablecoins.USDC.address,Rr=h==="yes"?C:ce,Ge=T==="buy"?Le:Rr,Xe=T==="buy"?Rr:Le,Ao=d==="dflow"&&!!Ge&&!!Xe&&!!g&&Fe!=="0",{refetch:Lr}=useDFlowQuote({inputMint:Ge,outputMint:Xe,amount:Fe,userPublicKey:g??"",slippageBps:100},{enabled:Ao}),Or=d==="dflow"?g??"":v??"",{data:Se,isLoading:Fo}=usePositions({source:d,user:Or},{enabled:!!Or}),mt=useMemo(()=>ye?d==="dflow"?ye.dflowUsdcBalance:ye.polymarketUsdcBalance:Se&&Se.positions.reduce((B,Ne)=>Ne.side==="USDC"||Ne.side==="collateral"?B+(Ne.current_value??0):B,0)||null,[ye,Se,d]),Bo=ye?ye.isLoading:Fo,$t=useMemo(()=>Se?Se.positions.find(B=>B.side?.toLowerCase()==="yes"&&B.market?.slug===e.slug)?.size??0:null,[Se,e.slug]),Wt=useMemo(()=>Se?Se.positions.find(B=>B.side?.toLowerCase()==="no"&&B.market?.slug===e.slug)?.size??0:null,[Se,e.slug]),zt=useMemo(()=>O==="limit"&&p&&!isNaN(K)?K:ne,[O,p,K,ne]),ft=useMemo(()=>{if(isNaN(R)||R<=0)return 0;if(T==="buy")return R;let N=h==="yes"?e.outcomes[0]?.best_bid??0:e.outcomes[1]?.best_bid??0;return R*N},[T,h,R,e.outcomes]),Ir=useMemo(()=>isNaN(R)||R<=0?0:T==="buy"?zt>0?R/zt*1:0:ft,[T,R,zt,ft]),Ho=Ir-ft,Uo=useCallback(N=>{M(N),ie(NaN);},[]),$o=useCallback(N=>{if(isNaN(N)){ie(NaN);return}let B=Math.max(0,N),Ne=T==="buy"?Math.round(B*100)/100:Math.round(B);ie(Ne);},[T]),Wo=useCallback(N=>{if(isNaN(N)){fe(NaN);return}let B=Math.max(.01,Math.min(.99,N));fe(Math.round(B*100)/100);},[]),Kt=useMemo(()=>{let N=[];(isNaN(R)||R<Xt)&&N.push(`Minimum quantity is ${Xt}`),e.status!=="open"&&N.push("Market is not active"),T==="buy"&&mt!=null&&!isNaN(R)&&R>0&&R>mt&&N.push("Insufficient USDC balance");let B=h==="yes"?$t:Wt;return T==="sell"&&B!=null&&!isNaN(R)&&R>0&&R>B&&N.push("Insufficient shares"),O==="limit"&&p&&(isNaN(K)||K<.01||K>.99)&&N.push("Limit price must be between $0.01 and $0.99"),O==="limit"&&p&&I&&$==="custom"&&(isNaN(z)||z<=0)&&N.push(o("predict.trade.expiration.invalidDate")),{isValid:N.length===0,errors:N}},[R,e.status,T,mt,$t,Wt,h,O,p,K,I,$,z,o]),{mutateAsync:_r}=useDFlowSubmit(),{data:Vt}=useOrder({id:Q??"",source:d},{enabled:!!Q});useEffect(()=>{if(!Vt||!Q)return;let{status:N}=Vt;N==="closed"?(X(false),le(null),toast.success(o("predict.trade.submitSuccess")),en(),ie(NaN)):(N==="failed"||N==="expired")&&(X(false),le(null),toast.error(o("predict.trade.submitError")));},[Vt,Q,o]);let Dr=useCallback(async()=>{if(!g||!u)return;if(!Ge||!Xe){toast.error("Missing token mint addresses"),X(false);return}let N=await l.checkDFlowKYC(g);if(!N.verified){be(true),E(N.kyc_url||null),X(false);return}let we=(await Lr()).data?.transaction;if(!we){toast.error(o("predict.trade.submitError")),X(false);return}let ke=Uint8Array.from(atob(we),gt=>gt.charCodeAt(0)),Yt=await u.signTransaction(ke),qt=await _r({signedTransaction:btoa(String.fromCharCode(...Yt)),orderContext:{user_public_key:g,input_mint:Ge,output_mint:Xe,amount:Fe,price:String(ne),side:T==="buy"?"BUY":"SELL",outcome:h==="yes"?"YES":"NO",market_slug:e.slug,slippage_bps:100}});le(qt.signature);},[g,u,l,Lr,_r,Ge,Xe,Fe,ne,T,h,e.slug,o]),Ar=useCallback(async()=>{if(!m||!a)return;let N=m.chain,B=N!==Chain.POLYGON;B&&await s(Chain.POLYGON);try{let Ne=await m.getEip1193Provider();if(!Ne){toast.error(o("predict.trade.submitError")),X(!1);return}let we={address:m.address,signatureType:0,signTypedData:async(Xo,Qo,Jo)=>await Ne.request({method:"eth_signTypedData_v4",params:[m.address,JSON.stringify({domain:Xo,types:Qo,message:Jo})]})},ke=a.credentials;if(!ke&&(await a.authenticate(we),ke=a.credentials,!ke))throw new Error("Polymarket authentication failed");let Yt=h==="yes"?0:1,qt=e.provider_meta?.[`polymarket.tokenId${Yt}`]??e.provider_meta?.["polymarket.conditionId"]??"",gt=e.provider_meta?.["polymarket.negRisk"]??!1,Ko=O==="limit"&&!isNaN(K)?K:ne,Fr={tokenId:qt,price:Ko,size:R,side:T==="buy"?"BUY":"SELL",orderType:O==="limit"?I?"GTD":"GTC":"FOK",tickSize:"0.01",negRisk:gt,...O==="limit"&&I&&{expiration:Is($,z,Re)}},Vo=buildCtfExchangeDomain(gt),Yo=buildOrderMessage({...Fr,signerAddress:we.address,signatureType:we.signatureType}),qo=await we.signTypedData(Vo,CTF_ORDER_TYPES,Yo),Br=buildSignedOrder({...Fr,signerAddress:we.address,signatureType:we.signatureType,signature:qo}),jo=JSON.stringify(Br),Go=await buildPolymarketL2Headers(ke.address,{apiKey:ke.apiKey,secret:ke.secret,passphrase:ke.passphrase,method:"POST",requestPath:"/api/v1/orders/polymarket",body:jo});await l.createPolymarketOrder(Br,Go),c.invalidateQueries({queryKey:["predict","orders"]}),c.invalidateQueries({queryKey:["predict","positions"]}),toast.success(o("predict.trade.submitSuccess")),en(),ie(NaN),X(!1);}finally{B&&N&&s(N).catch(()=>{});}},[m,a,s,h,e.provider_meta,O,K,ne,R,T,l,c,I,$,z,Re,o]),zo=useCallback(async()=>{if(!(!Kt.isValid||!f)){X(true),le(null),be(false);try{d==="dflow"?await Dr():await Ar();}catch{toast.error(o("predict.trade.submitError")),X(false);}}},[Kt.isValid,f,d,Dr,Ar,o]);return {outcome:h,side:T,orderType:O,quantity:R,limitPrice:K,shares:je,estimatedCost:ft,potentialPayout:Ir,potentialProfit:Ho,usdcBalance:mt,yesTokenBalance:$t,noTokenBalance:Wt,isBalanceLoading:Bo,isSubmitting:Me,validation:Kt,supportsLimitOrder:p,kycRequired:he,kycUrl:S,expirationEnabled:I,expirationPreset:$,customDuration:z,customDurationUnit:Re,setOutcome:Ut,setSide:Uo,setOrderType:Ht,setQuantity:$o,setLimitPrice:Wo,setExpirationEnabled:y,setExpirationPreset:q,setCustomDuration:Pe,setCustomDurationUnit:Bt,submit:zo}}var Ys=`https://s1.chainstream.io/chains/sol/tokens/${SOLANA_TOKENS.stablecoins.USDC.address}/image.png`,qs=["5m","1h","12h","24h","eod","custom"],js={"5m":"predict.trade.expiration.5m","1h":"predict.trade.expiration.1h","12h":"predict.trade.expiration.12h","24h":"predict.trade.expiration.24h",eod:"predict.trade.expiration.eod",custom:"predict.trade.expiration.custom"},Gs=["minutes","hours","days"],Xs={minutes:"predict.trade.expiration.minutes",hours:"predict.trade.expiration.hours",days:"predict.trade.expiration.days"};function cn({event:e,market:t,variant:n="bordered",outcome:o,side:r,orderType:i,quantity:s,limitPrice:l,shares:a,potentialProfit:c,potentialPayout:d,estimatedCost:p,usdcBalance:u,yesTokenBalance:m,noTokenBalance:f,isBalanceLoading:g,isSubmitting:v,isValid:h,validationErrors:D,supportsLimitOrder:T,kycRequired:M,kycUrl:O,expirationEnabled:Z,expirationPreset:R,customDuration:ie,customDurationUnit:K,onOutcomeChange:fe,onSideChange:Me,onOrderTypeChange:X,onQuantityChange:Q,onLimitPriceChange:le,onExpirationEnabledChange:he,onExpirationPresetChange:be,onCustomDurationChange:S,onCustomDurationUnitChange:E,onSubmit:I}){let{t:y}=useTranslation(),[$,q]=useState(false),z=useDisclosure();useEffect(()=>{M&&!z.isOpen&&z.onOpen();},[M]);let Pe=useMemo(()=>{let C=r==="buy"?o==="yes"?t.yesAsk:t.noAsk:o==="yes"?t.yesBid:t.noBid;return C!=null?parseFloat((Number(C)*100).toFixed(2)):null},[r,o,t]),Re=!isNaN(s)&&s>0,Bt=useMemo(()=>{if(v)return y("predict.trade.submitting");if(M)return y("predict.trade.kycRequired");if(!Re)return y("predict.trade.enterAmount");let C=y(r==="buy"?"predict.trade.buy":"predict.trade.sell"),ce=y(o==="yes"?"predict.trade.yes":"predict.trade.no"),Le=r==="buy"&&c>0?` \u2192 Win $${c.toFixed(2)}`:"";return `${C} ${ce}${Le}`},[v,M,Re,r,o,c,y]),ye=useMemo(()=>o==="yes"?"primary":"secondary",[o]),ne=()=>{Q(Math.floor((u??0)/2*100)/100);},Ht=()=>{Q(u??0);},[Ut,je]=useState(false),Fe=()=>{if(M){z.onOpen();return}if(!h){je(true);return}je(false),I();};return jsxs(Fragment,{children:[jsxs("div",{className:cn$1("flex w-full flex-col gap-y-4 p-4",n==="bordered"&&"rounded-xl border border-default-200 bg-content1"),children:[e&&jsxs("div",{className:"flex items-center gap-x-3",children:[e.imageUrl&&jsx("img",{src:e.imageUrl,alt:e.title,className:"h-10 w-10 shrink-0 rounded-lg object-cover"}),jsxs("div",{className:"flex min-w-0 flex-col gap-y-0.5",children:[jsx("span",{className:"text-sm text-neutral-500 leading-tight line-clamp-1",children:e.title}),jsxs("span",{className:"text-base font-semibold leading-tight line-clamp-1",children:[jsxs("span",{className:o==="yes"?"text-bullish":"text-bearish",children:[y(r==="buy"?"predict.trade.buy":"predict.trade.sell")," ",y(o==="yes"?"predict.trade.yes":"predict.trade.no")]}),jsxs("span",{className:"text-foreground",children:[" \xB7 ",t.yesSubTitle]})]})]})]}),jsxs("div",{className:"flex items-center justify-between",children:[T?jsxs(Tabs,{variant:"underlined",selectedKey:i,onSelectionChange:C=>X(C),classNames:{tabList:"gap-x-4",tab:"px-0"},children:[jsx(Tab,{title:y("predict.trade.market")},"market"),jsx(Tab,{title:y("predict.trade.limit")},"limit")]}):jsx("span",{className:"text-sm font-medium text-foreground",children:y("predict.trade.market")}),i==="limit"&&T?jsx(StyledNumberInput,{"aria-label":"Limit price",placeholder:"50",size:"sm",radius:"none",value:isNaN(l)?void 0:parseFloat((l*100).toFixed(2)),onValueChange:C=>le(C/100),minValue:1,maxValue:99,step:1,formatOptions:{maximumFractionDigits:2},endContent:jsx("span",{className:"text-xl font-bold tabular-nums text-foreground",children:"\xA2"}),classNames:{base:"w-28",inputWrapper:"bg-content2 data-[hover=true]:bg-content2 group-data-[focus=true]:bg-content2 rounded-lg px-2 h-9 min-h-9",input:"text-xl font-bold tabular-nums text-right"}}):Pe!=null&&jsxs("span",{className:"text-xl font-bold tabular-nums",children:[Pe," \xA2"]})]}),jsx("div",{className:"flex gap-x-2",children:["yes","no"].map(C=>{let ce=C==="yes"?m:f;return jsxs("div",{className:"flex flex-1 flex-col gap-y-1",children:[jsxs("button",{type:"button",onClick:()=>fe(C),className:`w-full rounded-lg border py-2 text-sm font-medium transition-colors cursor-pointer ${o===C?C==="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:[jsx("span",{children:y(C==="yes"?"predict.trade.yes":"predict.trade.no")}),(()=>{let Le=r==="buy"?C==="yes"?t.yesAsk:t.noAsk:C==="yes"?t.yesBid:t.noBid;return Le!=null?jsxs("span",{className:"ml-1 opacity-70",children:[parseFloat((Number(Le)*100).toFixed(2)),"\xA2"]}):null})()]}),r==="sell"&&o===C&&jsx("span",{className:"text-center text-xs text-foreground",children:g?"\u2013":`${ce??0} shares`})]},C)})}),jsxs("div",{className:"flex flex-col gap-y-1.5",children:[jsxs("div",{className:"flex items-center justify-between text-xs text-neutral-500",children:[jsx("span",{className:"text-sm font-medium text-foreground",children:y(r==="buy"?"predict.trade.youArePaying":"predict.trade.contracts")}),r==="buy"&&jsxs("div",{className:"flex items-center gap-x-2",children:[jsx("img",{src:Ys,alt:"USDC",className:"h-3.5 w-3.5 rounded-full object-cover"}),jsx("span",{className:"font-medium text-foreground tabular-nums",children:u!=null?`${u.toFixed(2)} USDC`:"\u2013"}),jsx("button",{type:"button",onClick:ne,className:"rounded px-1.5 py-0.5 bg-content2 hover:bg-content3 transition-colors cursor-pointer text-foreground font-medium",children:y("predict.trade.half")}),jsx("button",{type:"button",onClick:Ht,className:"rounded px-1.5 py-0.5 bg-content2 hover:bg-content3 transition-colors cursor-pointer text-foreground font-medium",children:y("predict.trade.max")})]})]}),jsx(StyledNumberInput,{fullWidth:true,placeholder:"0",radius:"lg",size:"lg",value:isNaN(s)?void 0:s,onValueChange:C=>{je(false),Q(C);},minValue:0,step:r==="buy"?.01:1,formatOptions:r==="buy"?{maximumFractionDigits:2}:{maximumFractionDigits:0},startContent:r==="buy"?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"}},r),r==="sell"&&jsxs("div",{className:"flex gap-x-2 justify-end",children:[[25,50].map(C=>jsxs("button",{type:"button",onClick:()=>{Q(Math.floor((o==="yes"?m??0:f??0)*C/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:[C,"%"]},C)),jsx("button",{type:"button",onClick:()=>{Q(o==="yes"?m??0:f??0);},className:"rounded-md bg-content2 px-2.5 py-1 text-xs font-medium text-default-600 transition-colors hover:bg-content3 cursor-pointer",children:y("common.all")})]}),Ut&&D.length>0&&jsx("div",{className:"flex flex-col gap-y-0.5",children:D.map(C=>jsx("span",{className:"text-xs text-danger",children:C},C))})]}),i==="limit"&&T&&jsxs("div",{className:"flex flex-col gap-y-2",children:[jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{className:"text-sm font-medium text-primary",children:y("predict.trade.setExpiration")}),jsx(StyledSwitch,{size:"sm",color:"primary",isSelected:Z,onValueChange:he,"aria-label":y("predict.trade.setExpiration")})]}),Z&&jsxs(Fragment,{children:[jsx(Select,{"aria-label":y("predict.trade.setExpiration"),selectedKeys:[R],onSelectionChange:C=>{let ce=Array.from(C)[0];ce&&be(ce);},size:"sm",radius:"lg",classNames:{trigger:"bg-content2 data-[hover=true]:bg-content2 min-h-10",value:"text-sm"},children:qs.map(C=>jsx(SelectItem,{children:y(js[C])},C))}),R==="custom"&&jsxs("div",{className:"flex gap-x-2",children:[jsx(StyledNumberInput,{"aria-label":"Duration amount",size:"sm",radius:"lg",value:isNaN(ie)?void 0:ie,onValueChange:S,minValue:1,step:1,formatOptions:{maximumFractionDigits:0},classNames:{base:"flex-1",inputWrapper:"bg-content2 data-[hover=true]:bg-content2 group-data-[focus=true]:bg-content2 min-h-10",input:"text-sm"}}),jsx(Select,{"aria-label":"Duration unit",selectedKeys:[K],onSelectionChange:C=>{let ce=Array.from(C)[0];ce&&E(ce);},size:"sm",radius:"lg",classNames:{base:"w-32",trigger:"bg-content2 data-[hover=true]:bg-content2 min-h-10",value:"text-sm"},children:Gs.map(C=>jsx(SelectItem,{children:y(Xs[C])},C))})]})]})]}),jsxs("div",{className:"flex flex-col gap-y-2",children:[jsxs("div",{className:"flex items-center justify-between text-sm",children:[jsxs("button",{type:"button",onClick:()=>q(C=>!C),className:"flex items-center gap-x-1 text-neutral-500 hover:text-foreground cursor-pointer transition-colors",children:[jsx("span",{children:y("predict.trade.odds")}),jsx(ChevronDownIcon,{className:cn$1("h-3.5 w-3.5 transition-transform",$&&"rotate-180")})]}),Pe!=null&&jsxs("span",{className:"text-foreground font-medium tabular-nums",children:[Pe,"% chance"]})]}),$&&jsxs("div",{className:"flex flex-col gap-y-1.5 border-l-2 border-default-300 pl-3 text-sm text-neutral-500",children:[jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{children:"Total Size"}),jsx("span",{className:"tabular-nums text-foreground",children:!isNaN(s)&&s>0?`$${p.toFixed(2)}`:"\u2013"})]}),jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{children:"No. of Contracts"}),jsx("span",{className:"tabular-nums text-foreground",children:!isNaN(a)&&a>0?parseFloat(a.toFixed(2)):"\u2013"})]}),jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{children:"Payout"}),jsx("span",{className:"tabular-nums text-foreground",children:!isNaN(s)&&s>0?`$${d.toFixed(2)}`:"\u2013"})]}),jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{children:"Est. Profit"}),jsx("span",{className:"tabular-nums text-bullish",children:!isNaN(s)&&s>0&&c>0?`+$${c.toFixed(2)}`:"\u2013"})]})]})]}),jsx(Button,{color:ye,fullWidth:true,radius:"lg",size:"lg",isDisabled:!Re||v,isLoading:v,onPress:Fe,children:Bt})]}),jsx(Modal,{isOpen:z.isOpen,onClose:z.onClose,size:"md",children:jsxs(ModalContent,{children:[jsx(ModalHeader,{className:"flex flex-col gap-1",children:jsxs("span",{className:"text-lg",children:["\u{1F6E1}\uFE0F ",y("predict.trade.kycModalTitle")]})}),jsxs(ModalBody,{className:"gap-y-4",children:[jsx("p",{className:"text-sm text-default-600",children:y("predict.trade.kycModalDescription")}),jsxs("ul",{className:"flex flex-col gap-y-2 text-sm text-foreground",children:[jsxs("li",{className:"flex items-start gap-x-2",children:[jsx("span",{className:"mt-0.5 text-primary",children:"\u2713"}),jsx("span",{children:y("predict.trade.kycModalBullet1")})]}),jsxs("li",{className:"flex items-start gap-x-2",children:[jsx("span",{className:"mt-0.5 text-primary",children:"\u2713"}),jsx("span",{children:y("predict.trade.kycModalBullet2")})]}),jsxs("li",{className:"flex items-start gap-x-2",children:[jsx("span",{className:"mt-0.5 text-primary",children:"\u2713"}),jsx("span",{children:y("predict.trade.kycModalBullet3")})]})]}),jsx("p",{className:"text-xs text-default-400",children:y("predict.trade.kycModalNote")})]}),jsxs(ModalFooter,{children:[jsx(Button,{variant:"light",onPress:z.onClose,children:y("common.cancel")}),O&&jsx(Button,{color:"primary",onPress:()=>{window.open(O,"_blank","noopener,noreferrer"),z.onClose();},children:y("predict.trade.goToKYC")})]})]})})]})}function bt({event:e,market:t,variant:n,initialSide:o,initialOutcome:r,chain:i}){let{outcome:s,side:l,orderType:a,quantity:c,limitPrice:d,shares:p,estimatedCost:u,potentialPayout:m,potentialProfit:f,usdcBalance:g,yesTokenBalance:v,noTokenBalance:h,isBalanceLoading:D,isSubmitting:T,validation:M,supportsLimitOrder:O,kycRequired:Z,kycUrl:R,expirationEnabled:ie,expirationPreset:K,customDuration:fe,customDurationUnit:Me,setOutcome:X,setSide:Q,setOrderType:le,setQuantity:he,setLimitPrice:be,setExpirationEnabled:S,setExpirationPreset:E,setCustomDuration:I,setCustomDurationUnit:y,submit:$}=tn({market:t,initialSide:o,initialOutcome:r}),q=useAuthCallback($),z=useMemo(()=>e?Yr(e):void 0,[e]),Pe=useMemo(()=>qr(t),[t]);return jsx(cn,{event:z,market:Pe,variant:n,outcome:s,side:l,orderType:a,quantity:c,limitPrice:d,shares:p,estimatedCost:u,potentialPayout:m,potentialProfit:f,usdcBalance:g,yesTokenBalance:v,noTokenBalance:h,isBalanceLoading:D,isSubmitting:T,isValid:M.isValid,validationErrors:M.errors,supportsLimitOrder:O,kycRequired:Z,kycUrl:R,expirationEnabled:ie,expirationPreset:K,customDuration:fe,customDurationUnit:Me,onOutcomeChange:X,onSideChange:Q,onOrderTypeChange:le,onQuantityChange:he,onLimitPriceChange:be,onExpirationEnabledChange:S,onExpirationPresetChange:E,onCustomDurationChange:I,onCustomDurationUnitChange:y,onSubmit:q})}var Je="predict-trade";function yt({id:e=Je}){return jsx(AsyncModal,{id:e,children:t=>jsx(oa,{...t})})}function oa({params:e,isOpen:t,onOpenChange:n}){let{isMobile:o}=useScreen();return e?jsx(StyledModal,{isOpen:t,onOpenChange:n,size:o?"lg":"md",backdrop:"blur",radius:"lg",children:jsx(ModalContent,{children:jsx(ModalBody,{className:"p-2",children:jsx(bt,{event:e.event,market:e.market,initialOutcome:e.initialOutcome,initialSide:"buy",chain:e.chain,variant:"flat"})})})}):null}var nr={sortPreset:"volume",sortAsc:false,source:void 0,timeRemaining:void 0,minVolume:void 0,minLiquidity:void 0};function or(e){let t=0;return e.source&&t++,e.timeRemaining&&t++,e.minVolume&&t++,e.minLiquidity&&t++,t}function pn({isOpen:e,onClose:t,value:n,onChange:o}){let{t:r}=useTranslation(),[i,s]=useState(n),l=useCallback(v=>{v?s(n):t();},[n,t]),a=useCallback(()=>{s(nr);},[]),c=useCallback(()=>{o(i),t();},[i,o,t]),d=useCallback((v,h)=>{s(D=>({...D,[v]:h}));},[]),p=useMemo(()=>or(i),[i]),u=useMemo(()=>[{value:void 0,label:r("predict.filter.all")},{value:"polymarket",label:r("predict.platform.polymarket")},{value:"dflow",label:r("predict.platform.dflow")}],[r]),m=useMemo(()=>[{value:void 0,label:r("predict.filter.all")},{value:"1d",label:r("predict.filter.lessThanDay")},{value:"7d",label:r("predict.filter.lessThanWeek")},{value:"30d",label:r("predict.filter.lessThanMonth")}],[r]),f=useMemo(()=>[{value:void 0,label:r("predict.filter.all")},{value:"1000",label:">$1K"},{value:"10000",label:">$10K"},{value:"100000",label:">$100K"},{value:"1000000",label:">$1M"}],[r]),g=useMemo(()=>[{value:void 0,label:r("predict.filter.all")},{value:"1000",label:">$1K"},{value:"10000",label:">$10K"},{value:"100000",label:">$100K"},{value:"1000000",label:">$1M"}],[r]);return jsx(StyledModal,{isOpen:e,onOpenChange:l,size:"md",scrollBehavior:"inside",children:jsxs(ModalContent,{children:[jsx(ModalHeader,{className:"px-4 py-2",children:jsx("span",{className:"text-base font-semibold",children:r("predict.filter.title")})}),jsxs(ModalBody,{className:"flex flex-col gap-5",children:[jsx(Nt,{label:r("predict.filter.platform"),children:jsx(wt,{options:u,selected:i.source,onSelect:v=>d("source",v)})}),jsx(Nt,{label:r("predict.filter.timeRemaining"),children:jsx(wt,{options:m,selected:i.timeRemaining,onSelect:v=>d("timeRemaining",v)})}),jsx(Nt,{label:r("predict.filter.minVolume"),children:jsx(wt,{options:f,selected:i.minVolume,onSelect:v=>d("minVolume",v)})}),jsx(Nt,{label:r("predict.filter.minLiquidity"),children:jsx(wt,{options:g,selected:i.minLiquidity,onSelect:v=>d("minLiquidity",v)})})]}),jsx(ModalFooter,{className:"px-4",children:jsxs("div",{className:"w-full flex justify-between items-center",children:[jsx(Button,{variant:"light",color:"default",size:"sm",radius:"full",startContent:jsx(RefreshIcon,{width:16,height:16}),onPress:a,children:r("predict.filter.reset")}),jsxs(Button,{color:"primary",size:"sm",radius:"full",onPress:c,children:[r("predict.filter.showResults"),p>0&&jsxs("span",{className:"ml-1 text-xs opacity-80",children:["(",p,")"]})]})]})})]})})}function Nt({label:e,children:t}){return jsxs("div",{className:"flex flex-col gap-2.5",children:[jsx("span",{className:"text-sm font-semibold text-foreground",children:e}),t]})}function wt({options:e,selected:t,onSelect:n,allowDeselect:o=true}){return jsx("div",{className:"flex flex-wrap gap-2",children:e.map(r=>{let i=t===r.value;return jsx("button",{type:"button",onClick:()=>{n(i&&o?void 0:r.value);},className:cn$1("shrink-0 rounded-lg px-3 py-1.5 text-xs font-medium transition-colors duration-150 cursor-pointer border",i?"bg-primary/15 text-primary border-primary/40":"bg-content2 text-foreground/60 border-default-100 hover:bg-default-100 hover:text-foreground"),children:r.label},r.value??"__all")})})}var vn={start_time:{sort_by:"created_at"},volume:{sort_by:"volume"},liquidity:{sort_by:"liquidity"},ending_soon:{sort_by:"end_at"}},fn={start_time:"predict.sort.startTime",volume:"predict.sort.volume",liquidity:"predict.sort.liquidity",ending_soon:"predict.sort.endingSoon"},ka=["start_time","volume","liquidity","ending_soon"];function xn({sortPreset:e,onSortChange:t,sortAsc:n,onSortAscChange:o,onFilterPress:r,filterCount:i=0,className:s}){let{t:l}=useTranslation(),[a,c]=useState(false),d=useRef(null);useEffect(()=>{if(!a)return;let u=f=>{d.current&&!d.current.contains(f.target)&&c(false);},m=f=>{f.key==="Escape"&&c(false);};return document.addEventListener("mousedown",u),document.addEventListener("keydown",m),()=>{document.removeEventListener("mousedown",u),document.removeEventListener("keydown",m);}},[a]);let p=gn[e];return jsxs("div",{className:cn$1("flex items-center gap-2",s),children:[jsxs("div",{ref:d,className:"relative flex shrink-0 items-center rounded-full border border-border",children:[jsxs("button",{type:"button",onClick:()=>c(u=>!u),className:"flex shrink-0 items-center gap-2 px-3 py-1.5 text-xs font-medium text-neutral transition-colors hover:text-primary/80 cursor-pointer",children:[jsx(p,{className:"size-[18px] shrink-0"}),jsx("span",{className:"whitespace-nowrap",children:l(fn[e])})]}),jsx("div",{className:"h-6 w-px bg-border"}),jsx("button",{type:"button",onClick:()=>o(!n),className:"px-2.5 py-1.5 text-xs text-neutral transition-colors hover:text-primary/80 cursor-pointer",children:n?"\u2191":"\u2193"}),a&&jsx("div",{className:"absolute left-0 top-full z-20 mt-1 flex min-w-max flex-col gap-0.5 rounded-lg border border-border bg-content1 p-1 shadow-lg",children:ka.map(u=>{let m=gn[u];return jsxs("button",{type:"button",onClick:()=>{t(u),c(false);},className:cn$1("flex w-full items-center gap-2 rounded px-2.5 py-1.5 text-xs font-medium transition-colors cursor-pointer",u===e?"bg-primary/10 text-primary":"text-neutral hover:bg-content2 hover:text-foreground"),children:[jsx(m,{className:"size-4 shrink-0"}),jsx("span",{children:l(fn[u])})]},u)})})]}),jsx(StyledBadge,{content:i>0?i:void 0,color:"primary",size:"sm",isInvisible:i===0,children:jsxs("button",{type:"button",onClick:r,className:"flex shrink-0 items-center gap-2 rounded-full border border-border px-3 py-1.5 text-xs font-medium text-neutral transition-colors hover:text-primary/80 cursor-pointer",children:[jsx(FilterIcon,{className:"size-[18px]"}),jsx("span",{className:"whitespace-nowrap",children:l("predict.filter.title")})]})})]})}var gn={start_time:CalendarIcon,volume:ChartLineIcon,liquidity:DropletIcon,ending_soon:TimerIcon};function yn(e={}){let t=useMemo(()=>resolveEventsParams(e),[e.tagSlugSelection,e.limit,e.status,e.sort_by,e.sort_asc,e.source,e.with_markets,e.minVolume,e.minLiquidity,e.timeRemaining]),{data:n,isLoading:o,isFetching:r,isFetchingNextPage:i,isError:s,error:l,hasNextPage:a,fetchNextPage:c,refetch:d}=useInfiniteEvents(t),p=useMemo(()=>n?.pages.flatMap(f=>f.items).filter(f=>f!=null)??[],[n]),u=useCallback(()=>{c();},[c]),m=useCallback(()=>{d();},[d]);return {data:p,isLoading:o,isFetching:r&&!i,isFetchingMore:i,isError:s,error:l??null,hasMore:a??false,fetchMore:u,refetch:m}}function sr({count:e=6}){return jsx("div",{className:"grid w-full grid-cols-1 gap-0 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4",children:Array.from({length:e}).map((t,n)=>jsx("div",{className:"p-2",children:jsxs("div",{className:"flex h-full min-h-52 flex-col rounded-xl border border-border/90 bg-background p-3 lg:min-h-72 lg:p-4",children:[jsxs("div",{className:"flex items-center gap-3",children:[jsx(Skeleton,{className:"size-10 shrink-0 rounded-lg"}),jsxs("div",{className:"flex flex-1 flex-col gap-1",children:[jsx(Skeleton,{className:"h-4 w-11/12 rounded"}),jsx(Skeleton,{className:"h-3 w-2/5 rounded"})]})]}),jsxs("div",{className:"mt-3 flex flex-1 flex-col gap-2 lg:gap-3",children:[jsxs("div",{className:"flex items-center justify-between gap-2",children:[jsx(Skeleton,{className:"h-7 w-1/2 rounded"}),jsx(Skeleton,{className:"h-7 w-[85px] rounded-lg lg:h-9 lg:w-24"})]}),jsxs("div",{className:"flex items-center justify-between gap-2",children:[jsx(Skeleton,{className:"h-7 w-3/5 rounded"}),jsx(Skeleton,{className:"h-7 w-[85px] rounded-lg lg:h-9 lg:w-24"})]}),jsxs("div",{className:"flex items-center justify-between gap-2",children:[jsx(Skeleton,{className:"h-7 w-2/5 rounded"}),jsx(Skeleton,{className:"h-7 w-[85px] rounded-lg lg:h-9 lg:w-24"})]})]}),jsxs("div",{className:"mt-auto flex items-center justify-between pt-3",children:[jsx(Skeleton,{className:"h-3 w-20 rounded"}),jsx(Skeleton,{className:"h-3 w-24 rounded"})]})]})},n))})}function xu({count:e=48}){return jsxs("div",{className:"flex h-full w-full max-w-[1680px] mx-auto flex-col gap-y-3",children:[jsxs("div",{className:"flex min-h-8 items-center justify-between gap-3 lg:min-h-9",children:[jsxs("div",{className:"flex items-center gap-2 overflow-hidden",children:[jsx(Skeleton,{className:"h-6 w-16 rounded"}),jsx(Skeleton,{className:"h-6 w-20 rounded"}),jsx(Skeleton,{className:"h-6 w-16 rounded"}),jsx(Skeleton,{className:"h-6 w-20 rounded"})]}),jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[jsx(Skeleton,{className:"h-7 w-28 rounded-full"}),jsx(Skeleton,{className:"h-7 w-24 rounded-full"})]})]}),jsx("div",{className:"min-h-0 flex-1",children:jsx(sr,{count:e})})]})}var Sn=3,ir={bg:"hsl(var(--heroui-primary) / 0.14)",text:"hsl(var(--heroui-primary))",shadow:"hsl(var(--heroui-primary) / 0.18)"},Cn={bg:"hsl(var(--heroui-secondary) / 0.14)",text:"hsl(var(--heroui-secondary))",shadow:"hsl(var(--heroui-secondary) / 0.18)"},Ia={bg:"rgba(239, 68, 68, 0.14)",text:"rgb(239, 68, 68)",shadow:"rgba(239, 68, 68, 0.18)"},tt=[{bg:"rgba(139,92,246,0.14)",text:"rgb(139,92,246)",shadow:"rgba(139,92,246,0.18)"},{bg:"rgba(34,197,94,0.14)",text:"rgb(34,197,94)",shadow:"rgba(34,197,94,0.18)"},{bg:"rgba(0,166,212,0.14)",text:"rgb(0,166,212)",shadow:"rgba(0,166,212,0.18)"},{bg:"rgba(194,120,32,0.14)",text:"rgb(194,120,32)",shadow:"rgba(194,120,32,0.18)"},{bg:"rgba(202,138,4,0.14)",text:"rgb(202,138,4)",shadow:"rgba(202,138,4,0.18)"},{bg:"rgba(236,72,153,0.14)",text:"rgb(236,72,153)",shadow:"rgba(236,72,153,0.18)"},{bg:"rgba(99,102,241,0.14)",text:"rgb(99,102,241)",shadow:"rgba(99,102,241,0.18)"},{bg:"rgba(244,114,82,0.14)",text:"rgb(244,114,82)",shadow:"rgba(244,114,82,0.18)"}];function Nn(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return Math.abs(t)}function _a(e){let t=e.outcomes?.map(s=>s.label?.toLowerCase().trim()??"")??[];if(t.some(s=>s==="up")&&t.some(s=>s==="down"))return [ir,Ia];if(t.some(s=>s==="yes")&&t.some(s=>s==="no"))return [ir,Cn];let n=t[0]??"",o=t[1]??"",r=Nn(n)%tt.length,i=Nn(o)%tt.length;return i===r&&(i=(i+1)%tt.length),[tt[r],tt[i]]}function Da(e){let t=e.outcomes?.[0];return t?t.best_ask??t.price??null:null}function Tn(e){let t=Da(e);return t!=null?parseFloat((t*100).toFixed(2)):0}function Mn(e){return e<=1&&e>0?"< 1%":e>=99&&e<100?"> 99%":`${e}%`}function wn(e){let t=e.outcomes?.[0],n=t?.best_ask??t?.price??0;return parseFloat((n*100).toFixed(2)).toString()}function kn(e){let t=e.outcomes?.[1];if(t){let r=t.best_ask??t.price??0;return parseFloat((r*100).toFixed(2)).toString()}let n=e.outcomes?.[0],o=n?.best_ask??n?.price??0;return parseFloat(((1-o)*100).toFixed(2)).toString()}function Aa(e){let t=new Date(e).getTime()-Date.now();if(t<=0)return null;let n=Math.floor(t/864e5),o=Math.floor(t%864e5/36e5),r=Math.floor(t%36e5/6e4),i=[];return n>0&&i.push(`${n}d`),o>0&&i.push(`${o}h`),i.push(`${r}m`),i.join(" ")}var Fa=`
|
|
1
|
+
import {createContext,memo,useRef,useCallback,useState,useContext,useMemo,useEffect,Fragment as Fragment$1,Component}from'react';import {cn as cn$1,Skeleton,toast,useDisclosure,Tabs,Tab,StyledNumberInput,StyledSwitch,Select,SelectItem,ChevronDownIcon,Button,Modal,ModalContent,ModalHeader,ModalBody,ModalFooter,useScreen,StyledModal,RefreshIcon,TimerIcon,DropletIcon,ChartLineIcon,CalendarIcon,StyledBadge,FilterIcon,Linkable,Avatar,ChevronUpIcon,PolymarketIcon,KalshiIcon,Spinner,OrderbookTableIcon,OrderbookDepthIcon,Dropdown,DropdownTrigger,DropdownMenu,DropdownItem,ChevronRightIcon,ChevronLeftIcon,TrashIcon,Chip,StyledInput,XCloseIcon,Kbd,SearchIcon,EmptyIcon}from'@liberfi.io/ui';import {AsyncModal,useAsyncModal}from'@liberfi.io/ui-scaffold';import {useTranslation}from'@liberfi.io/i18n';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {useWallets,useAuth,useSwitchChain,useAuthCallback}from'@liberfi.io/wallet-connector';import {useQueryClient,useQueries}from'@tanstack/react-query';import Zt from'canvas-confetti';import {ChartRange,useBalance,usePredictClient,PolymarketContext,useDFlowQuote,usePositions,useDFlowSubmit,useOrder,buildCtfExchangeDomain,buildOrderMessage,CTF_ORDER_TYPES,buildSignedOrder,buildPolymarketL2Headers,resolveEventsParams,useInfiniteEvents,useInfiniteOrders,useCancelOrder,useInfiniteTrades,useOrderbook,useMarketHistory,useEvent,useSimilarEvents,candlesticksQueryKey,useSearchEvents}from'@liberfi.io/react-predict';export{PredictClient,PredictContext,PredictProvider,PredictWsClient,createPredictClient,createPredictWsClient,useBalance,useCancelOrder,useCandlesticks,useDFlowKYC,useDFlowQuote,useDFlowSubmit,useEvent,useEvents,useInfiniteEvents,useMarket,useMarketHistory,useMarketTrades,useOrder,useOrderbook,useOrders,usePositions,usePredictClient,usePriceHistory,useSearchEvents,useSimilarEvents,useTrades}from'@liberfi.io/react-predict';import {ChainNamespace,Chain}from'@liberfi.io/types';import {SOLANA_TOKENS,debounce}from'@liberfi.io/utils';import {List}from'react-window';import {useInfiniteLoader}from'react-window-infinite-loader';import {useResizeObserver,useScrollCollapse,useCallbackRef}from'@liberfi.io/hooks';import {ResponsiveContainer,LineChart,CartesianGrid,XAxis,YAxis,Tooltip,Line,ReferenceDot}from'recharts';import {useAtom}from'jotai';import {atomWithStorage}from'jotai/utils';typeof window<"u"&&(window.__LIBERFI_VERSION__=window.__LIBERFI_VERSION__||{},window.__LIBERFI_VERSION__["@liberfi.io/ui-predict"]="0.1.92");var Zo="0.1.92";var es={Weather:["Daily temperature","Snow and rain","Climate change","Natural disasters","Hurricanes"],Companies:["IPOs","Product launches","KPIs","Elon Musk","CEOs","Layoffs"],Crypto:["BTC","15 min","Hourly","ETH","SOL","DOGE","Pre-Market","XRP","BNB","HYPE"],Economics:["Growth","Fed","Inflation","Oil and energy","Employment","Housing","Jobs & Economy","Bankruptcy & Defaults","GDP","Global Central Banks"],Elections:["Primaries","International elections"],Entertainment:["Music","Movies","Music charts","Television","Awards","Video games","Oscars","Rotten Tomatoes"],Financials:["S&P","Nasdaq","Daily","Metals","Treasuries","Oil","EUR/USD","USD/JPY","WTI"],Mentions:["Politicians","Earnings","Entertainment"],Politics:["Trump","Congress","International","SCOTUS & courts","Local","Recurring","Iran","House"],Science:["AI","Energy","Space"],Social:null,Sports:["Soccer","Basketball","Baseball","Football","Hockey","Golf","Tennis","Motorsport","Esports","Boxing","MMA","Rugby","Lacrosse","Mentions","Chess","Cricket","Aussie Rules","Darts"],World:null},Hr=["Politics","Sports","Crypto","Economics","Financials","Elections","Entertainment","Companies","Science and Technology","Climate and Weather","Mentions","Social","World"],jt=(()=>{let e=t=>{let n=Hr.indexOf(t);return n===-1?Hr.length:n};return Object.entries(es).map(([t,n])=>({slug:t,label:t,tags:(n??[]).map(o=>({slug:o,label:o}))})).sort((t,n)=>e(t.slug)-e(n.slug))})();function Wr({categories:e,selectedCategory:t,selectedTag:n,activeTags:o,onCategorySelect:r,onTagSelect:i,trailing:s,pulsingTab:l="Trending",className:a}){let{t:c}=useTranslation(),d=useCallback(()=>{r(null);},[r]),p=c("predict.categories.trending");return jsxs("div",{className:cn$1("sticky top-0 z-30 flex w-full flex-col justify-between gap-2 px-4 py-1 lg:px-2 lg:py-1",a),children:[jsxs("div",{className:"flex w-full items-center gap-2",children:[jsx("div",{className:"hideScrollbar min-w-0 flex-1 overflow-x-auto overflow-y-hidden",children:jsxs("div",{className:"flex min-h-8 items-stretch gap-x-2 lg:min-h-9",children:[jsx(Ur,{label:p,isSelected:t===null,onPress:d,showPulse:p===l}),jsx(os,{}),e.map(u=>jsx(Ur,{label:u.category,isSelected:t===u.category,onPress:()=>r(u.category),badge:u.badge,showPulse:u.category===l},u.category))]})}),s&&jsx("div",{className:"flex-shrink-0",children:s})]}),t&&o.length>0&&jsx("div",{className:"hideScrollbar overflow-x-auto overflow-y-hidden flex items-center",children:jsxs("div",{className:"flex gap-x-1 pl-2 lg:w-full lg:gap-x-2",children:[jsx($r,{label:c("predict.categories.allMarkets"),isSelected:n===null,onPress:()=>i(null)}),o.map(u=>jsx($r,{label:u.label,icon:u.icon,isSelected:n===u.label,onPress:()=>i(u.label)},u.label))]})})]})}function Ur({label:e,isSelected:t,onPress:n,badge:o,showPulse:r}){return jsxs("button",{type:"button",onClick:n,className:cn$1("relative shrink-0 cursor-pointer whitespace-nowrap border-b p-1 text-base font-normal capitalize transition-colors",t?"border-primary/50 text-primary":"border-transparent text-neutral-500 hover:text-neutral-300"),children:[r?jsxs("span",{className:"flex items-center gap-x-1.5",children:[jsx("span",{className:"h-2 w-2 animate-pulse rounded-full bg-[rgb(240,68,56)]"}),jsx("span",{children:e})]}):e,o&&jsx("span",{className:"absolute -right-1 top-0 rounded bg-primary px-0.5 py-px text-[0.625rem] font-semibold leading-none text-neutral-950",children:o})]})}function os(){return jsx("span",{className:"flex items-center text-neutral-600","aria-hidden":"true",children:"|"})}function $r({label:e,icon:t,isSelected:n,onPress:o}){return jsxs("button",{type:"button",onClick:o,className:cn$1("flex shrink-0 items-center justify-center gap-x-1 min-w-14 rounded-2xl border px-2 py-1 text-sm font-medium uppercase transition-colors cursor-pointer",n?"border-transparent bg-primary text-black":"border-border/80 text-neutral-200 hover:bg-primary/10 hover:text-primary"),children:[t&&jsx("span",{className:cn$1("iconify size-4",t)}),e]})}function rd({count:e=6}){return jsx("div",{className:"flex w-full flex-col gap-2 px-4 py-1 lg:px-2 lg:py-1",children:jsx("div",{className:"flex min-h-8 items-center gap-x-2 lg:min-h-9",children:Array.from({length:e}).map((t,n)=>jsx(Skeleton,{className:"h-6 w-16 shrink-0 rounded"},n))})})}function ss(e){return e.map(t=>({category:t.label,tags:t.tags.map(n=>n.label)}))}function as(e){return e?e.tags.map(t=>({label:t.label,icon:t.icon})):[]}function Vr({onSelect:e,trailing:t,className:n}){let[o,r]=useState(null),[i,s]=useState(null),l=useCallback(u=>{r(u),s(null),e?.({categorySlug:u,tagSlug:null});},[e]),a=useCallback(u=>{s(u),e?.({categorySlug:o,tagSlug:u});},[o,e]),c=ss(jt),d=jt.find(u=>u.slug===o),p=as(d);return jsx(Wr,{categories:c,selectedCategory:o,selectedTag:i,activeTags:p,onCategorySelect:l,onTagSelect:a,trailing:t,className:n})}function Yr(e){return {title:e.title,imageUrl:e.image_url}}function qr(e){let t=e.outcomes[0],n=e.outcomes[1];return {question:e.question,yesAsk:t?.best_ask??t?.price,noAsk:n?.best_ask??n?.price,yesBid:t?.best_bid,noBid:n?.best_bid,yesSubTitle:t?.label??"Yes",noSubTitle:n?.label??"No"}}var Qe=48,Gt=4,xt={ONE_MINUTE:1,ONE_HOUR:60,ONE_DAY:1440},oe={ONE_DAY:"1d",ONE_WEEK:"1w",ONE_MONTH:"1m",ALL:"all"},ht=oe.ALL,ud={[oe.ONE_DAY]:xt.ONE_MINUTE,[oe.ONE_WEEK]:xt.ONE_HOUR,[oe.ONE_MONTH]:xt.ONE_HOUR,[oe.ALL]:xt.ONE_DAY},pd={[oe.ONE_DAY]:300,[oe.ONE_WEEK]:3600,[oe.ONE_MONTH]:10800,[oe.ALL]:1440*60},md={[oe.ONE_DAY]:1440*60,[oe.ONE_WEEK]:10080*60,[oe.ONE_MONTH]:720*60*60,[oe.ALL]:null},Xt=1,fd=1,gd=1,vd=99,Be={ONE_HOUR:"1h",SIX_HOURS:"6h",ONE_DAY:"1d",ONE_WEEK:"1w",MAX:"max"},xd=Be.ONE_WEEK,hd={[Be.ONE_HOUR]:60,[Be.SIX_HOURS]:60,[Be.ONE_DAY]:300,[Be.ONE_WEEK]:1800,[Be.MAX]:1800};var Xr=createContext(null);function Jt(){let e=useContext(Xr);if(!e)throw new Error("usePredictWallet must be used within a PredictWalletProvider");return e}var us=3e4;function ps({pollingInterval:e=us,enabled:t=true,children:n}){let o=useWallets(),r=useMemo(()=>o.find(m=>m.chainNamespace===ChainNamespace.SOLANA&&m.isConnected)?.address,[o]),i=useMemo(()=>o.find(m=>m.chainNamespace===ChainNamespace.EVM&&m.isConnected)?.address,[o]),{data:s,isLoading:l,error:a}=useBalance({source:"kalshi",user:r??""},{enabled:t&&!!r,refetchInterval:e}),{data:c,isLoading:d,error:p}=useBalance({source:"polymarket",user:i??""},{enabled:t&&!!i,refetchInterval:e}),u=useMemo(()=>({solanaAddress:r,evmAddress:i,dflowUsdcBalance:s?Number(s.balance):0,polymarketUsdcBalance:c?Number(c.balance):0,isLoading:l||d,error:a??p??null}),[r,i,s,c,l,d,a,p]);return jsx(Xr.Provider,{value:u,children:n})}var Os={minutes:60,hours:3600,days:86400};function Is(e,t,n){let o=Math.floor(Date.now()/1e3);switch(e){case "5m":return o+300;case "1h":return o+3600;case "12h":return o+720*60;case "24h":return o+1440*60;case "eod":{let r=new Date;return r.setUTCHours(23,59,59,0),Math.floor(r.getTime()/1e3)}case "custom":return o+t*Os[n]}}function en(){let e={startVelocity:30,spread:360,ticks:60,zIndex:9999};Zt({...e,particleCount:80,origin:{x:.5,y:.4}}),setTimeout(()=>{Zt({...e,particleCount:40,origin:{x:.3,y:.6}});},150),setTimeout(()=>{Zt({...e,particleCount:40,origin:{x:.7,y:.6}});},300);}function tn({market:e,initialOutcome:t="yes",initialSide:n="buy"}){let{t:o}=useTranslation(),{status:r}=useAuth(),i=useWallets(),s=useSwitchChain(),l=usePredictClient(),a=useContext(PolymarketContext),c=useQueryClient(),d=e.source,p=d==="polymarket",u=i.find(N=>N.chainNamespace===ChainNamespace.SOLANA&&N.isConnected),m=i.find(N=>N.chainNamespace===ChainNamespace.EVM&&N.isConnected&&"switchChain"in N),f=r==="authenticated",g=u?.address,v=m?.address,[h,D]=useState(t),[T,M]=useState(n),[O,Z]=useState("market"),[R,ie]=useState(NaN),[K,fe]=useState(NaN),[Me,X]=useState(false),[Q,le]=useState(null),[he,be]=useState(false),[S,E]=useState(null),[I,y]=useState(false),[$,q]=useState("1h"),[z,Pe]=useState(30),[Re,Bt]=useState("minutes"),ye=null;try{let N=Jt();ye={dflowUsdcBalance:N.dflowUsdcBalance,polymarketUsdcBalance:N.polymarketUsdcBalance,isLoading:N.isLoading};}catch{}let ne=useMemo(()=>{let N=h==="yes"?0:1,B=e.outcomes[N];return T==="buy"?B?.best_ask??B?.price??.5:B?.best_bid??B?.price??.5},[e.outcomes,h,T]),Ht=useCallback(N=>{Z(N);},[]),Ut=useCallback(N=>{D(N),fe(NaN);},[]);useEffect(()=>{O==="limit"&&isNaN(K)&&fe(Math.round(ne*100)/100);},[O,K,ne]);let je=useMemo(()=>isNaN(R)||R<=0?0:T==="buy"?ne>0?R/ne:0:R,[T,R,ne]),Fe=useMemo(()=>isNaN(R)||R<=0?"0":String(Math.round(R*1e6)),[R]),C=e.provider_meta?.["dflow.yesMint"]??"",ce=e.provider_meta?.["dflow.noMint"]??"",Le=e.provider_meta?.["dflow.collateralMint"]||SOLANA_TOKENS.stablecoins.USDC.address,Rr=h==="yes"?C:ce,Ge=T==="buy"?Le:Rr,Xe=T==="buy"?Rr:Le,Ao=d==="kalshi"&&!!Ge&&!!Xe&&!!g&&Fe!=="0",{refetch:Lr}=useDFlowQuote({inputMint:Ge,outputMint:Xe,amount:Fe,userPublicKey:g??"",slippageBps:100},{enabled:Ao}),Or=d==="kalshi"?g??"":v??"",{data:Se,isLoading:Fo}=usePositions({source:d,user:Or},{enabled:!!Or}),mt=useMemo(()=>ye?d==="kalshi"?ye.dflowUsdcBalance:ye.polymarketUsdcBalance:Se&&Se.positions.reduce((B,Ne)=>Ne.side==="USDC"||Ne.side==="collateral"?B+(Ne.current_value??0):B,0)||null,[ye,Se,d]),Bo=ye?ye.isLoading:Fo,$t=useMemo(()=>Se?Se.positions.find(B=>B.side?.toLowerCase()==="yes"&&B.market?.slug===e.slug)?.size??0:null,[Se,e.slug]),Wt=useMemo(()=>Se?Se.positions.find(B=>B.side?.toLowerCase()==="no"&&B.market?.slug===e.slug)?.size??0:null,[Se,e.slug]),zt=useMemo(()=>O==="limit"&&p&&!isNaN(K)?K:ne,[O,p,K,ne]),ft=useMemo(()=>{if(isNaN(R)||R<=0)return 0;if(T==="buy")return R;let N=h==="yes"?e.outcomes[0]?.best_bid??0:e.outcomes[1]?.best_bid??0;return R*N},[T,h,R,e.outcomes]),Ir=useMemo(()=>isNaN(R)||R<=0?0:T==="buy"?zt>0?R/zt*1:0:ft,[T,R,zt,ft]),Ho=Ir-ft,Uo=useCallback(N=>{M(N),ie(NaN);},[]),$o=useCallback(N=>{if(isNaN(N)){ie(NaN);return}let B=Math.max(0,N),Ne=T==="buy"?Math.round(B*100)/100:Math.round(B);ie(Ne);},[T]),Wo=useCallback(N=>{if(isNaN(N)){fe(NaN);return}let B=Math.max(.01,Math.min(.99,N));fe(Math.round(B*100)/100);},[]),Kt=useMemo(()=>{let N=[];(isNaN(R)||R<Xt)&&N.push(`Minimum quantity is ${Xt}`),e.status!=="open"&&N.push("Market is not active"),T==="buy"&&mt!=null&&!isNaN(R)&&R>0&&R>mt&&N.push("Insufficient USDC balance");let B=h==="yes"?$t:Wt;return T==="sell"&&B!=null&&!isNaN(R)&&R>0&&R>B&&N.push("Insufficient shares"),O==="limit"&&p&&(isNaN(K)||K<.01||K>.99)&&N.push("Limit price must be between $0.01 and $0.99"),O==="limit"&&p&&I&&$==="custom"&&(isNaN(z)||z<=0)&&N.push(o("predict.trade.expiration.invalidDate")),{isValid:N.length===0,errors:N}},[R,e.status,T,mt,$t,Wt,h,O,p,K,I,$,z,o]),{mutateAsync:_r}=useDFlowSubmit(),{data:Vt}=useOrder({id:Q??"",source:d},{enabled:!!Q});useEffect(()=>{if(!Vt||!Q)return;let{status:N}=Vt;N==="closed"?(X(false),le(null),toast.success(o("predict.trade.submitSuccess")),en(),ie(NaN)):(N==="failed"||N==="expired")&&(X(false),le(null),toast.error(o("predict.trade.submitError")));},[Vt,Q,o]);let Dr=useCallback(async()=>{if(!g||!u)return;if(!Ge||!Xe){toast.error("Missing token mint addresses"),X(false);return}let N=await l.checkDFlowKYC(g);if(!N.verified){be(true),E(N.kyc_url||null),X(false);return}let we=(await Lr()).data?.transaction;if(!we){toast.error(o("predict.trade.submitError")),X(false);return}let ke=Uint8Array.from(atob(we),gt=>gt.charCodeAt(0)),Yt=await u.signTransaction(ke),qt=await _r({signedTransaction:btoa(String.fromCharCode(...Yt)),orderContext:{user_public_key:g,input_mint:Ge,output_mint:Xe,amount:Fe,price:String(ne),side:T==="buy"?"BUY":"SELL",outcome:h==="yes"?"YES":"NO",market_slug:e.slug,slippage_bps:100}});le(qt.signature);},[g,u,l,Lr,_r,Ge,Xe,Fe,ne,T,h,e.slug,o]),Ar=useCallback(async()=>{if(!m||!a)return;let N=m.chain,B=N!==Chain.POLYGON;B&&await s(Chain.POLYGON);try{let Ne=await m.getEip1193Provider();if(!Ne){toast.error(o("predict.trade.submitError")),X(!1);return}let we={address:m.address,signatureType:0,signTypedData:async(Xo,Qo,Jo)=>await Ne.request({method:"eth_signTypedData_v4",params:[m.address,JSON.stringify({domain:Xo,types:Qo,message:Jo})]})},ke=a.credentials;if(!ke&&(await a.authenticate(we),ke=a.credentials,!ke))throw new Error("Polymarket authentication failed");let Yt=h==="yes"?0:1,qt=e.provider_meta?.[`polymarket.tokenId${Yt}`]??e.provider_meta?.["polymarket.conditionId"]??"",gt=e.provider_meta?.["polymarket.negRisk"]??!1,Ko=O==="limit"&&!isNaN(K)?K:ne,Fr={tokenId:qt,price:Ko,size:R,side:T==="buy"?"BUY":"SELL",orderType:O==="limit"?I?"GTD":"GTC":"FOK",tickSize:"0.01",negRisk:gt,...O==="limit"&&I&&{expiration:Is($,z,Re)}},Vo=buildCtfExchangeDomain(gt),Yo=buildOrderMessage({...Fr,signerAddress:we.address,signatureType:we.signatureType}),qo=await we.signTypedData(Vo,CTF_ORDER_TYPES,Yo),Br=buildSignedOrder({...Fr,signerAddress:we.address,signatureType:we.signatureType,signature:qo}),jo=JSON.stringify(Br),Go=await buildPolymarketL2Headers(ke.address,{apiKey:ke.apiKey,secret:ke.secret,passphrase:ke.passphrase,method:"POST",requestPath:"/api/v1/orders/polymarket",body:jo});await l.createPolymarketOrder(Br,Go),c.invalidateQueries({queryKey:["predict","orders"]}),c.invalidateQueries({queryKey:["predict","positions"]}),toast.success(o("predict.trade.submitSuccess")),en(),ie(NaN),X(!1);}finally{B&&N&&s(N).catch(()=>{});}},[m,a,s,h,e.provider_meta,O,K,ne,R,T,l,c,I,$,z,Re,o]),zo=useCallback(async()=>{if(!(!Kt.isValid||!f)){X(true),le(null),be(false);try{d==="kalshi"?await Dr():await Ar();}catch{toast.error(o("predict.trade.submitError")),X(false);}}},[Kt.isValid,f,d,Dr,Ar,o]);return {outcome:h,side:T,orderType:O,quantity:R,limitPrice:K,shares:je,estimatedCost:ft,potentialPayout:Ir,potentialProfit:Ho,usdcBalance:mt,yesTokenBalance:$t,noTokenBalance:Wt,isBalanceLoading:Bo,isSubmitting:Me,validation:Kt,supportsLimitOrder:p,kycRequired:he,kycUrl:S,expirationEnabled:I,expirationPreset:$,customDuration:z,customDurationUnit:Re,setOutcome:Ut,setSide:Uo,setOrderType:Ht,setQuantity:$o,setLimitPrice:Wo,setExpirationEnabled:y,setExpirationPreset:q,setCustomDuration:Pe,setCustomDurationUnit:Bt,submit:zo}}var Ys=`https://s1.chainstream.io/chains/sol/tokens/${SOLANA_TOKENS.stablecoins.USDC.address}/image.png`,qs=["5m","1h","12h","24h","eod","custom"],js={"5m":"predict.trade.expiration.5m","1h":"predict.trade.expiration.1h","12h":"predict.trade.expiration.12h","24h":"predict.trade.expiration.24h",eod:"predict.trade.expiration.eod",custom:"predict.trade.expiration.custom"},Gs=["minutes","hours","days"],Xs={minutes:"predict.trade.expiration.minutes",hours:"predict.trade.expiration.hours",days:"predict.trade.expiration.days"};function cn({event:e,market:t,variant:n="bordered",outcome:o,side:r,orderType:i,quantity:s,limitPrice:l,shares:a,potentialProfit:c,potentialPayout:d,estimatedCost:p,usdcBalance:u,yesTokenBalance:m,noTokenBalance:f,isBalanceLoading:g,isSubmitting:v,isValid:h,validationErrors:D,supportsLimitOrder:T,kycRequired:M,kycUrl:O,expirationEnabled:Z,expirationPreset:R,customDuration:ie,customDurationUnit:K,onOutcomeChange:fe,onSideChange:Me,onOrderTypeChange:X,onQuantityChange:Q,onLimitPriceChange:le,onExpirationEnabledChange:he,onExpirationPresetChange:be,onCustomDurationChange:S,onCustomDurationUnitChange:E,onSubmit:I}){let{t:y}=useTranslation(),[$,q]=useState(false),z=useDisclosure();useEffect(()=>{M&&!z.isOpen&&z.onOpen();},[M]);let Pe=useMemo(()=>{let C=r==="buy"?o==="yes"?t.yesAsk:t.noAsk:o==="yes"?t.yesBid:t.noBid;return C!=null?parseFloat((Number(C)*100).toFixed(2)):null},[r,o,t]),Re=!isNaN(s)&&s>0,Bt=useMemo(()=>{if(v)return y("predict.trade.submitting");if(M)return y("predict.trade.kycRequired");if(!Re)return y("predict.trade.enterAmount");let C=y(r==="buy"?"predict.trade.buy":"predict.trade.sell"),ce=y(o==="yes"?"predict.trade.yes":"predict.trade.no"),Le=r==="buy"&&c>0?` \u2192 Win $${c.toFixed(2)}`:"";return `${C} ${ce}${Le}`},[v,M,Re,r,o,c,y]),ye=useMemo(()=>o==="yes"?"primary":"secondary",[o]),ne=()=>{Q(Math.floor((u??0)/2*100)/100);},Ht=()=>{Q(u??0);},[Ut,je]=useState(false),Fe=()=>{if(M){z.onOpen();return}if(!h){je(true);return}je(false),I();};return jsxs(Fragment,{children:[jsxs("div",{className:cn$1("flex w-full flex-col gap-y-4 p-4",n==="bordered"&&"rounded-xl border border-default-200 bg-content1"),children:[e&&jsxs("div",{className:"flex items-center gap-x-3",children:[e.imageUrl&&jsx("img",{src:e.imageUrl,alt:e.title,className:"h-10 w-10 shrink-0 rounded-lg object-cover"}),jsxs("div",{className:"flex min-w-0 flex-col gap-y-0.5",children:[jsx("span",{className:"text-sm text-neutral-500 leading-tight line-clamp-1",children:e.title}),jsxs("span",{className:"text-base font-semibold leading-tight line-clamp-1",children:[jsxs("span",{className:o==="yes"?"text-bullish":"text-bearish",children:[y(r==="buy"?"predict.trade.buy":"predict.trade.sell")," ",y(o==="yes"?"predict.trade.yes":"predict.trade.no")]}),jsxs("span",{className:"text-foreground",children:[" \xB7 ",t.yesSubTitle]})]})]})]}),jsxs("div",{className:"flex items-center justify-between",children:[T?jsxs(Tabs,{variant:"underlined",selectedKey:i,onSelectionChange:C=>X(C),classNames:{tabList:"gap-x-4",tab:"px-0"},children:[jsx(Tab,{title:y("predict.trade.market")},"market"),jsx(Tab,{title:y("predict.trade.limit")},"limit")]}):jsx("span",{className:"text-sm font-medium text-foreground",children:y("predict.trade.market")}),i==="limit"&&T?jsx(StyledNumberInput,{"aria-label":"Limit price",placeholder:"50",size:"sm",radius:"none",value:isNaN(l)?void 0:parseFloat((l*100).toFixed(2)),onValueChange:C=>le(C/100),minValue:1,maxValue:99,step:1,formatOptions:{maximumFractionDigits:2},endContent:jsx("span",{className:"text-xl font-bold tabular-nums text-foreground",children:"\xA2"}),classNames:{base:"w-28",inputWrapper:"bg-content2 data-[hover=true]:bg-content2 group-data-[focus=true]:bg-content2 rounded-lg px-2 h-9 min-h-9",input:"text-xl font-bold tabular-nums text-right"}}):Pe!=null&&jsxs("span",{className:"text-xl font-bold tabular-nums",children:[Pe," \xA2"]})]}),jsx("div",{className:"flex gap-x-2",children:["yes","no"].map(C=>{let ce=C==="yes"?m:f;return jsxs("div",{className:"flex flex-1 flex-col gap-y-1",children:[jsxs("button",{type:"button",onClick:()=>fe(C),className:`w-full rounded-lg border py-2 text-sm font-medium transition-colors cursor-pointer ${o===C?C==="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:[jsx("span",{children:y(C==="yes"?"predict.trade.yes":"predict.trade.no")}),(()=>{let Le=r==="buy"?C==="yes"?t.yesAsk:t.noAsk:C==="yes"?t.yesBid:t.noBid;return Le!=null?jsxs("span",{className:"ml-1 opacity-70",children:[parseFloat((Number(Le)*100).toFixed(2)),"\xA2"]}):null})()]}),r==="sell"&&o===C&&jsx("span",{className:"text-center text-xs text-foreground",children:g?"\u2013":`${ce??0} shares`})]},C)})}),jsxs("div",{className:"flex flex-col gap-y-1.5",children:[jsxs("div",{className:"flex items-center justify-between text-xs text-neutral-500",children:[jsx("span",{className:"text-sm font-medium text-foreground",children:y(r==="buy"?"predict.trade.youArePaying":"predict.trade.contracts")}),r==="buy"&&jsxs("div",{className:"flex items-center gap-x-2",children:[jsx("img",{src:Ys,alt:"USDC",className:"h-3.5 w-3.5 rounded-full object-cover"}),jsx("span",{className:"font-medium text-foreground tabular-nums",children:u!=null?`${u.toFixed(2)} USDC`:"\u2013"}),jsx("button",{type:"button",onClick:ne,className:"rounded px-1.5 py-0.5 bg-content2 hover:bg-content3 transition-colors cursor-pointer text-foreground font-medium",children:y("predict.trade.half")}),jsx("button",{type:"button",onClick:Ht,className:"rounded px-1.5 py-0.5 bg-content2 hover:bg-content3 transition-colors cursor-pointer text-foreground font-medium",children:y("predict.trade.max")})]})]}),jsx(StyledNumberInput,{fullWidth:true,placeholder:"0",radius:"lg",size:"lg",value:isNaN(s)?void 0:s,onValueChange:C=>{je(false),Q(C);},minValue:0,step:r==="buy"?.01:1,formatOptions:r==="buy"?{maximumFractionDigits:2}:{maximumFractionDigits:0},startContent:r==="buy"?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"}},r),r==="sell"&&jsxs("div",{className:"flex gap-x-2 justify-end",children:[[25,50].map(C=>jsxs("button",{type:"button",onClick:()=>{Q(Math.floor((o==="yes"?m??0:f??0)*C/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:[C,"%"]},C)),jsx("button",{type:"button",onClick:()=>{Q(o==="yes"?m??0:f??0);},className:"rounded-md bg-content2 px-2.5 py-1 text-xs font-medium text-default-600 transition-colors hover:bg-content3 cursor-pointer",children:y("common.all")})]}),Ut&&D.length>0&&jsx("div",{className:"flex flex-col gap-y-0.5",children:D.map(C=>jsx("span",{className:"text-xs text-danger",children:C},C))})]}),i==="limit"&&T&&jsxs("div",{className:"flex flex-col gap-y-2",children:[jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{className:"text-sm font-medium text-primary",children:y("predict.trade.setExpiration")}),jsx(StyledSwitch,{size:"sm",color:"primary",isSelected:Z,onValueChange:he,"aria-label":y("predict.trade.setExpiration")})]}),Z&&jsxs(Fragment,{children:[jsx(Select,{"aria-label":y("predict.trade.setExpiration"),selectedKeys:[R],onSelectionChange:C=>{let ce=Array.from(C)[0];ce&&be(ce);},size:"sm",radius:"lg",classNames:{trigger:"bg-content2 data-[hover=true]:bg-content2 min-h-10",value:"text-sm"},children:qs.map(C=>jsx(SelectItem,{children:y(js[C])},C))}),R==="custom"&&jsxs("div",{className:"flex gap-x-2",children:[jsx(StyledNumberInput,{"aria-label":"Duration amount",size:"sm",radius:"lg",value:isNaN(ie)?void 0:ie,onValueChange:S,minValue:1,step:1,formatOptions:{maximumFractionDigits:0},classNames:{base:"flex-1",inputWrapper:"bg-content2 data-[hover=true]:bg-content2 group-data-[focus=true]:bg-content2 min-h-10",input:"text-sm"}}),jsx(Select,{"aria-label":"Duration unit",selectedKeys:[K],onSelectionChange:C=>{let ce=Array.from(C)[0];ce&&E(ce);},size:"sm",radius:"lg",classNames:{base:"w-32",trigger:"bg-content2 data-[hover=true]:bg-content2 min-h-10",value:"text-sm"},children:Gs.map(C=>jsx(SelectItem,{children:y(Xs[C])},C))})]})]})]}),jsxs("div",{className:"flex flex-col gap-y-2",children:[jsxs("div",{className:"flex items-center justify-between text-sm",children:[jsxs("button",{type:"button",onClick:()=>q(C=>!C),className:"flex items-center gap-x-1 text-neutral-500 hover:text-foreground cursor-pointer transition-colors",children:[jsx("span",{children:y("predict.trade.odds")}),jsx(ChevronDownIcon,{className:cn$1("h-3.5 w-3.5 transition-transform",$&&"rotate-180")})]}),Pe!=null&&jsxs("span",{className:"text-foreground font-medium tabular-nums",children:[Pe,"% chance"]})]}),$&&jsxs("div",{className:"flex flex-col gap-y-1.5 border-l-2 border-default-300 pl-3 text-sm text-neutral-500",children:[jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{children:"Total Size"}),jsx("span",{className:"tabular-nums text-foreground",children:!isNaN(s)&&s>0?`$${p.toFixed(2)}`:"\u2013"})]}),jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{children:"No. of Contracts"}),jsx("span",{className:"tabular-nums text-foreground",children:!isNaN(a)&&a>0?parseFloat(a.toFixed(2)):"\u2013"})]}),jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{children:"Payout"}),jsx("span",{className:"tabular-nums text-foreground",children:!isNaN(s)&&s>0?`$${d.toFixed(2)}`:"\u2013"})]}),jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{children:"Est. Profit"}),jsx("span",{className:"tabular-nums text-bullish",children:!isNaN(s)&&s>0&&c>0?`+$${c.toFixed(2)}`:"\u2013"})]})]})]}),jsx(Button,{color:ye,fullWidth:true,radius:"lg",size:"lg",isDisabled:!Re||v,isLoading:v,onPress:Fe,children:Bt})]}),jsx(Modal,{isOpen:z.isOpen,onClose:z.onClose,size:"md",children:jsxs(ModalContent,{children:[jsx(ModalHeader,{className:"flex flex-col gap-1",children:jsxs("span",{className:"text-lg",children:["\u{1F6E1}\uFE0F ",y("predict.trade.kycModalTitle")]})}),jsxs(ModalBody,{className:"gap-y-4",children:[jsx("p",{className:"text-sm text-default-600",children:y("predict.trade.kycModalDescription")}),jsxs("ul",{className:"flex flex-col gap-y-2 text-sm text-foreground",children:[jsxs("li",{className:"flex items-start gap-x-2",children:[jsx("span",{className:"mt-0.5 text-primary",children:"\u2713"}),jsx("span",{children:y("predict.trade.kycModalBullet1")})]}),jsxs("li",{className:"flex items-start gap-x-2",children:[jsx("span",{className:"mt-0.5 text-primary",children:"\u2713"}),jsx("span",{children:y("predict.trade.kycModalBullet2")})]}),jsxs("li",{className:"flex items-start gap-x-2",children:[jsx("span",{className:"mt-0.5 text-primary",children:"\u2713"}),jsx("span",{children:y("predict.trade.kycModalBullet3")})]})]}),jsx("p",{className:"text-xs text-default-400",children:y("predict.trade.kycModalNote")})]}),jsxs(ModalFooter,{children:[jsx(Button,{variant:"light",onPress:z.onClose,children:y("common.cancel")}),O&&jsx(Button,{color:"primary",onPress:()=>{window.open(O,"_blank","noopener,noreferrer"),z.onClose();},children:y("predict.trade.goToKYC")})]})]})})]})}function bt({event:e,market:t,variant:n,initialSide:o,initialOutcome:r,chain:i}){let{outcome:s,side:l,orderType:a,quantity:c,limitPrice:d,shares:p,estimatedCost:u,potentialPayout:m,potentialProfit:f,usdcBalance:g,yesTokenBalance:v,noTokenBalance:h,isBalanceLoading:D,isSubmitting:T,validation:M,supportsLimitOrder:O,kycRequired:Z,kycUrl:R,expirationEnabled:ie,expirationPreset:K,customDuration:fe,customDurationUnit:Me,setOutcome:X,setSide:Q,setOrderType:le,setQuantity:he,setLimitPrice:be,setExpirationEnabled:S,setExpirationPreset:E,setCustomDuration:I,setCustomDurationUnit:y,submit:$}=tn({market:t,initialSide:o,initialOutcome:r}),q=useAuthCallback($),z=useMemo(()=>e?Yr(e):void 0,[e]),Pe=useMemo(()=>qr(t),[t]);return jsx(cn,{event:z,market:Pe,variant:n,outcome:s,side:l,orderType:a,quantity:c,limitPrice:d,shares:p,estimatedCost:u,potentialPayout:m,potentialProfit:f,usdcBalance:g,yesTokenBalance:v,noTokenBalance:h,isBalanceLoading:D,isSubmitting:T,isValid:M.isValid,validationErrors:M.errors,supportsLimitOrder:O,kycRequired:Z,kycUrl:R,expirationEnabled:ie,expirationPreset:K,customDuration:fe,customDurationUnit:Me,onOutcomeChange:X,onSideChange:Q,onOrderTypeChange:le,onQuantityChange:he,onLimitPriceChange:be,onExpirationEnabledChange:S,onExpirationPresetChange:E,onCustomDurationChange:I,onCustomDurationUnitChange:y,onSubmit:q})}var Je="predict-trade";function yt({id:e=Je}){return jsx(AsyncModal,{id:e,children:t=>jsx(oa,{...t})})}function oa({params:e,isOpen:t,onOpenChange:n}){let{isMobile:o}=useScreen();return e?jsx(StyledModal,{isOpen:t,onOpenChange:n,size:o?"lg":"md",backdrop:"blur",radius:"lg",children:jsx(ModalContent,{children:jsx(ModalBody,{className:"p-2",children:jsx(bt,{event:e.event,market:e.market,initialOutcome:e.initialOutcome,initialSide:"buy",chain:e.chain,variant:"flat"})})})}):null}var nr={sortPreset:"volume",sortAsc:false,source:void 0,timeRemaining:void 0,minVolume:void 0,minLiquidity:void 0};function or(e){let t=0;return e.source&&t++,e.timeRemaining&&t++,e.minVolume&&t++,e.minLiquidity&&t++,t}function pn({isOpen:e,onClose:t,value:n,onChange:o}){let{t:r}=useTranslation(),[i,s]=useState(n),l=useCallback(v=>{v?s(n):t();},[n,t]),a=useCallback(()=>{s(nr);},[]),c=useCallback(()=>{o(i),t();},[i,o,t]),d=useCallback((v,h)=>{s(D=>({...D,[v]:h}));},[]),p=useMemo(()=>or(i),[i]),u=useMemo(()=>[{value:void 0,label:r("predict.filter.all")},{value:"polymarket",label:r("predict.platform.polymarket")},{value:"kalshi",label:r("predict.platform.kalshi")}],[r]),m=useMemo(()=>[{value:void 0,label:r("predict.filter.all")},{value:"1d",label:r("predict.filter.lessThanDay")},{value:"7d",label:r("predict.filter.lessThanWeek")},{value:"30d",label:r("predict.filter.lessThanMonth")}],[r]),f=useMemo(()=>[{value:void 0,label:r("predict.filter.all")},{value:"1000",label:">$1K"},{value:"10000",label:">$10K"},{value:"100000",label:">$100K"},{value:"1000000",label:">$1M"}],[r]),g=useMemo(()=>[{value:void 0,label:r("predict.filter.all")},{value:"1000",label:">$1K"},{value:"10000",label:">$10K"},{value:"100000",label:">$100K"},{value:"1000000",label:">$1M"}],[r]);return jsx(StyledModal,{isOpen:e,onOpenChange:l,size:"md",scrollBehavior:"inside",children:jsxs(ModalContent,{children:[jsx(ModalHeader,{className:"px-4 py-2",children:jsx("span",{className:"text-base font-semibold",children:r("predict.filter.title")})}),jsxs(ModalBody,{className:"flex flex-col gap-5",children:[jsx(Nt,{label:r("predict.filter.platform"),children:jsx(wt,{options:u,selected:i.source,onSelect:v=>d("source",v)})}),jsx(Nt,{label:r("predict.filter.timeRemaining"),children:jsx(wt,{options:m,selected:i.timeRemaining,onSelect:v=>d("timeRemaining",v)})}),jsx(Nt,{label:r("predict.filter.minVolume"),children:jsx(wt,{options:f,selected:i.minVolume,onSelect:v=>d("minVolume",v)})}),jsx(Nt,{label:r("predict.filter.minLiquidity"),children:jsx(wt,{options:g,selected:i.minLiquidity,onSelect:v=>d("minLiquidity",v)})})]}),jsx(ModalFooter,{className:"px-4",children:jsxs("div",{className:"w-full flex justify-between items-center",children:[jsx(Button,{variant:"light",color:"default",size:"sm",radius:"full",startContent:jsx(RefreshIcon,{width:16,height:16}),onPress:a,children:r("predict.filter.reset")}),jsxs(Button,{color:"primary",size:"sm",radius:"full",onPress:c,children:[r("predict.filter.showResults"),p>0&&jsxs("span",{className:"ml-1 text-xs opacity-80",children:["(",p,")"]})]})]})})]})})}function Nt({label:e,children:t}){return jsxs("div",{className:"flex flex-col gap-2.5",children:[jsx("span",{className:"text-sm font-semibold text-foreground",children:e}),t]})}function wt({options:e,selected:t,onSelect:n,allowDeselect:o=true}){return jsx("div",{className:"flex flex-wrap gap-2",children:e.map(r=>{let i=t===r.value;return jsx("button",{type:"button",onClick:()=>{n(i&&o?void 0:r.value);},className:cn$1("shrink-0 rounded-lg px-3 py-1.5 text-xs font-medium transition-colors duration-150 cursor-pointer border",i?"bg-primary/15 text-primary border-primary/40":"bg-content2 text-foreground/60 border-default-100 hover:bg-default-100 hover:text-foreground"),children:r.label},r.value??"__all")})})}var vn={start_time:{sort_by:"created_at"},volume:{sort_by:"volume"},liquidity:{sort_by:"liquidity"},ending_soon:{sort_by:"end_at"}},fn={start_time:"predict.sort.startTime",volume:"predict.sort.volume",liquidity:"predict.sort.liquidity",ending_soon:"predict.sort.endingSoon"},ka=["start_time","volume","liquidity","ending_soon"];function xn({sortPreset:e,onSortChange:t,sortAsc:n,onSortAscChange:o,onFilterPress:r,filterCount:i=0,className:s}){let{t:l}=useTranslation(),[a,c]=useState(false),d=useRef(null);useEffect(()=>{if(!a)return;let u=f=>{d.current&&!d.current.contains(f.target)&&c(false);},m=f=>{f.key==="Escape"&&c(false);};return document.addEventListener("mousedown",u),document.addEventListener("keydown",m),()=>{document.removeEventListener("mousedown",u),document.removeEventListener("keydown",m);}},[a]);let p=gn[e];return jsxs("div",{className:cn$1("flex items-center gap-2",s),children:[jsxs("div",{ref:d,className:"relative flex shrink-0 items-center rounded-full border border-border",children:[jsxs("button",{type:"button",onClick:()=>c(u=>!u),className:"flex shrink-0 items-center gap-2 px-3 py-1.5 text-xs font-medium text-neutral transition-colors hover:text-primary/80 cursor-pointer",children:[jsx(p,{className:"size-[18px] shrink-0"}),jsx("span",{className:"whitespace-nowrap",children:l(fn[e])})]}),jsx("div",{className:"h-6 w-px bg-border"}),jsx("button",{type:"button",onClick:()=>o(!n),className:"px-2.5 py-1.5 text-xs text-neutral transition-colors hover:text-primary/80 cursor-pointer",children:n?"\u2191":"\u2193"}),a&&jsx("div",{className:"absolute left-0 top-full z-20 mt-1 flex min-w-max flex-col gap-0.5 rounded-lg border border-border bg-content1 p-1 shadow-lg",children:ka.map(u=>{let m=gn[u];return jsxs("button",{type:"button",onClick:()=>{t(u),c(false);},className:cn$1("flex w-full items-center gap-2 rounded px-2.5 py-1.5 text-xs font-medium transition-colors cursor-pointer",u===e?"bg-primary/10 text-primary":"text-neutral hover:bg-content2 hover:text-foreground"),children:[jsx(m,{className:"size-4 shrink-0"}),jsx("span",{children:l(fn[u])})]},u)})})]}),jsx(StyledBadge,{content:i>0?i:void 0,color:"primary",size:"sm",isInvisible:i===0,children:jsxs("button",{type:"button",onClick:r,className:"flex shrink-0 items-center gap-2 rounded-full border border-border px-3 py-1.5 text-xs font-medium text-neutral transition-colors hover:text-primary/80 cursor-pointer",children:[jsx(FilterIcon,{className:"size-[18px]"}),jsx("span",{className:"whitespace-nowrap",children:l("predict.filter.title")})]})})]})}var gn={start_time:CalendarIcon,volume:ChartLineIcon,liquidity:DropletIcon,ending_soon:TimerIcon};function yn(e={}){let t=useMemo(()=>resolveEventsParams(e),[e.tagSlugSelection,e.limit,e.status,e.sort_by,e.sort_asc,e.source,e.with_markets,e.minVolume,e.minLiquidity,e.timeRemaining]),{data:n,isLoading:o,isFetching:r,isFetchingNextPage:i,isError:s,error:l,hasNextPage:a,fetchNextPage:c,refetch:d}=useInfiniteEvents(t),p=useMemo(()=>n?.pages.flatMap(f=>f.items).filter(f=>f!=null)??[],[n]),u=useCallback(()=>{c();},[c]),m=useCallback(()=>{d();},[d]);return {data:p,isLoading:o,isFetching:r&&!i,isFetchingMore:i,isError:s,error:l??null,hasMore:a??false,fetchMore:u,refetch:m}}function sr({count:e=6}){return jsx("div",{className:"grid w-full grid-cols-1 gap-0 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4",children:Array.from({length:e}).map((t,n)=>jsx("div",{className:"p-2",children:jsxs("div",{className:"flex h-full min-h-52 flex-col rounded-xl border border-border/90 bg-background p-3 lg:min-h-72 lg:p-4",children:[jsxs("div",{className:"flex items-center gap-3",children:[jsx(Skeleton,{className:"size-10 shrink-0 rounded-lg"}),jsxs("div",{className:"flex flex-1 flex-col gap-1",children:[jsx(Skeleton,{className:"h-4 w-11/12 rounded"}),jsx(Skeleton,{className:"h-3 w-2/5 rounded"})]})]}),jsxs("div",{className:"mt-3 flex flex-1 flex-col gap-2 lg:gap-3",children:[jsxs("div",{className:"flex items-center justify-between gap-2",children:[jsx(Skeleton,{className:"h-7 w-1/2 rounded"}),jsx(Skeleton,{className:"h-7 w-[85px] rounded-lg lg:h-9 lg:w-24"})]}),jsxs("div",{className:"flex items-center justify-between gap-2",children:[jsx(Skeleton,{className:"h-7 w-3/5 rounded"}),jsx(Skeleton,{className:"h-7 w-[85px] rounded-lg lg:h-9 lg:w-24"})]}),jsxs("div",{className:"flex items-center justify-between gap-2",children:[jsx(Skeleton,{className:"h-7 w-2/5 rounded"}),jsx(Skeleton,{className:"h-7 w-[85px] rounded-lg lg:h-9 lg:w-24"})]})]}),jsxs("div",{className:"mt-auto flex items-center justify-between pt-3",children:[jsx(Skeleton,{className:"h-3 w-20 rounded"}),jsx(Skeleton,{className:"h-3 w-24 rounded"})]})]})},n))})}function xu({count:e=48}){return jsxs("div",{className:"flex h-full w-full max-w-[1680px] mx-auto flex-col gap-y-3",children:[jsxs("div",{className:"flex min-h-8 items-center justify-between gap-3 lg:min-h-9",children:[jsxs("div",{className:"flex items-center gap-2 overflow-hidden",children:[jsx(Skeleton,{className:"h-6 w-16 rounded"}),jsx(Skeleton,{className:"h-6 w-20 rounded"}),jsx(Skeleton,{className:"h-6 w-16 rounded"}),jsx(Skeleton,{className:"h-6 w-20 rounded"})]}),jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[jsx(Skeleton,{className:"h-7 w-28 rounded-full"}),jsx(Skeleton,{className:"h-7 w-24 rounded-full"})]})]}),jsx("div",{className:"min-h-0 flex-1",children:jsx(sr,{count:e})})]})}var Sn=3,ir={bg:"hsl(var(--heroui-primary) / 0.14)",text:"hsl(var(--heroui-primary))",shadow:"hsl(var(--heroui-primary) / 0.18)"},Cn={bg:"hsl(var(--heroui-secondary) / 0.14)",text:"hsl(var(--heroui-secondary))",shadow:"hsl(var(--heroui-secondary) / 0.18)"},Ia={bg:"rgba(239, 68, 68, 0.14)",text:"rgb(239, 68, 68)",shadow:"rgba(239, 68, 68, 0.18)"},tt=[{bg:"rgba(139,92,246,0.14)",text:"rgb(139,92,246)",shadow:"rgba(139,92,246,0.18)"},{bg:"rgba(34,197,94,0.14)",text:"rgb(34,197,94)",shadow:"rgba(34,197,94,0.18)"},{bg:"rgba(0,166,212,0.14)",text:"rgb(0,166,212)",shadow:"rgba(0,166,212,0.18)"},{bg:"rgba(194,120,32,0.14)",text:"rgb(194,120,32)",shadow:"rgba(194,120,32,0.18)"},{bg:"rgba(202,138,4,0.14)",text:"rgb(202,138,4)",shadow:"rgba(202,138,4,0.18)"},{bg:"rgba(236,72,153,0.14)",text:"rgb(236,72,153)",shadow:"rgba(236,72,153,0.18)"},{bg:"rgba(99,102,241,0.14)",text:"rgb(99,102,241)",shadow:"rgba(99,102,241,0.18)"},{bg:"rgba(244,114,82,0.14)",text:"rgb(244,114,82)",shadow:"rgba(244,114,82,0.18)"}];function Nn(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return Math.abs(t)}function _a(e){let t=e.outcomes?.map(s=>s.label?.toLowerCase().trim()??"")??[];if(t.some(s=>s==="up")&&t.some(s=>s==="down"))return [ir,Ia];if(t.some(s=>s==="yes")&&t.some(s=>s==="no"))return [ir,Cn];let n=t[0]??"",o=t[1]??"",r=Nn(n)%tt.length,i=Nn(o)%tt.length;return i===r&&(i=(i+1)%tt.length),[tt[r],tt[i]]}function Da(e){let t=e.outcomes?.[0];return t?t.best_ask??t.price??null:null}function Tn(e){let t=Da(e);return t!=null?parseFloat((t*100).toFixed(2)):0}function Mn(e){return e<=1&&e>0?"< 1%":e>=99&&e<100?"> 99%":`${e}%`}function wn(e){let t=e.outcomes?.[0],n=t?.best_ask??t?.price??0;return parseFloat((n*100).toFixed(2)).toString()}function kn(e){let t=e.outcomes?.[1];if(t){let r=t.best_ask??t.price??0;return parseFloat((r*100).toFixed(2)).toString()}let n=e.outcomes?.[0],o=n?.best_ask??n?.price??0;return parseFloat(((1-o)*100).toFixed(2)).toString()}function Aa(e){let t=new Date(e).getTime()-Date.now();if(t<=0)return null;let n=Math.floor(t/864e5),o=Math.floor(t%864e5/36e5),r=Math.floor(t%36e5/6e4),i=[];return n>0&&i.push(`${n}d`),o>0&&i.push(`${o}h`),i.push(`${r}m`),i.join(" ")}var Fa=`
|
|
2
2
|
.badge-shine { position: relative; overflow: hidden; }
|
|
3
3
|
.badge-shine::after {
|
|
4
4
|
content: "";
|
|
@@ -16,7 +16,7 @@ import {createContext,memo,useRef,useCallback,useState,useContext,useMemo,useEff
|
|
|
16
16
|
60% { transform: translate(200%); }
|
|
17
17
|
100% { transform: translate(200%); }
|
|
18
18
|
}
|
|
19
|
-
`;function Rn({event:e,href:t,LinkComponent:n,onSelect:o,onSelectOutcome:r,onHover:i}){let[s,l]=useState(null),a=e.markets??[],c=useMemo(()=>a.length>2?[...a].sort((M,O)=>(O.outcomes?.[0]?.price??0)-(M.outcomes?.[0]?.price??0)):a,[a]),d=c.filter(M=>M.status==="open"),p=c.length===1,u=d.slice(0,Sn),m=d.length-Sn,f=useMemo(()=>`$${Math.round(e.volume??0).toLocaleString("en-US")}`,[e.volume]),g=s?d.find(M=>M.slug===s)??null:null,v=!!g||p,h=()=>{v||o?.(e);},D=M=>{M.stopPropagation(),g&&(M.preventDefault(),l(null));},T=M=>{M.stopPropagation(),t||(M.preventDefault(),o?.(e));};return jsxs("div",{className:cn$1("group flex h-full w-full flex-col rounded-xl","min-h-52 border border-border/90 bg-background p-3","lg:min-h-72 lg:max-w-md lg:p-4","gap-y-1.5 lg:gap-y-4","transition duration-300","hover:border-primary/40 hover:shadow-card-glow","focus-within:border-primary/40 focus-within:shadow-card-glow",!v&&"cursor-pointer"),onMouseEnter:()=>i?.(e),onClick:h,children:[jsx("style",{children:Fa}),jsx(Ba,{event:e,href:t,LinkComponent:n,onClick:D,isExpanded:v}),jsx("div",{className:"flex flex-1 flex-col",children:p?jsx(Ya,{market:d[0],event:e,formattedVolume:f,href:t,LinkComponent:n,onSelect:o,onSelectOutcome:r}):g?jsx(qa,{market:g,event:e,onCollapse:()=>l(null),onSelectOutcome:r}):jsx(Ka,{displayedMarkets:u,moreCount:m,formattedVolume:f,source:e.source,href:t,LinkComponent:n,onMarketClick:M=>l(M.slug),onShowMore:T})})]})}function Ba({event:e,href:t,LinkComponent:n,onClick:o,isExpanded:r}){let i=e.start_at?Aa(e.start_at):null;return jsxs(Linkable,{href:t,LinkComponent:n,as:"button",className:"group/header flex items-center gap-x-2 lg:gap-x-4 w-full text-left cursor-pointer",onClick:o,children:[jsx(Avatar,{src:e.image_url||void 0,name:e.title||"Event",radius:"lg",className:"h-8 w-8 flex-shrink-0 transition-transform duration-300 group-hover/header:scale-110 lg:h-12 lg:w-12",classNames:{base:"bg-transparent"}}),jsxs("div",{className:"flex min-w-0 flex-1 flex-col justify-center gap-y-0.5",children:[jsx("p",{className:cn$1("min-w-0 text-sm font-semibold leading-snug text-slate-200 line-clamp-2 lg:text-base",r&&"group-hover/header:text-neutral-400"),children:e.title}),i&&jsxs("span",{className:"text-[10px] leading-4 text-neutral-500",children:["Live in ",i]})]}),jsx(Ua,{event:e})]})}function Ha(e){let t=[];if(e.status==="closed")return t.push({kind:"closed"}),t.slice(0,2);let n=e.tags?.some(r=>r.label?.toLowerCase()==="crypto"),o=e.tags?.some(r=>r.label?.toLowerCase()==="live");if(n&&e.end_at){let r=new Date(e.end_at).getTime()-Date.now(),i=300*1e3,s=900*1e3;if(r>0&&r<=s){let l=r<=i?"#ef4444":"#f59e0b";t.push({kind:"crypto-short",label:r<=i?"5m":"15m",color:l});}}return o&&t.push({kind:"live"}),t.slice(0,2)}function Ua({event:e}){let t=useMemo(()=>Ha(e),[e]);return t.length===0?null:jsx("div",{className:"flex flex-shrink-0 flex-col items-end gap-1",children:t.map((n,o)=>{switch(n.kind){case "live":return jsx($a,{},o);case "crypto-short":return jsx(Wa,{label:n.label,color:n.color},o);case "closed":return jsx(za,{},o)}})})}function $a(){let{t:e}=useTranslation();return jsxs("span",{className:"badge-shine relative inline-flex items-center gap-1 overflow-hidden rounded-md bg-[rgb(240,68,56)]/10 px-1.5 py-0.5 text-xs font-semibold text-[rgb(240,68,56)]",children:[jsx("span",{className:"h-2 w-2 animate-pulse rounded-full bg-current"}),e("predict.event.status.live")]})}function Wa({label:e,color:t}){return jsxs("span",{className:"badge-shine relative inline-flex items-center gap-1 overflow-hidden rounded-md px-1.5 py-0.5 text-xs font-semibold",style:{backgroundColor:`${t}26`,color:t},children:[jsx(TimerIcon,{className:"size-3 shrink-0"}),e]})}function za(){let{t:e}=useTranslation();return jsx("span",{className:"inline-flex items-center rounded-md bg-neutral-800/80 px-1.5 py-0.5 text-xs font-semibold text-neutral-400",children:e("predict.event.status.closed")})}function Ka({displayedMarkets:e,moreCount:t,formattedVolume:n,source:o,href:r,LinkComponent:i,onMarketClick:s,onShowMore:l}){let{t:a}=useTranslation();return jsxs(Fragment,{children:[e.length>0&&jsx("div",{className:"flex w-full flex-1 flex-col gap-y-0.5 lg:gap-y-2",children:e.map(c=>{let d=Tn(c);return jsxs("button",{type:"button",className:"flex h-9 w-full items-center justify-between gap-x-2 transition-opacity hover:cursor-pointer hover:opacity-80",onClick:p=>{p.stopPropagation(),s(c);},children:[jsx("span",{className:"min-w-0 flex-1 text-left text-xs text-slate-200 line-clamp-1 lg:text-sm",children:c.outcomes?.[0]?.label??c.question}),jsxs("div",{className:"flex items-center gap-x-2",children:[jsx("span",{className:"text-sm font-semibold text-slate-200 lg:text-lg",children:Mn(d)}),jsx(Va,{})]})]},c.slug)})}),jsxs("div",{className:"mt-auto flex items-center justify-between pt-3",children:[t>0?jsxs(Linkable,{href:r,LinkComponent:i,as:"button",className:"flex items-center gap-1 text-[10px] font-normal text-neutral-500 transition-colors hover:text-slate-200 cursor-pointer lg:text-xs",onClick:l,children:[a("predict.event.showMore"),jsx(On,{className:"h-3 w-3"})]}):jsx("div",{}),jsxs("span",{className:"inline-flex items-center gap-x-1.5 text-[10px] font-normal text-neutral-500 lg:text-xs",children:[n," ",a("predict.event.volume"),jsx(In,{source:o})]})]})]})}function Pn({bgColor:e,textColor:t,shadowColor:n,onClick:o,children:r}){return jsx("button",{type:"button",className:"flex h-12 flex-1 w-full items-center justify-center gap-x-1 overflow-hidden rounded-lg p-3 text-base font-normal hover:cursor-pointer will-change-transform [-webkit-tap-highlight-color:transparent]",style:{backgroundColor:e,color:t,"--shadow-color":n,"--shadow-offset":"4px",boxShadow:"inset 0 -1px 0 rgba(255,255,255,0.08), 0 var(--shadow-offset, 4px) 0 var(--shadow-color, rgba(0,0,0,0.22))",transition:"transform .12s, box-shadow .12s, opacity .14s"},onMouseEnter:l=>{let a=l.currentTarget;a.style.setProperty("--shadow-offset","2px"),a.style.transform="translateY(2px)";},onMouseLeave:l=>{let a=l.currentTarget;a.style.setProperty("--shadow-offset","4px"),a.style.transform="translateY(0px)";},onClick:o,children:r})}function Ln({market:e,event:t,onSelectOutcome:n,dynamicColors:o=false,labelFormat:r="action"}){let{t:i}=useTranslation(),[s,l]=o?_a(e):[ir,Cn],a=e.outcomes?.[0]?.label?.toLowerCase().trim()??"",c=e.outcomes?.[1]?.label?.toLowerCase().trim()??"",d=r==="label"&&a===c?"action":r,p=d==="label"?`${e.outcomes?.[0]?.label??"Yes"} ${wn(e)}\xA2`:i("predict.market.action.yes",{price:wn(e)}),u=d==="label"?`${e.outcomes?.[1]?.label??"No"} ${kn(e)}\xA2`:i("predict.market.action.no",{price:kn(e)});return jsxs("div",{className:"flex gap-2",children:[jsx(Pn,{bgColor:s.bg,textColor:s.text,shadowColor:s.shadow,onClick:m=>{m.stopPropagation(),n?.(t,e,"yes");},children:p}),jsx(Pn,{bgColor:l.bg,textColor:l.text,shadowColor:l.shadow,onClick:m=>{m.stopPropagation(),n?.(t,e,"no");},children:u})]})}function Va(){let{t:e}=useTranslation();return jsxs("span",{className:"inline-flex h-7 w-[85px] items-center justify-center gap-x-3 rounded-lg p-1.5 text-xs font-semibold flex-shrink-0 bg-gradient-to-r from-primary/15 to-secondary/15 lg:h-9 lg:w-24 lg:gap-x-4 lg:p-2 lg:text-sm",children:[jsx("span",{className:"text-primary",children:e("predict.market.yes")}),jsx("span",{className:"text-neutral-400",children:"/"}),jsx("span",{className:"text-secondary",children:e("predict.market.no")})]})}function Ya({market:e,event:t,formattedVolume:n,href:o,LinkComponent:r,onSelect:i,onSelectOutcome:s}){let{t:l}=useTranslation();return jsxs(Fragment,{children:[jsx("div",{className:"flex-1",children:jsx(Ln,{market:e,event:t,onSelectOutcome:s,dynamicColors:true,labelFormat:"label"})}),jsxs("div",{className:"mt-auto flex items-center justify-between pt-3",children:[jsxs(Linkable,{href:o,LinkComponent:r,as:"button",className:"flex items-center gap-1 text-[10px] font-normal text-neutral-500 transition-colors hover:text-slate-200 cursor-pointer lg:text-xs",onClick:c=>{c.stopPropagation(),o||(c.preventDefault(),i?.(t));},children:[l("predict.event.viewEvent"),jsx(On,{className:"h-3 w-3"})]}),jsxs("span",{className:"inline-flex items-center gap-x-1.5 text-[10px] font-normal text-neutral-500 lg:text-xs",children:[n," ",l("predict.event.volume"),jsx(In,{source:t.source})]})]})]})}function qa({market:e,event:t,onCollapse:n,onSelectOutcome:o}){let{t:r}=useTranslation(),i=Tn(e);return jsxs(Fragment,{children:[jsxs("div",{className:"flex-1",children:[jsxs("button",{type:"button",className:"flex h-9 w-full items-center justify-between cursor-pointer",onClick:s=>{s.stopPropagation(),n();},children:[jsx("span",{className:"min-w-0 flex-1 text-left text-xs text-slate-200 lg:text-sm",children:e.outcomes?.[0]?.label??e.question}),jsxs("div",{className:"flex items-center gap-x-1 flex-shrink-0",children:[jsx("span",{className:"text-sm font-semibold text-slate-200 lg:text-lg",children:Mn(i)}),jsx(ChevronUpIcon,{className:"h-4 w-4 text-neutral-400"})]})]}),jsx("div",{className:"mt-3",children:jsx(Ln,{market:e,event:t,onSelectOutcome:o,labelFormat:"action"})})]}),jsxs("button",{type:"button",className:"mt-auto flex items-center gap-x-1 pt-4 text-[10px] font-normal text-neutral-500 transition-colors hover:text-slate-200 cursor-pointer lg:text-xs",onClick:s=>{s.stopPropagation(),n();},children:[jsx(ja,{className:"h-3 w-3"}),r("predict.event.back")]})]})}function On({className:e}){return jsx("svg",{viewBox:"0 0 12 12",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:e,children:jsx("path",{d:"M4.5 2.5L8 6l-3.5 3.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function ja({className:e}){return jsx("svg",{viewBox:"0 0 12 12",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:e,children:jsx("path",{d:"M7.5 2.5L4 6l3.5 3.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function In({source:e}){return jsxs("span",{className:"inline-flex items-center gap-x-1 text-neutral-400",title:e==="polymarket"?"Polymarket":"Kalshi",children:[jsx("span",{className:"text-neutral-600",children:"\xB7"}),e==="polymarket"?jsx(PolymarketIcon,{className:"h-5 w-auto shrink-0"}):jsx(KalshiIcon,{className:"h-3 w-auto shrink-0"})]})}var ei=768,Dn=1024,ti=1280,ri=8,ni=224,oi=304,si=114;function ai(e){return e>=ti?4:e>=Dn?3:e>=ei?2:1}function ii(e){return e>=Dn?oi:ni}function An({events:e,hasMore:t=false,onFetchMore:n,onSelect:o,onSelectOutcome:r,getEventHref:i,LinkComponent:s,onHover:l}){let a=useRef(null),c=useRef(null),{width:d=0,height:p=0}=useResizeObserver({ref:a}),u=ai(d),m=ii(d),f=Math.ceil(e.length/u)||0,g=!t&&e.length>0,v=f+(t?1:0)+(g?1:0),h=useCallback(O=>O<f,[f]),D=useCallback(async()=>{n?.();},[n]),T=useInfiniteLoader({isRowLoaded:h,loadMoreRows:D,rowCount:v,threshold:3}),M=useCallback(()=>{c.current?.scrollToRow({index:0,behavior:"smooth"});},[]);return jsx("div",{ref:a,className:"@container w-full h-full",children:p>0&&jsx(List,{listRef:c,className:"no-scrollbar",style:{height:p},onRowsRendered:T,rowComponent:li,rowCount:v,rowHeight:O=>g&&O===v-1?si:(m),rowProps:{events:e,columnCount:u,dataRowCount:f,showEndOfList:g,totalRowCount:v,onSelect:o,onSelectOutcome:r,getEventHref:i,LinkComponent:s,onHover:l,onScrollToTop:M}})})}function li({index:e,style:t,events:n,columnCount:o,dataRowCount:r,showEndOfList:i,totalRowCount:s,onSelect:l,onSelectOutcome:a,getEventHref:c,LinkComponent:d,onHover:p,onScrollToTop:u}){if(i&&e===s-1)return jsx("div",{style:t,children:jsx(ci,{onScrollToTop:u})});if(e>=r)return jsx("div",{style:t,className:"flex justify-center items-start pt-4",children:jsx(Spinner,{size:"sm"})});let m=e*o,f=n.slice(m,m+o),g=o-f.length;return jsx("div",{style:t,children:jsxs("div",{className:"flex w-full h-full",children:[f.map(v=>v==null?null:jsx("div",{className:"flex-1 min-w-0 flex",style:{padding:ri},children:jsx(Rn,{event:v,href:c?.(v),LinkComponent:d,onSelect:l,onSelectOutcome:a,onHover:p})},v.slug)),g>0&&Array.from({length:g}).map((v,h)=>jsx("div",{style:{flex:1,minWidth:0}},`spacer-${h}`))]})})}function ci({onScrollToTop:e}){let{t}=useTranslation();return jsxs("div",{className:"flex w-full flex-col items-center justify-center gap-y-4 py-6",children:[jsxs("div",{className:"flex w-full items-center justify-center gap-x-4",children:[jsx("div",{className:"h-px w-16 bg-neutral-700"}),jsx("span",{className:"text-xs font-medium text-neutral-500",children:t("predict.event.endOfList")}),jsx("div",{className:"h-px w-16 bg-neutral-700"})]}),jsxs("button",{type:"button",className:"flex cursor-pointer items-center gap-x-1 text-xs font-medium text-neutral-400",onClick:e,children:[jsx("span",{className:"iconify size-4 ph--arrow-up-bold"}),jsx("span",{children:t("predict.event.backToTop")})]})]})}function Bn({tagSlugSelection:e,limit:t=48,status:n,sort_by:o,sort_asc:r,source:i,with_markets:s,timeRemaining:l,minVolume:a,minLiquidity:c,onSelect:d,onSelectOutcome:p,getEventHref:u,LinkComponent:m,onHover:f}){let{data:g,hasMore:v,fetchMore:h,isFetching:D}=yn({tagSlugSelection:e,limit:t,status:n,sort_by:o,sort_asc:r,source:i,with_markets:s,timeRemaining:l,minVolume:a,minLiquidity:c});return D?jsx(sr,{count:48}):jsx(An,{events:g,hasMore:v,onFetchMore:h,onSelect:d,onSelectOutcome:p,getEventHref:u,LinkComponent:m,onHover:f})}function ju({onSelect:e,onSelectOutcome:t,getEventHref:n,LinkComponent:o,onHover:r}){let[i,s]=useState({categorySlug:null,tagSlug:null}),[l,a]=useState(nr),{isOpen:c,onOpen:d,onClose:p}=useDisclosure(),{onOpen:u}=useAsyncModal(Je),m=useCallback((O,Z,R)=>{t?.(O,Z,R),u({params:{event:O,market:Z,initialOutcome:R}});},[t,u]),f=useCallback(O=>{s(O);},[]),g=useCallback(O=>{a(Z=>({...Z,sortPreset:O}));},[]),v=useCallback(O=>{a(Z=>({...Z,sortAsc:O}));},[]),h=useCallback(O=>{a(O);},[]),D=useMemo(()=>vn[l.sortPreset].sort_by,[l.sortPreset]),T=useMemo(()=>or(l),[l]),M=useMemo(()=>jsx(xn,{sortPreset:l.sortPreset,onSortChange:g,sortAsc:l.sortAsc,onSortAscChange:v,onFilterPress:d,filterCount:T}),[l.sortPreset,l.sortAsc,T,g,v,d]);return jsxs("div",{className:"flex h-full w-full max-w-[1680px] mx-auto flex-col gap-y-3",children:[jsx(Vr,{onSelect:f,trailing:M}),jsx(pn,{isOpen:c,onClose:p,value:l,onChange:h}),jsx("div",{className:"min-h-0 flex-1",children:jsx(Bn,{tagSlugSelection:i,sort_by:D,sort_asc:l.sortAsc,source:l.source,timeRemaining:l.timeRemaining,minVolume:l.minVolume,minLiquidity:l.minLiquidity,onSelect:e,onSelectOutcome:m,getEventHref:n,LinkComponent:o,onHover:r})}),jsx(yt,{})]})}var fr=40,Ct=36,st=480,gr=st-Ct;function Wn({event:e,walletAddress:t,onCancelOrder:n}){let{t:o}=useTranslation(),[r,i]=useState("positions"),s=useMemo(()=>e.markets?.map(p=>p.slug)??[],[e.markets]),{data:l}=usePositions({source:e.source,user:t??""}),a=useMemo(()=>!l?.positions||!t?0:s.length===0?l.positions.length:l.positions.filter(p=>p.market&&s.includes(p.market.slug)).length,[l?.positions,s,t]),d=[{key:"positions",label:a>0?`${o("predict.positions.title")} (${a})`:o("predict.positions.title")},{key:"orders",label:o("predict.openOrders.title")},{key:"trades",label:o("predict.tradeHistory.title")}];return jsxs("div",{className:"flex flex-col gap-y-2 mt-6 px-1 lg:px-4",children:[jsx("div",{className:"flex items-center gap-x-1 border-b border-border",children:d.map(p=>jsx("button",{type:"button",onClick:()=>i(p.key),className:cn$1("px-3 py-2 text-sm font-medium transition-colors cursor-pointer",r===p.key?"text-foreground border-b-2 border-primary":"text-neutral hover:text-foreground"),children:p.label},p.key))}),t?jsxs("div",{style:{height:st},children:[r==="positions"&&jsx(hi,{source:e.source,walletAddress:t,marketSlugs:s}),r==="orders"&&jsx(yi,{source:e.source,walletAddress:t,marketSlugs:s,onCancelOrder:n}),r==="trades"&&jsx(wi,{source:e.source,walletAddress:t})]}):jsx("div",{className:"flex items-center justify-center text-sm text-neutral",style:{height:st},children:o("predict.trade.connectWallet")})]})}function hi({source:e,walletAddress:t,marketSlugs:n}){let{t:o}=useTranslation(),{data:r,isLoading:i}=usePositions({source:e,user:t}),s=useMemo(()=>r?.positions?n.length===0?r.positions:r.positions.filter(l=>l.market&&n.includes(l.market.slug)):[],[r?.positions,n]);return i?jsx(xr,{}):s.length===0?jsx(vr,{message:o("predict.positions.empty")}):jsxs("div",{className:"flex flex-col h-full",children:[jsxs("div",{className:"flex items-center text-neutral text-xs lg:text-sm font-normal shrink-0",style:{height:Ct},children:[jsx("div",{className:"flex-[3] min-w-0 pr-2 whitespace-nowrap",children:o("predict.positions.event")}),jsx("div",{className:"flex-1 pr-2 text-right whitespace-nowrap",children:o("predict.positions.totalSize")}),jsx("div",{className:"flex-1 pr-2 text-right whitespace-nowrap",children:o("predict.positions.value")}),jsx("div",{className:"flex-1 pr-2 text-right whitespace-nowrap",children:o("predict.positions.avgPrice")}),jsx("div",{className:"flex-1 pr-2 text-right whitespace-nowrap",children:o("predict.positions.markPrice")}),jsx("div",{className:"flex-[1.5] pr-2 text-right whitespace-nowrap",children:o("predict.positions.pnl")}),jsx("div",{className:"flex-1 pr-2 text-right whitespace-nowrap",children:o("predict.positions.payoutIfRight")}),jsx("div",{className:"flex-[1.5] pr-2 text-right whitespace-nowrap",children:o("predict.positions.estSettlement")}),jsx("div",{className:"w-16 shrink-0"})]}),jsx(List,{style:{height:gr},rowComponent:bi,rowCount:s.length,rowHeight:fr,rowProps:{positions:s,closeLabel:o("predict.positions.close")}})]})}function bi({index:e,style:t,positions:n,closeLabel:o}){let r=n[e];if(!r)return null;let i=r.pnl??0,s=r.pnl_percent??0,l=r.avg_price??0,a=r.current_price??0,c=i>0?"text-success":i<0?"text-danger":"text-foreground",d=i>0?"+":"",p=r.market?.outcomes?.[0]?.label??r.market?.question??"\u2014",u=r.side,m=r.size,f=r.size*a,g=r.market?.end_at?Ei(r.market.end_at):"\u2014";return jsxs("div",{style:t,className:"flex items-center border-b border-border/50 hover:bg-content2/40 transition-colors text-xs lg:text-sm",children:[jsx("div",{className:"flex-[3] min-w-0 pr-2",children:jsxs("div",{className:"flex flex-col gap-y-0.5",children:[jsx("span",{className:"text-foreground truncate font-medium",children:p}),jsx("span",{className:cn$1("text-[10px] font-medium",u.toLowerCase()==="yes"?"text-primary":"text-secondary"),children:u})]})}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:r.size}),jsxs("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:["$",f.toFixed(2)]}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:Pt(l)}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:Pt(a)}),jsxs("div",{className:cn$1("flex-[1.5] pr-2 text-right font-mono whitespace-nowrap",c),children:[d,"$",Math.abs(i).toFixed(2),jsxs("span",{className:"text-[10px] ml-0.5 opacity-70",children:["(",d,s.toFixed(1),"%)"]})]}),jsxs("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:["$",m.toFixed(2)]}),jsx("div",{className:"flex-[1.5] pr-2 text-right text-neutral whitespace-nowrap",children:g}),jsx("div",{className:"w-16 shrink-0 text-right",children:jsx("button",{type:"button",className:"text-xs text-neutral hover:text-foreground cursor-pointer transition-colors rounded px-2 py-0.5 border border-border hover:border-foreground/40",children:o})})]})}function yi({source:e,walletAddress:t,marketSlugs:n,onCancelOrder:o}){let{t:r}=useTranslation(),{data:i,isLoading:s,fetchNextPage:l,hasNextPage:a}=useInfiniteOrders({source:e,wallet_address:t}),c=useCancelOrder(),d=useMemo(()=>{let h=i?.pages?.flatMap(M=>M.items)??[],D=new Set(["live","open","submitted","pending"]),T=h.filter(M=>D.has(M.status));return n.length>0&&(T=T.filter(M=>M.market_id&&n.includes(M.market_id))),T},[i?.pages,n]),p=useCallback(h=>{o?o(h.id):c.mutate({source:h.source,id:h.id});},[o,c]),u=d.length,m=u+(a?1:0),f=useCallback(h=>h<u,[u]),g=useCallback(async()=>{await l();},[l]),v=useInfiniteLoader({isRowLoaded:f,loadMoreRows:g,rowCount:m,threshold:5});return s?jsx(xr,{}):d.length===0&&!a?jsx(vr,{message:r("predict.openOrders.empty")}):jsxs("div",{className:"flex flex-col h-full",children:[jsxs("div",{className:"flex items-center text-neutral text-xs lg:text-sm font-normal shrink-0",style:{height:Ct},children:[jsx("div",{className:"w-16 shrink-0 pr-2",children:r("predict.openOrders.side")}),jsx("div",{className:"flex-1 pr-2",children:r("predict.openOrders.outcome")}),jsx("div",{className:"flex-1 pr-2",children:r("predict.openOrders.type")}),jsx("div",{className:"flex-1 pr-2 text-right",children:r("predict.openOrders.price")}),jsx("div",{className:"flex-1 pr-2 text-right",children:r("predict.openOrders.filled")}),jsx("div",{className:"w-20 shrink-0 pr-2",children:r("predict.openOrders.status")}),jsx("div",{className:"w-16 shrink-0"})]}),jsx(List,{style:{height:gr},onRowsRendered:v,rowComponent:Si,rowCount:m,rowHeight:fr,rowProps:{orders:d,itemCount:u,onCancel:p,isCancelling:c.isPending,cancelLabel:r("predict.openOrders.cancel")}})]})}function Si({index:e,style:t,orders:n,itemCount:o,onCancel:r,isCancelling:i,cancelLabel:s}){if(e>=o)return jsx("div",{style:t,className:"flex justify-center items-center",children:jsx(Spinner,{size:"sm"})});let l=n[e];if(!l)return null;let a=l.side==="BUY";return jsxs("div",{style:t,className:"flex items-center border-b border-border/50 text-xs lg:text-sm",children:[jsx("div",{className:"w-16 shrink-0 pr-2",children:jsx("span",{className:cn$1("inline-block rounded px-1.5 py-0.5 text-[10px] font-medium",a?"bg-primary/10 text-primary":"bg-danger/10 text-danger"),children:l.side})}),jsx("div",{className:"flex-1 pr-2 text-foreground capitalize",children:l.outcome??"\u2014"}),jsx("div",{className:"flex-1 pr-2 text-neutral capitalize",children:l.order_type??"limit"}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:l.price?Pt(parseFloat(l.price)):"\u2014"}),jsxs("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:[l.size_matched??"0","/",l.original_size??"\u2014"]}),jsx("div",{className:"w-20 shrink-0 pr-2",children:jsx(Ni,{status:l.status})}),jsx("div",{className:"w-16 shrink-0 text-right",children:jsx("button",{type:"button",onClick:()=>r(l),disabled:i,className:"text-[10px] text-danger hover:text-danger/80 cursor-pointer disabled:opacity-50 transition-colors",children:i?jsx(Spinner,{size:"sm"}):s})})]})}function Ni({status:e}){return jsx("span",{className:cn$1("inline-block rounded px-1.5 py-0.5 text-[10px] font-medium capitalize",{live:"bg-success/10 text-success",open:"bg-success/10 text-success",submitted:"bg-warning/10 text-warning",pending:"bg-warning/10 text-warning",matched:"bg-primary/10 text-primary",cancelled:"bg-neutral/10 text-neutral",failed:"bg-danger/10 text-danger",expired:"bg-neutral/10 text-neutral"}[e]??"bg-neutral/10 text-neutral"),children:e})}function wi({source:e,walletAddress:t}){let{t:n}=useTranslation(),{data:o,isLoading:r,fetchNextPage:i,hasNextPage:s}=useInfiniteTrades({source:e,wallet:t,limit:50}),l=useMemo(()=>o?.pages?.flatMap(m=>m.items)??[],[o?.pages]),a=l.length,c=a+(s?1:0),d=useCallback(m=>m<a,[a]),p=useCallback(async()=>{await i();},[i]),u=useInfiniteLoader({isRowLoaded:d,loadMoreRows:p,rowCount:c,threshold:5});return r?jsx(xr,{}):l.length===0&&!s?jsx(vr,{message:n("predict.tradeHistory.empty")}):jsxs("div",{className:"flex flex-col h-full",children:[jsxs("div",{className:"flex items-center text-neutral text-xs lg:text-sm font-normal shrink-0",style:{height:Ct},children:[jsx("div",{className:"w-16 shrink-0 pr-2",children:n("predict.tradeHistory.side")}),jsx("div",{className:"flex-1 pr-2",children:n("predict.tradeHistory.outcome")}),jsx("div",{className:"flex-1 pr-2 text-right",children:n("predict.tradeHistory.price")}),jsx("div",{className:"flex-1 pr-2 text-right",children:n("predict.tradeHistory.qty")}),jsx("div",{className:"flex-1 pr-2 text-right",children:n("predict.tradeHistory.total")}),jsx("div",{className:"flex-[1.5] pr-2 text-right",children:n("predict.tradeHistory.time")})]}),jsx(List,{style:{height:gr},onRowsRendered:u,rowComponent:ki,rowCount:c,rowHeight:fr,rowProps:{trades:l,itemCount:a}})]})}function ki({index:e,style:t,trades:n,itemCount:o}){if(e>=o)return jsx("div",{style:t,className:"flex justify-center items-center",children:jsx(Spinner,{size:"sm"})});let r=n[e];if(!r)return null;let i=r.side?.toUpperCase()==="BUY",s=Pi(r.timestamp),l=r.price??0,a=r.usd_size??0;return jsxs("div",{style:t,className:"flex items-center border-b border-border/50 text-xs lg:text-sm",children:[jsx("div",{className:"w-16 shrink-0 pr-2",children:jsx("span",{className:cn$1("inline-block rounded px-1.5 py-0.5 text-[10px] font-medium",i?"bg-primary/10 text-primary":"bg-danger/10 text-danger"),children:r.side})}),jsx("div",{className:"flex-1 pr-2 text-foreground capitalize",children:r.outcome??"\u2014"}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:Pt(l)}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:r.size}),jsxs("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:["$",a.toFixed(2)]}),jsx("div",{className:"flex-[1.5] pr-2 text-right text-neutral whitespace-nowrap",children:s})]})}function vr({message:e}){return jsx("div",{className:"flex items-center justify-center text-sm text-neutral",style:{height:st},children:e})}function xr(){return jsx("div",{className:"flex flex-col gap-y-2 py-3 animate-pulse",style:{height:st},children:Array.from({length:6}).map((e,t)=>jsx(Skeleton,{className:"h-8 w-full rounded-md"},t))})}function Pt(e){let t=e*100;return t<1&&t>0?"< 1\xA2":`${t.toFixed(1)}\xA2`}function Pi(e){let t=new Date(e*1e3),n=(t.getMonth()+1).toString().padStart(2,"0"),o=t.getDate().toString().padStart(2,"0"),r=t.getHours().toString().padStart(2,"0"),i=t.getMinutes().toString().padStart(2,"0");return `${n}/${o} ${r}:${i}`}function Ei(e){try{return new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}catch{return "\u2014"}}function at({marketCount:e=4,showBack:t}){return jsxs("div",{className:"flex w-full flex-col gap-4 animate-pulse lg:gap-6",children:[t&&jsx("div",{className:"h-5"}),jsxs("div",{className:"flex items-center gap-x-2 h-16 lg:h-20 lg:gap-x-4",children:[jsx(Skeleton,{className:"size-16 shrink-0 rounded-lg lg:size-20"}),jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-1.5",children:[jsxs("div",{className:"flex items-center gap-1.5",children:[jsx(Skeleton,{className:"h-3.5 w-12 rounded"}),jsx(Skeleton,{className:"h-3.5 w-10 rounded"}),jsx(Skeleton,{className:"h-3.5 w-10 rounded"})]}),jsx(Skeleton,{className:"h-5 w-full max-w-sm rounded lg:h-6"})]})]}),jsx(Skeleton,{className:"h-4 w-48 rounded"}),jsxs("div",{className:"flex flex-col gap-3",children:[jsxs("div",{className:"flex items-center gap-4",children:[jsx(Skeleton,{className:"h-4 w-24 rounded"}),jsx(Skeleton,{className:"h-4 w-20 rounded"})]}),jsx(Skeleton,{className:"h-[300px] w-full rounded-xl"}),jsxs("div",{className:"flex items-center justify-between",children:[jsx(Skeleton,{className:"h-4 w-20 rounded"}),jsxs("div",{className:"flex items-center gap-2",children:[jsx(Skeleton,{className:"h-7 w-[200px] rounded-lg"}),jsx(Skeleton,{className:"h-7 w-28 rounded-lg"})]})]})]}),jsxs("div",{className:"flex flex-col",children:[jsxs("div",{className:"flex items-center py-2",children:[jsx("div",{className:"flex-1"}),jsx(Skeleton,{className:"h-3.5 w-14 rounded"}),jsx("div",{className:"flex-1"})]}),Array.from({length:e}).map((n,o)=>jsxs("div",{className:"flex items-center gap-x-2 border-b border-border py-2.5 lg:gap-x-3",children:[jsx(Skeleton,{className:"size-5 shrink-0 rounded-lg lg:size-8"}),jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-1",children:[jsx(Skeleton,{className:"h-3.5 w-32 rounded lg:h-4 lg:w-48"}),jsx(Skeleton,{className:"h-2.5 w-16 rounded"})]}),jsx(Skeleton,{className:"h-4 w-10 rounded"}),jsxs("div",{className:"flex items-center gap-2",children:[jsx(Skeleton,{className:"h-8 w-16 rounded-lg lg:w-24"}),jsx(Skeleton,{className:"h-8 w-16 rounded-lg lg:w-24"})]})]},o))]}),jsxs("div",{className:"flex flex-col gap-2",children:[jsx(Skeleton,{className:"h-4 w-16 rounded"}),jsx(Skeleton,{className:"h-3.5 w-full rounded"}),jsx(Skeleton,{className:"h-3.5 w-4/5 rounded"}),jsx(Skeleton,{className:"h-3.5 w-3/5 rounded"})]})]})}function zn(){return jsxs("div",{className:"flex flex-col gap-3 rounded-xl border border-border p-4 animate-pulse",children:[jsx(Skeleton,{className:"h-10 w-full rounded-lg"}),jsx(Skeleton,{className:"h-24 w-full rounded-lg"}),jsx(Skeleton,{className:"h-10 w-full rounded-lg"})]})}var qn="var(--color-bullish)",jn="var(--color-bearish)";function it(e){let t=Math.abs(e);return t>=1e9?`${parseFloat((e/1e9).toFixed(2))}B`:t>=1e6?`${parseFloat((e/1e6).toFixed(2))}M`:t>=1e3?`${parseFloat((e/1e3).toFixed(2))}K`:e.toLocaleString()}function Mi(e,t){return e<=0||t<=0?0:Math.pow(e/t,.3)}function Ri(e,t){let n=new Float64Array(101),o=new Float64Array(101);for(let m of e){let f=Math.round(m.price*100);f>=0&&f<=100&&(n[f]+=m.quantity);}for(let m of t){let f=Math.round(m.price*100);f>=0&&f<=100&&(o[f]+=m.quantity);}let r=0,i=0,s=new Float64Array(101),l=new Float64Array(101);for(let m=100;m>=0;m--)r+=n[m],i+=n[m]*m/100,s[m]=r,l[m]=i;let a=0,c=0,d=new Float64Array(101),p=new Float64Array(101);for(let m=0;m<=100;m++)a+=o[m],c+=o[m]*m/100,d[m]=a,p[m]=c;let u=Math.max(s[0]??0,d[100]??0);return Array.from({length:101},(m,f)=>{let g=s[f]>0,v=d[f]>0,h=s[f]||d[f],D=n[f]>0||o[f]>0;return {priceCents:f,displayHeight:Mi(h,u),opacity:h>0?D?1:.5:0,isBid:g,isAsk:v,bidCumTotal:s[f],askCumTotal:d[f],bidCumCost:l[f],askCumCost:p[f]}})}function Li({info:e}){let{t}=useTranslation(),n=e.isBid?qn:jn,o=e.leftPct>65?void 0:`${e.leftPct}%`,r=e.leftPct>65?`${100-e.leftPct}%`:void 0;return jsxs("div",{style:{position:"absolute",top:8,left:o,right:r,zIndex:10,background:"rgba(17,24,39,0.95)",border:"1px solid rgba(255,255,255,0.08)",borderRadius:8,padding:"8px 12px",fontSize:12,color:"#f9fafb",minWidth:140,pointerEvents:"none"},children:[jsx("div",{style:{marginBottom:4,fontWeight:600},children:t("predict.orderBook.depthToPrice",{price:e.priceCents})}),jsx("div",{style:{color:n},children:t("predict.orderBook.depthContracts",{amount:it(Math.round(e.cumTotal))})}),jsxs("div",{style:{color:n},children:["$",it(Math.round(e.cumCost))]})]})}var Oi=memo(function({slot:t,onEnter:n,onLeave:o}){let r=useRef(null),i=t.isBid||t.isAsk,s=t.isBid?qn:t.isAsk?jn:void 0;return jsx("div",{style:{position:"absolute",left:`${t.priceCents}%`,width:"1%",height:"100%",boxSizing:"border-box",borderRight:t.priceCents<100?"1px solid transparent":"none",cursor:i?"crosshair":"default"},onMouseEnter:()=>n(t,r.current),onMouseLeave:o,children:i&&jsx("div",{ref:r,style:{position:"absolute",bottom:0,left:0,width:"100%",height:`${t.displayHeight*100}%`,backgroundColor:s,opacity:t.opacity}})})}),Ii=[0,10,20,30,40,50,60,70,80,90,100];function _i(){return jsx("div",{className:"relative flex h-6 items-center border-b border-t border-border px-1",style:{background:"rgba(0,0,0,0.15)"},children:Ii.map(e=>jsx("span",{className:"absolute text-neutral font-normal",style:{fontSize:10,left:`${e}%`,transform:e===0?"translateX(0px)":e===100?"translateX(-100%)":"translateX(-50%)"},children:e},e))})}function Gn({bids:e,asks:t}){let{t:n}=useTranslation(),o=useMemo(()=>Ri(e,t),[e,t]),r=useMemo(()=>{let p=e.length>0?Math.max(...e.map(m=>m.price)):0,u=t.length>0?Math.min(...t.map(m=>m.price)):1;return Math.round((p+u)/2*100)},[e,t]),i=useMemo(()=>o.some(p=>p.isBid||p.isAsk),[o]),[s,l]=useState(null),a=useRef(null),c=useCallback((p,u)=>{a.current&&(a.current.style.filter=""),u?(u.style.filter="brightness(1.5)",a.current=u):a.current=null,p.isBid||p.isAsk?l({priceCents:p.priceCents,isBid:p.isBid,cumTotal:p.isBid?p.bidCumTotal:p.askCumTotal,cumCost:p.isBid?p.bidCumCost:p.askCumCost,leftPct:p.priceCents}):l(null);},[]),d=useCallback(()=>{a.current&&(a.current.style.filter="",a.current=null),l(null);},[]);return i?jsxs("div",{style:{display:"flex",flexDirection:"column",width:"100%",height:"100%",userSelect:"none",overflow:"hidden"},children:[jsxs("div",{style:{flex:1,position:"relative",width:"100%",overflow:"hidden"},children:[r>0&&jsx("div",{style:{position:"absolute",left:`${r}%`,top:0,bottom:0,width:1,backgroundImage:"repeating-linear-gradient(to bottom, #6b7280 0, #6b7280 4px, transparent 4px, transparent 8px)",zIndex:1,pointerEvents:"none"}}),s&&jsx(Li,{info:s}),o.map(p=>jsx(Oi,{slot:p,onEnter:c,onLeave:d},p.priceCents))]}),jsx(_i,{})]}):jsx("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#6b7280",fontSize:13},children:n("predict.orderBook.noData")})}function br(e){let t=e*100,n=Math.round(t*10)/10;return Number.isInteger(n)?`${n}\xA2`:`${n.toFixed(1)}\xA2`}function Xn(){let{t:e}=useTranslation();return jsxs("div",{className:"flex items-center justify-center gap-x-2 h-full text-neutral text-xs",children:[jsx(Spinner,{size:"sm"}),jsx("span",{children:e("predict.orderBook.loading")})]})}function eo({market:e,outcome:t="yes",onTradeAction:n}){let{t:o}=useTranslation(),[r,i]=useState("depth"),s=t==="no",l=e.source,{data:a,isLoading:c}=useOrderbook({slug:e.slug,source:l}),d=useMemo(()=>((s?a?.asks:a?.bids)??[]).map(v=>({price:s?1-v.price:v.price,quantity:v.size})),[a?.bids,a?.asks,s]),p=useMemo(()=>((s?a?.bids:a?.asks)??[]).map(v=>({price:s?1-v.price:v.price,quantity:v.size})),[a?.bids,a?.asks,s]),u=useMemo(()=>d.length>0?Math.max(...d.map(g=>g.price)):null,[d]),m=useMemo(()=>p.length>0?Math.min(...p.map(g=>g.price)):null,[p]),f=useMemo(()=>{if(u==null||m==null)return null;let g=(m-u)*100;return Math.round(g*10)/10},[u,m]);return jsxs("div",{className:"flex flex-col h-[262px]",children:[jsxs("div",{className:"flex h-9 items-center border-b border-border px-1 text-xs",children:[jsx("span",{className:"flex-1 text-left text-neutral",children:f!=null?`${o("predict.orderBook.spread")}: ${Number.isInteger(f)?`${f}\xA2`:`${f.toFixed(1)}\xA2`}`:null}),jsxs("span",{className:"flex flex-1 items-center justify-center gap-x-1 whitespace-nowrap",children:[u!=null&&jsxs("span",{style:{color:"var(--color-bullish)"},children:[o("predict.trade.bestBid"),": ",br(u)]}),u!=null&&m!=null&&jsx("span",{className:"text-neutral",children:"|"}),m!=null&&jsxs("span",{style:{color:"var(--color-bearish)"},children:[o("predict.trade.bestAsk"),": ",br(m)]})]}),jsx("div",{className:"flex flex-1 justify-end",children:jsx("button",{type:"button",title:r==="depth"?"Orderbook":"Depth chart",onClick:()=>i(g=>g==="depth"?"table":"depth"),className:"flex items-center text-neutral transition-colors cursor-pointer hover:text-foreground",children:r==="depth"?jsx(OrderbookTableIcon,{className:"h-4 w-4"}):jsx(OrderbookDepthIcon,{className:"h-4 w-4"})})})]}),jsxs("div",{className:"flex-1 min-h-0 overflow-hidden",children:[r==="depth"&&jsx(Fragment,{children:c?jsx(Xn,{}):jsx(Gn,{bids:d,asks:p})}),r==="table"&&jsx(Fragment,{children:c?jsx(Xn,{}):jsx(Ui,{bids:d,asks:p,bestBid:u??void 0,bestAsk:m??void 0,spread:f??void 0})})]})]})}var Qn=8;function Ui({bids:e,asks:t,spread:n}){let{t:o}=useTranslation(),r=useMemo(()=>[...t].sort((a,c)=>a.price-c.price).slice(0,Qn).reverse(),[t]),i=useMemo(()=>[...e].sort((a,c)=>c.price-a.price).slice(0,Qn),[e]),s=useMemo(()=>{let a=[...r,...i].map(c=>c.quantity);return Math.max(...a,1)},[r,i]);return r.length===0&&i.length===0?jsx("div",{className:"flex items-center justify-center h-full text-xs text-neutral",children:o("predict.orderBook.empty")}):jsxs("div",{className:"flex flex-col h-full overflow-y-auto text-xs font-mono select-none",children:[r.map(a=>jsx(Jn,{price:a.price,quantity:a.quantity,side:"ask",maxQty:s},`ask-${a.price}`)),jsx("div",{className:"flex items-center justify-center gap-x-2 py-1 border-y border-border text-neutral text-[10px]",children:n!=null&&jsxs("span",{children:[o("predict.orderBook.spread"),":"," ",Number.isInteger(n)?`${n}\xA2`:`${n.toFixed(1)}\xA2`]})}),i.map(a=>jsx(Jn,{price:a.price,quantity:a.quantity,side:"bid",maxQty:s},`bid-${a.price}`)),jsxs("div",{className:"grid grid-cols-3 px-2 pt-2 pb-0.5 text-[10px] text-neutral border-t border-border",children:[jsx("span",{children:o("predict.orderBook.price")}),jsx("span",{className:"text-center",children:o("predict.orderBook.contracts")}),jsx("span",{className:"text-right",children:o("predict.orderBook.total")})]})]})}function Jn({price:e,quantity:t,side:n,maxQty:o}){let r=n==="ask",i=Math.min(t/o*100,100),s=r?"bg-bearish/10":"bg-bullish/10",l=r?"text-bearish":"text-bullish",a=it(Math.round(t)),c=Math.round(t*e),d=`$${it(c)}`;return jsxs("div",{className:"relative grid grid-cols-3 px-2 py-1 hover:bg-content2 transition-colors cursor-default",children:[jsx("div",{className:`absolute inset-y-0 left-0 ${s} transition-[width] duration-200`,style:{width:`${i}%`}}),jsx("span",{className:`relative z-10 ${l}`,children:br(e)}),jsx("span",{className:"relative z-10 text-foreground text-center",children:a}),jsx("span",{className:"relative z-10 text-foreground text-right",children:d})]})}var Nr=class extends Component{state={error:null};static getDerivedStateFromError(t){return {error:t}}componentDidCatch(t,n){}render(){return this.state.error?jsxs("div",{style:{height:this.props.fallbackHeight??320,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:8,color:"#6b7280",fontSize:13},children:[jsx("span",{children:"Chart unavailable"}),jsx("span",{style:{fontSize:11,opacity:.7},children:this.state.error.message})]}):this.props.children}},Rt=4,to=["#22d3ee","#a3e635","#f97316","#f472b6","#a78bfa"];function Ji(e,t){let n=new Date(e);return t===ChartRange.ONE_DAY?n.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:false}):n.toLocaleDateString("en-US",{month:"short",day:"numeric"})}function Zi(e,t){let n=new Date(e);return t===ChartRange.ONE_DAY?n.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:false}):t===ChartRange.ONE_WEEK?n.toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:false}):n.toLocaleDateString("en-US",{month:"short",day:"numeric"})}function ro(e){return `${(e*100).toFixed(2)}%`}var el=[{range:ChartRange.ONE_DAY,label:"1D"},{range:ChartRange.ONE_WEEK,label:"1W"},{range:ChartRange.ONE_MONTH,label:"1M"},{range:ChartRange.ALL,label:"ALL"}];function tl({value:e,onChange:t}){return jsx("div",{style:{display:"flex",alignItems:"center",gap:2},children:el.map(({range:n,label:o})=>{let r=n===e;return jsx("button",{onClick:()=>t(n),style:{padding:"2px 8px",border:"none",background:"transparent",color:r?"#f9fafb":"#6b7280",fontWeight:r?700:400,fontSize:12,cursor:"pointer",borderRadius:4,letterSpacing:"0.02em",transition:"color 0.15s",userSelect:"none"},children:o},n)})})}function rl(){let e=useRef(null),t=useRef(null),n=useCallback(r=>{let i=e.current,s=t.current;if(!i||!s)return;let l=i.getBoundingClientRect(),a=(r.clientX-l.left)/l.width*100;s.style.background=`linear-gradient(to right, transparent ${a}%, rgba(0,0,0,0.55) ${a}%)`,s.style.opacity="1";},[]),o=useCallback(()=>{t.current&&(t.current.style.opacity="0");},[]);return {wrapperRef:e,overlayRef:t,onMouseMove:n,onMouseLeave:o}}function nl({active:e,payload:t,label:n,labelMap:o,allSeries:r,range:i}){if(!e||!r?.length)return null;let s=new Map;t?.forEach(a=>s.set(a.dataKey,a));let l=r.map(a=>s.get(a.slug)??{dataKey:a.slug,value:void 0,stroke:a.color,color:a.color});return jsxs("div",{style:{background:"rgba(10,10,10,0.92)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:8,padding:"8px 12px",minWidth:180,backdropFilter:"blur(8px)",fontSize:12},children:[jsx("div",{style:{color:"#9ca3af",marginBottom:6,fontWeight:500},children:typeof n=="number"?Zi(n,i):n}),l.map(a=>jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:3},children:[jsx("span",{style:{display:"inline-block",width:3,height:14,borderRadius:2,background:a.stroke??a.color,flexShrink:0}}),jsx("span",{style:{color:"#9ca3af",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:120},children:o.get(a.dataKey)??a.dataKey}),jsx("span",{style:{color:"#f9fafb",fontWeight:700,fontVariantNumeric:"tabular-nums"},children:a.value!=null?ro(a.value):"--"})]},a.dataKey))]})}function ol({markets:e,selectedSlugs:t,colorMap:n,onToggle:o}){let[r,i]=useState(false),s=useRef(null);useEffect(()=>{if(!r)return;function c(d){s.current&&!s.current.contains(d.target)&&i(false);}return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[r]);let l=t.length>=Rt,a=jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flex:1,minWidth:0},children:[jsx("div",{style:{display:"flex",gap:3,flexShrink:0},children:t.map(c=>jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:n.get(c)??"#6b7280",display:"inline-block"}},c))}),jsx("span",{style:{color:"#e5e7eb",fontSize:12,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.length===1?(()=>{let c=e.find(d=>d.slug===t[0]);return c?.outcomes?.[0]?.label??c?.question??"1 market"})():`${t.length} / ${e.length} markets`})]});return jsxs("div",{ref:s,style:{position:"relative",display:"inline-block",width:200},children:[jsxs("button",{onClick:()=>i(c=>!c),style:{display:"inline-flex",alignItems:"center",gap:6,padding:"5px 10px",borderRadius:8,border:"1px solid rgba(255,255,255,0.12)",background:"rgba(255,255,255,0.05)",cursor:"pointer",width:"100%",userSelect:"none"},children:[a,jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",style:{flexShrink:0,transform:r?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.15s",color:"#6b7280"},children:jsx("path",{d:"M2 4l4 4 4-4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]}),r&&jsxs("div",{style:{position:"absolute",top:"calc(100% + 4px)",left:0,zIndex:50,background:"#111827",border:"1px solid rgba(255,255,255,0.1)",borderRadius:10,boxShadow:"0 8px 24px rgba(0,0,0,0.5)",minWidth:260,maxWidth:360,maxHeight:320,overflowY:"auto",padding:"6px 0"},children:[jsxs("div",{style:{padding:"4px 12px 8px",fontSize:11,color:"#6b7280",borderBottom:"1px solid rgba(255,255,255,0.06)",marginBottom:4},children:["Select up to ",Rt," markets"]}),e.map(c=>{let d=t.includes(c.slug),p=!d&&l,u=d&&t.length===1,m=n.get(c.slug)??"#6b7280",f=c.outcomes.find(v=>v.label.toLowerCase()==="yes")??c.outcomes[0],g=f?.price!=null?`${Math.round(f.price*100)}%`:null;return jsxs("button",{onClick:()=>{u||p||o(c.slug);},style:{display:"flex",alignItems:"center",gap:10,width:"100%",padding:"7px 12px",border:"none",background:d?"rgba(255,255,255,0.05)":"transparent",cursor:p||u?"not-allowed":"pointer",opacity:p?.35:1,textAlign:"left",transition:"background 0.1s"},onMouseEnter:v=>{!p&&!u&&(v.currentTarget.style.background="rgba(255,255,255,0.07)");},onMouseLeave:v=>{v.currentTarget.style.background=d?"rgba(255,255,255,0.05)":"transparent";},children:[jsx("span",{style:{width:16,height:16,borderRadius:4,border:d?`2px solid ${m}`:"2px solid rgba(255,255,255,0.2)",background:d?`${m}30`:"transparent",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center"},children:d&&jsx("svg",{width:"9",height:"7",viewBox:"0 0 9 7",fill:"none",children:jsx("path",{d:"M1 3.5L3.5 6L8 1",stroke:m,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:m,flexShrink:0}}),jsx("span",{style:{color:d?"#f9fafb":"#9ca3af",fontSize:12,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c.outcomes?.[0]?.label??c.question}),g&&jsx("span",{style:{color:m,fontWeight:700,fontSize:12,flexShrink:0},children:g})]},c.slug)})]})]})}function sl({series:e,colorMap:t,displayValues:n}){return jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px 24px",padding:"0 2px"},children:e.map(o=>{let r=t.get(o.marketSlug)??"#6b7280",i=n.get(o.marketSlug);return jsxs("div",{style:{display:"inline-flex",alignItems:"flex-start",gap:6},children:[jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:r,flexShrink:0,marginTop:3}}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:1},children:[jsx("span",{style:{color:"#9ca3af",fontSize:12,lineHeight:"17px",whiteSpace:"nowrap"},children:o.label}),jsx("span",{style:{color:"#f9fafb",fontSize:14,fontWeight:700,lineHeight:"20px",fontVariantNumeric:"tabular-nums"},children:i!=null?ro(i):"--"})]})]},o.marketSlug)})})}function al(e){let t=Math.floor(e.length/2);return e.length%2===1?e[t]:(e[t-1]+e[t])/2}function il(e,t){if(e.length<=t)return e;let n=[],o=e.length/t;for(let r=0;r<t;r++){let i=Math.floor(r*o),s=Math.min(Math.floor((r+1)*o),e.length),l=e.slice(i,s),a=l.map(c=>c.price).sort((c,d)=>c-d);n.push({timestamp:l[l.length-1].timestamp,price:al(a)});}return n}function ll(e,t=200){if(e.length===0)return [];let n=e.map(l=>({...l,data:il(l.data,t)})),o=new Set;n.forEach(l=>l.data.forEach(a=>o.add(a.timestamp)));let r=Array.from(o).sort((l,a)=>l-a),i=n.map(l=>{let a=new Map;return l.data.forEach(c=>a.set(c.timestamp,c.price)),{slug:l.marketSlug,map:a}}),s=new Map;return r.map(l=>{let a={timestamp:l};return i.forEach(({slug:c,map:d})=>{let p=d.get(l);if(p!==void 0)s.set(c,p),a[c]=p;else {let u=s.get(c);u!==void 0&&(a[c]=u);}}),a})}function no(e){return jsx(Nr,{children:jsx(cl,{...e})})}function cl({event:e,isLoading:t,className:n,volume:o}){let r=useMemo(()=>(e.markets??[]).filter(S=>S.status==="open"),[e.markets]),i=useMemo(()=>[...r].sort((S,E)=>{let I=y=>(y.outcomes.find($=>$.label.toLowerCase()==="yes")??y.outcomes[0])?.price??0;return I(E)-I(S)}),[r]),[s,l]=useState(()=>i.slice(0,Rt).map(S=>S.slug)),[a,c]=useState(ht),d=useMemo(()=>{let S=new Map;return s.forEach((E,I)=>{S.set(E,to[I%to.length]);}),S},[s]),p=useMemo(()=>r.filter(S=>s.includes(S.slug)),[r,s]),{series:u,isLoading:m}=useMarketHistory(p,a),f=t||m,g=useMemo(()=>{if(u.length>0&&u.some(I=>I.data.length>0))return u;let S=Date.now(),E=864e5;return p.map(I=>{let $=(I.outcomes?.find(q=>q.label.toLowerCase()==="yes")??I.outcomes?.[0])?.price??.5;return {marketSlug:I.slug,label:I.outcomes?.[0]?.label??I.question,data:[{timestamp:S-7*E,price:$},{timestamp:S,price:$}]}})},[u,p]),v=useMemo(()=>a===ChartRange.ONE_DAY?96:a===ChartRange.ONE_WEEK?168:a===ChartRange.ONE_MONTH?180:300,[a]),h=useMemo(()=>ll(g,v),[g,v]),D=useMemo(()=>{if(h.length===0)return [0,1];let S=1/0,E=-1/0;if(s.forEach(y=>{h.forEach($=>{let q=$[y];q!=null&&(q<S&&(S=q),q>E&&(E=q));});}),!isFinite(S))return [0,1];let I=Math.max((E-S)*.15,.05);return [Math.max(0,S-I),Math.min(1,E+I)]},[h,s]),T=useMemo(()=>{let S=new Map;return g.forEach(E=>{E.data.length>0&&S.set(E.marketSlug,E.data[E.data.length-1].price);}),S},[g]),M=useMemo(()=>{let S=new Map;return g.forEach(E=>S.set(E.marketSlug,E.label)),S},[g]),O=useMemo(()=>g.map(S=>({slug:S.marketSlug,color:d.get(S.marketSlug)??"#6b7280"})),[g,d]),{wrapperRef:Z,overlayRef:R,onMouseMove:ie,onMouseLeave:K}=rl(),fe=useCallback(S=>{l(E=>E.includes(S)?E.length<=1?E:E.filter(I=>I!==S):E.length>=Rt?E:[...E,S]);},[]),[Me,X]=useState(null),Q=useRef(null),le=useRef(""),he=useRef(0),be=!f&&h.length>0;return jsxs("div",{className:n,style:{display:"flex",flexDirection:"column",gap:12},children:[jsx(sl,{series:g,colorMap:d,displayValues:Me??T}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:0},children:[jsx("div",{ref:Z,style:{height:300,width:"100%",userSelect:"none",position:"relative"},onMouseMove:be?S=>{ie(S),cancelAnimationFrame(he.current),he.current=requestAnimationFrame(()=>{X(Q.current);});}:void 0,onMouseLeave:be?()=>{K(),cancelAnimationFrame(he.current),le.current="",Q.current=null,X(null);}:void 0,children:f?jsx("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:jsx("div",{style:{width:28,height:28,borderRadius:"50%",border:"2.5px solid #22d3ee",borderTopColor:"transparent",animation:"spin 0.7s linear infinite"}})}):h.length===0?jsx("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#6b7280",fontSize:13},children:"No price history data"}):jsxs(Fragment,{children:[jsx("div",{ref:R,style:{position:"absolute",inset:0,opacity:0,pointerEvents:"none",zIndex:1}}),jsx(ResponsiveContainer,{width:"100%",height:"100%",children:jsxs(LineChart,{data:h,margin:{top:8,right:16,left:0,bottom:0},children:[jsx(CartesianGrid,{horizontal:true,vertical:false,strokeDasharray:"3 3",stroke:"#374151",opacity:.5}),jsx(XAxis,{dataKey:"timestamp",type:"number",scale:"time",domain:["dataMin","dataMax"],tickFormatter:S=>Ji(S,a),axisLine:false,tickLine:false,tick:{fill:"#6b7280",fontSize:11},minTickGap:70}),jsx(YAxis,{domain:D,tickFormatter:S=>`${Math.round(S*100)}%`,axisLine:false,tickLine:false,tick:{fill:"#6b7280",fontSize:11},width:40,tickCount:6}),jsx(Tooltip,{content:S=>{let E=S;if(E.active&&E.payload?.length){let I=E.payload.map(y=>`${y.dataKey}:${y.value}`).join(",");if(I!==le.current){le.current=I;let y=new Map;E.payload.forEach($=>{$.value!=null&&y.set($.dataKey,$.value);}),Q.current=y;}}return jsx(nl,{...E,labelMap:M,allSeries:O,range:a})},cursor:{stroke:"#4b5563",strokeWidth:1,strokeDasharray:"4 4"},wrapperStyle:{zIndex:2},isAnimationActive:false}),g.map(S=>{let E=d.get(S.marketSlug)??"#6b7280";return jsx(Line,{type:"linear",dataKey:S.marketSlug,stroke:E,strokeWidth:2,strokeLinejoin:"round",strokeLinecap:"round",dot:false,activeDot:{r:4.5,strokeWidth:2,stroke:"rgba(10,10,10,0.8)",fill:E},connectNulls:true,isAnimationActive:false},S.marketSlug)}),Me==null&&h.length>0&&g.map(S=>{let E=h[h.length-1],I=E[S.marketSlug];if(I==null)return null;let y=d.get(S.marketSlug)??"#6b7280";return jsx(ReferenceDot,{x:E.timestamp,y:I,ifOverflow:"extendDomain",shape:$=>{let{cx:q,cy:z}=$;return q==null||z==null?jsx("g",{}):jsxs("g",{children:[jsxs("circle",{cx:q,cy:z,r:6,fill:y,opacity:.3,children:[jsx("animate",{attributeName:"r",values:"4;9;4",dur:"2s",repeatCount:"indefinite"}),jsx("animate",{attributeName:"opacity",values:"0.4;0.05;0.4",dur:"2s",repeatCount:"indefinite"})]}),jsx("circle",{cx:q,cy:z,r:3.5,fill:y})]})}},`pulse-${S.marketSlug}`)})]})})]})}),jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"6px 8px",marginTop:6},children:[o!=null&&o>0&&jsxs("span",{style:{color:"#6b7280",fontSize:12},children:["$",Math.round(o).toLocaleString()," vol"]}),jsx("div",{style:{flex:1,minWidth:0}}),jsx(tl,{value:a,onChange:c}),i.length>1&&jsx("div",{style:{width:"100%",display:"flex",alignItems:"center"},children:jsx(ol,{markets:i,selectedSlugs:s,colorMap:d,onToggle:fe})})]})]})]})}function ct(e){return e.outcomes[0]?.best_ask??e.outcomes[0]?.price??0}function wl(e){return `${parseFloat((e*100).toFixed(2))}%`}function oo(e){let t=e*100;return t<1&&t>0?"< 1":parseFloat(t.toFixed(2)).toString()}function Lt(e){return e.outcomes?.[0]?.label??e.question}function kl(e){switch(e){case "polymarket":return "Polymarket";case "dflow":return "Kalshi";default:return e}}function lt(e){if(!e)return "\u2014";let t=new Date(e);if(isNaN(t.getTime()))return "\u2014";let n=t.toLocaleString("default",{month:"short"}),o=t.getDate(),r=t.getFullYear(),i=t.getHours().toString().padStart(2,"0"),s=t.getMinutes().toString().padStart(2,"0");return `${n} ${o}, ${r} ${i}:${s}`}function so(e){let[t,n]=useState(Date.now());if(useEffect(()=>{if(!e)return;let d=setInterval(()=>n(Date.now()),1e3);return ()=>clearInterval(d)},[e]),!e)return null;let o=new Date(e).getTime();if(isNaN(o))return null;let r=o-t;if(r<=0)return null;let i=Math.floor(r/864e5),s=Math.floor(r%864e5/36e5),l=Math.floor(r%36e5/6e4),a=Math.floor(r%6e4/1e3),c=[];return i>0&&c.push(`${i}d`),c.push(`${String(s).padStart(2,"0")}h`),c.push(`${String(l).padStart(2,"0")}m`),c.push(`${String(a).padStart(2,"0")}s`),c.join(" ")}function ao(e){if(!e)return null;let t=new Date(e);if(isNaN(t.getTime()))return null;let n=t.getHours().toString().padStart(2,"0"),o=t.getMinutes().toString().padStart(2,"0"),r=(t.getMonth()+1).toString().padStart(2,"0"),i=t.getDate().toString().padStart(2,"0"),s=t.getFullYear(),l=-t.getTimezoneOffset(),a=l>=0?"+":"-",c=String(Math.abs(Math.floor(l/60))).padStart(2,"0");return `${n}:${o} ${r}/${i}/${s} (${a}${c})`}function co({event:e,onTradeAction:t}){let{t:n}=useTranslation(),{ref:o,isCollapsed:r}=useScrollCollapse(),i=useMemo(()=>{let p=[...e.markets||[]],u=p.filter(f=>f.status==="open").sort((f,g)=>ct(g)-ct(f)),m=p.filter(f=>f.status!=="open").sort((f,g)=>ct(g)-ct(f));return [...u,...m]},[e.markets]),s=e.status==="closed"||e.status==="voided",l=so(s?void 0:e.start_at),a=so(s?void 0:e.end_at),c=ao(e.start_at),d=ao(e.end_at);return jsxs("div",{className:"w-full flex flex-col gap-y-4 lg:gap-y-6",children:[jsxs("div",{ref:o,className:`sticky top-0 z-30 flex items-center backdrop-blur-md transition-all duration-300 ${r?"h-14 lg:h-16 gap-x-2 py-2 px-1 lg:px-4 -mx-1 lg:-mx-4 shadow-sm":"h-16 lg:h-20 gap-x-2 lg:gap-x-4"}`,children:[jsx(Avatar,{src:e.image_url||void 0,name:e.title||"Event",radius:"lg",classNames:{base:"bg-transparent"},className:`flex-shrink-0 transition-all duration-300 ${r?"!h-10 !w-10 lg:!h-12 lg:!w-12":"!h-16 !w-16 lg:!h-20 lg:!w-20"}`}),jsxs("div",{className:"flex flex-col gap-0.5 min-w-0 flex-1",children:[!r&&jsxs("div",{className:"flex items-center gap-1.5",children:[e.tags?.slice(0,3).map((p,u)=>jsxs(Fragment$1,{children:[u>0&&jsx("span",{className:"text-sm text-neutral/50",children:"\xB7"}),jsx("span",{className:"text-sm text-neutral truncate",children:p.label})]},p.slug)),jsx(Tl,{source:e.source})]}),jsx("span",{className:`font-semibold truncate transition-all duration-300 ${r?"text-sm lg:text-base":"text-lg lg:text-xl"}`,children:e.title})]})]}),(l||a||s)&&jsx("div",{className:"flex items-center gap-x-2 text-xs lg:text-sm font-mono",children:s?d&&jsx("span",{className:"text-neutral",children:n("predict.event.endedAt",{time:d})}):l?jsxs(Fragment,{children:[jsx("span",{className:"text-foreground",children:n("predict.event.beginsIn",{time:l})}),c&&jsxs(Fragment,{children:[jsx("span",{className:"text-neutral/50",children:"\xB7"}),jsx("span",{className:"text-neutral",children:c})]})]}):a?jsxs(Fragment,{children:[jsx("span",{className:"text-foreground",children:n("predict.event.endsIn",{time:a})}),d&&jsxs(Fragment,{children:[jsx("span",{className:"text-neutral/50",children:"\xB7"}),jsx("span",{className:"text-neutral",children:d})]})]}):null}),jsx(no,{event:e,volume:e.volume??void 0}),jsx(Pl,{markets:i,onTradeAction:t}),jsx(Cl,{markets:i,event:e})]})}var io=5;function Pl({markets:e,onTradeAction:t}){let{t:n}=useTranslation(),{isMobile:o}=useScreen(),[r,i]=useState(false),[s,l]=useState(null),a=e.find(g=>g.status==="open")?.slug,[c,d]=useState(a?`${a}:yes`:null);if(e.length===0)return null;let p=e.length>io,u=r?e:e.slice(0,io),m=g=>{l(v=>v===g?null:g);},f=(g,v,h)=>{d(`${g.slug}:${v}`),o||l(g.slug),t?.(g,v,h);};return jsxs("div",{className:"flex flex-col",children:[jsxs("table",{className:"w-full border-collapse",children:[jsx("thead",{children:jsxs("tr",{children:[jsx("th",{}),jsx("th",{className:"py-2 text-left text-xs text-neutral font-normal lg:text-center lg:text-sm",children:n("predict.market.table.chance")}),jsx("th",{})]})}),jsx("tbody",{children:u.map(g=>{let v=ct(g),h=g.outcomes[1]?.best_ask??g.outcomes[1]?.price,D=s===g.slug;return jsx(El,{market:g,yesPrice:v,noPrice:h??void 0,activeYes:c===`${g.slug}:yes`,activeNo:c===`${g.slug}:no`,isExpanded:D,onToggleExpand:()=>m(g.slug),onTradeAction:f},g.slug)})})]}),p&&jsxs("button",{type:"button",onClick:()=>i(g=>!g),className:"flex w-full items-center justify-start gap-x-2 py-2 pl-1 text-xs text-neutral lg:pl-2 lg:text-sm cursor-pointer hover:text-foreground transition-colors",children:[jsx("span",{children:n(r?"predict.event.rules.collapse":"predict.event.moreMarketsLabel")}),jsx(ChevronDownIcon,{className:cn$1("h-4 w-4 transition-transform",r&&"rotate-180")})]})]})}function El({market:e,yesPrice:t,noPrice:n,activeYes:o,activeNo:r,isExpanded:i,onToggleExpand:s,onTradeAction:l}){let{t:a}=useTranslation(),c=e.status==="open",d=e.volume?`$${Math.round(e.volume).toLocaleString("en-US")} vol`:void 0;return jsxs(Fragment,{children:[jsxs("tr",{className:"cursor-pointer border-b border-border text-xs hover:bg-content2 lg:text-base",onClick:s,role:"button",tabIndex:0,onKeyDown:p=>{(p.key==="Enter"||p.key===" ")&&(p.preventDefault(),s());},children:[jsx("td",{className:"py-2 pl-1 lg:pl-2",children:jsxs("div",{className:"flex items-center gap-x-1 lg:gap-x-2",children:[e.image_url&&jsx(Avatar,{src:e.image_url,name:Lt(e)?.[0]||"?",radius:"lg",className:"size-5 shrink-0 lg:size-8",imgProps:{className:"object-cover"}}),jsxs("div",{className:"flex flex-col",children:[jsx("span",{className:"text-foreground truncate max-w-[200px] lg:max-w-[300px]",children:Lt(e)}),d&&jsx("span",{className:"text-[8px] text-neutral lg:text-xxs",children:d})]})]})}),jsx("td",{className:"py-2 text-left text-foreground lg:text-center",children:wl(t)}),jsx("td",{className:"py-2 pr-1 lg:pr-2",children:c?jsxs("div",{className:"flex items-center justify-end gap-x-2",children:[jsx("button",{type:"button",className:cn$1("flex min-w-16 items-center justify-center whitespace-nowrap rounded-lg p-2 lg:min-w-24 cursor-pointer hover:opacity-80 transition-all",o?"bg-primary text-primary-foreground":"bg-primary/10 text-primary"),onClick:p=>{p.stopPropagation(),l?.(e,"yes","buy");},children:a("predict.market.action.yes",{price:oo(t)})}),jsx("button",{type:"button",className:cn$1("flex min-w-16 items-center justify-center whitespace-nowrap rounded-lg p-2 lg:min-w-24 cursor-pointer hover:opacity-80 transition-all",r?"bg-secondary text-secondary-foreground":"bg-secondary/10 text-secondary"),onClick:p=>{p.stopPropagation(),l?.(e,"no","buy");},children:n!=null?a("predict.market.action.no",{price:oo(n)}):a("predict.market.no")})]}):jsx("div",{className:"flex items-center justify-end",children:jsx("span",{className:cn$1("inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium",e.status==="closed"?"bg-neutral/10 text-neutral":e.status==="voided"?"bg-warning/10 text-warning":"bg-primary/10 text-primary"),children:e.status==="closed"?a("predict.event.status.closed"):e.status==="voided"?a("predict.event.status.voided"):a("predict.event.status.pending")})})})]}),i&&jsx("tr",{children:jsx("td",{colSpan:3,className:"pb-3",children:jsx("div",{className:"max-h-100 overflow-y-auto",children:jsx(eo,{market:e,outcome:r?"no":"yes",onTradeAction:l})})})})]})}function Cl({markets:e,event:t}){let{t:n}=useTranslation(),[o,r]=useState(false),[i,s]=useState(false),[l,a]=useState(0),c=e.filter(m=>m.rules&&m.rules.length>0||m.description);if(c.length===0)return null;let d=c[l]??c[0],p=d.rules&&d.rules.length>0?d.rules.join(`
|
|
19
|
+
`;function Rn({event:e,href:t,LinkComponent:n,onSelect:o,onSelectOutcome:r,onHover:i}){let[s,l]=useState(null),a=e.markets??[],c=useMemo(()=>a.length>2?[...a].sort((M,O)=>(O.outcomes?.[0]?.price??0)-(M.outcomes?.[0]?.price??0)):a,[a]),d=c.filter(M=>M.status==="open"),p=c.length===1,u=d.slice(0,Sn),m=d.length-Sn,f=useMemo(()=>`$${Math.round(e.volume??0).toLocaleString("en-US")}`,[e.volume]),g=s?d.find(M=>M.slug===s)??null:null,v=!!g||p,h=()=>{v||o?.(e);},D=M=>{M.stopPropagation(),g&&(M.preventDefault(),l(null));},T=M=>{M.stopPropagation(),t||(M.preventDefault(),o?.(e));};return jsxs("div",{className:cn$1("group flex h-full w-full flex-col rounded-xl","min-h-52 border border-border/90 bg-background p-3","lg:min-h-72 lg:max-w-md lg:p-4","gap-y-1.5 lg:gap-y-4","transition duration-300","hover:border-primary/40 hover:shadow-card-glow","focus-within:border-primary/40 focus-within:shadow-card-glow",!v&&"cursor-pointer"),onMouseEnter:()=>i?.(e),onClick:h,children:[jsx("style",{children:Fa}),jsx(Ba,{event:e,href:t,LinkComponent:n,onClick:D,isExpanded:v}),jsx("div",{className:"flex flex-1 flex-col",children:p?jsx(Ya,{market:d[0],event:e,formattedVolume:f,href:t,LinkComponent:n,onSelect:o,onSelectOutcome:r}):g?jsx(qa,{market:g,event:e,onCollapse:()=>l(null),onSelectOutcome:r}):jsx(Ka,{displayedMarkets:u,moreCount:m,formattedVolume:f,source:e.source,href:t,LinkComponent:n,onMarketClick:M=>l(M.slug),onShowMore:T})})]})}function Ba({event:e,href:t,LinkComponent:n,onClick:o,isExpanded:r}){let i=e.start_at?Aa(e.start_at):null;return jsxs(Linkable,{href:t,LinkComponent:n,as:"button",className:"group/header flex items-center gap-x-2 lg:gap-x-4 w-full text-left cursor-pointer",onClick:o,children:[jsx(Avatar,{src:e.image_url||void 0,name:e.title||"Event",radius:"lg",className:"h-8 w-8 flex-shrink-0 transition-transform duration-300 group-hover/header:scale-110 lg:h-12 lg:w-12",classNames:{base:"bg-transparent"}}),jsxs("div",{className:"flex min-w-0 flex-1 flex-col justify-center gap-y-0.5",children:[jsx("p",{className:cn$1("min-w-0 text-sm font-semibold leading-snug text-slate-200 line-clamp-2 lg:text-base",r&&"group-hover/header:text-neutral-400"),children:e.title}),i&&jsxs("span",{className:"text-[10px] leading-4 text-neutral-500",children:["Live in ",i]})]}),jsx(Ua,{event:e})]})}function Ha(e){let t=[];if(e.status==="closed")return t.push({kind:"closed"}),t.slice(0,2);let n=e.tags?.some(r=>r.label?.toLowerCase()==="crypto"),o=e.tags?.some(r=>r.label?.toLowerCase()==="live");if(n&&e.end_at){let r=new Date(e.end_at).getTime()-Date.now(),i=300*1e3,s=900*1e3;if(r>0&&r<=s){let l=r<=i?"#ef4444":"#f59e0b";t.push({kind:"crypto-short",label:r<=i?"5m":"15m",color:l});}}return o&&t.push({kind:"live"}),t.slice(0,2)}function Ua({event:e}){let t=useMemo(()=>Ha(e),[e]);return t.length===0?null:jsx("div",{className:"flex flex-shrink-0 flex-col items-end gap-1",children:t.map((n,o)=>{switch(n.kind){case "live":return jsx($a,{},o);case "crypto-short":return jsx(Wa,{label:n.label,color:n.color},o);case "closed":return jsx(za,{},o)}})})}function $a(){let{t:e}=useTranslation();return jsxs("span",{className:"badge-shine relative inline-flex items-center gap-1 overflow-hidden rounded-md bg-[rgb(240,68,56)]/10 px-1.5 py-0.5 text-xs font-semibold text-[rgb(240,68,56)]",children:[jsx("span",{className:"h-2 w-2 animate-pulse rounded-full bg-current"}),e("predict.event.status.live")]})}function Wa({label:e,color:t}){return jsxs("span",{className:"badge-shine relative inline-flex items-center gap-1 overflow-hidden rounded-md px-1.5 py-0.5 text-xs font-semibold",style:{backgroundColor:`${t}26`,color:t},children:[jsx(TimerIcon,{className:"size-3 shrink-0"}),e]})}function za(){let{t:e}=useTranslation();return jsx("span",{className:"inline-flex items-center rounded-md bg-neutral-800/80 px-1.5 py-0.5 text-xs font-semibold text-neutral-400",children:e("predict.event.status.closed")})}function Ka({displayedMarkets:e,moreCount:t,formattedVolume:n,source:o,href:r,LinkComponent:i,onMarketClick:s,onShowMore:l}){let{t:a}=useTranslation();return jsxs(Fragment,{children:[e.length>0&&jsx("div",{className:"flex w-full flex-1 flex-col gap-y-0.5 lg:gap-y-2",children:e.map(c=>{let d=Tn(c);return jsxs("button",{type:"button",className:"flex h-9 w-full items-center justify-between gap-x-2 transition-opacity hover:cursor-pointer hover:opacity-80",onClick:p=>{p.stopPropagation(),s(c);},children:[jsx("span",{className:"min-w-0 flex-1 text-left text-xs text-slate-200 line-clamp-1 lg:text-sm",children:c.outcomes?.[0]?.label??c.question}),jsxs("div",{className:"flex items-center gap-x-2",children:[jsx("span",{className:"text-sm font-semibold text-slate-200 lg:text-lg",children:Mn(d)}),jsx(Va,{})]})]},c.slug)})}),jsxs("div",{className:"mt-auto flex items-center justify-between pt-3",children:[t>0?jsxs(Linkable,{href:r,LinkComponent:i,as:"button",className:"flex items-center gap-1 text-[10px] font-normal text-neutral-500 transition-colors hover:text-slate-200 cursor-pointer lg:text-xs",onClick:l,children:[a("predict.event.showMore"),jsx(On,{className:"h-3 w-3"})]}):jsx("div",{}),jsxs("span",{className:"inline-flex items-center gap-x-1.5 text-[10px] font-normal text-neutral-500 lg:text-xs",children:[n," ",a("predict.event.volume"),jsx(In,{source:o})]})]})]})}function Pn({bgColor:e,textColor:t,shadowColor:n,onClick:o,children:r}){return jsx("button",{type:"button",className:"flex h-12 flex-1 w-full items-center justify-center gap-x-1 overflow-hidden rounded-lg p-3 text-base font-normal hover:cursor-pointer will-change-transform [-webkit-tap-highlight-color:transparent]",style:{backgroundColor:e,color:t,"--shadow-color":n,"--shadow-offset":"4px",boxShadow:"inset 0 -1px 0 rgba(255,255,255,0.08), 0 var(--shadow-offset, 4px) 0 var(--shadow-color, rgba(0,0,0,0.22))",transition:"transform .12s, box-shadow .12s, opacity .14s"},onMouseEnter:l=>{let a=l.currentTarget;a.style.setProperty("--shadow-offset","2px"),a.style.transform="translateY(2px)";},onMouseLeave:l=>{let a=l.currentTarget;a.style.setProperty("--shadow-offset","4px"),a.style.transform="translateY(0px)";},onClick:o,children:r})}function Ln({market:e,event:t,onSelectOutcome:n,dynamicColors:o=false,labelFormat:r="action"}){let{t:i}=useTranslation(),[s,l]=o?_a(e):[ir,Cn],a=e.outcomes?.[0]?.label?.toLowerCase().trim()??"",c=e.outcomes?.[1]?.label?.toLowerCase().trim()??"",d=r==="label"&&a===c?"action":r,p=d==="label"?`${e.outcomes?.[0]?.label??"Yes"} ${wn(e)}\xA2`:i("predict.market.action.yes",{price:wn(e)}),u=d==="label"?`${e.outcomes?.[1]?.label??"No"} ${kn(e)}\xA2`:i("predict.market.action.no",{price:kn(e)});return jsxs("div",{className:"flex gap-2",children:[jsx(Pn,{bgColor:s.bg,textColor:s.text,shadowColor:s.shadow,onClick:m=>{m.stopPropagation(),n?.(t,e,"yes");},children:p}),jsx(Pn,{bgColor:l.bg,textColor:l.text,shadowColor:l.shadow,onClick:m=>{m.stopPropagation(),n?.(t,e,"no");},children:u})]})}function Va(){let{t:e}=useTranslation();return jsxs("span",{className:"inline-flex h-7 w-[85px] items-center justify-center gap-x-3 rounded-lg p-1.5 text-xs font-semibold flex-shrink-0 bg-gradient-to-r from-primary/15 to-secondary/15 lg:h-9 lg:w-24 lg:gap-x-4 lg:p-2 lg:text-sm",children:[jsx("span",{className:"text-primary",children:e("predict.market.yes")}),jsx("span",{className:"text-neutral-400",children:"/"}),jsx("span",{className:"text-secondary",children:e("predict.market.no")})]})}function Ya({market:e,event:t,formattedVolume:n,href:o,LinkComponent:r,onSelect:i,onSelectOutcome:s}){let{t:l}=useTranslation();return jsxs(Fragment,{children:[jsx("div",{className:"flex-1",children:jsx(Ln,{market:e,event:t,onSelectOutcome:s,dynamicColors:true,labelFormat:"label"})}),jsxs("div",{className:"mt-auto flex items-center justify-between pt-3",children:[jsxs(Linkable,{href:o,LinkComponent:r,as:"button",className:"flex items-center gap-1 text-[10px] font-normal text-neutral-500 transition-colors hover:text-slate-200 cursor-pointer lg:text-xs",onClick:c=>{c.stopPropagation(),o||(c.preventDefault(),i?.(t));},children:[l("predict.event.viewEvent"),jsx(On,{className:"h-3 w-3"})]}),jsxs("span",{className:"inline-flex items-center gap-x-1.5 text-[10px] font-normal text-neutral-500 lg:text-xs",children:[n," ",l("predict.event.volume"),jsx(In,{source:t.source})]})]})]})}function qa({market:e,event:t,onCollapse:n,onSelectOutcome:o}){let{t:r}=useTranslation(),i=Tn(e);return jsxs(Fragment,{children:[jsxs("div",{className:"flex-1",children:[jsxs("button",{type:"button",className:"flex h-9 w-full items-center justify-between cursor-pointer",onClick:s=>{s.stopPropagation(),n();},children:[jsx("span",{className:"min-w-0 flex-1 text-left text-xs text-slate-200 lg:text-sm",children:e.outcomes?.[0]?.label??e.question}),jsxs("div",{className:"flex items-center gap-x-1 flex-shrink-0",children:[jsx("span",{className:"text-sm font-semibold text-slate-200 lg:text-lg",children:Mn(i)}),jsx(ChevronUpIcon,{className:"h-4 w-4 text-neutral-400"})]})]}),jsx("div",{className:"mt-3",children:jsx(Ln,{market:e,event:t,onSelectOutcome:o,labelFormat:"action"})})]}),jsxs("button",{type:"button",className:"mt-auto flex items-center gap-x-1 pt-4 text-[10px] font-normal text-neutral-500 transition-colors hover:text-slate-200 cursor-pointer lg:text-xs",onClick:s=>{s.stopPropagation(),n();},children:[jsx(ja,{className:"h-3 w-3"}),r("predict.event.back")]})]})}function On({className:e}){return jsx("svg",{viewBox:"0 0 12 12",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:e,children:jsx("path",{d:"M4.5 2.5L8 6l-3.5 3.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function ja({className:e}){return jsx("svg",{viewBox:"0 0 12 12",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:e,children:jsx("path",{d:"M7.5 2.5L4 6l3.5 3.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function In({source:e}){return jsxs("span",{className:"inline-flex items-center gap-x-1 text-neutral-400",title:e==="polymarket"?"Polymarket":"Kalshi",children:[jsx("span",{className:"text-neutral-600",children:"\xB7"}),e==="polymarket"?jsx(PolymarketIcon,{className:"h-5 w-auto shrink-0"}):jsx(KalshiIcon,{className:"h-3 w-auto shrink-0"})]})}var ei=768,Dn=1024,ti=1280,ri=8,ni=224,oi=304,si=114;function ai(e){return e>=ti?4:e>=Dn?3:e>=ei?2:1}function ii(e){return e>=Dn?oi:ni}function An({events:e,hasMore:t=false,onFetchMore:n,onSelect:o,onSelectOutcome:r,getEventHref:i,LinkComponent:s,onHover:l}){let a=useRef(null),c=useRef(null),{width:d=0,height:p=0}=useResizeObserver({ref:a}),u=ai(d),m=ii(d),f=Math.ceil(e.length/u)||0,g=!t&&e.length>0,v=f+(t?1:0)+(g?1:0),h=useCallback(O=>O<f,[f]),D=useCallback(async()=>{n?.();},[n]),T=useInfiniteLoader({isRowLoaded:h,loadMoreRows:D,rowCount:v,threshold:3}),M=useCallback(()=>{c.current?.scrollToRow({index:0,behavior:"smooth"});},[]);return jsx("div",{ref:a,className:"@container w-full h-full",children:p>0&&jsx(List,{listRef:c,className:"no-scrollbar",style:{height:p},onRowsRendered:T,rowComponent:li,rowCount:v,rowHeight:O=>g&&O===v-1?si:(m),rowProps:{events:e,columnCount:u,dataRowCount:f,showEndOfList:g,totalRowCount:v,onSelect:o,onSelectOutcome:r,getEventHref:i,LinkComponent:s,onHover:l,onScrollToTop:M}})})}function li({index:e,style:t,events:n,columnCount:o,dataRowCount:r,showEndOfList:i,totalRowCount:s,onSelect:l,onSelectOutcome:a,getEventHref:c,LinkComponent:d,onHover:p,onScrollToTop:u}){if(i&&e===s-1)return jsx("div",{style:t,children:jsx(ci,{onScrollToTop:u})});if(e>=r)return jsx("div",{style:t,className:"flex justify-center items-start pt-4",children:jsx(Spinner,{size:"sm"})});let m=e*o,f=n.slice(m,m+o),g=o-f.length;return jsx("div",{style:t,children:jsxs("div",{className:"flex w-full h-full",children:[f.map(v=>v==null?null:jsx("div",{className:"flex-1 min-w-0 flex",style:{padding:ri},children:jsx(Rn,{event:v,href:c?.(v),LinkComponent:d,onSelect:l,onSelectOutcome:a,onHover:p})},v.slug)),g>0&&Array.from({length:g}).map((v,h)=>jsx("div",{style:{flex:1,minWidth:0}},`spacer-${h}`))]})})}function ci({onScrollToTop:e}){let{t}=useTranslation();return jsxs("div",{className:"flex w-full flex-col items-center justify-center gap-y-4 py-6",children:[jsxs("div",{className:"flex w-full items-center justify-center gap-x-4",children:[jsx("div",{className:"h-px w-16 bg-neutral-700"}),jsx("span",{className:"text-xs font-medium text-neutral-500",children:t("predict.event.endOfList")}),jsx("div",{className:"h-px w-16 bg-neutral-700"})]}),jsxs("button",{type:"button",className:"flex cursor-pointer items-center gap-x-1 text-xs font-medium text-neutral-400",onClick:e,children:[jsx("span",{className:"iconify size-4 ph--arrow-up-bold"}),jsx("span",{children:t("predict.event.backToTop")})]})]})}function Bn({tagSlugSelection:e,limit:t=48,status:n,sort_by:o,sort_asc:r,source:i,with_markets:s,timeRemaining:l,minVolume:a,minLiquidity:c,onSelect:d,onSelectOutcome:p,getEventHref:u,LinkComponent:m,onHover:f}){let{data:g,hasMore:v,fetchMore:h,isFetching:D}=yn({tagSlugSelection:e,limit:t,status:n,sort_by:o,sort_asc:r,source:i,with_markets:s,timeRemaining:l,minVolume:a,minLiquidity:c});return D?jsx(sr,{count:48}):jsx(An,{events:g,hasMore:v,onFetchMore:h,onSelect:d,onSelectOutcome:p,getEventHref:u,LinkComponent:m,onHover:f})}function ju({onSelect:e,onSelectOutcome:t,getEventHref:n,LinkComponent:o,onHover:r}){let[i,s]=useState({categorySlug:null,tagSlug:null}),[l,a]=useState(nr),{isOpen:c,onOpen:d,onClose:p}=useDisclosure(),{onOpen:u}=useAsyncModal(Je),m=useCallback((O,Z,R)=>{t?.(O,Z,R),u({params:{event:O,market:Z,initialOutcome:R}});},[t,u]),f=useCallback(O=>{s(O);},[]),g=useCallback(O=>{a(Z=>({...Z,sortPreset:O}));},[]),v=useCallback(O=>{a(Z=>({...Z,sortAsc:O}));},[]),h=useCallback(O=>{a(O);},[]),D=useMemo(()=>vn[l.sortPreset].sort_by,[l.sortPreset]),T=useMemo(()=>or(l),[l]),M=useMemo(()=>jsx(xn,{sortPreset:l.sortPreset,onSortChange:g,sortAsc:l.sortAsc,onSortAscChange:v,onFilterPress:d,filterCount:T}),[l.sortPreset,l.sortAsc,T,g,v,d]);return jsxs("div",{className:"flex h-full w-full max-w-[1680px] mx-auto flex-col gap-y-3",children:[jsx(Vr,{onSelect:f,trailing:M}),jsx(pn,{isOpen:c,onClose:p,value:l,onChange:h}),jsx("div",{className:"min-h-0 flex-1",children:jsx(Bn,{tagSlugSelection:i,sort_by:D,sort_asc:l.sortAsc,source:l.source,timeRemaining:l.timeRemaining,minVolume:l.minVolume,minLiquidity:l.minLiquidity,onSelect:e,onSelectOutcome:m,getEventHref:n,LinkComponent:o,onHover:r})}),jsx(yt,{})]})}var fr=40,Ct=36,st=480,gr=st-Ct;function Wn({event:e,walletAddress:t,onCancelOrder:n}){let{t:o}=useTranslation(),[r,i]=useState("positions"),s=useMemo(()=>e.markets?.map(p=>p.slug)??[],[e.markets]),{data:l}=usePositions({source:e.source,user:t??""}),a=useMemo(()=>!l?.positions||!t?0:s.length===0?l.positions.length:l.positions.filter(p=>p.market&&s.includes(p.market.slug)).length,[l?.positions,s,t]),d=[{key:"positions",label:a>0?`${o("predict.positions.title")} (${a})`:o("predict.positions.title")},{key:"orders",label:o("predict.openOrders.title")},{key:"trades",label:o("predict.tradeHistory.title")}];return jsxs("div",{className:"flex flex-col gap-y-2 mt-6 px-1 lg:px-4",children:[jsx("div",{className:"flex items-center gap-x-1 border-b border-border",children:d.map(p=>jsx("button",{type:"button",onClick:()=>i(p.key),className:cn$1("px-3 py-2 text-sm font-medium transition-colors cursor-pointer",r===p.key?"text-foreground border-b-2 border-primary":"text-neutral hover:text-foreground"),children:p.label},p.key))}),t?jsxs("div",{style:{height:st},children:[r==="positions"&&jsx(hi,{source:e.source,walletAddress:t,marketSlugs:s}),r==="orders"&&jsx(yi,{source:e.source,walletAddress:t,marketSlugs:s,onCancelOrder:n}),r==="trades"&&jsx(wi,{source:e.source,walletAddress:t})]}):jsx("div",{className:"flex items-center justify-center text-sm text-neutral",style:{height:st},children:o("predict.trade.connectWallet")})]})}function hi({source:e,walletAddress:t,marketSlugs:n}){let{t:o}=useTranslation(),{data:r,isLoading:i}=usePositions({source:e,user:t}),s=useMemo(()=>r?.positions?n.length===0?r.positions:r.positions.filter(l=>l.market&&n.includes(l.market.slug)):[],[r?.positions,n]);return i?jsx(xr,{}):s.length===0?jsx(vr,{message:o("predict.positions.empty")}):jsxs("div",{className:"flex flex-col h-full",children:[jsxs("div",{className:"flex items-center text-neutral text-xs lg:text-sm font-normal shrink-0",style:{height:Ct},children:[jsx("div",{className:"flex-[3] min-w-0 pr-2 whitespace-nowrap",children:o("predict.positions.event")}),jsx("div",{className:"flex-1 pr-2 text-right whitespace-nowrap",children:o("predict.positions.totalSize")}),jsx("div",{className:"flex-1 pr-2 text-right whitespace-nowrap",children:o("predict.positions.value")}),jsx("div",{className:"flex-1 pr-2 text-right whitespace-nowrap",children:o("predict.positions.avgPrice")}),jsx("div",{className:"flex-1 pr-2 text-right whitespace-nowrap",children:o("predict.positions.markPrice")}),jsx("div",{className:"flex-[1.5] pr-2 text-right whitespace-nowrap",children:o("predict.positions.pnl")}),jsx("div",{className:"flex-1 pr-2 text-right whitespace-nowrap",children:o("predict.positions.payoutIfRight")}),jsx("div",{className:"flex-[1.5] pr-2 text-right whitespace-nowrap",children:o("predict.positions.estSettlement")}),jsx("div",{className:"w-16 shrink-0"})]}),jsx(List,{style:{height:gr},rowComponent:bi,rowCount:s.length,rowHeight:fr,rowProps:{positions:s,closeLabel:o("predict.positions.close")}})]})}function bi({index:e,style:t,positions:n,closeLabel:o}){let r=n[e];if(!r)return null;let i=r.pnl??0,s=r.pnl_percent??0,l=r.avg_price??0,a=r.current_price??0,c=i>0?"text-success":i<0?"text-danger":"text-foreground",d=i>0?"+":"",p=r.market?.outcomes?.[0]?.label??r.market?.question??"\u2014",u=r.side,m=r.size,f=r.size*a,g=r.market?.end_at?Ei(r.market.end_at):"\u2014";return jsxs("div",{style:t,className:"flex items-center border-b border-border/50 hover:bg-content2/40 transition-colors text-xs lg:text-sm",children:[jsx("div",{className:"flex-[3] min-w-0 pr-2",children:jsxs("div",{className:"flex flex-col gap-y-0.5",children:[jsx("span",{className:"text-foreground truncate font-medium",children:p}),jsx("span",{className:cn$1("text-[10px] font-medium",u.toLowerCase()==="yes"?"text-primary":"text-secondary"),children:u})]})}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:r.size}),jsxs("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:["$",f.toFixed(2)]}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:Pt(l)}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:Pt(a)}),jsxs("div",{className:cn$1("flex-[1.5] pr-2 text-right font-mono whitespace-nowrap",c),children:[d,"$",Math.abs(i).toFixed(2),jsxs("span",{className:"text-[10px] ml-0.5 opacity-70",children:["(",d,s.toFixed(1),"%)"]})]}),jsxs("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:["$",m.toFixed(2)]}),jsx("div",{className:"flex-[1.5] pr-2 text-right text-neutral whitespace-nowrap",children:g}),jsx("div",{className:"w-16 shrink-0 text-right",children:jsx("button",{type:"button",className:"text-xs text-neutral hover:text-foreground cursor-pointer transition-colors rounded px-2 py-0.5 border border-border hover:border-foreground/40",children:o})})]})}function yi({source:e,walletAddress:t,marketSlugs:n,onCancelOrder:o}){let{t:r}=useTranslation(),{data:i,isLoading:s,fetchNextPage:l,hasNextPage:a}=useInfiniteOrders({source:e,wallet_address:t}),c=useCancelOrder(),d=useMemo(()=>{let h=i?.pages?.flatMap(M=>M.items)??[],D=new Set(["live","open","submitted","pending"]),T=h.filter(M=>D.has(M.status));return n.length>0&&(T=T.filter(M=>M.market_id&&n.includes(M.market_id))),T},[i?.pages,n]),p=useCallback(h=>{o?o(h.id):c.mutate({source:h.source,id:h.id});},[o,c]),u=d.length,m=u+(a?1:0),f=useCallback(h=>h<u,[u]),g=useCallback(async()=>{await l();},[l]),v=useInfiniteLoader({isRowLoaded:f,loadMoreRows:g,rowCount:m,threshold:5});return s?jsx(xr,{}):d.length===0&&!a?jsx(vr,{message:r("predict.openOrders.empty")}):jsxs("div",{className:"flex flex-col h-full",children:[jsxs("div",{className:"flex items-center text-neutral text-xs lg:text-sm font-normal shrink-0",style:{height:Ct},children:[jsx("div",{className:"w-16 shrink-0 pr-2",children:r("predict.openOrders.side")}),jsx("div",{className:"flex-1 pr-2",children:r("predict.openOrders.outcome")}),jsx("div",{className:"flex-1 pr-2",children:r("predict.openOrders.type")}),jsx("div",{className:"flex-1 pr-2 text-right",children:r("predict.openOrders.price")}),jsx("div",{className:"flex-1 pr-2 text-right",children:r("predict.openOrders.filled")}),jsx("div",{className:"w-20 shrink-0 pr-2",children:r("predict.openOrders.status")}),jsx("div",{className:"w-16 shrink-0"})]}),jsx(List,{style:{height:gr},onRowsRendered:v,rowComponent:Si,rowCount:m,rowHeight:fr,rowProps:{orders:d,itemCount:u,onCancel:p,isCancelling:c.isPending,cancelLabel:r("predict.openOrders.cancel")}})]})}function Si({index:e,style:t,orders:n,itemCount:o,onCancel:r,isCancelling:i,cancelLabel:s}){if(e>=o)return jsx("div",{style:t,className:"flex justify-center items-center",children:jsx(Spinner,{size:"sm"})});let l=n[e];if(!l)return null;let a=l.side==="BUY";return jsxs("div",{style:t,className:"flex items-center border-b border-border/50 text-xs lg:text-sm",children:[jsx("div",{className:"w-16 shrink-0 pr-2",children:jsx("span",{className:cn$1("inline-block rounded px-1.5 py-0.5 text-[10px] font-medium",a?"bg-primary/10 text-primary":"bg-danger/10 text-danger"),children:l.side})}),jsx("div",{className:"flex-1 pr-2 text-foreground capitalize",children:l.outcome??"\u2014"}),jsx("div",{className:"flex-1 pr-2 text-neutral capitalize",children:l.order_type??"limit"}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:l.price?Pt(parseFloat(l.price)):"\u2014"}),jsxs("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:[l.size_matched??"0","/",l.original_size??"\u2014"]}),jsx("div",{className:"w-20 shrink-0 pr-2",children:jsx(Ni,{status:l.status})}),jsx("div",{className:"w-16 shrink-0 text-right",children:jsx("button",{type:"button",onClick:()=>r(l),disabled:i,className:"text-[10px] text-danger hover:text-danger/80 cursor-pointer disabled:opacity-50 transition-colors",children:i?jsx(Spinner,{size:"sm"}):s})})]})}function Ni({status:e}){return jsx("span",{className:cn$1("inline-block rounded px-1.5 py-0.5 text-[10px] font-medium capitalize",{live:"bg-success/10 text-success",open:"bg-success/10 text-success",submitted:"bg-warning/10 text-warning",pending:"bg-warning/10 text-warning",matched:"bg-primary/10 text-primary",cancelled:"bg-neutral/10 text-neutral",failed:"bg-danger/10 text-danger",expired:"bg-neutral/10 text-neutral"}[e]??"bg-neutral/10 text-neutral"),children:e})}function wi({source:e,walletAddress:t}){let{t:n}=useTranslation(),{data:o,isLoading:r,fetchNextPage:i,hasNextPage:s}=useInfiniteTrades({source:e,wallet:t,limit:50}),l=useMemo(()=>o?.pages?.flatMap(m=>m.items)??[],[o?.pages]),a=l.length,c=a+(s?1:0),d=useCallback(m=>m<a,[a]),p=useCallback(async()=>{await i();},[i]),u=useInfiniteLoader({isRowLoaded:d,loadMoreRows:p,rowCount:c,threshold:5});return r?jsx(xr,{}):l.length===0&&!s?jsx(vr,{message:n("predict.tradeHistory.empty")}):jsxs("div",{className:"flex flex-col h-full",children:[jsxs("div",{className:"flex items-center text-neutral text-xs lg:text-sm font-normal shrink-0",style:{height:Ct},children:[jsx("div",{className:"w-16 shrink-0 pr-2",children:n("predict.tradeHistory.side")}),jsx("div",{className:"flex-1 pr-2",children:n("predict.tradeHistory.outcome")}),jsx("div",{className:"flex-1 pr-2 text-right",children:n("predict.tradeHistory.price")}),jsx("div",{className:"flex-1 pr-2 text-right",children:n("predict.tradeHistory.qty")}),jsx("div",{className:"flex-1 pr-2 text-right",children:n("predict.tradeHistory.total")}),jsx("div",{className:"flex-[1.5] pr-2 text-right",children:n("predict.tradeHistory.time")})]}),jsx(List,{style:{height:gr},onRowsRendered:u,rowComponent:ki,rowCount:c,rowHeight:fr,rowProps:{trades:l,itemCount:a}})]})}function ki({index:e,style:t,trades:n,itemCount:o}){if(e>=o)return jsx("div",{style:t,className:"flex justify-center items-center",children:jsx(Spinner,{size:"sm"})});let r=n[e];if(!r)return null;let i=r.side?.toUpperCase()==="BUY",s=Pi(r.timestamp),l=r.price??0,a=r.usd_size??0;return jsxs("div",{style:t,className:"flex items-center border-b border-border/50 text-xs lg:text-sm",children:[jsx("div",{className:"w-16 shrink-0 pr-2",children:jsx("span",{className:cn$1("inline-block rounded px-1.5 py-0.5 text-[10px] font-medium",i?"bg-primary/10 text-primary":"bg-danger/10 text-danger"),children:r.side})}),jsx("div",{className:"flex-1 pr-2 text-foreground capitalize",children:r.outcome??"\u2014"}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:Pt(l)}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:r.size}),jsxs("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:["$",a.toFixed(2)]}),jsx("div",{className:"flex-[1.5] pr-2 text-right text-neutral whitespace-nowrap",children:s})]})}function vr({message:e}){return jsx("div",{className:"flex items-center justify-center text-sm text-neutral",style:{height:st},children:e})}function xr(){return jsx("div",{className:"flex flex-col gap-y-2 py-3 animate-pulse",style:{height:st},children:Array.from({length:6}).map((e,t)=>jsx(Skeleton,{className:"h-8 w-full rounded-md"},t))})}function Pt(e){let t=e*100;return t<1&&t>0?"< 1\xA2":`${t.toFixed(1)}\xA2`}function Pi(e){let t=new Date(e*1e3),n=(t.getMonth()+1).toString().padStart(2,"0"),o=t.getDate().toString().padStart(2,"0"),r=t.getHours().toString().padStart(2,"0"),i=t.getMinutes().toString().padStart(2,"0");return `${n}/${o} ${r}:${i}`}function Ei(e){try{return new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}catch{return "\u2014"}}function at({marketCount:e=4,showBack:t}){return jsxs("div",{className:"flex w-full flex-col gap-4 animate-pulse lg:gap-6",children:[t&&jsx("div",{className:"h-5"}),jsxs("div",{className:"flex items-center gap-x-2 h-16 lg:h-20 lg:gap-x-4",children:[jsx(Skeleton,{className:"size-16 shrink-0 rounded-lg lg:size-20"}),jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-1.5",children:[jsxs("div",{className:"flex items-center gap-1.5",children:[jsx(Skeleton,{className:"h-3.5 w-12 rounded"}),jsx(Skeleton,{className:"h-3.5 w-10 rounded"}),jsx(Skeleton,{className:"h-3.5 w-10 rounded"})]}),jsx(Skeleton,{className:"h-5 w-full max-w-sm rounded lg:h-6"})]})]}),jsx(Skeleton,{className:"h-4 w-48 rounded"}),jsxs("div",{className:"flex flex-col gap-3",children:[jsxs("div",{className:"flex items-center gap-4",children:[jsx(Skeleton,{className:"h-4 w-24 rounded"}),jsx(Skeleton,{className:"h-4 w-20 rounded"})]}),jsx(Skeleton,{className:"h-[300px] w-full rounded-xl"}),jsxs("div",{className:"flex items-center justify-between",children:[jsx(Skeleton,{className:"h-4 w-20 rounded"}),jsxs("div",{className:"flex items-center gap-2",children:[jsx(Skeleton,{className:"h-7 w-[200px] rounded-lg"}),jsx(Skeleton,{className:"h-7 w-28 rounded-lg"})]})]})]}),jsxs("div",{className:"flex flex-col",children:[jsxs("div",{className:"flex items-center py-2",children:[jsx("div",{className:"flex-1"}),jsx(Skeleton,{className:"h-3.5 w-14 rounded"}),jsx("div",{className:"flex-1"})]}),Array.from({length:e}).map((n,o)=>jsxs("div",{className:"flex items-center gap-x-2 border-b border-border py-2.5 lg:gap-x-3",children:[jsx(Skeleton,{className:"size-5 shrink-0 rounded-lg lg:size-8"}),jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-1",children:[jsx(Skeleton,{className:"h-3.5 w-32 rounded lg:h-4 lg:w-48"}),jsx(Skeleton,{className:"h-2.5 w-16 rounded"})]}),jsx(Skeleton,{className:"h-4 w-10 rounded"}),jsxs("div",{className:"flex items-center gap-2",children:[jsx(Skeleton,{className:"h-8 w-16 rounded-lg lg:w-24"}),jsx(Skeleton,{className:"h-8 w-16 rounded-lg lg:w-24"})]})]},o))]}),jsxs("div",{className:"flex flex-col gap-2",children:[jsx(Skeleton,{className:"h-4 w-16 rounded"}),jsx(Skeleton,{className:"h-3.5 w-full rounded"}),jsx(Skeleton,{className:"h-3.5 w-4/5 rounded"}),jsx(Skeleton,{className:"h-3.5 w-3/5 rounded"})]})]})}function zn(){return jsxs("div",{className:"flex flex-col gap-3 rounded-xl border border-border p-4 animate-pulse",children:[jsx(Skeleton,{className:"h-10 w-full rounded-lg"}),jsx(Skeleton,{className:"h-24 w-full rounded-lg"}),jsx(Skeleton,{className:"h-10 w-full rounded-lg"})]})}var qn="var(--color-bullish)",jn="var(--color-bearish)";function it(e){let t=Math.abs(e);return t>=1e9?`${parseFloat((e/1e9).toFixed(2))}B`:t>=1e6?`${parseFloat((e/1e6).toFixed(2))}M`:t>=1e3?`${parseFloat((e/1e3).toFixed(2))}K`:e.toLocaleString()}function Mi(e,t){return e<=0||t<=0?0:Math.pow(e/t,.3)}function Ri(e,t){let n=new Float64Array(101),o=new Float64Array(101);for(let m of e){let f=Math.round(m.price*100);f>=0&&f<=100&&(n[f]+=m.quantity);}for(let m of t){let f=Math.round(m.price*100);f>=0&&f<=100&&(o[f]+=m.quantity);}let r=0,i=0,s=new Float64Array(101),l=new Float64Array(101);for(let m=100;m>=0;m--)r+=n[m],i+=n[m]*m/100,s[m]=r,l[m]=i;let a=0,c=0,d=new Float64Array(101),p=new Float64Array(101);for(let m=0;m<=100;m++)a+=o[m],c+=o[m]*m/100,d[m]=a,p[m]=c;let u=Math.max(s[0]??0,d[100]??0);return Array.from({length:101},(m,f)=>{let g=s[f]>0,v=d[f]>0,h=s[f]||d[f],D=n[f]>0||o[f]>0;return {priceCents:f,displayHeight:Mi(h,u),opacity:h>0?D?1:.5:0,isBid:g,isAsk:v,bidCumTotal:s[f],askCumTotal:d[f],bidCumCost:l[f],askCumCost:p[f]}})}function Li({info:e}){let{t}=useTranslation(),n=e.isBid?qn:jn,o=e.leftPct>65?void 0:`${e.leftPct}%`,r=e.leftPct>65?`${100-e.leftPct}%`:void 0;return jsxs("div",{style:{position:"absolute",top:8,left:o,right:r,zIndex:10,background:"rgba(17,24,39,0.95)",border:"1px solid rgba(255,255,255,0.08)",borderRadius:8,padding:"8px 12px",fontSize:12,color:"#f9fafb",minWidth:140,pointerEvents:"none"},children:[jsx("div",{style:{marginBottom:4,fontWeight:600},children:t("predict.orderBook.depthToPrice",{price:e.priceCents})}),jsx("div",{style:{color:n},children:t("predict.orderBook.depthContracts",{amount:it(Math.round(e.cumTotal))})}),jsxs("div",{style:{color:n},children:["$",it(Math.round(e.cumCost))]})]})}var Oi=memo(function({slot:t,onEnter:n,onLeave:o}){let r=useRef(null),i=t.isBid||t.isAsk,s=t.isBid?qn:t.isAsk?jn:void 0;return jsx("div",{style:{position:"absolute",left:`${t.priceCents}%`,width:"1%",height:"100%",boxSizing:"border-box",borderRight:t.priceCents<100?"1px solid transparent":"none",cursor:i?"crosshair":"default"},onMouseEnter:()=>n(t,r.current),onMouseLeave:o,children:i&&jsx("div",{ref:r,style:{position:"absolute",bottom:0,left:0,width:"100%",height:`${t.displayHeight*100}%`,backgroundColor:s,opacity:t.opacity}})})}),Ii=[0,10,20,30,40,50,60,70,80,90,100];function _i(){return jsx("div",{className:"relative flex h-6 items-center border-b border-t border-border px-1",style:{background:"rgba(0,0,0,0.15)"},children:Ii.map(e=>jsx("span",{className:"absolute text-neutral font-normal",style:{fontSize:10,left:`${e}%`,transform:e===0?"translateX(0px)":e===100?"translateX(-100%)":"translateX(-50%)"},children:e},e))})}function Gn({bids:e,asks:t}){let{t:n}=useTranslation(),o=useMemo(()=>Ri(e,t),[e,t]),r=useMemo(()=>{let p=e.length>0?Math.max(...e.map(m=>m.price)):0,u=t.length>0?Math.min(...t.map(m=>m.price)):1;return Math.round((p+u)/2*100)},[e,t]),i=useMemo(()=>o.some(p=>p.isBid||p.isAsk),[o]),[s,l]=useState(null),a=useRef(null),c=useCallback((p,u)=>{a.current&&(a.current.style.filter=""),u?(u.style.filter="brightness(1.5)",a.current=u):a.current=null,p.isBid||p.isAsk?l({priceCents:p.priceCents,isBid:p.isBid,cumTotal:p.isBid?p.bidCumTotal:p.askCumTotal,cumCost:p.isBid?p.bidCumCost:p.askCumCost,leftPct:p.priceCents}):l(null);},[]),d=useCallback(()=>{a.current&&(a.current.style.filter="",a.current=null),l(null);},[]);return i?jsxs("div",{style:{display:"flex",flexDirection:"column",width:"100%",height:"100%",userSelect:"none",overflow:"hidden"},children:[jsxs("div",{style:{flex:1,position:"relative",width:"100%",overflow:"hidden"},children:[r>0&&jsx("div",{style:{position:"absolute",left:`${r}%`,top:0,bottom:0,width:1,backgroundImage:"repeating-linear-gradient(to bottom, #6b7280 0, #6b7280 4px, transparent 4px, transparent 8px)",zIndex:1,pointerEvents:"none"}}),s&&jsx(Li,{info:s}),o.map(p=>jsx(Oi,{slot:p,onEnter:c,onLeave:d},p.priceCents))]}),jsx(_i,{})]}):jsx("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#6b7280",fontSize:13},children:n("predict.orderBook.noData")})}function br(e){let t=e*100,n=Math.round(t*10)/10;return Number.isInteger(n)?`${n}\xA2`:`${n.toFixed(1)}\xA2`}function Xn(){let{t:e}=useTranslation();return jsxs("div",{className:"flex items-center justify-center gap-x-2 h-full text-neutral text-xs",children:[jsx(Spinner,{size:"sm"}),jsx("span",{children:e("predict.orderBook.loading")})]})}function eo({market:e,outcome:t="yes",onTradeAction:n}){let{t:o}=useTranslation(),[r,i]=useState("depth"),s=t==="no",l=e.source,{data:a,isLoading:c}=useOrderbook({slug:e.slug,source:l}),d=useMemo(()=>((s?a?.asks:a?.bids)??[]).map(v=>({price:s?1-v.price:v.price,quantity:v.size})),[a?.bids,a?.asks,s]),p=useMemo(()=>((s?a?.bids:a?.asks)??[]).map(v=>({price:s?1-v.price:v.price,quantity:v.size})),[a?.bids,a?.asks,s]),u=useMemo(()=>d.length>0?Math.max(...d.map(g=>g.price)):null,[d]),m=useMemo(()=>p.length>0?Math.min(...p.map(g=>g.price)):null,[p]),f=useMemo(()=>{if(u==null||m==null)return null;let g=(m-u)*100;return Math.round(g*10)/10},[u,m]);return jsxs("div",{className:"flex flex-col h-[262px]",children:[jsxs("div",{className:"flex h-9 items-center border-b border-border px-1 text-xs",children:[jsx("span",{className:"flex-1 text-left text-neutral",children:f!=null?`${o("predict.orderBook.spread")}: ${Number.isInteger(f)?`${f}\xA2`:`${f.toFixed(1)}\xA2`}`:null}),jsxs("span",{className:"flex flex-1 items-center justify-center gap-x-1 whitespace-nowrap",children:[u!=null&&jsxs("span",{style:{color:"var(--color-bullish)"},children:[o("predict.trade.bestBid"),": ",br(u)]}),u!=null&&m!=null&&jsx("span",{className:"text-neutral",children:"|"}),m!=null&&jsxs("span",{style:{color:"var(--color-bearish)"},children:[o("predict.trade.bestAsk"),": ",br(m)]})]}),jsx("div",{className:"flex flex-1 justify-end",children:jsx("button",{type:"button",title:r==="depth"?"Orderbook":"Depth chart",onClick:()=>i(g=>g==="depth"?"table":"depth"),className:"flex items-center text-neutral transition-colors cursor-pointer hover:text-foreground",children:r==="depth"?jsx(OrderbookTableIcon,{className:"h-4 w-4"}):jsx(OrderbookDepthIcon,{className:"h-4 w-4"})})})]}),jsxs("div",{className:"flex-1 min-h-0 overflow-hidden",children:[r==="depth"&&jsx(Fragment,{children:c?jsx(Xn,{}):jsx(Gn,{bids:d,asks:p})}),r==="table"&&jsx(Fragment,{children:c?jsx(Xn,{}):jsx(Ui,{bids:d,asks:p,bestBid:u??void 0,bestAsk:m??void 0,spread:f??void 0})})]})]})}var Qn=8;function Ui({bids:e,asks:t,spread:n}){let{t:o}=useTranslation(),r=useMemo(()=>[...t].sort((a,c)=>a.price-c.price).slice(0,Qn).reverse(),[t]),i=useMemo(()=>[...e].sort((a,c)=>c.price-a.price).slice(0,Qn),[e]),s=useMemo(()=>{let a=[...r,...i].map(c=>c.quantity);return Math.max(...a,1)},[r,i]);return r.length===0&&i.length===0?jsx("div",{className:"flex items-center justify-center h-full text-xs text-neutral",children:o("predict.orderBook.empty")}):jsxs("div",{className:"flex flex-col h-full overflow-y-auto text-xs font-mono select-none",children:[r.map(a=>jsx(Jn,{price:a.price,quantity:a.quantity,side:"ask",maxQty:s},`ask-${a.price}`)),jsx("div",{className:"flex items-center justify-center gap-x-2 py-1 border-y border-border text-neutral text-[10px]",children:n!=null&&jsxs("span",{children:[o("predict.orderBook.spread"),":"," ",Number.isInteger(n)?`${n}\xA2`:`${n.toFixed(1)}\xA2`]})}),i.map(a=>jsx(Jn,{price:a.price,quantity:a.quantity,side:"bid",maxQty:s},`bid-${a.price}`)),jsxs("div",{className:"grid grid-cols-3 px-2 pt-2 pb-0.5 text-[10px] text-neutral border-t border-border",children:[jsx("span",{children:o("predict.orderBook.price")}),jsx("span",{className:"text-center",children:o("predict.orderBook.contracts")}),jsx("span",{className:"text-right",children:o("predict.orderBook.total")})]})]})}function Jn({price:e,quantity:t,side:n,maxQty:o}){let r=n==="ask",i=Math.min(t/o*100,100),s=r?"bg-bearish/10":"bg-bullish/10",l=r?"text-bearish":"text-bullish",a=it(Math.round(t)),c=Math.round(t*e),d=`$${it(c)}`;return jsxs("div",{className:"relative grid grid-cols-3 px-2 py-1 hover:bg-content2 transition-colors cursor-default",children:[jsx("div",{className:`absolute inset-y-0 left-0 ${s} transition-[width] duration-200`,style:{width:`${i}%`}}),jsx("span",{className:`relative z-10 ${l}`,children:br(e)}),jsx("span",{className:"relative z-10 text-foreground text-center",children:a}),jsx("span",{className:"relative z-10 text-foreground text-right",children:d})]})}var Nr=class extends Component{state={error:null};static getDerivedStateFromError(t){return {error:t}}componentDidCatch(t,n){}render(){return this.state.error?jsxs("div",{style:{height:this.props.fallbackHeight??320,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:8,color:"#6b7280",fontSize:13},children:[jsx("span",{children:"Chart unavailable"}),jsx("span",{style:{fontSize:11,opacity:.7},children:this.state.error.message})]}):this.props.children}},Rt=4,to=["#22d3ee","#a3e635","#f97316","#f472b6","#a78bfa"];function Ji(e,t){let n=new Date(e);return t===ChartRange.ONE_DAY?n.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:false}):n.toLocaleDateString("en-US",{month:"short",day:"numeric"})}function Zi(e,t){let n=new Date(e);return t===ChartRange.ONE_DAY?n.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:false}):t===ChartRange.ONE_WEEK?n.toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:false}):n.toLocaleDateString("en-US",{month:"short",day:"numeric"})}function ro(e){return `${(e*100).toFixed(2)}%`}var el=[{range:ChartRange.ONE_DAY,label:"1D"},{range:ChartRange.ONE_WEEK,label:"1W"},{range:ChartRange.ONE_MONTH,label:"1M"},{range:ChartRange.ALL,label:"ALL"}];function tl({value:e,onChange:t}){return jsx("div",{style:{display:"flex",alignItems:"center",gap:2},children:el.map(({range:n,label:o})=>{let r=n===e;return jsx("button",{onClick:()=>t(n),style:{padding:"2px 8px",border:"none",background:"transparent",color:r?"#f9fafb":"#6b7280",fontWeight:r?700:400,fontSize:12,cursor:"pointer",borderRadius:4,letterSpacing:"0.02em",transition:"color 0.15s",userSelect:"none"},children:o},n)})})}function rl(){let e=useRef(null),t=useRef(null),n=useCallback(r=>{let i=e.current,s=t.current;if(!i||!s)return;let l=i.getBoundingClientRect(),a=(r.clientX-l.left)/l.width*100;s.style.background=`linear-gradient(to right, transparent ${a}%, rgba(0,0,0,0.55) ${a}%)`,s.style.opacity="1";},[]),o=useCallback(()=>{t.current&&(t.current.style.opacity="0");},[]);return {wrapperRef:e,overlayRef:t,onMouseMove:n,onMouseLeave:o}}function nl({active:e,payload:t,label:n,labelMap:o,allSeries:r,range:i}){if(!e||!r?.length)return null;let s=new Map;t?.forEach(a=>s.set(a.dataKey,a));let l=r.map(a=>s.get(a.slug)??{dataKey:a.slug,value:void 0,stroke:a.color,color:a.color});return jsxs("div",{style:{background:"rgba(10,10,10,0.92)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:8,padding:"8px 12px",minWidth:180,backdropFilter:"blur(8px)",fontSize:12},children:[jsx("div",{style:{color:"#9ca3af",marginBottom:6,fontWeight:500},children:typeof n=="number"?Zi(n,i):n}),l.map(a=>jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:3},children:[jsx("span",{style:{display:"inline-block",width:3,height:14,borderRadius:2,background:a.stroke??a.color,flexShrink:0}}),jsx("span",{style:{color:"#9ca3af",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:120},children:o.get(a.dataKey)??a.dataKey}),jsx("span",{style:{color:"#f9fafb",fontWeight:700,fontVariantNumeric:"tabular-nums"},children:a.value!=null?ro(a.value):"--"})]},a.dataKey))]})}function ol({markets:e,selectedSlugs:t,colorMap:n,onToggle:o}){let[r,i]=useState(false),s=useRef(null);useEffect(()=>{if(!r)return;function c(d){s.current&&!s.current.contains(d.target)&&i(false);}return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[r]);let l=t.length>=Rt,a=jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flex:1,minWidth:0},children:[jsx("div",{style:{display:"flex",gap:3,flexShrink:0},children:t.map(c=>jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:n.get(c)??"#6b7280",display:"inline-block"}},c))}),jsx("span",{style:{color:"#e5e7eb",fontSize:12,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.length===1?(()=>{let c=e.find(d=>d.slug===t[0]);return c?.outcomes?.[0]?.label??c?.question??"1 market"})():`${t.length} / ${e.length} markets`})]});return jsxs("div",{ref:s,style:{position:"relative",display:"inline-block",width:200},children:[jsxs("button",{onClick:()=>i(c=>!c),style:{display:"inline-flex",alignItems:"center",gap:6,padding:"5px 10px",borderRadius:8,border:"1px solid rgba(255,255,255,0.12)",background:"rgba(255,255,255,0.05)",cursor:"pointer",width:"100%",userSelect:"none"},children:[a,jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",style:{flexShrink:0,transform:r?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.15s",color:"#6b7280"},children:jsx("path",{d:"M2 4l4 4 4-4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})]}),r&&jsxs("div",{style:{position:"absolute",top:"calc(100% + 4px)",left:0,zIndex:50,background:"#111827",border:"1px solid rgba(255,255,255,0.1)",borderRadius:10,boxShadow:"0 8px 24px rgba(0,0,0,0.5)",minWidth:260,maxWidth:360,maxHeight:320,overflowY:"auto",padding:"6px 0"},children:[jsxs("div",{style:{padding:"4px 12px 8px",fontSize:11,color:"#6b7280",borderBottom:"1px solid rgba(255,255,255,0.06)",marginBottom:4},children:["Select up to ",Rt," markets"]}),e.map(c=>{let d=t.includes(c.slug),p=!d&&l,u=d&&t.length===1,m=n.get(c.slug)??"#6b7280",f=c.outcomes.find(v=>v.label.toLowerCase()==="yes")??c.outcomes[0],g=f?.price!=null?`${Math.round(f.price*100)}%`:null;return jsxs("button",{onClick:()=>{u||p||o(c.slug);},style:{display:"flex",alignItems:"center",gap:10,width:"100%",padding:"7px 12px",border:"none",background:d?"rgba(255,255,255,0.05)":"transparent",cursor:p||u?"not-allowed":"pointer",opacity:p?.35:1,textAlign:"left",transition:"background 0.1s"},onMouseEnter:v=>{!p&&!u&&(v.currentTarget.style.background="rgba(255,255,255,0.07)");},onMouseLeave:v=>{v.currentTarget.style.background=d?"rgba(255,255,255,0.05)":"transparent";},children:[jsx("span",{style:{width:16,height:16,borderRadius:4,border:d?`2px solid ${m}`:"2px solid rgba(255,255,255,0.2)",background:d?`${m}30`:"transparent",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center"},children:d&&jsx("svg",{width:"9",height:"7",viewBox:"0 0 9 7",fill:"none",children:jsx("path",{d:"M1 3.5L3.5 6L8 1",stroke:m,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:m,flexShrink:0}}),jsx("span",{style:{color:d?"#f9fafb":"#9ca3af",fontSize:12,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c.outcomes?.[0]?.label??c.question}),g&&jsx("span",{style:{color:m,fontWeight:700,fontSize:12,flexShrink:0},children:g})]},c.slug)})]})]})}function sl({series:e,colorMap:t,displayValues:n}){return jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px 24px",padding:"0 2px"},children:e.map(o=>{let r=t.get(o.marketSlug)??"#6b7280",i=n.get(o.marketSlug);return jsxs("div",{style:{display:"inline-flex",alignItems:"flex-start",gap:6},children:[jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:r,flexShrink:0,marginTop:3}}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:1},children:[jsx("span",{style:{color:"#9ca3af",fontSize:12,lineHeight:"17px",whiteSpace:"nowrap"},children:o.label}),jsx("span",{style:{color:"#f9fafb",fontSize:14,fontWeight:700,lineHeight:"20px",fontVariantNumeric:"tabular-nums"},children:i!=null?ro(i):"--"})]})]},o.marketSlug)})})}function al(e){let t=Math.floor(e.length/2);return e.length%2===1?e[t]:(e[t-1]+e[t])/2}function il(e,t){if(e.length<=t)return e;let n=[],o=e.length/t;for(let r=0;r<t;r++){let i=Math.floor(r*o),s=Math.min(Math.floor((r+1)*o),e.length),l=e.slice(i,s),a=l.map(c=>c.price).sort((c,d)=>c-d);n.push({timestamp:l[l.length-1].timestamp,price:al(a)});}return n}function ll(e,t=200){if(e.length===0)return [];let n=e.map(l=>({...l,data:il(l.data,t)})),o=new Set;n.forEach(l=>l.data.forEach(a=>o.add(a.timestamp)));let r=Array.from(o).sort((l,a)=>l-a),i=n.map(l=>{let a=new Map;return l.data.forEach(c=>a.set(c.timestamp,c.price)),{slug:l.marketSlug,map:a}}),s=new Map;return r.map(l=>{let a={timestamp:l};return i.forEach(({slug:c,map:d})=>{let p=d.get(l);if(p!==void 0)s.set(c,p),a[c]=p;else {let u=s.get(c);u!==void 0&&(a[c]=u);}}),a})}function no(e){return jsx(Nr,{children:jsx(cl,{...e})})}function cl({event:e,isLoading:t,className:n,volume:o}){let r=useMemo(()=>(e.markets??[]).filter(S=>S.status==="open"),[e.markets]),i=useMemo(()=>[...r].sort((S,E)=>{let I=y=>(y.outcomes.find($=>$.label.toLowerCase()==="yes")??y.outcomes[0])?.price??0;return I(E)-I(S)}),[r]),[s,l]=useState(()=>i.slice(0,Rt).map(S=>S.slug)),[a,c]=useState(ht),d=useMemo(()=>{let S=new Map;return s.forEach((E,I)=>{S.set(E,to[I%to.length]);}),S},[s]),p=useMemo(()=>r.filter(S=>s.includes(S.slug)),[r,s]),{series:u,isLoading:m}=useMarketHistory(p,a),f=t||m,g=useMemo(()=>{if(u.length>0&&u.some(I=>I.data.length>0))return u;let S=Date.now(),E=864e5;return p.map(I=>{let $=(I.outcomes?.find(q=>q.label.toLowerCase()==="yes")??I.outcomes?.[0])?.price??.5;return {marketSlug:I.slug,label:I.outcomes?.[0]?.label??I.question,data:[{timestamp:S-7*E,price:$},{timestamp:S,price:$}]}})},[u,p]),v=useMemo(()=>a===ChartRange.ONE_DAY?96:a===ChartRange.ONE_WEEK?168:a===ChartRange.ONE_MONTH?180:300,[a]),h=useMemo(()=>ll(g,v),[g,v]),D=useMemo(()=>{if(h.length===0)return [0,1];let S=1/0,E=-1/0;if(s.forEach(y=>{h.forEach($=>{let q=$[y];q!=null&&(q<S&&(S=q),q>E&&(E=q));});}),!isFinite(S))return [0,1];let I=Math.max((E-S)*.15,.05);return [Math.max(0,S-I),Math.min(1,E+I)]},[h,s]),T=useMemo(()=>{let S=new Map;return g.forEach(E=>{E.data.length>0&&S.set(E.marketSlug,E.data[E.data.length-1].price);}),S},[g]),M=useMemo(()=>{let S=new Map;return g.forEach(E=>S.set(E.marketSlug,E.label)),S},[g]),O=useMemo(()=>g.map(S=>({slug:S.marketSlug,color:d.get(S.marketSlug)??"#6b7280"})),[g,d]),{wrapperRef:Z,overlayRef:R,onMouseMove:ie,onMouseLeave:K}=rl(),fe=useCallback(S=>{l(E=>E.includes(S)?E.length<=1?E:E.filter(I=>I!==S):E.length>=Rt?E:[...E,S]);},[]),[Me,X]=useState(null),Q=useRef(null),le=useRef(""),he=useRef(0),be=!f&&h.length>0;return jsxs("div",{className:n,style:{display:"flex",flexDirection:"column",gap:12},children:[jsx(sl,{series:g,colorMap:d,displayValues:Me??T}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:0},children:[jsx("div",{ref:Z,style:{height:300,width:"100%",userSelect:"none",position:"relative"},onMouseMove:be?S=>{ie(S),cancelAnimationFrame(he.current),he.current=requestAnimationFrame(()=>{X(Q.current);});}:void 0,onMouseLeave:be?()=>{K(),cancelAnimationFrame(he.current),le.current="",Q.current=null,X(null);}:void 0,children:f?jsx("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:jsx("div",{style:{width:28,height:28,borderRadius:"50%",border:"2.5px solid #22d3ee",borderTopColor:"transparent",animation:"spin 0.7s linear infinite"}})}):h.length===0?jsx("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#6b7280",fontSize:13},children:"No price history data"}):jsxs(Fragment,{children:[jsx("div",{ref:R,style:{position:"absolute",inset:0,opacity:0,pointerEvents:"none",zIndex:1}}),jsx(ResponsiveContainer,{width:"100%",height:"100%",children:jsxs(LineChart,{data:h,margin:{top:8,right:16,left:0,bottom:0},children:[jsx(CartesianGrid,{horizontal:true,vertical:false,strokeDasharray:"3 3",stroke:"#374151",opacity:.5}),jsx(XAxis,{dataKey:"timestamp",type:"number",scale:"time",domain:["dataMin","dataMax"],tickFormatter:S=>Ji(S,a),axisLine:false,tickLine:false,tick:{fill:"#6b7280",fontSize:11},minTickGap:70}),jsx(YAxis,{domain:D,tickFormatter:S=>`${Math.round(S*100)}%`,axisLine:false,tickLine:false,tick:{fill:"#6b7280",fontSize:11},width:40,tickCount:6}),jsx(Tooltip,{content:S=>{let E=S;if(E.active&&E.payload?.length){let I=E.payload.map(y=>`${y.dataKey}:${y.value}`).join(",");if(I!==le.current){le.current=I;let y=new Map;E.payload.forEach($=>{$.value!=null&&y.set($.dataKey,$.value);}),Q.current=y;}}return jsx(nl,{...E,labelMap:M,allSeries:O,range:a})},cursor:{stroke:"#4b5563",strokeWidth:1,strokeDasharray:"4 4"},wrapperStyle:{zIndex:2},isAnimationActive:false}),g.map(S=>{let E=d.get(S.marketSlug)??"#6b7280";return jsx(Line,{type:"linear",dataKey:S.marketSlug,stroke:E,strokeWidth:2,strokeLinejoin:"round",strokeLinecap:"round",dot:false,activeDot:{r:4.5,strokeWidth:2,stroke:"rgba(10,10,10,0.8)",fill:E},connectNulls:true,isAnimationActive:false},S.marketSlug)}),Me==null&&h.length>0&&g.map(S=>{let E=h[h.length-1],I=E[S.marketSlug];if(I==null)return null;let y=d.get(S.marketSlug)??"#6b7280";return jsx(ReferenceDot,{x:E.timestamp,y:I,ifOverflow:"extendDomain",shape:$=>{let{cx:q,cy:z}=$;return q==null||z==null?jsx("g",{}):jsxs("g",{children:[jsxs("circle",{cx:q,cy:z,r:6,fill:y,opacity:.3,children:[jsx("animate",{attributeName:"r",values:"4;9;4",dur:"2s",repeatCount:"indefinite"}),jsx("animate",{attributeName:"opacity",values:"0.4;0.05;0.4",dur:"2s",repeatCount:"indefinite"})]}),jsx("circle",{cx:q,cy:z,r:3.5,fill:y})]})}},`pulse-${S.marketSlug}`)})]})})]})}),jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"6px 8px",marginTop:6},children:[o!=null&&o>0&&jsxs("span",{style:{color:"#6b7280",fontSize:12},children:["$",Math.round(o).toLocaleString()," vol"]}),jsx("div",{style:{flex:1,minWidth:0}}),jsx(tl,{value:a,onChange:c}),i.length>1&&jsx("div",{style:{width:"100%",display:"flex",alignItems:"center"},children:jsx(ol,{markets:i,selectedSlugs:s,colorMap:d,onToggle:fe})})]})]})]})}function ct(e){return e.outcomes[0]?.best_ask??e.outcomes[0]?.price??0}function wl(e){return `${parseFloat((e*100).toFixed(2))}%`}function oo(e){let t=e*100;return t<1&&t>0?"< 1":parseFloat(t.toFixed(2)).toString()}function Lt(e){return e.outcomes?.[0]?.label??e.question}function kl(e){switch(e){case "polymarket":return "Polymarket";case "kalshi":return "Kalshi";default:return e}}function lt(e){if(!e)return "\u2014";let t=new Date(e);if(isNaN(t.getTime()))return "\u2014";let n=t.toLocaleString("default",{month:"short"}),o=t.getDate(),r=t.getFullYear(),i=t.getHours().toString().padStart(2,"0"),s=t.getMinutes().toString().padStart(2,"0");return `${n} ${o}, ${r} ${i}:${s}`}function so(e){let[t,n]=useState(Date.now());if(useEffect(()=>{if(!e)return;let d=setInterval(()=>n(Date.now()),1e3);return ()=>clearInterval(d)},[e]),!e)return null;let o=new Date(e).getTime();if(isNaN(o))return null;let r=o-t;if(r<=0)return null;let i=Math.floor(r/864e5),s=Math.floor(r%864e5/36e5),l=Math.floor(r%36e5/6e4),a=Math.floor(r%6e4/1e3),c=[];return i>0&&c.push(`${i}d`),c.push(`${String(s).padStart(2,"0")}h`),c.push(`${String(l).padStart(2,"0")}m`),c.push(`${String(a).padStart(2,"0")}s`),c.join(" ")}function ao(e){if(!e)return null;let t=new Date(e);if(isNaN(t.getTime()))return null;let n=t.getHours().toString().padStart(2,"0"),o=t.getMinutes().toString().padStart(2,"0"),r=(t.getMonth()+1).toString().padStart(2,"0"),i=t.getDate().toString().padStart(2,"0"),s=t.getFullYear(),l=-t.getTimezoneOffset(),a=l>=0?"+":"-",c=String(Math.abs(Math.floor(l/60))).padStart(2,"0");return `${n}:${o} ${r}/${i}/${s} (${a}${c})`}function co({event:e,onTradeAction:t}){let{t:n}=useTranslation(),{ref:o,isCollapsed:r}=useScrollCollapse(),i=useMemo(()=>{let p=[...e.markets||[]],u=p.filter(f=>f.status==="open").sort((f,g)=>ct(g)-ct(f)),m=p.filter(f=>f.status!=="open").sort((f,g)=>ct(g)-ct(f));return [...u,...m]},[e.markets]),s=e.status==="closed"||e.status==="voided",l=so(s?void 0:e.start_at),a=so(s?void 0:e.end_at),c=ao(e.start_at),d=ao(e.end_at);return jsxs("div",{className:"w-full flex flex-col gap-y-4 lg:gap-y-6",children:[jsxs("div",{ref:o,className:`sticky top-0 z-30 flex items-center backdrop-blur-md transition-all duration-300 ${r?"h-14 lg:h-16 gap-x-2 py-2 px-1 lg:px-4 -mx-1 lg:-mx-4 shadow-sm":"h-16 lg:h-20 gap-x-2 lg:gap-x-4"}`,children:[jsx(Avatar,{src:e.image_url||void 0,name:e.title||"Event",radius:"lg",classNames:{base:"bg-transparent"},className:`flex-shrink-0 transition-all duration-300 ${r?"!h-10 !w-10 lg:!h-12 lg:!w-12":"!h-16 !w-16 lg:!h-20 lg:!w-20"}`}),jsxs("div",{className:"flex flex-col gap-0.5 min-w-0 flex-1",children:[!r&&jsxs("div",{className:"flex items-center gap-1.5",children:[e.tags?.slice(0,3).map((p,u)=>jsxs(Fragment$1,{children:[u>0&&jsx("span",{className:"text-sm text-neutral/50",children:"\xB7"}),jsx("span",{className:"text-sm text-neutral truncate",children:p.label})]},p.slug)),jsx(Tl,{source:e.source})]}),jsx("span",{className:`font-semibold truncate transition-all duration-300 ${r?"text-sm lg:text-base":"text-lg lg:text-xl"}`,children:e.title})]})]}),(l||a||s)&&jsx("div",{className:"flex items-center gap-x-2 text-xs lg:text-sm font-mono",children:s?d&&jsx("span",{className:"text-neutral",children:n("predict.event.endedAt",{time:d})}):l?jsxs(Fragment,{children:[jsx("span",{className:"text-foreground",children:n("predict.event.beginsIn",{time:l})}),c&&jsxs(Fragment,{children:[jsx("span",{className:"text-neutral/50",children:"\xB7"}),jsx("span",{className:"text-neutral",children:c})]})]}):a?jsxs(Fragment,{children:[jsx("span",{className:"text-foreground",children:n("predict.event.endsIn",{time:a})}),d&&jsxs(Fragment,{children:[jsx("span",{className:"text-neutral/50",children:"\xB7"}),jsx("span",{className:"text-neutral",children:d})]})]}):null}),jsx(no,{event:e,volume:e.volume??void 0}),jsx(Pl,{markets:i,onTradeAction:t}),jsx(Cl,{markets:i,event:e})]})}var io=5;function Pl({markets:e,onTradeAction:t}){let{t:n}=useTranslation(),{isMobile:o}=useScreen(),[r,i]=useState(false),[s,l]=useState(null),a=e.find(g=>g.status==="open")?.slug,[c,d]=useState(a?`${a}:yes`:null);if(e.length===0)return null;let p=e.length>io,u=r?e:e.slice(0,io),m=g=>{l(v=>v===g?null:g);},f=(g,v,h)=>{d(`${g.slug}:${v}`),o||l(g.slug),t?.(g,v,h);};return jsxs("div",{className:"flex flex-col",children:[jsxs("table",{className:"w-full border-collapse",children:[jsx("thead",{children:jsxs("tr",{children:[jsx("th",{}),jsx("th",{className:"py-2 text-left text-xs text-neutral font-normal lg:text-center lg:text-sm",children:n("predict.market.table.chance")}),jsx("th",{})]})}),jsx("tbody",{children:u.map(g=>{let v=ct(g),h=g.outcomes[1]?.best_ask??g.outcomes[1]?.price,D=s===g.slug;return jsx(El,{market:g,yesPrice:v,noPrice:h??void 0,activeYes:c===`${g.slug}:yes`,activeNo:c===`${g.slug}:no`,isExpanded:D,onToggleExpand:()=>m(g.slug),onTradeAction:f},g.slug)})})]}),p&&jsxs("button",{type:"button",onClick:()=>i(g=>!g),className:"flex w-full items-center justify-start gap-x-2 py-2 pl-1 text-xs text-neutral lg:pl-2 lg:text-sm cursor-pointer hover:text-foreground transition-colors",children:[jsx("span",{children:n(r?"predict.event.rules.collapse":"predict.event.moreMarketsLabel")}),jsx(ChevronDownIcon,{className:cn$1("h-4 w-4 transition-transform",r&&"rotate-180")})]})]})}function El({market:e,yesPrice:t,noPrice:n,activeYes:o,activeNo:r,isExpanded:i,onToggleExpand:s,onTradeAction:l}){let{t:a}=useTranslation(),c=e.status==="open",d=e.volume?`$${Math.round(e.volume).toLocaleString("en-US")} vol`:void 0;return jsxs(Fragment,{children:[jsxs("tr",{className:"cursor-pointer border-b border-border text-xs hover:bg-content2 lg:text-base",onClick:s,role:"button",tabIndex:0,onKeyDown:p=>{(p.key==="Enter"||p.key===" ")&&(p.preventDefault(),s());},children:[jsx("td",{className:"py-2 pl-1 lg:pl-2",children:jsxs("div",{className:"flex items-center gap-x-1 lg:gap-x-2",children:[e.image_url&&jsx(Avatar,{src:e.image_url,name:Lt(e)?.[0]||"?",radius:"lg",className:"size-5 shrink-0 lg:size-8",imgProps:{className:"object-cover"}}),jsxs("div",{className:"flex flex-col",children:[jsx("span",{className:"text-foreground truncate max-w-[200px] lg:max-w-[300px]",children:Lt(e)}),d&&jsx("span",{className:"text-[8px] text-neutral lg:text-xxs",children:d})]})]})}),jsx("td",{className:"py-2 text-left text-foreground lg:text-center",children:wl(t)}),jsx("td",{className:"py-2 pr-1 lg:pr-2",children:c?jsxs("div",{className:"flex items-center justify-end gap-x-2",children:[jsx("button",{type:"button",className:cn$1("flex min-w-16 items-center justify-center whitespace-nowrap rounded-lg p-2 lg:min-w-24 cursor-pointer hover:opacity-80 transition-all",o?"bg-primary text-primary-foreground":"bg-primary/10 text-primary"),onClick:p=>{p.stopPropagation(),l?.(e,"yes","buy");},children:a("predict.market.action.yes",{price:oo(t)})}),jsx("button",{type:"button",className:cn$1("flex min-w-16 items-center justify-center whitespace-nowrap rounded-lg p-2 lg:min-w-24 cursor-pointer hover:opacity-80 transition-all",r?"bg-secondary text-secondary-foreground":"bg-secondary/10 text-secondary"),onClick:p=>{p.stopPropagation(),l?.(e,"no","buy");},children:n!=null?a("predict.market.action.no",{price:oo(n)}):a("predict.market.no")})]}):jsx("div",{className:"flex items-center justify-end",children:jsx("span",{className:cn$1("inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium",e.status==="closed"?"bg-neutral/10 text-neutral":e.status==="voided"?"bg-warning/10 text-warning":"bg-primary/10 text-primary"),children:e.status==="closed"?a("predict.event.status.closed"):e.status==="voided"?a("predict.event.status.voided"):a("predict.event.status.pending")})})})]}),i&&jsx("tr",{children:jsx("td",{colSpan:3,className:"pb-3",children:jsx("div",{className:"max-h-100 overflow-y-auto",children:jsx(eo,{market:e,outcome:r?"no":"yes",onTradeAction:l})})})})]})}function Cl({markets:e,event:t}){let{t:n}=useTranslation(),[o,r]=useState(false),[i,s]=useState(false),[l,a]=useState(0),c=e.filter(m=>m.rules&&m.rules.length>0||m.description);if(c.length===0)return null;let d=c[l]??c[0],p=d.rules&&d.rules.length>0?d.rules.join(`
|
|
20
20
|
|
|
21
21
|
`):d.description??"";if(!p)return null;let u=p.length>200&&!o?p.slice(0,200)+"...":p;return jsxs("div",{className:"flex flex-col gap-y-3",children:[jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{className:"text-sm font-semibold text-foreground lg:text-base",children:n("predict.event.rules")}),c.length>1&&jsxs(Dropdown,{placement:"bottom-end",classNames:{content:"min-w-36 bg-content1 border border-border"},children:[jsx(DropdownTrigger,{children:jsx(Button,{size:"sm",variant:"bordered",radius:"lg",endContent:jsx(ChevronDownIcon,{className:"h-3.5 w-3.5"}),className:"text-xs text-foreground",children:Lt(d)})}),jsx(DropdownMenu,{"aria-label":"Select market rules",selectionMode:"single",selectedKeys:[String(l)],onAction:m=>{a(Number(m)),r(false);},classNames:{list:"gap-1"},itemClasses:{base:"rounded-md px-3 h-8"},children:c.map((m,f)=>jsx(DropdownItem,{className:cn$1(f===l?"bg-content2 text-foreground":"text-neutral","data-[hover=true]:bg-content2 data-[hover=true]:text-foreground"),children:Lt(m)},String(f)))})]})]}),jsx("div",{className:"text-xs text-foreground/80 lg:text-sm whitespace-pre-wrap",children:u}),p.length>200&&jsx("button",{type:"button",onClick:()=>r(m=>!m),className:"text-xs text-neutral hover:text-foreground cursor-pointer transition-colors self-start",children:n(o?"predict.event.rules.collapse":"predict.event.showMore")}),jsxs("button",{type:"button",onClick:()=>s(m=>!m),className:"flex items-center justify-between w-full mt-2 text-xs font-medium text-neutral lg:text-sm cursor-pointer hover:text-foreground transition-colors",children:[jsx("span",{children:n("predict.event.timelineAndPayout")}),jsx(ChevronDownIcon,{className:cn$1("h-4 w-4 transition-transform",i&&"rotate-180")})]}),i&&jsxs(Fragment,{children:[jsx("div",{className:"flex flex-col",children:(()=>{let m=d.status,f=[];return d.created_at&&f.push({label:n("predict.event.timeline.created"),value:lt(d.created_at),isActive:true}),f.push({label:n("predict.event.timeline.open"),value:lt(d.start_at),isActive:m!=="pending"}),m==="voided"?f.push({label:n("predict.event.timeline.voided"),value:lt(d.closed_at??d.end_at),isActive:true}):m==="closed"?f.push({label:n("predict.event.timeline.closed"),value:lt(d.closed_at??d.end_at),isActive:true}):f.push({label:n("predict.event.timeline.close"),value:lt(d.end_at),isActive:false}),f})().map((m,f,g)=>jsxs("div",{className:"flex items-stretch gap-x-3",children:[jsxs("div",{className:"flex flex-col items-center w-3",children:[jsx("div",{className:`h-3 w-3 shrink-0 rounded-full border-2 mt-0.5 ${m.isActive?"border-primary bg-primary":"border-border bg-transparent"}`}),f<g.length-1&&jsx("div",{className:"w-px flex-1 bg-border"})]}),jsxs("div",{className:`flex flex-col ${f<g.length-1?"pb-4":""}`,children:[jsx("span",{className:"text-xs font-medium text-foreground lg:text-sm",children:m.label}),jsx("span",{className:"text-xs text-neutral lg:text-sm",children:m.value})]})]},m.label))}),jsxs("div",{className:"flex flex-wrap items-center gap-x-3 text-xxs text-neutral mt-2 lg:text-xs",children:[jsxs("span",{children:[jsxs("span",{className:"text-neutral",children:[n("predict.event.id.event"),":"]})," ",jsx("span",{className:"text-foreground",children:t.slug})]}),jsxs("span",{children:[jsxs("span",{className:"text-neutral",children:[n("predict.event.id.market"),":"]})," ",jsx("span",{className:"text-foreground",children:d.slug})]}),jsxs("span",{children:[jsxs("span",{className:"text-neutral",children:[n("predict.event.id.source"),":"]})," ",jsx("span",{className:"text-foreground",children:kl(d.source)})]})]})]})]})}function Tl({source:e}){return jsxs("span",{className:"inline-flex items-center gap-x-1 text-neutral-400",title:e==="polymarket"?"Polymarket":"Kalshi",children:[jsx("span",{className:"text-neutral-600",children:"\xB7"}),e==="polymarket"?jsx(PolymarketIcon,{className:"h-5 w-auto shrink-0"}):jsx(KalshiIcon,{className:"h-3 w-auto shrink-0"})]})}function uo({eventSlug:e,source:t,onTradeAction:n}){let{data:o,isLoading:r,error:i}=useEvent({slug:e,source:t});return r?jsx(at,{}):i||!o?jsx("div",{className:"flex w-full items-center justify-center py-20 text-danger",children:i?.message||"Event not found"}):jsx(co,{event:o,onTradeAction:n})}function po({eventSlug:e,source:t,limit:n=4,onEventClick:o}){let{t:r}=useTranslation(),{data:i,isLoading:s}=useSimilarEvents({slug:e,source:t,limit:n});return s||!i||i.length===0?null:jsxs("div",{className:"flex flex-col gap-y-3 mt-6 px-1 lg:px-0",children:[jsx("span",{className:"text-sm font-semibold text-foreground lg:text-base",children:r("predict.similar.title")}),jsx("div",{className:"grid grid-cols-1 gap-3",children:i.map(l=>jsx(_l,{event:l,onClick:o},l.slug))})]})}function _l({event:e,onClick:t}){let n=e.volume;return jsxs("button",{type:"button",onClick:()=>t?.(e),className:"flex items-center gap-x-3 rounded-xl border border-border p-3 hover:bg-content2 transition-colors cursor-pointer text-left w-full",children:[jsx(Avatar,{src:e.image_url||void 0,name:e.title?.[0]||"?",radius:"lg",className:"size-8 shrink-0 bg-transparent",imgProps:{className:"object-cover"}}),jsxs("div",{className:"flex flex-col min-w-0 flex-1",children:[jsx("span",{className:"text-sm font-medium text-foreground truncate",children:e.title}),n!=null&&n>0&&jsxs("span",{className:"text-xs text-neutral",children:["$",Math.round(n).toLocaleString()," vol"]})]}),jsx(ChevronRightIcon,{className:"h-4 w-4 text-neutral shrink-0"})]})}function mo(e){return e.outcomes[0]?.best_ask??e.outcomes[0]?.price??0}function dm({eventSlug:e,source:t,chain:n,walletAddress:o,onSimilarEventClick:r,onBack:i}){let{t:s}=useTranslation(),{isMobile:l}=useScreen(),{onOpen:a}=useAsyncModal(Je),{data:c,isLoading:d}=useEvent({slug:e,source:t}),p=useMemo(()=>[...c?.markets||[]].sort((h,D)=>mo(D)-mo(h)),[c?.markets]),[u,m]=useState(null),f=useCallback((h,D,T)=>{m(M=>({market:h,outcome:D,side:T,version:(M?.version??0)+1})),l&&c&&a({params:{event:c,market:h,initialOutcome:D,chain:n}});},[l,c,n,a]),g=u?.market??p[0];if(d){let h=!!i;return l?jsx(at,{showBack:h}):jsxs("div",{className:"flex w-full max-w-6xl mx-auto gap-x-4 lg:gap-x-6",children:[jsx("div",{className:"min-w-0 flex-1 max-w-3xl",children:jsx(at,{showBack:h})}),jsx("aside",{className:"hidden lg:block w-[340px] xl:w-[380px] shrink-0",children:jsx("div",{className:"sticky top-4 max-h-[calc(100dvh-2rem)] overflow-y-auto scrollbar-thin",children:jsx(zn,{})})})]})}let v=u?`${u.market.slug}-${u.version}`:g?.slug??"default";return jsxs("div",{className:"flex w-full flex-col gap-y-4 pb-12 lg:max-w-7xl lg:gap-y-8 lg:pb-16 mx-auto",children:[jsxs("div",{className:"flex w-full justify-center gap-4 pt-4 lg:gap-6",children:[jsxs("div",{className:"flex-auto min-w-0 flex flex-col gap-y-4 px-4 lg:gap-y-6 lg:px-0",children:[i&&jsx("div",{className:"flex items-center justify-between",children:jsx(Button,{as:"a",onPress:i,startContent:jsx(ChevronLeftIcon,{className:"h-4 w-4"}),className:"text-neutral bg-transparent h-5 min-h-5 gap-x-2 p-0 text-base w-auto min-w-auto",children:s("common.back")})}),jsx(uo,{eventSlug:e,source:t,onTradeAction:f})]}),jsxs("div",{className:"hidden flex-none w-md flex-col gap-y-4 lg:sticky lg:top-4 lg:flex lg:self-start",children:[g&&jsx(bt,{event:c,market:g,initialSide:u?.side,initialOutcome:u?.outcome,chain:n},v),c&&jsx(po,{eventSlug:e,source:c.source,onEventClick:r})]})]}),c&&jsx("div",{className:"flex w-full flex-col",children:jsx(Wn,{event:c,walletAddress:o})}),jsx(yt,{})]})}function fo(e){return e.outcomes[0]?.best_ask??e.outcomes[0]?.price??0}function jl(e){switch(e){case ChartRange.ONE_DAY:return {interval:"15m",limit:96};case ChartRange.ONE_WEEK:return {interval:"1h",limit:168};case ChartRange.ONE_MONTH:return {interval:"4h",limit:180};case ChartRange.ALL:return {interval:"1d",limit:300};default:return {interval:"1h",limit:100}}}var xm=e=>{let{candlestickMarketSlugs:t,chartRange:n=ht,source:o}=e,r=usePredictClient(),i=useMemo(()=>jl(n),[n]),{data:s,isLoading:l,error:a}=useEvent({slug:e.eventSlug,source:o}),c=useMemo(()=>s?.markets?(t&&t.length>0?t.slice(0,4).map(g=>s.markets.find(v=>v.slug===g)).filter(g=>g!==void 0):[...s.markets].sort((g,v)=>fo(v)-fo(g)).slice(0,4)).map(g=>g.slug):[],[t,s?.markets]),d=useQueries({queries:c.map(f=>({queryKey:candlesticksQueryKey(f,i),queryFn:()=>r.listCandlesticks(f,i),enabled:c.length>0}))}),p=d.some(f=>f.isLoading),u=useMemo(()=>{let f=new Map;return c.forEach((g,v)=>{let h=d[v]?.error;h&&f.set(g,h);}),f},[c,d]),m=useMemo(()=>{let f=new Map;return c.forEach((g,v)=>{let h=d[v]?.data;h&&f.set(g,h);}),f},[c,d]);return {event:s,isEventLoading:l,eventError:a,candlestickParams:i,candlesticks:m,isCandlesticksLoading:p,candlestickErrors:u}};var Ql=10,Jl=atomWithStorage("liberfi:predict_search_histories",[],void 0,{getOnInit:true});function At(){let[e,t]=useAtom(Jl),n=useCallback(r=>{let i=r.trim();i&&t(s=>{let l=s.filter(a=>a!==i);return [i,...l].slice(0,Ql)});},[t]),o=useCallback(()=>{t([]);},[t]);return {histories:e,addHistory:n,clearHistories:o}}function ho({histories:e,onSelect:t,onClear:n,className:o}){let{t:r}=useTranslation();return e.length===0?null:jsxs("div",{className:cn$1("px-4 pb-4",o),children:[jsxs("div",{className:"flex items-center justify-between",children:[jsx("span",{className:"text-sm font-medium",children:r("predict.search.history")}),jsx(Button,{isIconOnly:true,size:"sm",className:"bg-transparent min-w-6 w-6 h-6 text-neutral",onPress:n,children:jsx(TrashIcon,{width:20,height:20})})]}),jsx("div",{className:"flex flex-wrap gap-2 mt-2",children:e.map(i=>jsx(Chip,{size:"sm",variant:"bordered",className:cn$1("text-neutral","border-border border-1","cursor-pointer","hover:opacity-hover"),onClick:()=>t?.(i),children:i},i))})]})}function bo({onSelect:e,className:t}){let{histories:n,clearHistories:o}=At();return jsx(ho,{className:cn$1(t),histories:n,onSelect:e,onClear:o})}function yo({value:e,onValueChange:t,onClear:n,onEscape:o,className:r}){let{t:i}=useTranslation();return jsx("div",{className:r,children:jsx(StyledInput,{autoFocus:true,variant:"flat",radius:"full",value:e,onValueChange:t,placeholder:i("predict.search.placeholder"),startContent:jsx(SearchIcon,{width:20,height:20,className:"text-neutral"}),endContent:e?jsx(Button,{isIconOnly:true,className:"bg-transparent min-w-6 w-6 h-6 text-neutral",onPress:n,children:jsx(XCloseIcon,{width:20,height:20})}):jsx(Kbd,{className:"min-w-8 justify-center text-xs text-neutral bg-transparent border border-border rounded-full cursor-pointer select-none",onMouseDown:s=>{s.preventDefault(),o?.();},children:"Esc"})})})}function No({event:e,href:t,LinkComponent:n,onSelect:o,onHover:r,className:i}){let{t:s}=useTranslation(),l=e.tags?.[0],a=useMemo(()=>`$${Math.round(e.volume??0).toLocaleString("en-US")}`,[e.volume]);return jsxs(Linkable,{href:t,LinkComponent:n,className:cn$1("w-full h-full px-3 flex items-center gap-3","hover:cursor-pointer hover:bg-content2 rounded-lg","transition-colors duration-150",i),onClick:c=>{t&&o&&c.preventDefault(),o?.(e);},onMouseEnter:()=>r?.(e),children:[jsx(Avatar,{src:e.image_url||void 0,name:e.title||"Event",radius:"full",className:"h-10 w-10 flex-shrink-0"}),jsxs("div",{className:"flex-1 min-w-0 flex flex-col justify-center gap-y-0.5",children:[jsx("span",{className:"min-w-0 text-sm font-medium truncate",children:e.title}),jsxs("div",{className:"flex items-center gap-x-2 text-[10px] font-normal text-neutral-500 lg:text-xs",children:[l&&jsx("span",{className:cn$1("inline-flex items-center","rounded-full px-1.5 py-0.5","text-[10px] font-semibold leading-none uppercase","bg-primary/15 text-primary"),children:l.label}),jsxs("span",{className:"inline-flex items-center gap-x-1.5",children:[a," ",s("predict.event.volume"),jsx(xc,{source:e.source})]})]})]})]})}function xc({source:e}){return jsxs("span",{className:"inline-flex items-center gap-x-1 text-neutral-400",title:e==="polymarket"?"Polymarket":"Kalshi",children:[jsx("span",{className:"text-neutral-600",children:"\xB7"}),e==="polymarket"?jsx(PolymarketIcon,{className:"h-5 w-auto shrink-0"}):jsx(KalshiIcon,{className:"h-3 w-auto shrink-0"})]})}function wo({keyword:e="",limit:t,source:n}){let{data:o,isLoading:r,isFetchingNextPage:i,hasNextPage:s,fetchNextPage:l}=useSearchEvents({keyword:e,limit:t,source:n},{enabled:true});return {events:useMemo(()=>o?.pages.flatMap(c=>c.items).filter(c=>c!=null)??[],[o]),isLoading:r,isFetchingNextPage:i,hasNextPage:s??false,fetchNextPage:l}}var Ec=56;function Co({onSelect:e,getEventHref:t,LinkComponent:n,onHover:o,className:r,...i}){let{events:s,isLoading:l,isFetchingNextPage:a,hasNextPage:c,fetchNextPage:d}=wo(i),p=useRef(null),{height:u}=useResizeObserver({ref:p}),m=useCallback(h=>h<s.length,[s]),f=useCallback(async()=>{c&&!a&&await d();},[c,a,d]),g=useMemo(()=>c?s.length+1:s.length,[s,c]),v=useInfiniteLoader({isRowLoaded:m,loadMoreRows:f,rowCount:g,threshold:5});return l?jsx(Tc,{className:r}):s.length===0?jsx(Mc,{className:r}):jsx("div",{className:cn$1("w-full h-full flex flex-col",r),children:jsx("div",{className:"flex-auto min-h-0",ref:p,children:jsx(List,{style:{height:u},onRowsRendered:v,rowComponent:Cc,rowCount:g,rowHeight:Ec,rowProps:{events:s,onSelect:e,getEventHref:t,LinkComponent:n,onHover:o},overscanCount:5})})})}function Cc({index:e,style:t,events:n,onSelect:o,getEventHref:r,LinkComponent:i,onHover:s}){let l=n[e];return l?jsx("div",{style:t,children:jsx(No,{event:l,href:r?.(l),LinkComponent:i,onSelect:o,onHover:s})}):jsx("div",{style:t,className:"flex items-center justify-center",children:jsx(Spinner,{size:"sm"})})}function Tc({className:e}){let{t}=useTranslation();return jsxs("div",{className:cn$1("flex items-center justify-center gap-2 py-16",e),children:[jsx(Spinner,{size:"sm"}),jsx("span",{className:"text-sm text-neutral",children:t("predict.search.loading")})]})}function Mc({className:e}){let{t}=useTranslation();return jsxs("div",{className:cn$1("flex flex-col items-center justify-center py-16",e),children:[jsx(EmptyIcon,{width:28,height:28,className:"text-neutral"}),jsx("p",{className:"mt-2 text-sm text-neutral",children:t("predict.search.noResults")})]})}function Lo({onKeywordChange:e}){let[t,n]=useState(""),[o,r]=useState(""),{addHistory:i}=At(),s=useCallbackRef(e),l=useCallbackRef(i),a=useMemo(()=>debounce(u=>{r(u),s(u),u&&l(u);},500),[s,l]),c=useCallback(u=>{n(u),a(u);},[a]),d=useCallback(u=>{a.cancel(),n(u),r(u),s(u),u&&l(u);},[a,s,l]),p=useCallback(()=>d(""),[d]);return {text:t,keyword:o,setText:c,setKeyword:d,clearKeyword:p}}function Oo({onKeywordChange:e,onSelectEvent:t,getEventHref:n,LinkComponent:o,onHover:r,onEscape:i,source:s}){let{text:l,keyword:a,setText:c,setKeyword:d,clearKeyword:p}=Lo({onKeywordChange:e});return jsxs("div",{className:"w-full h-full flex flex-col gap-3",children:[jsx(yo,{value:l,onValueChange:c,onClear:p,onEscape:i}),!a&&jsx(bo,{onSelect:d}),jsx(Co,{className:"flex-auto min-h-0",keyword:a,onSelect:t,getEventHref:n,LinkComponent:o,onHover:r,source:s})]})}var Tr="predict-search";function Bf({id:e=Tr}){return jsx(AsyncModal,{id:e,children:t=>jsx(Wc,{...t})})}function Wc({params:e,isOpen:t,onOpenChange:n,onResult:o}){let{t:r}=useTranslation(),{isMobile:i}=useScreen(),s=useCallback(a=>{o(a);},[o]),l=useCallback(()=>{n(false);},[n]);return jsx(StyledModal,{isOpen:t,onOpenChange:n,size:i?"full":"lg",hideCloseButton:true,backdrop:"blur",radius:"lg",children:jsxs(ModalContent,{className:"w-full h-full",children:[jsxs(ModalHeader,{className:"sm:hidden flex items-center justify-between pt-4 pb-2",children:[jsx("span",{className:"text-base font-semibold",children:r("predict.search.title")}),jsx(Button,{isIconOnly:true,onPress:()=>n(false),size:"sm",className:"bg-transparent min-w-6 w-6 h-6",children:jsx(XCloseIcon,{width:20,height:20})})]}),jsx(ModalBody,{className:"p-4",children:jsx(Oo,{getEventHref:e?.getEventHref,LinkComponent:e?.LinkComponent,onHover:e?.onHover,source:e?.source,onSelectEvent:s,onEscape:l})})]})})}function qf({onSelectEvent:e,modalParams:t,className:n}){let{t:o}=useTranslation(),{isDesktop:r,isMobile:i}=useScreen(),{onOpen:s,onClose:l}=useAsyncModal(Tr),a=useCallbackRef(e),c=useCallbackRef(async()=>{let p=await s({params:t});p&&a(p);}),d=useCallbackRef(()=>{l();});return useEffect(()=>{let p=u=>{let m=document.activeElement,f=!!m&&(m.tagName==="INPUT"||m.tagName==="TEXTAREA"||m.getAttribute("contenteditable")==="true");u.key==="/"&&!f&&(u.preventDefault(),c()),u.key==="Escape"&&(u.preventDefault(),d());};return window.addEventListener("keydown",p),()=>{window.removeEventListener("keydown",p);}},[c,d]),jsx(Button,{size:"sm",radius:"full",isIconOnly:!r,onPress:c,variant:i?"flat":"bordered",startContent:r?jsx(SearchIcon,{className:"text-neutral"}):void 0,endContent:r?jsx(Kbd,{className:"ml-auto min-w-6 justify-center text-xs bg-transparent border border-border rounded-full",children:"/"}):void 0,className:cn$1(r&&"min-w-56 justify-start pl-3 pr-1.5 text-neutral",n),children:r?o("predict.search.placeholder"):jsx(SearchIcon,{className:"text-neutral"})})}export{md as CHART_RANGE_DURATION,ud as CHART_RANGE_PERIOD,pd as CHART_RANGE_SAMPLE_INTERVAL,xt as CandlestickPeriod,rd as CategoriesSkeleton,Wr as CategoriesUI,Vr as CategoriesWidget,oe as ChartRange,ht as DEFAULT_CHART_RANGE,nr as DEFAULT_FILTER_STATE,Qe as DEFAULT_PAGE_SIZE,xd as DEFAULT_PRICE_HISTORY_INTERVAL,dm as EventDetailPage,at as EventDetailSkeleton,co as EventDetailUI,uo as EventDetailWidget,Rn as EventItem,Gn as EventMarketDepthChartUI,eo as EventMarketDetailWidget,no as EventPriceChart,pn as EventsFilterUI,ju as EventsPage,xu as EventsPageSkeleton,sr as EventsSkeleton,xn as EventsToolbarUI,An as EventsUI,Bn as EventsWidget,Gt as MAX_PRICE_HISTORY_MARKETS,vd as ORDER_MAX_PRICE,gd as ORDER_MIN_PRICE,Xt as ORDER_MIN_QUANTITY,fd as ORDER_PRICE_STEP,Tr as PREDICT_SEARCH_MODAL_ID,Je as PREDICT_TRADE_MODAL_ID,hd as PRICE_HISTORY_SAMPLE_INTERVAL,Bf as PredictSearchModal,yt as PredictTradeModal,ps as PredictWalletProvider,Be as PriceHistoryInterval,vn as SORT_PRESETS,jt as STATIC_CATEGORIES,qf as SearchEventsButton,ho as SearchHistoryUI,bo as SearchHistoryWidget,yo as SearchInputUI,No as SearchResultItemUI,Co as SearchResultListWidget,Oo as SearchWidget,_l as SimilarEventCard,po as SimilarEventsSection,zn as TradeFormSkeleton,cn as TradeFormUI,bt as TradeFormWidget,Wn as UserActivitySection,or as countActiveFilters,it as formatKMB,xm as useEventDetail,yn as useEventsInfinite,At as usePredictSearchHistory,Jt as usePredictWallet,wo as useSearchResultListScript,Lo as useSearchScript,tn as useTradeForm,Zo as version};//# sourceMappingURL=index.mjs.map
|
|
22
22
|
//# sourceMappingURL=index.mjs.map
|