@liberfi.io/ui-predict 0.1.84 → 0.1.86

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.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,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 Ht 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.84");var Bo="0.1.84";var Fo={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},Nr=["Politics","Sports","Crypto","Economics","Financials","Elections","Entertainment","Companies","Science and Technology","Climate and Weather","Mentions","Social","World"],Ot=(()=>{let e=t=>{let r=Nr.indexOf(t);return r===-1?Nr.length:r};return Object.entries(Fo).map(([t,r])=>({slug:t,label:t,tags:(r??[]).map(o=>({slug:o,label:o}))})).sort((t,r)=>e(t.slug)-e(r.slug))})();function Cr({categories:e,selectedCategory:t,selectedTag:r,activeTags:o,onCategorySelect:n,onTagSelect:s,trailing:a,pulsingTab:i="Trending",className:l}){let{t:d}=useTranslation(),c=useCallback(()=>{n(null);},[n]),u=d("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",l),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(Pr,{label:u,isSelected:t===null,onPress:c,showPulse:u===i}),jsx(zo,{}),e.map(m=>jsx(Pr,{label:m.category,isSelected:t===m.category,onPress:()=>n(m.category),badge:m.badge,showPulse:m.category===i},m.category))]})}),a&&jsx("div",{className:"flex-shrink-0",children:a})]}),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(Er,{label:d("predict.categories.allMarkets"),isSelected:r===null,onPress:()=>s(null)}),o.map(m=>jsx(Er,{label:m.label,icon:m.icon,isSelected:r===m.label,onPress:()=>s(m.label)},m.label))]})})]})}function Pr({label:e,isSelected:t,onPress:r,badge:o,showPulse:n}){return jsxs("button",{type:"button",onClick:r,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:[n?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 zo(){return jsx("span",{className:"flex items-center text-neutral-600","aria-hidden":"true",children:"|"})}function Er({label:e,icon:t,isSelected:r,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",r?"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 Tc({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,r)=>jsx(Skeleton,{className:"h-6 w-16 shrink-0 rounded"},r))})})}function Ko(e){return e.map(t=>({category:t.label,tags:t.tags.map(r=>r.label)}))}function Vo(e){return e?e.tags.map(t=>({label:t.label,icon:t.icon})):[]}function Rr({onSelect:e,trailing:t,className:r}){let[o,n]=useState(null),[s,a]=useState(null),i=useCallback(m=>{n(m),a(null),e?.({categorySlug:m,tagSlug:null});},[e]),l=useCallback(m=>{a(m),e?.({categorySlug:o,tagSlug:m});},[o,e]),d=Ko(Ot),c=Ot.find(m=>m.slug===o),u=Vo(c);return jsx(Cr,{categories:d,selectedCategory:o,selectedTag:s,activeTags:u,onCategorySelect:i,onTagSelect:l,trailing:t,className:r})}function Lr(e){return {title:e.title,imageUrl:e.image_url}}function Or(e){let t=e.outcomes[0],r=e.outcomes[1];return {yesAsk:t?.best_ask??t?.price,noAsk:r?.best_ask??r?.price,yesBid:t?.best_bid,noBid:r?.best_bid,yesSubTitle:t?.label??"Yes",noSubTitle:r?.label??"No"}}var Ue=48,It=4,st={ONE_MINUTE:1,ONE_HOUR:60,ONE_DAY:1440},te={ONE_DAY:"1d",ONE_WEEK:"1w",ONE_MONTH:"1m",ALL:"all"},at=te.ALL,Hc={[te.ONE_DAY]:st.ONE_MINUTE,[te.ONE_WEEK]:st.ONE_HOUR,[te.ONE_MONTH]:st.ONE_HOUR,[te.ALL]:st.ONE_DAY},Bc={[te.ONE_DAY]:300,[te.ONE_WEEK]:3600,[te.ONE_MONTH]:10800,[te.ALL]:1440*60},Fc={[te.ONE_DAY]:1440*60,[te.ONE_WEEK]:10080*60,[te.ONE_MONTH]:720*60*60,[te.ALL]:null},_t=1,Uc=1,Wc=1,$c=99,Ee={ONE_HOUR:"1h",SIX_HOURS:"6h",ONE_DAY:"1d",ONE_WEEK:"1w",MAX:"max"},zc=Ee.ONE_WEEK,Kc={[Ee.ONE_HOUR]:60,[Ee.SIX_HOURS]:60,[Ee.ONE_DAY]:300,[Ee.ONE_WEEK]:1800,[Ee.MAX]:1800};var Ar=createContext(null);function Dt(){let e=useContext(Ar);if(!e)throw new Error("usePredictWallet must be used within a PredictWalletProvider");return e}var Xo=3e4;function Qo({pollingInterval:e=Xo,enabled:t=true,children:r}){let o=useWallets(),n=useMemo(()=>o.find(f=>f.chainNamespace===ChainNamespace.SOLANA&&f.isConnected)?.address,[o]),s=useMemo(()=>o.find(f=>f.chainNamespace===ChainNamespace.EVM&&f.isConnected)?.address,[o]),{data:a,isLoading:i,error:l}=useBalance({source:"dflow",user:n??""},{enabled:t&&!!n,refetchInterval:e}),{data:d,isLoading:c,error:u}=useBalance({source:"polymarket",user:s??""},{enabled:t&&!!s,refetchInterval:e}),m=useMemo(()=>({solanaAddress:n,evmAddress:s,dflowUsdcBalance:a?Number(a.balance):0,polymarketUsdcBalance:d?Number(d.balance):0,isLoading:i||c,error:l??u??null}),[n,s,a,d,i,c,l,u]);return jsx(Ar.Provider,{value:m,children:r})}function Br(){let e={startVelocity:30,spread:360,ticks:60,zIndex:9999};Ht({...e,particleCount:80,origin:{x:.5,y:.4}}),setTimeout(()=>{Ht({...e,particleCount:40,origin:{x:.3,y:.6}});},150),setTimeout(()=>{Ht({...e,particleCount:40,origin:{x:.7,y:.6}});},300);}function Fr({market:e,initialOutcome:t="yes",initialSide:r="buy"}){let{t:o}=useTranslation(),{status:n}=useAuth(),s=useWallets(),a=useSwitchChain(),i=usePredictClient(),l=useContext(PolymarketContext),d=useQueryClient(),c=e.source,u=c==="polymarket",m=s.find(P=>P.chainNamespace===ChainNamespace.SOLANA&&P.isConnected),f=s.find(P=>P.chainNamespace===ChainNamespace.EVM&&P.isConnected&&"switchChain"in P),p=n==="authenticated",g=m?.address,v=f?.address,[b,U]=useState(t),[E,M]=useState(r),[T,G]=useState("market"),[C,N]=useState(NaN),[z,he]=useState(NaN),[ne,K]=useState(false),[oe,se]=useState(null),[we,Se]=useState(false),[w,x]=useState(null),R=null;try{let P=Dt();R={dflowUsdcBalance:P.dflowUsdcBalance,polymarketUsdcBalance:P.polymarketUsdcBalance,isLoading:P.isLoading};}catch{}let A=useMemo(()=>{let P=b==="yes"?0:1,H=e.outcomes[P];return E==="buy"?H?.best_ask??H?.price??.5:H?.best_bid??H?.price??.5},[e.outcomes,b,E]);useMemo(()=>isNaN(C)||C<=0?0:E==="buy"?A>0?C/A:0:C,[E,C,A]);let j=useMemo(()=>isNaN(C)||C<=0?"0":String(Math.round(C*1e6)),[C]),Fe=e.provider_meta?.["dflow.yesMint"]??"",yo=e.provider_meta?.["dflow.noMint"]??"",mr=e.provider_meta?.["dflow.collateralMint"]??"",fr=b==="yes"?Fe:yo,et=E==="buy"?mr:fr,tt=E==="buy"?fr:mr,wo=c==="dflow"&&!!et&&!!tt&&!!g&&j!=="0",{refetch:gr}=useDFlowQuote({inputMint:et,outputMint:tt,amount:j,userPublicKey:g??"",slippageBps:100},{enabled:wo}),vr=c==="dflow"?g??"":v??"",{data:me,isLoading:So}=usePositions({source:c,user:vr},{enabled:!!vr}),rt=useMemo(()=>R?c==="dflow"?R.dflowUsdcBalance:R.polymarketUsdcBalance:me&&me.positions.reduce((H,fe)=>fe.side==="USDC"||fe.side==="collateral"?H+(fe.current_value??0):H,0)||null,[R,me,c]),ko=R?R.isLoading:So,Pt=useMemo(()=>me?me.positions.find(H=>H.side?.toLowerCase()==="yes"&&H.market?.slug===e.slug)?.size??0:null,[me,e.slug]),Et=useMemo(()=>me?me.positions.find(H=>H.side?.toLowerCase()==="no"&&H.market?.slug===e.slug)?.size??0:null,[me,e.slug]),Ct=useMemo(()=>T==="limit"&&u&&!isNaN(z)?z:A,[T,u,z,A]),nt=useMemo(()=>{if(isNaN(C)||C<=0)return 0;if(E==="buy")return C;let P=b==="yes"?e.outcomes[0]?.best_bid??0:e.outcomes[1]?.best_bid??0;return C*P},[E,b,C,e.outcomes]),xr=useMemo(()=>isNaN(C)||C<=0?0:E==="buy"?Ct>0?C/Ct*1:0:nt,[E,C,Ct,nt]),No=xr-nt,Po=useCallback(P=>{M(P),N(NaN);},[]),Eo=useCallback(P=>{if(isNaN(P)){N(NaN);return}let H=Math.max(0,P),fe=E==="buy"?Math.round(H*100)/100:Math.round(H);N(fe);},[E]),Co=useCallback(P=>{if(isNaN(P)){he(NaN);return}let H=Math.max(.01,Math.min(.99,P));he(Math.round(H*100)/100);},[]),Tt=useMemo(()=>{let P=[];(isNaN(C)||C<_t)&&P.push(`Minimum quantity is ${_t}`),e.status!=="open"&&P.push("Market is not active"),E==="buy"&&rt!=null&&!isNaN(C)&&C>0&&C>rt&&P.push("Insufficient USDC balance");let H=b==="yes"?Pt:Et;return E==="sell"&&H!=null&&!isNaN(C)&&C>0&&C>H&&P.push("Insufficient shares"),T==="limit"&&u&&(isNaN(z)||z<.01||z>.99)&&P.push("Limit price must be between $0.01 and $0.99"),{isValid:P.length===0,errors:P}},[C,e.status,E,rt,Pt,Et,b,T,u,z]),{mutateAsync:hr}=useDFlowSubmit(),{data:Mt}=useOrder({id:oe??"",source:c},{enabled:!!oe});useEffect(()=>{if(!Mt||!oe)return;let{status:P}=Mt;P==="closed"?(K(false),se(null),toast.success(o("predict.trade.submitSuccess")),Br(),N(NaN)):(P==="failed"||P==="expired")&&(K(false),se(null),toast.error(o("predict.trade.submitError")));},[Mt,oe,o]);let br=useCallback(async()=>{if(!g||!m)return;let P=await i.checkDFlowKYC(g);if(!P.verified){Se(true),x(P.kyc_url||null),K(false);return}let ge=(await gr()).data?.transaction;if(!ge){toast.error(o("predict.trade.submitError")),K(false);return}let ce=Uint8Array.from(atob(ge),Lt=>Lt.charCodeAt(0)),Rt=await m.sendTransaction(ce);await hr({signedTransaction:btoa(String.fromCharCode(...ce)),orderContext:{user_public_key:g,input_mint:et,output_mint:tt,amount:j,price:String(A),side:E==="buy"?"BUY":"SELL",outcome:b==="yes"?"YES":"NO",market_slug:e.slug,slippage_bps:100}}),se(Rt);},[g,m,i,gr,hr,et,tt,j,A,E,b,e.slug,o]),yr=useCallback(async()=>{if(!f||!l)return;let P=f.chain,H=P!==Chain.POLYGON;H&&await a(Chain.POLYGON);try{let fe=await f.getEip1193Provider();if(!fe){toast.error(o("predict.trade.submitError")),K(!1);return}let ge={address:f.address,signatureType:0,signTypedData:async(Ao,Do,Ho)=>await fe.request({method:"eth_signTypedData_v4",params:[f.address,JSON.stringify({domain:Ao,types:Do,message:Ho})]})},ce=l.credentials;if(!ce&&(await l.authenticate(ge),ce=l.credentials,!ce))throw new Error("Polymarket authentication failed");let Rt=b==="yes"?0:1,Lt=e.provider_meta?.[`polymarket.tokenId${Rt}`]??e.provider_meta?.["polymarket.conditionId"]??"",wr=e.provider_meta?.["polymarket.negRisk"]??!1,Mo=T==="limit"&&!isNaN(z)?z:A,Sr={tokenId:Lt,price:Mo,size:C,side:E==="buy"?"BUY":"SELL",orderType:T==="limit"?"GTC":"FOK",tickSize:"0.01",negRisk:wr},Ro=buildCtfExchangeDomain(wr),Lo=buildOrderMessage({...Sr,signerAddress:ge.address,signatureType:ge.signatureType}),Oo=await ge.signTypedData(Ro,CTF_ORDER_TYPES,Lo),kr=buildSignedOrder({...Sr,signerAddress:ge.address,signatureType:ge.signatureType,signature:Oo}),Io=JSON.stringify(kr),_o=await buildPolymarketL2Headers(ce.address,{apiKey:ce.apiKey,secret:ce.secret,passphrase:ce.passphrase,method:"POST",requestPath:"/api/v1/orders/polymarket",body:Io});await i.createPolymarketOrder(kr,_o),d.invalidateQueries({queryKey:["predict","orders"]}),d.invalidateQueries({queryKey:["predict","positions"]}),toast.success(o("predict.trade.submitSuccess")),Br(),N(NaN),K(!1);}finally{H&&P&&a(P).catch(()=>{});}},[f,l,a,b,e.provider_meta,T,z,A,C,E,i,d,o]),To=useCallback(async()=>{if(!(!Tt.isValid||!p)){K(true),se(null),Se(false);try{c==="dflow"?await br():await yr();}catch{toast.error(o("predict.trade.submitError")),K(false);}}},[Tt.isValid,p,c,br,yr,o]);return {outcome:b,side:E,orderType:T,quantity:C,limitPrice:z,estimatedCost:nt,potentialPayout:xr,potentialProfit:No,usdcBalance:rt,yesTokenBalance:Pt,noTokenBalance:Et,isBalanceLoading:ko,isSubmitting:ne,validation:Tt,supportsLimitOrder:u,kycRequired:we,kycUrl:w,setOutcome:U,setSide:Po,setOrderType:G,setQuantity:Eo,setLimitPrice:Co,submit:To}}var Ts=`https://s1.chainstream.io/chains/sol/tokens/${SOLANA_TOKENS.stablecoins.USDC.address}/image.png`;function $r({event:e,market:t,outcome:r,side:o,orderType:n,quantity:s,limitPrice:a,potentialProfit:i,estimatedCost:l,usdcBalance:d,yesTokenBalance:c,noTokenBalance:u,isBalanceLoading:m,isSubmitting:f,isValid:p,supportsLimitOrder:g,kycRequired:v,kycUrl:b,onOutcomeChange:U,onSideChange:E,onOrderTypeChange:M,onQuantityChange:T,onLimitPriceChange:G,onSubmit:C}){let{t:N}=useTranslation(),[z,he]=useState(false),ne=useDisclosure(),K=useMemo(()=>{let x=o==="buy"?r==="yes"?t.yesAsk:t.noAsk:r==="yes"?t.yesBid:t.noBid;return x!=null?Math.round(Number(x)*100):null},[o,r,t]),oe=useMemo(()=>{if(f)return N("predict.trade.submitting");if(v)return N("predict.trade.kycRequired");if(!s||isNaN(s)||s<=0)return N("predict.trade.enterAmount");let x=N(o==="buy"?"predict.trade.buy":"predict.trade.sell"),R=N(r==="yes"?"predict.trade.yes":"predict.trade.no");return `${x} ${R}`},[f,v,s,o,r,N]),se=useMemo(()=>r==="yes"?"primary":"secondary",[r]),we=()=>{T(Math.floor((d??0)/2*100)/100);},Se=()=>{T(d??0);},w=()=>{if(v){ne.onOpen();return}C();};return jsxs(Fragment,{children:[jsxs("div",{className:"flex w-full flex-col gap-y-4 rounded-xl border border-default-200 bg-content1 p-4",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:r==="yes"?"text-bullish":"text-bearish",children:[N(o==="buy"?"predict.trade.buy":"predict.trade.sell")," ",N(r==="yes"?"predict.trade.yes":"predict.trade.no")]}),jsxs("span",{className:"text-foreground",children:[" \xB7 ",r==="yes"?t.yesSubTitle:t.noSubTitle]})]})]})]}),jsxs("div",{className:"flex items-center justify-between",children:[g?jsxs(Tabs,{variant:"underlined",selectedKey:n,onSelectionChange:x=>M(x),classNames:{tabList:"gap-x-4",tab:"px-0"},children:[jsx(Tab,{title:N("predict.trade.market")},"market"),jsx(Tab,{title:N("predict.trade.limit")},"limit")]}):jsx("span",{className:"text-sm font-medium text-foreground",children:N("predict.trade.market")}),K!=null&&jsxs("span",{className:"text-xl font-bold tabular-nums",children:[K," \xA2"]})]}),jsxs(Tabs,{variant:"underlined",selectedKey:o,onSelectionChange:x=>E(x),classNames:{tabList:"gap-x-4",tab:"px-0"},children:[jsx(Tab,{title:N("predict.trade.buy")},"buy"),jsx(Tab,{title:N("predict.trade.sell")},"sell")]}),jsx("div",{className:"flex gap-x-2",children:["yes","no"].map(x=>{let R=x==="yes"?c:u;return jsxs("div",{className:"flex flex-1 flex-col gap-y-1",children:[jsxs("button",{type:"button",onClick:()=>U(x),className:`w-full rounded-lg border py-2 text-sm font-medium transition-colors cursor-pointer ${r===x?x==="yes"?"border-primary bg-primary-50 text-primary":"border-secondary bg-secondary-50 text-secondary":"border-default-400 text-foreground hover:border-default-500"}`,children:[jsx("span",{children:N(x==="yes"?"predict.trade.yes":"predict.trade.no")}),(()=>{let A=o==="buy"?x==="yes"?t.yesAsk:t.noAsk:x==="yes"?t.yesBid:t.noBid;return A!=null?jsxs("span",{className:"ml-1 opacity-70",children:[Math.round(Number(A)*100),"\xA2"]}):null})()]}),o==="sell"&&r===x&&jsx("span",{className:"text-center text-xs text-foreground",children:m?"\u2013":`${R??0} shares`})]},x)})}),g&&n==="limit"&&jsxs("div",{className:"flex flex-col gap-y-1.5",children:[jsx("span",{className:"text-sm font-medium text-foreground",children:N("predict.trade.limitPrice")}),jsx(StyledNumberInput,{fullWidth:true,placeholder:"0.50",radius:"lg",size:"lg",value:isNaN(a)?void 0:a,onValueChange:x=>G(x),minValue:.01,maxValue:.99,step:.01,formatOptions:{maximumFractionDigits:2},startContent:jsx("span",{className:"text-default-600 text-xl",children:"$"}),classNames:{inputWrapper:"bg-content2 data-[hover=true]:bg-content2 group-data-[focus=true]:bg-content2 h-14 min-h-14",input:"text-lg"}})]}),o==="buy"&&jsxs("div",{className:"flex items-center justify-between text-xs text-neutral-500",children:[jsx("span",{children:N("predict.trade.youArePaying")}),jsxs("div",{className:"flex items-center gap-x-2",children:[jsx("img",{src:Ts,alt:"USDC",className:"h-3.5 w-3.5 rounded-full object-cover"}),jsx("span",{className:"font-medium text-foreground tabular-nums",children:d!=null?`${d.toFixed(6)} USDC`:"\u2013"}),jsx("button",{type:"button",onClick:we,className:"rounded px-1.5 py-0.5 bg-content2 hover:bg-content3 transition-colors cursor-pointer text-foreground font-medium",children:N("predict.trade.half")}),jsx("button",{type:"button",onClick:Se,className:"rounded px-1.5 py-0.5 bg-content2 hover:bg-content3 transition-colors cursor-pointer text-foreground font-medium",children:N("predict.trade.max")})]})]}),jsxs("div",{className:"flex flex-col gap-y-1.5",children:[jsx("span",{className:"text-sm font-medium text-foreground",children:N(o==="buy"?"predict.trade.amount":"predict.trade.contracts")}),jsx(StyledNumberInput,{fullWidth:true,placeholder:"0",radius:"lg",size:"lg",value:isNaN(s)?void 0:s,onValueChange:x=>{T(x);},minValue:0,step:o==="buy"?.01:1,formatOptions:o==="buy"?{maximumFractionDigits:2}:{maximumFractionDigits:0},startContent:o==="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"}},o),o==="sell"&&jsxs("div",{className:"flex gap-x-2 justify-end",children:[[25,50].map(x=>jsxs("button",{type:"button",onClick:()=>{T(Math.floor((r==="yes"?c??0:u??0)*x/100));},className:"rounded-md bg-content2 px-2.5 py-1 text-xs font-medium text-default-600 transition-colors hover:bg-content3 cursor-pointer",children:[x,"%"]},x)),jsx("button",{type:"button",onClick:()=>{T(r==="yes"?c??0:u??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:N("common.all")})]})]}),!isNaN(s)&&s>0&&jsxs("div",{className:"flex flex-col items-end gap-y-0.5",children:[jsx("span",{className:"text-sm text-foreground",children:N(o==="buy"?"predict.trade.potentialWin":"predict.trade.estimatedReceive")}),jsxs("span",{className:"text-xl font-semibold text-bullish",children:["$",(o==="buy"?i:l).toFixed(2)]})]}),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:()=>he(x=>!x),className:"flex items-center gap-x-1 text-neutral-500 hover:text-foreground cursor-pointer transition-colors",children:[jsx("span",{children:N("predict.trade.odds")}),jsx(ChevronDownIcon,{className:cn$1("h-3.5 w-3.5 transition-transform",z&&"rotate-180")})]}),K!=null&&jsxs("span",{className:"text-foreground font-medium tabular-nums",children:[K,"% chance"]})]}),z&&jsxs("div",{className:"flex items-center justify-between text-xs text-neutral-500",children:[jsxs("span",{children:[N("predict.trade.bestBid"),":"," ",Math.round((t.yesBid??0)*100),"\xA2"]}),jsxs("span",{children:[N("predict.trade.bestAsk"),":"," ",Math.round((t.yesAsk??0)*100),"\xA2"]})]})]}),jsx(Button,{color:se,fullWidth:true,radius:"lg",size:"lg",isDisabled:!v&&!p||f||!v&&(!s||isNaN(s)||s<=0),isLoading:f,onPress:w,children:oe})]}),jsx(Modal,{isOpen:ne.isOpen,onClose:ne.onClose,children:jsxs(ModalContent,{children:[jsx(ModalHeader,{className:"flex flex-col gap-1",children:N("predict.trade.kycModalTitle")}),jsx(ModalBody,{children:jsx("p",{className:"text-sm text-default-600",children:N("predict.trade.kycModalDescription")})}),jsxs(ModalFooter,{children:[jsx(Button,{variant:"light",onPress:ne.onClose,children:N("common.cancel")}),b&&jsx(Button,{color:"primary",onPress:()=>{window.open(b,"_blank","noopener,noreferrer"),ne.onClose();},children:N("predict.trade.goToKYC")})]})]})})]})}function lt({event:e,market:t,initialSide:r,initialOutcome:o,chain:n}){let{outcome:s,side:a,orderType:i,quantity:l,limitPrice:d,estimatedCost:c,potentialPayout:u,potentialProfit:m,usdcBalance:f,yesTokenBalance:p,noTokenBalance:g,isBalanceLoading:v,isSubmitting:b,validation:U,supportsLimitOrder:E,kycRequired:M,kycUrl:T,setOutcome:G,setSide:C,setOrderType:N,setQuantity:z,setLimitPrice:he,submit:ne}=Fr({market:t,initialSide:r,initialOutcome:o}),K=useAuthCallback(ne),oe=useMemo(()=>e?Lr(e):void 0,[e]),se=useMemo(()=>Or(t),[t]);return jsx($r,{event:oe,market:se,outcome:s,side:a,orderType:i,quantity:l,limitPrice:d,estimatedCost:c,potentialPayout:u,potentialProfit:m,usdcBalance:f,yesTokenBalance:p,noTokenBalance:g,isBalanceLoading:v,isSubmitting:b,isValid:U.isValid,validationErrors:U.errors,supportsLimitOrder:E,kycRequired:M,kycUrl:T,onOutcomeChange:G,onSideChange:C,onOrderTypeChange:N,onQuantityChange:z,onLimitPriceChange:he,onSubmit:K})}var Ut="predict-trade";function Kr({id:e=Ut}){return jsx(AsyncModal,{id:e,children:t=>jsx(Hs,{...t})})}function Hs({params:e,isOpen:t,onOpenChange:r}){let{isMobile:o}=useScreen();return e?jsx(StyledModal,{isOpen:t,onOpenChange:r,size:o?"full":"md",backdrop:"blur",radius:"lg",children:jsx(ModalContent,{children:jsx(ModalBody,{className:"p-4",children:jsx(lt,{event:e.event,market:e.market,initialOutcome:e.initialOutcome,initialSide:"buy",chain:e.chain})})})}):null}var Wt={sortPreset:"volume",sortAsc:false,source:"dflow",timeRemaining:void 0,minVolume:void 0,minLiquidity:void 0};function $t(e){let t=0;return e.source&&t++,e.timeRemaining&&t++,e.minVolume&&t++,e.minLiquidity&&t++,t}function Yr({isOpen:e,onClose:t,value:r,onChange:o}){let{t:n}=useTranslation(),[s,a]=useState(r),i=useCallback(v=>{v?a(r):t();},[r,t]),l=useCallback(()=>{a(Wt);},[]),d=useCallback(()=>{o(s),t();},[s,o,t]),c=useCallback((v,b)=>{a(U=>({...U,[v]:b}));},[]),u=useMemo(()=>$t(s),[s]),m=useMemo(()=>[{value:void 0,label:n("predict.filter.all")},{value:"polymarket",label:n("predict.platform.polymarket")},{value:"dflow",label:n("predict.platform.dflow")}],[n]),f=useMemo(()=>[{value:void 0,label:n("predict.filter.all")},{value:"1d",label:n("predict.filter.lessThanDay")},{value:"7d",label:n("predict.filter.lessThanWeek")},{value:"30d",label:n("predict.filter.lessThanMonth")}],[n]),p=useMemo(()=>[{value:void 0,label:n("predict.filter.all")},{value:"1000",label:">$1K"},{value:"10000",label:">$10K"},{value:"100000",label:">$100K"},{value:"1000000",label:">$1M"}],[n]),g=useMemo(()=>[{value:void 0,label:n("predict.filter.all")},{value:"1000",label:">$1K"},{value:"10000",label:">$10K"},{value:"100000",label:">$100K"},{value:"1000000",label:">$1M"}],[n]);return jsx(StyledModal,{isOpen:e,onOpenChange:i,size:"md",scrollBehavior:"inside",children:jsxs(ModalContent,{children:[jsx(ModalHeader,{className:"px-4 py-2",children:jsx("span",{className:"text-base font-semibold",children:n("predict.filter.title")})}),jsxs(ModalBody,{className:"flex flex-col gap-5",children:[jsx(dt,{label:n("predict.filter.platform"),children:jsx(ut,{options:m,selected:s.source,onSelect:v=>c("source",v)})}),jsx(dt,{label:n("predict.filter.timeRemaining"),children:jsx(ut,{options:f,selected:s.timeRemaining,onSelect:v=>c("timeRemaining",v)})}),jsx(dt,{label:n("predict.filter.minVolume"),children:jsx(ut,{options:p,selected:s.minVolume,onSelect:v=>c("minVolume",v)})}),jsx(dt,{label:n("predict.filter.minLiquidity"),children:jsx(ut,{options:g,selected:s.minLiquidity,onSelect:v=>c("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:l,children:n("predict.filter.reset")}),jsxs(Button,{color:"primary",size:"sm",radius:"full",onPress:d,children:[n("predict.filter.showResults"),u>0&&jsxs("span",{className:"ml-1 text-xs opacity-80",children:["(",u,")"]})]})]})})]})})}function dt({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 ut({options:e,selected:t,onSelect:r,allowDeselect:o=true}){return jsx("div",{className:"flex flex-wrap gap-2",children:e.map(n=>{let s=t===n.value;return jsx("button",{type:"button",onClick:()=>{r(s&&o?void 0:n.value);},className:cn$1("shrink-0 rounded-lg px-3 py-1.5 text-xs font-medium transition-colors duration-150 cursor-pointer border",s?"bg-primary/15 text-primary border-primary/40":"bg-content2 text-foreground/60 border-default-100 hover:bg-default-100 hover:text-foreground"),children:n.label},n.value??"__all")})})}var Xr={start_time:{sort_by:"created_at"},volume:{sort_by:"volume"},liquidity:{sort_by:"liquidity"},ending_soon:{sort_by:"end_at"}},Gr={start_time:"predict.sort.startTime",volume:"predict.sort.volume",liquidity:"predict.sort.liquidity",ending_soon:"predict.sort.endingSoon"},na=["start_time","volume","liquidity","ending_soon"];function Qr({sortPreset:e,onSortChange:t,sortAsc:r,onSortAscChange:o,onFilterPress:n,filterCount:s=0,className:a}){let{t:i}=useTranslation(),[l,d]=useState(false),c=useRef(null);useEffect(()=>{if(!l)return;let m=p=>{c.current&&!c.current.contains(p.target)&&d(false);},f=p=>{p.key==="Escape"&&d(false);};return document.addEventListener("mousedown",m),document.addEventListener("keydown",f),()=>{document.removeEventListener("mousedown",m),document.removeEventListener("keydown",f);}},[l]);let u=jr[e];return jsxs("div",{className:cn$1("flex items-center gap-2",a),children:[jsxs("div",{ref:c,className:"relative flex shrink-0 items-center rounded-full border border-border",children:[jsxs("button",{type:"button",onClick:()=>d(m=>!m),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(u,{className:"size-[18px] shrink-0"}),jsx("span",{className:"whitespace-nowrap",children:i(Gr[e])})]}),jsx("div",{className:"h-6 w-px bg-border"}),jsx("button",{type:"button",onClick:()=>o(!r),className:"px-2.5 py-1.5 text-xs text-neutral transition-colors hover:text-primary/80 cursor-pointer",children:r?"\u2191":"\u2193"}),l&&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:na.map(m=>{let f=jr[m];return jsxs("button",{type:"button",onClick:()=>{t(m),d(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",m===e?"bg-primary/10 text-primary":"text-neutral hover:bg-content2 hover:text-foreground"),children:[jsx(f,{className:"size-4 shrink-0"}),jsx("span",{children:i(Gr[m])})]},m)})})]}),jsx(StyledBadge,{content:s>0?s:void 0,color:"primary",size:"sm",isInvisible:s===0,children:jsxs("button",{type:"button",onClick:n,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:i("predict.filter.title")})]})})]})}var jr={start_time:CalendarIcon,volume:ChartLineIcon,liquidity:DropletIcon,ending_soon:TimerIcon};function en(e={}){let t=useMemo(()=>resolveEventsParams(e),[e.tagSlugSelection,e.limit,e.status,e.sort_by,e.sort_asc,e.source,e.with_markets]),{data:r,isLoading:o,isFetching:n,isFetchingNextPage:s,isError:a,error:i,hasNextPage:l,fetchNextPage:d,refetch:c}=useInfiniteEvents(t),u=useMemo(()=>r?.pages.flatMap(p=>p.items).filter(p=>p!=null)??[],[r]),m=useCallback(()=>{d();},[d]),f=useCallback(()=>{c();},[c]);return {data:u,isLoading:o,isFetching:n&&!s,isFetchingMore:s,isError:a,error:i??null,hasMore:l??false,fetchMore:m,refetch:f}}function zt({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,r)=>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"})]})]})},r))})}function $d({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(zt,{count:e})})]})}var tn=3,Vt={bg:"hsl(var(--heroui-primary) / 0.14)",text:"hsl(var(--heroui-primary))",shadow:"hsl(var(--heroui-primary) / 0.18)"},ln={bg:"hsl(var(--heroui-secondary) / 0.14)",text:"hsl(var(--heroui-secondary))",shadow:"hsl(var(--heroui-secondary) / 0.18)"},pa={bg:"rgba(239, 68, 68, 0.14)",text:"rgb(239, 68, 68)",shadow:"rgba(239, 68, 68, 0.18)"},ze=[{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 rn(e){let t=0;for(let r=0;r<e.length;r++)t=(t<<5)-t+e.charCodeAt(r)|0;return Math.abs(t)}function ma(e){let t=e.outcomes?.map(a=>a.label?.toLowerCase().trim()??"")??[];if(t.some(a=>a==="up")&&t.some(a=>a==="down"))return [Vt,pa];if(t.some(a=>a==="yes")&&t.some(a=>a==="no"))return [Vt,ln];let r=t[0]??"",o=t[1]??"",n=rn(r)%ze.length,s=rn(o)%ze.length;return s===n&&(s=(s+1)%ze.length),[ze[n],ze[s]]}function fa(e){let t=e.outcomes?.[0];return t?t.best_ask??t.price??null:null}function cn(e){let t=fa(e);return t!=null?Math.round(t*100):0}function dn(e){return e<=1&&e>0?"< 1%":e>=99&&e<100?"> 99%":`${e}%`}function nn(e){let t=e.outcomes?.[0];return ((t?.best_ask??t?.price??0)*100).toFixed(1)}function on(e){let t=e.outcomes?.[1];if(t){let n=t.best_ask??t.price??0;return Math.round(n*100).toString()}let r=e.outcomes?.[0],o=r?.best_ask??r?.price??0;return Math.round((1-o)*100).toString()}function ga(e){let t=new Date(e).getTime()-Date.now();if(t<=0)return null;let r=Math.floor(t/864e5),o=Math.floor(t%864e5/36e5),n=Math.floor(t%36e5/6e4),s=[];return r>0&&s.push(`${r}d`),o>0&&s.push(`${o}h`),s.push(`${n}m`),s.join(" ")}var va=`
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,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 Wt 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.86");var $o="0.1.86";var zo={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},Cr=["Politics","Sports","Crypto","Economics","Financials","Elections","Entertainment","Companies","Science and Technology","Climate and Weather","Mentions","Social","World"],Dt=(()=>{let e=t=>{let n=Cr.indexOf(t);return n===-1?Cr.length:n};return Object.entries(zo).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 Rr({categories:e,selectedCategory:t,selectedTag:n,activeTags:o,onCategorySelect:r,onTagSelect:a,trailing:s,pulsingTab:i="Trending",className:l}){let{t:d}=useTranslation(),c=useCallback(()=>{r(null);},[r]),m=d("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",l),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(Tr,{label:m,isSelected:t===null,onPress:c,showPulse:m===i}),jsx(qo,{}),e.map(p=>jsx(Tr,{label:p.category,isSelected:t===p.category,onPress:()=>r(p.category),badge:p.badge,showPulse:p.category===i},p.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(Mr,{label:d("predict.categories.allMarkets"),isSelected:n===null,onPress:()=>a(null)}),o.map(p=>jsx(Mr,{label:p.label,icon:p.icon,isSelected:n===p.label,onPress:()=>a(p.label)},p.label))]})})]})}function Tr({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 qo(){return jsx("span",{className:"flex items-center text-neutral-600","aria-hidden":"true",children:"|"})}function Mr({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 Oc({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 jo(e){return e.map(t=>({category:t.label,tags:t.tags.map(n=>n.label)}))}function Go(e){return e?e.tags.map(t=>({label:t.label,icon:t.icon})):[]}function Ir({onSelect:e,trailing:t,className:n}){let[o,r]=useState(null),[a,s]=useState(null),i=useCallback(p=>{r(p),s(null),e?.({categorySlug:p,tagSlug:null});},[e]),l=useCallback(p=>{s(p),e?.({categorySlug:o,tagSlug:p});},[o,e]),d=jo(Dt),c=Dt.find(p=>p.slug===o),m=Go(c);return jsx(Rr,{categories:d,selectedCategory:o,selectedTag:a,activeTags:m,onCategorySelect:i,onTagSelect:l,trailing:t,className:n})}function _r(e){return {title:e.title,imageUrl:e.image_url}}function Ar(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 Ye=48,Ft=4,dt={ONE_MINUTE:1,ONE_HOUR:60,ONE_DAY:1440},ne={ONE_DAY:"1d",ONE_WEEK:"1w",ONE_MONTH:"1m",ALL:"all"},ut=ne.ALL,Wc={[ne.ONE_DAY]:dt.ONE_MINUTE,[ne.ONE_WEEK]:dt.ONE_HOUR,[ne.ONE_MONTH]:dt.ONE_HOUR,[ne.ALL]:dt.ONE_DAY},$c={[ne.ONE_DAY]:300,[ne.ONE_WEEK]:3600,[ne.ONE_MONTH]:10800,[ne.ALL]:1440*60},zc={[ne.ONE_DAY]:1440*60,[ne.ONE_WEEK]:10080*60,[ne.ONE_MONTH]:720*60*60,[ne.ALL]:null},Ht=1,Kc=1,Vc=1,Yc=99,Ie={ONE_HOUR:"1h",SIX_HOURS:"6h",ONE_DAY:"1d",ONE_WEEK:"1w",MAX:"max"},qc=Ie.ONE_WEEK,jc={[Ie.ONE_HOUR]:60,[Ie.SIX_HOURS]:60,[Ie.ONE_DAY]:300,[Ie.ONE_WEEK]:1800,[Ie.MAX]:1800};var Hr=createContext(null);function Ut(){let e=useContext(Hr);if(!e)throw new Error("usePredictWallet must be used within a PredictWalletProvider");return e}var es=3e4;function ts({pollingInterval:e=es,enabled:t=true,children:n}){let o=useWallets(),r=useMemo(()=>o.find(f=>f.chainNamespace===ChainNamespace.SOLANA&&f.isConnected)?.address,[o]),a=useMemo(()=>o.find(f=>f.chainNamespace===ChainNamespace.EVM&&f.isConnected)?.address,[o]),{data:s,isLoading:i,error:l}=useBalance({source:"dflow",user:r??""},{enabled:t&&!!r,refetchInterval:e}),{data:d,isLoading:c,error:m}=useBalance({source:"polymarket",user:a??""},{enabled:t&&!!a,refetchInterval:e}),p=useMemo(()=>({solanaAddress:r,evmAddress:a,dflowUsdcBalance:s?Number(s.balance):0,polymarketUsdcBalance:d?Number(d.balance):0,isLoading:i||c,error:l??m??null}),[r,a,s,d,i,c,l,m]);return jsx(Hr.Provider,{value:p,children:n})}function $r(){let e={startVelocity:30,spread:360,ticks:60,zIndex:9999};Wt({...e,particleCount:80,origin:{x:.5,y:.4}}),setTimeout(()=>{Wt({...e,particleCount:40,origin:{x:.3,y:.6}});},150),setTimeout(()=>{Wt({...e,particleCount:40,origin:{x:.7,y:.6}});},300);}function zr({market:e,initialOutcome:t="yes",initialSide:n="buy"}){let{t:o}=useTranslation(),{status:r}=useAuth(),a=useWallets(),s=useSwitchChain(),i=usePredictClient(),l=useContext(PolymarketContext),d=useQueryClient(),c=e.source,m=c==="polymarket",p=a.find(w=>w.chainNamespace===ChainNamespace.SOLANA&&w.isConnected),f=a.find(w=>w.chainNamespace===ChainNamespace.EVM&&w.isConnected&&"switchChain"in w),u=r==="authenticated",g=p?.address,v=f?.address,[h,$]=useState(t),[P,C]=useState(n),[R,j]=useState("market"),[M,ce]=useState(NaN),[W,ue]=useState(NaN),[Se,N]=useState(false),[re,se]=useState(null),[Q,ae]=useState(false),[y,T]=useState(null),I=null;try{let w=Ut();I={dflowUsdcBalance:w.dflowUsdcBalance,polymarketUsdcBalance:w.polymarketUsdcBalance,isLoading:w.isLoading};}catch{}let D=useMemo(()=>{let w=h==="yes"?0:1,H=e.outcomes[w];return P==="buy"?H?.best_ask??H?.price??.5:H?.best_bid??H?.price??.5},[e.outcomes,h,P]),G=useCallback(w=>{j(w);},[]),J=useCallback(w=>{$(w),ue(NaN);},[]);useEffect(()=>{R==="limit"&&isNaN(W)&&ue(Math.round(D*100)/100);},[R,W,D]);let ge=useMemo(()=>isNaN(M)||M<=0?0:P==="buy"?D>0?M/D:0:M,[P,M,D]),Le=useMemo(()=>isNaN(M)||M<=0?"0":String(Math.round(M*1e6)),[M]),_=e.provider_meta?.["dflow.yesMint"]??"",Oe=e.provider_meta?.["dflow.noMint"]??"",Ee=e.provider_meta?.["dflow.collateralMint"]||SOLANA_TOKENS.stablecoins.USDC.address,hr=h==="yes"?_:Oe,Ke=P==="buy"?Ee:hr,Ve=P==="buy"?hr:Ee,Po=c==="dflow"&&!!Ke&&!!Ve&&!!g&&Le!=="0",{refetch:br}=useDFlowQuote({inputMint:Ke,outputMint:Ve,amount:Le,userPublicKey:g??"",slippageBps:100},{enabled:Po}),yr=c==="dflow"?g??"":v??"",{data:ve,isLoading:Eo}=usePositions({source:c,user:yr},{enabled:!!yr}),at=useMemo(()=>I?c==="dflow"?I.dflowUsdcBalance:I.polymarketUsdcBalance:ve&&ve.positions.reduce((H,xe)=>xe.side==="USDC"||xe.side==="collateral"?H+(xe.current_value??0):H,0)||null,[I,ve,c]),Co=I?I.isLoading:Eo,Mt=useMemo(()=>ve?ve.positions.find(H=>H.side?.toLowerCase()==="yes"&&H.market?.slug===e.slug)?.size??0:null,[ve,e.slug]),Rt=useMemo(()=>ve?ve.positions.find(H=>H.side?.toLowerCase()==="no"&&H.market?.slug===e.slug)?.size??0:null,[ve,e.slug]),Lt=useMemo(()=>R==="limit"&&m&&!isNaN(W)?W:D,[R,m,W,D]),it=useMemo(()=>{if(isNaN(M)||M<=0)return 0;if(P==="buy")return M;let w=h==="yes"?e.outcomes[0]?.best_bid??0:e.outcomes[1]?.best_bid??0;return M*w},[P,h,M,e.outcomes]),wr=useMemo(()=>isNaN(M)||M<=0?0:P==="buy"?Lt>0?M/Lt*1:0:it,[P,M,Lt,it]),To=wr-it,Mo=useCallback(w=>{C(w),ce(NaN);},[]),Ro=useCallback(w=>{if(isNaN(w)){ce(NaN);return}let H=Math.max(0,w),xe=P==="buy"?Math.round(H*100)/100:Math.round(H);ce(xe);},[P]),Lo=useCallback(w=>{if(isNaN(w)){ue(NaN);return}let H=Math.max(.01,Math.min(.99,w));ue(Math.round(H*100)/100);},[]),Ot=useMemo(()=>{let w=[];(isNaN(M)||M<Ht)&&w.push(`Minimum quantity is ${Ht}`),e.status!=="open"&&w.push("Market is not active"),P==="buy"&&at!=null&&!isNaN(M)&&M>0&&M>at&&w.push("Insufficient USDC balance");let H=h==="yes"?Mt:Rt;return P==="sell"&&H!=null&&!isNaN(M)&&M>0&&M>H&&w.push("Insufficient shares"),R==="limit"&&m&&(isNaN(W)||W<.01||W>.99)&&w.push("Limit price must be between $0.01 and $0.99"),{isValid:w.length===0,errors:w}},[M,e.status,P,at,Mt,Rt,h,R,m,W]),{mutateAsync:Sr}=useDFlowSubmit(),{data:It}=useOrder({id:re??"",source:c},{enabled:!!re});useEffect(()=>{if(!It||!re)return;let{status:w}=It;w==="closed"?(N(false),se(null),toast.success(o("predict.trade.submitSuccess")),$r(),ce(NaN)):(w==="failed"||w==="expired")&&(N(false),se(null),toast.error(o("predict.trade.submitError")));},[It,re,o]);let Nr=useCallback(async()=>{if(!g||!p)return;if(!Ke||!Ve){toast.error("Missing token mint addresses"),N(false);return}let w=await i.checkDFlowKYC(g);if(!w.verified){ae(true),T(w.kyc_url||null),N(false);return}let he=(await br()).data?.transaction;if(!he){toast.error(o("predict.trade.submitError")),N(false);return}let be=Uint8Array.from(atob(he),lt=>lt.charCodeAt(0)),_t=await p.signTransaction(be),At=await Sr({signedTransaction:btoa(String.fromCharCode(..._t)),orderContext:{user_public_key:g,input_mint:Ke,output_mint:Ve,amount:Le,price:String(D),side:P==="buy"?"BUY":"SELL",outcome:h==="yes"?"YES":"NO",market_slug:e.slug,slippage_bps:100}});se(At.signature);},[g,p,i,br,Sr,Ke,Ve,Le,D,P,h,e.slug,o]),kr=useCallback(async()=>{if(!f||!l)return;let w=f.chain,H=w!==Chain.POLYGON;H&&await s(Chain.POLYGON);try{let xe=await f.getEip1193Provider();if(!xe){toast.error(o("predict.trade.submitError")),N(!1);return}let he={address:f.address,signatureType:0,signTypedData:async(Bo,Uo,Wo)=>await xe.request({method:"eth_signTypedData_v4",params:[f.address,JSON.stringify({domain:Bo,types:Uo,message:Wo})]})},be=l.credentials;if(!be&&(await l.authenticate(he),be=l.credentials,!be))throw new Error("Polymarket authentication failed");let _t=h==="yes"?0:1,At=e.provider_meta?.[`polymarket.tokenId${_t}`]??e.provider_meta?.["polymarket.conditionId"]??"",lt=e.provider_meta?.["polymarket.negRisk"]??!1,Io=R==="limit"&&!isNaN(W)?W:D,Pr={tokenId:At,price:Io,size:M,side:P==="buy"?"BUY":"SELL",orderType:R==="limit"?"GTC":"FOK",tickSize:"0.01",negRisk:lt},_o=buildCtfExchangeDomain(lt),Ao=buildOrderMessage({...Pr,signerAddress:he.address,signatureType:he.signatureType}),Do=await he.signTypedData(_o,CTF_ORDER_TYPES,Ao),Er=buildSignedOrder({...Pr,signerAddress:he.address,signatureType:he.signatureType,signature:Do}),Fo=JSON.stringify(Er),Ho=await buildPolymarketL2Headers(be.address,{apiKey:be.apiKey,secret:be.secret,passphrase:be.passphrase,method:"POST",requestPath:"/api/v1/orders/polymarket",body:Fo});await i.createPolymarketOrder(Er,Ho),d.invalidateQueries({queryKey:["predict","orders"]}),d.invalidateQueries({queryKey:["predict","positions"]}),toast.success(o("predict.trade.submitSuccess")),$r(),ce(NaN),N(!1);}finally{H&&w&&s(w).catch(()=>{});}},[f,l,s,h,e.provider_meta,R,W,D,M,P,i,d,o]),Oo=useCallback(async()=>{if(!(!Ot.isValid||!u)){N(true),se(null),ae(false);try{c==="dflow"?await Nr():await kr();}catch{toast.error(o("predict.trade.submitError")),N(false);}}},[Ot.isValid,u,c,Nr,kr,o]);return {outcome:h,side:P,orderType:R,quantity:M,limitPrice:W,shares:ge,estimatedCost:it,potentialPayout:wr,potentialProfit:To,usdcBalance:at,yesTokenBalance:Mt,noTokenBalance:Rt,isBalanceLoading:Co,isSubmitting:Se,validation:Ot,supportsLimitOrder:m,kycRequired:Q,kycUrl:y,setOutcome:J,setSide:Mo,setOrderType:G,setQuantity:Ro,setLimitPrice:Lo,submit:Oo}}var Os=`https://s1.chainstream.io/chains/sol/tokens/${SOLANA_TOKENS.stablecoins.USDC.address}/image.png`;function jr({event:e,market:t,variant:n="bordered",outcome:o,side:r,orderType:a,quantity:s,limitPrice:i,shares:l,potentialProfit:d,potentialPayout:c,estimatedCost:m,usdcBalance:p,yesTokenBalance:f,noTokenBalance:u,isBalanceLoading:g,isSubmitting:v,isValid:h,validationErrors:$,supportsLimitOrder:P,kycRequired:C,kycUrl:R,onOutcomeChange:j,onSideChange:M,onOrderTypeChange:ce,onQuantityChange:W,onLimitPriceChange:ue,onSubmit:Se}){let{t:N}=useTranslation(),[re,se]=useState(false),Q=useDisclosure();useEffect(()=>{C&&!Q.isOpen&&Q.onOpen();},[C]);let ae=useMemo(()=>{let _=r==="buy"?o==="yes"?t.yesAsk:t.noAsk:o==="yes"?t.yesBid:t.noBid;return _!=null?parseFloat((Number(_)*100).toFixed(2)):null},[r,o,t]),y=!isNaN(s)&&s>0,T=useMemo(()=>{if(v)return N("predict.trade.submitting");if(C)return N("predict.trade.kycRequired");if(!y)return N("predict.trade.enterAmount");let _=N(r==="buy"?"predict.trade.buy":"predict.trade.sell"),Oe=N(o==="yes"?"predict.trade.yes":"predict.trade.no"),Ee=r==="buy"&&d>0?` \u2192 Win $${d.toFixed(2)}`:"";return `${_} ${Oe}${Ee}`},[v,C,y,r,o,d,N]),I=useMemo(()=>o==="yes"?"primary":"secondary",[o]),D=()=>{W(Math.floor((p??0)/2*100)/100);},G=()=>{W(p??0);},[J,ge]=useState(false),Le=()=>{if(C){Q.onOpen();return}if(!h){ge(true);return}ge(false),Se();};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:[N(r==="buy"?"predict.trade.buy":"predict.trade.sell")," ",N(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:[P?jsxs(Tabs,{variant:"underlined",selectedKey:a,onSelectionChange:_=>ce(_),classNames:{tabList:"gap-x-4",tab:"px-0"},children:[jsx(Tab,{title:N("predict.trade.market")},"market"),jsx(Tab,{title:N("predict.trade.limit")},"limit")]}):jsx("span",{className:"text-sm font-medium text-foreground",children:N("predict.trade.market")}),a==="limit"&&P?jsx(StyledNumberInput,{"aria-label":"Limit price",placeholder:"50",size:"sm",radius:"none",value:isNaN(i)?void 0:parseFloat((i*100).toFixed(2)),onValueChange:_=>ue(_/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"}}):ae!=null&&jsxs("span",{className:"text-xl font-bold tabular-nums",children:[ae," \xA2"]})]}),jsx("div",{className:"flex gap-x-2",children:["yes","no"].map(_=>{let Oe=_==="yes"?f:u;return jsxs("div",{className:"flex flex-1 flex-col gap-y-1",children:[jsxs("button",{type:"button",onClick:()=>j(_),className:`w-full rounded-lg border py-2 text-sm font-medium transition-colors cursor-pointer ${o===_?_==="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:N(_==="yes"?"predict.trade.yes":"predict.trade.no")}),(()=>{let Ee=r==="buy"?_==="yes"?t.yesAsk:t.noAsk:_==="yes"?t.yesBid:t.noBid;return Ee!=null?jsxs("span",{className:"ml-1 opacity-70",children:[parseFloat((Number(Ee)*100).toFixed(2)),"\xA2"]}):null})()]}),r==="sell"&&o===_&&jsx("span",{className:"text-center text-xs text-foreground",children:g?"\u2013":`${Oe??0} shares`})]},_)})}),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:N(r==="buy"?"predict.trade.youArePaying":"predict.trade.contracts")}),r==="buy"&&jsxs("div",{className:"flex items-center gap-x-2",children:[jsx("img",{src:Os,alt:"USDC",className:"h-3.5 w-3.5 rounded-full object-cover"}),jsx("span",{className:"font-medium text-foreground tabular-nums",children:p!=null?`${p.toFixed(2)} USDC`:"\u2013"}),jsx("button",{type:"button",onClick:D,className:"rounded px-1.5 py-0.5 bg-content2 hover:bg-content3 transition-colors cursor-pointer text-foreground font-medium",children:N("predict.trade.half")}),jsx("button",{type:"button",onClick:G,className:"rounded px-1.5 py-0.5 bg-content2 hover:bg-content3 transition-colors cursor-pointer text-foreground font-medium",children:N("predict.trade.max")})]})]}),jsx(StyledNumberInput,{fullWidth:true,placeholder:"0",radius:"lg",size:"lg",value:isNaN(s)?void 0:s,onValueChange:_=>{ge(false),W(_);},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(_=>jsxs("button",{type:"button",onClick:()=>{W(Math.floor((o==="yes"?f??0:u??0)*_/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:[_,"%"]},_)),jsx("button",{type:"button",onClick:()=>{W(o==="yes"?f??0:u??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:N("common.all")})]}),J&&$.length>0&&jsx("div",{className:"flex flex-col gap-y-0.5",children:$.map(_=>jsx("span",{className:"text-xs text-danger",children:_},_))})]}),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:()=>se(_=>!_),className:"flex items-center gap-x-1 text-neutral-500 hover:text-foreground cursor-pointer transition-colors",children:[jsx("span",{children:N("predict.trade.odds")}),jsx(ChevronDownIcon,{className:cn$1("h-3.5 w-3.5 transition-transform",re&&"rotate-180")})]}),ae!=null&&jsxs("span",{className:"text-foreground font-medium tabular-nums",children:[ae,"% chance"]})]}),re&&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?`$${m.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(l)&&l>0?parseFloat(l.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?`$${c.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&&d>0?`+$${d.toFixed(2)}`:"\u2013"})]})]})]}),jsx(Button,{color:I,fullWidth:true,radius:"lg",size:"lg",isDisabled:!y||v,isLoading:v,onPress:Le,children:T})]}),jsx(Modal,{isOpen:Q.isOpen,onClose:Q.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 ",N("predict.trade.kycModalTitle")]})}),jsxs(ModalBody,{className:"gap-y-4",children:[jsx("p",{className:"text-sm text-default-600",children:N("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:N("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:N("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:N("predict.trade.kycModalBullet3")})]})]}),jsx("p",{className:"text-xs text-default-400",children:N("predict.trade.kycModalNote")})]}),jsxs(ModalFooter,{children:[jsx(Button,{variant:"light",onPress:Q.onClose,children:N("common.cancel")}),R&&jsx(Button,{color:"primary",onPress:()=>{window.open(R,"_blank","noopener,noreferrer"),Q.onClose();},children:N("predict.trade.goToKYC")})]})]})})]})}function pt({event:e,market:t,variant:n,initialSide:o,initialOutcome:r,chain:a}){let{outcome:s,side:i,orderType:l,quantity:d,limitPrice:c,shares:m,estimatedCost:p,potentialPayout:f,potentialProfit:u,usdcBalance:g,yesTokenBalance:v,noTokenBalance:h,isBalanceLoading:$,isSubmitting:P,validation:C,supportsLimitOrder:R,kycRequired:j,kycUrl:M,setOutcome:ce,setSide:W,setOrderType:ue,setQuantity:Se,setLimitPrice:N,submit:re}=zr({market:t,initialSide:o,initialOutcome:r}),se=useAuthCallback(re),Q=useMemo(()=>e?_r(e):void 0,[e]),ae=useMemo(()=>Ar(t),[t]);return jsx(jr,{event:Q,market:ae,variant:n,outcome:s,side:i,orderType:l,quantity:d,limitPrice:c,shares:m,estimatedCost:p,potentialPayout:f,potentialProfit:u,usdcBalance:g,yesTokenBalance:v,noTokenBalance:h,isBalanceLoading:$,isSubmitting:P,isValid:C.isValid,validationErrors:C.errors,supportsLimitOrder:R,kycRequired:j,kycUrl:M,onOutcomeChange:ce,onSideChange:W,onOrderTypeChange:ue,onQuantityChange:Se,onLimitPriceChange:N,onSubmit:se})}var Kt="predict-trade";function Xr({id:e=Kt}){return jsx(AsyncModal,{id:e,children:t=>jsx(Ws,{...t})})}function Ws({params:e,isOpen:t,onOpenChange:n}){let{isMobile:o}=useScreen();return e?jsx(StyledModal,{isOpen:t,onOpenChange:n,size:o?"full":"md",backdrop:"blur",radius:"lg",children:jsx(ModalContent,{children:jsx(ModalBody,{className:"p-4",children:jsx(pt,{event:e.event,market:e.market,initialOutcome:e.initialOutcome,initialSide:"buy",chain:e.chain,variant:"flat"})})})}):null}var Vt={sortPreset:"volume",sortAsc:false,source:void 0,timeRemaining:void 0,minVolume:void 0,minLiquidity:void 0};function Yt(e){let t=0;return e.source&&t++,e.timeRemaining&&t++,e.minVolume&&t++,e.minLiquidity&&t++,t}function Jr({isOpen:e,onClose:t,value:n,onChange:o}){let{t:r}=useTranslation(),[a,s]=useState(n),i=useCallback(v=>{v?s(n):t();},[n,t]),l=useCallback(()=>{s(Vt);},[]),d=useCallback(()=>{o(a),t();},[a,o,t]),c=useCallback((v,h)=>{s($=>({...$,[v]:h}));},[]),m=useMemo(()=>Yt(a),[a]),p=useMemo(()=>[{value:void 0,label:r("predict.filter.all")},{value:"polymarket",label:r("predict.platform.polymarket")},{value:"dflow",label:r("predict.platform.dflow")}],[r]),f=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]),u=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:i,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(ft,{label:r("predict.filter.platform"),children:jsx(gt,{options:p,selected:a.source,onSelect:v=>c("source",v)})}),jsx(ft,{label:r("predict.filter.timeRemaining"),children:jsx(gt,{options:f,selected:a.timeRemaining,onSelect:v=>c("timeRemaining",v)})}),jsx(ft,{label:r("predict.filter.minVolume"),children:jsx(gt,{options:u,selected:a.minVolume,onSelect:v=>c("minVolume",v)})}),jsx(ft,{label:r("predict.filter.minLiquidity"),children:jsx(gt,{options:g,selected:a.minLiquidity,onSelect:v=>c("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:l,children:r("predict.filter.reset")}),jsxs(Button,{color:"primary",size:"sm",radius:"full",onPress:d,children:[r("predict.filter.showResults"),m>0&&jsxs("span",{className:"ml-1 text-xs opacity-80",children:["(",m,")"]})]})]})})]})})}function ft({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 gt({options:e,selected:t,onSelect:n,allowDeselect:o=true}){return jsx("div",{className:"flex flex-wrap gap-2",children:e.map(r=>{let a=t===r.value;return jsx("button",{type:"button",onClick:()=>{n(a&&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",a?"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 rn={start_time:{sort_by:"created_at"},volume:{sort_by:"volume"},liquidity:{sort_by:"liquidity"},ending_soon:{sort_by:"end_at"}},en={start_time:"predict.sort.startTime",volume:"predict.sort.volume",liquidity:"predict.sort.liquidity",ending_soon:"predict.sort.endingSoon"},ia=["start_time","volume","liquidity","ending_soon"];function nn({sortPreset:e,onSortChange:t,sortAsc:n,onSortAscChange:o,onFilterPress:r,filterCount:a=0,className:s}){let{t:i}=useTranslation(),[l,d]=useState(false),c=useRef(null);useEffect(()=>{if(!l)return;let p=u=>{c.current&&!c.current.contains(u.target)&&d(false);},f=u=>{u.key==="Escape"&&d(false);};return document.addEventListener("mousedown",p),document.addEventListener("keydown",f),()=>{document.removeEventListener("mousedown",p),document.removeEventListener("keydown",f);}},[l]);let m=tn[e];return jsxs("div",{className:cn$1("flex items-center gap-2",s),children:[jsxs("div",{ref:c,className:"relative flex shrink-0 items-center rounded-full border border-border",children:[jsxs("button",{type:"button",onClick:()=>d(p=>!p),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(m,{className:"size-[18px] shrink-0"}),jsx("span",{className:"whitespace-nowrap",children:i(en[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"}),l&&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:ia.map(p=>{let f=tn[p];return jsxs("button",{type:"button",onClick:()=>{t(p),d(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",p===e?"bg-primary/10 text-primary":"text-neutral hover:bg-content2 hover:text-foreground"),children:[jsx(f,{className:"size-4 shrink-0"}),jsx("span",{children:i(en[p])})]},p)})})]}),jsx(StyledBadge,{content:a>0?a:void 0,color:"primary",size:"sm",isInvisible:a===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:i("predict.filter.title")})]})})]})}var tn={start_time:CalendarIcon,volume:ChartLineIcon,liquidity:DropletIcon,ending_soon:TimerIcon};function an(e={}){let t=useMemo(()=>resolveEventsParams(e),[e.tagSlugSelection,e.limit,e.status,e.sort_by,e.sort_asc,e.source,e.with_markets]),{data:n,isLoading:o,isFetching:r,isFetchingNextPage:a,isError:s,error:i,hasNextPage:l,fetchNextPage:d,refetch:c}=useInfiniteEvents(t),m=useMemo(()=>n?.pages.flatMap(u=>u.items).filter(u=>u!=null)??[],[n]),p=useCallback(()=>{d();},[d]),f=useCallback(()=>{c();},[c]);return {data:m,isLoading:o,isFetching:r&&!a,isFetchingMore:a,isError:s,error:i??null,hasMore:l??false,fetchMore:p,refetch:f}}function qt({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 qd({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(qt,{count:e})})]})}var ln=3,Gt={bg:"hsl(var(--heroui-primary) / 0.14)",text:"hsl(var(--heroui-primary))",shadow:"hsl(var(--heroui-primary) / 0.18)"},fn={bg:"hsl(var(--heroui-secondary) / 0.14)",text:"hsl(var(--heroui-secondary))",shadow:"hsl(var(--heroui-secondary) / 0.18)"},va={bg:"rgba(239, 68, 68, 0.14)",text:"rgb(239, 68, 68)",shadow:"rgba(239, 68, 68, 0.18)"},Ge=[{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 cn(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 xa(e){let t=e.outcomes?.map(s=>s.label?.toLowerCase().trim()??"")??[];if(t.some(s=>s==="up")&&t.some(s=>s==="down"))return [Gt,va];if(t.some(s=>s==="yes")&&t.some(s=>s==="no"))return [Gt,fn];let n=t[0]??"",o=t[1]??"",r=cn(n)%Ge.length,a=cn(o)%Ge.length;return a===r&&(a=(a+1)%Ge.length),[Ge[r],Ge[a]]}function ha(e){let t=e.outcomes?.[0];return t?t.best_ask??t.price??null:null}function gn(e){let t=ha(e);return t!=null?parseFloat((t*100).toFixed(2)):0}function vn(e){return e<=1&&e>0?"< 1%":e>=99&&e<100?"> 99%":`${e}%`}function dn(e){let t=e.outcomes?.[0],n=t?.best_ask??t?.price??0;return parseFloat((n*100).toFixed(2)).toString()}function un(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 ba(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),a=[];return n>0&&a.push(`${n}d`),o>0&&a.push(`${o}h`),a.push(`${r}m`),a.join(" ")}var ya=`
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 un({event:e,href:t,LinkComponent:r,onSelect:o,onSelectOutcome:n,onHover:s}){let[a,i]=useState(null),l=e.markets??[],d=useMemo(()=>l.length>2?[...l].sort((M,T)=>(T.outcomes?.[0]?.price??0)-(M.outcomes?.[0]?.price??0)):l,[l]),c=d.filter(M=>M.status==="open"),u=d.length===1,m=c.slice(0,tn),f=c.length-tn,p=useMemo(()=>`$${Math.round(e.volume??0).toLocaleString("en-US")}`,[e.volume]),g=a?c.find(M=>M.slug===a)??null:null,v=!!g||u,b=()=>{v||o?.(e);},U=M=>{M.stopPropagation(),g&&(M.preventDefault(),i(null));},E=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:()=>s?.(e),onClick:b,children:[jsx("style",{children:va}),jsx(xa,{event:e,href:t,LinkComponent:r,onClick:U,isExpanded:v}),jsx("div",{className:"flex flex-1 flex-col",children:u?jsx(Pa,{market:c[0],event:e,formattedVolume:p,href:t,LinkComponent:r,onSelect:o,onSelectOutcome:n}):g?jsx(Ea,{market:g,event:e,onCollapse:()=>i(null),onSelectOutcome:n}):jsx(ka,{displayedMarkets:m,moreCount:f,formattedVolume:p,source:e.source,href:t,LinkComponent:r,onMarketClick:M=>i(M.slug),onShowMore:E})})]})}function xa({event:e,href:t,LinkComponent:r,onClick:o,isExpanded:n}){let s=e.start_at?ga(e.start_at):null;return jsxs(Linkable,{href:t,LinkComponent:r,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",n&&"group-hover/header:text-neutral-400"),children:e.title}),s&&jsxs("span",{className:"text-[10px] leading-4 text-neutral-500",children:["Live in ",s]})]}),jsx(ba,{event:e})]})}function ha(e){let t=[];if(e.status==="closed")return t.push({kind:"closed"}),t.slice(0,2);let r=e.tags?.some(n=>n.label?.toLowerCase()==="crypto"),o=e.tags?.some(n=>n.label?.toLowerCase()==="live");if(r&&e.end_at){let n=new Date(e.end_at).getTime()-Date.now(),s=300*1e3,a=900*1e3;if(n>0&&n<=a){let i=n<=s?"#ef4444":"#f59e0b";t.push({kind:"crypto-short",label:n<=s?"5m":"15m",color:i});}}return o&&t.push({kind:"live"}),t.slice(0,2)}function ba({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((r,o)=>{switch(r.kind){case "live":return jsx(ya,{},o);case "crypto-short":return jsx(wa,{label:r.label,color:r.color},o);case "closed":return jsx(Sa,{},o)}})})}function ya(){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 Sa(){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:r,source:o,href:n,LinkComponent:s,onMarketClick:a,onShowMore:i}){let{t:l}=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(d=>{let c=cn(d);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:u=>{u.stopPropagation(),a(d);},children:[jsx("span",{className:"min-w-0 flex-1 text-left text-xs text-slate-200 line-clamp-1 lg:text-sm",children:d.outcomes?.[0]?.label??d.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:dn(c)}),jsx(Na,{})]})]},d.slug)})}),jsxs("div",{className:"mt-auto flex items-center justify-between pt-3",children:[t>0?jsxs(Linkable,{href:n,LinkComponent:s,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:i,children:[l("predict.event.showMore"),jsx(mn,{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:[r," ",l("predict.event.volume"),jsx(fn,{source:o})]})]})]})}function sn({bgColor:e,textColor:t,shadowColor:r,onClick:o,children:n}){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":r,"--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:i=>{let l=i.currentTarget;l.style.setProperty("--shadow-offset","2px"),l.style.transform="translateY(2px)";},onMouseLeave:i=>{let l=i.currentTarget;l.style.setProperty("--shadow-offset","4px"),l.style.transform="translateY(0px)";},onClick:o,children:n})}function pn({market:e,event:t,onSelectOutcome:r,dynamicColors:o=false,labelFormat:n="action"}){let{t:s}=useTranslation(),[a,i]=o?ma(e):[Vt,ln],l=e.outcomes?.[0]?.label?.toLowerCase().trim()??"",d=e.outcomes?.[1]?.label?.toLowerCase().trim()??"",c=n==="label"&&l===d?"action":n,u=c==="label"?`${e.outcomes?.[0]?.label??"Yes"} ${nn(e)}\xA2`:s("predict.market.action.yes",{price:nn(e)}),m=c==="label"?`${e.outcomes?.[1]?.label??"No"} ${on(e)}\xA2`:s("predict.market.action.no",{price:on(e)});return jsxs("div",{className:"flex gap-2",children:[jsx(sn,{bgColor:a.bg,textColor:a.text,shadowColor:a.shadow,onClick:f=>{f.stopPropagation(),r?.(t,e,"yes");},children:u}),jsx(sn,{bgColor:i.bg,textColor:i.text,shadowColor:i.shadow,onClick:f=>{f.stopPropagation(),r?.(t,e,"no");},children:m})]})}function Na(){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 Pa({market:e,event:t,formattedVolume:r,href:o,LinkComponent:n,onSelect:s,onSelectOutcome:a}){let{t:i}=useTranslation();return jsxs(Fragment,{children:[jsx("div",{className:"flex-1",children:jsx(pn,{market:e,event:t,onSelectOutcome:a,dynamicColors:true,labelFormat:"label"})}),jsxs("div",{className:"mt-auto flex items-center justify-between pt-3",children:[jsxs(Linkable,{href:o,LinkComponent:n,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:d=>{d.stopPropagation(),o||(d.preventDefault(),s?.(t));},children:[i("predict.event.viewEvent"),jsx(mn,{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:[r," ",i("predict.event.volume"),jsx(fn,{source:t.source})]})]})]})}function Ea({market:e,event:t,onCollapse:r,onSelectOutcome:o}){let{t:n}=useTranslation(),s=cn(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:a=>{a.stopPropagation(),r();},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:dn(s)}),jsx(ChevronUpIcon,{className:"h-4 w-4 text-neutral-400"})]})]}),jsx("div",{className:"mt-3",children:jsx(pn,{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:a=>{a.stopPropagation(),r();},children:[jsx(Ca,{className:"h-3 w-3"}),n("predict.event.back")]})]})}function mn({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 Ca({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 fn({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 Ia=768,vn=1024,_a=1280,Aa=8,Da=224,Ha=304,Ba=114;function Fa(e){return e>=_a?4:e>=vn?3:e>=Ia?2:1}function Ua(e){return e>=vn?Ha:Da}function xn({events:e,hasMore:t=false,onFetchMore:r,onSelect:o,onSelectOutcome:n,getEventHref:s,LinkComponent:a,onHover:i}){let l=useRef(null),d=useRef(null),{width:c=0,height:u=0}=useResizeObserver({ref:l}),m=Fa(c),f=Ua(c),p=Math.ceil(e.length/m)||0,g=!t&&e.length>0,v=p+(t?1:0)+(g?1:0),b=useCallback(T=>T<p,[p]),U=useCallback(async()=>{r?.();},[r]),E=useInfiniteLoader({isRowLoaded:b,loadMoreRows:U,rowCount:v,threshold:3}),M=useCallback(()=>{d.current?.scrollToRow({index:0,behavior:"smooth"});},[]);return jsx("div",{ref:l,className:"@container w-full h-full",children:u>0&&jsx(List,{listRef:d,className:"no-scrollbar",style:{height:u},onRowsRendered:E,rowComponent:Wa,rowCount:v,rowHeight:T=>g&&T===v-1?Ba:(f),rowProps:{events:e,columnCount:m,dataRowCount:p,showEndOfList:g,totalRowCount:v,onSelect:o,onSelectOutcome:n,getEventHref:s,LinkComponent:a,onHover:i,onScrollToTop:M}})})}function Wa({index:e,style:t,events:r,columnCount:o,dataRowCount:n,showEndOfList:s,totalRowCount:a,onSelect:i,onSelectOutcome:l,getEventHref:d,LinkComponent:c,onHover:u,onScrollToTop:m}){if(s&&e===a-1)return jsx("div",{style:t,children:jsx($a,{onScrollToTop:m})});if(e>=n)return jsx("div",{style:t,className:"flex justify-center items-start pt-4",children:jsx(Spinner,{size:"sm"})});let f=e*o,p=r.slice(f,f+o),g=o-p.length;return jsx("div",{style:t,children:jsxs("div",{className:"flex w-full h-full",children:[p.map(v=>v==null?null:jsx("div",{className:"flex-1 min-w-0 flex",style:{padding:Aa},children:jsx(un,{event:v,href:d?.(v),LinkComponent:c,onSelect:i,onSelectOutcome:l,onHover:u})},v.slug)),g>0&&Array.from({length:g}).map((v,b)=>jsx("div",{style:{flex:1,minWidth:0}},`spacer-${b}`))]})})}function $a({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:r,sort_by:o,sort_asc:n,source:s,with_markets:a,onSelect:i,onSelectOutcome:l,getEventHref:d,LinkComponent:c,onHover:u}){let{data:m,hasMore:f,fetchMore:p,isFetching:g}=en({tagSlugSelection:e,limit:t,status:r,sort_by:o,sort_asc:n,source:s,with_markets:a});return g?jsx(zt,{count:48}):jsx(xn,{events:m,hasMore:f,onFetchMore:p,onSelect:i,onSelectOutcome:l,getEventHref:d,LinkComponent:c,onHover:u})}function bu({onSelect:e,onSelectOutcome:t,getEventHref:r,LinkComponent:o,onHover:n}){let[s,a]=useState({categorySlug:null,tagSlug:null}),[i,l]=useState(Wt),{isOpen:d,onOpen:c,onClose:u}=useDisclosure(),{onOpen:m}=useAsyncModal(Ut),f=useCallback((T,G,C)=>{t?.(T,G,C),m({params:{event:T,market:G,initialOutcome:C}});},[t,m]),p=useCallback(T=>{a(T);},[]),g=useCallback(T=>{l(G=>({...G,sortPreset:T}));},[]),v=useCallback(T=>{l(G=>({...G,sortAsc:T}));},[]),b=useCallback(T=>{l(T);},[]),U=useMemo(()=>Xr[i.sortPreset].sort_by,[i.sortPreset]),E=useMemo(()=>$t(i),[i]),M=jsx(Qr,{sortPreset:i.sortPreset,onSortChange:g,sortAsc:i.sortAsc,onSortAscChange:v,onFilterPress:c,filterCount:E});return jsxs("div",{className:"flex h-full w-full max-w-[1680px] mx-auto flex-col gap-y-3",children:[jsx(Rr,{onSelect:p,trailing:M}),jsx(Yr,{isOpen:d,onClose:u,value:i,onChange:b}),jsx("div",{className:"min-h-0 flex-1",children:jsx(bn,{tagSlugSelection:s,sort_by:U,sort_asc:i.sortAsc,source:i.source,onSelect:e,onSelectOutcome:f,getEventHref:r,LinkComponent:o,onHover:n})}),jsx(Kr,{})]})}var Qt=40,gt=36,qe=480,Jt=qe-gt;function Nn({event:e,walletAddress:t,onCancelOrder:r}){let{t:o}=useTranslation(),[n,s]=useState("positions"),a=useMemo(()=>e.markets?.map(u=>u.slug)??[],[e.markets]),{data:i}=usePositions({source:e.source,user:t??""}),l=useMemo(()=>!i?.positions||!t?0:a.length===0?i.positions.length:i.positions.filter(u=>u.market&&a.includes(u.market.slug)).length,[i?.positions,a,t]),c=[{key:"positions",label:l>0?`${o("predict.positions.title")} (${l})`: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:c.map(u=>jsx("button",{type:"button",onClick:()=>s(u.key),className:cn$1("px-3 py-2 text-sm font-medium transition-colors cursor-pointer",n===u.key?"text-foreground border-b-2 border-primary":"text-neutral hover:text-foreground"),children:u.label},u.key))}),t?jsxs("div",{style:{height:qe},children:[n==="positions"&&jsx(Qa,{source:e.source,walletAddress:t,marketSlugs:a}),n==="orders"&&jsx(Za,{source:e.source,walletAddress:t,marketSlugs:a,onCancelOrder:r}),n==="trades"&&jsx(ri,{source:e.source,walletAddress:t})]}):jsx("div",{className:"flex items-center justify-center text-sm text-neutral",style:{height:qe},children:o("predict.trade.connectWallet")})]})}function Qa({source:e,walletAddress:t,marketSlugs:r}){let{t:o}=useTranslation(),{data:n,isLoading:s}=usePositions({source:e,user:t}),a=useMemo(()=>n?.positions?r.length===0?n.positions:n.positions.filter(i=>i.market&&r.includes(i.market.slug)):[],[n?.positions,r]);return s?jsx(er,{}):a.length===0?jsx(Zt,{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:gt},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:Jt},rowComponent:Ja,rowCount:a.length,rowHeight:Qt,rowProps:{positions:a,closeLabel:o("predict.positions.close")}})]})}function Ja({index:e,style:t,positions:r,closeLabel:o}){let n=r[e];if(!n)return null;let s=n.pnl??0,a=n.pnl_percent??0,i=n.avg_price??0,l=n.current_price??0,d=s>0?"text-success":s<0?"text-danger":"text-foreground",c=s>0?"+":"",u=n.market?.outcomes?.[0]?.label??n.market?.question??"\u2014",m=n.side,f=n.size,p=n.size*l,g=n.market?.end_at?si(n.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:u}),jsx("span",{className:cn$1("text-[10px] font-medium",m.toLowerCase()==="yes"?"text-primary":"text-secondary"),children:m})]})}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:n.size}),jsxs("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:["$",p.toFixed(2)]}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:mt(i)}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:mt(l)}),jsxs("div",{className:cn$1("flex-[1.5] pr-2 text-right font-mono whitespace-nowrap",d),children:[c,"$",Math.abs(s).toFixed(2),jsxs("span",{className:"text-[10px] ml-0.5 opacity-70",children:["(",c,a.toFixed(1),"%)"]})]}),jsxs("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:["$",f.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 Za({source:e,walletAddress:t,marketSlugs:r,onCancelOrder:o}){let{t:n}=useTranslation(),{data:s,isLoading:a,fetchNextPage:i,hasNextPage:l}=useInfiniteOrders({source:e,wallet_address:t}),d=useCancelOrder(),c=useMemo(()=>{let b=s?.pages?.flatMap(M=>M.items)??[],U=new Set(["live","open","submitted","pending"]),E=b.filter(M=>U.has(M.status));return r.length>0&&(E=E.filter(M=>M.market_id&&r.includes(M.market_id))),E},[s?.pages,r]),u=useCallback(b=>{o?o(b.id):d.mutate({source:b.source,id:b.id});},[o,d]),m=c.length,f=m+(l?1:0),p=useCallback(b=>b<m,[m]),g=useCallback(async()=>{await i();},[i]),v=useInfiniteLoader({isRowLoaded:p,loadMoreRows:g,rowCount:f,threshold:5});return a?jsx(er,{}):c.length===0&&!l?jsx(Zt,{message:n("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:gt},children:[jsx("div",{className:"w-16 shrink-0 pr-2",children:n("predict.openOrders.side")}),jsx("div",{className:"flex-1 pr-2",children:n("predict.openOrders.outcome")}),jsx("div",{className:"flex-1 pr-2",children:n("predict.openOrders.type")}),jsx("div",{className:"flex-1 pr-2 text-right",children:n("predict.openOrders.price")}),jsx("div",{className:"flex-1 pr-2 text-right",children:n("predict.openOrders.filled")}),jsx("div",{className:"w-20 shrink-0 pr-2",children:n("predict.openOrders.status")}),jsx("div",{className:"w-16 shrink-0"})]}),jsx(List,{style:{height:Jt},onRowsRendered:v,rowComponent:ei,rowCount:f,rowHeight:Qt,rowProps:{orders:c,itemCount:m,onCancel:u,isCancelling:d.isPending,cancelLabel:n("predict.openOrders.cancel")}})]})}function ei({index:e,style:t,orders:r,itemCount:o,onCancel:n,isCancelling:s,cancelLabel:a}){if(e>=o)return jsx("div",{style:t,className:"flex justify-center items-center",children:jsx(Spinner,{size:"sm"})});let i=r[e];if(!i)return null;let l=i.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",l?"bg-primary/10 text-primary":"bg-danger/10 text-danger"),children:i.side})}),jsx("div",{className:"flex-1 pr-2 text-foreground capitalize",children:i.outcome??"\u2014"}),jsx("div",{className:"flex-1 pr-2 text-neutral capitalize",children:i.order_type??"limit"}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:i.price?mt(parseFloat(i.price)):"\u2014"}),jsxs("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:[i.size_matched??"0","/",i.original_size??"\u2014"]}),jsx("div",{className:"w-20 shrink-0 pr-2",children:jsx(ti,{status:i.status})}),jsx("div",{className:"w-16 shrink-0 text-right",children:jsx("button",{type:"button",onClick:()=>n(i),disabled:s,className:"text-[10px] text-danger hover:text-danger/80 cursor-pointer disabled:opacity-50 transition-colors",children:s?jsx(Spinner,{size:"sm"}):a})})]})}function ti({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 ri({source:e,walletAddress:t}){let{t:r}=useTranslation(),{data:o,isLoading:n,fetchNextPage:s,hasNextPage:a}=useInfiniteTrades({source:e,wallet:t,limit:50}),i=useMemo(()=>o?.pages?.flatMap(f=>f.items)??[],[o?.pages]),l=i.length,d=l+(a?1:0),c=useCallback(f=>f<l,[l]),u=useCallback(async()=>{await s();},[s]),m=useInfiniteLoader({isRowLoaded:c,loadMoreRows:u,rowCount:d,threshold:5});return n?jsx(er,{}):i.length===0&&!a?jsx(Zt,{message:r("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:gt},children:[jsx("div",{className:"w-16 shrink-0 pr-2",children:r("predict.tradeHistory.side")}),jsx("div",{className:"flex-1 pr-2",children:r("predict.tradeHistory.outcome")}),jsx("div",{className:"flex-1 pr-2 text-right",children:r("predict.tradeHistory.price")}),jsx("div",{className:"flex-1 pr-2 text-right",children:r("predict.tradeHistory.qty")}),jsx("div",{className:"flex-1 pr-2 text-right",children:r("predict.tradeHistory.total")}),jsx("div",{className:"flex-[1.5] pr-2 text-right",children:r("predict.tradeHistory.time")})]}),jsx(List,{style:{height:Jt},onRowsRendered:m,rowComponent:ni,rowCount:d,rowHeight:Qt,rowProps:{trades:i,itemCount:l}})]})}function ni({index:e,style:t,trades:r,itemCount:o}){if(e>=o)return jsx("div",{style:t,className:"flex justify-center items-center",children:jsx(Spinner,{size:"sm"})});let n=r[e];if(!n)return null;let s=n.side?.toUpperCase()==="BUY",a=oi(n.timestamp),i=n.price??0,l=n.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",s?"bg-primary/10 text-primary":"bg-danger/10 text-danger"),children:n.side})}),jsx("div",{className:"flex-1 pr-2 text-foreground capitalize",children:n.outcome??"\u2014"}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:mt(i)}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:n.size}),jsxs("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:["$",l.toFixed(2)]}),jsx("div",{className:"flex-[1.5] pr-2 text-right text-neutral whitespace-nowrap",children:a})]})}function Zt({message:e}){return jsx("div",{className:"flex items-center justify-center text-sm text-neutral",style:{height:qe},children:e})}function er(){return jsx("div",{className:"flex flex-col gap-y-2 py-3 animate-pulse",style:{height:qe},children:Array.from({length:6}).map((e,t)=>jsx(Skeleton,{className:"h-8 w-full rounded-md"},t))})}function mt(e){let t=e*100;return t<1&&t>0?"< 1\xA2":`${t.toFixed(1)}\xA2`}function oi(e){let t=new Date(e*1e3),r=(t.getMonth()+1).toString().padStart(2,"0"),o=t.getDate().toString().padStart(2,"0"),n=t.getHours().toString().padStart(2,"0"),s=t.getMinutes().toString().padStart(2,"0");return `${r}/${o} ${n}:${s}`}function si(e){try{return new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}catch{return "\u2014"}}function Ge({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((r,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 Pn(){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 Tn="var(--color-bullish)",Mn="var(--color-bearish)";function je(e){if(Math.abs(e)>=1e4){let t=e/1e4;return `${parseFloat(t.toFixed(2))}\u4E07`}return e.toLocaleString()}function li(e,t){return e<=0||t<=0?0:Math.pow(e/t,.3)}function ci(e,t){let r=new Float64Array(101),o=new Float64Array(101);for(let f of e){let p=Math.round(f.price*100);p>=0&&p<=100&&(r[p]+=f.quantity);}for(let f of t){let p=Math.round(f.price*100);p>=0&&p<=100&&(o[p]+=f.quantity);}let n=0,s=0,a=new Float64Array(101),i=new Float64Array(101);for(let f=100;f>=0;f--)n+=r[f],s+=r[f]*f/100,a[f]=n,i[f]=s;let l=0,d=0,c=new Float64Array(101),u=new Float64Array(101);for(let f=0;f<=100;f++)l+=o[f],d+=o[f]*f/100,c[f]=l,u[f]=d;let m=Math.max(a[0]??0,c[100]??0);return Array.from({length:101},(f,p)=>{let g=a[p]>0,v=c[p]>0,b=a[p]||c[p],U=r[p]>0||o[p]>0;return {priceCents:p,displayHeight:li(b,m),opacity:b>0?U?1:.5:0,isBid:g,isAsk:v,bidCumTotal:a[p],askCumTotal:c[p],bidCumCost:i[p],askCumCost:u[p]}})}function di({info:e}){let t=e.isBid?Tn:Mn,r=e.leftPct>65?void 0:`${e.leftPct}%`,o=e.leftPct>65?`${100-e.leftPct}%`:void 0;return jsxs("div",{style:{position:"absolute",top:8,left:r,right:o,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:[jsxs("div",{style:{marginBottom:4,fontWeight:600},children:[e.priceCents,"\xA2"]}),jsxs("div",{style:{color:t},children:[je(Math.round(e.cumTotal))," contracts"]}),jsxs("div",{style:{color:t},children:["$",je(Math.round(e.cumCost))]})]})}var ui=memo(function({slot:t,onEnter:r,onLeave:o}){let n=useRef(null),s=t.isBid||t.isAsk,a=t.isBid?Tn:t.isAsk?Mn: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:s?"crosshair":"default"},onMouseEnter:()=>r(t,n.current),onMouseLeave:o,children:s&&jsx("div",{ref:n,style:{position:"absolute",bottom:0,left:0,width:"100%",height:`${t.displayHeight*100}%`,backgroundColor:a,opacity:t.opacity}})})}),pi=[0,10,20,30,40,50,60,70,80,90,100];function mi(){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:pi.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 Rn({bids:e,asks:t}){let r=useMemo(()=>ci(e,t),[e,t]),o=useMemo(()=>{let c=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((c+u)/2*100)},[e,t]),n=useMemo(()=>r.some(c=>c.isBid||c.isAsk),[r]),[s,a]=useState(null),i=useRef(null),l=useCallback((c,u)=>{i.current&&(i.current.style.filter=""),u?(u.style.filter="brightness(1.5)",i.current=u):i.current=null,c.isBid||c.isAsk?a({priceCents:c.priceCents,isBid:c.isBid,cumTotal:c.isBid?c.bidCumTotal:c.askCumTotal,cumCost:c.isBid?c.bidCumCost:c.askCumCost,leftPct:c.priceCents}):a(null);},[]),d=useCallback(()=>{i.current&&(i.current.style.filter="",i.current=null),a(null);},[]);return n?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:[o>0&&jsx("div",{style:{position:"absolute",left:`${o}%`,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(di,{info:s}),r.map(c=>jsx(ui,{slot:c,onEnter:l,onLeave:d},c.priceCents))]}),jsx(mi,{})]}):jsx("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#6b7280",fontSize:13},children:"No depth data"})}function Ln(e){let t=e*100,r=Math.round(t*10)/10;return Number.isInteger(r)?`${r}\xA2`:`${r.toFixed(1)}\xA2`}function On(){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 Dn({market:e,outcome:t="yes",onTradeAction:r}){let{t:o}=useTranslation(),[n,s]=useState("depth"),a=t==="no",i=e.source,{data:l,isLoading:d}=useOrderbook({slug:e.slug,source:i}),c=useMemo(()=>((a?l?.asks:l?.bids)??[]).map(v=>({price:a?1-v.price:v.price,quantity:v.size})),[l?.bids,l?.asks,a]),u=useMemo(()=>((a?l?.bids:l?.asks)??[]).map(v=>({price:a?1-v.price:v.price,quantity:v.size})),[l?.bids,l?.asks,a]),m=useMemo(()=>c.length>0?Math.max(...c.map(g=>g.price)):null,[c]),f=useMemo(()=>u.length>0?Math.min(...u.map(g=>g.price)):null,[u]),p=useMemo(()=>{if(m==null||f==null)return null;let g=(f-m)*100;return Math.round(g*10)/10},[m,f]);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:p!=null?`${o("predict.orderBook.spread")}: ${Number.isInteger(p)?`${p}\xA2`:`${p.toFixed(1)}\xA2`}`:null}),jsxs("span",{className:"flex flex-1 items-center justify-center gap-x-1 whitespace-nowrap",children:[m!=null&&jsxs("span",{style:{color:"var(--color-bullish)"},children:[o("predict.trade.bestBid"),": ",Ln(m)]}),m!=null&&f!=null&&jsx("span",{className:"text-neutral",children:"|"}),f!=null&&jsxs("span",{style:{color:"var(--color-bearish)"},children:[o("predict.trade.bestAsk"),": ",Ln(f)]})]}),jsx("div",{className:"flex flex-1 justify-end",children:jsx("button",{type:"button",title:n==="depth"?"Orderbook":"Depth chart",onClick:()=>s(g=>g==="depth"?"table":"depth"),className:"flex items-center text-neutral transition-colors cursor-pointer hover:text-foreground",children:n==="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:[n==="depth"&&jsx(Fragment,{children:d?jsx(On,{}):jsx(Rn,{bids:c,asks:u})}),n==="table"&&jsx(Fragment,{children:d?jsx(On,{}):jsx(bi,{bids:c,asks:u,bestBid:m??void 0,bestAsk:f??void 0,spread:p??void 0})})]})]})}var In=8;function bi({bids:e,asks:t,spread:r}){let{t:o}=useTranslation(),n=useMemo(()=>[...t].sort((l,d)=>d.price-l.price).slice(0,In),[t]),s=useMemo(()=>[...e].sort((l,d)=>d.price-l.price).slice(0,In),[e]),a=useMemo(()=>{let l=[...n,...s].map(d=>d.quantity);return Math.max(...l,1)},[n,s]);return n.length===0&&s.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:[n.map(l=>jsx(_n,{price:l.price,quantity:l.quantity,side:"ask",maxQty:a},`ask-${l.price}`)),jsx("div",{className:"flex items-center justify-center gap-x-2 py-1 border-y border-border text-neutral text-[10px]",children:r!=null&&jsxs("span",{children:[o("predict.orderBook.spread"),":"," ",Number.isInteger(r)?`${r}\xA2`:`${r.toFixed(1)}\xA2`]})}),s.map(l=>jsx(_n,{price:l.price,quantity:l.quantity,side:"bid",maxQty:a},`bid-${l.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 _n({price:e,quantity:t,side:r,maxQty:o}){let n=r==="ask",s=Math.min(t/o*100,100),a=n?"bg-bullish/10":"bg-bearish/10",i=n?"text-bullish":"text-bearish",l=Math.round(e*100),d=je(Math.round(t)),c=Math.round(t*e),u=`$${je(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 ${a} transition-[width] duration-200`,style:{width:`${s}%`}}),jsxs("span",{className:`relative z-10 ${i}`,children:[l,"\xA2"]}),jsx("span",{className:"relative z-10 text-foreground text-center",children:d}),jsx("span",{className:"relative z-10 text-foreground text-right",children:u})]})}var or=class extends Component{state={error:null};static getDerivedStateFromError(t){return {error:t}}componentDidCatch(t,r){}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}},xt=4,Hn=["#22d3ee","#a3e635","#f97316","#f472b6","#a78bfa"];function Li(e,t){let r=new Date(e);return t===ChartRange.ONE_DAY?r.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:false}):r.toLocaleDateString("en-US",{month:"short",day:"numeric"})}function Oi(e,t){let r=new Date(e);return t===ChartRange.ONE_DAY?r.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:false}):t===ChartRange.ONE_WEEK?r.toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",hour12:false}):r.toLocaleDateString("en-US",{month:"short",day:"numeric"})}function Fn(e){return `${(e*100).toFixed(2)}%`}var Ii=[{range:ChartRange.ONE_DAY,label:"1D"},{range:ChartRange.ONE_WEEK,label:"1W"},{range:ChartRange.ONE_MONTH,label:"1M"},{range:ChartRange.ALL,label:"ALL"}];function _i({value:e,onChange:t}){return jsx("div",{style:{display:"flex",alignItems:"center",gap:2},children:Ii.map(({range:r,label:o})=>{let n=r===e;return jsx("button",{onClick:()=>t(r),style:{padding:"2px 8px",border:"none",background:"transparent",color:n?"#f9fafb":"#6b7280",fontWeight:n?700:400,fontSize:12,cursor:"pointer",borderRadius:4,letterSpacing:"0.02em",transition:"color 0.15s",userSelect:"none"},children:o},r)})})}function Ai(){let e=useRef(null),t=useRef(null),r=useCallback(n=>{let s=e.current,a=t.current;if(!s||!a)return;let i=s.getBoundingClientRect(),l=(n.clientX-i.left)/i.width*100;a.style.background=`linear-gradient(to right, transparent ${l}%, rgba(0,0,0,0.55) ${l}%)`,a.style.opacity="1";},[]),o=useCallback(()=>{t.current&&(t.current.style.opacity="0");},[]);return {wrapperRef:e,overlayRef:t,onMouseMove:r,onMouseLeave:o}}function Di({active:e,payload:t,label:r,labelMap:o,allSeries:n,range:s}){if(!e||!n?.length)return null;let a=new Map;t?.forEach(l=>a.set(l.dataKey,l));let i=n.map(l=>a.get(l.slug)??{dataKey:l.slug,value:void 0,stroke:l.color,color:l.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 r=="number"?Oi(r,s):r}),i.map(l=>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:l.stroke??l.color,flexShrink:0}}),jsx("span",{style:{color:"#9ca3af",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:120},children:o.get(l.dataKey)??l.dataKey}),jsx("span",{style:{color:"#f9fafb",fontWeight:700,fontVariantNumeric:"tabular-nums"},children:l.value!=null?Fn(l.value):"--"})]},l.dataKey))]})}function Hi({markets:e,selectedSlugs:t,colorMap:r,onToggle:o}){let[n,s]=useState(false),a=useRef(null);useEffect(()=>{if(!n)return;function d(c){a.current&&!a.current.contains(c.target)&&s(false);}return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[n]);let i=t.length>=xt,l=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(d=>jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:r.get(d)??"#6b7280",display:"inline-block"}},d))}),jsx("span",{style:{color:"#e5e7eb",fontSize:12,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.length===1?(()=>{let d=e.find(c=>c.slug===t[0]);return d?.outcomes?.[0]?.label??d?.question??"1 market"})():`${t.length} / ${e.length} markets`})]});return jsxs("div",{ref:a,style:{position:"relative",display:"inline-block",width:200},children:[jsxs("button",{onClick:()=>s(d=>!d),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:[l,jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",style:{flexShrink:0,transform:n?"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"})})]}),n&&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 ",xt," markets"]}),e.map(d=>{let c=t.includes(d.slug),u=!c&&i,m=c&&t.length===1,f=r.get(d.slug)??"#6b7280",p=d.outcomes.find(v=>v.label.toLowerCase()==="yes")??d.outcomes[0],g=p?.price!=null?`${Math.round(p.price*100)}%`:null;return jsxs("button",{onClick:()=>{m||u||o(d.slug);},style:{display:"flex",alignItems:"center",gap:10,width:"100%",padding:"7px 12px",border:"none",background:c?"rgba(255,255,255,0.05)":"transparent",cursor:u||m?"not-allowed":"pointer",opacity:u?.35:1,textAlign:"left",transition:"background 0.1s"},onMouseEnter:v=>{!u&&!m&&(v.currentTarget.style.background="rgba(255,255,255,0.07)");},onMouseLeave:v=>{v.currentTarget.style.background=c?"rgba(255,255,255,0.05)":"transparent";},children:[jsx("span",{style:{width:16,height:16,borderRadius:4,border:c?`2px solid ${f}`:"2px solid rgba(255,255,255,0.2)",background:c?`${f}30`:"transparent",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center"},children:c&&jsx("svg",{width:"9",height:"7",viewBox:"0 0 9 7",fill:"none",children:jsx("path",{d:"M1 3.5L3.5 6L8 1",stroke:f,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:f,flexShrink:0}}),jsx("span",{style:{color:c?"#f9fafb":"#9ca3af",fontSize:12,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d.outcomes?.[0]?.label??d.question}),g&&jsx("span",{style:{color:f,fontWeight:700,fontSize:12,flexShrink:0},children:g})]},d.slug)})]})]})}function Bi({series:e,colorMap:t,displayValues:r}){return jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px 24px",padding:"0 2px"},children:e.map(o=>{let n=t.get(o.marketSlug)??"#6b7280",s=r.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:n,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:s!=null?Fn(s):"--"})]})]},o.marketSlug)})})}function Fi(e){let t=Math.floor(e.length/2);return e.length%2===1?e[t]:(e[t-1]+e[t])/2}function Ui(e,t){if(e.length<=t)return e;let r=[],o=e.length/t;for(let n=0;n<t;n++){let s=Math.floor(n*o),a=Math.min(Math.floor((n+1)*o),e.length),i=e.slice(s,a),l=i.map(d=>d.price).sort((d,c)=>d-c);r.push({timestamp:i[i.length-1].timestamp,price:Fi(l)});}return r}function Wi(e,t=200){if(e.length===0)return [];let r=e.map(i=>({...i,data:Ui(i.data,t)})),o=new Set;r.forEach(i=>i.data.forEach(l=>o.add(l.timestamp)));let n=Array.from(o).sort((i,l)=>i-l),s=r.map(i=>{let l=new Map;return i.data.forEach(d=>l.set(d.timestamp,d.price)),{slug:i.marketSlug,map:l}}),a=new Map;return n.map(i=>{let l={timestamp:i};return s.forEach(({slug:d,map:c})=>{let u=c.get(i);if(u!==void 0)a.set(d,u),l[d]=u;else {let m=a.get(d);m!==void 0&&(l[d]=m);}}),l})}function Un(e){return jsx(or,{children:jsx($i,{...e})})}function $i({event:e,isLoading:t,className:r,volume:o}){let n=useMemo(()=>(e.markets??[]).filter(w=>w.status==="open"),[e.markets]),s=useMemo(()=>[...n].sort((w,x)=>{let R=A=>(A.outcomes.find(ee=>ee.label.toLowerCase()==="yes")??A.outcomes[0])?.price??0;return R(x)-R(w)}),[n]),[a,i]=useState(()=>s.slice(0,xt).map(w=>w.slug)),[l,d]=useState(at),c=useMemo(()=>{let w=new Map;return a.forEach((x,R)=>{w.set(x,Hn[R%Hn.length]);}),w},[a]),u=useMemo(()=>n.filter(w=>a.includes(w.slug)),[n,a]),{series:m,isLoading:f}=useMarketHistory(u,l),p=t||f,g=useMemo(()=>{if(m.length>0&&m.some(R=>R.data.length>0))return m;let w=Date.now(),x=864e5;return u.map(R=>{let ee=(R.outcomes?.find(j=>j.label.toLowerCase()==="yes")??R.outcomes?.[0])?.price??.5;return {marketSlug:R.slug,label:R.outcomes?.[0]?.label??R.question,data:[{timestamp:w-7*x,price:ee},{timestamp:w,price:ee}]}})},[m,u]),v=useMemo(()=>l===ChartRange.ONE_DAY?96:l===ChartRange.ONE_WEEK?168:l===ChartRange.ONE_MONTH?180:300,[l]),b=useMemo(()=>Wi(g,v),[g,v]),U=useMemo(()=>{if(b.length===0)return [0,1];let w=1/0,x=-1/0;if(a.forEach(A=>{b.forEach(ee=>{let j=ee[A];j!=null&&(j<w&&(w=j),j>x&&(x=j));});}),!isFinite(w))return [0,1];let R=Math.max((x-w)*.15,.05);return [Math.max(0,w-R),Math.min(1,x+R)]},[b,a]),E=useMemo(()=>{let w=new Map;return g.forEach(x=>{x.data.length>0&&w.set(x.marketSlug,x.data[x.data.length-1].price);}),w},[g]),M=useMemo(()=>{let w=new Map;return g.forEach(x=>w.set(x.marketSlug,x.label)),w},[g]),T=useMemo(()=>g.map(w=>({slug:w.marketSlug,color:c.get(w.marketSlug)??"#6b7280"})),[g,c]),{wrapperRef:G,overlayRef:C,onMouseMove:N,onMouseLeave:z}=Ai(),he=useCallback(w=>{i(x=>x.includes(w)?x.length<=1?x:x.filter(R=>R!==w):x.length>=xt?x:[...x,w]);},[]),[ne,K]=useState(null),oe=useRef(null),se=useRef(""),we=useRef(0),Se=!p&&b.length>0;return jsxs("div",{className:r,style:{display:"flex",flexDirection:"column",gap:12},children:[jsx(Bi,{series:g,colorMap:c,displayValues:ne??E}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:0},children:[jsx("div",{ref:G,style:{height:300,width:"100%",userSelect:"none",position:"relative"},onMouseMove:Se?w=>{N(w),cancelAnimationFrame(we.current),we.current=requestAnimationFrame(()=>{K(oe.current);});}:void 0,onMouseLeave:Se?()=>{z(),cancelAnimationFrame(we.current),se.current="",oe.current=null,K(null);}:void 0,children:p?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"}})}):b.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:C,style:{position:"absolute",inset:0,opacity:0,pointerEvents:"none",zIndex:1}}),jsx(ResponsiveContainer,{width:"100%",height:"100%",children:jsxs(LineChart,{data:b,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:w=>Li(w,l),axisLine:false,tickLine:false,tick:{fill:"#6b7280",fontSize:11},minTickGap:70}),jsx(YAxis,{domain:U,tickFormatter:w=>`${Math.round(w*100)}%`,axisLine:false,tickLine:false,tick:{fill:"#6b7280",fontSize:11},width:40,tickCount:6}),jsx(Tooltip,{content:w=>{let x=w;if(x.active&&x.payload?.length){let R=x.payload.map(A=>`${A.dataKey}:${A.value}`).join(",");if(R!==se.current){se.current=R;let A=new Map;x.payload.forEach(ee=>{ee.value!=null&&A.set(ee.dataKey,ee.value);}),oe.current=A;}}return jsx(Di,{...x,labelMap:M,allSeries:T,range:l})},cursor:{stroke:"#4b5563",strokeWidth:1,strokeDasharray:"4 4"},wrapperStyle:{zIndex:2},isAnimationActive:false}),g.map(w=>{let x=c.get(w.marketSlug)??"#6b7280";return jsx(Line,{type:"linear",dataKey:w.marketSlug,stroke:x,strokeWidth:2,strokeLinejoin:"round",strokeLinecap:"round",dot:false,activeDot:{r:4.5,strokeWidth:2,stroke:"rgba(10,10,10,0.8)",fill:x},connectNulls:true,isAnimationActive:false},w.marketSlug)}),ne==null&&b.length>0&&g.map(w=>{let x=b[b.length-1],R=x[w.marketSlug];if(R==null)return null;let A=c.get(w.marketSlug)??"#6b7280";return jsx(ReferenceDot,{x:x.timestamp,y:R,ifOverflow:"extendDomain",shape:ee=>{let{cx:j,cy:Fe}=ee;return j==null||Fe==null?jsx("g",{}):jsxs("g",{children:[jsxs("circle",{cx:j,cy:Fe,r:6,fill:A,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:j,cy:Fe,r:3.5,fill:A})]})}},`pulse-${w.marketSlug}`)})]})})]})}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,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}}),s.length>1&&jsxs(Fragment,{children:[jsx(Hi,{markets:s,selectedSlugs:a,colorMap:c,onToggle:he}),jsx("span",{style:{width:1,height:14,background:"#374151",flexShrink:0}})]}),jsx(_i,{value:l,onChange:d})]})]})]})}function Qe(e){return e.outcomes[0]?.best_ask??e.outcomes[0]?.price??0}function el(e){return `${Math.round(e*100)}%`}function Wn(e){let t=e*100;return t<1&&t>0?"< 1":Number.isInteger(t)?`${t}`:t.toFixed(1)}function ht(e){return e.outcomes?.[0]?.label??e.question}function tl(e){switch(e){case "polymarket":return "Polymarket";case "dflow":return "Kalshi";default:return e}}function Xe(e){if(!e)return "\u2014";let t=new Date(e);if(isNaN(t.getTime()))return "\u2014";let r=t.toLocaleString("default",{month:"short"}),o=t.getDate(),n=t.getFullYear(),s=t.getHours().toString().padStart(2,"0"),a=t.getMinutes().toString().padStart(2,"0");return `${r} ${o}, ${n} ${s}:${a}`}function $n(e){let[t,r]=useState(Date.now());if(useEffect(()=>{if(!e)return;let c=setInterval(()=>r(Date.now()),1e3);return ()=>clearInterval(c)},[e]),!e)return null;let o=new Date(e).getTime();if(isNaN(o))return null;let n=o-t;if(n<=0)return null;let s=Math.floor(n/864e5),a=Math.floor(n%864e5/36e5),i=Math.floor(n%36e5/6e4),l=Math.floor(n%6e4/1e3),d=[];return s>0&&d.push(`${s}d`),d.push(`${String(a).padStart(2,"0")}h`),d.push(`${String(i).padStart(2,"0")}m`),d.push(`${String(l).padStart(2,"0")}s`),d.join(" ")}function zn(e){if(!e)return null;let t=new Date(e);if(isNaN(t.getTime()))return null;let r=t.getHours().toString().padStart(2,"0"),o=t.getMinutes().toString().padStart(2,"0"),n=(t.getMonth()+1).toString().padStart(2,"0"),s=t.getDate().toString().padStart(2,"0"),a=t.getFullYear(),i=-t.getTimezoneOffset(),l=i>=0?"+":"-",d=String(Math.abs(Math.floor(i/60))).padStart(2,"0");return `${r}:${o} ${n}/${s}/${a} (${l}${d})`}function Yn({event:e,onTradeAction:t}){let{t:r}=useTranslation(),{ref:o,isCollapsed:n}=useScrollCollapse(),s=useMemo(()=>{let u=[...e.markets||[]],m=u.filter(p=>p.status==="open").sort((p,g)=>Qe(g)-Qe(p)),f=u.filter(p=>p.status!=="open").sort((p,g)=>Qe(g)-Qe(p));return [...m,...f]},[e.markets]),a=e.status==="closed"||e.status==="voided",i=$n(a?void 0:e.start_at),l=$n(a?void 0:e.end_at),d=zn(e.start_at),c=zn(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 ${n?"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 ${n?"!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:[!n&&jsxs("div",{className:"flex items-center gap-1.5",children:[e.tags?.slice(0,3).map((u,m)=>jsxs(Fragment$1,{children:[m>0&&jsx("span",{className:"text-sm text-neutral/50",children:"\xB7"}),jsx("span",{className:"text-sm text-neutral truncate",children:u.label})]},u.slug)),jsx(sl,{source:e.source})]}),jsx("span",{className:`font-semibold truncate transition-all duration-300 ${n?"text-sm lg:text-base":"text-lg lg:text-xl"}`,children:e.title})]})]}),(i||l||a)&&jsx("div",{className:"flex items-center gap-x-2 text-xs lg:text-sm font-mono",children:a?c&&jsx("span",{className:"text-neutral",children:r("predict.event.endedAt",{time:c})}):i?jsxs(Fragment,{children:[jsx("span",{className:"text-foreground",children:r("predict.event.beginsIn",{time:i})}),d&&jsxs(Fragment,{children:[jsx("span",{className:"text-neutral/50",children:"\xB7"}),jsx("span",{className:"text-neutral",children:d})]})]}):l?jsxs(Fragment,{children:[jsx("span",{className:"text-foreground",children:r("predict.event.endsIn",{time:l})}),c&&jsxs(Fragment,{children:[jsx("span",{className:"text-neutral/50",children:"\xB7"}),jsx("span",{className:"text-neutral",children:c})]})]}):null}),jsx(Un,{event:e,volume:e.volume??void 0}),jsx(rl,{markets:s,onTradeAction:t}),jsx(ol,{markets:s,event:e})]})}var Kn=5;function rl({markets:e,onTradeAction:t}){let{t:r}=useTranslation(),[o,n]=useState(false),[s,a]=useState(null),i=e.find(p=>p.status==="open")?.slug,[l,d]=useState(i?`${i}:yes`:null);if(e.length===0)return null;let c=e.length>Kn,u=o?e:e.slice(0,Kn),m=p=>{a(g=>g===p?null:p);},f=(p,g,v)=>{d(`${p.slug}:${g}`),a(p.slug),t?.(p,g,v);};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:r("predict.market.table.chance")}),jsx("th",{})]})}),jsx("tbody",{children:u.map(p=>{let g=Qe(p),v=p.outcomes[1]?.best_ask??p.outcomes[1]?.price,b=s===p.slug;return jsx(nl,{market:p,yesPrice:g,noPrice:v??void 0,activeYes:l===`${p.slug}:yes`,activeNo:l===`${p.slug}:no`,isExpanded:b,onToggleExpand:()=>m(p.slug),onTradeAction:f},p.slug)})})]}),c&&jsxs("button",{type:"button",onClick:()=>n(p=>!p),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:r(o?"predict.event.rules.collapse":"predict.event.moreMarketsLabel")}),jsx(ChevronDownIcon,{className:cn$1("h-4 w-4 transition-transform",o&&"rotate-180")})]})]})}function nl({market:e,yesPrice:t,noPrice:r,activeYes:o,activeNo:n,isExpanded:s,onToggleExpand:a,onTradeAction:i}){let{t:l}=useTranslation(),d=e.status==="open",c=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:a,role:"button",tabIndex:0,onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&(u.preventDefault(),a());},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:ht(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:ht(e)}),c&&jsx("span",{className:"text-[8px] text-neutral lg:text-xxs",children:c})]})]})}),jsx("td",{className:"py-2 text-left text-foreground lg:text-center",children:el(t)}),jsx("td",{className:"py-2 pr-1 lg:pr-2",children:d?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:u=>{u.stopPropagation(),i?.(e,"yes","buy");},children:l("predict.market.action.yes",{price:Wn(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",n?"bg-secondary text-secondary-foreground":"bg-secondary/10 text-secondary"),onClick:u=>{u.stopPropagation(),i?.(e,"no","buy");},children:r!=null?l("predict.market.action.no",{price:Wn(r)}):l("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"?l("predict.event.status.closed"):e.status==="voided"?l("predict.event.status.voided"):l("predict.event.status.pending")})})})]}),s&&jsx("tr",{children:jsx("td",{colSpan:3,className:"pb-3",children:jsx("div",{className:"max-h-100 overflow-y-auto",children:jsx(Dn,{market:e,outcome:n?"no":"yes",onTradeAction:i})})})})]})}function ol({markets:e,event:t}){let{t:r}=useTranslation(),[o,n]=useState(false),[s,a]=useState(false),[i,l]=useState(0),d=e.filter(f=>f.rules&&f.rules.length>0||f.description);if(d.length===0)return null;let c=d[i]??d[0],u=c.rules&&c.rules.length>0?c.rules.join(`
19
+ `;function xn({event:e,href:t,LinkComponent:n,onSelect:o,onSelectOutcome:r,onHover:a}){let[s,i]=useState(null),l=e.markets??[],d=useMemo(()=>l.length>2?[...l].sort((C,R)=>(R.outcomes?.[0]?.price??0)-(C.outcomes?.[0]?.price??0)):l,[l]),c=d.filter(C=>C.status==="open"),m=d.length===1,p=c.slice(0,ln),f=c.length-ln,u=useMemo(()=>`$${Math.round(e.volume??0).toLocaleString("en-US")}`,[e.volume]),g=s?c.find(C=>C.slug===s)??null:null,v=!!g||m,h=()=>{v||o?.(e);},$=C=>{C.stopPropagation(),g&&(C.preventDefault(),i(null));},P=C=>{C.stopPropagation(),t||(C.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:()=>a?.(e),onClick:h,children:[jsx("style",{children:ya}),jsx(wa,{event:e,href:t,LinkComponent:n,onClick:$,isExpanded:v}),jsx("div",{className:"flex flex-1 flex-col",children:m?jsx(Ma,{market:c[0],event:e,formattedVolume:u,href:t,LinkComponent:n,onSelect:o,onSelectOutcome:r}):g?jsx(Ra,{market:g,event:e,onCollapse:()=>i(null),onSelectOutcome:r}):jsx(Ca,{displayedMarkets:p,moreCount:f,formattedVolume:u,source:e.source,href:t,LinkComponent:n,onMarketClick:C=>i(C.slug),onShowMore:P})})]})}function wa({event:e,href:t,LinkComponent:n,onClick:o,isExpanded:r}){let a=e.start_at?ba(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}),a&&jsxs("span",{className:"text-[10px] leading-4 text-neutral-500",children:["Live in ",a]})]}),jsx(Na,{event:e})]})}function Sa(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(),a=300*1e3,s=900*1e3;if(r>0&&r<=s){let i=r<=a?"#ef4444":"#f59e0b";t.push({kind:"crypto-short",label:r<=a?"5m":"15m",color:i});}}return o&&t.push({kind:"live"}),t.slice(0,2)}function Na({event:e}){let t=useMemo(()=>Sa(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(ka,{},o);case "crypto-short":return jsx(Pa,{label:n.label,color:n.color},o);case "closed":return jsx(Ea,{},o)}})})}function ka(){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 Pa({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 Ea(){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 Ca({displayedMarkets:e,moreCount:t,formattedVolume:n,source:o,href:r,LinkComponent:a,onMarketClick:s,onShowMore:i}){let{t:l}=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(d=>{let c=gn(d);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:m=>{m.stopPropagation(),s(d);},children:[jsx("span",{className:"min-w-0 flex-1 text-left text-xs text-slate-200 line-clamp-1 lg:text-sm",children:d.outcomes?.[0]?.label??d.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:vn(c)}),jsx(Ta,{})]})]},d.slug)})}),jsxs("div",{className:"mt-auto flex items-center justify-between pt-3",children:[t>0?jsxs(Linkable,{href:r,LinkComponent:a,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:i,children:[l("predict.event.showMore"),jsx(bn,{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," ",l("predict.event.volume"),jsx(yn,{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:i=>{let l=i.currentTarget;l.style.setProperty("--shadow-offset","2px"),l.style.transform="translateY(2px)";},onMouseLeave:i=>{let l=i.currentTarget;l.style.setProperty("--shadow-offset","4px"),l.style.transform="translateY(0px)";},onClick:o,children:r})}function hn({market:e,event:t,onSelectOutcome:n,dynamicColors:o=false,labelFormat:r="action"}){let{t:a}=useTranslation(),[s,i]=o?xa(e):[Gt,fn],l=e.outcomes?.[0]?.label?.toLowerCase().trim()??"",d=e.outcomes?.[1]?.label?.toLowerCase().trim()??"",c=r==="label"&&l===d?"action":r,m=c==="label"?`${e.outcomes?.[0]?.label??"Yes"} ${dn(e)}\xA2`:a("predict.market.action.yes",{price:dn(e)}),p=c==="label"?`${e.outcomes?.[1]?.label??"No"} ${un(e)}\xA2`:a("predict.market.action.no",{price:un(e)});return jsxs("div",{className:"flex gap-2",children:[jsx(pn,{bgColor:s.bg,textColor:s.text,shadowColor:s.shadow,onClick:f=>{f.stopPropagation(),n?.(t,e,"yes");},children:m}),jsx(pn,{bgColor:i.bg,textColor:i.text,shadowColor:i.shadow,onClick:f=>{f.stopPropagation(),n?.(t,e,"no");},children:p})]})}function Ta(){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 Ma({market:e,event:t,formattedVolume:n,href:o,LinkComponent:r,onSelect:a,onSelectOutcome:s}){let{t:i}=useTranslation();return jsxs(Fragment,{children:[jsx("div",{className:"flex-1",children:jsx(hn,{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:d=>{d.stopPropagation(),o||(d.preventDefault(),a?.(t));},children:[i("predict.event.viewEvent"),jsx(bn,{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," ",i("predict.event.volume"),jsx(yn,{source:t.source})]})]})]})}function Ra({market:e,event:t,onCollapse:n,onSelectOutcome:o}){let{t:r}=useTranslation(),a=gn(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:vn(a)}),jsx(ChevronUpIcon,{className:"h-4 w-4 text-neutral-400"})]})]}),jsx("div",{className:"mt-3",children:jsx(hn,{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(La,{className:"h-3 w-3"}),r("predict.event.back")]})]})}function bn({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 La({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 yn({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 Fa=768,Sn=1024,Ha=1280,Ba=8,Ua=224,Wa=304,$a=114;function za(e){return e>=Ha?4:e>=Sn?3:e>=Fa?2:1}function Ka(e){return e>=Sn?Wa:Ua}function Nn({events:e,hasMore:t=false,onFetchMore:n,onSelect:o,onSelectOutcome:r,getEventHref:a,LinkComponent:s,onHover:i}){let l=useRef(null),d=useRef(null),{width:c=0,height:m=0}=useResizeObserver({ref:l}),p=za(c),f=Ka(c),u=Math.ceil(e.length/p)||0,g=!t&&e.length>0,v=u+(t?1:0)+(g?1:0),h=useCallback(R=>R<u,[u]),$=useCallback(async()=>{n?.();},[n]),P=useInfiniteLoader({isRowLoaded:h,loadMoreRows:$,rowCount:v,threshold:3}),C=useCallback(()=>{d.current?.scrollToRow({index:0,behavior:"smooth"});},[]);return jsx("div",{ref:l,className:"@container w-full h-full",children:m>0&&jsx(List,{listRef:d,className:"no-scrollbar",style:{height:m},onRowsRendered:P,rowComponent:Va,rowCount:v,rowHeight:R=>g&&R===v-1?$a:(f),rowProps:{events:e,columnCount:p,dataRowCount:u,showEndOfList:g,totalRowCount:v,onSelect:o,onSelectOutcome:r,getEventHref:a,LinkComponent:s,onHover:i,onScrollToTop:C}})})}function Va({index:e,style:t,events:n,columnCount:o,dataRowCount:r,showEndOfList:a,totalRowCount:s,onSelect:i,onSelectOutcome:l,getEventHref:d,LinkComponent:c,onHover:m,onScrollToTop:p}){if(a&&e===s-1)return jsx("div",{style:t,children:jsx(Ya,{onScrollToTop:p})});if(e>=r)return jsx("div",{style:t,className:"flex justify-center items-start pt-4",children:jsx(Spinner,{size:"sm"})});let f=e*o,u=n.slice(f,f+o),g=o-u.length;return jsx("div",{style:t,children:jsxs("div",{className:"flex w-full h-full",children:[u.map(v=>v==null?null:jsx("div",{className:"flex-1 min-w-0 flex",style:{padding:Ba},children:jsx(xn,{event:v,href:d?.(v),LinkComponent:c,onSelect:i,onSelectOutcome:l,onHover:m})},v.slug)),g>0&&Array.from({length:g}).map((v,h)=>jsx("div",{style:{flex:1,minWidth:0}},`spacer-${h}`))]})})}function Ya({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 Pn({tagSlugSelection:e,limit:t=48,status:n,sort_by:o,sort_asc:r,source:a,with_markets:s,onSelect:i,onSelectOutcome:l,getEventHref:d,LinkComponent:c,onHover:m}){let{data:p,hasMore:f,fetchMore:u,isFetching:g}=an({tagSlugSelection:e,limit:t,status:n,sort_by:o,sort_asc:r,source:a,with_markets:s});return g?jsx(qt,{count:48}):jsx(Nn,{events:p,hasMore:f,onFetchMore:u,onSelect:i,onSelectOutcome:l,getEventHref:d,LinkComponent:c,onHover:m})}function ku({onSelect:e,onSelectOutcome:t,getEventHref:n,LinkComponent:o,onHover:r}){let[a,s]=useState({categorySlug:null,tagSlug:null}),[i,l]=useState(Vt),{isOpen:d,onOpen:c,onClose:m}=useDisclosure(),{onOpen:p}=useAsyncModal(Kt),f=useCallback((R,j,M)=>{t?.(R,j,M),p({params:{event:R,market:j,initialOutcome:M}});},[t,p]),u=useCallback(R=>{s(R);},[]),g=useCallback(R=>{l(j=>({...j,sortPreset:R}));},[]),v=useCallback(R=>{l(j=>({...j,sortAsc:R}));},[]),h=useCallback(R=>{l(R);},[]),$=useMemo(()=>rn[i.sortPreset].sort_by,[i.sortPreset]),P=useMemo(()=>Yt(i),[i]),C=useMemo(()=>jsx(nn,{sortPreset:i.sortPreset,onSortChange:g,sortAsc:i.sortAsc,onSortAscChange:v,onFilterPress:c,filterCount:P}),[i.sortPreset,i.sortAsc,P,g,v,c]);return jsxs("div",{className:"flex h-full w-full max-w-[1680px] mx-auto flex-col gap-y-3",children:[jsx(Ir,{onSelect:u,trailing:C}),jsx(Jr,{isOpen:d,onClose:m,value:i,onChange:h}),jsx("div",{className:"min-h-0 flex-1",children:jsx(Pn,{tagSlugSelection:a,sort_by:$,sort_asc:i.sortAsc,source:i.source,onSelect:e,onSelectOutcome:f,getEventHref:n,LinkComponent:o,onHover:r})}),jsx(Xr,{})]})}var rr=40,bt=36,Ze=480,nr=Ze-bt;function Mn({event:e,walletAddress:t,onCancelOrder:n}){let{t:o}=useTranslation(),[r,a]=useState("positions"),s=useMemo(()=>e.markets?.map(m=>m.slug)??[],[e.markets]),{data:i}=usePositions({source:e.source,user:t??""}),l=useMemo(()=>!i?.positions||!t?0:s.length===0?i.positions.length:i.positions.filter(m=>m.market&&s.includes(m.market.slug)).length,[i?.positions,s,t]),c=[{key:"positions",label:l>0?`${o("predict.positions.title")} (${l})`: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:c.map(m=>jsx("button",{type:"button",onClick:()=>a(m.key),className:cn$1("px-3 py-2 text-sm font-medium transition-colors cursor-pointer",r===m.key?"text-foreground border-b-2 border-primary":"text-neutral hover:text-foreground"),children:m.label},m.key))}),t?jsxs("div",{style:{height:Ze},children:[r==="positions"&&jsx(ti,{source:e.source,walletAddress:t,marketSlugs:s}),r==="orders"&&jsx(ni,{source:e.source,walletAddress:t,marketSlugs:s,onCancelOrder:n}),r==="trades"&&jsx(ai,{source:e.source,walletAddress:t})]}):jsx("div",{className:"flex items-center justify-center text-sm text-neutral",style:{height:Ze},children:o("predict.trade.connectWallet")})]})}function ti({source:e,walletAddress:t,marketSlugs:n}){let{t:o}=useTranslation(),{data:r,isLoading:a}=usePositions({source:e,user:t}),s=useMemo(()=>r?.positions?n.length===0?r.positions:r.positions.filter(i=>i.market&&n.includes(i.market.slug)):[],[r?.positions,n]);return a?jsx(sr,{}):s.length===0?jsx(or,{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:bt},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:nr},rowComponent:ri,rowCount:s.length,rowHeight:rr,rowProps:{positions:s,closeLabel:o("predict.positions.close")}})]})}function ri({index:e,style:t,positions:n,closeLabel:o}){let r=n[e];if(!r)return null;let a=r.pnl??0,s=r.pnl_percent??0,i=r.avg_price??0,l=r.current_price??0,d=a>0?"text-success":a<0?"text-danger":"text-foreground",c=a>0?"+":"",m=r.market?.outcomes?.[0]?.label??r.market?.question??"\u2014",p=r.side,f=r.size,u=r.size*l,g=r.market?.end_at?ci(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:m}),jsx("span",{className:cn$1("text-[10px] font-medium",p.toLowerCase()==="yes"?"text-primary":"text-secondary"),children:p})]})}),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:["$",u.toFixed(2)]}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:xt(i)}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:xt(l)}),jsxs("div",{className:cn$1("flex-[1.5] pr-2 text-right font-mono whitespace-nowrap",d),children:[c,"$",Math.abs(a).toFixed(2),jsxs("span",{className:"text-[10px] ml-0.5 opacity-70",children:["(",c,s.toFixed(1),"%)"]})]}),jsxs("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:["$",f.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 ni({source:e,walletAddress:t,marketSlugs:n,onCancelOrder:o}){let{t:r}=useTranslation(),{data:a,isLoading:s,fetchNextPage:i,hasNextPage:l}=useInfiniteOrders({source:e,wallet_address:t}),d=useCancelOrder(),c=useMemo(()=>{let h=a?.pages?.flatMap(C=>C.items)??[],$=new Set(["live","open","submitted","pending"]),P=h.filter(C=>$.has(C.status));return n.length>0&&(P=P.filter(C=>C.market_id&&n.includes(C.market_id))),P},[a?.pages,n]),m=useCallback(h=>{o?o(h.id):d.mutate({source:h.source,id:h.id});},[o,d]),p=c.length,f=p+(l?1:0),u=useCallback(h=>h<p,[p]),g=useCallback(async()=>{await i();},[i]),v=useInfiniteLoader({isRowLoaded:u,loadMoreRows:g,rowCount:f,threshold:5});return s?jsx(sr,{}):c.length===0&&!l?jsx(or,{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:bt},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:nr},onRowsRendered:v,rowComponent:oi,rowCount:f,rowHeight:rr,rowProps:{orders:c,itemCount:p,onCancel:m,isCancelling:d.isPending,cancelLabel:r("predict.openOrders.cancel")}})]})}function oi({index:e,style:t,orders:n,itemCount:o,onCancel:r,isCancelling:a,cancelLabel:s}){if(e>=o)return jsx("div",{style:t,className:"flex justify-center items-center",children:jsx(Spinner,{size:"sm"})});let i=n[e];if(!i)return null;let l=i.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",l?"bg-primary/10 text-primary":"bg-danger/10 text-danger"),children:i.side})}),jsx("div",{className:"flex-1 pr-2 text-foreground capitalize",children:i.outcome??"\u2014"}),jsx("div",{className:"flex-1 pr-2 text-neutral capitalize",children:i.order_type??"limit"}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:i.price?xt(parseFloat(i.price)):"\u2014"}),jsxs("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:[i.size_matched??"0","/",i.original_size??"\u2014"]}),jsx("div",{className:"w-20 shrink-0 pr-2",children:jsx(si,{status:i.status})}),jsx("div",{className:"w-16 shrink-0 text-right",children:jsx("button",{type:"button",onClick:()=>r(i),disabled:a,className:"text-[10px] text-danger hover:text-danger/80 cursor-pointer disabled:opacity-50 transition-colors",children:a?jsx(Spinner,{size:"sm"}):s})})]})}function si({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 ai({source:e,walletAddress:t}){let{t:n}=useTranslation(),{data:o,isLoading:r,fetchNextPage:a,hasNextPage:s}=useInfiniteTrades({source:e,wallet:t,limit:50}),i=useMemo(()=>o?.pages?.flatMap(f=>f.items)??[],[o?.pages]),l=i.length,d=l+(s?1:0),c=useCallback(f=>f<l,[l]),m=useCallback(async()=>{await a();},[a]),p=useInfiniteLoader({isRowLoaded:c,loadMoreRows:m,rowCount:d,threshold:5});return r?jsx(sr,{}):i.length===0&&!s?jsx(or,{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:bt},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:nr},onRowsRendered:p,rowComponent:ii,rowCount:d,rowHeight:rr,rowProps:{trades:i,itemCount:l}})]})}function ii({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 a=r.side?.toUpperCase()==="BUY",s=li(r.timestamp),i=r.price??0,l=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",a?"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:xt(i)}),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:["$",l.toFixed(2)]}),jsx("div",{className:"flex-[1.5] pr-2 text-right text-neutral whitespace-nowrap",children:s})]})}function or({message:e}){return jsx("div",{className:"flex items-center justify-center text-sm text-neutral",style:{height:Ze},children:e})}function sr(){return jsx("div",{className:"flex flex-col gap-y-2 py-3 animate-pulse",style:{height:Ze},children:Array.from({length:6}).map((e,t)=>jsx(Skeleton,{className:"h-8 w-full rounded-md"},t))})}function xt(e){let t=e*100;return t<1&&t>0?"< 1\xA2":`${t.toFixed(1)}\xA2`}function li(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"),a=t.getMinutes().toString().padStart(2,"0");return `${n}/${o} ${r}:${a}`}function ci(e){try{return new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}catch{return "\u2014"}}function et({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 Rn(){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 In="var(--color-bullish)",_n="var(--color-bearish)";function tt(e){if(Math.abs(e)>=1e4){let t=e/1e4;return `${parseFloat(t.toFixed(2))}\u4E07`}return e.toLocaleString()}function pi(e,t){return e<=0||t<=0?0:Math.pow(e/t,.3)}function mi(e,t){let n=new Float64Array(101),o=new Float64Array(101);for(let f of e){let u=Math.round(f.price*100);u>=0&&u<=100&&(n[u]+=f.quantity);}for(let f of t){let u=Math.round(f.price*100);u>=0&&u<=100&&(o[u]+=f.quantity);}let r=0,a=0,s=new Float64Array(101),i=new Float64Array(101);for(let f=100;f>=0;f--)r+=n[f],a+=n[f]*f/100,s[f]=r,i[f]=a;let l=0,d=0,c=new Float64Array(101),m=new Float64Array(101);for(let f=0;f<=100;f++)l+=o[f],d+=o[f]*f/100,c[f]=l,m[f]=d;let p=Math.max(s[0]??0,c[100]??0);return Array.from({length:101},(f,u)=>{let g=s[u]>0,v=c[u]>0,h=s[u]||c[u],$=n[u]>0||o[u]>0;return {priceCents:u,displayHeight:pi(h,p),opacity:h>0?$?1:.5:0,isBid:g,isAsk:v,bidCumTotal:s[u],askCumTotal:c[u],bidCumCost:i[u],askCumCost:m[u]}})}function fi({info:e}){let t=e.isBid?In:_n,n=e.leftPct>65?void 0:`${e.leftPct}%`,o=e.leftPct>65?`${100-e.leftPct}%`:void 0;return jsxs("div",{style:{position:"absolute",top:8,left:n,right:o,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:[jsxs("div",{style:{marginBottom:4,fontWeight:600},children:[e.priceCents,"\xA2"]}),jsxs("div",{style:{color:t},children:[tt(Math.round(e.cumTotal))," contracts"]}),jsxs("div",{style:{color:t},children:["$",tt(Math.round(e.cumCost))]})]})}var gi=memo(function({slot:t,onEnter:n,onLeave:o}){let r=useRef(null),a=t.isBid||t.isAsk,s=t.isBid?In:t.isAsk?_n: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:a?"crosshair":"default"},onMouseEnter:()=>n(t,r.current),onMouseLeave:o,children:a&&jsx("div",{ref:r,style:{position:"absolute",bottom:0,left:0,width:"100%",height:`${t.displayHeight*100}%`,backgroundColor:s,opacity:t.opacity}})})}),vi=[0,10,20,30,40,50,60,70,80,90,100];function xi(){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:vi.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 An({bids:e,asks:t}){let n=useMemo(()=>mi(e,t),[e,t]),o=useMemo(()=>{let c=e.length>0?Math.max(...e.map(p=>p.price)):0,m=t.length>0?Math.min(...t.map(p=>p.price)):1;return Math.round((c+m)/2*100)},[e,t]),r=useMemo(()=>n.some(c=>c.isBid||c.isAsk),[n]),[a,s]=useState(null),i=useRef(null),l=useCallback((c,m)=>{i.current&&(i.current.style.filter=""),m?(m.style.filter="brightness(1.5)",i.current=m):i.current=null,c.isBid||c.isAsk?s({priceCents:c.priceCents,isBid:c.isBid,cumTotal:c.isBid?c.bidCumTotal:c.askCumTotal,cumCost:c.isBid?c.bidCumCost:c.askCumCost,leftPct:c.priceCents}):s(null);},[]),d=useCallback(()=>{i.current&&(i.current.style.filter="",i.current=null),s(null);},[]);return r?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:[o>0&&jsx("div",{style:{position:"absolute",left:`${o}%`,top:0,bottom:0,width:1,backgroundImage:"repeating-linear-gradient(to bottom, #6b7280 0, #6b7280 4px, transparent 4px, transparent 8px)",zIndex:1,pointerEvents:"none"}}),a&&jsx(fi,{info:a}),n.map(c=>jsx(gi,{slot:c,onEnter:l,onLeave:d},c.priceCents))]}),jsx(xi,{})]}):jsx("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#6b7280",fontSize:13},children:"No depth data"})}function Dn(e){let t=e*100,n=Math.round(t*10)/10;return Number.isInteger(n)?`${n}\xA2`:`${n.toFixed(1)}\xA2`}function Fn(){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 Wn({market:e,outcome:t="yes",onTradeAction:n}){let{t:o}=useTranslation(),[r,a]=useState("depth"),s=t==="no",i=e.source,{data:l,isLoading:d}=useOrderbook({slug:e.slug,source:i}),c=useMemo(()=>((s?l?.asks:l?.bids)??[]).map(v=>({price:s?1-v.price:v.price,quantity:v.size})),[l?.bids,l?.asks,s]),m=useMemo(()=>((s?l?.bids:l?.asks)??[]).map(v=>({price:s?1-v.price:v.price,quantity:v.size})),[l?.bids,l?.asks,s]),p=useMemo(()=>c.length>0?Math.max(...c.map(g=>g.price)):null,[c]),f=useMemo(()=>m.length>0?Math.min(...m.map(g=>g.price)):null,[m]),u=useMemo(()=>{if(p==null||f==null)return null;let g=(f-p)*100;return Math.round(g*10)/10},[p,f]);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:u!=null?`${o("predict.orderBook.spread")}: ${Number.isInteger(u)?`${u}\xA2`:`${u.toFixed(1)}\xA2`}`:null}),jsxs("span",{className:"flex flex-1 items-center justify-center gap-x-1 whitespace-nowrap",children:[p!=null&&jsxs("span",{style:{color:"var(--color-bullish)"},children:[o("predict.trade.bestBid"),": ",Dn(p)]}),p!=null&&f!=null&&jsx("span",{className:"text-neutral",children:"|"}),f!=null&&jsxs("span",{style:{color:"var(--color-bearish)"},children:[o("predict.trade.bestAsk"),": ",Dn(f)]})]}),jsx("div",{className:"flex flex-1 justify-end",children:jsx("button",{type:"button",title:r==="depth"?"Orderbook":"Depth chart",onClick:()=>a(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:d?jsx(Fn,{}):jsx(An,{bids:c,asks:m})}),r==="table"&&jsx(Fragment,{children:d?jsx(Fn,{}):jsx(Ni,{bids:c,asks:m,bestBid:p??void 0,bestAsk:f??void 0,spread:u??void 0})})]})]})}var Hn=8;function Ni({bids:e,asks:t,spread:n}){let{t:o}=useTranslation(),r=useMemo(()=>[...t].sort((l,d)=>d.price-l.price).slice(0,Hn),[t]),a=useMemo(()=>[...e].sort((l,d)=>d.price-l.price).slice(0,Hn),[e]),s=useMemo(()=>{let l=[...r,...a].map(d=>d.quantity);return Math.max(...l,1)},[r,a]);return r.length===0&&a.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(l=>jsx(Bn,{price:l.price,quantity:l.quantity,side:"ask",maxQty:s},`ask-${l.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`]})}),a.map(l=>jsx(Bn,{price:l.price,quantity:l.quantity,side:"bid",maxQty:s},`bid-${l.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 Bn({price:e,quantity:t,side:n,maxQty:o}){let r=n==="ask",a=Math.min(t/o*100,100),s=r?"bg-bullish/10":"bg-bearish/10",i=r?"text-bullish":"text-bearish",l=Math.round(e*100),d=tt(Math.round(t)),c=Math.round(t*e),m=`$${tt(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:`${a}%`}}),jsxs("span",{className:`relative z-10 ${i}`,children:[l,"\xA2"]}),jsx("span",{className:"relative z-10 text-foreground text-center",children:d}),jsx("span",{className:"relative z-10 text-foreground text-right",children:m})]})}var cr=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}},wt=4,$n=["#22d3ee","#a3e635","#f97316","#f472b6","#a78bfa"];function Ai(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 Di(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 Kn(e){return `${(e*100).toFixed(2)}%`}var Fi=[{range:ChartRange.ONE_DAY,label:"1D"},{range:ChartRange.ONE_WEEK,label:"1W"},{range:ChartRange.ONE_MONTH,label:"1M"},{range:ChartRange.ALL,label:"ALL"}];function Hi({value:e,onChange:t}){return jsx("div",{style:{display:"flex",alignItems:"center",gap:2},children:Fi.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 Bi(){let e=useRef(null),t=useRef(null),n=useCallback(r=>{let a=e.current,s=t.current;if(!a||!s)return;let i=a.getBoundingClientRect(),l=(r.clientX-i.left)/i.width*100;s.style.background=`linear-gradient(to right, transparent ${l}%, rgba(0,0,0,0.55) ${l}%)`,s.style.opacity="1";},[]),o=useCallback(()=>{t.current&&(t.current.style.opacity="0");},[]);return {wrapperRef:e,overlayRef:t,onMouseMove:n,onMouseLeave:o}}function Ui({active:e,payload:t,label:n,labelMap:o,allSeries:r,range:a}){if(!e||!r?.length)return null;let s=new Map;t?.forEach(l=>s.set(l.dataKey,l));let i=r.map(l=>s.get(l.slug)??{dataKey:l.slug,value:void 0,stroke:l.color,color:l.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"?Di(n,a):n}),i.map(l=>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:l.stroke??l.color,flexShrink:0}}),jsx("span",{style:{color:"#9ca3af",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:120},children:o.get(l.dataKey)??l.dataKey}),jsx("span",{style:{color:"#f9fafb",fontWeight:700,fontVariantNumeric:"tabular-nums"},children:l.value!=null?Kn(l.value):"--"})]},l.dataKey))]})}function Wi({markets:e,selectedSlugs:t,colorMap:n,onToggle:o}){let[r,a]=useState(false),s=useRef(null);useEffect(()=>{if(!r)return;function d(c){s.current&&!s.current.contains(c.target)&&a(false);}return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[r]);let i=t.length>=wt,l=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(d=>jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:n.get(d)??"#6b7280",display:"inline-block"}},d))}),jsx("span",{style:{color:"#e5e7eb",fontSize:12,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.length===1?(()=>{let d=e.find(c=>c.slug===t[0]);return d?.outcomes?.[0]?.label??d?.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:()=>a(d=>!d),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:[l,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 ",wt," markets"]}),e.map(d=>{let c=t.includes(d.slug),m=!c&&i,p=c&&t.length===1,f=n.get(d.slug)??"#6b7280",u=d.outcomes.find(v=>v.label.toLowerCase()==="yes")??d.outcomes[0],g=u?.price!=null?`${Math.round(u.price*100)}%`:null;return jsxs("button",{onClick:()=>{p||m||o(d.slug);},style:{display:"flex",alignItems:"center",gap:10,width:"100%",padding:"7px 12px",border:"none",background:c?"rgba(255,255,255,0.05)":"transparent",cursor:m||p?"not-allowed":"pointer",opacity:m?.35:1,textAlign:"left",transition:"background 0.1s"},onMouseEnter:v=>{!m&&!p&&(v.currentTarget.style.background="rgba(255,255,255,0.07)");},onMouseLeave:v=>{v.currentTarget.style.background=c?"rgba(255,255,255,0.05)":"transparent";},children:[jsx("span",{style:{width:16,height:16,borderRadius:4,border:c?`2px solid ${f}`:"2px solid rgba(255,255,255,0.2)",background:c?`${f}30`:"transparent",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center"},children:c&&jsx("svg",{width:"9",height:"7",viewBox:"0 0 9 7",fill:"none",children:jsx("path",{d:"M1 3.5L3.5 6L8 1",stroke:f,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:f,flexShrink:0}}),jsx("span",{style:{color:c?"#f9fafb":"#9ca3af",fontSize:12,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d.outcomes?.[0]?.label??d.question}),g&&jsx("span",{style:{color:f,fontWeight:700,fontSize:12,flexShrink:0},children:g})]},d.slug)})]})]})}function $i({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",a=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:a!=null?Kn(a):"--"})]})]},o.marketSlug)})})}function zi(e){let t=Math.floor(e.length/2);return e.length%2===1?e[t]:(e[t-1]+e[t])/2}function Ki(e,t){if(e.length<=t)return e;let n=[],o=e.length/t;for(let r=0;r<t;r++){let a=Math.floor(r*o),s=Math.min(Math.floor((r+1)*o),e.length),i=e.slice(a,s),l=i.map(d=>d.price).sort((d,c)=>d-c);n.push({timestamp:i[i.length-1].timestamp,price:zi(l)});}return n}function Vi(e,t=200){if(e.length===0)return [];let n=e.map(i=>({...i,data:Ki(i.data,t)})),o=new Set;n.forEach(i=>i.data.forEach(l=>o.add(l.timestamp)));let r=Array.from(o).sort((i,l)=>i-l),a=n.map(i=>{let l=new Map;return i.data.forEach(d=>l.set(d.timestamp,d.price)),{slug:i.marketSlug,map:l}}),s=new Map;return r.map(i=>{let l={timestamp:i};return a.forEach(({slug:d,map:c})=>{let m=c.get(i);if(m!==void 0)s.set(d,m),l[d]=m;else {let p=s.get(d);p!==void 0&&(l[d]=p);}}),l})}function Vn(e){return jsx(cr,{children:jsx(Yi,{...e})})}function Yi({event:e,isLoading:t,className:n,volume:o}){let r=useMemo(()=>(e.markets??[]).filter(y=>y.status==="open"),[e.markets]),a=useMemo(()=>[...r].sort((y,T)=>{let I=D=>(D.outcomes.find(G=>G.label.toLowerCase()==="yes")??D.outcomes[0])?.price??0;return I(T)-I(y)}),[r]),[s,i]=useState(()=>a.slice(0,wt).map(y=>y.slug)),[l,d]=useState(ut),c=useMemo(()=>{let y=new Map;return s.forEach((T,I)=>{y.set(T,$n[I%$n.length]);}),y},[s]),m=useMemo(()=>r.filter(y=>s.includes(y.slug)),[r,s]),{series:p,isLoading:f}=useMarketHistory(m,l),u=t||f,g=useMemo(()=>{if(p.length>0&&p.some(I=>I.data.length>0))return p;let y=Date.now(),T=864e5;return m.map(I=>{let G=(I.outcomes?.find(J=>J.label.toLowerCase()==="yes")??I.outcomes?.[0])?.price??.5;return {marketSlug:I.slug,label:I.outcomes?.[0]?.label??I.question,data:[{timestamp:y-7*T,price:G},{timestamp:y,price:G}]}})},[p,m]),v=useMemo(()=>l===ChartRange.ONE_DAY?96:l===ChartRange.ONE_WEEK?168:l===ChartRange.ONE_MONTH?180:300,[l]),h=useMemo(()=>Vi(g,v),[g,v]),$=useMemo(()=>{if(h.length===0)return [0,1];let y=1/0,T=-1/0;if(s.forEach(D=>{h.forEach(G=>{let J=G[D];J!=null&&(J<y&&(y=J),J>T&&(T=J));});}),!isFinite(y))return [0,1];let I=Math.max((T-y)*.15,.05);return [Math.max(0,y-I),Math.min(1,T+I)]},[h,s]),P=useMemo(()=>{let y=new Map;return g.forEach(T=>{T.data.length>0&&y.set(T.marketSlug,T.data[T.data.length-1].price);}),y},[g]),C=useMemo(()=>{let y=new Map;return g.forEach(T=>y.set(T.marketSlug,T.label)),y},[g]),R=useMemo(()=>g.map(y=>({slug:y.marketSlug,color:c.get(y.marketSlug)??"#6b7280"})),[g,c]),{wrapperRef:j,overlayRef:M,onMouseMove:ce,onMouseLeave:W}=Bi(),ue=useCallback(y=>{i(T=>T.includes(y)?T.length<=1?T:T.filter(I=>I!==y):T.length>=wt?T:[...T,y]);},[]),[Se,N]=useState(null),re=useRef(null),se=useRef(""),Q=useRef(0),ae=!u&&h.length>0;return jsxs("div",{className:n,style:{display:"flex",flexDirection:"column",gap:12},children:[jsx($i,{series:g,colorMap:c,displayValues:Se??P}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:0},children:[jsx("div",{ref:j,style:{height:300,width:"100%",userSelect:"none",position:"relative"},onMouseMove:ae?y=>{ce(y),cancelAnimationFrame(Q.current),Q.current=requestAnimationFrame(()=>{N(re.current);});}:void 0,onMouseLeave:ae?()=>{W(),cancelAnimationFrame(Q.current),se.current="",re.current=null,N(null);}:void 0,children:u?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:M,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:y=>Ai(y,l),axisLine:false,tickLine:false,tick:{fill:"#6b7280",fontSize:11},minTickGap:70}),jsx(YAxis,{domain:$,tickFormatter:y=>`${Math.round(y*100)}%`,axisLine:false,tickLine:false,tick:{fill:"#6b7280",fontSize:11},width:40,tickCount:6}),jsx(Tooltip,{content:y=>{let T=y;if(T.active&&T.payload?.length){let I=T.payload.map(D=>`${D.dataKey}:${D.value}`).join(",");if(I!==se.current){se.current=I;let D=new Map;T.payload.forEach(G=>{G.value!=null&&D.set(G.dataKey,G.value);}),re.current=D;}}return jsx(Ui,{...T,labelMap:C,allSeries:R,range:l})},cursor:{stroke:"#4b5563",strokeWidth:1,strokeDasharray:"4 4"},wrapperStyle:{zIndex:2},isAnimationActive:false}),g.map(y=>{let T=c.get(y.marketSlug)??"#6b7280";return jsx(Line,{type:"linear",dataKey:y.marketSlug,stroke:T,strokeWidth:2,strokeLinejoin:"round",strokeLinecap:"round",dot:false,activeDot:{r:4.5,strokeWidth:2,stroke:"rgba(10,10,10,0.8)",fill:T},connectNulls:true,isAnimationActive:false},y.marketSlug)}),Se==null&&h.length>0&&g.map(y=>{let T=h[h.length-1],I=T[y.marketSlug];if(I==null)return null;let D=c.get(y.marketSlug)??"#6b7280";return jsx(ReferenceDot,{x:T.timestamp,y:I,ifOverflow:"extendDomain",shape:G=>{let{cx:J,cy:ge}=G;return J==null||ge==null?jsx("g",{}):jsxs("g",{children:[jsxs("circle",{cx:J,cy:ge,r:6,fill:D,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:J,cy:ge,r:3.5,fill:D})]})}},`pulse-${y.marketSlug}`)})]})})]})}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,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}}),a.length>1&&jsxs(Fragment,{children:[jsx(Wi,{markets:a,selectedSlugs:s,colorMap:c,onToggle:ue}),jsx("span",{style:{width:1,height:14,background:"#374151",flexShrink:0}})]}),jsx(Hi,{value:l,onChange:d})]})]})]})}function nt(e){return e.outcomes[0]?.best_ask??e.outcomes[0]?.price??0}function ol(e){return `${parseFloat((e*100).toFixed(2))}%`}function Yn(e){let t=e*100;return t<1&&t>0?"< 1":parseFloat(t.toFixed(2)).toString()}function St(e){return e.outcomes?.[0]?.label??e.question}function sl(e){switch(e){case "polymarket":return "Polymarket";case "dflow":return "Kalshi";default:return e}}function rt(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(),a=t.getHours().toString().padStart(2,"0"),s=t.getMinutes().toString().padStart(2,"0");return `${n} ${o}, ${r} ${a}:${s}`}function qn(e){let[t,n]=useState(Date.now());if(useEffect(()=>{if(!e)return;let c=setInterval(()=>n(Date.now()),1e3);return ()=>clearInterval(c)},[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 a=Math.floor(r/864e5),s=Math.floor(r%864e5/36e5),i=Math.floor(r%36e5/6e4),l=Math.floor(r%6e4/1e3),d=[];return a>0&&d.push(`${a}d`),d.push(`${String(s).padStart(2,"0")}h`),d.push(`${String(i).padStart(2,"0")}m`),d.push(`${String(l).padStart(2,"0")}s`),d.join(" ")}function jn(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"),a=t.getDate().toString().padStart(2,"0"),s=t.getFullYear(),i=-t.getTimezoneOffset(),l=i>=0?"+":"-",d=String(Math.abs(Math.floor(i/60))).padStart(2,"0");return `${n}:${o} ${r}/${a}/${s} (${l}${d})`}function Qn({event:e,onTradeAction:t}){let{t:n}=useTranslation(),{ref:o,isCollapsed:r}=useScrollCollapse(),a=useMemo(()=>{let m=[...e.markets||[]],p=m.filter(u=>u.status==="open").sort((u,g)=>nt(g)-nt(u)),f=m.filter(u=>u.status!=="open").sort((u,g)=>nt(g)-nt(u));return [...p,...f]},[e.markets]),s=e.status==="closed"||e.status==="voided",i=qn(s?void 0:e.start_at),l=qn(s?void 0:e.end_at),d=jn(e.start_at),c=jn(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((m,p)=>jsxs(Fragment$1,{children:[p>0&&jsx("span",{className:"text-sm text-neutral/50",children:"\xB7"}),jsx("span",{className:"text-sm text-neutral truncate",children:m.label})]},m.slug)),jsx(cl,{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})]})]}),(i||l||s)&&jsx("div",{className:"flex items-center gap-x-2 text-xs lg:text-sm font-mono",children:s?c&&jsx("span",{className:"text-neutral",children:n("predict.event.endedAt",{time:c})}):i?jsxs(Fragment,{children:[jsx("span",{className:"text-foreground",children:n("predict.event.beginsIn",{time:i})}),d&&jsxs(Fragment,{children:[jsx("span",{className:"text-neutral/50",children:"\xB7"}),jsx("span",{className:"text-neutral",children:d})]})]}):l?jsxs(Fragment,{children:[jsx("span",{className:"text-foreground",children:n("predict.event.endsIn",{time:l})}),c&&jsxs(Fragment,{children:[jsx("span",{className:"text-neutral/50",children:"\xB7"}),jsx("span",{className:"text-neutral",children:c})]})]}):null}),jsx(Vn,{event:e,volume:e.volume??void 0}),jsx(al,{markets:a,onTradeAction:t}),jsx(ll,{markets:a,event:e})]})}var Gn=5;function al({markets:e,onTradeAction:t}){let{t:n}=useTranslation(),[o,r]=useState(false),[a,s]=useState(null),i=e.find(u=>u.status==="open")?.slug,[l,d]=useState(i?`${i}:yes`:null);if(e.length===0)return null;let c=e.length>Gn,m=o?e:e.slice(0,Gn),p=u=>{s(g=>g===u?null:u);},f=(u,g,v)=>{d(`${u.slug}:${g}`),s(u.slug),t?.(u,g,v);};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:m.map(u=>{let g=nt(u),v=u.outcomes[1]?.best_ask??u.outcomes[1]?.price,h=a===u.slug;return jsx(il,{market:u,yesPrice:g,noPrice:v??void 0,activeYes:l===`${u.slug}:yes`,activeNo:l===`${u.slug}:no`,isExpanded:h,onToggleExpand:()=>p(u.slug),onTradeAction:f},u.slug)})})]}),c&&jsxs("button",{type:"button",onClick:()=>r(u=>!u),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(o?"predict.event.rules.collapse":"predict.event.moreMarketsLabel")}),jsx(ChevronDownIcon,{className:cn$1("h-4 w-4 transition-transform",o&&"rotate-180")})]})]})}function il({market:e,yesPrice:t,noPrice:n,activeYes:o,activeNo:r,isExpanded:a,onToggleExpand:s,onTradeAction:i}){let{t:l}=useTranslation(),d=e.status==="open",c=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:m=>{(m.key==="Enter"||m.key===" ")&&(m.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:St(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:St(e)}),c&&jsx("span",{className:"text-[8px] text-neutral lg:text-xxs",children:c})]})]})}),jsx("td",{className:"py-2 text-left text-foreground lg:text-center",children:ol(t)}),jsx("td",{className:"py-2 pr-1 lg:pr-2",children:d?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:m=>{m.stopPropagation(),i?.(e,"yes","buy");},children:l("predict.market.action.yes",{price:Yn(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:m=>{m.stopPropagation(),i?.(e,"no","buy");},children:n!=null?l("predict.market.action.no",{price:Yn(n)}):l("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"?l("predict.event.status.closed"):e.status==="voided"?l("predict.event.status.voided"):l("predict.event.status.pending")})})})]}),a&&jsx("tr",{children:jsx("td",{colSpan:3,className:"pb-3",children:jsx("div",{className:"max-h-100 overflow-y-auto",children:jsx(Wn,{market:e,outcome:r?"no":"yes",onTradeAction:i})})})})]})}function ll({markets:e,event:t}){let{t:n}=useTranslation(),[o,r]=useState(false),[a,s]=useState(false),[i,l]=useState(0),d=e.filter(f=>f.rules&&f.rules.length>0||f.description);if(d.length===0)return null;let c=d[i]??d[0],m=c.rules&&c.rules.length>0?c.rules.join(`
20
20
 
21
- `):c.description??"";if(!u)return null;let m=u.length>200&&!o?u.slice(0,200)+"...":u;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:r("predict.event.rules")}),d.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:ht(c)})}),jsx(DropdownMenu,{"aria-label":"Select market rules",selectionMode:"single",selectedKeys:[String(i)],onAction:f=>{l(Number(f)),n(false);},classNames:{list:"gap-1"},itemClasses:{base:"rounded-md px-3 h-8"},children:d.map((f,p)=>jsx(DropdownItem,{className:cn$1(p===i?"bg-content2 text-foreground":"text-neutral","data-[hover=true]:bg-content2 data-[hover=true]:text-foreground"),children:ht(f)},String(p)))})]})]}),jsx("div",{className:"text-xs text-foreground/80 lg:text-sm whitespace-pre-wrap",children:m}),u.length>200&&jsx("button",{type:"button",onClick:()=>n(f=>!f),className:"text-xs text-neutral hover:text-foreground cursor-pointer transition-colors self-start",children:r(o?"predict.event.rules.collapse":"predict.event.showMore")}),jsxs("button",{type:"button",onClick:()=>a(f=>!f),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:r("predict.event.timelineAndPayout")}),jsx(ChevronDownIcon,{className:cn$1("h-4 w-4 transition-transform",s&&"rotate-180")})]}),s&&jsxs(Fragment,{children:[jsx("div",{className:"flex flex-col",children:(()=>{let f=c.status,p=[];return c.created_at&&p.push({label:r("predict.event.timeline.created"),value:Xe(c.created_at),isActive:true}),p.push({label:r("predict.event.timeline.open"),value:Xe(c.start_at),isActive:f!=="pending"}),f==="voided"?p.push({label:r("predict.event.timeline.voided"),value:Xe(c.closed_at??c.end_at),isActive:true}):f==="closed"?p.push({label:r("predict.event.timeline.closed"),value:Xe(c.closed_at??c.end_at),isActive:true}):p.push({label:r("predict.event.timeline.close"),value:Xe(c.end_at),isActive:false}),p})().map((f,p,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 ${f.isActive?"border-primary bg-primary":"border-border bg-transparent"}`}),p<g.length-1&&jsx("div",{className:"w-px flex-1 bg-border"})]}),jsxs("div",{className:`flex flex-col ${p<g.length-1?"pb-4":""}`,children:[jsx("span",{className:"text-xs font-medium text-foreground lg:text-sm",children:f.label}),jsx("span",{className:"text-xs text-neutral lg:text-sm",children:f.value})]})]},f.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:[r("predict.event.id.event"),":"]})," ",jsx("span",{className:"text-foreground",children:t.slug})]}),jsxs("span",{children:[jsxs("span",{className:"text-neutral",children:[r("predict.event.id.market"),":"]})," ",jsx("span",{className:"text-foreground",children:c.slug})]}),jsxs("span",{children:[jsxs("span",{className:"text-neutral",children:[r("predict.event.id.source"),":"]})," ",jsx("span",{className:"text-foreground",children:tl(c.source)})]})]})]})]})}function sl({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 qn({eventSlug:e,source:t,onTradeAction:r}){let{data:o,isLoading:n,error:s}=useEvent({slug:e,source:t});return n?jsx(Ge,{}):s||!o?jsx("div",{className:"flex w-full items-center justify-center py-20 text-danger",children:s?.message||"Event not found"}):jsx(Yn,{event:o,onTradeAction:r})}function Gn({eventSlug:e,source:t,limit:r=4,onEventClick:o}){let{t:n}=useTranslation(),{data:s,isLoading:a}=useSimilarEvents({slug:e,source:t,limit:r});return a||!s||s.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:n("predict.similar.title")}),jsx("div",{className:"grid grid-cols-1 gap-3",children:s.map(i=>jsx(ul,{event:i,onClick:o},i.slug))})]})}function ul({event:e,onClick:t}){let r=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}),r!=null&&r>0&&jsxs("span",{className:"text-xs text-neutral",children:["$",Math.round(r).toLocaleString()," vol"]})]}),jsx(ChevronRightIcon,{className:"h-4 w-4 text-neutral shrink-0"})]})}function jn(e){return e.outcomes[0]?.best_ask??e.outcomes[0]?.price??0}function Op({eventSlug:e,source:t,chain:r,walletAddress:o,onSimilarEventClick:n,onBack:s}){let{t:a}=useTranslation(),{isMobile:i}=useScreen(),{isOpen:l,onOpen:d,onClose:c}=useDisclosure(),{data:u,isLoading:m}=useEvent({slug:e,source:t}),f=useMemo(()=>[...u?.markets||[]].sort((E,M)=>jn(M)-jn(E)),[u?.markets]),[p,g]=useState(null),v=useCallback((E,M,T)=>{g(G=>({market:E,outcome:M,side:T,version:(G?.version??0)+1})),i&&d();},[i,d]),b=p?.market??f[0];if(m){let E=!!s;return i?jsx(Ge,{showBack:E}):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(Ge,{showBack:E})}),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(Pn,{})})})]})}let U=p?`${p.market.slug}-${p.version}`:b?.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:[s&&jsx("div",{className:"flex items-center justify-between",children:jsx(Button,{as:"a",onPress:s,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:a("common.back")})}),jsx(qn,{eventSlug:e,source:t,onTradeAction:v})]}),jsxs("div",{className:"hidden flex-none w-md flex-col gap-y-4 lg:sticky lg:top-4 lg:flex lg:self-start",children:[b&&jsx(lt,{event:u,market:b,initialSide:p?.side,initialOutcome:p?.outcome,chain:r},U),u&&jsx(Gn,{eventSlug:e,source:u.source,onEventClick:n})]})]}),u&&jsx("div",{className:"flex w-full flex-col",children:jsx(Nn,{event:u,walletAddress:o})})]})}function Xn(e){return e.outcomes[0]?.best_ask??e.outcomes[0]?.price??0}function Pl(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 Fp=e=>{let{candlestickMarketSlugs:t,chartRange:r=at,source:o}=e,n=usePredictClient(),s=useMemo(()=>Pl(r),[r]),{data:a,isLoading:i,error:l}=useEvent({slug:e.eventSlug,source:o}),d=useMemo(()=>a?.markets?(t&&t.length>0?t.slice(0,4).map(g=>a.markets.find(v=>v.slug===g)).filter(g=>g!==void 0):[...a.markets].sort((g,v)=>Xn(v)-Xn(g)).slice(0,4)).map(g=>g.slug):[],[t,a?.markets]),c=useQueries({queries:d.map(p=>({queryKey:candlesticksQueryKey(p,s),queryFn:()=>n.listCandlesticks(p,s),enabled:d.length>0}))}),u=c.some(p=>p.isLoading),m=useMemo(()=>{let p=new Map;return d.forEach((g,v)=>{let b=c[v]?.error;b&&p.set(g,b);}),p},[d,c]),f=useMemo(()=>{let p=new Map;return d.forEach((g,v)=>{let b=c[v]?.data;b&&p.set(g,b);}),p},[d,c]);return {event:a,isEventLoading:i,eventError:l,candlestickParams:s,candlesticks:f,isCandlesticksLoading:u,candlestickErrors:m}};var Tl=10,Ml=atomWithStorage("liberfi:predict_search_histories",[],void 0,{getOnInit:true});function kt(){let[e,t]=useAtom(Ml),r=useCallback(n=>{let s=n.trim();s&&t(a=>{let i=a.filter(l=>l!==s);return [s,...i].slice(0,Tl)});},[t]),o=useCallback(()=>{t([]);},[t]);return {histories:e,addHistory:r,clearHistories:o}}function eo({histories:e,onSelect:t,onClear:r,className:o}){let{t:n}=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:n("predict.search.history")}),jsx(Button,{isIconOnly:true,size:"sm",className:"bg-transparent min-w-6 w-6 h-6 text-neutral",onPress:r,children:jsx(TrashIcon,{width:20,height:20})})]}),jsx("div",{className:"flex flex-wrap gap-2 mt-2",children:e.map(s=>jsx(Chip,{size:"sm",variant:"bordered",className:cn$1("text-neutral","border-border border-1","cursor-pointer","hover:opacity-hover"),onClick:()=>t?.(s),children:s},s))})]})}function to({onSelect:e,className:t}){let{histories:r,clearHistories:o}=kt();return jsx(eo,{className:cn$1(t),histories:r,onSelect:e,onClear:o})}function ro({value:e,onValueChange:t,onClear:r,onEscape:o,className:n}){let{t:s}=useTranslation();return jsx("div",{className:n,children:jsx(StyledInput,{autoFocus:true,variant:"flat",radius:"full",value:e,onValueChange:t,placeholder:s("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:r,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:a=>{a.preventDefault(),o?.();},children:"Esc"})})})}function so({event:e,href:t,LinkComponent:r,onSelect:o,onHover:n,className:s}){let a=e.tags?.[0];return jsxs(Linkable,{href:t,LinkComponent:r,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",s),onClick:i=>{t&&o&&i.preventDefault(),o?.(e);},onMouseEnter:()=>n?.(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 items-center gap-2.5",children:[jsx("span",{className:"min-w-0 text-sm font-medium truncate",children:e.title}),a&&jsx("span",{className:cn$1("flex-shrink-0 inline-flex items-center","rounded-full px-2.5 py-1.5","text-[11px] font-semibold leading-none uppercase","bg-primary/15 text-primary"),children:a.label})]})]})}function ao({keyword:e="",limit:t,source:r}){let{data:o,isLoading:n,isFetchingNextPage:s,hasNextPage:a,fetchNextPage:i}=useSearchEvents({keyword:e,limit:t,source:r},{enabled:true});return {events:useMemo(()=>o?.pages.flatMap(d=>d.items).filter(d=>d!=null)??[],[o]),isLoading:n,isFetchingNextPage:s,hasNextPage:a??false,fetchNextPage:i}}var Jl=56;function uo({onSelect:e,getEventHref:t,LinkComponent:r,onHover:o,className:n,...s}){let{events:a,isLoading:i,isFetchingNextPage:l,hasNextPage:d,fetchNextPage:c}=ao(s),u=useRef(null),{height:m}=useResizeObserver({ref:u}),f=useCallback(b=>b<a.length,[a]),p=useCallback(async()=>{d&&!l&&await c();},[d,l,c]),g=useMemo(()=>d?a.length+1:a.length,[a,d]),v=useInfiniteLoader({isRowLoaded:f,loadMoreRows:p,rowCount:g,threshold:5});return i?jsx(ec,{className:n}):a.length===0?jsx(tc,{className:n}):jsx("div",{className:cn$1("w-full h-full flex flex-col",n),children:jsx("div",{className:"flex-auto min-h-0",ref:u,children:jsx(List,{style:{height:m},onRowsRendered:v,rowComponent:Zl,rowCount:g,rowHeight:Jl,rowProps:{events:a,onSelect:e,getEventHref:t,LinkComponent:r,onHover:o},overscanCount:5})})})}function Zl({index:e,style:t,events:r,onSelect:o,getEventHref:n,LinkComponent:s,onHover:a}){let i=r[e];return i?jsx("div",{style:t,children:jsx(so,{event:i,href:n?.(i),LinkComponent:s,onSelect:o,onHover:a})}):jsx("div",{style:t,className:"flex items-center justify-center",children:jsx(Spinner,{size:"sm"})})}function ec({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 tc({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 go({onKeywordChange:e}){let[t,r]=useState(""),[o,n]=useState(""),{addHistory:s}=kt(),a=useCallbackRef(e),i=useCallbackRef(s),l=useMemo(()=>debounce(m=>{n(m),a(m),m&&i(m);},500),[a,i]),d=useCallback(m=>{r(m),l(m);},[l]),c=useCallback(m=>{l.cancel(),r(m),n(m),a(m),m&&i(m);},[l,a,i]),u=useCallback(()=>c(""),[c]);return {text:t,keyword:o,setText:d,setKeyword:c,clearKeyword:u}}function vo({onKeywordChange:e,onSelectEvent:t,getEventHref:r,LinkComponent:o,onHover:n,onEscape:s,source:a}){let{text:i,keyword:l,setText:d,setKeyword:c,clearKeyword:u}=go({onKeywordChange:e});return jsxs("div",{className:"w-full h-full flex flex-col gap-3",children:[jsx(ro,{value:i,onValueChange:d,onClear:u,onEscape:s}),!l&&jsx(to,{onSelect:c}),jsx(uo,{className:"flex-auto min-h-0",keyword:l,onSelect:t,getEventHref:r,LinkComponent:o,onHover:n,source:a})]})}var ur="predict-search";function nf({id:e=ur}){return jsx(AsyncModal,{id:e,children:t=>jsx(fc,{...t})})}function fc({params:e,isOpen:t,onOpenChange:r,onResult:o}){let{t:n}=useTranslation(),{isMobile:s}=useScreen(),a=useCallback(l=>{o(l);},[o]),i=useCallback(()=>{r(false);},[r]);return jsx(StyledModal,{isOpen:t,onOpenChange:r,size:s?"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:n("predict.search.title")}),jsx(Button,{isIconOnly:true,onPress:()=>r(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(vo,{getEventHref:e?.getEventHref,LinkComponent:e?.LinkComponent,onHover:e?.onHover,source:e?.source,onSelectEvent:a,onEscape:i})})]})})}function mf({onSelectEvent:e,modalParams:t,className:r}){let{t:o}=useTranslation(),{isDesktop:n,isMobile:s}=useScreen(),{onOpen:a,onClose:i}=useAsyncModal(ur),l=useCallbackRef(e),d=useCallbackRef(async()=>{let u=await a({params:t});u&&l(u);}),c=useCallbackRef(()=>{i();});return useEffect(()=>{let u=m=>{let f=document.activeElement,p=!!f&&(f.tagName==="INPUT"||f.tagName==="TEXTAREA"||f.getAttribute("contenteditable")==="true");m.key==="/"&&!p&&(m.preventDefault(),d()),m.key==="Escape"&&(m.preventDefault(),c());};return window.addEventListener("keydown",u),()=>{window.removeEventListener("keydown",u);}},[d,c]),jsx(Button,{size:"sm",radius:"full",isIconOnly:!n,onPress:d,variant:s?"flat":"bordered",startContent:n?jsx(SearchIcon,{className:"text-neutral"}):void 0,endContent:n?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(n&&"min-w-56 justify-start pl-3 pr-1.5 text-neutral",r),children:n?o("predict.search.placeholder"):jsx(SearchIcon,{className:"text-neutral"})})}export{Fc as CHART_RANGE_DURATION,Hc as CHART_RANGE_PERIOD,Bc as CHART_RANGE_SAMPLE_INTERVAL,st as CandlestickPeriod,Tc as CategoriesSkeleton,Cr as CategoriesUI,Rr as CategoriesWidget,te as ChartRange,at as DEFAULT_CHART_RANGE,Wt as DEFAULT_FILTER_STATE,Ue as DEFAULT_PAGE_SIZE,zc as DEFAULT_PRICE_HISTORY_INTERVAL,Op as EventDetailPage,Ge as EventDetailSkeleton,Yn as EventDetailUI,qn as EventDetailWidget,un as EventItem,Rn as EventMarketDepthChartUI,Dn as EventMarketDetailWidget,Un as EventPriceChart,Yr as EventsFilterUI,bu as EventsPage,$d as EventsPageSkeleton,zt as EventsSkeleton,Qr as EventsToolbarUI,xn as EventsUI,bn as EventsWidget,It as MAX_PRICE_HISTORY_MARKETS,$c as ORDER_MAX_PRICE,Wc as ORDER_MIN_PRICE,_t as ORDER_MIN_QUANTITY,Uc as ORDER_PRICE_STEP,ur as PREDICT_SEARCH_MODAL_ID,Ut as PREDICT_TRADE_MODAL_ID,Kc as PRICE_HISTORY_SAMPLE_INTERVAL,nf as PredictSearchModal,Kr as PredictTradeModal,Qo as PredictWalletProvider,Ee as PriceHistoryInterval,Xr as SORT_PRESETS,Ot as STATIC_CATEGORIES,mf as SearchEventsButton,eo as SearchHistoryUI,to as SearchHistoryWidget,ro as SearchInputUI,so as SearchResultItemUI,uo as SearchResultListWidget,vo as SearchWidget,ul as SimilarEventCard,Gn as SimilarEventsSection,Pn as TradeFormSkeleton,$r as TradeFormUI,lt as TradeFormWidget,Nn as UserActivitySection,$t as countActiveFilters,je as formatWan,Fp as useEventDetail,en as useEventsInfinite,kt as usePredictSearchHistory,Dt as usePredictWallet,ao as useSearchResultListScript,go as useSearchScript,Fr as useTradeForm,Bo as version};//# sourceMappingURL=index.mjs.map
21
+ `):c.description??"";if(!m)return null;let p=m.length>200&&!o?m.slice(0,200)+"...":m;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")}),d.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:St(c)})}),jsx(DropdownMenu,{"aria-label":"Select market rules",selectionMode:"single",selectedKeys:[String(i)],onAction:f=>{l(Number(f)),r(false);},classNames:{list:"gap-1"},itemClasses:{base:"rounded-md px-3 h-8"},children:d.map((f,u)=>jsx(DropdownItem,{className:cn$1(u===i?"bg-content2 text-foreground":"text-neutral","data-[hover=true]:bg-content2 data-[hover=true]:text-foreground"),children:St(f)},String(u)))})]})]}),jsx("div",{className:"text-xs text-foreground/80 lg:text-sm whitespace-pre-wrap",children:p}),m.length>200&&jsx("button",{type:"button",onClick:()=>r(f=>!f),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(f=>!f),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",a&&"rotate-180")})]}),a&&jsxs(Fragment,{children:[jsx("div",{className:"flex flex-col",children:(()=>{let f=c.status,u=[];return c.created_at&&u.push({label:n("predict.event.timeline.created"),value:rt(c.created_at),isActive:true}),u.push({label:n("predict.event.timeline.open"),value:rt(c.start_at),isActive:f!=="pending"}),f==="voided"?u.push({label:n("predict.event.timeline.voided"),value:rt(c.closed_at??c.end_at),isActive:true}):f==="closed"?u.push({label:n("predict.event.timeline.closed"),value:rt(c.closed_at??c.end_at),isActive:true}):u.push({label:n("predict.event.timeline.close"),value:rt(c.end_at),isActive:false}),u})().map((f,u,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 ${f.isActive?"border-primary bg-primary":"border-border bg-transparent"}`}),u<g.length-1&&jsx("div",{className:"w-px flex-1 bg-border"})]}),jsxs("div",{className:`flex flex-col ${u<g.length-1?"pb-4":""}`,children:[jsx("span",{className:"text-xs font-medium text-foreground lg:text-sm",children:f.label}),jsx("span",{className:"text-xs text-neutral lg:text-sm",children:f.value})]})]},f.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:c.slug})]}),jsxs("span",{children:[jsxs("span",{className:"text-neutral",children:[n("predict.event.id.source"),":"]})," ",jsx("span",{className:"text-foreground",children:sl(c.source)})]})]})]})]})}function cl({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 Jn({eventSlug:e,source:t,onTradeAction:n}){let{data:o,isLoading:r,error:a}=useEvent({slug:e,source:t});return r?jsx(et,{}):a||!o?jsx("div",{className:"flex w-full items-center justify-center py-20 text-danger",children:a?.message||"Event not found"}):jsx(Qn,{event:o,onTradeAction:n})}function Zn({eventSlug:e,source:t,limit:n=4,onEventClick:o}){let{t:r}=useTranslation(),{data:a,isLoading:s}=useSimilarEvents({slug:e,source:t,limit:n});return s||!a||a.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:a.map(i=>jsx(gl,{event:i,onClick:o},i.slug))})]})}function gl({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 eo(e){return e.outcomes[0]?.best_ask??e.outcomes[0]?.price??0}function Fp({eventSlug:e,source:t,chain:n,walletAddress:o,onSimilarEventClick:r,onBack:a}){let{t:s}=useTranslation(),{isMobile:i}=useScreen(),{isOpen:l,onOpen:d,onClose:c}=useDisclosure(),{data:m,isLoading:p}=useEvent({slug:e,source:t}),f=useMemo(()=>[...m?.markets||[]].sort((P,C)=>eo(C)-eo(P)),[m?.markets]),[u,g]=useState(null),v=useCallback((P,C,R)=>{g(j=>({market:P,outcome:C,side:R,version:(j?.version??0)+1})),i&&d();},[i,d]),h=u?.market??f[0];if(p){let P=!!a;return i?jsx(et,{showBack:P}):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(et,{showBack:P})}),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(Rn,{})})})]})}let $=u?`${u.market.slug}-${u.version}`:h?.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:[a&&jsx("div",{className:"flex items-center justify-between",children:jsx(Button,{as:"a",onPress:a,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(Jn,{eventSlug:e,source:t,onTradeAction:v})]}),jsxs("div",{className:"hidden flex-none w-md flex-col gap-y-4 lg:sticky lg:top-4 lg:flex lg:self-start",children:[h&&jsx(pt,{event:m,market:h,initialSide:u?.side,initialOutcome:u?.outcome,chain:n},$),m&&jsx(Zn,{eventSlug:e,source:m.source,onEventClick:r})]})]}),m&&jsx("div",{className:"flex w-full flex-col",children:jsx(Mn,{event:m,walletAddress:o})})]})}function to(e){return e.outcomes[0]?.best_ask??e.outcomes[0]?.price??0}function Ml(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 Kp=e=>{let{candlestickMarketSlugs:t,chartRange:n=ut,source:o}=e,r=usePredictClient(),a=useMemo(()=>Ml(n),[n]),{data:s,isLoading:i,error:l}=useEvent({slug:e.eventSlug,source:o}),d=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)=>to(v)-to(g)).slice(0,4)).map(g=>g.slug):[],[t,s?.markets]),c=useQueries({queries:d.map(u=>({queryKey:candlesticksQueryKey(u,a),queryFn:()=>r.listCandlesticks(u,a),enabled:d.length>0}))}),m=c.some(u=>u.isLoading),p=useMemo(()=>{let u=new Map;return d.forEach((g,v)=>{let h=c[v]?.error;h&&u.set(g,h);}),u},[d,c]),f=useMemo(()=>{let u=new Map;return d.forEach((g,v)=>{let h=c[v]?.data;h&&u.set(g,h);}),u},[d,c]);return {event:s,isEventLoading:i,eventError:l,candlestickParams:a,candlesticks:f,isCandlesticksLoading:m,candlestickErrors:p}};var Ol=10,Il=atomWithStorage("liberfi:predict_search_histories",[],void 0,{getOnInit:true});function Ct(){let[e,t]=useAtom(Il),n=useCallback(r=>{let a=r.trim();a&&t(s=>{let i=s.filter(l=>l!==a);return [a,...i].slice(0,Ol)});},[t]),o=useCallback(()=>{t([]);},[t]);return {histories:e,addHistory:n,clearHistories:o}}function so({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(a=>jsx(Chip,{size:"sm",variant:"bordered",className:cn$1("text-neutral","border-border border-1","cursor-pointer","hover:opacity-hover"),onClick:()=>t?.(a),children:a},a))})]})}function ao({onSelect:e,className:t}){let{histories:n,clearHistories:o}=Ct();return jsx(so,{className:cn$1(t),histories:n,onSelect:e,onClear:o})}function io({value:e,onValueChange:t,onClear:n,onEscape:o,className:r}){let{t:a}=useTranslation();return jsx("div",{className:r,children:jsx(StyledInput,{autoFocus:true,variant:"flat",radius:"full",value:e,onValueChange:t,placeholder:a("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 uo({event:e,href:t,LinkComponent:n,onSelect:o,onHover:r,className:a}){let s=e.tags?.[0];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",a),onClick:i=>{t&&o&&i.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 items-center gap-2.5",children:[jsx("span",{className:"min-w-0 text-sm font-medium truncate",children:e.title}),s&&jsx("span",{className:cn$1("flex-shrink-0 inline-flex items-center","rounded-full px-2.5 py-1.5","text-[11px] font-semibold leading-none uppercase","bg-primary/15 text-primary"),children:s.label})]})]})}function po({keyword:e="",limit:t,source:n}){let{data:o,isLoading:r,isFetchingNextPage:a,hasNextPage:s,fetchNextPage:i}=useSearchEvents({keyword:e,limit:t,source:n},{enabled:true});return {events:useMemo(()=>o?.pages.flatMap(d=>d.items).filter(d=>d!=null)??[],[o]),isLoading:r,isFetchingNextPage:a,hasNextPage:s??false,fetchNextPage:i}}var rc=56;function vo({onSelect:e,getEventHref:t,LinkComponent:n,onHover:o,className:r,...a}){let{events:s,isLoading:i,isFetchingNextPage:l,hasNextPage:d,fetchNextPage:c}=po(a),m=useRef(null),{height:p}=useResizeObserver({ref:m}),f=useCallback(h=>h<s.length,[s]),u=useCallback(async()=>{d&&!l&&await c();},[d,l,c]),g=useMemo(()=>d?s.length+1:s.length,[s,d]),v=useInfiniteLoader({isRowLoaded:f,loadMoreRows:u,rowCount:g,threshold:5});return i?jsx(oc,{className:r}):s.length===0?jsx(sc,{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:m,children:jsx(List,{style:{height:p},onRowsRendered:v,rowComponent:nc,rowCount:g,rowHeight:rc,rowProps:{events:s,onSelect:e,getEventHref:t,LinkComponent:n,onHover:o},overscanCount:5})})})}function nc({index:e,style:t,events:n,onSelect:o,getEventHref:r,LinkComponent:a,onHover:s}){let i=n[e];return i?jsx("div",{style:t,children:jsx(uo,{event:i,href:r?.(i),LinkComponent:a,onSelect:o,onHover:s})}):jsx("div",{style:t,className:"flex items-center justify-center",children:jsx(Spinner,{size:"sm"})})}function oc({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 sc({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 yo({onKeywordChange:e}){let[t,n]=useState(""),[o,r]=useState(""),{addHistory:a}=Ct(),s=useCallbackRef(e),i=useCallbackRef(a),l=useMemo(()=>debounce(p=>{r(p),s(p),p&&i(p);},500),[s,i]),d=useCallback(p=>{n(p),l(p);},[l]),c=useCallback(p=>{l.cancel(),n(p),r(p),s(p),p&&i(p);},[l,s,i]),m=useCallback(()=>c(""),[c]);return {text:t,keyword:o,setText:d,setKeyword:c,clearKeyword:m}}function wo({onKeywordChange:e,onSelectEvent:t,getEventHref:n,LinkComponent:o,onHover:r,onEscape:a,source:s}){let{text:i,keyword:l,setText:d,setKeyword:c,clearKeyword:m}=yo({onKeywordChange:e});return jsxs("div",{className:"w-full h-full flex flex-col gap-3",children:[jsx(io,{value:i,onValueChange:d,onClear:m,onEscape:a}),!l&&jsx(ao,{onSelect:c}),jsx(vo,{className:"flex-auto min-h-0",keyword:l,onSelect:t,getEventHref:n,LinkComponent:o,onHover:r,source:s})]})}var vr="predict-search";function cf({id:e=vr}){return jsx(AsyncModal,{id:e,children:t=>jsx(hc,{...t})})}function hc({params:e,isOpen:t,onOpenChange:n,onResult:o}){let{t:r}=useTranslation(),{isMobile:a}=useScreen(),s=useCallback(l=>{o(l);},[o]),i=useCallback(()=>{n(false);},[n]);return jsx(StyledModal,{isOpen:t,onOpenChange:n,size:a?"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(wo,{getEventHref:e?.getEventHref,LinkComponent:e?.LinkComponent,onHover:e?.onHover,source:e?.source,onSelectEvent:s,onEscape:i})})]})})}function hf({onSelectEvent:e,modalParams:t,className:n}){let{t:o}=useTranslation(),{isDesktop:r,isMobile:a}=useScreen(),{onOpen:s,onClose:i}=useAsyncModal(vr),l=useCallbackRef(e),d=useCallbackRef(async()=>{let m=await s({params:t});m&&l(m);}),c=useCallbackRef(()=>{i();});return useEffect(()=>{let m=p=>{let f=document.activeElement,u=!!f&&(f.tagName==="INPUT"||f.tagName==="TEXTAREA"||f.getAttribute("contenteditable")==="true");p.key==="/"&&!u&&(p.preventDefault(),d()),p.key==="Escape"&&(p.preventDefault(),c());};return window.addEventListener("keydown",m),()=>{window.removeEventListener("keydown",m);}},[d,c]),jsx(Button,{size:"sm",radius:"full",isIconOnly:!r,onPress:d,variant:a?"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{zc as CHART_RANGE_DURATION,Wc as CHART_RANGE_PERIOD,$c as CHART_RANGE_SAMPLE_INTERVAL,dt as CandlestickPeriod,Oc as CategoriesSkeleton,Rr as CategoriesUI,Ir as CategoriesWidget,ne as ChartRange,ut as DEFAULT_CHART_RANGE,Vt as DEFAULT_FILTER_STATE,Ye as DEFAULT_PAGE_SIZE,qc as DEFAULT_PRICE_HISTORY_INTERVAL,Fp as EventDetailPage,et as EventDetailSkeleton,Qn as EventDetailUI,Jn as EventDetailWidget,xn as EventItem,An as EventMarketDepthChartUI,Wn as EventMarketDetailWidget,Vn as EventPriceChart,Jr as EventsFilterUI,ku as EventsPage,qd as EventsPageSkeleton,qt as EventsSkeleton,nn as EventsToolbarUI,Nn as EventsUI,Pn as EventsWidget,Ft as MAX_PRICE_HISTORY_MARKETS,Yc as ORDER_MAX_PRICE,Vc as ORDER_MIN_PRICE,Ht as ORDER_MIN_QUANTITY,Kc as ORDER_PRICE_STEP,vr as PREDICT_SEARCH_MODAL_ID,Kt as PREDICT_TRADE_MODAL_ID,jc as PRICE_HISTORY_SAMPLE_INTERVAL,cf as PredictSearchModal,Xr as PredictTradeModal,ts as PredictWalletProvider,Ie as PriceHistoryInterval,rn as SORT_PRESETS,Dt as STATIC_CATEGORIES,hf as SearchEventsButton,so as SearchHistoryUI,ao as SearchHistoryWidget,io as SearchInputUI,uo as SearchResultItemUI,vo as SearchResultListWidget,wo as SearchWidget,gl as SimilarEventCard,Zn as SimilarEventsSection,Rn as TradeFormSkeleton,jr as TradeFormUI,pt as TradeFormWidget,Mn as UserActivitySection,Yt as countActiveFilters,tt as formatWan,Kp as useEventDetail,an as useEventsInfinite,Ct as usePredictSearchHistory,Ut as usePredictWallet,po as useSearchResultListScript,yo as useSearchScript,zr as useTradeForm,$o as version};//# sourceMappingURL=index.mjs.map
22
22
  //# sourceMappingURL=index.mjs.map