@liberfi.io/ui-predict 0.1.80 → 0.1.82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -15
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {memo,useRef,createContext,useCallback,useState,useMemo,useEffect,Fragment as Fragment$1,Component}from'react';import {cn as cn$1,Skeleton,toast,Tabs,Tab,StyledNumberInput,ChevronDownIcon,Button,useScreen,StyledModal,ModalContent,ModalBody,ModalHeader,ModalFooter,RefreshIcon,TimerIcon,DropletIcon,ChartLineIcon,CalendarIcon,StyledBadge,FilterIcon,Linkable,Avatar,ChevronUpIcon,PolymarketIcon,KalshiIcon,Spinner,useDisclosure,OrderbookTableIcon,OrderbookDepthIcon,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 {useAuth,useWallets,useAuthCallback}from'@liberfi.io/wallet-connector';import xt from'canvas-confetti';import {ChartRange,useDFlowQuote,usePositions,useDFlowSubmit,useOrder,resolveEventsParams,useInfiniteEvents,useOrders,useCancelOrder,useTrades,useOrderbook,useMarketHistory,useEvent,useSimilarEvents,usePredictClient,candlesticksQueryKey,useSearchEvents,useBalance}from'@liberfi.io/react-predict';export{PredictClient,PredictContext,PredictProvider,PredictWsClient,createPredictClient,createPredictWsClient,useBalance,useCancelOrder,useCandlesticks,useDFlowQuote,useDFlowSubmit,useEvent,useEvents,useInfiniteEvents,useMarket,useMarketHistory,useMarketTrades,useOrder,useOrderbook,useOrders,usePositions,usePredictClient,usePriceHistory,useSearchEvents,useSimilarEvents,useTrades}from'@liberfi.io/react-predict';import {ChainNamespace}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 {useQueries}from'@tanstack/react-query';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.80");var Un="0.1.80";var $n={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},Kt=["Politics","Sports","Crypto","Economics","Financials","Elections","Entertainment","Companies","Science and Technology","Climate and Weather","Mentions","Social","World"],mt=(()=>{let e=t=>{let r=Kt.indexOf(t);return r===-1?Kt.length:r};return Object.entries($n).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 qt({categories:e,selectedCategory:t,selectedTag:r,activeTags:o,onCategorySelect:n,onTagSelect:i,trailing:a,pulsingTab:l="Trending",className:s}){let{t:c}=useTranslation(),d=useCallback(()=>{n(null);},[n]),u=c("predict.categories.trending");return jsxs("div",{className:cn$1("sticky top-0 z-30 flex w-full flex-col justify-between gap-2 px-4 py-1 lg:px-2 lg:py-1",s),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(Vt,{label:u,isSelected:t===null,onPress:d,showPulse:u===l}),jsx(Vn,{}),e.map(p=>jsx(Vt,{label:p.category,isSelected:t===p.category,onPress:()=>n(p.category),badge:p.badge,showPulse:p.category===l},p.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(Yt,{label:c("predict.categories.allMarkets"),isSelected:r===null,onPress:()=>i(null)}),o.map(p=>jsx(Yt,{label:p.label,icon:p.icon,isSelected:r===p.label,onPress:()=>i(p.label)},p.label))]})})]})}function Vt({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 Vn(){return jsx("span",{className:"flex items-center text-neutral-600","aria-hidden":"true",children:"|"})}function Yt({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 fl({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 Yn(e){return e.map(t=>({category:t.label,tags:t.tags.map(r=>r.label)}))}function qn(e){return e?e.tags.map(t=>({label:t.label,icon:t.icon})):[]}function Xt({onSelect:e,trailing:t,className:r}){let[o,n]=useState(null),[i,a]=useState(null),l=useCallback(p=>{n(p),a(null),e?.({categorySlug:p,tagSlug:null});},[e]),s=useCallback(p=>{a(p),e?.({categorySlug:o,tagSlug:p});},[o,e]),c=Yn(mt),d=mt.find(p=>p.slug===o),u=qn(d);return jsx(qt,{categories:c,selectedCategory:o,selectedTag:i,activeTags:u,onCategorySelect:l,onTagSelect:s,trailing:t,className:r})}function Qt(e){return {title:e.title,imageUrl:e.image_url}}function Zt(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 Ie=48,ft=4,Ve={ONE_MINUTE:1,ONE_HOUR:60,ONE_DAY:1440},X={ONE_DAY:"1d",ONE_WEEK:"1w",ONE_MONTH:"1m",ALL:"all"},Ye=X.ALL,Pl={[X.ONE_DAY]:Ve.ONE_MINUTE,[X.ONE_WEEK]:Ve.ONE_HOUR,[X.ONE_MONTH]:Ve.ONE_HOUR,[X.ALL]:Ve.ONE_DAY},El={[X.ONE_DAY]:300,[X.ONE_WEEK]:3600,[X.ONE_MONTH]:10800,[X.ALL]:1440*60},Nl={[X.ONE_DAY]:1440*60,[X.ONE_WEEK]:10080*60,[X.ONE_MONTH]:720*60*60,[X.ALL]:null},gt=1,wl=1,Cl=1,Tl=99,xe={ONE_HOUR:"1h",SIX_HOURS:"6h",ONE_DAY:"1d",ONE_WEEK:"1w",MAX:"max"},Ml=xe.ONE_WEEK,Rl={[xe.ONE_HOUR]:60,[xe.SIX_HOURS]:60,[xe.ONE_DAY]:300,[xe.ONE_WEEK]:1800,[xe.MAX]:1800};function oo(){let e={startVelocity:30,spread:360,ticks:60,zIndex:9999};xt({...e,particleCount:80,origin:{x:.5,y:.4}}),setTimeout(()=>{xt({...e,particleCount:40,origin:{x:.3,y:.6}});},150),setTimeout(()=>{xt({...e,particleCount:40,origin:{x:.7,y:.6}});},300);}function Jt({market:e,chain:t="solana",initialOutcome:r="yes",initialSide:o="buy"}){let{t:n}=useTranslation(),{status:i}=useAuth(),l=useWallets().find(M=>M.chainNamespace===ChainNamespace.SOLANA&&M.isConnected),s=i==="authenticated",c=l?.address,d=e.source,[u,p]=useState(r),[f,m]=useState(o),[g,x]=useState(NaN),[h,I]=useState(false),[D,E]=useState(null),C=useMemo(()=>{let M=u==="yes"?0:1,F=e.outcomes[M];return f==="buy"?F?.best_ask??F?.price??.5:F?.best_bid??F?.price??.5},[e.outcomes,u,f]),H=useMemo(()=>isNaN(g)||g<=0?0:f==="buy"?C>0?g/C:0:g,[f,g,C]),G=useMemo(()=>isNaN(g)||g<=0?"0":String(Math.round(g*1e6)),[g]),Me=e.provider_meta?.["dflow.yesMint"]??"",Re=e.provider_meta?.["dflow.noMint"]??"",ge=e.provider_meta?.["dflow.collateralMint"]??"",N=u==="yes"?Me:Re,Z=f==="buy"?ge:N,re=f==="buy"?N:ge,Le=!!Z&&!!re&&!!c&&G!=="0",{refetch:ve}=useDFlowQuote({inputMint:Z,outputMint:re,amount:G,userPublicKey:c??"",slippageBps:100},{enabled:Le}),{data:J,isLoading:y}=usePositions({source:d,user:c??""},{enabled:!!c}),P=useMemo(()=>J&&J.positions.reduce((F,le)=>le.side==="USDC"||le.side==="collateral"?F+(le.current_value??0):F,0)||null,[J]),T=useMemo(()=>J?J.positions.find(F=>F.side?.toLowerCase()==="yes"&&F.market?.slug===e.slug)?.size??0:null,[J,e.slug]),U=useMemo(()=>J?J.positions.find(F=>F.side?.toLowerCase()==="no"&&F.market?.slug===e.slug)?.size??0:null,[J,e.slug]),W=useMemo(()=>{if(isNaN(g)||g<=0)return 0;if(f==="buy")return g;let M=u==="yes"?e.outcomes[0]?.best_bid??0:e.outcomes[1]?.best_bid??0;return g*M},[f,u,g,e.outcomes]),q=useMemo(()=>isNaN(g)||g<=0?0:f==="buy"?H*1:W,[f,H,W,g]),Oe=q-W,An=useCallback(M=>{m(M),x(NaN);},[]),Dn=useCallback(M=>{if(isNaN(M)){x(NaN);return}let F=Math.max(0,M),le=f==="buy"?Math.round(F*100)/100:Math.round(F);x(le);},[f]),ut=useMemo(()=>{let M=[];(isNaN(g)||g<gt)&&M.push(`Minimum quantity is ${gt}`),e.status!=="open"&&M.push("Market is not active"),f==="buy"&&P!=null&&!isNaN(g)&&g>0&&g>P&&M.push("Insufficient USDC balance");let F=u==="yes"?T:U;return f==="sell"&&F!=null&&!isNaN(g)&&g>0&&g>F&&M.push("Insufficient shares"),{isValid:M.length===0,errors:M}},[g,e.status,f,P,T,U,u]),{mutateAsync:Wt}=useDFlowSubmit(),{data:pt}=useOrder({id:D??"",source:d},{enabled:!!D});useEffect(()=>{if(!pt||!D)return;let{status:M}=pt;M==="closed"?(I(false),E(null),toast.success(n("predict.trade.submitSuccess")),oo(),x(NaN)):(M==="failed"||M==="expired")&&(I(false),E(null),toast.error(n("predict.trade.submitError")));},[pt,D,n]);let Hn=useCallback(async()=>{if(!(!ut.isValid||!s||!c||!l)){I(true),E(null);try{let le=(await ve()).data?.transaction;if(!le){toast.error(n("predict.trade.submitError")),I(!1);return}let zt=Uint8Array.from(atob(le),Bn=>Bn.charCodeAt(0)),Fn=await l.sendTransaction(zt);await Wt({signedTransaction:btoa(String.fromCharCode(...zt)),orderContext:{user_public_key:c,input_mint:Z,output_mint:re,amount:G,price:String(C),side:f==="buy"?"BUY":"SELL",outcome:u==="yes"?"YES":"NO",market_slug:e.slug,slippage_bps:100}}),E(Fn);}catch{toast.error(n("predict.trade.submitError")),I(false);}}},[ut.isValid,s,c,l,ve,Wt,Z,re,G,C,f,u,e.slug,n]);return {outcome:u,side:f,quantity:g,estimatedCost:W,potentialPayout:q,potentialProfit:Oe,usdcBalance:P,yesTokenBalance:T,noTokenBalance:U,isBalanceLoading:y,isSubmitting:h,validation:ut,setOutcome:p,setSide:An,setQuantity:Dn,submit:Hn}}var po=`https://s1.chainstream.io/chains/sol/tokens/${SOLANA_TOKENS.stablecoins.USDC.address}/image.png`;function rr({event:e,market:t,outcome:r,side:o,quantity:n,potentialProfit:i,estimatedCost:a,usdcBalance:l,yesTokenBalance:s,noTokenBalance:c,isBalanceLoading:d,isSubmitting:u,isValid:p,onOutcomeChange:f,onSideChange:m,onQuantityChange:g,onSubmit:x}){let{t:h}=useTranslation(),[I,D]=useState("market"),[E,C]=useState(false),H=useMemo(()=>{let N=o==="buy"?r==="yes"?t.yesAsk:t.noAsk:r==="yes"?t.yesBid:t.noBid;return N!=null?Math.round(Number(N)*100):null},[o,r,t]),G=useMemo(()=>{if(u)return h("predict.trade.submitting");if(!n||isNaN(n)||n<=0)return h("predict.trade.enterAmount");let N=h(o==="buy"?"predict.trade.buy":"predict.trade.sell"),Z=h(r==="yes"?"predict.trade.yes":"predict.trade.no");return `${N} ${Z}`},[u,n,o,r,h]),Me=useMemo(()=>r==="yes"?"primary":"secondary",[r]),Re=()=>{g(Math.floor((l??0)/2*100)/100);},ge=()=>{g(l??0);};return 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:[h(o==="buy"?"predict.trade.buy":"predict.trade.sell")," ",h(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:[jsxs(Tabs,{variant:"underlined",selectedKey:I,onSelectionChange:N=>D(N),classNames:{tabList:"gap-x-4",tab:"px-0"},children:[jsx(Tab,{title:h("predict.trade.market")},"market"),jsx(Tab,{title:h("predict.trade.limit")},"limit")]}),H!=null&&jsxs("span",{className:"text-xl font-bold tabular-nums",children:[H," \xA2"]})]}),jsxs(Tabs,{variant:"underlined",selectedKey:o,onSelectionChange:N=>m(N),classNames:{tabList:"gap-x-4",tab:"px-0"},children:[jsx(Tab,{title:h("predict.trade.buy")},"buy"),jsx(Tab,{title:h("predict.trade.sell")},"sell")]}),jsx("div",{className:"flex gap-x-2",children:["yes","no"].map(N=>{let Z=N==="yes"?s:c;return jsxs("div",{className:"flex flex-1 flex-col gap-y-1",children:[jsxs("button",{type:"button",onClick:()=>f(N),className:`w-full rounded-lg border py-2 text-sm font-medium transition-colors cursor-pointer ${r===N?N==="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:h(N==="yes"?"predict.trade.yes":"predict.trade.no")}),(()=>{let re=o==="buy"?N==="yes"?t.yesAsk:t.noAsk:N==="yes"?t.yesBid:t.noBid;return re!=null?jsxs("span",{className:"ml-1 opacity-70",children:[Math.round(Number(re)*100),"\xA2"]}):null})()]}),o==="sell"&&r===N&&jsx("span",{className:"text-center text-xs text-foreground",children:d?"\u2013":`${Z??0} shares`})]},N)})}),o==="buy"&&jsxs("div",{className:"flex items-center justify-between text-xs text-neutral-500",children:[jsx("span",{children:h("predict.trade.youArePaying")}),jsxs("div",{className:"flex items-center gap-x-2",children:[jsx("img",{src:po,alt:"USDC",className:"h-3.5 w-3.5 rounded-full object-cover"}),jsx("span",{className:"font-medium text-foreground tabular-nums",children:l!=null?`${l.toFixed(6)} USDC`:"\u2013"}),jsx("button",{type:"button",onClick:Re,className:"rounded px-1.5 py-0.5 bg-content2 hover:bg-content3 transition-colors cursor-pointer text-foreground font-medium",children:h("predict.trade.half")}),jsx("button",{type:"button",onClick:ge,className:"rounded px-1.5 py-0.5 bg-content2 hover:bg-content3 transition-colors cursor-pointer text-foreground font-medium",children:h("predict.trade.max")})]})]}),jsxs("div",{className:"flex flex-col gap-y-1.5",children:[jsx("span",{className:"text-sm font-medium text-foreground",children:h(o==="buy"?"predict.trade.amount":"predict.trade.contracts")}),jsx(StyledNumberInput,{fullWidth:true,placeholder:"0",radius:"lg",size:"lg",value:isNaN(n)?void 0:n,onValueChange:N=>{g(N);},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(N=>jsxs("button",{type:"button",onClick:()=>{g(Math.floor((r==="yes"?s??0:c??0)*N/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:[N,"%"]},N)),jsx("button",{type:"button",onClick:()=>{g(r==="yes"?s??0:c??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:h("common.all")})]})]}),!isNaN(n)&&n>0&&jsxs("div",{className:"flex flex-col items-end gap-y-0.5",children:[jsx("span",{className:"text-sm text-foreground",children:h(o==="buy"?"predict.trade.potentialWin":"predict.trade.estimatedReceive")}),jsxs("span",{className:"text-xl font-semibold text-bullish",children:["$",(o==="buy"?i:a).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:()=>C(N=>!N),className:"flex items-center gap-x-1 text-neutral-500 hover:text-foreground cursor-pointer transition-colors",children:[jsx("span",{children:h("predict.trade.odds")}),jsx(ChevronDownIcon,{className:cn$1("h-3.5 w-3.5 transition-transform",E&&"rotate-180")})]}),H!=null&&jsxs("span",{className:"text-foreground font-medium tabular-nums",children:[H,"% chance"]})]}),E&&jsxs("div",{className:"flex items-center justify-between text-xs text-neutral-500",children:[jsxs("span",{children:[h("predict.trade.bestBid"),":"," ",Math.round((t.yesBid??0)*100),"\xA2"]}),jsxs("span",{children:[h("predict.trade.bestAsk"),":"," ",Math.round((t.yesAsk??0)*100),"\xA2"]})]})]}),jsx(Button,{color:Me,fullWidth:true,radius:"lg",size:"lg",isDisabled:!p||u||!n||isNaN(n)||n<=0,isLoading:u,onPress:x,children:G})]})}function Ge({event:e,market:t,initialSide:r,initialOutcome:o,chain:n}){let{outcome:i,side:a,quantity:l,estimatedCost:s,potentialPayout:c,potentialProfit:d,usdcBalance:u,yesTokenBalance:p,noTokenBalance:f,isBalanceLoading:m,isSubmitting:g,validation:x,setOutcome:h,setSide:I,setQuantity:D,submit:E}=Jt({market:t,initialSide:r,initialOutcome:o,chain:n}),C=useAuthCallback(E),H=useMemo(()=>e?Qt(e):void 0,[e]),G=useMemo(()=>Zt(t),[t]);return jsx(rr,{event:H,market:G,outcome:i,side:a,quantity:l,estimatedCost:s,potentialPayout:c,potentialProfit:d,usdcBalance:u,yesTokenBalance:p,noTokenBalance:f,isBalanceLoading:m,isSubmitting:g,isValid:x.isValid,validationErrors:x.errors,onOutcomeChange:h,onSideChange:I,onQuantityChange:D,onSubmit:C})}var bt="predict-trade";function or({id:e=bt}){return jsx(AsyncModal,{id:e,children:t=>jsx(yo,{...t})})}function yo({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(Ge,{event:e.event,market:e.market,initialOutcome:e.initialOutcome,initialSide:"buy",chain:e.chain})})})}):null}var yt={sortPreset:"volume",sortAsc:false,source:"dflow",timeRemaining:void 0,minVolume:void 0,minLiquidity:void 0};function St(e){let t=0;return e.source&&t++,e.timeRemaining&&t++,e.minVolume&&t++,e.minLiquidity&&t++,t}function ar({isOpen:e,onClose:t,value:r,onChange:o}){let{t:n}=useTranslation(),[i,a]=useState(r),l=useCallback(x=>{x?a(r):t();},[r,t]),s=useCallback(()=>{a(yt);},[]),c=useCallback(()=>{o(i),t();},[i,o,t]),d=useCallback((x,h)=>{a(I=>({...I,[x]:h}));},[]),u=useMemo(()=>St(i),[i]),p=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]),m=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:l,size:"md",scrollBehavior:"inside",children:jsxs(ModalContent,{children:[jsx(ModalHeader,{className:"px-4 py-2",children:jsx("span",{className:"text-base font-semibold",children:n("predict.filter.title")})}),jsxs(ModalBody,{className:"flex flex-col gap-5",children:[jsx(Qe,{label:n("predict.filter.platform"),children:jsx(Ze,{options:p,selected:i.source,onSelect:x=>d("source",x)})}),jsx(Qe,{label:n("predict.filter.timeRemaining"),children:jsx(Ze,{options:f,selected:i.timeRemaining,onSelect:x=>d("timeRemaining",x)})}),jsx(Qe,{label:n("predict.filter.minVolume"),children:jsx(Ze,{options:m,selected:i.minVolume,onSelect:x=>d("minVolume",x)})}),jsx(Qe,{label:n("predict.filter.minLiquidity"),children:jsx(Ze,{options:g,selected:i.minLiquidity,onSelect:x=>d("minLiquidity",x)})})]}),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:s,children:n("predict.filter.reset")}),jsxs(Button,{color:"primary",size:"sm",radius:"full",onPress:c,children:[n("predict.filter.showResults"),u>0&&jsxs("span",{className:"ml-1 text-xs opacity-80",children:["(",u,")"]})]})]})})]})})}function Qe({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 Ze({options:e,selected:t,onSelect:r,allowDeselect:o=true}){return jsx("div",{className:"flex flex-wrap gap-2",children:e.map(n=>{let i=t===n.value;return jsx("button",{type:"button",onClick:()=>{r(i&&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",i?"bg-primary/15 text-primary border-primary/40":"bg-content2 text-foreground/60 border-default-100 hover:bg-default-100 hover:text-foreground"),children:n.label},n.value??"__all")})})}var dr={start_time:{sort_by:"created_at"},volume:{sort_by:"volume"},liquidity:{sort_by:"liquidity"},ending_soon:{sort_by:"end_at"}},lr={start_time:"predict.sort.startTime",volume:"predict.sort.volume",liquidity:"predict.sort.liquidity",ending_soon:"predict.sort.endingSoon"},Uo=["start_time","volume","liquidity","ending_soon"];function ur({sortPreset:e,onSortChange:t,sortAsc:r,onSortAscChange:o,onFilterPress:n,filterCount:i=0,className:a}){let{t:l}=useTranslation(),[s,c]=useState(false),d=useRef(null);useEffect(()=>{if(!s)return;let p=m=>{d.current&&!d.current.contains(m.target)&&c(false);},f=m=>{m.key==="Escape"&&c(false);};return document.addEventListener("mousedown",p),document.addEventListener("keydown",f),()=>{document.removeEventListener("mousedown",p),document.removeEventListener("keydown",f);}},[s]);let u=cr[e];return jsxs("div",{className:cn$1("flex items-center gap-2",a),children:[jsxs("div",{ref:d,className:"relative flex shrink-0 items-center rounded-full border border-border",children:[jsxs("button",{type:"button",onClick:()=>c(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(u,{className:"size-[18px] shrink-0"}),jsx("span",{className:"whitespace-nowrap",children:l(lr[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"}),s&&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:Uo.map(p=>{let f=cr[p];return jsxs("button",{type:"button",onClick:()=>{t(p),c(false);},className:cn$1("flex w-full items-center gap-2 rounded px-2.5 py-1.5 text-xs font-medium transition-colors cursor-pointer",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:l(lr[p])})]},p)})})]}),jsx(StyledBadge,{content:i>0?i:void 0,color:"primary",size:"sm",isInvisible:i===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:l("predict.filter.title")})]})})]})}var cr={start_time:CalendarIcon,volume:ChartLineIcon,liquidity:DropletIcon,ending_soon:TimerIcon};function fr(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:i,isError:a,error:l,hasNextPage:s,fetchNextPage:c,refetch:d}=useInfiniteEvents(t),u=useMemo(()=>r?.pages.flatMap(m=>m.items).filter(m=>m!=null)??[],[r]),p=useCallback(()=>{c();},[c]),f=useCallback(()=>{d();},[d]);return {data:u,isLoading:o,isFetching:n&&!i,isFetchingMore:i,isError:a,error:l??null,hasMore:s??false,fetchMore:p,refetch:f}}function kt({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 yc({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(kt,{count:e})})]})}var gr=3,Et={bg:"hsl(var(--heroui-primary) / 0.14)",text:"hsl(var(--heroui-primary))",shadow:"hsl(var(--heroui-primary) / 0.18)"},Sr={bg:"hsl(var(--heroui-secondary) / 0.14)",text:"hsl(var(--heroui-secondary))",shadow:"hsl(var(--heroui-secondary) / 0.18)"},Go={bg:"rgba(239, 68, 68, 0.14)",text:"rgb(239, 68, 68)",shadow:"rgba(239, 68, 68, 0.18)"},He=[{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 vr(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 Xo(e){let t=e.outcomes?.map(a=>a.label?.toLowerCase().trim()??"")??[];if(t.some(a=>a==="up")&&t.some(a=>a==="down"))return [Et,Go];if(t.some(a=>a==="yes")&&t.some(a=>a==="no"))return [Et,Sr];let r=t[0]??"",o=t[1]??"",n=vr(r)%He.length,i=vr(o)%He.length;return i===n&&(i=(i+1)%He.length),[He[n],He[i]]}function Qo(e){let t=e.outcomes?.[0];return t?t.best_ask??t.price??null:null}function kr(e){let t=Qo(e);return t!=null?Math.round(t*100):0}function Pr(e){return e<=1&&e>0?"< 1%":e>=99&&e<100?"> 99%":`${e}%`}function xr(e){let t=e.outcomes?.[0];return ((t?.best_ask??t?.price??0)*100).toFixed(1)}function hr(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 Zo(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),i=[];return r>0&&i.push(`${r}d`),o>0&&i.push(`${o}h`),i.push(`${n}m`),i.join(" ")}var Jo=`
|
|
1
|
+
import {memo,useRef,createContext,useCallback,useState,useMemo,useEffect,Fragment as Fragment$1,Component}from'react';import {cn as cn$1,Skeleton,toast,Tabs,Tab,StyledNumberInput,ChevronDownIcon,Button,useScreen,StyledModal,ModalContent,ModalBody,ModalHeader,ModalFooter,RefreshIcon,TimerIcon,DropletIcon,ChartLineIcon,CalendarIcon,StyledBadge,FilterIcon,Linkable,Avatar,ChevronUpIcon,PolymarketIcon,KalshiIcon,Spinner,useDisclosure,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 {useAuth,useWallets,useAuthCallback}from'@liberfi.io/wallet-connector';import kt from'canvas-confetti';import {ChartRange,useDFlowQuote,usePositions,useDFlowSubmit,useOrder,resolveEventsParams,useInfiniteEvents,useInfiniteOrders,useCancelOrder,useInfiniteTrades,useOrderbook,useMarketHistory,useEvent,useSimilarEvents,usePredictClient,candlesticksQueryKey,useSearchEvents,useBalance}from'@liberfi.io/react-predict';export{PredictClient,PredictContext,PredictProvider,PredictWsClient,createPredictClient,createPredictWsClient,useBalance,useCancelOrder,useCandlesticks,useDFlowQuote,useDFlowSubmit,useEvent,useEvents,useInfiniteEvents,useMarket,useMarketHistory,useMarketTrades,useOrder,useOrderbook,useOrders,usePositions,usePredictClient,usePriceHistory,useSearchEvents,useSimilarEvents,useTrades}from'@liberfi.io/react-predict';import {ChainNamespace}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 {useQueries}from'@tanstack/react-query';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.82");var qn="0.1.82";var Gn={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},er=["Politics","Sports","Crypto","Economics","Financials","Elections","Entertainment","Companies","Science and Technology","Climate and Weather","Mentions","Social","World"],bt=(()=>{let e=t=>{let r=er.indexOf(t);return r===-1?er.length:r};return Object.entries(Gn).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 nr({categories:e,selectedCategory:t,selectedTag:r,activeTags:o,onCategorySelect:n,onTagSelect:a,trailing:i,pulsingTab:s="Trending",className:l}){let{t:c}=useTranslation(),d=useCallback(()=>{n(null);},[n]),u=c("predict.categories.trending");return jsxs("div",{className:cn$1("sticky top-0 z-30 flex w-full flex-col justify-between gap-2 px-4 py-1 lg:px-2 lg:py-1",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:u,isSelected:t===null,onPress:d,showPulse:u===s}),jsx(Jn,{}),e.map(f=>jsx(tr,{label:f.category,isSelected:t===f.category,onPress:()=>n(f.category),badge:f.badge,showPulse:f.category===s},f.category))]})}),i&&jsx("div",{className:"flex-shrink-0",children:i})]}),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(rr,{label:c("predict.categories.allMarkets"),isSelected:r===null,onPress:()=>a(null)}),o.map(f=>jsx(rr,{label:f.label,icon:f.icon,isSelected:r===f.label,onPress:()=>a(f.label)},f.label))]})})]})}function tr({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 Jn(){return jsx("span",{className:"flex items-center text-neutral-600","aria-hidden":"true",children:"|"})}function rr({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 El({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 eo(e){return e.map(t=>({category:t.label,tags:t.tags.map(r=>r.label)}))}function to(e){return e?e.tags.map(t=>({label:t.label,icon:t.icon})):[]}function ir({onSelect:e,trailing:t,className:r}){let[o,n]=useState(null),[a,i]=useState(null),s=useCallback(f=>{n(f),i(null),e?.({categorySlug:f,tagSlug:null});},[e]),l=useCallback(f=>{i(f),e?.({categorySlug:o,tagSlug:f});},[o,e]),c=eo(bt),d=bt.find(f=>f.slug===o),u=to(d);return jsx(nr,{categories:c,selectedCategory:o,selectedTag:a,activeTags:u,onCategorySelect:s,onTagSelect:l,trailing:t,className:r})}function ar(e){return {title:e.title,imageUrl:e.image_url}}function lr(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 _e=48,yt=4,Xe={ONE_MINUTE:1,ONE_HOUR:60,ONE_DAY:1440},J={ONE_DAY:"1d",ONE_WEEK:"1w",ONE_MONTH:"1m",ALL:"all"},Qe=J.ALL,Al={[J.ONE_DAY]:Xe.ONE_MINUTE,[J.ONE_WEEK]:Xe.ONE_HOUR,[J.ONE_MONTH]:Xe.ONE_HOUR,[J.ALL]:Xe.ONE_DAY},Dl={[J.ONE_DAY]:300,[J.ONE_WEEK]:3600,[J.ONE_MONTH]:10800,[J.ALL]:1440*60},Hl={[J.ONE_DAY]:1440*60,[J.ONE_WEEK]:10080*60,[J.ONE_MONTH]:720*60*60,[J.ALL]:null},St=1,Fl=1,Bl=1,Ul=99,be={ONE_HOUR:"1h",SIX_HOURS:"6h",ONE_DAY:"1d",ONE_WEEK:"1w",MAX:"max"},$l=be.ONE_WEEK,Wl={[be.ONE_HOUR]:60,[be.SIX_HOURS]:60,[be.ONE_DAY]:300,[be.ONE_WEEK]:1800,[be.MAX]:1800};function mo(){let e={startVelocity:30,spread:360,ticks:60,zIndex:9999};kt({...e,particleCount:80,origin:{x:.5,y:.4}}),setTimeout(()=>{kt({...e,particleCount:40,origin:{x:.3,y:.6}});},150),setTimeout(()=>{kt({...e,particleCount:40,origin:{x:.7,y:.6}});},300);}function cr({market:e,chain:t="solana",initialOutcome:r="yes",initialSide:o="buy"}){let{t:n}=useTranslation(),{status:a}=useAuth(),s=useWallets().find(L=>L.chainNamespace===ChainNamespace.SOLANA&&L.isConnected),l=a==="authenticated",c=s?.address,d=e.source,[u,f]=useState(r),[p,m]=useState(o),[g,x]=useState(NaN),[v,_]=useState(false),[M,N]=useState(null),C=useMemo(()=>{let L=u==="yes"?0:1,U=e.outcomes[L];return p==="buy"?U?.best_ask??U?.price??.5:U?.best_bid??U?.price??.5},[e.outcomes,u,p]),B=useMemo(()=>isNaN(g)||g<=0?0:p==="buy"?C>0?g/C:0:g,[p,g,C]),Z=useMemo(()=>isNaN(g)||g<=0?"0":String(Math.round(g*1e6)),[g]),Re=e.provider_meta?.["dflow.yesMint"]??"",Le=e.provider_meta?.["dflow.noMint"]??"",xe=e.provider_meta?.["dflow.collateralMint"]??"",P=u==="yes"?Re:Le,te=p==="buy"?xe:P,se=p==="buy"?P:xe,Ie=!!te&&!!se&&!!c&&Z!=="0",{refetch:he}=useDFlowQuote({inputMint:te,outputMint:se,amount:Z,userPublicKey:c??"",slippageBps:100},{enabled:Ie}),{data:re,isLoading:y}=usePositions({source:d,user:c??""},{enabled:!!c}),k=useMemo(()=>re&&re.positions.reduce((U,ue)=>ue.side==="USDC"||ue.side==="collateral"?U+(ue.current_value??0):U,0)||null,[re]),R=useMemo(()=>re?re.positions.find(U=>U.side?.toLowerCase()==="yes"&&U.market?.slug===e.slug)?.size??0:null,[re,e.slug]),W=useMemo(()=>re?re.positions.find(U=>U.side?.toLowerCase()==="no"&&U.market?.slug===e.slug)?.size??0:null,[re,e.slug]),K=useMemo(()=>{if(isNaN(g)||g<=0)return 0;if(p==="buy")return g;let L=u==="yes"?e.outcomes[0]?.best_bid??0:e.outcomes[1]?.best_bid??0;return g*L},[p,u,g,e.outcomes]),X=useMemo(()=>isNaN(g)||g<=0?0:p==="buy"?B*1:K,[p,B,K,g]),Oe=X-K,zn=useCallback(L=>{m(L),x(NaN);},[]),Kn=useCallback(L=>{if(isNaN(L)){x(NaN);return}let U=Math.max(0,L),ue=p==="buy"?Math.round(U*100)/100:Math.round(U);x(ue);},[p]),xt=useMemo(()=>{let L=[];(isNaN(g)||g<St)&&L.push(`Minimum quantity is ${St}`),e.status!=="open"&&L.push("Market is not active"),p==="buy"&&k!=null&&!isNaN(g)&&g>0&&g>k&&L.push("Insufficient USDC balance");let U=u==="yes"?R:W;return p==="sell"&&U!=null&&!isNaN(g)&&g>0&&g>U&&L.push("Insufficient shares"),{isValid:L.length===0,errors:L}},[g,e.status,p,k,R,W,u]),{mutateAsync:Zt}=useDFlowSubmit(),{data:ht}=useOrder({id:M??"",source:d},{enabled:!!M});useEffect(()=>{if(!ht||!M)return;let{status:L}=ht;L==="closed"?(_(false),N(null),toast.success(n("predict.trade.submitSuccess")),mo(),x(NaN)):(L==="failed"||L==="expired")&&(_(false),N(null),toast.error(n("predict.trade.submitError")));},[ht,M,n]);let Vn=useCallback(async()=>{if(!(!xt.isValid||!l||!c||!s)){_(true),N(null);try{let ue=(await he()).data?.transaction;if(!ue){toast.error(n("predict.trade.submitError")),_(!1);return}let Jt=Uint8Array.from(atob(ue),jn=>jn.charCodeAt(0)),Yn=await s.sendTransaction(Jt);await Zt({signedTransaction:btoa(String.fromCharCode(...Jt)),orderContext:{user_public_key:c,input_mint:te,output_mint:se,amount:Z,price:String(C),side:p==="buy"?"BUY":"SELL",outcome:u==="yes"?"YES":"NO",market_slug:e.slug,slippage_bps:100}}),N(Yn);}catch{toast.error(n("predict.trade.submitError")),_(false);}}},[xt.isValid,l,c,s,he,Zt,te,se,Z,C,p,u,e.slug,n]);return {outcome:u,side:p,quantity:g,estimatedCost:K,potentialPayout:X,potentialProfit:Oe,usdcBalance:k,yesTokenBalance:R,noTokenBalance:W,isBalanceLoading:y,isSubmitting:v,validation:xt,setOutcome:f,setSide:zn,setQuantity:Kn,submit:Vn}}var yo=`https://s1.chainstream.io/chains/sol/tokens/${SOLANA_TOKENS.stablecoins.USDC.address}/image.png`;function pr({event:e,market:t,outcome:r,side:o,quantity:n,potentialProfit:a,estimatedCost:i,usdcBalance:s,yesTokenBalance:l,noTokenBalance:c,isBalanceLoading:d,isSubmitting:u,isValid:f,onOutcomeChange:p,onSideChange:m,onQuantityChange:g,onSubmit:x}){let{t:v}=useTranslation(),[_,M]=useState("market"),[N,C]=useState(false),B=useMemo(()=>{let P=o==="buy"?r==="yes"?t.yesAsk:t.noAsk:r==="yes"?t.yesBid:t.noBid;return P!=null?Math.round(Number(P)*100):null},[o,r,t]),Z=useMemo(()=>{if(u)return v("predict.trade.submitting");if(!n||isNaN(n)||n<=0)return v("predict.trade.enterAmount");let P=v(o==="buy"?"predict.trade.buy":"predict.trade.sell"),te=v(r==="yes"?"predict.trade.yes":"predict.trade.no");return `${P} ${te}`},[u,n,o,r,v]),Re=useMemo(()=>r==="yes"?"primary":"secondary",[r]),Le=()=>{g(Math.floor((s??0)/2*100)/100);},xe=()=>{g(s??0);};return 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:[v(o==="buy"?"predict.trade.buy":"predict.trade.sell")," ",v(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:[jsxs(Tabs,{variant:"underlined",selectedKey:_,onSelectionChange:P=>M(P),classNames:{tabList:"gap-x-4",tab:"px-0"},children:[jsx(Tab,{title:v("predict.trade.market")},"market"),jsx(Tab,{title:v("predict.trade.limit")},"limit")]}),B!=null&&jsxs("span",{className:"text-xl font-bold tabular-nums",children:[B," \xA2"]})]}),jsxs(Tabs,{variant:"underlined",selectedKey:o,onSelectionChange:P=>m(P),classNames:{tabList:"gap-x-4",tab:"px-0"},children:[jsx(Tab,{title:v("predict.trade.buy")},"buy"),jsx(Tab,{title:v("predict.trade.sell")},"sell")]}),jsx("div",{className:"flex gap-x-2",children:["yes","no"].map(P=>{let te=P==="yes"?l:c;return jsxs("div",{className:"flex flex-1 flex-col gap-y-1",children:[jsxs("button",{type:"button",onClick:()=>p(P),className:`w-full rounded-lg border py-2 text-sm font-medium transition-colors cursor-pointer ${r===P?P==="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:v(P==="yes"?"predict.trade.yes":"predict.trade.no")}),(()=>{let se=o==="buy"?P==="yes"?t.yesAsk:t.noAsk:P==="yes"?t.yesBid:t.noBid;return se!=null?jsxs("span",{className:"ml-1 opacity-70",children:[Math.round(Number(se)*100),"\xA2"]}):null})()]}),o==="sell"&&r===P&&jsx("span",{className:"text-center text-xs text-foreground",children:d?"\u2013":`${te??0} shares`})]},P)})}),o==="buy"&&jsxs("div",{className:"flex items-center justify-between text-xs text-neutral-500",children:[jsx("span",{children:v("predict.trade.youArePaying")}),jsxs("div",{className:"flex items-center gap-x-2",children:[jsx("img",{src:yo,alt:"USDC",className:"h-3.5 w-3.5 rounded-full object-cover"}),jsx("span",{className:"font-medium text-foreground tabular-nums",children:s!=null?`${s.toFixed(6)} USDC`:"\u2013"}),jsx("button",{type:"button",onClick:Le,className:"rounded px-1.5 py-0.5 bg-content2 hover:bg-content3 transition-colors cursor-pointer text-foreground font-medium",children:v("predict.trade.half")}),jsx("button",{type:"button",onClick:xe,className:"rounded px-1.5 py-0.5 bg-content2 hover:bg-content3 transition-colors cursor-pointer text-foreground font-medium",children:v("predict.trade.max")})]})]}),jsxs("div",{className:"flex flex-col gap-y-1.5",children:[jsx("span",{className:"text-sm font-medium text-foreground",children:v(o==="buy"?"predict.trade.amount":"predict.trade.contracts")}),jsx(StyledNumberInput,{fullWidth:true,placeholder:"0",radius:"lg",size:"lg",value:isNaN(n)?void 0:n,onValueChange:P=>{g(P);},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(P=>jsxs("button",{type:"button",onClick:()=>{g(Math.floor((r==="yes"?l??0:c??0)*P/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:[P,"%"]},P)),jsx("button",{type:"button",onClick:()=>{g(r==="yes"?l??0:c??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:v("common.all")})]})]}),!isNaN(n)&&n>0&&jsxs("div",{className:"flex flex-col items-end gap-y-0.5",children:[jsx("span",{className:"text-sm text-foreground",children:v(o==="buy"?"predict.trade.potentialWin":"predict.trade.estimatedReceive")}),jsxs("span",{className:"text-xl font-semibold text-bullish",children:["$",(o==="buy"?a:i).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:()=>C(P=>!P),className:"flex items-center gap-x-1 text-neutral-500 hover:text-foreground cursor-pointer transition-colors",children:[jsx("span",{children:v("predict.trade.odds")}),jsx(ChevronDownIcon,{className:cn$1("h-3.5 w-3.5 transition-transform",N&&"rotate-180")})]}),B!=null&&jsxs("span",{className:"text-foreground font-medium tabular-nums",children:[B,"% chance"]})]}),N&&jsxs("div",{className:"flex items-center justify-between text-xs text-neutral-500",children:[jsxs("span",{children:[v("predict.trade.bestBid"),":"," ",Math.round((t.yesBid??0)*100),"\xA2"]}),jsxs("span",{children:[v("predict.trade.bestAsk"),":"," ",Math.round((t.yesAsk??0)*100),"\xA2"]})]})]}),jsx(Button,{color:Re,fullWidth:true,radius:"lg",size:"lg",isDisabled:!f||u||!n||isNaN(n)||n<=0,isLoading:u,onPress:x,children:Z})]})}function et({event:e,market:t,initialSide:r,initialOutcome:o,chain:n}){let{outcome:a,side:i,quantity:s,estimatedCost:l,potentialPayout:c,potentialProfit:d,usdcBalance:u,yesTokenBalance:f,noTokenBalance:p,isBalanceLoading:m,isSubmitting:g,validation:x,setOutcome:v,setSide:_,setQuantity:M,submit:N}=cr({market:t,initialSide:r,initialOutcome:o,chain:n}),C=useAuthCallback(N),B=useMemo(()=>e?ar(e):void 0,[e]),Z=useMemo(()=>lr(t),[t]);return jsx(pr,{event:B,market:Z,outcome:a,side:i,quantity:s,estimatedCost:l,potentialPayout:c,potentialProfit:d,usdcBalance:u,yesTokenBalance:f,noTokenBalance:p,isBalanceLoading:m,isSubmitting:g,isValid:x.isValid,validationErrors:x.errors,onOutcomeChange:v,onSideChange:_,onQuantityChange:M,onSubmit:C})}var Pt="predict-trade";function fr({id:e=Pt}){return jsx(AsyncModal,{id:e,children:t=>jsx(To,{...t})})}function To({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(et,{event:e.event,market:e.market,initialOutcome:e.initialOutcome,initialSide:"buy",chain:e.chain})})})}):null}var Et={sortPreset:"volume",sortAsc:false,source:"dflow",timeRemaining:void 0,minVolume:void 0,minLiquidity:void 0};function Ct(e){let t=0;return e.source&&t++,e.timeRemaining&&t++,e.minVolume&&t++,e.minLiquidity&&t++,t}function vr({isOpen:e,onClose:t,value:r,onChange:o}){let{t:n}=useTranslation(),[a,i]=useState(r),s=useCallback(x=>{x?i(r):t();},[r,t]),l=useCallback(()=>{i(Et);},[]),c=useCallback(()=>{o(a),t();},[a,o,t]),d=useCallback((x,v)=>{i(_=>({..._,[x]:v}));},[]),u=useMemo(()=>Ct(a),[a]),f=useMemo(()=>[{value:void 0,label:n("predict.filter.all")},{value:"polymarket",label:n("predict.platform.polymarket")},{value:"dflow",label:n("predict.platform.dflow")}],[n]),p=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]),m=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:s,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(rt,{label:n("predict.filter.platform"),children:jsx(nt,{options:f,selected:a.source,onSelect:x=>d("source",x)})}),jsx(rt,{label:n("predict.filter.timeRemaining"),children:jsx(nt,{options:p,selected:a.timeRemaining,onSelect:x=>d("timeRemaining",x)})}),jsx(rt,{label:n("predict.filter.minVolume"),children:jsx(nt,{options:m,selected:a.minVolume,onSelect:x=>d("minVolume",x)})}),jsx(rt,{label:n("predict.filter.minLiquidity"),children:jsx(nt,{options:g,selected:a.minLiquidity,onSelect:x=>d("minLiquidity",x)})})]}),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:c,children:[n("predict.filter.showResults"),u>0&&jsxs("span",{className:"ml-1 text-xs opacity-80",children:["(",u,")"]})]})]})})]})})}function rt({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 nt({options:e,selected:t,onSelect:r,allowDeselect:o=true}){return jsx("div",{className:"flex flex-wrap gap-2",children:e.map(n=>{let a=t===n.value;return jsx("button",{type:"button",onClick:()=>{r(a&&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",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:n.label},n.value??"__all")})})}var yr={start_time:{sort_by:"created_at"},volume:{sort_by:"volume"},liquidity:{sort_by:"liquidity"},ending_soon:{sort_by:"end_at"}},hr={start_time:"predict.sort.startTime",volume:"predict.sort.volume",liquidity:"predict.sort.liquidity",ending_soon:"predict.sort.endingSoon"},qo=["start_time","volume","liquidity","ending_soon"];function Sr({sortPreset:e,onSortChange:t,sortAsc:r,onSortAscChange:o,onFilterPress:n,filterCount:a=0,className:i}){let{t:s}=useTranslation(),[l,c]=useState(false),d=useRef(null);useEffect(()=>{if(!l)return;let f=m=>{d.current&&!d.current.contains(m.target)&&c(false);},p=m=>{m.key==="Escape"&&c(false);};return document.addEventListener("mousedown",f),document.addEventListener("keydown",p),()=>{document.removeEventListener("mousedown",f),document.removeEventListener("keydown",p);}},[l]);let u=br[e];return jsxs("div",{className:cn$1("flex items-center gap-2",i),children:[jsxs("div",{ref:d,className:"relative flex shrink-0 items-center rounded-full border border-border",children:[jsxs("button",{type:"button",onClick:()=>c(f=>!f),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:s(hr[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:qo.map(f=>{let p=br[f];return jsxs("button",{type:"button",onClick:()=>{t(f),c(false);},className:cn$1("flex w-full items-center gap-2 rounded px-2.5 py-1.5 text-xs font-medium transition-colors cursor-pointer",f===e?"bg-primary/10 text-primary":"text-neutral hover:bg-content2 hover:text-foreground"),children:[jsx(p,{className:"size-4 shrink-0"}),jsx("span",{children:s(hr[f])})]},f)})})]}),jsx(StyledBadge,{content:a>0?a:void 0,color:"primary",size:"sm",isInvisible:a===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:s("predict.filter.title")})]})})]})}var br={start_time:CalendarIcon,volume:ChartLineIcon,liquidity:DropletIcon,ending_soon:TimerIcon};function Nr(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:a,isError:i,error:s,hasNextPage:l,fetchNextPage:c,refetch:d}=useInfiniteEvents(t),u=useMemo(()=>r?.pages.flatMap(m=>m.items).filter(m=>m!=null)??[],[r]),f=useCallback(()=>{c();},[c]),p=useCallback(()=>{d();},[d]);return {data:u,isLoading:o,isFetching:n&&!a,isFetchingMore:a,isError:i,error:s??null,hasMore:l??false,fetchMore:f,refetch:p}}function Tt({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 Ic({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(Tt,{count:e})})]})}var Pr=3,Rt={bg:"hsl(var(--heroui-primary) / 0.14)",text:"hsl(var(--heroui-primary))",shadow:"hsl(var(--heroui-primary) / 0.18)"},Lr={bg:"hsl(var(--heroui-secondary) / 0.14)",text:"hsl(var(--heroui-secondary))",shadow:"hsl(var(--heroui-secondary) / 0.18)"},ns={bg:"rgba(239, 68, 68, 0.14)",text:"rgb(239, 68, 68)",shadow:"rgba(239, 68, 68, 0.18)"},Fe=[{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 Er(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 os(e){let t=e.outcomes?.map(i=>i.label?.toLowerCase().trim()??"")??[];if(t.some(i=>i==="up")&&t.some(i=>i==="down"))return [Rt,ns];if(t.some(i=>i==="yes")&&t.some(i=>i==="no"))return [Rt,Lr];let r=t[0]??"",o=t[1]??"",n=Er(r)%Fe.length,a=Er(o)%Fe.length;return a===n&&(a=(a+1)%Fe.length),[Fe[n],Fe[a]]}function ss(e){let t=e.outcomes?.[0];return t?t.best_ask??t.price??null:null}function Ir(e){let t=ss(e);return t!=null?Math.round(t*100):0}function Or(e){return e<=1&&e>0?"< 1%":e>=99&&e<100?"> 99%":`${e}%`}function Cr(e){let t=e.outcomes?.[0];return ((t?.best_ask??t?.price??0)*100).toFixed(1)}function Tr(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 is(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),a=[];return r>0&&a.push(`${r}d`),o>0&&a.push(`${o}h`),a.push(`${n}m`),a.join(" ")}var as=`
|
|
2
2
|
.badge-shine { position: relative; overflow: hidden; }
|
|
3
3
|
.badge-shine::after {
|
|
4
4
|
content: "";
|
|
@@ -16,7 +16,7 @@ import {memo,useRef,createContext,useCallback,useState,useMemo,useEffect,Fragmen
|
|
|
16
16
|
60% { transform: translate(200%); }
|
|
17
17
|
100% { transform: translate(200%); }
|
|
18
18
|
}
|
|
19
|
-
`;function Er({event:e,href:t,LinkComponent:r,onSelect:o,onSelectOutcome:n,onHover:i}){let[a,l]=useState(null),s=e.markets??[],c=useMemo(()=>s.length>2?[...s].sort((E,C)=>(C.outcomes?.[0]?.price??0)-(E.outcomes?.[0]?.price??0)):s,[s]),d=c.filter(E=>E.status==="open"),u=c.length===1,p=d.slice(0,gr),f=d.length-gr,m=useMemo(()=>`$${Math.round(e.volume??0).toLocaleString("en-US")}`,[e.volume]),g=a?d.find(E=>E.slug===a)??null:null,x=!!g||u,h=()=>{x||o?.(e);},I=E=>{E.stopPropagation(),g&&(E.preventDefault(),l(null));},D=E=>{E.stopPropagation(),t||(E.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",!x&&"cursor-pointer"),onMouseEnter:()=>i?.(e),onClick:h,children:[jsx("style",{children:Jo}),jsx(es,{event:e,href:t,LinkComponent:r,onClick:I,isExpanded:x}),jsx("div",{className:"flex flex-1 flex-col",children:u?jsx(ls,{market:d[0],event:e,formattedVolume:m,href:t,LinkComponent:r,onSelect:o,onSelectOutcome:n}):g?jsx(cs,{market:g,event:e,onCollapse:()=>l(null),onSelectOutcome:n}):jsx(as,{displayedMarkets:p,moreCount:f,formattedVolume:m,source:e.source,href:t,LinkComponent:r,onMarketClick:E=>l(E.slug),onShowMore:D})})]})}function es({event:e,href:t,LinkComponent:r,onClick:o,isExpanded:n}){let i=e.start_at?Zo(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}),i&&jsxs("span",{className:"text-[10px] leading-4 text-neutral-500",children:["Live in ",i]})]}),jsx(rs,{event:e})]})}function ts(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(),i=300*1e3,a=900*1e3;if(n>0&&n<=a){let l=n<=i?"#ef4444":"#f59e0b";t.push({kind:"crypto-short",label:n<=i?"5m":"15m",color:l});}}return o&&t.push({kind:"live"}),t.slice(0,2)}function rs({event:e}){let t=useMemo(()=>ts(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(ns,{},o);case "crypto-short":return jsx(os,{label:r.label,color:r.color},o);case "closed":return jsx(ss,{},o)}})})}function ns(){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 os({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 ss(){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 as({displayedMarkets:e,moreCount:t,formattedVolume:r,source:o,href:n,LinkComponent:i,onMarketClick:a,onShowMore:l}){let{t:s}=useTranslation();return jsxs(Fragment,{children:[e.length>0&&jsx("div",{className:"flex w-full flex-1 flex-col gap-y-0.5 lg:gap-y-2",children:e.map(c=>{let d=kr(c);return jsxs("button",{type:"button",className:"flex h-9 w-full items-center justify-between gap-x-2 transition-opacity hover:cursor-pointer hover:opacity-80",onClick:u=>{u.stopPropagation(),a(c);},children:[jsx("span",{className:"min-w-0 flex-1 text-left text-xs text-slate-200 line-clamp-1 lg:text-sm",children:c.outcomes?.[0]?.label??c.question}),jsxs("div",{className:"flex items-center gap-x-2",children:[jsx("span",{className:"text-sm font-semibold text-slate-200 lg:text-lg",children:Pr(d)}),jsx(is,{})]})]},c.slug)})}),jsxs("div",{className:"mt-auto flex items-center justify-between pt-3",children:[t>0?jsxs(Linkable,{href:n,LinkComponent:i,as:"button",className:"flex items-center gap-1 text-[10px] font-normal text-neutral-500 transition-colors hover:text-slate-200 cursor-pointer lg:text-xs",onClick:l,children:[s("predict.event.showMore"),jsx(wr,{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," ",s("predict.event.volume"),jsx(Cr,{source:o})]})]})]})}function br({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:l=>{let s=l.currentTarget;s.style.setProperty("--shadow-offset","2px"),s.style.transform="translateY(2px)";},onMouseLeave:l=>{let s=l.currentTarget;s.style.setProperty("--shadow-offset","4px"),s.style.transform="translateY(0px)";},onClick:o,children:n})}function Nr({market:e,event:t,onSelectOutcome:r,dynamicColors:o=false,labelFormat:n="action"}){let{t:i}=useTranslation(),[a,l]=o?Xo(e):[Et,Sr],s=e.outcomes?.[0]?.label?.toLowerCase().trim()??"",c=e.outcomes?.[1]?.label?.toLowerCase().trim()??"",d=n==="label"&&s===c?"action":n,u=d==="label"?`${e.outcomes?.[0]?.label??"Yes"} ${xr(e)}\xA2`:i("predict.market.action.yes",{price:xr(e)}),p=d==="label"?`${e.outcomes?.[1]?.label??"No"} ${hr(e)}\xA2`:i("predict.market.action.no",{price:hr(e)});return jsxs("div",{className:"flex gap-2",children:[jsx(br,{bgColor:a.bg,textColor:a.text,shadowColor:a.shadow,onClick:f=>{f.stopPropagation(),r?.(t,e,"yes");},children:u}),jsx(br,{bgColor:l.bg,textColor:l.text,shadowColor:l.shadow,onClick:f=>{f.stopPropagation(),r?.(t,e,"no");},children:p})]})}function is(){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 ls({market:e,event:t,formattedVolume:r,href:o,LinkComponent:n,onSelect:i,onSelectOutcome:a}){let{t:l}=useTranslation();return jsxs(Fragment,{children:[jsx("div",{className:"flex-1",children:jsx(Nr,{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:c=>{c.stopPropagation(),o||(c.preventDefault(),i?.(t));},children:[l("predict.event.viewEvent"),jsx(wr,{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," ",l("predict.event.volume"),jsx(Cr,{source:t.source})]})]})]})}function cs({market:e,event:t,onCollapse:r,onSelectOutcome:o}){let{t:n}=useTranslation(),i=kr(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:Pr(i)}),jsx(ChevronUpIcon,{className:"h-4 w-4 text-neutral-400"})]})]}),jsx("div",{className:"mt-3",children:jsx(Nr,{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(ds,{className:"h-3 w-3"}),n("predict.event.back")]})]})}function wr({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 ds({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 Cr({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 vs=768,Mr=1024,xs=1280,hs=8,bs=224,ys=304,Ss=114;function ks(e){return e>=xs?4:e>=Mr?3:e>=vs?2:1}function Ps(e){return e>=Mr?ys:bs}function Rr({events:e,hasMore:t=false,onFetchMore:r,onSelect:o,onSelectOutcome:n,getEventHref:i,LinkComponent:a,onHover:l}){let s=useRef(null),c=useRef(null),{width:d=0,height:u=0}=useResizeObserver({ref:s}),p=ks(d),f=Ps(d),m=Math.ceil(e.length/p)||0,g=!t&&e.length>0,x=m+(t?1:0)+(g?1:0),h=useCallback(C=>C<m,[m]),I=useCallback(async()=>{r?.();},[r]),D=useInfiniteLoader({isRowLoaded:h,loadMoreRows:I,rowCount:x,threshold:3}),E=useCallback(()=>{c.current?.scrollToRow({index:0,behavior:"smooth"});},[]);return jsx("div",{ref:s,className:"@container w-full h-full",children:u>0&&jsx(List,{listRef:c,className:"no-scrollbar",style:{height:u},onRowsRendered:D,rowComponent:Es,rowCount:x,rowHeight:C=>g&&C===x-1?Ss:(f),rowProps:{events:e,columnCount:p,dataRowCount:m,showEndOfList:g,totalRowCount:x,onSelect:o,onSelectOutcome:n,getEventHref:i,LinkComponent:a,onHover:l,onScrollToTop:E}})})}function Es({index:e,style:t,events:r,columnCount:o,dataRowCount:n,showEndOfList:i,totalRowCount:a,onSelect:l,onSelectOutcome:s,getEventHref:c,LinkComponent:d,onHover:u,onScrollToTop:p}){if(i&&e===a-1)return jsx("div",{style:t,children:jsx(Ns,{onScrollToTop:p})});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,m=r.slice(f,f+o),g=o-m.length;return jsx("div",{style:t,children:jsxs("div",{className:"flex w-full h-full",children:[m.map(x=>x==null?null:jsx("div",{className:"flex-1 min-w-0 flex",style:{padding:hs},children:jsx(Er,{event:x,href:c?.(x),LinkComponent:d,onSelect:l,onSelectOutcome:s,onHover:u})},x.slug)),g>0&&Array.from({length:g}).map((x,h)=>jsx("div",{style:{flex:1,minWidth:0}},`spacer-${h}`))]})})}function Ns({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 Or({tagSlugSelection:e,limit:t=48,status:r,sort_by:o,sort_asc:n,source:i,with_markets:a,onSelect:l,onSelectOutcome:s,getEventHref:c,LinkComponent:d,onHover:u}){let{data:p,hasMore:f,fetchMore:m,isFetching:g}=fr({tagSlugSelection:e,limit:t,status:r,sort_by:o,sort_asc:n,source:i,with_markets:a});return g?jsx(kt,{count:48}):jsx(Rr,{events:p,hasMore:f,onFetchMore:m,onSelect:l,onSelectOutcome:s,getEventHref:c,LinkComponent:d,onHover:u})}function Qc({onSelect:e,onSelectOutcome:t,getEventHref:r,LinkComponent:o,onHover:n}){let[i,a]=useState({categorySlug:null,tagSlug:null}),[l,s]=useState(yt),{isOpen:c,onOpen:d,onClose:u}=useDisclosure(),{onOpen:p}=useAsyncModal(bt),f=useCallback((C,H,G)=>{t?.(C,H,G),p({params:{event:C,market:H,initialOutcome:G}});},[t,p]),m=useCallback(C=>{a(C);},[]),g=useCallback(C=>{s(H=>({...H,sortPreset:C}));},[]),x=useCallback(C=>{s(H=>({...H,sortAsc:C}));},[]),h=useCallback(C=>{s(C);},[]),I=useMemo(()=>dr[l.sortPreset].sort_by,[l.sortPreset]),D=useMemo(()=>St(l),[l]),E=jsx(ur,{sortPreset:l.sortPreset,onSortChange:g,sortAsc:l.sortAsc,onSortAscChange:x,onFilterPress:d,filterCount:D});return jsxs("div",{className:"flex h-full w-full max-w-[1680px] mx-auto flex-col gap-y-3",children:[jsx(Xt,{onSelect:m,trailing:E}),jsx(ar,{isOpen:c,onClose:u,value:l,onChange:h}),jsx("div",{className:"min-h-0 flex-1",children:jsx(Or,{tagSlugSelection:i,sort_by:I,sort_asc:l.sortAsc,source:l.source,onSelect:e,onSelectOutcome:f,getEventHref:r,LinkComponent:o,onHover:n})}),jsx(or,{})]})}function Dr({event:e,walletAddress:t,onCancelOrder:r}){let{t:o}=useTranslation(),[n,i]=useState("positions"),a=useMemo(()=>e.markets?.map(u=>u.slug)??[],[e.markets]),{data:l}=usePositions({source:e.source,user:t??""}),s=useMemo(()=>!l?.positions||!t?0:a.length===0?l.positions.length:l.positions.filter(u=>u.market&&a.includes(u.market.slug)).length,[l?.positions,a,t]),d=[{key:"positions",label:s>0?`${o("predict.positions.title")} (${s})`:o("predict.positions.title")},{key:"orders",label:o("predict.openOrders.title")},{key:"trades",label:o("predict.tradeHistory.title")}];return jsxs("div",{className:"flex flex-col gap-y-2 mt-6 px-1 lg:px-4",children:[jsx("div",{className:"flex items-center gap-x-1 border-b border-border",children:d.map(u=>jsx("button",{type:"button",onClick:()=>i(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",{className:"min-h-[120px]",children:[n==="positions"&&jsx(As,{source:e.source,walletAddress:t,marketSlugs:a}),n==="orders"&&jsx(Hs,{source:e.source,walletAddress:t,marketSlugs:a,onCancelOrder:r}),n==="trades"&&jsx(Us,{source:e.source,walletAddress:t})]}):jsx("div",{className:"flex items-center justify-center py-12 text-sm text-neutral",children:o("predict.trade.connectWallet")})]})}function As({source:e,walletAddress:t,marketSlugs:r}){let{t:o}=useTranslation(),{data:n,isLoading:i}=usePositions({source:e,user:t}),a=useMemo(()=>n?.positions?r.length===0?n.positions:n.positions.filter(l=>l.market&&r.includes(l.market.slug)):[],[n?.positions,r]);return i?jsx(Mt,{rows:3}):a.length===0?jsx(Tt,{message:o("predict.positions.empty")}):jsx("div",{className:"overflow-x-auto",children:jsxs("table",{className:"w-full text-xs lg:text-sm",children:[jsx("thead",{children:jsxs("tr",{className:"text-neutral text-left",children:[jsx("th",{className:"py-2 pr-4 font-normal whitespace-nowrap",children:o("predict.positions.event")}),jsx("th",{className:"py-2 pr-3 font-normal text-right whitespace-nowrap",children:o("predict.positions.totalSize")}),jsx("th",{className:"py-2 pr-3 font-normal text-right whitespace-nowrap",children:o("predict.positions.value")}),jsx("th",{className:"py-2 pr-3 font-normal text-right whitespace-nowrap",children:o("predict.positions.avgPrice")}),jsx("th",{className:"py-2 pr-3 font-normal text-right whitespace-nowrap",children:o("predict.positions.markPrice")}),jsx("th",{className:"py-2 pr-3 font-normal text-right whitespace-nowrap",children:o("predict.positions.pnl")}),jsx("th",{className:"py-2 pr-3 font-normal text-right whitespace-nowrap",children:o("predict.positions.payoutIfRight")}),jsx("th",{className:"py-2 pr-3 font-normal text-right whitespace-nowrap",children:o("predict.positions.estSettlement")}),jsx("th",{className:"py-2 font-normal text-right whitespace-nowrap"})]})}),jsx("tbody",{children:a.map((l,s)=>jsx(Ds,{position:l},`${l.market?.slug??s}-${l.side}`))})]})})}function Ds({position:e}){let{t}=useTranslation(),r=e.pnl??0,o=e.pnl_percent??0,n=e.avg_price??0,i=e.current_price??0,a=r>0?"text-success":r<0?"text-danger":"text-foreground",l=r>0?"+":"",s=e.market?.outcomes?.[0]?.label??e.market?.question??"\u2014",c=e.side,d=e.size,u=e.size*i,p=e.market?.end_at?zs(e.market.end_at):"\u2014";return jsxs("tr",{className:"border-b border-border/50 last:border-b-0 hover:bg-content2/40 transition-colors",children:[jsx("td",{className:"py-2 pr-4 max-w-[200px]",children:jsxs("div",{className:"flex flex-col gap-y-0.5",children:[jsx("span",{className:"text-foreground truncate font-medium",children:s}),jsx("span",{className:cn$1("inline-block text-[10px] font-medium w-fit",c.toLowerCase()==="yes"?"text-primary":"text-secondary"),children:c})]})}),jsx("td",{className:"py-2 pr-3 text-right font-mono text-foreground whitespace-nowrap",children:e.size}),jsxs("td",{className:"py-2 pr-3 text-right font-mono text-foreground whitespace-nowrap",children:["$",u.toFixed(2)]}),jsx("td",{className:"py-2 pr-3 text-right font-mono text-foreground whitespace-nowrap",children:tt(n)}),jsx("td",{className:"py-2 pr-3 text-right font-mono text-foreground whitespace-nowrap",children:tt(i)}),jsxs("td",{className:cn$1("py-2 pr-3 text-right font-mono whitespace-nowrap",a),children:[l,"$",Math.abs(r).toFixed(2),jsxs("span",{className:"text-[10px] ml-0.5 opacity-70",children:["(",l,o.toFixed(1),"%)"]})]}),jsxs("td",{className:"py-2 pr-3 text-right font-mono text-foreground whitespace-nowrap",children:["$",d.toFixed(2)]}),jsx("td",{className:"py-2 pr-3 text-right text-neutral whitespace-nowrap",children:p}),jsx("td",{className:"py-2 text-right whitespace-nowrap",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:t("predict.positions.close")})})]})}function Hs({source:e,walletAddress:t,marketSlugs:r,onCancelOrder:o}){let{t:n}=useTranslation(),{data:i,isLoading:a}=useOrders({source:e,wallet_address:t}),l=useCancelOrder(),s=useMemo(()=>{if(!i?.items)return [];let d=new Set(["live","open","submitted","pending"]),u=i.items.filter(p=>d.has(p.status));return r.length>0&&(u=u.filter(p=>p.market_id&&r.includes(p.market_id))),u},[i?.items,r]),c=d=>{o?o(d.id):l.mutate({source:d.source,id:d.id});};return a?jsx(Mt,{rows:3}):s.length===0?jsx(Tt,{message:n("predict.openOrders.empty")}):jsx("div",{className:"overflow-x-auto",children:jsxs("table",{className:"w-full text-xs lg:text-sm",children:[jsx("thead",{children:jsxs("tr",{className:"text-neutral text-left",children:[jsx("th",{className:"py-2 pr-2 font-normal",children:n("predict.openOrders.side")}),jsx("th",{className:"py-2 pr-2 font-normal",children:n("predict.openOrders.outcome")}),jsx("th",{className:"py-2 pr-2 font-normal",children:n("predict.openOrders.type")}),jsx("th",{className:"py-2 pr-2 font-normal text-right",children:n("predict.openOrders.price")}),jsx("th",{className:"py-2 pr-2 font-normal text-right",children:n("predict.openOrders.filled")}),jsx("th",{className:"py-2 pr-2 font-normal",children:n("predict.openOrders.status")}),jsx("th",{className:"py-2 font-normal"})]})}),jsx("tbody",{children:s.map(d=>jsx(Fs,{order:d,onCancel:()=>c(d),isCancelling:l.isPending},d.id))})]})})}function Fs({order:e,onCancel:t,isCancelling:r}){let{t:o}=useTranslation(),n=e.side==="BUY";return jsxs("tr",{className:"border-b border-border/50 last:border-b-0",children:[jsx("td",{className:"py-2 pr-2",children:jsx("span",{className:cn$1("inline-block rounded px-1.5 py-0.5 text-[10px] font-medium",n?"bg-primary/10 text-primary":"bg-danger/10 text-danger"),children:e.side})}),jsx("td",{className:"py-2 pr-2 text-foreground capitalize",children:e.outcome??"\u2014"}),jsx("td",{className:"py-2 pr-2 text-neutral capitalize",children:e.order_type??"limit"}),jsx("td",{className:"py-2 pr-2 text-right font-mono text-foreground",children:e.price?tt(parseFloat(e.price)):"\u2014"}),jsxs("td",{className:"py-2 pr-2 text-right font-mono text-foreground",children:[e.size_matched??"0","/",e.original_size??"\u2014"]}),jsx("td",{className:"py-2 pr-2",children:jsx(Bs,{status:e.status})}),jsx("td",{className:"py-2 text-right",children:jsx("button",{type:"button",onClick:t,disabled:r,className:"text-[10px] text-danger hover:text-danger/80 cursor-pointer disabled:opacity-50 transition-colors",children:r?jsx(Spinner,{size:"sm"}):o("predict.openOrders.cancel")})})]})}function Bs({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 Us({source:e,walletAddress:t}){let{t:r}=useTranslation(),{data:o,isLoading:n}=useTrades({source:e,wallet:t,limit:50}),i=o?.items??[];return n?jsx(Mt,{rows:3}):i.length===0?jsx(Tt,{message:r("predict.tradeHistory.empty")}):jsx("div",{className:"overflow-x-auto",children:jsxs("table",{className:"w-full text-xs lg:text-sm",children:[jsx("thead",{children:jsxs("tr",{className:"text-neutral text-left",children:[jsx("th",{className:"py-2 pr-2 font-normal",children:r("predict.tradeHistory.side")}),jsx("th",{className:"py-2 pr-2 font-normal",children:r("predict.tradeHistory.outcome")}),jsx("th",{className:"py-2 pr-2 font-normal text-right",children:r("predict.tradeHistory.price")}),jsx("th",{className:"py-2 pr-2 font-normal text-right",children:r("predict.tradeHistory.qty")}),jsx("th",{className:"py-2 pr-2 font-normal text-right",children:r("predict.tradeHistory.total")}),jsx("th",{className:"py-2 font-normal text-right",children:r("predict.tradeHistory.time")})]})}),jsx("tbody",{children:i.map(a=>jsx($s,{trade:a},a.id))})]})})}function $s({trade:e}){let t=e.side?.toUpperCase()==="BUY",r=Ws(e.timestamp),o=e.price??0,n=e.usd_size??0;return jsxs("tr",{className:"border-b border-border/50 last:border-b-0",children:[jsx("td",{className:"py-2 pr-2",children:jsx("span",{className:cn$1("inline-block rounded px-1.5 py-0.5 text-[10px] font-medium",t?"bg-primary/10 text-primary":"bg-danger/10 text-danger"),children:e.side})}),jsx("td",{className:"py-2 pr-2 text-foreground capitalize",children:e.outcome??"\u2014"}),jsx("td",{className:"py-2 pr-2 text-right font-mono text-foreground",children:tt(o)}),jsx("td",{className:"py-2 pr-2 text-right font-mono text-foreground",children:e.size}),jsxs("td",{className:"py-2 pr-2 text-right font-mono text-foreground",children:["$",n.toFixed(2)]}),jsx("td",{className:"py-2 text-right text-neutral whitespace-nowrap",children:r})]})}function Tt({message:e}){return jsx("div",{className:"flex items-center justify-center py-12 text-sm text-neutral",children:e})}function Mt({rows:e}){return jsx("div",{className:"flex flex-col gap-y-2 py-3 animate-pulse",children:Array.from({length:e}).map((t,r)=>jsx(Skeleton,{className:"h-8 w-full rounded-md"},r))})}function tt(e){let t=e*100;return t<1&&t>0?"< 1\xA2":`${t.toFixed(1)}\xA2`}function Ws(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"),i=t.getMinutes().toString().padStart(2,"0");return `${r}/${o} ${n}:${i}`}function zs(e){try{return new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}catch{return "\u2014"}}function Be({marketCount:e=4}){return jsxs("div",{className:"flex w-full flex-col gap-4 animate-pulse",children:[jsxs("div",{className:"flex items-center gap-3",children:[jsx(Skeleton,{className:"size-14 shrink-0 rounded-lg"}),jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-2",children:[jsx(Skeleton,{className:"h-4 w-32 rounded"}),jsx(Skeleton,{className:"h-6 w-full max-w-md rounded"})]})]}),jsx(Skeleton,{className:"h-48 w-full rounded-xl"}),Array.from({length:e}).map((t,r)=>jsx(Skeleton,{className:"h-12 w-full rounded-md"},r))]})}function Hr(){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 Ur="var(--color-bullish)",$r="var(--color-bearish)";function Ue(e){if(Math.abs(e)>=1e4){let t=e/1e4;return `${parseFloat(t.toFixed(2))}\u4E07`}return e.toLocaleString()}function Ys(e,t){return e<=0||t<=0?0:Math.pow(e/t,.3)}function qs(e,t){let r=new Float64Array(101),o=new Float64Array(101);for(let f of e){let m=Math.round(f.price*100);m>=0&&m<=100&&(r[m]+=f.quantity);}for(let f of t){let m=Math.round(f.price*100);m>=0&&m<=100&&(o[m]+=f.quantity);}let n=0,i=0,a=new Float64Array(101),l=new Float64Array(101);for(let f=100;f>=0;f--)n+=r[f],i+=r[f]*f/100,a[f]=n,l[f]=i;let s=0,c=0,d=new Float64Array(101),u=new Float64Array(101);for(let f=0;f<=100;f++)s+=o[f],c+=o[f]*f/100,d[f]=s,u[f]=c;let p=Math.max(a[0]??0,d[100]??0);return Array.from({length:101},(f,m)=>{let g=a[m]>0,x=d[m]>0,h=a[m]||d[m],I=r[m]>0||o[m]>0;return {priceCents:m,displayHeight:Ys(h,p),opacity:h>0?I?1:.5:0,isBid:g,isAsk:x,bidCumTotal:a[m],askCumTotal:d[m],bidCumCost:l[m],askCumCost:u[m]}})}function js({info:e}){let t=e.isBid?Ur:$r,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:[Ue(Math.round(e.cumTotal))," contracts"]}),jsxs("div",{style:{color:t},children:["$",Ue(Math.round(e.cumCost))]})]})}var Gs=memo(function({slot:t,onEnter:r,onLeave:o}){let n=useRef(null),i=t.isBid||t.isAsk,a=t.isBid?Ur:t.isAsk?$r:void 0;return jsx("div",{style:{position:"absolute",left:`${t.priceCents}%`,width:"1%",height:"100%",boxSizing:"border-box",borderRight:t.priceCents<100?"1px solid transparent":"none",cursor:i?"crosshair":"default"},onMouseEnter:()=>r(t,n.current),onMouseLeave:o,children:i&&jsx("div",{ref:n,style:{position:"absolute",bottom:0,left:0,width:"100%",height:`${t.displayHeight*100}%`,backgroundColor:a,opacity:t.opacity}})})}),Xs=[0,10,20,30,40,50,60,70,80,90,100];function Qs(){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:Xs.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 Wr({bids:e,asks:t}){let r=useMemo(()=>qs(e,t),[e,t]),o=useMemo(()=>{let d=e.length>0?Math.max(...e.map(p=>p.price)):0,u=t.length>0?Math.min(...t.map(p=>p.price)):1;return Math.round((d+u)/2*100)},[e,t]),n=useMemo(()=>r.some(d=>d.isBid||d.isAsk),[r]),[i,a]=useState(null),l=useRef(null),s=useCallback((d,u)=>{l.current&&(l.current.style.filter=""),u?(u.style.filter="brightness(1.5)",l.current=u):l.current=null,d.isBid||d.isAsk?a({priceCents:d.priceCents,isBid:d.isBid,cumTotal:d.isBid?d.bidCumTotal:d.askCumTotal,cumCost:d.isBid?d.bidCumCost:d.askCumCost,leftPct:d.priceCents}):a(null);},[]),c=useCallback(()=>{l.current&&(l.current.style.filter="",l.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"}}),i&&jsx(js,{info:i}),r.map(d=>jsx(Gs,{slot:d,onEnter:s,onLeave:c},d.priceCents))]}),jsx(Qs,{})]}):jsx("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#6b7280",fontSize:13},children:"No depth data"})}function zr(e){let t=e*100,r=Math.round(t*10)/10;return Number.isInteger(r)?`${r}\xA2`:`${r.toFixed(1)}\xA2`}function Kr(){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 jr({market:e,outcome:t="yes",onTradeAction:r}){let{t:o}=useTranslation(),[n,i]=useState("depth"),a=t==="no",l=e.source,{data:s,isLoading:c}=useOrderbook({slug:e.slug,source:l}),d=useMemo(()=>((a?s?.asks:s?.bids)??[]).map(x=>({price:a?1-x.price:x.price,quantity:x.size})),[s?.bids,s?.asks,a]),u=useMemo(()=>((a?s?.bids:s?.asks)??[]).map(x=>({price:a?1-x.price:x.price,quantity:x.size})),[s?.bids,s?.asks,a]),p=useMemo(()=>d.length>0?Math.max(...d.map(g=>g.price)):null,[d]),f=useMemo(()=>u.length>0?Math.min(...u.map(g=>g.price)):null,[u]),m=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:m!=null?`${o("predict.orderBook.spread")}: ${Number.isInteger(m)?`${m}\xA2`:`${m.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"),": ",zr(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"),": ",zr(f)]})]}),jsx("div",{className:"flex flex-1 justify-end",children:jsx("button",{type:"button",title:n==="depth"?"Orderbook":"Depth chart",onClick:()=>i(g=>g==="depth"?"table":"depth"),className:"flex items-center text-neutral transition-colors cursor-pointer hover:text-foreground",children: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:c?jsx(Kr,{}):jsx(Wr,{bids:d,asks:u})}),n==="table"&&jsx(Fragment,{children:c?jsx(Kr,{}):jsx(na,{bids:d,asks:u,bestBid:p??void 0,bestAsk:f??void 0,spread:m??void 0})})]})]})}var Vr=8;function na({bids:e,asks:t,spread:r}){let{t:o}=useTranslation(),n=useMemo(()=>[...t].sort((s,c)=>c.price-s.price).slice(0,Vr),[t]),i=useMemo(()=>[...e].sort((s,c)=>c.price-s.price).slice(0,Vr),[e]),a=useMemo(()=>{let s=[...n,...i].map(c=>c.quantity);return Math.max(...s,1)},[n,i]);return n.length===0&&i.length===0?jsx("div",{className:"flex items-center justify-center h-full text-xs text-neutral",children:o("predict.orderBook.empty")}):jsxs("div",{className:"flex flex-col h-full overflow-y-auto text-xs font-mono select-none",children:[n.map(s=>jsx(Yr,{price:s.price,quantity:s.quantity,side:"ask",maxQty:a},`ask-${s.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`]})}),i.map(s=>jsx(Yr,{price:s.price,quantity:s.quantity,side:"bid",maxQty:a},`bid-${s.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 Yr({price:e,quantity:t,side:r,maxQty:o}){let n=r==="ask",i=Math.min(t/o*100,100),a=n?"bg-bullish/10":"bg-bearish/10",l=n?"text-bullish":"text-bearish",s=Math.round(e*100),c=Ue(Math.round(t)),d=Math.round(t*e),u=`$${Ue(d)}`;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:`${i}%`}}),jsxs("span",{className:`relative z-10 ${l}`,children:[s,"\xA2"]}),jsx("span",{className:"relative z-10 text-foreground text-center",children:c}),jsx("span",{className:"relative z-10 text-foreground text-right",children:u})]})}var It=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}},ot=4,Gr=["#22d3ee","#a3e635","#f97316","#f472b6","#a78bfa"];function ga(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 va(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 Qr(e){return `${(e*100).toFixed(2)}%`}var xa=[{range:ChartRange.ONE_DAY,label:"1D"},{range:ChartRange.ONE_WEEK,label:"1W"},{range:ChartRange.ONE_MONTH,label:"1M"},{range:ChartRange.ALL,label:"ALL"}];function ha({value:e,onChange:t}){return jsx("div",{style:{display:"flex",alignItems:"center",gap:2},children:xa.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 ba(){let e=useRef(null),t=useRef(null),r=useCallback(n=>{let i=e.current,a=t.current;if(!i||!a)return;let l=i.getBoundingClientRect(),s=(n.clientX-l.left)/l.width*100;a.style.background=`linear-gradient(to right, transparent ${s}%, rgba(0,0,0,0.55) ${s}%)`,a.style.opacity="1";},[]),o=useCallback(()=>{t.current&&(t.current.style.opacity="0");},[]);return {wrapperRef:e,overlayRef:t,onMouseMove:r,onMouseLeave:o}}function ya({active:e,payload:t,label:r,labelMap:o,allSeries:n,range:i}){if(!e||!n?.length)return null;let a=new Map;t?.forEach(s=>a.set(s.dataKey,s));let l=n.map(s=>a.get(s.slug)??{dataKey:s.slug,value:void 0,stroke:s.color,color:s.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"?va(r,i):r}),l.map(s=>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:s.stroke??s.color,flexShrink:0}}),jsx("span",{style:{color:"#9ca3af",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:120},children:o.get(s.dataKey)??s.dataKey}),jsx("span",{style:{color:"#f9fafb",fontWeight:700,fontVariantNumeric:"tabular-nums"},children:s.value!=null?Qr(s.value):"--"})]},s.dataKey))]})}function Sa({markets:e,selectedSlugs:t,colorMap:r,onToggle:o}){let[n,i]=useState(false),a=useRef(null);useEffect(()=>{if(!n)return;function c(d){a.current&&!a.current.contains(d.target)&&i(false);}return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[n]);let l=t.length>=ot,s=jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flex:1,minWidth:0},children:[jsx("div",{style:{display:"flex",gap:3,flexShrink:0},children:t.map(c=>jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:r.get(c)??"#6b7280",display:"inline-block"}},c))}),jsx("span",{style:{color:"#e5e7eb",fontSize:12,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.length===1?(()=>{let c=e.find(d=>d.slug===t[0]);return c?.outcomes?.[0]?.label??c?.question??"1 market"})():`${t.length} / ${e.length} markets`})]});return jsxs("div",{ref:a,style:{position:"relative",display:"inline-block",width:200},children:[jsxs("button",{onClick:()=>i(c=>!c),style:{display:"inline-flex",alignItems:"center",gap:6,padding:"5px 10px",borderRadius:8,border:"1px solid rgba(255,255,255,0.12)",background:"rgba(255,255,255,0.05)",cursor:"pointer",width:"100%",userSelect:"none"},children:[s,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 ",ot," markets"]}),e.map(c=>{let d=t.includes(c.slug),u=!d&&l,p=d&&t.length===1,f=r.get(c.slug)??"#6b7280",m=c.outcomes.find(x=>x.label.toLowerCase()==="yes")??c.outcomes[0],g=m?.price!=null?`${Math.round(m.price*100)}%`:null;return jsxs("button",{onClick:()=>{p||u||o(c.slug);},style:{display:"flex",alignItems:"center",gap:10,width:"100%",padding:"7px 12px",border:"none",background:d?"rgba(255,255,255,0.05)":"transparent",cursor:u||p?"not-allowed":"pointer",opacity:u?.35:1,textAlign:"left",transition:"background 0.1s"},onMouseEnter:x=>{!u&&!p&&(x.currentTarget.style.background="rgba(255,255,255,0.07)");},onMouseLeave:x=>{x.currentTarget.style.background=d?"rgba(255,255,255,0.05)":"transparent";},children:[jsx("span",{style:{width:16,height:16,borderRadius:4,border:d?`2px solid ${f}`:"2px solid rgba(255,255,255,0.2)",background:d?`${f}30`:"transparent",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center"},children:d&&jsx("svg",{width:"9",height:"7",viewBox:"0 0 9 7",fill:"none",children:jsx("path",{d:"M1 3.5L3.5 6L8 1",stroke: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:d?"#f9fafb":"#9ca3af",fontSize:12,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c.outcomes?.[0]?.label??c.question}),g&&jsx("span",{style:{color:f,fontWeight:700,fontSize:12,flexShrink:0},children:g})]},c.slug)})]})]})}function ka({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",i=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:i!=null?Qr(i):"--"})]})]},o.marketSlug)})})}function Pa(e){let t=Math.floor(e.length/2);return e.length%2===1?e[t]:(e[t-1]+e[t])/2}function Ea(e,t){if(e.length<=t)return e;let r=[],o=e.length/t;for(let n=0;n<t;n++){let i=Math.floor(n*o),a=Math.min(Math.floor((n+1)*o),e.length),l=e.slice(i,a),s=l.map(c=>c.price).sort((c,d)=>c-d);r.push({timestamp:l[l.length-1].timestamp,price:Pa(s)});}return r}function Na(e,t=200){if(e.length===0)return [];let r=e.map(l=>({...l,data:Ea(l.data,t)})),o=new Set;r.forEach(l=>l.data.forEach(s=>o.add(s.timestamp)));let n=Array.from(o).sort((l,s)=>l-s),i=r.map(l=>{let s=new Map;return l.data.forEach(c=>s.set(c.timestamp,c.price)),{slug:l.marketSlug,map:s}}),a=new Map;return n.map(l=>{let s={timestamp:l};return i.forEach(({slug:c,map:d})=>{let u=d.get(l);if(u!==void 0)a.set(c,u),s[c]=u;else {let p=a.get(c);p!==void 0&&(s[c]=p);}}),s})}function Zr(e){return jsx(It,{children:jsx(wa,{...e})})}function wa({event:e,isLoading:t,className:r,volume:o}){let n=useMemo(()=>e.markets??[],[e.markets]),i=useMemo(()=>[...n].sort((y,P)=>{let T=U=>(U.outcomes.find(W=>W.label.toLowerCase()==="yes")??U.outcomes[0])?.price??0;return T(P)-T(y)}),[n]),[a,l]=useState(()=>i.slice(0,ot).map(y=>y.slug)),[s,c]=useState(Ye),d=useMemo(()=>{let y=new Map;return a.forEach((P,T)=>{y.set(P,Gr[T%Gr.length]);}),y},[a]),u=useMemo(()=>n.filter(y=>a.includes(y.slug)),[n,a]),{series:p,isLoading:f}=useMarketHistory(u,s),m=t||f,g=useMemo(()=>{if(p.length>0&&p.some(T=>T.data.length>0))return p;let y=Date.now(),P=864e5;return u.map(T=>{let W=(T.outcomes?.find(q=>q.label.toLowerCase()==="yes")??T.outcomes?.[0])?.price??.5;return {marketSlug:T.slug,label:T.outcomes?.[0]?.label??T.question,data:[{timestamp:y-7*P,price:W},{timestamp:y,price:W}]}})},[p,u]),x=useMemo(()=>s===ChartRange.ONE_DAY?96:s===ChartRange.ONE_WEEK?168:s===ChartRange.ONE_MONTH?180:300,[s]),h=useMemo(()=>Na(g,x),[g,x]),I=useMemo(()=>{if(h.length===0)return [0,1];let y=1/0,P=-1/0;if(a.forEach(U=>{h.forEach(W=>{let q=W[U];q!=null&&(q<y&&(y=q),q>P&&(P=q));});}),!isFinite(y))return [0,1];let T=Math.max((P-y)*.15,.05);return [Math.max(0,y-T),Math.min(1,P+T)]},[h,a]),D=useMemo(()=>{let y=new Map;return g.forEach(P=>{P.data.length>0&&y.set(P.marketSlug,P.data[P.data.length-1].price);}),y},[g]),E=useMemo(()=>{let y=new Map;return g.forEach(P=>y.set(P.marketSlug,P.label)),y},[g]),C=useMemo(()=>g.map(y=>({slug:y.marketSlug,color:d.get(y.marketSlug)??"#6b7280"})),[g,d]),{wrapperRef:H,overlayRef:G,onMouseMove:Me,onMouseLeave:Re}=ba(),ge=useCallback(y=>{l(P=>P.includes(y)?P.length<=1?P:P.filter(T=>T!==y):P.length>=ot?P:[...P,y]);},[]),[N,Z]=useState(null),re=useRef(null),Le=useRef(""),ve=useRef(0),J=!m&&h.length>0;return jsxs("div",{className:r,style:{display:"flex",flexDirection:"column",gap:12},children:[jsx(ka,{series:g,colorMap:d,displayValues:N??D}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:0},children:[jsx("div",{ref:H,style:{height:300,width:"100%",userSelect:"none",position:"relative"},onMouseMove:J?y=>{Me(y),cancelAnimationFrame(ve.current),ve.current=requestAnimationFrame(()=>{Z(re.current);});}:void 0,onMouseLeave:J?()=>{Re(),cancelAnimationFrame(ve.current),Le.current="",re.current=null,Z(null);}:void 0,children:m?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:G,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=>ga(y,s),axisLine:false,tickLine:false,tick:{fill:"#6b7280",fontSize:11},minTickGap:70}),jsx(YAxis,{domain:I,tickFormatter:y=>`${Math.round(y*100)}%`,axisLine:false,tickLine:false,tick:{fill:"#6b7280",fontSize:11},width:40,tickCount:6}),jsx(Tooltip,{content:y=>{let P=y;if(P.active&&P.payload?.length){let T=P.payload.map(U=>`${U.dataKey}:${U.value}`).join(",");if(T!==Le.current){Le.current=T;let U=new Map;P.payload.forEach(W=>{W.value!=null&&U.set(W.dataKey,W.value);}),re.current=U;}}return jsx(ya,{...P,labelMap:E,allSeries:C,range:s})},cursor:{stroke:"#4b5563",strokeWidth:1,strokeDasharray:"4 4"},wrapperStyle:{zIndex:2},isAnimationActive:false}),g.map(y=>{let P=d.get(y.marketSlug)??"#6b7280";return jsx(Line,{type:"linear",dataKey:y.marketSlug,stroke:P,strokeWidth:2,strokeLinejoin:"round",strokeLinecap:"round",dot:false,activeDot:{r:4.5,strokeWidth:2,stroke:"rgba(10,10,10,0.8)",fill:P},connectNulls:true,isAnimationActive:false},y.marketSlug)}),N==null&&h.length>0&&g.map(y=>{let P=h[h.length-1],T=P[y.marketSlug];if(T==null)return null;let U=d.get(y.marketSlug)??"#6b7280";return jsx(ReferenceDot,{x:P.timestamp,y:T,ifOverflow:"extendDomain",shape:W=>{let{cx:q,cy:Oe}=W;return q==null||Oe==null?jsx("g",{}):jsxs("g",{children:[jsxs("circle",{cx:q,cy:Oe,r:6,fill:U,opacity:.3,children:[jsx("animate",{attributeName:"r",values:"4;9;4",dur:"2s",repeatCount:"indefinite"}),jsx("animate",{attributeName:"opacity",values:"0.4;0.05;0.4",dur:"2s",repeatCount:"indefinite"})]}),jsx("circle",{cx:q,cy:Oe,r:3.5,fill:U})]})}},`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}}),i.length>1&&jsxs(Fragment,{children:[jsx(Sa,{markets:i,selectedSlugs:a,colorMap:d,onToggle:ge}),jsx("span",{style:{width:1,height:14,background:"#374151",flexShrink:0}})]}),jsx(ha,{value:s,onChange:c})]})]})]})}function _t(e){return e.outcomes[0]?.best_ask??e.outcomes[0]?.price??0}function Ia(e){return `${Math.round(e*100)}%`}function Jr(e){let t=e*100;return t<1&&t>0?"< 1":Number.isInteger(t)?`${t}`:t.toFixed(1)}function en(e){return e.outcomes?.[0]?.label??e.question}function _a(e){switch(e){case "polymarket":return "Polymarket";case "dflow":return "Kalshi";default:return e}}function tn(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(),i=t.getHours().toString().padStart(2,"0"),a=t.getMinutes().toString().padStart(2,"0");return `${r} ${o}, ${n} ${i}:${a}`}function rn(e){let[t,r]=useState(Date.now());if(useEffect(()=>{if(!e)return;let d=setInterval(()=>r(Date.now()),1e3);return ()=>clearInterval(d)},[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 i=Math.floor(n/864e5),a=Math.floor(n%864e5/36e5),l=Math.floor(n%36e5/6e4),s=Math.floor(n%6e4/1e3),c=[];return i>0&&c.push(`${i}d`),c.push(`${String(a).padStart(2,"0")}h`),c.push(`${String(l).padStart(2,"0")}m`),c.push(`${String(s).padStart(2,"0")}s`),c.join(" ")}function nn(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"),i=t.getDate().toString().padStart(2,"0"),a=t.getFullYear(),l=-t.getTimezoneOffset(),s=l>=0?"+":"-",c=String(Math.abs(Math.floor(l/60))).padStart(2,"0");return `${r}:${o} ${n}/${i}/${a} (${s}${c})`}function ln({event:e,onTradeAction:t}){let{t:r}=useTranslation(),{ref:o,isCollapsed:n}=useScrollCollapse(),i=useMemo(()=>[...e.markets||[]].sort((u,p)=>_t(p)-_t(u)),[e.markets]),a=e.status==="closed"||e.status==="voided",l=rn(a?void 0:e.start_at),s=rn(a?void 0:e.end_at),c=nn(e.start_at),d=nn(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,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:u.label})]},u.slug)),jsx(Fa,{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})]})]}),(l||s||a)&&jsx("div",{className:"flex items-center gap-x-2 text-xs lg:text-sm font-mono",children:a?d&&jsx("span",{className:"text-neutral",children:r("predict.event.endedAt",{time:d})}):l?jsxs(Fragment,{children:[jsx("span",{className:"text-foreground",children:r("predict.event.beginsIn",{time:l})}),c&&jsxs(Fragment,{children:[jsx("span",{className:"text-neutral/50",children:"\xB7"}),jsx("span",{className:"text-neutral",children:c})]})]}):s?jsxs(Fragment,{children:[jsx("span",{className:"text-foreground",children:r("predict.event.endsIn",{time:s})}),d&&jsxs(Fragment,{children:[jsx("span",{className:"text-neutral/50",children:"\xB7"}),jsx("span",{className:"text-neutral",children:d})]})]}):null}),jsx(Zr,{event:e,volume:e.volume??void 0}),jsx(Aa,{markets:i,onTradeAction:t}),jsx(Ha,{markets:i,event:e})]})}var on=5;function Aa({markets:e,onTradeAction:t}){let{t:r}=useTranslation(),[o,n]=useState(false),[i,a]=useState(null),l=e.find(m=>m.status==="open")?.slug,[s,c]=useState(l?`${l}:yes`:null);if(e.length===0)return null;let d=e.length>on,u=o?e:e.slice(0,on),p=m=>{a(g=>g===m?null:m);},f=(m,g,x)=>{c(`${m.slug}:${g}`),a(m.slug),t?.(m,g,x);};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(m=>{let g=_t(m),x=m.outcomes[1]?.best_ask??m.outcomes[1]?.price,h=i===m.slug;return jsx(Da,{market:m,yesPrice:g,noPrice:x??void 0,activeYes:s===`${m.slug}:yes`,activeNo:s===`${m.slug}:no`,isExpanded:h,onToggleExpand:()=>p(m.slug),onTradeAction:f},m.slug)})})]}),d&&jsxs("button",{type:"button",onClick:()=>n(m=>!m),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 Da({market:e,yesPrice:t,noPrice:r,activeYes:o,activeNo:n,isExpanded:i,onToggleExpand:a,onTradeAction:l}){let{t:s}=useTranslation(),c=e.status==="open",d=e.volume?`$${Math.round(e.volume).toLocaleString("en-US")} vol`:void 0;return jsxs(Fragment,{children:[jsxs("tr",{className:"cursor-pointer border-b border-border text-xs hover:bg-content2 lg:text-base",onClick: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:en(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:en(e)}),d&&jsx("span",{className:"text-[8px] text-neutral lg:text-xxs",children:d})]})]})}),jsx("td",{className:"py-2 text-left text-foreground lg:text-center",children:Ia(t)}),jsx("td",{className:"py-2 pr-1 lg:pr-2",children:c?jsxs("div",{className:"flex items-center justify-end gap-x-2",children:[jsx("button",{type:"button",className:cn$1("flex min-w-16 items-center justify-center whitespace-nowrap rounded-lg p-2 lg:min-w-24 cursor-pointer hover:opacity-80 transition-all",o?"bg-primary text-primary-foreground":"bg-primary/10 text-primary"),onClick:u=>{u.stopPropagation(),l?.(e,"yes","buy");},children:s("predict.market.action.yes",{price:Jr(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(),l?.(e,"no","buy");},children:r!=null?s("predict.market.action.no",{price:Jr(r)}):s("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"?s("predict.event.status.closed"):e.status==="voided"?s("predict.event.status.voided"):s("predict.event.status.pending")})})})]}),i&&jsx("tr",{children:jsx("td",{colSpan:3,className:"pb-3",children:jsx("div",{className:"max-h-100 overflow-y-auto",children:jsx(jr,{market:e,outcome:n?"no":"yes",onTradeAction:l})})})})]})}function Ha({markets:e,event:t}){let{t:r}=useTranslation(),[o,n]=useState(false),[i,a]=useState(false),l=e.filter(u=>u.rules&&u.rules.length>0);if(l.length===0)return null;let s=l[0];if(!s?.rules?.length)return null;let c=s.rules.join(`
|
|
19
|
+
`;function _r({event:e,href:t,LinkComponent:r,onSelect:o,onSelectOutcome:n,onHover:a}){let[i,s]=useState(null),l=e.markets??[],c=useMemo(()=>l.length>2?[...l].sort((N,C)=>(C.outcomes?.[0]?.price??0)-(N.outcomes?.[0]?.price??0)):l,[l]),d=c.filter(N=>N.status==="open"),u=c.length===1,f=d.slice(0,Pr),p=d.length-Pr,m=useMemo(()=>`$${Math.round(e.volume??0).toLocaleString("en-US")}`,[e.volume]),g=i?d.find(N=>N.slug===i)??null:null,x=!!g||u,v=()=>{x||o?.(e);},_=N=>{N.stopPropagation(),g&&(N.preventDefault(),s(null));},M=N=>{N.stopPropagation(),t||(N.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",!x&&"cursor-pointer"),onMouseEnter:()=>a?.(e),onClick:v,children:[jsx("style",{children:as}),jsx(ls,{event:e,href:t,LinkComponent:r,onClick:_,isExpanded:x}),jsx("div",{className:"flex flex-1 flex-col",children:u?jsx(vs,{market:d[0],event:e,formattedVolume:m,href:t,LinkComponent:r,onSelect:o,onSelectOutcome:n}):g?jsx(xs,{market:g,event:e,onCollapse:()=>s(null),onSelectOutcome:n}):jsx(fs,{displayedMarkets:f,moreCount:p,formattedVolume:m,source:e.source,href:t,LinkComponent:r,onMarketClick:N=>s(N.slug),onShowMore:M})})]})}function ls({event:e,href:t,LinkComponent:r,onClick:o,isExpanded:n}){let a=e.start_at?is(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}),a&&jsxs("span",{className:"text-[10px] leading-4 text-neutral-500",children:["Live in ",a]})]}),jsx(ds,{event:e})]})}function cs(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(),a=300*1e3,i=900*1e3;if(n>0&&n<=i){let s=n<=a?"#ef4444":"#f59e0b";t.push({kind:"crypto-short",label:n<=a?"5m":"15m",color:s});}}return o&&t.push({kind:"live"}),t.slice(0,2)}function ds({event:e}){let t=useMemo(()=>cs(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(us,{},o);case "crypto-short":return jsx(ps,{label:r.label,color:r.color},o);case "closed":return jsx(ms,{},o)}})})}function us(){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 ps({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 ms(){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 fs({displayedMarkets:e,moreCount:t,formattedVolume:r,source:o,href:n,LinkComponent:a,onMarketClick:i,onShowMore:s}){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(c=>{let d=Ir(c);return jsxs("button",{type:"button",className:"flex h-9 w-full items-center justify-between gap-x-2 transition-opacity hover:cursor-pointer hover:opacity-80",onClick:u=>{u.stopPropagation(),i(c);},children:[jsx("span",{className:"min-w-0 flex-1 text-left text-xs text-slate-200 line-clamp-1 lg:text-sm",children:c.outcomes?.[0]?.label??c.question}),jsxs("div",{className:"flex items-center gap-x-2",children:[jsx("span",{className:"text-sm font-semibold text-slate-200 lg:text-lg",children:Or(d)}),jsx(gs,{})]})]},c.slug)})}),jsxs("div",{className:"mt-auto flex items-center justify-between pt-3",children:[t>0?jsxs(Linkable,{href:n,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:s,children:[l("predict.event.showMore"),jsx(Dr,{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(Hr,{source:o})]})]})]})}function Mr({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:s=>{let l=s.currentTarget;l.style.setProperty("--shadow-offset","2px"),l.style.transform="translateY(2px)";},onMouseLeave:s=>{let l=s.currentTarget;l.style.setProperty("--shadow-offset","4px"),l.style.transform="translateY(0px)";},onClick:o,children:n})}function Ar({market:e,event:t,onSelectOutcome:r,dynamicColors:o=false,labelFormat:n="action"}){let{t:a}=useTranslation(),[i,s]=o?os(e):[Rt,Lr],l=e.outcomes?.[0]?.label?.toLowerCase().trim()??"",c=e.outcomes?.[1]?.label?.toLowerCase().trim()??"",d=n==="label"&&l===c?"action":n,u=d==="label"?`${e.outcomes?.[0]?.label??"Yes"} ${Cr(e)}\xA2`:a("predict.market.action.yes",{price:Cr(e)}),f=d==="label"?`${e.outcomes?.[1]?.label??"No"} ${Tr(e)}\xA2`:a("predict.market.action.no",{price:Tr(e)});return jsxs("div",{className:"flex gap-2",children:[jsx(Mr,{bgColor:i.bg,textColor:i.text,shadowColor:i.shadow,onClick:p=>{p.stopPropagation(),r?.(t,e,"yes");},children:u}),jsx(Mr,{bgColor:s.bg,textColor:s.text,shadowColor:s.shadow,onClick:p=>{p.stopPropagation(),r?.(t,e,"no");},children:f})]})}function gs(){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 vs({market:e,event:t,formattedVolume:r,href:o,LinkComponent:n,onSelect:a,onSelectOutcome:i}){let{t:s}=useTranslation();return jsxs(Fragment,{children:[jsx("div",{className:"flex-1",children:jsx(Ar,{market:e,event:t,onSelectOutcome:i,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:c=>{c.stopPropagation(),o||(c.preventDefault(),a?.(t));},children:[s("predict.event.viewEvent"),jsx(Dr,{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," ",s("predict.event.volume"),jsx(Hr,{source:t.source})]})]})]})}function xs({market:e,event:t,onCollapse:r,onSelectOutcome:o}){let{t:n}=useTranslation(),a=Ir(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:i=>{i.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:Or(a)}),jsx(ChevronUpIcon,{className:"h-4 w-4 text-neutral-400"})]})]}),jsx("div",{className:"mt-3",children:jsx(Ar,{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:i=>{i.stopPropagation(),r();},children:[jsx(hs,{className:"h-3 w-3"}),n("predict.event.back")]})]})}function Dr({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 hs({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 Hr({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 Ns=768,Br=1024,Ps=1280,Es=8,Cs=224,Ts=304,Ms=114;function Rs(e){return e>=Ps?4:e>=Br?3:e>=Ns?2:1}function Ls(e){return e>=Br?Ts:Cs}function Ur({events:e,hasMore:t=false,onFetchMore:r,onSelect:o,onSelectOutcome:n,getEventHref:a,LinkComponent:i,onHover:s}){let l=useRef(null),c=useRef(null),{width:d=0,height:u=0}=useResizeObserver({ref:l}),f=Rs(d),p=Ls(d),m=Math.ceil(e.length/f)||0,g=!t&&e.length>0,x=m+(t?1:0)+(g?1:0),v=useCallback(C=>C<m,[m]),_=useCallback(async()=>{r?.();},[r]),M=useInfiniteLoader({isRowLoaded:v,loadMoreRows:_,rowCount:x,threshold:3}),N=useCallback(()=>{c.current?.scrollToRow({index:0,behavior:"smooth"});},[]);return jsx("div",{ref:l,className:"@container w-full h-full",children:u>0&&jsx(List,{listRef:c,className:"no-scrollbar",style:{height:u},onRowsRendered:M,rowComponent:Is,rowCount:x,rowHeight:C=>g&&C===x-1?Ms:(p),rowProps:{events:e,columnCount:f,dataRowCount:m,showEndOfList:g,totalRowCount:x,onSelect:o,onSelectOutcome:n,getEventHref:a,LinkComponent:i,onHover:s,onScrollToTop:N}})})}function Is({index:e,style:t,events:r,columnCount:o,dataRowCount:n,showEndOfList:a,totalRowCount:i,onSelect:s,onSelectOutcome:l,getEventHref:c,LinkComponent:d,onHover:u,onScrollToTop:f}){if(a&&e===i-1)return jsx("div",{style:t,children:jsx(Os,{onScrollToTop:f})});if(e>=n)return jsx("div",{style:t,className:"flex justify-center items-start pt-4",children:jsx(Spinner,{size:"sm"})});let p=e*o,m=r.slice(p,p+o),g=o-m.length;return jsx("div",{style:t,children:jsxs("div",{className:"flex w-full h-full",children:[m.map(x=>x==null?null:jsx("div",{className:"flex-1 min-w-0 flex",style:{padding:Es},children:jsx(_r,{event:x,href:c?.(x),LinkComponent:d,onSelect:s,onSelectOutcome:l,onHover:u})},x.slug)),g>0&&Array.from({length:g}).map((x,v)=>jsx("div",{style:{flex:1,minWidth:0}},`spacer-${v}`))]})})}function Os({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 Wr({tagSlugSelection:e,limit:t=48,status:r,sort_by:o,sort_asc:n,source:a,with_markets:i,onSelect:s,onSelectOutcome:l,getEventHref:c,LinkComponent:d,onHover:u}){let{data:f,hasMore:p,fetchMore:m,isFetching:g}=Nr({tagSlugSelection:e,limit:t,status:r,sort_by:o,sort_asc:n,source:a,with_markets:i});return g?jsx(Tt,{count:48}):jsx(Ur,{events:f,hasMore:p,onFetchMore:m,onSelect:s,onSelectOutcome:l,getEventHref:c,LinkComponent:d,onHover:u})}function cd({onSelect:e,onSelectOutcome:t,getEventHref:r,LinkComponent:o,onHover:n}){let[a,i]=useState({categorySlug:null,tagSlug:null}),[s,l]=useState(Et),{isOpen:c,onOpen:d,onClose:u}=useDisclosure(),{onOpen:f}=useAsyncModal(Pt),p=useCallback((C,B,Z)=>{t?.(C,B,Z),f({params:{event:C,market:B,initialOutcome:Z}});},[t,f]),m=useCallback(C=>{i(C);},[]),g=useCallback(C=>{l(B=>({...B,sortPreset:C}));},[]),x=useCallback(C=>{l(B=>({...B,sortAsc:C}));},[]),v=useCallback(C=>{l(C);},[]),_=useMemo(()=>yr[s.sortPreset].sort_by,[s.sortPreset]),M=useMemo(()=>Ct(s),[s]),N=jsx(Sr,{sortPreset:s.sortPreset,onSortChange:g,sortAsc:s.sortAsc,onSortAscChange:x,onFilterPress:d,filterCount:M});return jsxs("div",{className:"flex h-full w-full max-w-[1680px] mx-auto flex-col gap-y-3",children:[jsx(ir,{onSelect:m,trailing:N}),jsx(vr,{isOpen:c,onClose:u,value:s,onChange:v}),jsx("div",{className:"min-h-0 flex-1",children:jsx(Wr,{tagSlugSelection:a,sort_by:_,sort_asc:s.sortAsc,source:s.source,onSelect:e,onSelectOutcome:p,getEventHref:r,LinkComponent:o,onHover:n})}),jsx(fr,{})]})}var Dt=40,at=36,We=480,Ht=We-at;function jr({event:e,walletAddress:t,onCancelOrder:r}){let{t:o}=useTranslation(),[n,a]=useState("positions"),i=useMemo(()=>e.markets?.map(u=>u.slug)??[],[e.markets]),{data:s}=usePositions({source:e.source,user:t??""}),l=useMemo(()=>!s?.positions||!t?0:i.length===0?s.positions.length:s.positions.filter(u=>u.market&&i.includes(u.market.slug)).length,[s?.positions,i,t]),d=[{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:d.map(u=>jsx("button",{type:"button",onClick:()=>a(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:We},children:[n==="positions"&&jsx(Ws,{source:e.source,walletAddress:t,marketSlugs:i}),n==="orders"&&jsx(Ks,{source:e.source,walletAddress:t,marketSlugs:i,onCancelOrder:r}),n==="trades"&&jsx(js,{source:e.source,walletAddress:t})]}):jsx("div",{className:"flex items-center justify-center text-sm text-neutral",style:{height:We},children:o("predict.trade.connectWallet")})]})}function Ws({source:e,walletAddress:t,marketSlugs:r}){let{t:o}=useTranslation(),{data:n,isLoading:a}=usePositions({source:e,user:t}),i=useMemo(()=>n?.positions?r.length===0?n.positions:n.positions.filter(s=>s.market&&r.includes(s.market.slug)):[],[n?.positions,r]);return a?jsx(Bt,{}):i.length===0?jsx(Ft,{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:at},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:Ht},rowComponent:zs,rowCount:i.length,rowHeight:Dt,rowProps:{positions:i,closeLabel:o("predict.positions.close")}})]})}function zs({index:e,style:t,positions:r,closeLabel:o}){let n=r[e];if(!n)return null;let a=n.pnl??0,i=n.pnl_percent??0,s=n.avg_price??0,l=n.current_price??0,c=a>0?"text-success":a<0?"text-danger":"text-foreground",d=a>0?"+":"",u=n.market?.outcomes?.[0]?.label??n.market?.question??"\u2014",f=n.side,p=n.size,m=n.size*l,g=n.market?.end_at?Xs(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",f.toLowerCase()==="yes"?"text-primary":"text-secondary"),children:f})]})}),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:["$",m.toFixed(2)]}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:st(s)}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:st(l)}),jsxs("div",{className:cn$1("flex-[1.5] pr-2 text-right font-mono whitespace-nowrap",c),children:[d,"$",Math.abs(a).toFixed(2),jsxs("span",{className:"text-[10px] ml-0.5 opacity-70",children:["(",d,i.toFixed(1),"%)"]})]}),jsxs("div",{className:"flex-1 pr-2 text-right font-mono text-foreground whitespace-nowrap",children:["$",p.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 Ks({source:e,walletAddress:t,marketSlugs:r,onCancelOrder:o}){let{t:n}=useTranslation(),{data:a,isLoading:i,fetchNextPage:s,hasNextPage:l}=useInfiniteOrders({source:e,wallet_address:t}),c=useCancelOrder(),d=useMemo(()=>{let v=a?.pages?.flatMap(N=>N.items)??[],_=new Set(["live","open","submitted","pending"]),M=v.filter(N=>_.has(N.status));return r.length>0&&(M=M.filter(N=>N.market_id&&r.includes(N.market_id))),M},[a?.pages,r]),u=useCallback(v=>{o?o(v.id):c.mutate({source:v.source,id:v.id});},[o,c]),f=d.length,p=f+(l?1:0),m=useCallback(v=>v<f,[f]),g=useCallback(async()=>{await s();},[s]),x=useInfiniteLoader({isRowLoaded:m,loadMoreRows:g,rowCount:p,threshold:5});return i?jsx(Bt,{}):d.length===0&&!l?jsx(Ft,{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:at},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:Ht},onRowsRendered:x,rowComponent:Vs,rowCount:p,rowHeight:Dt,rowProps:{orders:d,itemCount:f,onCancel:u,isCancelling:c.isPending,cancelLabel:n("predict.openOrders.cancel")}})]})}function Vs({index:e,style:t,orders:r,itemCount:o,onCancel:n,isCancelling:a,cancelLabel:i}){if(e>=o)return jsx("div",{style:t,className:"flex justify-center items-center",children:jsx(Spinner,{size:"sm"})});let s=r[e];if(!s)return null;let l=s.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:s.side})}),jsx("div",{className:"flex-1 pr-2 text-foreground capitalize",children:s.outcome??"\u2014"}),jsx("div",{className:"flex-1 pr-2 text-neutral capitalize",children:s.order_type??"limit"}),jsx("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:s.price?st(parseFloat(s.price)):"\u2014"}),jsxs("div",{className:"flex-1 pr-2 text-right font-mono text-foreground",children:[s.size_matched??"0","/",s.original_size??"\u2014"]}),jsx("div",{className:"w-20 shrink-0 pr-2",children:jsx(Ys,{status:s.status})}),jsx("div",{className:"w-16 shrink-0 text-right",children:jsx("button",{type:"button",onClick:()=>n(s),disabled:a,className:"text-[10px] text-danger hover:text-danger/80 cursor-pointer disabled:opacity-50 transition-colors",children:a?jsx(Spinner,{size:"sm"}):i})})]})}function Ys({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 js({source:e,walletAddress:t}){let{t:r}=useTranslation(),{data:o,isLoading:n,fetchNextPage:a,hasNextPage:i}=useInfiniteTrades({source:e,wallet:t,limit:50}),s=useMemo(()=>o?.pages?.flatMap(p=>p.items)??[],[o?.pages]),l=s.length,c=l+(i?1:0),d=useCallback(p=>p<l,[l]),u=useCallback(async()=>{await a();},[a]),f=useInfiniteLoader({isRowLoaded:d,loadMoreRows:u,rowCount:c,threshold:5});return n?jsx(Bt,{}):s.length===0&&!i?jsx(Ft,{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:at},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:Ht},onRowsRendered:f,rowComponent:qs,rowCount:c,rowHeight:Dt,rowProps:{trades:s,itemCount:l}})]})}function qs({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 a=n.side?.toUpperCase()==="BUY",i=Gs(n.timestamp),s=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",a?"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:st(s)}),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:i})]})}function Ft({message:e}){return jsx("div",{className:"flex items-center justify-center text-sm text-neutral",style:{height:We},children:e})}function Bt(){return jsx("div",{className:"flex flex-col gap-y-2 py-3 animate-pulse",style:{height:We},children:Array.from({length:6}).map((e,t)=>jsx(Skeleton,{className:"h-8 w-full rounded-md"},t))})}function st(e){let t=e*100;return t<1&&t>0?"< 1\xA2":`${t.toFixed(1)}\xA2`}function Gs(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"),a=t.getMinutes().toString().padStart(2,"0");return `${r}/${o} ${n}:${a}`}function Xs(e){try{return new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}catch{return "\u2014"}}function ze({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 qr(){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 Qr="var(--color-bullish)",Zr="var(--color-bearish)";function Ke(e){if(Math.abs(e)>=1e4){let t=e/1e4;return `${parseFloat(t.toFixed(2))}\u4E07`}return e.toLocaleString()}function Js(e,t){return e<=0||t<=0?0:Math.pow(e/t,.3)}function ei(e,t){let r=new Float64Array(101),o=new Float64Array(101);for(let p of e){let m=Math.round(p.price*100);m>=0&&m<=100&&(r[m]+=p.quantity);}for(let p of t){let m=Math.round(p.price*100);m>=0&&m<=100&&(o[m]+=p.quantity);}let n=0,a=0,i=new Float64Array(101),s=new Float64Array(101);for(let p=100;p>=0;p--)n+=r[p],a+=r[p]*p/100,i[p]=n,s[p]=a;let l=0,c=0,d=new Float64Array(101),u=new Float64Array(101);for(let p=0;p<=100;p++)l+=o[p],c+=o[p]*p/100,d[p]=l,u[p]=c;let f=Math.max(i[0]??0,d[100]??0);return Array.from({length:101},(p,m)=>{let g=i[m]>0,x=d[m]>0,v=i[m]||d[m],_=r[m]>0||o[m]>0;return {priceCents:m,displayHeight:Js(v,f),opacity:v>0?_?1:.5:0,isBid:g,isAsk:x,bidCumTotal:i[m],askCumTotal:d[m],bidCumCost:s[m],askCumCost:u[m]}})}function ti({info:e}){let t=e.isBid?Qr:Zr,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:[Ke(Math.round(e.cumTotal))," contracts"]}),jsxs("div",{style:{color:t},children:["$",Ke(Math.round(e.cumCost))]})]})}var ri=memo(function({slot:t,onEnter:r,onLeave:o}){let n=useRef(null),a=t.isBid||t.isAsk,i=t.isBid?Qr:t.isAsk?Zr: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:()=>r(t,n.current),onMouseLeave:o,children:a&&jsx("div",{ref:n,style:{position:"absolute",bottom:0,left:0,width:"100%",height:`${t.displayHeight*100}%`,backgroundColor:i,opacity:t.opacity}})})}),ni=[0,10,20,30,40,50,60,70,80,90,100];function oi(){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:ni.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 Jr({bids:e,asks:t}){let r=useMemo(()=>ei(e,t),[e,t]),o=useMemo(()=>{let d=e.length>0?Math.max(...e.map(f=>f.price)):0,u=t.length>0?Math.min(...t.map(f=>f.price)):1;return Math.round((d+u)/2*100)},[e,t]),n=useMemo(()=>r.some(d=>d.isBid||d.isAsk),[r]),[a,i]=useState(null),s=useRef(null),l=useCallback((d,u)=>{s.current&&(s.current.style.filter=""),u?(u.style.filter="brightness(1.5)",s.current=u):s.current=null,d.isBid||d.isAsk?i({priceCents:d.priceCents,isBid:d.isBid,cumTotal:d.isBid?d.bidCumTotal:d.askCumTotal,cumCost:d.isBid?d.bidCumCost:d.askCumCost,leftPct:d.priceCents}):i(null);},[]),c=useCallback(()=>{s.current&&(s.current.style.filter="",s.current=null),i(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"}}),a&&jsx(ti,{info:a}),r.map(d=>jsx(ri,{slot:d,onEnter:l,onLeave:c},d.priceCents))]}),jsx(oi,{})]}):jsx("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#6b7280",fontSize:13},children:"No depth data"})}function en(e){let t=e*100,r=Math.round(t*10)/10;return Number.isInteger(r)?`${r}\xA2`:`${r.toFixed(1)}\xA2`}function tn(){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 sn({market:e,outcome:t="yes",onTradeAction:r}){let{t:o}=useTranslation(),[n,a]=useState("depth"),i=t==="no",s=e.source,{data:l,isLoading:c}=useOrderbook({slug:e.slug,source:s}),d=useMemo(()=>((i?l?.asks:l?.bids)??[]).map(x=>({price:i?1-x.price:x.price,quantity:x.size})),[l?.bids,l?.asks,i]),u=useMemo(()=>((i?l?.bids:l?.asks)??[]).map(x=>({price:i?1-x.price:x.price,quantity:x.size})),[l?.bids,l?.asks,i]),f=useMemo(()=>d.length>0?Math.max(...d.map(g=>g.price)):null,[d]),p=useMemo(()=>u.length>0?Math.min(...u.map(g=>g.price)):null,[u]),m=useMemo(()=>{if(f==null||p==null)return null;let g=(p-f)*100;return Math.round(g*10)/10},[f,p]);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:m!=null?`${o("predict.orderBook.spread")}: ${Number.isInteger(m)?`${m}\xA2`:`${m.toFixed(1)}\xA2`}`:null}),jsxs("span",{className:"flex flex-1 items-center justify-center gap-x-1 whitespace-nowrap",children:[f!=null&&jsxs("span",{style:{color:"var(--color-bullish)"},children:[o("predict.trade.bestBid"),": ",en(f)]}),f!=null&&p!=null&&jsx("span",{className:"text-neutral",children:"|"}),p!=null&&jsxs("span",{style:{color:"var(--color-bearish)"},children:[o("predict.trade.bestAsk"),": ",en(p)]})]}),jsx("div",{className:"flex flex-1 justify-end",children:jsx("button",{type:"button",title:n==="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: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:c?jsx(tn,{}):jsx(Jr,{bids:d,asks:u})}),n==="table"&&jsx(Fragment,{children:c?jsx(tn,{}):jsx(di,{bids:d,asks:u,bestBid:f??void 0,bestAsk:p??void 0,spread:m??void 0})})]})]})}var rn=8;function di({bids:e,asks:t,spread:r}){let{t:o}=useTranslation(),n=useMemo(()=>[...t].sort((l,c)=>c.price-l.price).slice(0,rn),[t]),a=useMemo(()=>[...e].sort((l,c)=>c.price-l.price).slice(0,rn),[e]),i=useMemo(()=>{let l=[...n,...a].map(c=>c.quantity);return Math.max(...l,1)},[n,a]);return n.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:[n.map(l=>jsx(nn,{price:l.price,quantity:l.quantity,side:"ask",maxQty:i},`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`]})}),a.map(l=>jsx(nn,{price:l.price,quantity:l.quantity,side:"bid",maxQty:i},`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 nn({price:e,quantity:t,side:r,maxQty:o}){let n=r==="ask",a=Math.min(t/o*100,100),i=n?"bg-bullish/10":"bg-bearish/10",s=n?"text-bullish":"text-bearish",l=Math.round(e*100),c=Ke(Math.round(t)),d=Math.round(t*e),u=`$${Ke(d)}`;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 ${i} transition-[width] duration-200`,style:{width:`${a}%`}}),jsxs("span",{className:`relative z-10 ${s}`,children:[l,"\xA2"]}),jsx("span",{className:"relative z-10 text-foreground text-center",children:c}),jsx("span",{className:"relative z-10 text-foreground text-right",children:u})]})}var zt=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}},ct=4,an=["#22d3ee","#a3e635","#f97316","#f472b6","#a78bfa"];function wi(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 ki(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 cn(e){return `${(e*100).toFixed(2)}%`}var Ni=[{range:ChartRange.ONE_DAY,label:"1D"},{range:ChartRange.ONE_WEEK,label:"1W"},{range:ChartRange.ONE_MONTH,label:"1M"},{range:ChartRange.ALL,label:"ALL"}];function Pi({value:e,onChange:t}){return jsx("div",{style:{display:"flex",alignItems:"center",gap:2},children:Ni.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 Ei(){let e=useRef(null),t=useRef(null),r=useCallback(n=>{let a=e.current,i=t.current;if(!a||!i)return;let s=a.getBoundingClientRect(),l=(n.clientX-s.left)/s.width*100;i.style.background=`linear-gradient(to right, transparent ${l}%, rgba(0,0,0,0.55) ${l}%)`,i.style.opacity="1";},[]),o=useCallback(()=>{t.current&&(t.current.style.opacity="0");},[]);return {wrapperRef:e,overlayRef:t,onMouseMove:r,onMouseLeave:o}}function Ci({active:e,payload:t,label:r,labelMap:o,allSeries:n,range:a}){if(!e||!n?.length)return null;let i=new Map;t?.forEach(l=>i.set(l.dataKey,l));let s=n.map(l=>i.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"?ki(r,a):r}),s.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?cn(l.value):"--"})]},l.dataKey))]})}function Ti({markets:e,selectedSlugs:t,colorMap:r,onToggle:o}){let[n,a]=useState(false),i=useRef(null);useEffect(()=>{if(!n)return;function c(d){i.current&&!i.current.contains(d.target)&&a(false);}return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[n]);let s=t.length>=ct,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(c=>jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:r.get(c)??"#6b7280",display:"inline-block"}},c))}),jsx("span",{style:{color:"#e5e7eb",fontSize:12,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.length===1?(()=>{let c=e.find(d=>d.slug===t[0]);return c?.outcomes?.[0]?.label??c?.question??"1 market"})():`${t.length} / ${e.length} markets`})]});return jsxs("div",{ref:i,style:{position:"relative",display:"inline-block",width:200},children:[jsxs("button",{onClick:()=>a(c=>!c),style:{display:"inline-flex",alignItems:"center",gap:6,padding:"5px 10px",borderRadius:8,border:"1px solid rgba(255,255,255,0.12)",background:"rgba(255,255,255,0.05)",cursor:"pointer",width:"100%",userSelect:"none"},children:[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 ",ct," markets"]}),e.map(c=>{let d=t.includes(c.slug),u=!d&&s,f=d&&t.length===1,p=r.get(c.slug)??"#6b7280",m=c.outcomes.find(x=>x.label.toLowerCase()==="yes")??c.outcomes[0],g=m?.price!=null?`${Math.round(m.price*100)}%`:null;return jsxs("button",{onClick:()=>{f||u||o(c.slug);},style:{display:"flex",alignItems:"center",gap:10,width:"100%",padding:"7px 12px",border:"none",background:d?"rgba(255,255,255,0.05)":"transparent",cursor:u||f?"not-allowed":"pointer",opacity:u?.35:1,textAlign:"left",transition:"background 0.1s"},onMouseEnter:x=>{!u&&!f&&(x.currentTarget.style.background="rgba(255,255,255,0.07)");},onMouseLeave:x=>{x.currentTarget.style.background=d?"rgba(255,255,255,0.05)":"transparent";},children:[jsx("span",{style:{width:16,height:16,borderRadius:4,border:d?`2px solid ${p}`:"2px solid rgba(255,255,255,0.2)",background:d?`${p}30`:"transparent",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center"},children:d&&jsx("svg",{width:"9",height:"7",viewBox:"0 0 9 7",fill:"none",children:jsx("path",{d:"M1 3.5L3.5 6L8 1",stroke:p,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:p,flexShrink:0}}),jsx("span",{style:{color:d?"#f9fafb":"#9ca3af",fontSize:12,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c.outcomes?.[0]?.label??c.question}),g&&jsx("span",{style:{color:p,fontWeight:700,fontSize:12,flexShrink:0},children:g})]},c.slug)})]})]})}function Mi({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",a=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:a!=null?cn(a):"--"})]})]},o.marketSlug)})})}function Ri(e){let t=Math.floor(e.length/2);return e.length%2===1?e[t]:(e[t-1]+e[t])/2}function Li(e,t){if(e.length<=t)return e;let r=[],o=e.length/t;for(let n=0;n<t;n++){let a=Math.floor(n*o),i=Math.min(Math.floor((n+1)*o),e.length),s=e.slice(a,i),l=s.map(c=>c.price).sort((c,d)=>c-d);r.push({timestamp:s[s.length-1].timestamp,price:Ri(l)});}return r}function Ii(e,t=200){if(e.length===0)return [];let r=e.map(s=>({...s,data:Li(s.data,t)})),o=new Set;r.forEach(s=>s.data.forEach(l=>o.add(l.timestamp)));let n=Array.from(o).sort((s,l)=>s-l),a=r.map(s=>{let l=new Map;return s.data.forEach(c=>l.set(c.timestamp,c.price)),{slug:s.marketSlug,map:l}}),i=new Map;return n.map(s=>{let l={timestamp:s};return a.forEach(({slug:c,map:d})=>{let u=d.get(s);if(u!==void 0)i.set(c,u),l[c]=u;else {let f=i.get(c);f!==void 0&&(l[c]=f);}}),l})}function dn(e){return jsx(zt,{children:jsx(Oi,{...e})})}function Oi({event:e,isLoading:t,className:r,volume:o}){let n=useMemo(()=>(e.markets??[]).filter(y=>y.status==="open"),[e.markets]),a=useMemo(()=>[...n].sort((y,k)=>{let R=W=>(W.outcomes.find(K=>K.label.toLowerCase()==="yes")??W.outcomes[0])?.price??0;return R(k)-R(y)}),[n]),[i,s]=useState(()=>a.slice(0,ct).map(y=>y.slug)),[l,c]=useState(Qe),d=useMemo(()=>{let y=new Map;return i.forEach((k,R)=>{y.set(k,an[R%an.length]);}),y},[i]),u=useMemo(()=>n.filter(y=>i.includes(y.slug)),[n,i]),{series:f,isLoading:p}=useMarketHistory(u,l),m=t||p,g=useMemo(()=>{if(f.length>0&&f.some(R=>R.data.length>0))return f;let y=Date.now(),k=864e5;return u.map(R=>{let K=(R.outcomes?.find(X=>X.label.toLowerCase()==="yes")??R.outcomes?.[0])?.price??.5;return {marketSlug:R.slug,label:R.outcomes?.[0]?.label??R.question,data:[{timestamp:y-7*k,price:K},{timestamp:y,price:K}]}})},[f,u]),x=useMemo(()=>l===ChartRange.ONE_DAY?96:l===ChartRange.ONE_WEEK?168:l===ChartRange.ONE_MONTH?180:300,[l]),v=useMemo(()=>Ii(g,x),[g,x]),_=useMemo(()=>{if(v.length===0)return [0,1];let y=1/0,k=-1/0;if(i.forEach(W=>{v.forEach(K=>{let X=K[W];X!=null&&(X<y&&(y=X),X>k&&(k=X));});}),!isFinite(y))return [0,1];let R=Math.max((k-y)*.15,.05);return [Math.max(0,y-R),Math.min(1,k+R)]},[v,i]),M=useMemo(()=>{let y=new Map;return g.forEach(k=>{k.data.length>0&&y.set(k.marketSlug,k.data[k.data.length-1].price);}),y},[g]),N=useMemo(()=>{let y=new Map;return g.forEach(k=>y.set(k.marketSlug,k.label)),y},[g]),C=useMemo(()=>g.map(y=>({slug:y.marketSlug,color:d.get(y.marketSlug)??"#6b7280"})),[g,d]),{wrapperRef:B,overlayRef:Z,onMouseMove:Re,onMouseLeave:Le}=Ei(),xe=useCallback(y=>{s(k=>k.includes(y)?k.length<=1?k:k.filter(R=>R!==y):k.length>=ct?k:[...k,y]);},[]),[P,te]=useState(null),se=useRef(null),Ie=useRef(""),he=useRef(0),re=!m&&v.length>0;return jsxs("div",{className:r,style:{display:"flex",flexDirection:"column",gap:12},children:[jsx(Mi,{series:g,colorMap:d,displayValues:P??M}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:0},children:[jsx("div",{ref:B,style:{height:300,width:"100%",userSelect:"none",position:"relative"},onMouseMove:re?y=>{Re(y),cancelAnimationFrame(he.current),he.current=requestAnimationFrame(()=>{te(se.current);});}:void 0,onMouseLeave:re?()=>{Le(),cancelAnimationFrame(he.current),Ie.current="",se.current=null,te(null);}:void 0,children:m?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"}})}):v.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:Z,style:{position:"absolute",inset:0,opacity:0,pointerEvents:"none",zIndex:1}}),jsx(ResponsiveContainer,{width:"100%",height:"100%",children:jsxs(LineChart,{data:v,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=>wi(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 k=y;if(k.active&&k.payload?.length){let R=k.payload.map(W=>`${W.dataKey}:${W.value}`).join(",");if(R!==Ie.current){Ie.current=R;let W=new Map;k.payload.forEach(K=>{K.value!=null&&W.set(K.dataKey,K.value);}),se.current=W;}}return jsx(Ci,{...k,labelMap:N,allSeries:C,range:l})},cursor:{stroke:"#4b5563",strokeWidth:1,strokeDasharray:"4 4"},wrapperStyle:{zIndex:2},isAnimationActive:false}),g.map(y=>{let k=d.get(y.marketSlug)??"#6b7280";return jsx(Line,{type:"linear",dataKey:y.marketSlug,stroke:k,strokeWidth:2,strokeLinejoin:"round",strokeLinecap:"round",dot:false,activeDot:{r:4.5,strokeWidth:2,stroke:"rgba(10,10,10,0.8)",fill:k},connectNulls:true,isAnimationActive:false},y.marketSlug)}),P==null&&v.length>0&&g.map(y=>{let k=v[v.length-1],R=k[y.marketSlug];if(R==null)return null;let W=d.get(y.marketSlug)??"#6b7280";return jsx(ReferenceDot,{x:k.timestamp,y:R,ifOverflow:"extendDomain",shape:K=>{let{cx:X,cy:Oe}=K;return X==null||Oe==null?jsx("g",{}):jsxs("g",{children:[jsxs("circle",{cx:X,cy:Oe,r:6,fill:W,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:X,cy:Oe,r:3.5,fill:W})]})}},`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(Ti,{markets:a,selectedSlugs:i,colorMap:d,onToggle:xe}),jsx("span",{style:{width:1,height:14,background:"#374151",flexShrink:0}})]}),jsx(Pi,{value:l,onChange:c})]})]})]})}function Ye(e){return e.outcomes[0]?.best_ask??e.outcomes[0]?.price??0}function Vi(e){return `${Math.round(e*100)}%`}function un(e){let t=e*100;return t<1&&t>0?"< 1":Number.isInteger(t)?`${t}`:t.toFixed(1)}function dt(e){return e.outcomes?.[0]?.label??e.question}function Yi(e){switch(e){case "polymarket":return "Polymarket";case "dflow":return "Kalshi";default:return e}}function Ve(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(),a=t.getHours().toString().padStart(2,"0"),i=t.getMinutes().toString().padStart(2,"0");return `${r} ${o}, ${n} ${a}:${i}`}function pn(e){let[t,r]=useState(Date.now());if(useEffect(()=>{if(!e)return;let d=setInterval(()=>r(Date.now()),1e3);return ()=>clearInterval(d)},[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 a=Math.floor(n/864e5),i=Math.floor(n%864e5/36e5),s=Math.floor(n%36e5/6e4),l=Math.floor(n%6e4/1e3),c=[];return a>0&&c.push(`${a}d`),c.push(`${String(i).padStart(2,"0")}h`),c.push(`${String(s).padStart(2,"0")}m`),c.push(`${String(l).padStart(2,"0")}s`),c.join(" ")}function mn(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"),a=t.getDate().toString().padStart(2,"0"),i=t.getFullYear(),s=-t.getTimezoneOffset(),l=s>=0?"+":"-",c=String(Math.abs(Math.floor(s/60))).padStart(2,"0");return `${r}:${o} ${n}/${a}/${i} (${l}${c})`}function vn({event:e,onTradeAction:t}){let{t:r}=useTranslation(),{ref:o,isCollapsed:n}=useScrollCollapse(),a=useMemo(()=>{let u=[...e.markets||[]],f=u.filter(m=>m.status==="open").sort((m,g)=>Ye(g)-Ye(m)),p=u.filter(m=>m.status!=="open").sort((m,g)=>Ye(g)-Ye(m));return [...f,...p]},[e.markets]),i=e.status==="closed"||e.status==="voided",s=pn(i?void 0:e.start_at),l=pn(i?void 0:e.end_at),c=mn(e.start_at),d=mn(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,f)=>jsxs(Fragment$1,{children:[f>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(Xi,{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})]})]}),(s||l||i)&&jsx("div",{className:"flex items-center gap-x-2 text-xs lg:text-sm font-mono",children:i?d&&jsx("span",{className:"text-neutral",children:r("predict.event.endedAt",{time:d})}):s?jsxs(Fragment,{children:[jsx("span",{className:"text-foreground",children:r("predict.event.beginsIn",{time:s})}),c&&jsxs(Fragment,{children:[jsx("span",{className:"text-neutral/50",children:"\xB7"}),jsx("span",{className:"text-neutral",children:c})]})]}):l?jsxs(Fragment,{children:[jsx("span",{className:"text-foreground",children:r("predict.event.endsIn",{time:l})}),d&&jsxs(Fragment,{children:[jsx("span",{className:"text-neutral/50",children:"\xB7"}),jsx("span",{className:"text-neutral",children:d})]})]}):null}),jsx(dn,{event:e,volume:e.volume??void 0}),jsx(ji,{markets:a,onTradeAction:t}),jsx(Gi,{markets:a,event:e})]})}var fn=5;function ji({markets:e,onTradeAction:t}){let{t:r}=useTranslation(),[o,n]=useState(false),[a,i]=useState(null),s=e.find(m=>m.status==="open")?.slug,[l,c]=useState(s?`${s}:yes`:null);if(e.length===0)return null;let d=e.length>fn,u=o?e:e.slice(0,fn),f=m=>{i(g=>g===m?null:m);},p=(m,g,x)=>{c(`${m.slug}:${g}`),i(m.slug),t?.(m,g,x);};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(m=>{let g=Ye(m),x=m.outcomes[1]?.best_ask??m.outcomes[1]?.price,v=a===m.slug;return jsx(qi,{market:m,yesPrice:g,noPrice:x??void 0,activeYes:l===`${m.slug}:yes`,activeNo:l===`${m.slug}:no`,isExpanded:v,onToggleExpand:()=>f(m.slug),onTradeAction:p},m.slug)})})]}),d&&jsxs("button",{type:"button",onClick:()=>n(m=>!m),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 qi({market:e,yesPrice:t,noPrice:r,activeYes:o,activeNo:n,isExpanded:a,onToggleExpand:i,onTradeAction:s}){let{t:l}=useTranslation(),c=e.status==="open",d=e.volume?`$${Math.round(e.volume).toLocaleString("en-US")} vol`:void 0;return jsxs(Fragment,{children:[jsxs("tr",{className:"cursor-pointer border-b border-border text-xs hover:bg-content2 lg:text-base",onClick:i,role:"button",tabIndex:0,onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&(u.preventDefault(),i());},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:dt(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:dt(e)}),d&&jsx("span",{className:"text-[8px] text-neutral lg:text-xxs",children:d})]})]})}),jsx("td",{className:"py-2 text-left text-foreground lg:text-center",children:Vi(t)}),jsx("td",{className:"py-2 pr-1 lg:pr-2",children:c?jsxs("div",{className:"flex items-center justify-end gap-x-2",children:[jsx("button",{type:"button",className:cn$1("flex min-w-16 items-center justify-center whitespace-nowrap rounded-lg p-2 lg:min-w-24 cursor-pointer hover:opacity-80 transition-all",o?"bg-primary text-primary-foreground":"bg-primary/10 text-primary"),onClick:u=>{u.stopPropagation(),s?.(e,"yes","buy");},children:l("predict.market.action.yes",{price:un(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(),s?.(e,"no","buy");},children:r!=null?l("predict.market.action.no",{price:un(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")})})})]}),a&&jsx("tr",{children:jsx("td",{colSpan:3,className:"pb-3",children:jsx("div",{className:"max-h-100 overflow-y-auto",children:jsx(sn,{market:e,outcome:n?"no":"yes",onTradeAction:s})})})})]})}function Gi({markets:e,event:t}){let{t:r}=useTranslation(),[o,n]=useState(false),[a,i]=useState(false),[s,l]=useState(0),c=e.filter(p=>p.rules&&p.rules.length>0||p.description);if(c.length===0)return null;let d=c[s]??c[0],u=d.rules&&d.rules.length>0?d.rules.join(`
|
|
20
20
|
|
|
21
|
-
`),d=c.length>200&&!o?c.slice(0,200)+"...":c;return jsxs("div",{className:"flex flex-col gap-y-3",children:[jsx("span",{className:"text-sm font-semibold text-foreground lg:text-base",children:r("predict.event.rules")}),jsx("div",{className:"text-xs text-foreground/80 lg:text-sm whitespace-pre-wrap",children:d}),c.length>200&&jsx("button",{type:"button",onClick:()=>n(u=>!u),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(u=>!u),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",i&&"rotate-180")})]}),i&&jsxs(Fragment,{children:[jsx("div",{className:"flex flex-col",children:[{label:r("predict.event.timeline.open"),value:tn(s.start_at),isActive:true},{label:r("predict.event.timeline.close"),value:tn(s.end_at),isActive:s.status==="closed"||s.status==="voided"}].map((u,p,f)=>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 ${u.isActive?"border-primary bg-primary":"border-border bg-transparent"}`}),p<f.length-1&&jsx("div",{className:"w-px flex-1 bg-border"})]}),jsxs("div",{className:`flex flex-col ${p<f.length-1?"pb-4":""}`,children:[jsx("span",{className:"text-xs font-medium text-foreground lg:text-sm",children:u.label}),jsx("span",{className:"text-xs text-neutral lg:text-sm",children:u.value})]})]},u.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:s.slug})]}),jsxs("span",{children:[jsxs("span",{className:"text-neutral",children:[r("predict.event.id.source"),":"]})," ",jsx("span",{className:"text-foreground",children:_a(s.source)})]})]})]})]})}function Fa({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 cn({eventSlug:e,source:t,onTradeAction:r}){let{data:o,isLoading:n,error:i}=useEvent({slug:e,source:t});return n?jsx(Be,{}):i||!o?jsx("div",{className:"flex w-full items-center justify-center py-20 text-danger",children:i?.message||"Event not found"}):jsx(ln,{event:o,onTradeAction:r})}function dn({eventSlug:e,source:t,limit:r=4,onEventClick:o}){let{t:n}=useTranslation(),{data:i,isLoading:a}=useSimilarEvents({slug:e,source:t,limit:r});return a||!i||i.length===0?null:jsxs("div",{className:"flex flex-col gap-y-3 mt-6 px-1 lg:px-0",children:[jsx("span",{className:"text-sm font-semibold text-foreground lg:text-base",children:n("predict.similar.title")}),jsx("div",{className:"grid grid-cols-1 gap-3",children:i.map(l=>jsx(Ka,{event:l,onClick:o},l.slug))})]})}function Ka({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",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 un(e){return e.outcomes[0]?.best_ask??e.outcomes[0]?.price??0}function lu({eventSlug:e,source:t,chain:r,walletAddress:o,onSimilarEventClick:n,onBack:i}){let{t:a}=useTranslation(),{isMobile:l}=useScreen(),{isOpen:s,onOpen:c,onClose:d}=useDisclosure(),{data:u,isLoading:p}=useEvent({slug:e,source:t}),f=useMemo(()=>[...u?.markets||[]].sort((D,E)=>un(E)-un(D)),[u?.markets]),[m,g]=useState(null),x=useCallback((D,E,C)=>{g(H=>({market:D,outcome:E,side:C,version:(H?.version??0)+1})),l&&c();},[l,c]),h=m?.market??f[0];if(p)return l?jsx(Be,{}):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(Be,{})}),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(Hr,{})})})]});let I=m?`${m.market.slug}-${m.version}`:h?.slug??"default";return jsxs("div",{className:"flex w-full flex-col gap-y-4 lg:max-w-7xl lg:gap-y-8 mx-auto",children:[jsxs("div",{className:"flex w-full justify-center gap-4 pt-4 lg:gap-6",children:[jsxs("div",{className:"flex-auto min-w-0 flex flex-col gap-y-4 px-4 lg:gap-y-6 lg:px-0",children:[i&&jsx("div",{className:"flex items-center justify-between",children:jsx(Button,{as:"a",onPress:i,startContent:jsx(ChevronLeftIcon,{className:"h-4 w-4"}),className:"text-neutral bg-transparent h-5 min-h-5 gap-x-2 p-0 text-base w-auto min-w-auto",children:a("common.back")})}),jsx(cn,{eventSlug:e,source:t,onTradeAction:x})]}),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(Ge,{event:u,market:h,initialSide:m?.side,initialOutcome:m?.outcome,chain:r},I),u&&jsx(dn,{eventSlug:e,source:u.source,onEventClick:n})]})]}),u&&jsx("div",{className:"flex w-full flex-col",children:jsx(Dr,{event:u,walletAddress:o})})]})}function pn(e){return e.outcomes[0]?.best_ask??e.outcomes[0]?.price??0}function oi(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 gu=e=>{let{candlestickMarketSlugs:t,chartRange:r=Ye,source:o}=e,n=usePredictClient(),i=useMemo(()=>oi(r),[r]),{data:a,isLoading:l,error:s}=useEvent({slug:e.eventSlug,source:o}),c=useMemo(()=>a?.markets?(t&&t.length>0?t.slice(0,4).map(g=>a.markets.find(x=>x.slug===g)).filter(g=>g!==void 0):[...a.markets].sort((g,x)=>pn(x)-pn(g)).slice(0,4)).map(g=>g.slug):[],[t,a?.markets]),d=useQueries({queries:c.map(m=>({queryKey:candlesticksQueryKey(m,i),queryFn:()=>n.listCandlesticks(m,i),enabled:c.length>0}))}),u=d.some(m=>m.isLoading),p=useMemo(()=>{let m=new Map;return c.forEach((g,x)=>{let h=d[x]?.error;h&&m.set(g,h);}),m},[c,d]),f=useMemo(()=>{let m=new Map;return c.forEach((g,x)=>{let h=d[x]?.data;h&&m.set(g,h);}),m},[c,d]);return {event:a,isEventLoading:l,eventError:s,candlestickParams:i,candlesticks:f,isCandlesticksLoading:u,candlestickErrors:p}};var ii=10,li=atomWithStorage("liberfi:predict_search_histories",[],void 0,{getOnInit:true});function ct(){let[e,t]=useAtom(li),r=useCallback(n=>{let i=n.trim();i&&t(a=>{let l=a.filter(s=>s!==i);return [i,...l].slice(0,ii)});},[t]),o=useCallback(()=>{t([]);},[t]);return {histories:e,addHistory:r,clearHistories:o}}function vn({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(i=>jsx(Chip,{size:"sm",variant:"bordered",className:cn$1("text-neutral","border-border border-1","cursor-pointer","hover:opacity-hover"),onClick:()=>t?.(i),children:i},i))})]})}function xn({onSelect:e,className:t}){let{histories:r,clearHistories:o}=ct();return jsx(vn,{className:cn$1(t),histories:r,onSelect:e,onClear:o})}function hn({value:e,onValueChange:t,onClear:r,onEscape:o,className:n}){let{t:i}=useTranslation();return jsx("div",{className:n,children:jsx(StyledInput,{autoFocus:true,variant:"flat",radius:"full",value:e,onValueChange:t,placeholder:i("predict.search.placeholder"),startContent:jsx(SearchIcon,{width:20,height:20,className:"text-neutral"}),endContent:e?jsx(Button,{isIconOnly:true,className:"bg-transparent min-w-6 w-6 h-6 text-neutral",onPress: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 Sn({event:e,href:t,LinkComponent:r,onSelect:o,onHover:n,className:i}){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",i),onClick:l=>{t&&o&&l.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 kn({keyword:e="",limit:t,source:r}){let{data:o,isLoading:n,isFetchingNextPage:i,hasNextPage:a,fetchNextPage:l}=useSearchEvents({keyword:e,limit:t,source:r},{enabled:true});return {events:useMemo(()=>o?.pages.flatMap(c=>c.items).filter(c=>c!=null)??[],[o]),isLoading:n,isFetchingNextPage:i,hasNextPage:a??false,fetchNextPage:l}}var Li=56;function wn({onSelect:e,getEventHref:t,LinkComponent:r,onHover:o,className:n,...i}){let{events:a,isLoading:l,isFetchingNextPage:s,hasNextPage:c,fetchNextPage:d}=kn(i),u=useRef(null),{height:p}=useResizeObserver({ref:u}),f=useCallback(h=>h<a.length,[a]),m=useCallback(async()=>{c&&!s&&await d();},[c,s,d]),g=useMemo(()=>c?a.length+1:a.length,[a,c]),x=useInfiniteLoader({isRowLoaded:f,loadMoreRows:m,rowCount:g,threshold:5});return l?jsx(Ii,{className:n}):a.length===0?jsx(_i,{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:p},onRowsRendered:x,rowComponent:Oi,rowCount:g,rowHeight:Li,rowProps:{events:a,onSelect:e,getEventHref:t,LinkComponent:r,onHover:o},overscanCount:5})})})}function Oi({index:e,style:t,events:r,onSelect:o,getEventHref:n,LinkComponent:i,onHover:a}){let l=r[e];return l?jsx("div",{style:t,children:jsx(Sn,{event:l,href:n?.(l),LinkComponent:i,onSelect:o,onHover:a})}):jsx("div",{style:t,className:"flex items-center justify-center",children:jsx(Spinner,{size:"sm"})})}function Ii({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 _i({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 Rn({onKeywordChange:e}){let[t,r]=useState(""),[o,n]=useState(""),{addHistory:i}=ct(),a=useCallbackRef(e),l=useCallbackRef(i),s=useMemo(()=>debounce(p=>{n(p),a(p),p&&l(p);},500),[a,l]),c=useCallback(p=>{r(p),s(p);},[s]),d=useCallback(p=>{s.cancel(),r(p),n(p),a(p),p&&l(p);},[s,a,l]),u=useCallback(()=>d(""),[d]);return {text:t,keyword:o,setText:c,setKeyword:d,clearKeyword:u}}function Ln({onKeywordChange:e,onSelectEvent:t,getEventHref:r,LinkComponent:o,onHover:n,onEscape:i,source:a}){let{text:l,keyword:s,setText:c,setKeyword:d,clearKeyword:u}=Rn({onKeywordChange:e});return jsxs("div",{className:"w-full h-full flex flex-col gap-3",children:[jsx(hn,{value:l,onValueChange:c,onClear:u,onEscape:i}),!s&&jsx(xn,{onSelect:d}),jsx(wn,{className:"flex-auto min-h-0",keyword:s,onSelect:t,getEventHref:r,LinkComponent:o,onHover:n,source:a})]})}var Ut="predict-search";function Ip({id:e=Ut}){return jsx(AsyncModal,{id:e,children:t=>jsx(qi,{...t})})}function qi({params:e,isOpen:t,onOpenChange:r,onResult:o}){let{t:n}=useTranslation(),{isMobile:i}=useScreen(),a=useCallback(s=>{o(s);},[o]),l=useCallback(()=>{r(false);},[r]);return jsx(StyledModal,{isOpen:t,onOpenChange:r,size:i?"full":"lg",hideCloseButton:true,backdrop:"blur",radius:"lg",children:jsxs(ModalContent,{className:"w-full h-full",children:[jsxs(ModalHeader,{className:"sm:hidden flex items-center justify-between pt-4 pb-2",children:[jsx("span",{className:"text-base font-semibold",children: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(Ln,{getEventHref:e?.getEventHref,LinkComponent:e?.LinkComponent,onHover:e?.onHover,source:e?.source,onSelectEvent:a,onEscape:l})})]})})}function Wp({onSelectEvent:e,modalParams:t,className:r}){let{t:o}=useTranslation(),{isDesktop:n,isMobile:i}=useScreen(),{onOpen:a,onClose:l}=useAsyncModal(Ut),s=useCallbackRef(e),c=useCallbackRef(async()=>{let u=await a({params:t});u&&s(u);}),d=useCallbackRef(()=>{l();});return useEffect(()=>{let u=p=>{let f=document.activeElement,m=!!f&&(f.tagName==="INPUT"||f.tagName==="TEXTAREA"||f.getAttribute("contenteditable")==="true");p.key==="/"&&!m&&(p.preventDefault(),c()),p.key==="Escape"&&(p.preventDefault(),d());};return window.addEventListener("keydown",u),()=>{window.removeEventListener("keydown",u);}},[c,d]),jsx(Button,{size:"sm",radius:"full",isIconOnly:!n,onPress:c,variant:i?"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"})})}var sl=createContext(null);var al=3e4;function il({walletAddress:e,source:t,pollingInterval:r=al,enabled:o=true,children:n}){let i=o&&!!e,{data:a,isLoading:l,error:s,refetch:c}=usePositions({user:e,source:t},{enabled:i,refetchInterval:r}),{data:d,isLoading:u,error:p}=useBalance({user:e,source:t??"dflow"},{enabled:i,refetchInterval:r}),f=useMemo(()=>({positions:a?.positions??[],usdcBalance:d?Number(d.balance):0,isLoading:l||u,error:s??p??null,refetch:c}),[a?.positions,d,l,u,s,p,c]);return jsx(sl.Provider,{value:f,children:n})}export{Nl as CHART_RANGE_DURATION,Pl as CHART_RANGE_PERIOD,El as CHART_RANGE_SAMPLE_INTERVAL,Ve as CandlestickPeriod,fl as CategoriesSkeleton,qt as CategoriesUI,Xt as CategoriesWidget,X as ChartRange,Ye as DEFAULT_CHART_RANGE,yt as DEFAULT_FILTER_STATE,Ie as DEFAULT_PAGE_SIZE,Ml as DEFAULT_PRICE_HISTORY_INTERVAL,lu as EventDetailPage,Be as EventDetailSkeleton,ln as EventDetailUI,cn as EventDetailWidget,Er as EventItem,Wr as EventMarketDepthChartUI,jr as EventMarketDetailWidget,Zr as EventPriceChart,ar as EventsFilterUI,Qc as EventsPage,yc as EventsPageSkeleton,kt as EventsSkeleton,ur as EventsToolbarUI,Rr as EventsUI,Or as EventsWidget,ft as MAX_PRICE_HISTORY_MARKETS,Tl as ORDER_MAX_PRICE,Cl as ORDER_MIN_PRICE,gt as ORDER_MIN_QUANTITY,wl as ORDER_PRICE_STEP,Ut as PREDICT_SEARCH_MODAL_ID,bt as PREDICT_TRADE_MODAL_ID,Rl as PRICE_HISTORY_SAMPLE_INTERVAL,Ip as PredictSearchModal,or as PredictTradeModal,xe as PriceHistoryInterval,dr as SORT_PRESETS,mt as STATIC_CATEGORIES,Wp as SearchEventsButton,vn as SearchHistoryUI,xn as SearchHistoryWidget,hn as SearchInputUI,Sn as SearchResultItemUI,wn as SearchResultListWidget,Ln as SearchWidget,Ka as SimilarEventCard,dn as SimilarEventsSection,Hr as TradeFormSkeleton,rr as TradeFormUI,Ge as TradeFormWidget,Dr as UserActivitySection,il as UserPredictProvider,St as countActiveFilters,Ue as formatWan,gu as useEventDetail,fr as useEventsInfinite,ct as usePredictSearchHistory,kn as useSearchResultListScript,Rn as useSearchScript,Jt as useTradeForm,Un as version};//# sourceMappingURL=index.mjs.map
|
|
21
|
+
`):d.description??"";if(!u)return null;let f=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")}),c.length>1&&jsxs(Dropdown,{placement:"bottom-end",classNames:{content:"min-w-36 bg-content1 border border-border"},children:[jsx(DropdownTrigger,{children:jsx(Button,{size:"sm",variant:"bordered",radius:"lg",endContent:jsx(ChevronDownIcon,{className:"h-3.5 w-3.5"}),className:"text-xs text-foreground",children:dt(d)})}),jsx(DropdownMenu,{"aria-label":"Select market rules",selectionMode:"single",selectedKeys:[String(s)],onAction:p=>{l(Number(p)),n(false);},classNames:{list:"gap-1"},itemClasses:{base:"rounded-md px-3 h-8"},children:c.map((p,m)=>jsx(DropdownItem,{className:cn$1(m===s?"bg-content2 text-foreground":"text-neutral","data-[hover=true]:bg-content2 data-[hover=true]:text-foreground"),children:dt(p)},String(m)))})]})]}),jsx("div",{className:"text-xs text-foreground/80 lg:text-sm whitespace-pre-wrap",children:f}),u.length>200&&jsx("button",{type:"button",onClick:()=>n(p=>!p),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:()=>i(p=>!p),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",a&&"rotate-180")})]}),a&&jsxs(Fragment,{children:[jsx("div",{className:"flex flex-col",children:(()=>{let p=d.status,m=[];return d.created_at&&m.push({label:r("predict.event.timeline.created"),value:Ve(d.created_at),isActive:true}),m.push({label:r("predict.event.timeline.open"),value:Ve(d.start_at),isActive:p!=="pending"}),p==="voided"?m.push({label:r("predict.event.timeline.voided"),value:Ve(d.closed_at??d.end_at),isActive:true}):p==="closed"?m.push({label:r("predict.event.timeline.closed"),value:Ve(d.closed_at??d.end_at),isActive:true}):m.push({label:r("predict.event.timeline.close"),value:Ve(d.end_at),isActive:false}),m})().map((p,m,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 ${p.isActive?"border-primary bg-primary":"border-border bg-transparent"}`}),m<g.length-1&&jsx("div",{className:"w-px flex-1 bg-border"})]}),jsxs("div",{className:`flex flex-col ${m<g.length-1?"pb-4":""}`,children:[jsx("span",{className:"text-xs font-medium text-foreground lg:text-sm",children:p.label}),jsx("span",{className:"text-xs text-neutral lg:text-sm",children:p.value})]})]},p.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:d.slug})]}),jsxs("span",{children:[jsxs("span",{className:"text-neutral",children:[r("predict.event.id.source"),":"]})," ",jsx("span",{className:"text-foreground",children:Yi(d.source)})]})]})]})]})}function Xi({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 xn({eventSlug:e,source:t,onTradeAction:r}){let{data:o,isLoading:n,error:a}=useEvent({slug:e,source:t});return n?jsx(ze,{}):a||!o?jsx("div",{className:"flex w-full items-center justify-center py-20 text-danger",children:a?.message||"Event not found"}):jsx(vn,{event:o,onTradeAction:r})}function hn({eventSlug:e,source:t,limit:r=4,onEventClick:o}){let{t:n}=useTranslation(),{data:a,isLoading:i}=useSimilarEvents({slug:e,source:t,limit:r});return i||!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:n("predict.similar.title")}),jsx("div",{className:"grid grid-cols-1 gap-3",children:a.map(s=>jsx(ra,{event:s,onClick:o},s.slug))})]})}function ra({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 bn(e){return e.outcomes[0]?.best_ask??e.outcomes[0]?.price??0}function wu({eventSlug:e,source:t,chain:r,walletAddress:o,onSimilarEventClick:n,onBack:a}){let{t:i}=useTranslation(),{isMobile:s}=useScreen(),{isOpen:l,onOpen:c,onClose:d}=useDisclosure(),{data:u,isLoading:f}=useEvent({slug:e,source:t}),p=useMemo(()=>[...u?.markets||[]].sort((M,N)=>bn(N)-bn(M)),[u?.markets]),[m,g]=useState(null),x=useCallback((M,N,C)=>{g(B=>({market:M,outcome:N,side:C,version:(B?.version??0)+1})),s&&c();},[s,c]),v=m?.market??p[0];if(f){let M=!!a;return s?jsx(ze,{showBack:M}):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(ze,{showBack:M})}),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(qr,{})})})]})}let _=m?`${m.market.slug}-${m.version}`:v?.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:i("common.back")})}),jsx(xn,{eventSlug:e,source:t,onTradeAction:x})]}),jsxs("div",{className:"hidden flex-none w-md flex-col gap-y-4 lg:sticky lg:top-4 lg:flex lg:self-start",children:[v&&jsx(et,{event:u,market:v,initialSide:m?.side,initialOutcome:m?.outcome,chain:r},_),u&&jsx(hn,{eventSlug:e,source:u.source,onEventClick:n})]})]}),u&&jsx("div",{className:"flex w-full flex-col",children:jsx(jr,{event:u,walletAddress:o})})]})}function yn(e){return e.outcomes[0]?.best_ask??e.outcomes[0]?.price??0}function va(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 Mu=e=>{let{candlestickMarketSlugs:t,chartRange:r=Qe,source:o}=e,n=usePredictClient(),a=useMemo(()=>va(r),[r]),{data:i,isLoading:s,error:l}=useEvent({slug:e.eventSlug,source:o}),c=useMemo(()=>i?.markets?(t&&t.length>0?t.slice(0,4).map(g=>i.markets.find(x=>x.slug===g)).filter(g=>g!==void 0):[...i.markets].sort((g,x)=>yn(x)-yn(g)).slice(0,4)).map(g=>g.slug):[],[t,i?.markets]),d=useQueries({queries:c.map(m=>({queryKey:candlesticksQueryKey(m,a),queryFn:()=>n.listCandlesticks(m,a),enabled:c.length>0}))}),u=d.some(m=>m.isLoading),f=useMemo(()=>{let m=new Map;return c.forEach((g,x)=>{let v=d[x]?.error;v&&m.set(g,v);}),m},[c,d]),p=useMemo(()=>{let m=new Map;return c.forEach((g,x)=>{let v=d[x]?.data;v&&m.set(g,v);}),m},[c,d]);return {event:i,isEventLoading:s,eventError:l,candlestickParams:a,candlesticks:p,isCandlesticksLoading:u,candlestickErrors:f}};var ba=10,ya=atomWithStorage("liberfi:predict_search_histories",[],void 0,{getOnInit:true});function gt(){let[e,t]=useAtom(ya),r=useCallback(n=>{let a=n.trim();a&&t(i=>{let s=i.filter(l=>l!==a);return [a,...s].slice(0,ba)});},[t]),o=useCallback(()=>{t([]);},[t]);return {histories:e,addHistory:r,clearHistories:o}}function Nn({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(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 Pn({onSelect:e,className:t}){let{histories:r,clearHistories:o}=gt();return jsx(Nn,{className:cn$1(t),histories:r,onSelect:e,onClear:o})}function En({value:e,onValueChange:t,onClear:r,onEscape:o,className:n}){let{t:a}=useTranslation();return jsx("div",{className:n,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: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:i=>{i.preventDefault(),o?.();},children:"Esc"})})})}function Mn({event:e,href:t,LinkComponent:r,onSelect:o,onHover:n,className:a}){let i=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",a),onClick:s=>{t&&o&&s.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}),i&&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:i.label})]})]})}function Rn({keyword:e="",limit:t,source:r}){let{data:o,isLoading:n,isFetchingNextPage:a,hasNextPage:i,fetchNextPage:s}=useSearchEvents({keyword:e,limit:t,source:r},{enabled:true});return {events:useMemo(()=>o?.pages.flatMap(c=>c.items).filter(c=>c!=null)??[],[o]),isLoading:n,isFetchingNextPage:a,hasNextPage:i??false,fetchNextPage:s}}var za=56;function _n({onSelect:e,getEventHref:t,LinkComponent:r,onHover:o,className:n,...a}){let{events:i,isLoading:s,isFetchingNextPage:l,hasNextPage:c,fetchNextPage:d}=Rn(a),u=useRef(null),{height:f}=useResizeObserver({ref:u}),p=useCallback(v=>v<i.length,[i]),m=useCallback(async()=>{c&&!l&&await d();},[c,l,d]),g=useMemo(()=>c?i.length+1:i.length,[i,c]),x=useInfiniteLoader({isRowLoaded:p,loadMoreRows:m,rowCount:g,threshold:5});return s?jsx(Va,{className:n}):i.length===0?jsx(Ya,{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:f},onRowsRendered:x,rowComponent:Ka,rowCount:g,rowHeight:za,rowProps:{events:i,onSelect:e,getEventHref:t,LinkComponent:r,onHover:o},overscanCount:5})})})}function Ka({index:e,style:t,events:r,onSelect:o,getEventHref:n,LinkComponent:a,onHover:i}){let s=r[e];return s?jsx("div",{style:t,children:jsx(Mn,{event:s,href:n?.(s),LinkComponent:a,onSelect:o,onHover:i})}):jsx("div",{style:t,className:"flex items-center justify-center",children:jsx(Spinner,{size:"sm"})})}function Va({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 Ya({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 Fn({onKeywordChange:e}){let[t,r]=useState(""),[o,n]=useState(""),{addHistory:a}=gt(),i=useCallbackRef(e),s=useCallbackRef(a),l=useMemo(()=>debounce(f=>{n(f),i(f),f&&s(f);},500),[i,s]),c=useCallback(f=>{r(f),l(f);},[l]),d=useCallback(f=>{l.cancel(),r(f),n(f),i(f),f&&s(f);},[l,i,s]),u=useCallback(()=>d(""),[d]);return {text:t,keyword:o,setText:c,setKeyword:d,clearKeyword:u}}function Bn({onKeywordChange:e,onSelectEvent:t,getEventHref:r,LinkComponent:o,onHover:n,onEscape:a,source:i}){let{text:s,keyword:l,setText:c,setKeyword:d,clearKeyword:u}=Fn({onKeywordChange:e});return jsxs("div",{className:"w-full h-full flex flex-col gap-3",children:[jsx(En,{value:s,onValueChange:c,onClear:u,onEscape:a}),!l&&jsx(Pn,{onSelect:d}),jsx(_n,{className:"flex-auto min-h-0",keyword:l,onSelect:t,getEventHref:r,LinkComponent:o,onHover:n,source:i})]})}var Xt="predict-search";function jp({id:e=Xt}){return jsx(AsyncModal,{id:e,children:t=>jsx(sl,{...t})})}function sl({params:e,isOpen:t,onOpenChange:r,onResult:o}){let{t:n}=useTranslation(),{isMobile:a}=useScreen(),i=useCallback(l=>{o(l);},[o]),s=useCallback(()=>{r(false);},[r]);return jsx(StyledModal,{isOpen:t,onOpenChange:r,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: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(Bn,{getEventHref:e?.getEventHref,LinkComponent:e?.LinkComponent,onHover:e?.onHover,source:e?.source,onSelectEvent:i,onEscape:s})})]})})}function rm({onSelectEvent:e,modalParams:t,className:r}){let{t:o}=useTranslation(),{isDesktop:n,isMobile:a}=useScreen(),{onOpen:i,onClose:s}=useAsyncModal(Xt),l=useCallbackRef(e),c=useCallbackRef(async()=>{let u=await i({params:t});u&&l(u);}),d=useCallbackRef(()=>{s();});return useEffect(()=>{let u=f=>{let p=document.activeElement,m=!!p&&(p.tagName==="INPUT"||p.tagName==="TEXTAREA"||p.getAttribute("contenteditable")==="true");f.key==="/"&&!m&&(f.preventDefault(),c()),f.key==="Escape"&&(f.preventDefault(),d());};return window.addEventListener("keydown",u),()=>{window.removeEventListener("keydown",u);}},[c,d]),jsx(Button,{size:"sm",radius:"full",isIconOnly:!n,onPress:c,variant:a?"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"})})}var xl=createContext(null);var hl=3e4;function bl({walletAddress:e,source:t,pollingInterval:r=hl,enabled:o=true,children:n}){let a=o&&!!e,{data:i,isLoading:s,error:l,refetch:c}=usePositions({user:e,source:t},{enabled:a,refetchInterval:r}),{data:d,isLoading:u,error:f}=useBalance({user:e,source:t??"dflow"},{enabled:a,refetchInterval:r}),p=useMemo(()=>({positions:i?.positions??[],usdcBalance:d?Number(d.balance):0,isLoading:s||u,error:l??f??null,refetch:c}),[i?.positions,d,s,u,l,f,c]);return jsx(xl.Provider,{value:p,children:n})}export{Hl as CHART_RANGE_DURATION,Al as CHART_RANGE_PERIOD,Dl as CHART_RANGE_SAMPLE_INTERVAL,Xe as CandlestickPeriod,El as CategoriesSkeleton,nr as CategoriesUI,ir as CategoriesWidget,J as ChartRange,Qe as DEFAULT_CHART_RANGE,Et as DEFAULT_FILTER_STATE,_e as DEFAULT_PAGE_SIZE,$l as DEFAULT_PRICE_HISTORY_INTERVAL,wu as EventDetailPage,ze as EventDetailSkeleton,vn as EventDetailUI,xn as EventDetailWidget,_r as EventItem,Jr as EventMarketDepthChartUI,sn as EventMarketDetailWidget,dn as EventPriceChart,vr as EventsFilterUI,cd as EventsPage,Ic as EventsPageSkeleton,Tt as EventsSkeleton,Sr as EventsToolbarUI,Ur as EventsUI,Wr as EventsWidget,yt as MAX_PRICE_HISTORY_MARKETS,Ul as ORDER_MAX_PRICE,Bl as ORDER_MIN_PRICE,St as ORDER_MIN_QUANTITY,Fl as ORDER_PRICE_STEP,Xt as PREDICT_SEARCH_MODAL_ID,Pt as PREDICT_TRADE_MODAL_ID,Wl as PRICE_HISTORY_SAMPLE_INTERVAL,jp as PredictSearchModal,fr as PredictTradeModal,be as PriceHistoryInterval,yr as SORT_PRESETS,bt as STATIC_CATEGORIES,rm as SearchEventsButton,Nn as SearchHistoryUI,Pn as SearchHistoryWidget,En as SearchInputUI,Mn as SearchResultItemUI,_n as SearchResultListWidget,Bn as SearchWidget,ra as SimilarEventCard,hn as SimilarEventsSection,qr as TradeFormSkeleton,pr as TradeFormUI,et as TradeFormWidget,jr as UserActivitySection,bl as UserPredictProvider,Ct as countActiveFilters,Ke as formatWan,Mu as useEventDetail,Nr as useEventsInfinite,gt as usePredictSearchHistory,Rn as useSearchResultListScript,Fn as useSearchScript,cr as useTradeForm,qn as version};//# sourceMappingURL=index.mjs.map
|
|
22
22
|
//# sourceMappingURL=index.mjs.map
|