@agg-market/ui 4.0.0 → 6.0.0

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.
Files changed (516) hide show
  1. package/README.md +26 -26
  2. package/dist/auth.d.mts +1 -0
  3. package/dist/auth.d.ts +1 -0
  4. package/dist/{connect-button.js → auth.js} +6 -4
  5. package/dist/auth.mjs +8 -0
  6. package/dist/chunk-2ICOSP7N.mjs +1211 -0
  7. package/dist/chunk-5ZKPBMRK.mjs +2411 -0
  8. package/dist/{chunk-5K7VXAYM.mjs → chunk-ADGL6RFX.mjs} +2 -4
  9. package/dist/chunk-BXW3VIKV.mjs +90 -0
  10. package/dist/{chart.js → chunk-CN7GI2RJ.mjs} +250 -103
  11. package/dist/chunk-G6YKGVQR.mjs +769 -0
  12. package/dist/{chunk-PZTHM6WG.mjs → chunk-HI4EEDN5.mjs} +897 -357
  13. package/dist/{chunk-5ADMXO3Y.mjs → chunk-INRG3D4M.mjs} +5 -11
  14. package/dist/{chunk-DCORNTCY.mjs → chunk-JE3Z52FD.mjs} +85 -64
  15. package/dist/chunk-KZOQW6NT.mjs +0 -0
  16. package/dist/chunk-LMOJKJOY.mjs +2616 -0
  17. package/dist/{chunk-YJA5VQW6.mjs → chunk-MHCHR65A.mjs} +2 -4
  18. package/dist/{chunk-IGPNIM2B.mjs → chunk-PASXFYKQ.mjs} +2 -4
  19. package/dist/chunk-UBBOLLOS.mjs +999 -0
  20. package/dist/events.d.mts +1 -0
  21. package/dist/events.d.ts +1 -0
  22. package/dist/{event-market-page.js → events.js} +5128 -5274
  23. package/dist/events.mjs +17 -0
  24. package/dist/index.d.mts +1 -78
  25. package/dist/index.d.ts +1 -78
  26. package/dist/index.js +8738 -8534
  27. package/dist/index.mjs +68 -167
  28. package/dist/modals.d.mts +1 -0
  29. package/dist/modals.d.ts +1 -0
  30. package/dist/{deposit-modal.js → modals.js} +1771 -6
  31. package/dist/modals.mjs +25 -0
  32. package/dist/pages.d.mts +1 -0
  33. package/dist/pages.d.ts +1 -0
  34. package/dist/pages.js +7928 -0
  35. package/dist/pages.mjs +16 -0
  36. package/dist/primitives.d.mts +1 -0
  37. package/dist/primitives.d.ts +1 -0
  38. package/dist/{market-details.js → primitives.js} +2980 -3153
  39. package/dist/{icon.mjs → primitives.mjs} +56 -9
  40. package/dist/styles.css +1 -1
  41. package/dist/tailwind.css +1 -1
  42. package/dist/trading.d.mts +1 -0
  43. package/dist/trading.d.ts +1 -0
  44. package/dist/{place-order.js → trading.js} +1907 -1394
  45. package/dist/trading.mjs +65 -0
  46. package/dist/types/auth/connect-button/connect-button.constants.d.mts +10 -0
  47. package/dist/types/auth/connect-button/connect-button.constants.d.ts +10 -0
  48. package/dist/{connect-button.d.mts → types/auth/connect-button/connect-button.types.d.mts} +5 -12
  49. package/dist/{connect-button.d.ts → types/auth/connect-button/connect-button.types.d.ts} +5 -12
  50. package/dist/types/auth/connect-button/index.d.mts +7 -0
  51. package/dist/types/auth/connect-button/index.d.ts +7 -0
  52. package/dist/types/auth/index.d.mts +1 -0
  53. package/dist/types/auth/index.d.ts +1 -0
  54. package/dist/types/constants.d.mts +1 -0
  55. package/dist/types/constants.d.ts +1 -0
  56. package/dist/types/deposit/deposit-modal.constants.d.mts +9 -0
  57. package/dist/types/deposit/deposit-modal.constants.d.ts +9 -0
  58. package/dist/{deposit-modal.d.mts → types/deposit/deposit-modal.types.d.mts} +3 -10
  59. package/dist/{deposit-modal.d.ts → types/deposit/deposit-modal.types.d.ts} +3 -10
  60. package/dist/types/deposit/index.d.mts +6 -0
  61. package/dist/types/deposit/index.d.ts +6 -0
  62. package/dist/types/deposit/steps/card-deposit.d.mts +7 -0
  63. package/dist/types/deposit/steps/card-deposit.d.ts +7 -0
  64. package/dist/types/deposit/steps/crypto-transfer.d.mts +7 -0
  65. package/dist/types/deposit/steps/crypto-transfer.d.ts +7 -0
  66. package/dist/types/deposit/steps/deposit-method.d.mts +7 -0
  67. package/dist/types/deposit/steps/deposit-method.d.ts +7 -0
  68. package/dist/types/deposit/steps/kalshi-deposit.d.mts +5 -0
  69. package/dist/types/deposit/steps/kalshi-deposit.d.ts +5 -0
  70. package/dist/types/deposit/steps/venue-selection.d.mts +7 -0
  71. package/dist/types/deposit/steps/venue-selection.d.ts +7 -0
  72. package/dist/types/events/index.d.mts +4 -0
  73. package/dist/types/events/index.d.ts +4 -0
  74. package/dist/types/events/item/event-list-item.constants.d.mts +1 -0
  75. package/dist/types/events/item/event-list-item.constants.d.ts +1 -0
  76. package/dist/types/events/item/event-list-item.types.d.mts +46 -0
  77. package/dist/types/events/item/event-list-item.types.d.ts +46 -0
  78. package/dist/types/events/item/event-list-item.utils.d.mts +23 -0
  79. package/dist/types/events/item/event-list-item.utils.d.ts +23 -0
  80. package/dist/types/events/item/index.d.mts +6 -0
  81. package/dist/types/events/item/index.d.ts +6 -0
  82. package/dist/types/events/item-details/event-list-item-details.constants.d.mts +10 -0
  83. package/dist/types/events/item-details/event-list-item-details.constants.d.ts +10 -0
  84. package/dist/types/events/item-details/event-list-item-details.types.d.mts +53 -0
  85. package/dist/types/events/item-details/event-list-item-details.types.d.ts +53 -0
  86. package/dist/types/events/item-details/event-list-item-details.utils.d.mts +26 -0
  87. package/dist/types/events/item-details/event-list-item-details.utils.d.ts +26 -0
  88. package/dist/types/events/item-details/index.d.mts +6 -0
  89. package/dist/types/events/item-details/index.d.ts +6 -0
  90. package/dist/types/events/list/event-list.constants.d.mts +3 -0
  91. package/dist/types/events/list/event-list.constants.d.ts +3 -0
  92. package/dist/types/events/list/event-list.types.d.mts +21 -0
  93. package/dist/types/events/list/event-list.types.d.ts +21 -0
  94. package/dist/types/events/list/event-list.utils.d.mts +6 -0
  95. package/dist/types/events/list/event-list.utils.d.ts +6 -0
  96. package/dist/types/events/list/index.d.mts +6 -0
  97. package/dist/types/events/list/index.d.ts +6 -0
  98. package/dist/types/events/market-details/index.d.mts +6 -0
  99. package/dist/types/events/market-details/index.d.ts +6 -0
  100. package/dist/types/events/market-details/market-details.constants.d.mts +9 -0
  101. package/dist/types/events/market-details/market-details.constants.d.ts +9 -0
  102. package/dist/types/events/market-details/market-details.types.d.mts +63 -0
  103. package/dist/types/events/market-details/market-details.types.d.ts +63 -0
  104. package/dist/types/events/market-details/market-details.utils.d.mts +46 -0
  105. package/dist/types/events/market-details/market-details.utils.d.ts +46 -0
  106. package/dist/types/index.d.mts +9 -0
  107. package/dist/types/index.d.ts +9 -0
  108. package/dist/types/modals/index.d.mts +4 -0
  109. package/dist/types/modals/index.d.ts +4 -0
  110. package/dist/types/onboarding/index.d.mts +11 -0
  111. package/dist/types/onboarding/index.d.ts +11 -0
  112. package/dist/types/onboarding/onboarding-modal.constants.d.mts +10 -0
  113. package/dist/types/onboarding/onboarding-modal.constants.d.ts +10 -0
  114. package/dist/types/onboarding/onboarding-modal.types.d.mts +55 -0
  115. package/dist/types/onboarding/onboarding-modal.types.d.ts +55 -0
  116. package/dist/types/onboarding/steps/connect-accounts.d.mts +5 -0
  117. package/dist/types/onboarding/steps/connect-accounts.d.ts +5 -0
  118. package/dist/types/onboarding/steps/connect-kalshi-modal.d.mts +5 -0
  119. package/dist/types/onboarding/steps/connect-kalshi-modal.d.ts +5 -0
  120. package/dist/types/onboarding/steps/connect-onchain-modal.d.mts +5 -0
  121. package/dist/types/onboarding/steps/connect-onchain-modal.d.ts +5 -0
  122. package/dist/types/onboarding/steps/how-it-works.d.mts +5 -0
  123. package/dist/types/onboarding/steps/how-it-works.d.ts +5 -0
  124. package/dist/types/onboarding/steps/profile-setup.d.mts +5 -0
  125. package/dist/types/onboarding/steps/profile-setup.d.ts +5 -0
  126. package/dist/types/pages/event-market/event-market.types.d.mts +42 -0
  127. package/dist/types/pages/event-market/event-market.types.d.ts +42 -0
  128. package/dist/types/pages/event-market/index.d.mts +6 -0
  129. package/dist/types/pages/event-market/index.d.ts +6 -0
  130. package/dist/types/pages/home/home.constants.d.mts +8 -0
  131. package/dist/types/pages/home/home.constants.d.ts +8 -0
  132. package/dist/{home-page.d.ts → types/pages/home/home.types.d.mts} +8 -18
  133. package/dist/{home-page.d.mts → types/pages/home/home.types.d.ts} +8 -18
  134. package/dist/types/pages/home/home.utils.d.mts +3 -0
  135. package/dist/types/pages/home/home.utils.d.ts +3 -0
  136. package/dist/types/pages/home/index.d.mts +6 -0
  137. package/dist/types/pages/home/index.d.ts +6 -0
  138. package/dist/types/pages/index.d.mts +3 -0
  139. package/dist/types/pages/index.d.ts +3 -0
  140. package/dist/types/pages/user-profile/components/activity-row.d.mts +10 -0
  141. package/dist/types/pages/user-profile/components/activity-row.d.ts +10 -0
  142. package/dist/types/pages/user-profile/components/balance-display.d.mts +12 -0
  143. package/dist/types/pages/user-profile/components/balance-display.d.ts +12 -0
  144. package/dist/types/pages/user-profile/components/balances-card.d.mts +12 -0
  145. package/dist/types/pages/user-profile/components/balances-card.d.ts +12 -0
  146. package/dist/types/pages/user-profile/components/default-avatar.d.mts +8 -0
  147. package/dist/types/pages/user-profile/components/default-avatar.d.ts +8 -0
  148. package/dist/types/pages/user-profile/components/empty-state.d.mts +10 -0
  149. package/dist/types/pages/user-profile/components/empty-state.d.ts +10 -0
  150. package/dist/types/pages/user-profile/components/position-row.d.mts +10 -0
  151. package/dist/types/pages/user-profile/components/position-row.d.ts +10 -0
  152. package/dist/types/pages/user-profile/components/positions-activity.d.mts +14 -0
  153. package/dist/types/pages/user-profile/components/positions-activity.d.ts +14 -0
  154. package/dist/types/pages/user-profile/components/user-info-card.d.mts +11 -0
  155. package/dist/types/pages/user-profile/components/user-info-card.d.ts +11 -0
  156. package/dist/types/pages/user-profile/index.d.mts +6 -0
  157. package/dist/types/pages/user-profile/index.d.ts +6 -0
  158. package/dist/types/pages/user-profile/user-profile.constants.d.mts +9 -0
  159. package/dist/types/pages/user-profile/user-profile.constants.d.ts +9 -0
  160. package/dist/{user-profile-page.d.ts → types/pages/user-profile/user-profile.types.d.mts} +12 -22
  161. package/dist/{user-profile-page.d.mts → types/pages/user-profile/user-profile.types.d.ts} +12 -22
  162. package/dist/types/primitives/badge/badge.constants.d.mts +4 -0
  163. package/dist/types/primitives/badge/badge.constants.d.ts +4 -0
  164. package/dist/types/primitives/badge/badge.types.d.mts +18 -0
  165. package/dist/types/primitives/badge/badge.types.d.ts +18 -0
  166. package/dist/types/primitives/badge/index.d.mts +7 -0
  167. package/dist/types/primitives/badge/index.d.ts +7 -0
  168. package/dist/types/primitives/button/button.constants.d.mts +6 -0
  169. package/dist/types/primitives/button/button.constants.d.ts +6 -0
  170. package/dist/types/primitives/button/button.types.d.mts +12 -0
  171. package/dist/types/primitives/button/button.types.d.ts +12 -0
  172. package/dist/types/primitives/button/index.d.mts +6 -0
  173. package/dist/types/primitives/button/index.d.ts +6 -0
  174. package/dist/types/primitives/card/card.types.d.mts +3 -0
  175. package/dist/types/primitives/card/card.types.d.ts +3 -0
  176. package/dist/types/primitives/card/index.d.mts +6 -0
  177. package/dist/types/primitives/card/index.d.ts +6 -0
  178. package/dist/{chart.d.mts → types/primitives/chart/index.d.mts} +7 -10
  179. package/dist/{chart.d.ts → types/primitives/chart/index.d.ts} +7 -10
  180. package/dist/types/primitives/hello-world.d.mts +4 -0
  181. package/dist/types/primitives/hello-world.d.ts +4 -0
  182. package/dist/types/primitives/icon/icon.constants.d.mts +2 -0
  183. package/dist/types/primitives/icon/icon.constants.d.ts +2 -0
  184. package/dist/types/primitives/icon/icon.types.d.mts +9 -0
  185. package/dist/types/primitives/icon/icon.types.d.ts +9 -0
  186. package/dist/types/primitives/icon/icon.utils.d.mts +2 -0
  187. package/dist/types/primitives/icon/icon.utils.d.ts +2 -0
  188. package/dist/types/primitives/icon/index.d.mts +46 -0
  189. package/dist/types/primitives/icon/index.d.ts +46 -0
  190. package/dist/types/primitives/icon/registry.d.mts +166 -0
  191. package/dist/types/primitives/icon/registry.d.ts +166 -0
  192. package/dist/types/primitives/icon/svg/arrow-trend-up.d.mts +5 -0
  193. package/dist/types/primitives/icon/svg/arrow-trend-up.d.ts +5 -0
  194. package/dist/types/primitives/icon/svg/arrows-to-dot.d.mts +5 -0
  195. package/dist/types/primitives/icon/svg/arrows-to-dot.d.ts +5 -0
  196. package/dist/types/primitives/icon/svg/bank.d.mts +5 -0
  197. package/dist/types/primitives/icon/svg/bank.d.ts +5 -0
  198. package/dist/types/primitives/icon/svg/best-prices.d.mts +5 -0
  199. package/dist/types/primitives/icon/svg/best-prices.d.ts +5 -0
  200. package/dist/types/primitives/icon/svg/bolt.d.mts +5 -0
  201. package/dist/types/primitives/icon/svg/bolt.d.ts +5 -0
  202. package/dist/types/primitives/icon/svg/check-badge.d.mts +5 -0
  203. package/dist/types/primitives/icon/svg/check-badge.d.ts +5 -0
  204. package/dist/types/primitives/icon/svg/check-circle.d.mts +5 -0
  205. package/dist/types/primitives/icon/svg/check-circle.d.ts +5 -0
  206. package/dist/types/primitives/icon/svg/chevron-down.d.mts +5 -0
  207. package/dist/types/primitives/icon/svg/chevron-down.d.ts +5 -0
  208. package/dist/types/primitives/icon/svg/chevron-left.d.mts +5 -0
  209. package/dist/types/primitives/icon/svg/chevron-left.d.ts +5 -0
  210. package/dist/types/primitives/icon/svg/chevron-right.d.mts +5 -0
  211. package/dist/types/primitives/icon/svg/chevron-right.d.ts +5 -0
  212. package/dist/types/primitives/icon/svg/chevron-up.d.mts +5 -0
  213. package/dist/types/primitives/icon/svg/chevron-up.d.ts +5 -0
  214. package/dist/types/primitives/icon/svg/close.d.mts +5 -0
  215. package/dist/types/primitives/icon/svg/close.d.ts +5 -0
  216. package/dist/types/primitives/icon/svg/copy.d.mts +5 -0
  217. package/dist/types/primitives/icon/svg/copy.d.ts +5 -0
  218. package/dist/types/primitives/icon/svg/create-account.d.mts +5 -0
  219. package/dist/types/primitives/icon/svg/create-account.d.ts +5 -0
  220. package/dist/types/primitives/icon/svg/credit-card.d.mts +5 -0
  221. package/dist/types/primitives/icon/svg/credit-card.d.ts +5 -0
  222. package/dist/types/primitives/icon/svg/disconnect.d.mts +5 -0
  223. package/dist/types/primitives/icon/svg/disconnect.d.ts +5 -0
  224. package/dist/types/primitives/icon/svg/discord.d.mts +5 -0
  225. package/dist/types/primitives/icon/svg/discord.d.ts +5 -0
  226. package/dist/types/primitives/icon/svg/document.d.mts +5 -0
  227. package/dist/types/primitives/icon/svg/document.d.ts +5 -0
  228. package/dist/types/primitives/icon/svg/dots-horizontal.d.mts +5 -0
  229. package/dist/types/primitives/icon/svg/dots-horizontal.d.ts +5 -0
  230. package/dist/types/primitives/icon/svg/download.d.mts +5 -0
  231. package/dist/types/primitives/icon/svg/download.d.ts +5 -0
  232. package/dist/types/primitives/icon/svg/email.d.mts +5 -0
  233. package/dist/types/primitives/icon/svg/email.d.ts +5 -0
  234. package/dist/types/primitives/icon/svg/external-link.d.mts +5 -0
  235. package/dist/types/primitives/icon/svg/external-link.d.ts +5 -0
  236. package/dist/types/primitives/icon/svg/info.d.mts +5 -0
  237. package/dist/types/primitives/icon/svg/info.d.ts +5 -0
  238. package/dist/types/primitives/icon/svg/link-accounts.d.mts +5 -0
  239. package/dist/types/primitives/icon/svg/link-accounts.d.ts +5 -0
  240. package/dist/types/primitives/icon/svg/pencil.d.mts +5 -0
  241. package/dist/types/primitives/icon/svg/pencil.d.ts +5 -0
  242. package/dist/types/primitives/icon/svg/play-square.d.mts +5 -0
  243. package/dist/types/primitives/icon/svg/play-square.d.ts +5 -0
  244. package/dist/types/primitives/icon/svg/profile.d.mts +5 -0
  245. package/dist/types/primitives/icon/svg/profile.d.ts +5 -0
  246. package/dist/types/primitives/icon/svg/revenue-alt.d.mts +5 -0
  247. package/dist/types/primitives/icon/svg/revenue-alt.d.ts +5 -0
  248. package/dist/types/primitives/icon/svg/search.d.mts +5 -0
  249. package/dist/types/primitives/icon/svg/search.d.ts +5 -0
  250. package/dist/types/primitives/icon/svg/shield-trust.d.mts +5 -0
  251. package/dist/types/primitives/icon/svg/shield-trust.d.ts +5 -0
  252. package/dist/types/primitives/icon/svg/stay-in-control.d.mts +5 -0
  253. package/dist/types/primitives/icon/svg/stay-in-control.d.ts +5 -0
  254. package/dist/types/primitives/icon/svg/telegram.d.mts +5 -0
  255. package/dist/types/primitives/icon/svg/telegram.d.ts +5 -0
  256. package/dist/types/primitives/icon/svg/triangle-down.d.mts +5 -0
  257. package/dist/types/primitives/icon/svg/triangle-down.d.ts +5 -0
  258. package/dist/types/primitives/icon/svg/triangle-up-filled.d.mts +5 -0
  259. package/dist/types/primitives/icon/svg/triangle-up-filled.d.ts +5 -0
  260. package/dist/types/primitives/icon/svg/triangle-up.d.mts +5 -0
  261. package/dist/types/primitives/icon/svg/triangle-up.d.ts +5 -0
  262. package/dist/types/primitives/icon/svg/twitter.d.mts +5 -0
  263. package/dist/types/primitives/icon/svg/twitter.d.ts +5 -0
  264. package/dist/types/primitives/icon/svg/upload.d.mts +5 -0
  265. package/dist/types/primitives/icon/svg/upload.d.ts +5 -0
  266. package/dist/types/primitives/icon/svg/wallet-avatar.d.mts +5 -0
  267. package/dist/types/primitives/icon/svg/wallet-avatar.d.ts +5 -0
  268. package/dist/types/primitives/icon/svg/wallet.d.mts +5 -0
  269. package/dist/types/primitives/icon/svg/wallet.d.ts +5 -0
  270. package/dist/types/primitives/icon/svg/warning-filled.d.mts +5 -0
  271. package/dist/types/primitives/icon/svg/warning-filled.d.ts +5 -0
  272. package/dist/types/primitives/icon/svg/warning.d.mts +5 -0
  273. package/dist/types/primitives/icon/svg/warning.d.ts +5 -0
  274. package/dist/types/primitives/icon/types.d.mts +5 -0
  275. package/dist/types/primitives/icon/types.d.ts +5 -0
  276. package/dist/types/primitives/index.d.mts +17 -0
  277. package/dist/types/primitives/index.d.ts +17 -0
  278. package/dist/types/primitives/loading-icon/index.d.mts +11 -0
  279. package/dist/types/primitives/loading-icon/index.d.ts +11 -0
  280. package/dist/types/primitives/modal/index.d.mts +10 -0
  281. package/dist/types/primitives/modal/index.d.ts +10 -0
  282. package/dist/types/primitives/modal/modal.types.d.mts +54 -0
  283. package/dist/types/primitives/modal/modal.types.d.ts +54 -0
  284. package/dist/{number-value.d.mts → types/primitives/number-value.d.mts} +3 -5
  285. package/dist/{number-value.d.ts → types/primitives/number-value.d.ts} +3 -5
  286. package/dist/types/primitives/search/index.d.mts +6 -0
  287. package/dist/types/primitives/search/index.d.ts +6 -0
  288. package/dist/types/primitives/search/search-empty-icon.d.mts +5 -0
  289. package/dist/types/primitives/search/search-empty-icon.d.ts +5 -0
  290. package/dist/types/primitives/search/search.types.d.mts +96 -0
  291. package/dist/types/primitives/search/search.types.d.ts +96 -0
  292. package/dist/{select.d.mts → types/primitives/select/index.d.mts} +3 -5
  293. package/dist/{select.d.ts → types/primitives/select/index.d.ts} +3 -5
  294. package/dist/types/primitives/skeleton/index.d.mts +7 -0
  295. package/dist/types/primitives/skeleton/index.d.ts +7 -0
  296. package/dist/types/primitives/skeleton/skeleton-block.d.mts +8 -0
  297. package/dist/types/primitives/skeleton/skeleton-block.d.ts +8 -0
  298. package/dist/{skeleton.d.mts → types/primitives/skeleton/skeleton.types.d.mts} +6 -9
  299. package/dist/{skeleton.d.ts → types/primitives/skeleton/skeleton.types.d.ts} +6 -9
  300. package/dist/types/primitives/skeleton/views/event-list-item-details-skeleton-view.d.mts +5 -0
  301. package/dist/types/primitives/skeleton/views/event-list-item-details-skeleton-view.d.ts +5 -0
  302. package/dist/types/primitives/skeleton/views/event-list-item-skeleton-view.d.mts +9 -0
  303. package/dist/types/primitives/skeleton/views/event-list-item-skeleton-view.d.ts +9 -0
  304. package/dist/types/primitives/skeleton/views/event-list-skeleton-view.d.mts +5 -0
  305. package/dist/types/primitives/skeleton/views/event-list-skeleton-view.d.ts +5 -0
  306. package/dist/types/primitives/skeleton/views/market-details-skeleton-view.d.mts +12 -0
  307. package/dist/types/primitives/skeleton/views/market-details-skeleton-view.d.ts +12 -0
  308. package/dist/types/primitives/skeleton/views/place-order-skeleton-view.d.mts +5 -0
  309. package/dist/types/primitives/skeleton/views/place-order-skeleton-view.d.ts +5 -0
  310. package/dist/types/primitives/skeleton/views/settlement-skeleton-view.d.mts +5 -0
  311. package/dist/types/primitives/skeleton/views/settlement-skeleton-view.d.ts +5 -0
  312. package/dist/types/primitives/state-message/index.d.mts +15 -0
  313. package/dist/types/primitives/state-message/index.d.ts +15 -0
  314. package/dist/{switch-button.d.mts → types/primitives/switch-button/index.d.mts} +4 -7
  315. package/dist/{switch-button.d.ts → types/primitives/switch-button/index.d.ts} +4 -7
  316. package/dist/types/primitives/tabs/index.d.mts +6 -0
  317. package/dist/types/primitives/tabs/index.d.ts +6 -0
  318. package/dist/types/primitives/tabs/tabs.types.d.mts +24 -0
  319. package/dist/types/primitives/tabs/tabs.types.d.ts +24 -0
  320. package/dist/types/primitives/tabs/tabs.utils.d.mts +14 -0
  321. package/dist/types/primitives/tabs/tabs.utils.d.ts +14 -0
  322. package/dist/types/primitives/typography/index.d.mts +7 -0
  323. package/dist/types/primitives/typography/index.d.ts +7 -0
  324. package/dist/types/primitives/typography/typography.constants.d.mts +3 -0
  325. package/dist/types/primitives/typography/typography.constants.d.ts +3 -0
  326. package/dist/types/primitives/typography/typography.types.d.mts +8 -0
  327. package/dist/types/primitives/typography/typography.types.d.ts +8 -0
  328. package/dist/types/primitives/venue-logo/index.d.mts +8 -0
  329. package/dist/types/primitives/venue-logo/index.d.ts +8 -0
  330. package/dist/types/primitives/venue-logo/logo-props.d.mts +10 -0
  331. package/dist/types/primitives/venue-logo/logo-props.d.ts +10 -0
  332. package/dist/types/primitives/venue-logo/svg/logo-kalshi.d.mts +5 -0
  333. package/dist/types/primitives/venue-logo/svg/logo-kalshi.d.ts +5 -0
  334. package/dist/types/primitives/venue-logo/svg/logo-opinion.d.mts +5 -0
  335. package/dist/types/primitives/venue-logo/svg/logo-opinion.d.ts +5 -0
  336. package/dist/types/primitives/venue-logo/svg/logo-polymarket.d.mts +5 -0
  337. package/dist/types/primitives/venue-logo/svg/logo-polymarket.d.ts +5 -0
  338. package/dist/types/primitives/venue-logo/svg/logo-probable.d.mts +5 -0
  339. package/dist/types/primitives/venue-logo/svg/logo-probable.d.ts +5 -0
  340. package/dist/types/primitives/venue-logo/venue-logo.constants.d.mts +9 -0
  341. package/dist/types/primitives/venue-logo/venue-logo.constants.d.ts +9 -0
  342. package/dist/types/primitives/venue-logo/venue-logo.types.d.mts +17 -0
  343. package/dist/types/primitives/venue-logo/venue-logo.types.d.ts +17 -0
  344. package/dist/types/profile/index.d.mts +6 -0
  345. package/dist/types/profile/index.d.ts +6 -0
  346. package/dist/types/profile/profile-modal.constants.d.mts +17 -0
  347. package/dist/types/profile/profile-modal.constants.d.ts +17 -0
  348. package/dist/{profile-modal.d.mts → types/profile/profile-modal.types.d.mts} +4 -11
  349. package/dist/{profile-modal.d.ts → types/profile/profile-modal.types.d.ts} +4 -11
  350. package/dist/types/profile/tabs/about-tab.d.mts +16 -0
  351. package/dist/types/profile/tabs/about-tab.d.ts +16 -0
  352. package/dist/types/profile/tabs/accounts-wallets-tab.d.mts +18 -0
  353. package/dist/types/profile/tabs/accounts-wallets-tab.d.ts +18 -0
  354. package/dist/types/shared/constants.d.mts +23 -0
  355. package/dist/types/shared/constants.d.ts +23 -0
  356. package/dist/types/shared/query-error.d.mts +2 -0
  357. package/dist/types/shared/query-error.d.ts +2 -0
  358. package/dist/types/shared/types.d.mts +1 -0
  359. package/dist/types/shared/types.d.ts +1 -0
  360. package/dist/types/shared/utils.d.mts +15 -0
  361. package/dist/types/shared/utils.d.ts +15 -0
  362. package/dist/types/trading/index.d.mts +4 -0
  363. package/dist/types/trading/index.d.ts +4 -0
  364. package/dist/{place-order.d.ts → types/trading/place-order/index.d.mts} +3 -7
  365. package/dist/{place-order.d.mts → types/trading/place-order/index.d.ts} +3 -7
  366. package/dist/{settlement.d.ts → types/trading/settlement/index.d.mts} +3 -7
  367. package/dist/{settlement.d.mts → types/trading/settlement/index.d.ts} +3 -7
  368. package/dist/{types-DkGlbmXq.d.ts → types/trading/types.d.mts} +35 -38
  369. package/dist/{types-DkGlbmXq.d.mts → types/trading/types.d.ts} +35 -38
  370. package/dist/types/trading/utils.d.mts +16 -0
  371. package/dist/types/trading/utils.d.ts +16 -0
  372. package/dist/types/withdraw/index.d.mts +6 -0
  373. package/dist/types/withdraw/index.d.ts +6 -0
  374. package/dist/types/withdraw/steps/kalshi-withdraw.d.mts +5 -0
  375. package/dist/types/withdraw/steps/kalshi-withdraw.d.ts +5 -0
  376. package/dist/types/withdraw/steps/venue-selection.d.mts +6 -0
  377. package/dist/types/withdraw/steps/venue-selection.d.ts +6 -0
  378. package/dist/types/withdraw/steps/withdraw-amount.d.mts +8 -0
  379. package/dist/types/withdraw/steps/withdraw-amount.d.ts +8 -0
  380. package/dist/types/withdraw/steps/withdraw-method.d.mts +7 -0
  381. package/dist/types/withdraw/steps/withdraw-method.d.ts +7 -0
  382. package/dist/types/withdraw/withdraw-modal.constants.d.mts +9 -0
  383. package/dist/types/withdraw/withdraw-modal.constants.d.ts +9 -0
  384. package/dist/{withdraw-modal.d.mts → types/withdraw/withdraw-modal.types.d.mts} +3 -10
  385. package/dist/{withdraw-modal.d.ts → types/withdraw/withdraw-modal.types.d.ts} +3 -10
  386. package/package.json +35 -273
  387. package/dist/badge.d.mts +0 -28
  388. package/dist/badge.d.ts +0 -28
  389. package/dist/badge.js +0 -110
  390. package/dist/badge.mjs +0 -9
  391. package/dist/button.d.mts +0 -20
  392. package/dist/button.d.ts +0 -20
  393. package/dist/button.js +0 -183
  394. package/dist/button.mjs +0 -8
  395. package/dist/card.d.mts +0 -10
  396. package/dist/card.d.ts +0 -10
  397. package/dist/card.js +0 -88
  398. package/dist/card.mjs +0 -7
  399. package/dist/chart.mjs +0 -8
  400. package/dist/chunk-3QLOUBDJ.mjs +0 -483
  401. package/dist/chunk-3W7NBJLU.mjs +0 -371
  402. package/dist/chunk-4S3I6X7F.mjs +0 -855
  403. package/dist/chunk-4VUDTWH7.mjs +0 -42
  404. package/dist/chunk-6JG6I5AY.mjs +0 -654
  405. package/dist/chunk-BNDFQPHF.mjs +0 -9
  406. package/dist/chunk-ERGNR6UQ.mjs +0 -67
  407. package/dist/chunk-FO263M3V.mjs +0 -10
  408. package/dist/chunk-FO2QCB4Z.mjs +0 -35
  409. package/dist/chunk-GJ4U5NCE.mjs +0 -134
  410. package/dist/chunk-GNSPZ53C.mjs +0 -991
  411. package/dist/chunk-HOXTJ742.mjs +0 -146
  412. package/dist/chunk-JNH64AKR.mjs +0 -720
  413. package/dist/chunk-K6IJ4WBM.mjs +0 -67
  414. package/dist/chunk-KAGYJ4XT.mjs +0 -126
  415. package/dist/chunk-LA3FBBSJ.mjs +0 -311
  416. package/dist/chunk-LCZKSITC.mjs +0 -162
  417. package/dist/chunk-M4RJHRFT.mjs +0 -445
  418. package/dist/chunk-MBHTXNHX.mjs +0 -289
  419. package/dist/chunk-MJHKBCXQ.mjs +0 -379
  420. package/dist/chunk-NDG43KGL.mjs +0 -44
  421. package/dist/chunk-NH2G3POM.mjs +0 -470
  422. package/dist/chunk-OBCHURW5.mjs +0 -64
  423. package/dist/chunk-OH56VUYK.mjs +0 -321
  424. package/dist/chunk-OJVTGNIF.mjs +0 -230
  425. package/dist/chunk-P2PJBO5C.mjs +0 -280
  426. package/dist/chunk-PORVP72S.mjs +0 -277
  427. package/dist/chunk-QLMVKLNJ.mjs +0 -669
  428. package/dist/chunk-QM7CGMFG.mjs +0 -156
  429. package/dist/chunk-S3H63TQ5.mjs +0 -537
  430. package/dist/chunk-ZFMCCBP6.mjs +0 -25
  431. package/dist/connect-button.mjs +0 -14
  432. package/dist/deposit-modal.mjs +0 -15
  433. package/dist/event-list-item-details.d.mts +0 -11
  434. package/dist/event-list-item-details.d.ts +0 -11
  435. package/dist/event-list-item-details.js +0 -2254
  436. package/dist/event-list-item-details.mjs +0 -19
  437. package/dist/event-list-item-details.types-CMbXOrT-.d.ts +0 -53
  438. package/dist/event-list-item-details.types-DekJKeMD.d.mts +0 -53
  439. package/dist/event-list-item.d.mts +0 -10
  440. package/dist/event-list-item.d.ts +0 -10
  441. package/dist/event-list-item.js +0 -2600
  442. package/dist/event-list-item.mjs +0 -17
  443. package/dist/event-list-item.types-Y6IeJ4e4.d.mts +0 -46
  444. package/dist/event-list-item.types-Y6IeJ4e4.d.ts +0 -46
  445. package/dist/event-list.d.mts +0 -9
  446. package/dist/event-list.d.ts +0 -9
  447. package/dist/event-list.js +0 -3578
  448. package/dist/event-list.mjs +0 -20
  449. package/dist/event-list.types-CkAAUqwW.d.mts +0 -13
  450. package/dist/event-list.types-CkAAUqwW.d.ts +0 -13
  451. package/dist/event-market-page.d.mts +0 -52
  452. package/dist/event-market-page.d.ts +0 -52
  453. package/dist/event-market-page.mjs +0 -28
  454. package/dist/hello-world.d.mts +0 -8
  455. package/dist/hello-world.d.ts +0 -8
  456. package/dist/hello-world.js +0 -92
  457. package/dist/hello-world.mjs +0 -8
  458. package/dist/home-page.js +0 -3842
  459. package/dist/home-page.mjs +0 -21
  460. package/dist/icon.d.mts +0 -193
  461. package/dist/icon.d.ts +0 -193
  462. package/dist/icon.js +0 -1465
  463. package/dist/loading-icon.d.mts +0 -14
  464. package/dist/loading-icon.d.ts +0 -14
  465. package/dist/loading-icon.js +0 -112
  466. package/dist/loading-icon.mjs +0 -8
  467. package/dist/market-details.d.mts +0 -73
  468. package/dist/market-details.d.ts +0 -73
  469. package/dist/market-details.mjs +0 -21
  470. package/dist/modal.d.mts +0 -66
  471. package/dist/modal.d.ts +0 -66
  472. package/dist/modal.js +0 -321
  473. package/dist/modal.mjs +0 -9
  474. package/dist/number-value.js +0 -67
  475. package/dist/number-value.mjs +0 -7
  476. package/dist/onboarding-modal.d.mts +0 -88
  477. package/dist/onboarding-modal.d.ts +0 -88
  478. package/dist/onboarding-modal.js +0 -2836
  479. package/dist/onboarding-modal.mjs +0 -24
  480. package/dist/place-order.mjs +0 -18
  481. package/dist/profile-modal.js +0 -2447
  482. package/dist/profile-modal.mjs +0 -14
  483. package/dist/registry-DfSCFAdC.d.mts +0 -178
  484. package/dist/registry-DfSCFAdC.d.ts +0 -178
  485. package/dist/search.d.mts +0 -51
  486. package/dist/search.d.ts +0 -51
  487. package/dist/search.js +0 -1954
  488. package/dist/search.mjs +0 -12
  489. package/dist/select.js +0 -1552
  490. package/dist/select.mjs +0 -11
  491. package/dist/settlement.js +0 -2445
  492. package/dist/settlement.mjs +0 -15
  493. package/dist/skeleton.js +0 -490
  494. package/dist/skeleton.mjs +0 -10
  495. package/dist/switch-button.js +0 -191
  496. package/dist/switch-button.mjs +0 -7
  497. package/dist/tabs.d.mts +0 -31
  498. package/dist/tabs.d.ts +0 -31
  499. package/dist/tabs.js +0 -2078
  500. package/dist/tabs.mjs +0 -12
  501. package/dist/types-BVj9ky9P.d.mts +0 -3
  502. package/dist/types-BVj9ky9P.d.ts +0 -3
  503. package/dist/typography.d.mts +0 -18
  504. package/dist/typography.d.ts +0 -18
  505. package/dist/typography.js +0 -93
  506. package/dist/typography.mjs +0 -9
  507. package/dist/user-profile-page.js +0 -3081
  508. package/dist/user-profile-page.mjs +0 -15
  509. package/dist/venue-logo.d.mts +0 -13
  510. package/dist/venue-logo.d.ts +0 -13
  511. package/dist/venue-logo.js +0 -323
  512. package/dist/venue-logo.mjs +0 -10
  513. package/dist/venue-logo.types-CGUc22ly.d.mts +0 -19
  514. package/dist/venue-logo.types-Dqr39S1-.d.ts +0 -19
  515. package/dist/withdraw-modal.js +0 -2449
  516. package/dist/withdraw-modal.mjs +0 -14
@@ -0,0 +1,2616 @@
1
+ import {
2
+ Badge,
3
+ LineChart,
4
+ StateMessage,
5
+ SwitchButton,
6
+ Typography
7
+ } from "./chunk-CN7GI2RJ.mjs";
8
+ import {
9
+ Card,
10
+ MarketDetailsOderbookSkeleton,
11
+ Skeleton,
12
+ Tabs,
13
+ baseCardClassName,
14
+ detailsBaseCardClassName,
15
+ eventListItemDetailsTimeRanges,
16
+ fallbackLineColors,
17
+ getMarketDetailsTabs,
18
+ lineColorByVenue,
19
+ marketDetailsBaseCardClassName,
20
+ marketDetailsDefaultIsOpened,
21
+ orderBookRowLimitDefault
22
+ } from "./chunk-UBBOLLOS.mjs";
23
+ import {
24
+ Button,
25
+ Icon,
26
+ VenueLogo,
27
+ __objRest,
28
+ __spreadProps,
29
+ __spreadValues,
30
+ cn,
31
+ getMotionClassName,
32
+ toDate
33
+ } from "./chunk-HI4EEDN5.mjs";
34
+
35
+ // src/events/item/index.tsx
36
+ import dayjs from "dayjs";
37
+ import { useMemo } from "react";
38
+ import {
39
+ useEvent,
40
+ useLabels,
41
+ useSdkUiConfig
42
+ } from "@agg-market/hooks";
43
+
44
+ // src/shared/query-error.ts
45
+ var getErrorStatus = (error) => {
46
+ if (!error || typeof error !== "object")
47
+ return null;
48
+ const status = error.status;
49
+ return typeof status === "number" ? status : null;
50
+ };
51
+ var isErrorWithStatus = (error, status) => {
52
+ return getErrorStatus(error) === status;
53
+ };
54
+
55
+ // src/events/item/event-list-item.utils.ts
56
+ var resolveEventListItemEvent = (fetchedEvent) => {
57
+ if (!fetchedEvent)
58
+ return void 0;
59
+ const mergedVenueMarkets = fetchedEvent.markets.flatMap(
60
+ (market) => market.venueMarkets
61
+ );
62
+ if (mergedVenueMarkets.length === 0)
63
+ return void 0;
64
+ return fetchedEvent;
65
+ };
66
+ var normalizeProbability = (value) => {
67
+ if (typeof value !== "number" || !Number.isFinite(value))
68
+ return void 0;
69
+ if (value < 0)
70
+ return 0;
71
+ if (value > 1)
72
+ return 1;
73
+ return value;
74
+ };
75
+ var hasDateLabel = (outcome) => {
76
+ return !!toDate(outcome.label);
77
+ };
78
+ var sortOutcomes = (outcomes) => {
79
+ if (outcomes.length <= 1)
80
+ return outcomes;
81
+ const now = Date.now();
82
+ if (outcomes.some(hasDateLabel)) {
83
+ return [...outcomes].sort((a, b) => {
84
+ var _a, _b, _c, _d;
85
+ const aDate = (_b = (_a = toDate(a.label)) == null ? void 0 : _a.getTime()) != null ? _b : 0;
86
+ const bDate = (_d = (_c = toDate(b.label)) == null ? void 0 : _c.getTime()) != null ? _d : 0;
87
+ return Math.abs(aDate - now) - Math.abs(bDate - now);
88
+ });
89
+ }
90
+ return [...outcomes].sort((a, b) => {
91
+ var _a, _b;
92
+ const aPrice = (_a = normalizeProbability(a.price)) != null ? _a : 0;
93
+ const bPrice = (_b = normalizeProbability(b.price)) != null ? _b : 0;
94
+ return bPrice - aPrice;
95
+ });
96
+ };
97
+ var compareVisibleOutcomeRows = (left, right) => {
98
+ var _a, _b;
99
+ const leftDate = toDate(resolveOutcomeTitle(left.outcome));
100
+ const rightDate = toDate(resolveOutcomeTitle(right.outcome));
101
+ if (leftDate && rightDate) {
102
+ return leftDate.getTime() - rightDate.getTime();
103
+ }
104
+ const leftProbability = (_a = normalizeProbability(left.outcome.price)) != null ? _a : -1;
105
+ const rightProbability = (_b = normalizeProbability(right.outcome.price)) != null ? _b : -1;
106
+ return rightProbability - leftProbability;
107
+ };
108
+ var shouldReplaceVisibleOutcome = (current, next) => {
109
+ var _a, _b;
110
+ const currentVolume = typeof current.market.volume === "number" ? current.market.volume : -1;
111
+ const nextVolume = typeof next.market.volume === "number" ? next.market.volume : -1;
112
+ if (currentVolume !== nextVolume) {
113
+ return nextVolume > currentVolume;
114
+ }
115
+ const currentProbability = (_a = normalizeProbability(current.outcome.price)) != null ? _a : -1;
116
+ const nextProbability = (_b = normalizeProbability(next.outcome.price)) != null ? _b : -1;
117
+ return nextProbability > currentProbability;
118
+ };
119
+ var resolveVisibleOutcomes = (venueMarkets, maxOutcomes) => {
120
+ const visibleOutcomesByLabel = /* @__PURE__ */ new Map();
121
+ venueMarkets.forEach((market) => {
122
+ sortOutcomes(market.venueMarketOutcomes).forEach((outcome) => {
123
+ const title = resolveOutcomeTitle(outcome);
124
+ const normalizedTitle = title.trim().toLowerCase();
125
+ const nextVisibleOutcome = {
126
+ venue: market.venue,
127
+ market,
128
+ outcome,
129
+ title
130
+ };
131
+ const currentVisibleOutcome = visibleOutcomesByLabel.get(normalizedTitle);
132
+ if (!currentVisibleOutcome || shouldReplaceVisibleOutcome(currentVisibleOutcome, nextVisibleOutcome)) {
133
+ visibleOutcomesByLabel.set(normalizedTitle, nextVisibleOutcome);
134
+ }
135
+ });
136
+ });
137
+ return [...visibleOutcomesByLabel.values()].sort(compareVisibleOutcomeRows).slice(0, Math.max(1, maxOutcomes));
138
+ };
139
+ var resolveOutcomeTitle = (outcome) => {
140
+ if (outcome.title && outcome.title.trim())
141
+ return outcome.title;
142
+ return outcome.label;
143
+ };
144
+ var selectPrimaryVenueMarket = (venueMarkets) => {
145
+ if (venueMarkets.length === 0)
146
+ return void 0;
147
+ if (venueMarkets.length === 1)
148
+ return venueMarkets[0];
149
+ return [...venueMarkets].sort((a, b) => {
150
+ const aVolume = typeof a.volume === "number" ? a.volume : -1;
151
+ const bVolume = typeof b.volume === "number" ? b.volume : -1;
152
+ return bVolume - aVolume;
153
+ })[0];
154
+ };
155
+ var resolveTileTitle = (event, primaryVenueMarket, titleOverride) => {
156
+ if (typeof titleOverride === "string" && titleOverride.trim()) {
157
+ return titleOverride;
158
+ }
159
+ if (typeof (primaryVenueMarket == null ? void 0 : primaryVenueMarket.question) === "string" && primaryVenueMarket.question.trim()) {
160
+ return primaryVenueMarket.question;
161
+ }
162
+ return event.title;
163
+ };
164
+ var resolveTileImage = (event, primaryVenueMarket, imageOverride) => {
165
+ if (typeof imageOverride === "string" && imageOverride.trim()) {
166
+ return imageOverride;
167
+ }
168
+ if (typeof (primaryVenueMarket == null ? void 0 : primaryVenueMarket.image) === "string" && primaryVenueMarket.image.trim()) {
169
+ return primaryVenueMarket.image;
170
+ }
171
+ if (typeof event.image === "string" && event.image.trim()) {
172
+ return event.image;
173
+ }
174
+ return void 0;
175
+ };
176
+ var formatCountLabel = (count, singular, plural) => {
177
+ return `${count} ${count === 1 ? singular : plural}`;
178
+ };
179
+ var getVenueSummary = (venueMarkets) => {
180
+ const uniqueVenues = Array.from(new Set(venueMarkets.map((market) => market.venue)));
181
+ return {
182
+ marketCount: venueMarkets.length,
183
+ venueCount: uniqueVenues.length,
184
+ singleVenue: uniqueVenues.length === 1 ? uniqueVenues[0] : void 0
185
+ };
186
+ };
187
+ var resolveVenueLabel = (venue, venueInfo, labels) => {
188
+ var _a, _b;
189
+ if (!venue)
190
+ return labels.eventItem.venueSingular;
191
+ return (_b = (_a = venueInfo == null ? void 0 : venueInfo[venue]) == null ? void 0 : _a.label) != null ? _b : labels.venues[venue];
192
+ };
193
+
194
+ // src/events/item/index.tsx
195
+ import { jsx, jsxs } from "react/jsx-runtime";
196
+ var EventListItemLoadingState = ({
197
+ classNames,
198
+ ariaLabel
199
+ }) => {
200
+ const labels = useLabels();
201
+ return /* @__PURE__ */ jsx(
202
+ Skeleton,
203
+ {
204
+ view: "event-list-item",
205
+ className: classNames == null ? void 0 : classNames.root,
206
+ ariaLabel: ariaLabel != null ? ariaLabel : labels.eventItem.loading
207
+ }
208
+ );
209
+ };
210
+ var EventListItemUnavailableState = ({
211
+ classNames,
212
+ ariaLabel
213
+ }) => {
214
+ const labels = useLabels();
215
+ return /* @__PURE__ */ jsx(
216
+ Card,
217
+ {
218
+ className: cn(baseCardClassName, classNames == null ? void 0 : classNames.root),
219
+ role: "status",
220
+ "aria-label": ariaLabel != null ? ariaLabel : labels.eventItem.unavailableAria,
221
+ children: /* @__PURE__ */ jsxs("div", { className: cn("flex flex-col gap-1", classNames == null ? void 0 : classNames.header), children: [
222
+ /* @__PURE__ */ jsx(Typography, { variant: "body-large-strong", className: cn("truncate", classNames == null ? void 0 : classNames.title), children: labels.eventItem.unavailableTitle }),
223
+ /* @__PURE__ */ jsx(Typography, { variant: "body", className: "text-agg-muted-foreground", children: labels.eventItem.unavailableDescription })
224
+ ] })
225
+ }
226
+ );
227
+ };
228
+ var EventListItemNotFoundState = ({
229
+ classNames,
230
+ ariaLabel
231
+ }) => {
232
+ const labels = useLabels();
233
+ return /* @__PURE__ */ jsx(Card, { className: cn("w-full gap-0 overflow-hidden p-0", classNames == null ? void 0 : classNames.root), children: /* @__PURE__ */ jsx(
234
+ StateMessage,
235
+ {
236
+ ariaLabel: ariaLabel != null ? ariaLabel : labels.eventItemDetails.notFoundAria,
237
+ title: labels.eventItemDetails.notFoundTitle,
238
+ description: labels.eventItemDetails.notFoundDescription,
239
+ className: "min-h-[280px] md:min-h-[320px]"
240
+ }
241
+ ) });
242
+ };
243
+ var EventListItemContent = ({
244
+ event,
245
+ title,
246
+ image,
247
+ showVenueLogo = true,
248
+ maxOutcomes = 2,
249
+ classNames,
250
+ venueInfo,
251
+ arbitrageByOutcomeId,
252
+ onClick,
253
+ ariaLabel
254
+ }) => {
255
+ var _a;
256
+ const config = useSdkUiConfig();
257
+ const labels = useLabels();
258
+ const allVenueMarkets = useMemo(() => {
259
+ return event.markets.flatMap((market) => market.venueMarkets);
260
+ }, [event.markets]);
261
+ const primaryVenueMarket = useMemo(() => {
262
+ return selectPrimaryVenueMarket(allVenueMarkets);
263
+ }, [allVenueMarkets]);
264
+ const visibleOutcomes = useMemo(() => {
265
+ if (allVenueMarkets.length === 0)
266
+ return [];
267
+ return resolveVisibleOutcomes(allVenueMarkets, maxOutcomes);
268
+ }, [allVenueMarkets, maxOutcomes]);
269
+ const resolvedTitle = resolveTileTitle(event, primaryVenueMarket, title);
270
+ const resolvedImage = resolveTileImage(event, primaryVenueMarket, image);
271
+ const { marketCount, venueCount, singleVenue } = getVenueSummary(allVenueMarkets);
272
+ const venueLabel = resolveVenueLabel(singleVenue, venueInfo, labels);
273
+ const visibleVenueLogos = useMemo(() => {
274
+ return Array.from(new Set(allVenueMarkets.map((market) => market.venue))).slice(0, 4);
275
+ }, [allVenueMarkets]);
276
+ const resolvedVolume = typeof event.volume === "number" ? event.volume : (_a = primaryVenueMarket == null ? void 0 : primaryVenueMarket.volume) != null ? _a : void 0;
277
+ const volumeLabel = typeof resolvedVolume === "number" ? `${config.formatCompactCurrency(resolvedVolume)} ${labels.eventItem.volumeSuffix}` : "";
278
+ const handleKeyDown = (eventToHandle) => {
279
+ if (!onClick)
280
+ return;
281
+ if ((eventToHandle == null ? void 0 : eventToHandle.key) === "Enter" || (eventToHandle == null ? void 0 : eventToHandle.key) === " ") {
282
+ eventToHandle == null ? void 0 : eventToHandle.preventDefault();
283
+ onClick();
284
+ }
285
+ };
286
+ const renderArbitrage = (value) => {
287
+ if (value == null)
288
+ return null;
289
+ if (Math.abs(value) < config.arbitrageThreshold)
290
+ return null;
291
+ return /* @__PURE__ */ jsxs("div", { className: cn("flex items-center gap-1", "text-agg-success"), children: [
292
+ /* @__PURE__ */ jsx(Typography, { variant: "label-strong", className: "text-agg-success", children: config.formatPercent(value) }),
293
+ /* @__PURE__ */ jsx(
294
+ Icon,
295
+ {
296
+ name: "triangle-up",
297
+ size: "small",
298
+ title: labels.eventItem.arbitrage,
299
+ className: "size-2!"
300
+ }
301
+ )
302
+ ] });
303
+ };
304
+ return /* @__PURE__ */ jsxs(
305
+ Card,
306
+ {
307
+ className: cn(baseCardClassName, onClick && "cursor-pointer", classNames == null ? void 0 : classNames.root),
308
+ role: onClick ? "button" : void 0,
309
+ tabIndex: onClick ? 0 : void 0,
310
+ onClick,
311
+ onKeyDown: handleKeyDown,
312
+ "aria-label": ariaLabel != null ? ariaLabel : resolvedTitle,
313
+ children: [
314
+ /* @__PURE__ */ jsxs("div", { className: cn("flex items-center gap-3", classNames == null ? void 0 : classNames.header), children: [
315
+ resolvedImage ? /* @__PURE__ */ jsx(
316
+ "img",
317
+ {
318
+ src: resolvedImage,
319
+ alt: "",
320
+ className: cn("h-10 w-10", "rounded-agg-lg object-cover")
321
+ }
322
+ ) : null,
323
+ /* @__PURE__ */ jsx(
324
+ Typography,
325
+ {
326
+ variant: "body-strong",
327
+ className: cn(
328
+ "min-w-0 text-agg-base font-agg-bold leading-agg-6 ",
329
+ "truncate text-wrap wrap-break-word line-clamp-2",
330
+ classNames == null ? void 0 : classNames.title
331
+ ),
332
+ children: resolvedTitle
333
+ }
334
+ )
335
+ ] }),
336
+ /* @__PURE__ */ jsx("div", { className: cn("flex flex-col gap-3", classNames == null ? void 0 : classNames.outcomes), children: visibleOutcomes.map((visibleOutcome) => {
337
+ const probability = normalizeProbability(visibleOutcome.outcome.price);
338
+ const showBadge = typeof probability === "number";
339
+ const arbitragePercent = arbitrageByOutcomeId == null ? void 0 : arbitrageByOutcomeId[visibleOutcome.outcome.id];
340
+ const outcomeTitle = resolveOutcomeTitle(visibleOutcome.outcome);
341
+ const formattedTitle = dayjs(outcomeTitle).isValid() ? dayjs(outcomeTitle).format("MMMM D, YYYY") : outcomeTitle;
342
+ return /* @__PURE__ */ jsxs(
343
+ "div",
344
+ {
345
+ className: cn(
346
+ "flex flex-row gap-3 w-full items-center justify-between",
347
+ classNames == null ? void 0 : classNames.outcomeRow
348
+ ),
349
+ children: [
350
+ /* @__PURE__ */ jsx(
351
+ Typography,
352
+ {
353
+ variant: "body",
354
+ className: "min-w-0 truncate text-agg-sm leading-agg-5 md:text-agg-base md:leading-agg-6",
355
+ children: formattedTitle
356
+ }
357
+ ),
358
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-row gap-3 items-center justify-end", children: [
359
+ renderArbitrage(arbitragePercent),
360
+ showBadge ? /* @__PURE__ */ jsx(
361
+ Badge,
362
+ {
363
+ text: config.formatPercent(probability),
364
+ prefix: showVenueLogo ? /* @__PURE__ */ jsx(VenueLogo, { venue: visibleOutcome.venue, size: "small" }) : void 0,
365
+ size: "large",
366
+ classNames: {
367
+ root: cn(
368
+ "h-9 min-w-[101px] justify-center px-4 text-agg-base leading-agg-6",
369
+ classNames == null ? void 0 : classNames.badge
370
+ )
371
+ }
372
+ }
373
+ ) : null
374
+ ] })
375
+ ]
376
+ },
377
+ `${visibleOutcome.market.id}-${visibleOutcome.outcome.id}`
378
+ );
379
+ }) }),
380
+ /* @__PURE__ */ jsxs(
381
+ "div",
382
+ {
383
+ className: cn(
384
+ "flex items-center justify-between gap-2",
385
+ "text-agg-muted-foreground",
386
+ classNames == null ? void 0 : classNames.footer
387
+ ),
388
+ children: [
389
+ /* @__PURE__ */ jsxs("div", { className: cn("flex items-center gap-1", "text-agg-sm leading-agg-5"), children: [
390
+ /* @__PURE__ */ jsx("span", { className: "truncate text-agg-muted-foreground", children: formatCountLabel(
391
+ marketCount,
392
+ labels.eventItem.marketSingular,
393
+ labels.eventItem.marketPlural
394
+ ) }),
395
+ /* @__PURE__ */ jsx("span", { className: "text-agg-muted-foreground", children: "\xD7" }),
396
+ singleVenue ? /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-1 truncate text-agg-muted-foreground", children: [
397
+ showVenueLogo ? /* @__PURE__ */ jsx(
398
+ VenueLogo,
399
+ {
400
+ venue: singleVenue,
401
+ size: "small",
402
+ isMonochromatic: true,
403
+ className: "text-agg-muted-foreground!"
404
+ }
405
+ ) : null,
406
+ /* @__PURE__ */ jsx("span", { children: venueLabel })
407
+ ] }) : /* @__PURE__ */ jsx("span", { className: "truncate text-agg-muted-foreground", children: formatCountLabel(
408
+ venueCount,
409
+ labels.eventItem.venueSingular,
410
+ labels.eventItem.venuePlural
411
+ ) }),
412
+ showVenueLogo && !singleVenue && visibleVenueLogos.length > 0 ? /* @__PURE__ */ jsx("span", { className: "flex items-center gap-1 overflow-hidden", children: visibleVenueLogos.map((venue) => /* @__PURE__ */ jsx(
413
+ VenueLogo,
414
+ {
415
+ venue,
416
+ size: "small",
417
+ isMonochromatic: true,
418
+ className: "text-agg-muted-foreground!"
419
+ },
420
+ venue
421
+ )) }) : null
422
+ ] }),
423
+ volumeLabel ? /* @__PURE__ */ jsx(Typography, { variant: "label", className: "text-agg-sm text-agg-muted-foreground", children: volumeLabel }) : null
424
+ ]
425
+ }
426
+ )
427
+ ]
428
+ }
429
+ );
430
+ };
431
+ var EventListItemByEventId = (_a) => {
432
+ var _b = _a, {
433
+ eventId
434
+ } = _b, rest = __objRest(_b, [
435
+ "eventId"
436
+ ]);
437
+ const {
438
+ event: fetchedEvent,
439
+ error,
440
+ isError,
441
+ isLoading
442
+ } = useEvent(eventId, {
443
+ enabled: !!eventId
444
+ });
445
+ const resolvedEvent = useMemo(() => {
446
+ return resolveEventListItemEvent(fetchedEvent);
447
+ }, [fetchedEvent]);
448
+ if (!eventId) {
449
+ return /* @__PURE__ */ jsx(EventListItemUnavailableState, { classNames: rest.classNames, ariaLabel: rest.ariaLabel });
450
+ }
451
+ if (isLoading) {
452
+ return /* @__PURE__ */ jsx(EventListItemLoadingState, { classNames: rest.classNames, ariaLabel: rest.ariaLabel });
453
+ }
454
+ if (isErrorWithStatus(error, 404)) {
455
+ return /* @__PURE__ */ jsx(EventListItemNotFoundState, { classNames: rest.classNames, ariaLabel: rest.ariaLabel });
456
+ }
457
+ if (!fetchedEvent && !isError) {
458
+ return /* @__PURE__ */ jsx(EventListItemLoadingState, { classNames: rest.classNames, ariaLabel: rest.ariaLabel });
459
+ }
460
+ if (!resolvedEvent) {
461
+ return /* @__PURE__ */ jsx(EventListItemUnavailableState, { classNames: rest.classNames, ariaLabel: rest.ariaLabel });
462
+ }
463
+ return /* @__PURE__ */ jsx(EventListItemContent, __spreadValues({ event: resolvedEvent }, rest));
464
+ };
465
+ var EventListItem = (props) => {
466
+ if (props.isLoading) {
467
+ return /* @__PURE__ */ jsx(EventListItemLoadingState, { classNames: props.classNames, ariaLabel: props.ariaLabel });
468
+ }
469
+ if ("event" in props && props.event) {
470
+ const _a = props, { event } = _a, rest = __objRest(_a, ["event"]);
471
+ return /* @__PURE__ */ jsx(EventListItemContent, __spreadValues({ event }, rest));
472
+ }
473
+ return /* @__PURE__ */ jsx(EventListItemByEventId, __spreadValues({}, props));
474
+ };
475
+ EventListItem.displayName = "EventListItem";
476
+
477
+ // src/events/item-details/index.tsx
478
+ import { useEffect, useMemo as useMemo2, useState } from "react";
479
+ import { useEvent as useEvent2, useLabels as useLabels2, usePriceHistory, useSdkUiConfig as useSdkUiConfig2 } from "@agg-market/hooks";
480
+
481
+ // src/events/item-details/event-list-item-details.utils.ts
482
+ import dayjs2 from "dayjs";
483
+ var normalizeLabel = (value) => {
484
+ return value.trim().toLowerCase();
485
+ };
486
+ var isDateLikeLabel = (value) => {
487
+ if (!value.trim())
488
+ return false;
489
+ return dayjs2(value).isValid();
490
+ };
491
+ var formatDateLabel = (value) => {
492
+ if (!isDateLikeLabel(value))
493
+ return value;
494
+ return dayjs2(value).format("MMM D, YYYY");
495
+ };
496
+ var getDefaultSelectedTimeRange = (value) => {
497
+ if (!value)
498
+ return "1M";
499
+ return value;
500
+ };
501
+ var getTimeWindowByRange = (range) => {
502
+ const endTs = dayjs2().unix();
503
+ if (range === "1H") {
504
+ return {
505
+ startTs: dayjs2.unix(endTs).subtract(1, "hour").unix(),
506
+ endTs,
507
+ intervalMinutes: 5
508
+ };
509
+ }
510
+ if (range === "6H") {
511
+ return {
512
+ startTs: dayjs2.unix(endTs).subtract(6, "hour").unix(),
513
+ endTs,
514
+ intervalMinutes: 15
515
+ };
516
+ }
517
+ if (range === "1D") {
518
+ return {
519
+ startTs: dayjs2.unix(endTs).subtract(1, "day").unix(),
520
+ endTs,
521
+ intervalMinutes: 30
522
+ };
523
+ }
524
+ if (range === "1W") {
525
+ return {
526
+ startTs: dayjs2.unix(endTs).subtract(7, "day").unix(),
527
+ endTs,
528
+ intervalMinutes: 60
529
+ };
530
+ }
531
+ if (range === "1M") {
532
+ return {
533
+ startTs: dayjs2.unix(endTs).subtract(1, "month").unix(),
534
+ endTs,
535
+ intervalMinutes: 240
536
+ };
537
+ }
538
+ return {
539
+ startTs: dayjs2.unix(endTs).subtract(6, "month").unix(),
540
+ endTs,
541
+ intervalMinutes: 720
542
+ };
543
+ };
544
+ var resolveOutcomeLabels = (venueMarkets) => {
545
+ var _a;
546
+ const primaryMarket = selectPrimaryVenueMarket(venueMarkets);
547
+ const initialLabels = ((_a = primaryMarket == null ? void 0 : primaryMarket.venueMarketOutcomes) != null ? _a : []).map(
548
+ (outcome) => resolveOutcomeTitle(outcome)
549
+ );
550
+ const labels = new Set(initialLabels);
551
+ venueMarkets.forEach((market) => {
552
+ sortOutcomes(market.venueMarketOutcomes).forEach((outcome) => {
553
+ labels.add(resolveOutcomeTitle(outcome));
554
+ });
555
+ });
556
+ return [...labels];
557
+ };
558
+ var resolveDefaultOutcomeLabel = (outcomeLabels) => {
559
+ return outcomeLabels[0];
560
+ };
561
+ var matchOutcomeByLabel = (outcome, selectedOutcomeLabel) => {
562
+ const normalizedSelectedLabel = normalizeLabel(selectedOutcomeLabel);
563
+ const resolvedTitle = resolveOutcomeTitle(outcome);
564
+ return normalizeLabel(resolvedTitle) === normalizedSelectedLabel || normalizeLabel(outcome.label) === normalizedSelectedLabel;
565
+ };
566
+ var resolveOutcomesByVenue = (venueMarkets, selectedOutcomeLabel) => {
567
+ return venueMarkets.map((market) => {
568
+ const matchedOutcome = sortOutcomes(market.venueMarketOutcomes).find((outcome) => {
569
+ return matchOutcomeByLabel(outcome, selectedOutcomeLabel);
570
+ });
571
+ if (!matchedOutcome)
572
+ return null;
573
+ return {
574
+ venue: market.venue,
575
+ market,
576
+ outcome: matchedOutcome
577
+ };
578
+ }).filter((item) => item != null);
579
+ };
580
+ var buildPriceHistoryGroups = (selectedOutcomes, fallbackMarketId) => {
581
+ const marketIdByVenue = /* @__PURE__ */ new Map();
582
+ selectedOutcomes.forEach(({ venue, market }) => {
583
+ var _a, _b;
584
+ const marketWithCanonicalId = market;
585
+ const canonicalMarketId = (_a = marketWithCanonicalId.marketId) != null ? _a : fallbackMarketId;
586
+ if (!canonicalMarketId)
587
+ return;
588
+ if (!marketIdByVenue.has(venue)) {
589
+ marketIdByVenue.set(venue, /* @__PURE__ */ new Set());
590
+ }
591
+ (_b = marketIdByVenue.get(venue)) == null ? void 0 : _b.add(canonicalMarketId);
592
+ });
593
+ return [...marketIdByVenue.entries()].map(([venue, marketIds]) => ({
594
+ venue,
595
+ venueMarketOutcomeIds: [...marketIds]
596
+ })).filter((group) => group.venueMarketOutcomeIds.length > 0);
597
+ };
598
+ var resolveSeriesColor = (venue, index) => {
599
+ var _a;
600
+ const colorFromVenue = lineColorByVenue[venue];
601
+ if (colorFromVenue)
602
+ return colorFromVenue;
603
+ return (_a = fallbackLineColors[index % fallbackLineColors.length]) != null ? _a : "#2e5cff";
604
+ };
605
+
606
+ // src/events/item-details/index.tsx
607
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
608
+ var EventListItemDetailsLoadingState = ({
609
+ classNames,
610
+ ariaLabel
611
+ }) => {
612
+ const labels = useLabels2();
613
+ return /* @__PURE__ */ jsx2(
614
+ Skeleton,
615
+ {
616
+ view: "event-list-item-details",
617
+ className: classNames == null ? void 0 : classNames.root,
618
+ ariaLabel: ariaLabel != null ? ariaLabel : labels.eventItemDetails.loading
619
+ }
620
+ );
621
+ };
622
+ var EventListItemDetailsUnavailableState = ({
623
+ classNames,
624
+ ariaLabel
625
+ }) => {
626
+ const labels = useLabels2();
627
+ return /* @__PURE__ */ jsx2(
628
+ Card,
629
+ {
630
+ className: cn(detailsBaseCardClassName, classNames == null ? void 0 : classNames.root),
631
+ role: "status",
632
+ "aria-label": ariaLabel != null ? ariaLabel : labels.eventItemDetails.unavailableAria,
633
+ children: /* @__PURE__ */ jsxs2("div", { className: cn("flex flex-col gap-1", classNames == null ? void 0 : classNames.header), children: [
634
+ /* @__PURE__ */ jsx2(Typography, { variant: "body-large-strong", className: cn("truncate", classNames == null ? void 0 : classNames.title), children: labels.eventItemDetails.unavailableTitle }),
635
+ /* @__PURE__ */ jsx2(Typography, { variant: "body", className: "text-agg-muted-foreground", children: labels.eventItemDetails.unavailableDescription })
636
+ ] })
637
+ }
638
+ );
639
+ };
640
+ var EventListItemDetailsNotFoundState = ({
641
+ classNames,
642
+ ariaLabel
643
+ }) => {
644
+ const labels = useLabels2();
645
+ return /* @__PURE__ */ jsx2(Card, { className: cn(detailsBaseCardClassName, classNames == null ? void 0 : classNames.root), children: /* @__PURE__ */ jsx2(
646
+ StateMessage,
647
+ {
648
+ ariaLabel: ariaLabel != null ? ariaLabel : labels.eventItemDetails.notFoundAria,
649
+ title: labels.eventItemDetails.notFoundTitle,
650
+ description: labels.eventItemDetails.notFoundDescription,
651
+ className: "min-h-[280px] md:min-h-[320px]"
652
+ }
653
+ ) });
654
+ };
655
+ var probabilityModeOrder = ["yes", "no"];
656
+ var clampProbability = (value) => {
657
+ if (value < 0)
658
+ return 0;
659
+ if (value > 1)
660
+ return 1;
661
+ return value;
662
+ };
663
+ var resolveAverageProbability = (values) => {
664
+ const validValues = values.filter((value) => value != null);
665
+ if (validValues.length === 0)
666
+ return void 0;
667
+ return validValues.reduce((sum, value) => sum + value, 0) / validValues.length;
668
+ };
669
+ var resolveOutcomeCandidateIds = (market, outcome) => {
670
+ var _a, _b;
671
+ const marketWithCanonicalId = market;
672
+ return [
673
+ outcome.id,
674
+ (_a = outcome.externalIdentifier) != null ? _a : void 0,
675
+ market.externalIdentifier,
676
+ (_b = marketWithCanonicalId.marketId) != null ? _b : void 0
677
+ ].filter((value) => typeof value === "string" && value.trim().length > 0);
678
+ };
679
+ var EventListItemDetailsGraphSection = ({
680
+ venueMarkets,
681
+ canonicalMarketId,
682
+ selectedOutcomeLabel,
683
+ onSelectedOutcomeLabelChange,
684
+ switchLabels,
685
+ isDateOutcomeMarket,
686
+ classNames,
687
+ showVenueLogo,
688
+ venueInfo,
689
+ formatPercent,
690
+ selectedTimeRange
691
+ }) => {
692
+ const labels = useLabels2();
693
+ const [selectedVenue, setSelectedVenue] = useState(null);
694
+ const [activeProbabilityMode, setActiveProbabilityMode] = useState("yes");
695
+ const probabilityModeConfigs = useMemo2(() => {
696
+ if (isDateOutcomeMarket) {
697
+ return {
698
+ yes: {
699
+ switchLabel: switchLabels[0],
700
+ sourceOutcomeLabel: selectedOutcomeLabel,
701
+ transformProbability: (value) => value
702
+ },
703
+ no: {
704
+ switchLabel: switchLabels[1],
705
+ sourceOutcomeLabel: selectedOutcomeLabel,
706
+ transformProbability: (value) => 1 - value
707
+ }
708
+ };
709
+ }
710
+ return {
711
+ yes: {
712
+ switchLabel: switchLabels[0],
713
+ sourceOutcomeLabel: switchLabels[0],
714
+ transformProbability: (value) => value
715
+ },
716
+ no: {
717
+ switchLabel: switchLabels[1],
718
+ sourceOutcomeLabel: switchLabels[1],
719
+ transformProbability: (value) => value
720
+ }
721
+ };
722
+ }, [isDateOutcomeMarket, selectedOutcomeLabel, switchLabels]);
723
+ const selectedOutcomesByMode = useMemo2(() => {
724
+ return {
725
+ yes: resolveOutcomesByVenue(venueMarkets, probabilityModeConfigs.yes.sourceOutcomeLabel),
726
+ no: resolveOutcomesByVenue(venueMarkets, probabilityModeConfigs.no.sourceOutcomeLabel)
727
+ };
728
+ }, [
729
+ probabilityModeConfigs.no.sourceOutcomeLabel,
730
+ probabilityModeConfigs.yes.sourceOutcomeLabel,
731
+ venueMarkets
732
+ ]);
733
+ useEffect(() => {
734
+ if (isDateOutcomeMarket) {
735
+ return;
736
+ }
737
+ const nextMode = selectedOutcomeLabel === probabilityModeConfigs.no.sourceOutcomeLabel ? "no" : "yes";
738
+ setActiveProbabilityMode(nextMode);
739
+ }, [isDateOutcomeMarket, probabilityModeConfigs.no.sourceOutcomeLabel, selectedOutcomeLabel]);
740
+ const normalizedVenueDataByMode = useMemo2(() => {
741
+ const buildModeData = (mode) => {
742
+ const modeConfig = probabilityModeConfigs[mode];
743
+ return selectedOutcomesByMode[mode].map((outcomeByVenue, index) => {
744
+ const rawProbability = normalizeProbability(outcomeByVenue.outcome.price);
745
+ const transformedProbability = rawProbability == null ? void 0 : clampProbability(modeConfig.transformProbability(rawProbability));
746
+ return {
747
+ venue: outcomeByVenue.venue,
748
+ venueLabel: resolveVenueLabel(outcomeByVenue.venue, venueInfo, labels),
749
+ market: outcomeByVenue.market,
750
+ outcome: outcomeByVenue.outcome,
751
+ probability: transformedProbability,
752
+ color: resolveSeriesColor(outcomeByVenue.venue, index)
753
+ };
754
+ });
755
+ };
756
+ return {
757
+ yes: buildModeData("yes"),
758
+ no: buildModeData("no")
759
+ };
760
+ }, [labels, probabilityModeConfigs, selectedOutcomesByMode, venueInfo]);
761
+ const allOutcomesForHistory = useMemo2(() => {
762
+ const outcomeByModeAndId = /* @__PURE__ */ new Map();
763
+ probabilityModeOrder.forEach((mode) => {
764
+ selectedOutcomesByMode[mode].forEach((outcomeByVenue) => {
765
+ outcomeByModeAndId.set(
766
+ `${outcomeByVenue.venue}:${outcomeByVenue.outcome.id}`,
767
+ outcomeByVenue
768
+ );
769
+ });
770
+ });
771
+ return [...outcomeByModeAndId.values()];
772
+ }, [selectedOutcomesByMode]);
773
+ const priceHistoryGroups = useMemo2(() => {
774
+ return buildPriceHistoryGroups(allOutcomesForHistory, canonicalMarketId);
775
+ }, [allOutcomesForHistory, canonicalMarketId]);
776
+ const timeWindow = useMemo2(() => {
777
+ return getTimeWindowByRange(selectedTimeRange);
778
+ }, [selectedTimeRange]);
779
+ const {
780
+ data: priceHistoryData,
781
+ isLoading: isPriceHistoryLoading,
782
+ error: priceHistoryError,
783
+ results: priceHistoryResults
784
+ } = usePriceHistory(__spreadProps(__spreadValues({
785
+ groups: priceHistoryGroups
786
+ }, timeWindow), {
787
+ enabled: priceHistoryGroups.length > 0
788
+ }));
789
+ const priceHistoryByVenue = useMemo2(() => {
790
+ const historyByVenue = /* @__PURE__ */ new Map();
791
+ if (!(priceHistoryData == null ? void 0 : priceHistoryData.length)) {
792
+ return historyByVenue;
793
+ }
794
+ priceHistoryData.forEach((historyItem) => {
795
+ const venue = historyItem.venue;
796
+ const venueHistory = historyByVenue.get(venue);
797
+ if (venueHistory) {
798
+ venueHistory.push(historyItem);
799
+ return;
800
+ }
801
+ historyByVenue.set(venue, [historyItem]);
802
+ });
803
+ return historyByVenue;
804
+ }, [priceHistoryData]);
805
+ const chartSeriesByMode = useMemo2(() => {
806
+ const buildSeries = (mode) => {
807
+ const modeConfig = probabilityModeConfigs[mode];
808
+ const chartSeries = [];
809
+ normalizedVenueDataByMode[mode].forEach((venueData) => {
810
+ var _a;
811
+ const venueHistory = priceHistoryByVenue.get(venueData.venue);
812
+ if (!(venueHistory == null ? void 0 : venueHistory.length))
813
+ return;
814
+ const candidateIds = resolveOutcomeCandidateIds(venueData.market, venueData.outcome);
815
+ const matchingHistory = (_a = venueHistory.find((historyItem) => candidateIds.includes(historyItem.marketId))) != null ? _a : venueHistory.length === 1 ? venueHistory[0] : void 0;
816
+ if (!matchingHistory)
817
+ return;
818
+ const points = matchingHistory.points.map((point) => {
819
+ const probability = normalizeProbability(point.price);
820
+ if (probability == null || !Number.isFinite(point.timestamp))
821
+ return null;
822
+ return {
823
+ time: point.timestamp,
824
+ value: clampProbability(modeConfig.transformProbability(probability)) * 100
825
+ };
826
+ }).filter((point) => point != null);
827
+ if (points.length === 0)
828
+ return;
829
+ chartSeries.push({
830
+ id: `${mode}-${venueData.venue}-${matchingHistory.marketId}`,
831
+ venue: venueData.venue,
832
+ color: venueData.color,
833
+ points,
834
+ lineWidth: 2,
835
+ lineStyle: "solid"
836
+ });
837
+ });
838
+ return chartSeries;
839
+ };
840
+ return {
841
+ yes: buildSeries("yes"),
842
+ no: buildSeries("no")
843
+ };
844
+ }, [normalizedVenueDataByMode, priceHistoryByVenue, probabilityModeConfigs]);
845
+ const visibleChartSeries = useMemo2(() => {
846
+ const modeSeries = chartSeriesByMode[activeProbabilityMode];
847
+ if (!selectedVenue)
848
+ return modeSeries;
849
+ return modeSeries.filter((seriesItem) => seriesItem.venue === selectedVenue);
850
+ }, [activeProbabilityMode, chartSeriesByMode, selectedVenue]);
851
+ const segmentedDisplayItems = useMemo2(() => {
852
+ return probabilityModeOrder.map((mode) => {
853
+ const averageProbability = resolveAverageProbability(
854
+ normalizedVenueDataByMode[mode].map((venueData) => venueData.probability)
855
+ );
856
+ const suffix = averageProbability == null ? "" : ` ${formatPercent(averageProbability)}`;
857
+ const switchLabel = probabilityModeConfigs[mode].switchLabel;
858
+ return {
859
+ mode,
860
+ display: `${switchLabel}${suffix}`
861
+ };
862
+ });
863
+ }, [formatPercent, normalizedVenueDataByMode, probabilityModeConfigs]);
864
+ const activeModeVenueData = normalizedVenueDataByMode[activeProbabilityMode];
865
+ useEffect(() => {
866
+ if (!selectedVenue) {
867
+ return;
868
+ }
869
+ if (activeModeVenueData.some((item) => item.venue === selectedVenue)) {
870
+ return;
871
+ }
872
+ setSelectedVenue(null);
873
+ }, [activeModeVenueData, selectedVenue]);
874
+ const handleProbabilityModeChange = (nextMode) => {
875
+ setActiveProbabilityMode(nextMode);
876
+ if (isDateOutcomeMarket) {
877
+ return;
878
+ }
879
+ onSelectedOutcomeLabelChange(probabilityModeConfigs[nextMode].sourceOutcomeLabel);
880
+ };
881
+ const handleVenueToggle = (venue) => {
882
+ setSelectedVenue((currentSelectedVenue) => {
883
+ if (currentSelectedVenue === venue)
884
+ return null;
885
+ return venue;
886
+ });
887
+ };
888
+ const handleRetryPriceHistory = () => {
889
+ void Promise.all(priceHistoryResults.map((result) => result.refetch()));
890
+ };
891
+ if (priceHistoryError) {
892
+ return /* @__PURE__ */ jsx2(
893
+ "div",
894
+ {
895
+ className: cn(
896
+ "w-full rounded-agg-xl border border-agg-separator bg-agg-secondary",
897
+ classNames == null ? void 0 : classNames.chart
898
+ ),
899
+ children: /* @__PURE__ */ jsx2(
900
+ StateMessage,
901
+ {
902
+ ariaLabel: labels.eventItemDetails.chartUnavailableAria,
903
+ tone: "warning",
904
+ title: labels.eventItemDetails.chartUnavailableTitle,
905
+ description: labels.eventItemDetails.chartUnavailableDescription,
906
+ actionLabel: labels.common.retry,
907
+ onAction: handleRetryPriceHistory,
908
+ className: "min-h-[300px] px-5 py-10 md:px-10"
909
+ }
910
+ )
911
+ }
912
+ );
913
+ }
914
+ return /* @__PURE__ */ jsx2(
915
+ LineChart,
916
+ {
917
+ classNames: { root: classNames == null ? void 0 : classNames.chart },
918
+ series: visibleChartSeries,
919
+ height: 300,
920
+ isLoading: isPriceHistoryLoading,
921
+ showSeriesControls: activeModeVenueData.length > 0 || segmentedDisplayItems.length > 0,
922
+ renderSeriesControls: () => {
923
+ return /* @__PURE__ */ jsxs2(
924
+ "div",
925
+ {
926
+ className: cn("flex flex-row items-center justify-between gap-4", classNames == null ? void 0 : classNames.summary),
927
+ children: [
928
+ /* @__PURE__ */ jsx2(
929
+ "div",
930
+ {
931
+ className: cn(
932
+ "flex min-w-0 gap-2 overflow-x-auto pb-1 md:flex-wrap md:overflow-visible md:pb-0",
933
+ classNames == null ? void 0 : classNames.outcomeBadges
934
+ ),
935
+ children: activeModeVenueData.map((venueData) => {
936
+ var _a;
937
+ const text = venueData.probability == null ? "-" : formatPercent(venueData.probability);
938
+ const isActiveVenue = selectedVenue === venueData.venue;
939
+ return /* @__PURE__ */ jsx2(
940
+ "button",
941
+ {
942
+ type: "button",
943
+ "aria-label": `${venueData.venueLabel} ${text}`,
944
+ "aria-pressed": isActiveVenue,
945
+ className: cn(
946
+ "rounded-agg-full focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-agg-primary focus-visible:ring-offset-2 focus-visible:ring-offset-agg-secondary-hover"
947
+ ),
948
+ children: /* @__PURE__ */ jsx2(
949
+ Badge,
950
+ {
951
+ text,
952
+ size: "large",
953
+ prefix: showVenueLogo ? /* @__PURE__ */ jsx2(
954
+ VenueLogo,
955
+ {
956
+ venue: venueData.venue,
957
+ size: "small",
958
+ title: (_a = venueInfo == null ? void 0 : venueInfo[venueData.venue]) == null ? void 0 : _a.label
959
+ }
960
+ ) : void 0,
961
+ classNames: {
962
+ root: cn("h-9 shrink-0 border-2 px-4 text-agg-base leading-agg-6")
963
+ },
964
+ isActive: isActiveVenue,
965
+ onClick: (e) => {
966
+ e.preventDefault();
967
+ e.stopPropagation();
968
+ handleVenueToggle(venueData.venue);
969
+ }
970
+ }
971
+ )
972
+ },
973
+ `${activeProbabilityMode}-${venueData.market.id}-${venueData.outcome.id}`
974
+ );
975
+ })
976
+ }
977
+ ),
978
+ /* @__PURE__ */ jsx2(
979
+ SwitchButton,
980
+ {
981
+ ariaLabel: labels.eventItemDetails.outcomeSelectorAria,
982
+ className: cn("w-full md:w-fit", classNames == null ? void 0 : classNames.segmentedControl),
983
+ value: activeProbabilityMode,
984
+ onValueChange: handleProbabilityModeChange,
985
+ options: segmentedDisplayItems.map((segmentedItem) => ({
986
+ value: segmentedItem.mode,
987
+ label: segmentedItem.display,
988
+ ariaLabel: segmentedItem.display
989
+ }))
990
+ }
991
+ )
992
+ ]
993
+ }
994
+ );
995
+ }
996
+ }
997
+ );
998
+ };
999
+ var EventListItemDetailsContent = ({
1000
+ event,
1001
+ title,
1002
+ image,
1003
+ showVenueLogo = true,
1004
+ classNames,
1005
+ venueInfo,
1006
+ detailsStats,
1007
+ ariaLabel,
1008
+ defaultTimeRange
1009
+ }) => {
1010
+ var _a, _b;
1011
+ const config = useSdkUiConfig2();
1012
+ const labels = useLabels2();
1013
+ const venueMarkets = useMemo2(() => {
1014
+ var _a2, _b2, _c;
1015
+ return (_c = (_b2 = (_a2 = event.markets) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.venueMarkets) != null ? _c : [];
1016
+ }, [event.markets]);
1017
+ const primaryVenueMarket = useMemo2(() => {
1018
+ return selectPrimaryVenueMarket(venueMarkets);
1019
+ }, [venueMarkets]);
1020
+ const outcomeLabels = useMemo2(() => {
1021
+ return resolveOutcomeLabels(venueMarkets);
1022
+ }, [venueMarkets]);
1023
+ const [selectedOutcomeLabel, setSelectedOutcomeLabel] = useState(() => {
1024
+ return resolveDefaultOutcomeLabel(outcomeLabels);
1025
+ });
1026
+ const [selectedTimeRange, setSelectedTimeRange] = useState(() => {
1027
+ return getDefaultSelectedTimeRange(defaultTimeRange);
1028
+ });
1029
+ useEffect(() => {
1030
+ setSelectedTimeRange(getDefaultSelectedTimeRange(defaultTimeRange));
1031
+ }, [defaultTimeRange]);
1032
+ const resolvedTitle = resolveTileTitle(event, primaryVenueMarket, title);
1033
+ const resolvedImage = resolveTileImage(event, primaryVenueMarket, image);
1034
+ const isDateOutcomeMarket = outcomeLabels.length > 2 && outcomeLabels.every(isDateLikeLabel);
1035
+ const outcomeSelectorLabels = outcomeLabels;
1036
+ const probabilityByLabel = useMemo2(() => {
1037
+ return new Map(
1038
+ outcomeLabels.map((label) => {
1039
+ const outcomesByVenue = resolveOutcomesByVenue(venueMarkets, label);
1040
+ const probabilities = outcomesByVenue.map((item) => normalizeProbability(item.outcome.price)).filter((value) => value != null);
1041
+ if (probabilities.length === 0) {
1042
+ return [label, void 0];
1043
+ }
1044
+ const averageProbability = probabilities.reduce((sum, value) => sum + value, 0) / probabilities.length;
1045
+ return [label, averageProbability];
1046
+ })
1047
+ );
1048
+ }, [outcomeLabels, venueMarkets]);
1049
+ const mainOutcomeLabel = useMemo2(() => {
1050
+ if (outcomeLabels.length === 0)
1051
+ return void 0;
1052
+ return [...outcomeLabels].sort((left, right) => {
1053
+ var _a2, _b2;
1054
+ const leftProbability = (_a2 = probabilityByLabel.get(left)) != null ? _a2 : -1;
1055
+ const rightProbability = (_b2 = probabilityByLabel.get(right)) != null ? _b2 : -1;
1056
+ return rightProbability - leftProbability;
1057
+ })[0];
1058
+ }, [outcomeLabels, probabilityByLabel]);
1059
+ useEffect(() => {
1060
+ if (!outcomeLabels.length) {
1061
+ setSelectedOutcomeLabel(void 0);
1062
+ return;
1063
+ }
1064
+ if (selectedOutcomeLabel && outcomeLabels.includes(selectedOutcomeLabel)) {
1065
+ return;
1066
+ }
1067
+ const fallbackOutcomeLabel = isDateOutcomeMarket ? resolveDefaultOutcomeLabel(outcomeLabels) : mainOutcomeLabel != null ? mainOutcomeLabel : resolveDefaultOutcomeLabel(outcomeLabels);
1068
+ setSelectedOutcomeLabel(fallbackOutcomeLabel);
1069
+ }, [isDateOutcomeMarket, mainOutcomeLabel, outcomeLabels, selectedOutcomeLabel]);
1070
+ const switchLabels = useMemo2(() => {
1071
+ var _a2, _b2;
1072
+ if (isDateOutcomeMarket) {
1073
+ return [labels.eventItemDetails.yes, labels.eventItemDetails.no];
1074
+ }
1075
+ const sortedOutcomeLabels = [...outcomeLabels].sort((left, right) => {
1076
+ var _a3, _b3;
1077
+ const leftProbability = (_a3 = probabilityByLabel.get(left)) != null ? _a3 : -1;
1078
+ const rightProbability = (_b3 = probabilityByLabel.get(right)) != null ? _b3 : -1;
1079
+ return rightProbability - leftProbability;
1080
+ });
1081
+ const firstLabel = (_a2 = sortedOutcomeLabels[0]) != null ? _a2 : labels.eventItemDetails.yes;
1082
+ const secondLabel = (_b2 = sortedOutcomeLabels.find((label) => label !== firstLabel)) != null ? _b2 : firstLabel;
1083
+ return [firstLabel, secondLabel];
1084
+ }, [
1085
+ isDateOutcomeMarket,
1086
+ labels.eventItemDetails.no,
1087
+ labels.eventItemDetails.yes,
1088
+ outcomeLabels,
1089
+ probabilityByLabel
1090
+ ]);
1091
+ const volumeLabel = useMemo2(() => {
1092
+ var _a2;
1093
+ const resolvedVolume = typeof event.volume === "number" ? event.volume : (_a2 = primaryVenueMarket == null ? void 0 : primaryVenueMarket.volume) != null ? _a2 : void 0;
1094
+ if (typeof resolvedVolume !== "number")
1095
+ return "";
1096
+ return `${config.formatCompactCurrency(resolvedVolume)} ${labels.eventItemDetails.volumeSuffix}`;
1097
+ }, [config, event.volume, labels.eventItemDetails.volumeSuffix, primaryVenueMarket == null ? void 0 : primaryVenueMarket.volume]);
1098
+ if (!primaryVenueMarket || !selectedOutcomeLabel) {
1099
+ return /* @__PURE__ */ jsx2(EventListItemDetailsUnavailableState, { classNames, ariaLabel });
1100
+ }
1101
+ return /* @__PURE__ */ jsxs2(
1102
+ Card,
1103
+ {
1104
+ className: cn(detailsBaseCardClassName, classNames == null ? void 0 : classNames.root),
1105
+ "aria-label": ariaLabel != null ? ariaLabel : resolvedTitle,
1106
+ children: [
1107
+ /* @__PURE__ */ jsxs2(
1108
+ "div",
1109
+ {
1110
+ className: cn(
1111
+ "flex flex-row gap-3 md:gap-4",
1112
+ "items-center justify-start",
1113
+ classNames == null ? void 0 : classNames.header
1114
+ ),
1115
+ children: [
1116
+ resolvedImage ? /* @__PURE__ */ jsx2(
1117
+ "img",
1118
+ {
1119
+ src: resolvedImage,
1120
+ alt: "",
1121
+ className: "size-10 rounded-agg-lg object-cover md:size-[60px]"
1122
+ }
1123
+ ) : null,
1124
+ /* @__PURE__ */ jsxs2("div", { className: "flex min-w-0 flex-1 flex-col gap-3", children: [
1125
+ /* @__PURE__ */ jsx2(
1126
+ Typography,
1127
+ {
1128
+ variant: "body-strong",
1129
+ className: cn(
1130
+ "min-w-0 text-agg-base font-agg-bold! leading-agg-6 md:text-agg-2xl md:leading-agg-8",
1131
+ "truncate text-wrap wrap-break-word line-clamp-2",
1132
+ classNames == null ? void 0 : classNames.title
1133
+ ),
1134
+ children: resolvedTitle
1135
+ }
1136
+ ),
1137
+ outcomeSelectorLabels.length > 2 ? /* @__PURE__ */ jsx2(
1138
+ "div",
1139
+ {
1140
+ className: cn(
1141
+ "flex items-center gap-2 overflow-x-auto pb-1 md:flex-wrap md:overflow-visible md:pb-0",
1142
+ classNames == null ? void 0 : classNames.headerPills
1143
+ ),
1144
+ children: outcomeSelectorLabels.map((outcomeSelectorLabel) => {
1145
+ const isActive = outcomeSelectorLabel === selectedOutcomeLabel;
1146
+ const displayLabel = isDateLikeLabel(outcomeSelectorLabel) ? formatDateLabel(outcomeSelectorLabel) : outcomeSelectorLabel;
1147
+ return /* @__PURE__ */ jsx2(
1148
+ Button,
1149
+ {
1150
+ size: "small",
1151
+ variant: "secondary",
1152
+ "aria-pressed": isActive,
1153
+ className: cn(
1154
+ "h-auto shrink-0 rounded-agg-full px-4 py-1.5 text-agg-sm leading-agg-5",
1155
+ "border-2",
1156
+ isActive ? "border-agg-primary bg-agg-secondary text-agg-foreground font-agg-bold" : "border-transparent bg-agg-secondary-hover text-agg-foreground font-agg-normal"
1157
+ ),
1158
+ onClick: () => setSelectedOutcomeLabel(outcomeSelectorLabel),
1159
+ children: displayLabel
1160
+ },
1161
+ outcomeSelectorLabel
1162
+ );
1163
+ })
1164
+ }
1165
+ ) : null
1166
+ ] })
1167
+ ]
1168
+ }
1169
+ ),
1170
+ detailsStats && detailsStats.length > 0 ? /* @__PURE__ */ jsx2("div", { className: cn("flex flex-wrap items-start gap-4 md:gap-6", classNames == null ? void 0 : classNames.headerStats), children: detailsStats.map((statItem) => {
1171
+ const deltaClassName = statItem.deltaTone === "positive" ? "text-agg-success!" : statItem.deltaTone === "negative" ? "text-agg-error!" : "text-agg-muted-foreground";
1172
+ return /* @__PURE__ */ jsxs2("div", { className: "flex flex-col gap-1", children: [
1173
+ /* @__PURE__ */ jsx2(Typography, { variant: "caption-caps", className: "text-agg-muted-foreground", children: statItem.label }),
1174
+ /* @__PURE__ */ jsxs2("div", { className: "flex items-baseline gap-1", children: [
1175
+ /* @__PURE__ */ jsx2(
1176
+ Typography,
1177
+ {
1178
+ variant: "body",
1179
+ className: "text-agg-lg leading-agg-7 text-agg-foreground",
1180
+ children: statItem.value
1181
+ }
1182
+ ),
1183
+ statItem.delta ? /* @__PURE__ */ jsx2(Typography, { variant: "label", className: cn(deltaClassName), children: statItem.delta }) : null
1184
+ ] })
1185
+ ] }, `${statItem.label}-${statItem.value}`);
1186
+ }) }) : null,
1187
+ /* @__PURE__ */ jsx2(
1188
+ EventListItemDetailsGraphSection,
1189
+ {
1190
+ venueMarkets,
1191
+ canonicalMarketId: (_b = (_a = event.markets) == null ? void 0 : _a[0]) == null ? void 0 : _b.id,
1192
+ selectedOutcomeLabel,
1193
+ onSelectedOutcomeLabelChange: setSelectedOutcomeLabel,
1194
+ switchLabels,
1195
+ isDateOutcomeMarket,
1196
+ classNames,
1197
+ showVenueLogo,
1198
+ venueInfo,
1199
+ formatPercent: config.formatPercent,
1200
+ selectedTimeRange
1201
+ }
1202
+ ),
1203
+ /* @__PURE__ */ jsxs2("div", { className: cn("flex flex-wrap items-center justify-between gap-4", classNames == null ? void 0 : classNames.footer), children: [
1204
+ /* @__PURE__ */ jsx2(Typography, { variant: "label", className: "text-agg-muted-foreground", children: volumeLabel || "-" }),
1205
+ /* @__PURE__ */ jsx2("div", { className: cn("flex items-center gap-2 md:gap-3", classNames == null ? void 0 : classNames.timeRange), children: eventListItemDetailsTimeRanges.map((timeRange) => {
1206
+ const isActive = timeRange === selectedTimeRange;
1207
+ return /* @__PURE__ */ jsx2(
1208
+ Button,
1209
+ {
1210
+ size: "small",
1211
+ variant: "tertiary",
1212
+ className: cn(
1213
+ "h-auto min-w-0 rounded-none px-0 py-0 text-agg-xs leading-agg-4 md:text-agg-sm md:leading-agg-5",
1214
+ "border-0 bg-transparent shadow-none",
1215
+ "hover:text-agg-foreground!",
1216
+ isActive ? "font-agg-bold! text-agg-foreground!" : "font-agg-normal! text-agg-muted-foreground!"
1217
+ ),
1218
+ "aria-pressed": isActive,
1219
+ onClick: () => setSelectedTimeRange(timeRange),
1220
+ children: timeRange === "ALL" ? labels.eventItemDetails.allTimeRange : timeRange
1221
+ },
1222
+ timeRange
1223
+ );
1224
+ }) })
1225
+ ] })
1226
+ ]
1227
+ }
1228
+ );
1229
+ };
1230
+ var EventListItemDetailsByEventId = (_a) => {
1231
+ var _b = _a, {
1232
+ eventId
1233
+ } = _b, rest = __objRest(_b, [
1234
+ "eventId"
1235
+ ]);
1236
+ const {
1237
+ event: fetchedEvent,
1238
+ error,
1239
+ isError,
1240
+ isLoading
1241
+ } = useEvent2(eventId, {
1242
+ enabled: !!eventId
1243
+ });
1244
+ const resolvedEvent = useMemo2(() => {
1245
+ return resolveEventListItemEvent(fetchedEvent);
1246
+ }, [fetchedEvent]);
1247
+ if (!eventId) {
1248
+ return /* @__PURE__ */ jsx2(
1249
+ EventListItemDetailsUnavailableState,
1250
+ {
1251
+ classNames: rest.classNames,
1252
+ ariaLabel: rest.ariaLabel
1253
+ }
1254
+ );
1255
+ }
1256
+ if (isLoading) {
1257
+ return /* @__PURE__ */ jsx2(EventListItemDetailsLoadingState, { classNames: rest.classNames, ariaLabel: rest.ariaLabel });
1258
+ }
1259
+ if (isErrorWithStatus(error, 404)) {
1260
+ return /* @__PURE__ */ jsx2(EventListItemDetailsNotFoundState, { classNames: rest.classNames, ariaLabel: rest.ariaLabel });
1261
+ }
1262
+ if (!fetchedEvent && !isError) {
1263
+ return /* @__PURE__ */ jsx2(EventListItemDetailsLoadingState, { classNames: rest.classNames, ariaLabel: rest.ariaLabel });
1264
+ }
1265
+ if (!resolvedEvent) {
1266
+ return /* @__PURE__ */ jsx2(
1267
+ EventListItemDetailsUnavailableState,
1268
+ {
1269
+ classNames: rest.classNames,
1270
+ ariaLabel: rest.ariaLabel
1271
+ }
1272
+ );
1273
+ }
1274
+ return /* @__PURE__ */ jsx2(EventListItemDetailsContent, __spreadValues({ event: resolvedEvent }, rest));
1275
+ };
1276
+ var EventListItemDetails = (props) => {
1277
+ if (props.isLoading) {
1278
+ return /* @__PURE__ */ jsx2(EventListItemDetailsLoadingState, { classNames: props.classNames, ariaLabel: props.ariaLabel });
1279
+ }
1280
+ if ("event" in props && props.event) {
1281
+ const _a = props, { event } = _a, rest = __objRest(_a, ["event"]);
1282
+ return /* @__PURE__ */ jsx2(EventListItemDetailsContent, __spreadValues({ event }, rest));
1283
+ }
1284
+ if ("eventId" in props && typeof props.eventId === "string") {
1285
+ const {
1286
+ title: titleOverride,
1287
+ image: imageOverride,
1288
+ showVenueLogo: showVenueLogoOverride,
1289
+ classNames,
1290
+ venueInfo,
1291
+ detailsStats,
1292
+ ariaLabel: ariaLabelOverride,
1293
+ defaultTimeRange: defaultTimeRangeOverride
1294
+ } = props;
1295
+ const byEventIdProps = {
1296
+ eventId: props.eventId,
1297
+ isLoading: false,
1298
+ title: titleOverride,
1299
+ image: imageOverride,
1300
+ showVenueLogo: showVenueLogoOverride,
1301
+ classNames,
1302
+ venueInfo,
1303
+ detailsStats,
1304
+ ariaLabel: ariaLabelOverride,
1305
+ defaultTimeRange: defaultTimeRangeOverride
1306
+ };
1307
+ return /* @__PURE__ */ jsx2(EventListItemDetailsByEventId, __spreadValues({}, byEventIdProps));
1308
+ }
1309
+ return /* @__PURE__ */ jsx2(
1310
+ EventListItemDetailsUnavailableState,
1311
+ {
1312
+ classNames: props.classNames,
1313
+ ariaLabel: props.ariaLabel
1314
+ }
1315
+ );
1316
+ };
1317
+ EventListItemDetails.displayName = "EventListItemDetails";
1318
+
1319
+ // src/events/market-details/index.tsx
1320
+ import { useEffect as useEffect2, useId, useMemo as useMemo3, useState as useState2 } from "react";
1321
+ import {
1322
+ useEvent as useEvent3,
1323
+ useLabels as useLabels3,
1324
+ useOrderBook,
1325
+ usePriceHistory as usePriceHistory2,
1326
+ useSdkUiConfig as useSdkUiConfig3
1327
+ } from "@agg-market/hooks";
1328
+
1329
+ // src/events/market-details/market-details.utils.ts
1330
+ import dayjs3 from "dayjs";
1331
+ import { z } from "zod";
1332
+ var MarketDetailsTabSchema = z.enum(["order-book", "graph", "other"]);
1333
+ var OrderBookLevelSchema = z.object({
1334
+ price: z.number().min(0).max(1),
1335
+ size: z.number().nonnegative()
1336
+ });
1337
+ var OrderBookRowSchema = z.object({
1338
+ id: z.string(),
1339
+ venue: z.enum(["kalshi", "polymarket"]),
1340
+ price: z.number().min(0).max(1),
1341
+ size: z.number().nonnegative(),
1342
+ total: z.number().nonnegative(),
1343
+ tone: z.enum(["positive", "negative"])
1344
+ });
1345
+ var normalizeLabel2 = (value) => {
1346
+ return value.trim().toLowerCase();
1347
+ };
1348
+ var hasBinaryLabels = (labels) => {
1349
+ const normalizedLabels = labels.map(normalizeLabel2);
1350
+ return normalizedLabels.includes("yes") && normalizedLabels.includes("no");
1351
+ };
1352
+ var resolveInitialTab = (defaultTab) => {
1353
+ const parsedTab = MarketDetailsTabSchema.safeParse(defaultTab);
1354
+ if (parsedTab.success)
1355
+ return parsedTab.data;
1356
+ return "order-book";
1357
+ };
1358
+ var resolveMarket = (event, marketId) => {
1359
+ if (!event.markets.length)
1360
+ return void 0;
1361
+ if (!marketId)
1362
+ return event.markets[0];
1363
+ return event.markets.find((market) => market.id === marketId);
1364
+ };
1365
+ var resolveDisplayOutcomeLabels = (labels) => {
1366
+ if (!hasBinaryLabels(labels))
1367
+ return labels;
1368
+ return ["Yes", "No"].filter(
1369
+ (label) => labels.some((value) => normalizeLabel2(value) === normalizeLabel2(label))
1370
+ );
1371
+ };
1372
+ var resolveInitialOutcomeLabel = (labels, defaultOutcomeLabel) => {
1373
+ var _a;
1374
+ if (labels.length === 0)
1375
+ return void 0;
1376
+ if (defaultOutcomeLabel) {
1377
+ const matchedLabel = labels.find(
1378
+ (label) => normalizeLabel2(label) === normalizeLabel2(defaultOutcomeLabel)
1379
+ );
1380
+ if (matchedLabel)
1381
+ return matchedLabel;
1382
+ }
1383
+ if (hasBinaryLabels(labels)) {
1384
+ return (_a = labels.find((label) => normalizeLabel2(label) === "yes")) != null ? _a : labels[0];
1385
+ }
1386
+ return labels[0];
1387
+ };
1388
+ var resolveAverageProbabilityByLabel = (venueMarkets, labels) => {
1389
+ return new Map(
1390
+ labels.map((label) => {
1391
+ const matchingOutcomes = resolveOutcomesByVenue(venueMarkets, label);
1392
+ const probabilities = matchingOutcomes.map((item) => normalizeProbability(item.outcome.price)).filter((value) => value != null);
1393
+ if (!probabilities.length) {
1394
+ return [label, void 0];
1395
+ }
1396
+ const averageProbability = probabilities.reduce((sum, value) => sum + value, 0) / probabilities.length;
1397
+ return [label, averageProbability];
1398
+ })
1399
+ );
1400
+ };
1401
+ var formatProbabilityPercent = (value) => {
1402
+ if (value == null)
1403
+ return "-";
1404
+ return `${Math.round(value * 100)}%`;
1405
+ };
1406
+ var formatProbabilityCents = (value) => {
1407
+ if (value == null)
1408
+ return "-";
1409
+ const cents = (value * 100).toFixed(1).replace(/\.0$/, "");
1410
+ return `${cents}\xA2`;
1411
+ };
1412
+ var resolveOutcomeTone = (label, index) => {
1413
+ const normalizedLabel = normalizeLabel2(label);
1414
+ if (normalizedLabel === "yes" || normalizedLabel === "up" || normalizedLabel === "buy") {
1415
+ return "positive";
1416
+ }
1417
+ if (normalizedLabel === "no" || normalizedLabel === "down" || normalizedLabel === "sell") {
1418
+ return "negative";
1419
+ }
1420
+ return index === 0 ? "positive" : "negative";
1421
+ };
1422
+ var resolveHeaderOutcomeItems = (venueMarkets, defaultOutcomeLabel) => {
1423
+ const labels = resolveDisplayOutcomeLabels(resolveOutcomeLabels(venueMarkets));
1424
+ const probabilityByLabel = resolveAverageProbabilityByLabel(venueMarkets, labels);
1425
+ return labels.slice(0, 2).map((label, index) => {
1426
+ var _a;
1427
+ return {
1428
+ label,
1429
+ probability: probabilityByLabel.get(label),
1430
+ tone: resolveOutcomeTone(label, index),
1431
+ isDefault: normalizeLabel2(label) === normalizeLabel2((_a = defaultOutcomeLabel != null ? defaultOutcomeLabel : labels[0]) != null ? _a : "")
1432
+ };
1433
+ });
1434
+ };
1435
+ var resolveSubtitle = ({
1436
+ venueMarkets,
1437
+ volume,
1438
+ formatCompactCurrency,
1439
+ labels
1440
+ }) => {
1441
+ const { venueCount } = getVenueSummary(venueMarkets);
1442
+ const parts = [
1443
+ `${venueCount} ${venueCount === 1 ? labels.marketDetails.meta.venueSingular : labels.marketDetails.meta.venuePlural}`
1444
+ ];
1445
+ if (typeof volume === "number") {
1446
+ parts.push(`${formatCompactCurrency(volume)} ${labels.marketDetails.meta.volumeSuffix}`);
1447
+ }
1448
+ return parts.join(" \xB7 ");
1449
+ };
1450
+ var resolveOrderBookRows = ({
1451
+ data,
1452
+ side
1453
+ }) => {
1454
+ if (!(data == null ? void 0 : data.length))
1455
+ return [];
1456
+ const tone = side === "asks" ? "negative" : "positive";
1457
+ const rows = data.flatMap((result) => {
1458
+ var _a;
1459
+ return ((_a = result.orderbook[side]) != null ? _a : []).flatMap(
1460
+ (level, index) => {
1461
+ const parsedLevel = OrderBookLevelSchema.safeParse(level);
1462
+ if (!parsedLevel.success)
1463
+ return [];
1464
+ const parsedRow = OrderBookRowSchema.safeParse({
1465
+ id: `${result.market.id}-${side}-${index}-${parsedLevel.data.price}`,
1466
+ venue: result.market.venue,
1467
+ price: parsedLevel.data.price,
1468
+ size: parsedLevel.data.size,
1469
+ total: parsedLevel.data.price * parsedLevel.data.size,
1470
+ tone
1471
+ });
1472
+ if (!parsedRow.success)
1473
+ return [];
1474
+ return [parsedRow.data];
1475
+ }
1476
+ );
1477
+ });
1478
+ const sortedRows = [...rows].sort((left, right) => {
1479
+ if (side === "asks")
1480
+ return left.price - right.price;
1481
+ return right.price - left.price;
1482
+ });
1483
+ const maxTotal = sortedRows.reduce((currentMax, row) => Math.max(currentMax, row.total), 0) || 1;
1484
+ return sortedRows.map((row) => __spreadProps(__spreadValues({}, row), {
1485
+ barScale: row.total / maxTotal
1486
+ }));
1487
+ };
1488
+ var resolveOtherTabRows = (market, labels) => {
1489
+ var _a;
1490
+ const rows = [];
1491
+ rows.push({
1492
+ label: labels.marketDetails.meta.status,
1493
+ value: (_a = market.status) != null ? _a : labels.marketDetails.meta.unknown
1494
+ });
1495
+ if (market.creationDate) {
1496
+ rows.push({
1497
+ label: labels.marketDetails.meta.created,
1498
+ value: dayjs3(market.creationDate).format("MMM D, YYYY")
1499
+ });
1500
+ }
1501
+ if (market.startDate) {
1502
+ rows.push({
1503
+ label: labels.marketDetails.meta.opens,
1504
+ value: dayjs3(market.startDate).format("MMM D, YYYY")
1505
+ });
1506
+ }
1507
+ if (market.endDate) {
1508
+ rows.push({
1509
+ label: labels.marketDetails.meta.closes,
1510
+ value: dayjs3(market.endDate).format("MMM D, YYYY")
1511
+ });
1512
+ }
1513
+ if (rows.length === 1) {
1514
+ rows.push({
1515
+ label: labels.marketDetails.meta.markets,
1516
+ value: `${market.venueMarkets.length}`
1517
+ });
1518
+ }
1519
+ return rows;
1520
+ };
1521
+ var buildMarketDetailsModel = ({
1522
+ event,
1523
+ marketId,
1524
+ title,
1525
+ image,
1526
+ formatCompactCurrency,
1527
+ labels
1528
+ }) => {
1529
+ var _a;
1530
+ const market = resolveMarket(event, marketId);
1531
+ if (!market)
1532
+ return void 0;
1533
+ const primaryVenueMarket = selectPrimaryVenueMarket(market.venueMarkets);
1534
+ if (!primaryVenueMarket)
1535
+ return void 0;
1536
+ const resolvedTitle = resolveTileTitle(event, primaryVenueMarket, title);
1537
+ const resolvedImage = resolveTileImage(event, primaryVenueMarket, image);
1538
+ const resolvedVolume = typeof market.volume === "number" ? market.volume : (_a = primaryVenueMarket.volume) != null ? _a : void 0;
1539
+ const subtitle = resolveSubtitle({
1540
+ venueMarkets: market.venueMarkets,
1541
+ volume: resolvedVolume,
1542
+ formatCompactCurrency,
1543
+ labels
1544
+ });
1545
+ const outcomeLabels = resolveDisplayOutcomeLabels(resolveOutcomeLabels(market.venueMarkets));
1546
+ const probabilityByLabel = resolveAverageProbabilityByLabel(market.venueMarkets, outcomeLabels);
1547
+ return {
1548
+ market,
1549
+ primaryVenueMarket,
1550
+ title: resolvedTitle,
1551
+ image: resolvedImage,
1552
+ subtitle,
1553
+ outcomeLabels,
1554
+ probabilityByLabel
1555
+ };
1556
+ };
1557
+
1558
+ // src/events/market-details/index.tsx
1559
+ import { Fragment, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
1560
+ var MarketDetailsLoadingState = ({
1561
+ isOpened = marketDetailsDefaultIsOpened,
1562
+ ariaLabel,
1563
+ classNames
1564
+ }) => {
1565
+ const labels = useLabels3();
1566
+ return /* @__PURE__ */ jsx3(
1567
+ Skeleton,
1568
+ {
1569
+ view: isOpened ? "market-details-detailed" : "market-details-minified",
1570
+ className: classNames == null ? void 0 : classNames.root,
1571
+ ariaLabel: ariaLabel != null ? ariaLabel : labels.marketDetails.loading
1572
+ }
1573
+ );
1574
+ };
1575
+ var MarketDetailsUnavailableState = ({
1576
+ ariaLabel,
1577
+ classNames
1578
+ }) => {
1579
+ const labels = useLabels3();
1580
+ return /* @__PURE__ */ jsx3(
1581
+ Card,
1582
+ {
1583
+ className: cn(marketDetailsBaseCardClassName, classNames == null ? void 0 : classNames.root),
1584
+ role: "status",
1585
+ "aria-label": ariaLabel != null ? ariaLabel : labels.marketDetails.unavailableAria,
1586
+ children: /* @__PURE__ */ jsxs3("div", { className: "flex flex-col gap-1 p-5", children: [
1587
+ /* @__PURE__ */ jsx3(Typography, { variant: "body-large-strong", children: labels.marketDetails.unavailableTitle }),
1588
+ /* @__PURE__ */ jsx3(Typography, { variant: "label", className: "text-agg-muted-foreground", children: labels.marketDetails.unavailableDescription })
1589
+ ] })
1590
+ }
1591
+ );
1592
+ };
1593
+ var MarketDetailsNotFoundState = ({
1594
+ ariaLabel,
1595
+ classNames
1596
+ }) => {
1597
+ const labels = useLabels3();
1598
+ return /* @__PURE__ */ jsx3(Card, { className: cn(marketDetailsBaseCardClassName, "p-0", classNames == null ? void 0 : classNames.root), children: /* @__PURE__ */ jsx3(
1599
+ StateMessage,
1600
+ {
1601
+ ariaLabel: ariaLabel != null ? ariaLabel : labels.marketDetails.notFoundAria,
1602
+ title: labels.marketDetails.notFoundTitle,
1603
+ description: labels.marketDetails.notFoundDescription,
1604
+ className: "min-h-[280px] md:min-h-[320px]"
1605
+ }
1606
+ ) });
1607
+ };
1608
+ var OrderBookRows = ({
1609
+ rows,
1610
+ title,
1611
+ formatNumber,
1612
+ formatCurrency,
1613
+ visibleRows
1614
+ }) => {
1615
+ const labels = useLabels3();
1616
+ const isAsks = title === labels.marketDetails.asks;
1617
+ const priceClassName = isAsks ? "text-agg-orderbook-ask" : "text-agg-orderbook-bid";
1618
+ const barClassName = isAsks ? "bg-agg-orderbook-ask/10" : "bg-agg-orderbook-bid/10";
1619
+ const maxVisibleRows = Math.max(1, visibleRows);
1620
+ const orderBookRowHeightPx = 28;
1621
+ const orderBookDividerHeightPx = 1;
1622
+ const orderBookRowGapPx = 8;
1623
+ const orderBookVisibleHeightPx = maxVisibleRows * orderBookRowHeightPx + Math.max(0, maxVisibleRows - 1) * (orderBookDividerHeightPx + orderBookRowGapPx);
1624
+ return /* @__PURE__ */ jsxs3("div", { className: "flex flex-col gap-2", children: [
1625
+ /* @__PURE__ */ jsx3(Typography, { variant: "caption-caps", children: title }),
1626
+ /* @__PURE__ */ jsx3(
1627
+ "div",
1628
+ {
1629
+ className: "overflow-y-auto pr-1 flex flex-col gap-2",
1630
+ style: { maxHeight: `${orderBookVisibleHeightPx}px` },
1631
+ role: "region",
1632
+ "aria-label": `${title} order book levels`,
1633
+ children: rows.map((row, index) => /* @__PURE__ */ jsxs3("div", { className: "flex flex-col gap-2", children: [
1634
+ /* @__PURE__ */ jsxs3("div", { className: "grid grid-cols-[52px_1fr_1fr_52px] items-center gap-2 md:grid-cols-[88px_1fr_1fr_minmax(120px,220px)] md:gap-6", children: [
1635
+ /* @__PURE__ */ jsxs3("div", { className: "flex items-center gap-1 md:gap-3", children: [
1636
+ /* @__PURE__ */ jsx3(VenueLogo, { venue: row.venue, size: "small" }),
1637
+ /* @__PURE__ */ jsx3(
1638
+ "span",
1639
+ {
1640
+ className: cn(
1641
+ "text-agg-xs font-agg-bold leading-agg-4 md:text-agg-sm md:leading-agg-5",
1642
+ priceClassName
1643
+ ),
1644
+ children: formatProbabilityCents(row.price)
1645
+ }
1646
+ )
1647
+ ] }),
1648
+ /* @__PURE__ */ jsx3("span", { className: "truncate text-agg-xs leading-agg-4 text-center text-agg-foreground md:text-agg-sm md:leading-agg-5", children: formatNumber(row.size) }),
1649
+ /* @__PURE__ */ jsx3("span", { className: "truncate text-agg-xs leading-agg-4 text-center text-agg-foreground md:text-agg-sm md:leading-agg-5", children: formatCurrency(row.total) }),
1650
+ /* @__PURE__ */ jsx3("div", { className: "flex justify-end", children: /* @__PURE__ */ jsx3(
1651
+ "div",
1652
+ {
1653
+ "aria-hidden": "true",
1654
+ className: cn("h-2 rounded-agg-full", barClassName),
1655
+ style: {
1656
+ width: `${Math.max(20, Math.round(row.barScale * 100))}%`
1657
+ }
1658
+ }
1659
+ ) })
1660
+ ] }),
1661
+ index < rows.length - 1 ? /* @__PURE__ */ jsx3("div", { className: "h-px w-full bg-agg-separator" }) : null
1662
+ ] }, row.id))
1663
+ }
1664
+ )
1665
+ ] });
1666
+ };
1667
+ var getOutcomeButtonClassName = ({
1668
+ enableAnimations,
1669
+ isPositive,
1670
+ isActive
1671
+ }) => {
1672
+ const defaultStateClassName = isPositive ? "border-[#18c15c]/50 bg-[#18c15c]/5 text-agg-foreground hover:bg-[#18c15c]/10" : "border-[#e5455f]/50 bg-[#e5455f]/5 text-agg-foreground hover:bg-[#e5455f]/10";
1673
+ const activeStateClassName = isPositive ? "border-transparent bg-[#18c15c] text-agg-on-primary" : "border-transparent bg-[#e5455f] text-agg-on-primary";
1674
+ return cn(
1675
+ "h-auto min-h-10 flex-1 rounded-agg-full border px-4 py-1.5 text-agg-base leading-agg-6 shadow-none md:flex-none md:min-w-[168px]",
1676
+ getMotionClassName(enableAnimations, "transition-all duration-300 ease-in-out"),
1677
+ isActive ? activeStateClassName : defaultStateClassName,
1678
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-agg-primary focus-visible:ring-offset-2 focus-visible:ring-offset-agg-secondary-hover",
1679
+ "cursor-pointer disabled:cursor-not-allowed disabled:text-agg-muted-foreground",
1680
+ isActive ? "font-agg-bold" : "font-agg-normal"
1681
+ );
1682
+ };
1683
+ var MarketDetailsContent = ({
1684
+ event,
1685
+ marketId,
1686
+ title,
1687
+ image,
1688
+ isOpened: defaultIsOpened = marketDetailsDefaultIsOpened,
1689
+ onOpenChange,
1690
+ defaultTab,
1691
+ defaultOutcomeLabel,
1692
+ defaultTimeRange = "1M",
1693
+ orderBookDepth = orderBookRowLimitDefault,
1694
+ ariaLabel,
1695
+ classNames,
1696
+ otherContent
1697
+ }) => {
1698
+ const config = useSdkUiConfig3();
1699
+ const labels = useLabels3();
1700
+ const detailsContentId = useId();
1701
+ const model = useMemo3(() => {
1702
+ return buildMarketDetailsModel({
1703
+ event,
1704
+ marketId,
1705
+ title,
1706
+ image,
1707
+ formatCompactCurrency: config.formatCompactCurrency,
1708
+ labels
1709
+ });
1710
+ }, [config.formatCompactCurrency, event, image, labels, marketId, title]);
1711
+ const resolvedMarket = useMemo3(() => {
1712
+ return resolveMarket(event, marketId);
1713
+ }, [event, marketId]);
1714
+ const marketDetailsTabs = useMemo3(() => {
1715
+ return getMarketDetailsTabs(labels);
1716
+ }, [labels]);
1717
+ const [selectedTab, setSelectedTab] = useState2(
1718
+ () => resolveInitialTab(defaultTab)
1719
+ );
1720
+ const [isOpened, setIsOpened] = useState2(defaultIsOpened);
1721
+ useEffect2(() => {
1722
+ setSelectedTab(resolveInitialTab(defaultTab));
1723
+ }, [defaultTab]);
1724
+ const [selectedTimeRange, setSelectedTimeRange] = useState2(defaultTimeRange);
1725
+ useEffect2(() => {
1726
+ setSelectedTimeRange(defaultTimeRange);
1727
+ }, [defaultTimeRange]);
1728
+ const [selectedOutcomeLabel, setSelectedOutcomeLabel] = useState2(
1729
+ () => {
1730
+ var _a;
1731
+ return resolveInitialOutcomeLabel((_a = model == null ? void 0 : model.outcomeLabels) != null ? _a : [], defaultOutcomeLabel);
1732
+ }
1733
+ );
1734
+ const [selectedGraphVenue, setSelectedGraphVenue] = useState2(null);
1735
+ useEffect2(() => {
1736
+ var _a;
1737
+ setSelectedOutcomeLabel(
1738
+ resolveInitialOutcomeLabel((_a = model == null ? void 0 : model.outcomeLabels) != null ? _a : [], defaultOutcomeLabel)
1739
+ );
1740
+ }, [defaultOutcomeLabel, model == null ? void 0 : model.outcomeLabels]);
1741
+ const headerOutcomeItems = useMemo3(() => {
1742
+ if (!model)
1743
+ return [];
1744
+ return resolveHeaderOutcomeItems(model.market.venueMarkets, selectedOutcomeLabel);
1745
+ }, [model, selectedOutcomeLabel]);
1746
+ const headlineProbability = useMemo3(() => {
1747
+ if (!model || !selectedOutcomeLabel)
1748
+ return void 0;
1749
+ return model.probabilityByLabel.get(selectedOutcomeLabel);
1750
+ }, [model, selectedOutcomeLabel]);
1751
+ const outcomesByLabel = useMemo3(() => {
1752
+ const outcomesByLabelMap = /* @__PURE__ */ new Map();
1753
+ if (!model) {
1754
+ return outcomesByLabelMap;
1755
+ }
1756
+ headerOutcomeItems.forEach((headerOutcomeItem) => {
1757
+ outcomesByLabelMap.set(
1758
+ headerOutcomeItem.label,
1759
+ resolveOutcomesByVenue(model.market.venueMarkets, headerOutcomeItem.label)
1760
+ );
1761
+ });
1762
+ return outcomesByLabelMap;
1763
+ }, [headerOutcomeItems, model]);
1764
+ const selectedOutcomesByVenue = useMemo3(() => {
1765
+ var _a;
1766
+ if (!selectedOutcomeLabel)
1767
+ return [];
1768
+ return (_a = outcomesByLabel.get(selectedOutcomeLabel)) != null ? _a : [];
1769
+ }, [outcomesByLabel, selectedOutcomeLabel]);
1770
+ const timeWindow = useMemo3(() => {
1771
+ return getTimeWindowByRange(selectedTimeRange);
1772
+ }, [selectedTimeRange]);
1773
+ const graphOutcomes = useMemo3(() => {
1774
+ const uniqueOutcomesByVenueAndId = /* @__PURE__ */ new Map();
1775
+ outcomesByLabel.forEach((outcomes) => {
1776
+ outcomes.forEach((outcomeByVenue) => {
1777
+ uniqueOutcomesByVenueAndId.set(
1778
+ `${outcomeByVenue.venue}:${outcomeByVenue.outcome.id}`,
1779
+ outcomeByVenue
1780
+ );
1781
+ });
1782
+ });
1783
+ return [...uniqueOutcomesByVenueAndId.values()];
1784
+ }, [outcomesByLabel]);
1785
+ const canonicalMarketIdForHistory = model == null ? void 0 : model.market.id;
1786
+ const priceHistoryGroups = useMemo3(() => {
1787
+ return buildPriceHistoryGroups(graphOutcomes, canonicalMarketIdForHistory);
1788
+ }, [canonicalMarketIdForHistory, graphOutcomes]);
1789
+ const { data: priceHistoryData, isLoading: isPriceHistoryLoading } = usePriceHistory2(__spreadProps(__spreadValues({
1790
+ groups: priceHistoryGroups
1791
+ }, timeWindow), {
1792
+ enabled: isOpened && selectedTab === "graph" && priceHistoryGroups.length > 0
1793
+ }));
1794
+ const orderBookInputs = useMemo3(() => {
1795
+ return selectedOutcomesByVenue.map(({ market, outcome }) => ({
1796
+ market,
1797
+ outcome,
1798
+ liveUpdate: true
1799
+ }));
1800
+ }, [selectedOutcomesByVenue]);
1801
+ const {
1802
+ data: orderBookData,
1803
+ isLoading: isOrderBookLoading,
1804
+ error: orderBookError,
1805
+ results: orderBookResults
1806
+ } = useOrderBook({
1807
+ orderbooks: orderBookInputs,
1808
+ enabled: isOpened && selectedTab === "order-book" && orderBookInputs.length > 0
1809
+ });
1810
+ const askRows = useMemo3(() => {
1811
+ return resolveOrderBookRows({
1812
+ data: orderBookData,
1813
+ side: "asks"
1814
+ });
1815
+ }, [orderBookData]);
1816
+ const bidRows = useMemo3(() => {
1817
+ return resolveOrderBookRows({
1818
+ data: orderBookData,
1819
+ side: "bids"
1820
+ });
1821
+ }, [orderBookData]);
1822
+ const priceHistoryByVenue = useMemo3(() => {
1823
+ const historyByVenue = /* @__PURE__ */ new Map();
1824
+ if (!(priceHistoryData == null ? void 0 : priceHistoryData.length)) {
1825
+ return historyByVenue;
1826
+ }
1827
+ priceHistoryData.forEach((historyItem) => {
1828
+ const venue = historyItem.venue;
1829
+ const venueHistory = historyByVenue.get(venue);
1830
+ if (venueHistory) {
1831
+ venueHistory.push(historyItem);
1832
+ return;
1833
+ }
1834
+ historyByVenue.set(venue, [historyItem]);
1835
+ });
1836
+ return historyByVenue;
1837
+ }, [priceHistoryData]);
1838
+ const graphSeriesByOutcomeLabel = useMemo3(() => {
1839
+ const seriesByOutcomeLabel = /* @__PURE__ */ new Map();
1840
+ const resolveOutcomeCandidateIds2 = (outcomeByVenue) => {
1841
+ var _a, _b;
1842
+ const marketWithCanonicalId = outcomeByVenue.market;
1843
+ return [
1844
+ outcomeByVenue.outcome.id,
1845
+ (_a = outcomeByVenue.outcome.externalIdentifier) != null ? _a : void 0,
1846
+ outcomeByVenue.market.externalIdentifier,
1847
+ (_b = marketWithCanonicalId.marketId) != null ? _b : void 0,
1848
+ canonicalMarketIdForHistory
1849
+ ].filter((value) => typeof value === "string" && value.trim().length > 0);
1850
+ };
1851
+ headerOutcomeItems.forEach((headerOutcomeItem) => {
1852
+ var _a;
1853
+ const outcomes = (_a = outcomesByLabel.get(headerOutcomeItem.label)) != null ? _a : [];
1854
+ const graphSeries2 = [];
1855
+ outcomes.forEach((outcomeByVenue, index) => {
1856
+ var _a2;
1857
+ const venueHistory = priceHistoryByVenue.get(outcomeByVenue.venue);
1858
+ if (!(venueHistory == null ? void 0 : venueHistory.length))
1859
+ return;
1860
+ const candidateIds = resolveOutcomeCandidateIds2(outcomeByVenue);
1861
+ const matchingHistory = (_a2 = venueHistory.find((historyItem) => candidateIds.includes(historyItem.marketId))) != null ? _a2 : venueHistory.length === 1 ? venueHistory[0] : void 0;
1862
+ if (!matchingHistory)
1863
+ return;
1864
+ const points = matchingHistory.points.map((point) => ({
1865
+ time: point.timestamp,
1866
+ value: point.price * 100
1867
+ })).filter((point) => Number.isFinite(point.time) && Number.isFinite(point.value));
1868
+ if (points.length === 0)
1869
+ return;
1870
+ graphSeries2.push({
1871
+ id: `${headerOutcomeItem.label}-${outcomeByVenue.venue}-${matchingHistory.marketId}`,
1872
+ venue: outcomeByVenue.venue,
1873
+ color: resolveSeriesColor(outcomeByVenue.venue, index),
1874
+ points
1875
+ });
1876
+ });
1877
+ seriesByOutcomeLabel.set(headerOutcomeItem.label, graphSeries2);
1878
+ });
1879
+ return seriesByOutcomeLabel;
1880
+ }, [canonicalMarketIdForHistory, headerOutcomeItems, outcomesByLabel, priceHistoryByVenue]);
1881
+ const graphSeries = useMemo3(() => {
1882
+ var _a;
1883
+ if (!selectedOutcomeLabel)
1884
+ return [];
1885
+ const seriesForOutcomeLabel = (_a = graphSeriesByOutcomeLabel.get(selectedOutcomeLabel)) != null ? _a : [];
1886
+ if (!selectedGraphVenue)
1887
+ return seriesForOutcomeLabel;
1888
+ return seriesForOutcomeLabel.filter((seriesItem) => seriesItem.venue === selectedGraphVenue);
1889
+ }, [graphSeriesByOutcomeLabel, selectedGraphVenue, selectedOutcomeLabel]);
1890
+ const otherRows = useMemo3(() => {
1891
+ if (!model)
1892
+ return [];
1893
+ return resolveOtherTabRows(model.market, labels);
1894
+ }, [labels, model]);
1895
+ const isOrderBookNotFound = isErrorWithStatus(orderBookError, 404);
1896
+ const hasOrderBookError = !!orderBookError && !isOrderBookNotFound;
1897
+ const hasNoOrderBook = isOrderBookNotFound || !isOrderBookLoading && !hasOrderBookError && (orderBookInputs.length === 0 || askRows.length === 0 && bidRows.length === 0);
1898
+ const handleOutcomeKeyDown = (eventToHandle) => {
1899
+ var _a;
1900
+ if ((eventToHandle == null ? void 0 : eventToHandle.key) !== "ArrowLeft" && (eventToHandle == null ? void 0 : eventToHandle.key) !== "ArrowRight") {
1901
+ return;
1902
+ }
1903
+ if (headerOutcomeItems.length <= 1)
1904
+ return;
1905
+ const activeIndex = headerOutcomeItems.findIndex((item) => {
1906
+ return item.label === selectedOutcomeLabel;
1907
+ });
1908
+ const direction = eventToHandle.key === "ArrowRight" ? 1 : -1;
1909
+ const nextIndex = activeIndex < 0 ? 0 : (activeIndex + direction + headerOutcomeItems.length) % headerOutcomeItems.length;
1910
+ setSelectedOutcomeLabel((_a = headerOutcomeItems[nextIndex]) == null ? void 0 : _a.label);
1911
+ };
1912
+ const handleToggleExpanded = (event2) => {
1913
+ if (event2 && "key" in event2 && (event2 == null ? void 0 : event2.key) !== "Enter" && (event2 == null ? void 0 : event2.key) !== " ") {
1914
+ return;
1915
+ }
1916
+ event2 == null ? void 0 : event2.preventDefault();
1917
+ event2 == null ? void 0 : event2.stopPropagation();
1918
+ setIsOpened((prev) => {
1919
+ const next = !prev;
1920
+ onOpenChange == null ? void 0 : onOpenChange(next);
1921
+ return next;
1922
+ });
1923
+ };
1924
+ const handleGraphVenueToggle = (venue) => {
1925
+ setSelectedGraphVenue((currentVenue) => {
1926
+ if (currentVenue === venue)
1927
+ return null;
1928
+ return venue;
1929
+ });
1930
+ };
1931
+ const handleRetryOrderBook = () => {
1932
+ void Promise.all(orderBookResults.map((result) => result.refetch()));
1933
+ };
1934
+ useEffect2(() => {
1935
+ if (!selectedGraphVenue) {
1936
+ return;
1937
+ }
1938
+ if (selectedOutcomesByVenue.some((item) => item.venue === selectedGraphVenue)) {
1939
+ return;
1940
+ }
1941
+ setSelectedGraphVenue(null);
1942
+ }, [selectedGraphVenue, selectedOutcomesByVenue]);
1943
+ if (marketId && !resolvedMarket) {
1944
+ return /* @__PURE__ */ jsx3(MarketDetailsNotFoundState, { ariaLabel, classNames });
1945
+ }
1946
+ if (!model) {
1947
+ return /* @__PURE__ */ jsx3(MarketDetailsUnavailableState, { ariaLabel, classNames });
1948
+ }
1949
+ return /* @__PURE__ */ jsxs3(
1950
+ Card,
1951
+ {
1952
+ className: cn(
1953
+ "w-full rounded-agg-2xl text-left outline-none",
1954
+ marketDetailsBaseCardClassName,
1955
+ classNames == null ? void 0 : classNames.root
1956
+ ),
1957
+ children: [
1958
+ /* @__PURE__ */ jsxs3(
1959
+ "div",
1960
+ {
1961
+ className: cn(
1962
+ "cursor-pointer disabled:cursor-default",
1963
+ "flex flex-wrap flex-row items-center justify-between gap-3 px-5 py-4",
1964
+ isOpened && "pb-3",
1965
+ classNames == null ? void 0 : classNames.header
1966
+ ),
1967
+ "aria-expanded": isOpened,
1968
+ "aria-controls": detailsContentId,
1969
+ role: "button",
1970
+ tabIndex: 0,
1971
+ "aria-label": isOpened ? labels.marketDetails.toggleCloseDetailsAria(model.title) : labels.marketDetails.toggleOpenDetailsAria(model.title),
1972
+ onClick: handleToggleExpanded,
1973
+ onKeyDown: handleToggleExpanded,
1974
+ children: [
1975
+ /* @__PURE__ */ jsxs3("div", { className: "flex min-w-52 items-center gap-3 md:gap-4", children: [
1976
+ model.image ? /* @__PURE__ */ jsx3(
1977
+ "img",
1978
+ {
1979
+ src: model.image,
1980
+ alt: "",
1981
+ className: "size-12 rounded-agg-lg object-cover md:size-[60px]"
1982
+ }
1983
+ ) : null,
1984
+ /* @__PURE__ */ jsxs3("div", { className: "flex min-w-0 flex-col", children: [
1985
+ /* @__PURE__ */ jsx3(Typography, { as: "h3", variant: "body-large-strong", className: "truncate", children: model.title }),
1986
+ /* @__PURE__ */ jsx3("div", { className: "flex items-center gap-3", children: /* @__PURE__ */ jsx3(Typography, { variant: "label", className: "truncate text-agg-muted-foreground", children: model.subtitle }) })
1987
+ ] })
1988
+ ] }),
1989
+ /* @__PURE__ */ jsx3(Typography, { as: "div", variant: "heading", className: "shrink-0", children: formatProbabilityPercent(headlineProbability) }),
1990
+ /* @__PURE__ */ jsx3(
1991
+ "div",
1992
+ {
1993
+ className: "flex gap-2",
1994
+ role: "tablist",
1995
+ "aria-label": labels.marketDetails.marketOutcomesAria,
1996
+ tabIndex: 0,
1997
+ onKeyDown: (e) => handleOutcomeKeyDown(e),
1998
+ children: headerOutcomeItems.map((item) => {
1999
+ const isPositive = item.tone === "positive";
2000
+ const isActiveOutcome = item.label === selectedOutcomeLabel;
2001
+ return /* @__PURE__ */ jsx3(
2002
+ "button",
2003
+ {
2004
+ type: "button",
2005
+ role: "tab",
2006
+ "aria-selected": isActiveOutcome,
2007
+ tabIndex: isActiveOutcome ? 0 : -1,
2008
+ className: getOutcomeButtonClassName({
2009
+ enableAnimations: config.enableAnimations,
2010
+ isPositive,
2011
+ isActive: isActiveOutcome
2012
+ }),
2013
+ onClick: (e) => {
2014
+ e.preventDefault();
2015
+ e.stopPropagation();
2016
+ setSelectedOutcomeLabel(item.label);
2017
+ },
2018
+ children: /* @__PURE__ */ jsxs3("span", { className: "inline-flex items-center gap-2", children: [
2019
+ /* @__PURE__ */ jsx3(
2020
+ VenueLogo,
2021
+ {
2022
+ venue: isPositive ? "polymarket" : "probable",
2023
+ size: "small",
2024
+ color: isActiveOutcome ? "var(--agg-color-on-primary)" : void 0
2025
+ }
2026
+ ),
2027
+ /* @__PURE__ */ jsx3(
2028
+ Typography,
2029
+ {
2030
+ variant: isActiveOutcome ? "body-strong" : "body",
2031
+ className: cn(
2032
+ "text-agg-base leading-agg-6",
2033
+ isActiveOutcome ? "text-agg-on-primary" : "text-agg-foreground"
2034
+ ),
2035
+ children: `${item.label} ${formatProbabilityCents(item.probability)}`
2036
+ }
2037
+ )
2038
+ ] })
2039
+ },
2040
+ item.label
2041
+ );
2042
+ })
2043
+ }
2044
+ )
2045
+ ]
2046
+ }
2047
+ ),
2048
+ /* @__PURE__ */ jsx3(
2049
+ "div",
2050
+ {
2051
+ id: detailsContentId,
2052
+ className: cn(
2053
+ "grid overflow-hidden",
2054
+ getMotionClassName(config.enableAnimations, "transition-all duration-500 ease-in-out"),
2055
+ isOpened ? "grid-rows-[1fr] opacity-100" : "pointer-events-none grid-rows-[0fr] opacity-0"
2056
+ ),
2057
+ "aria-hidden": !isOpened,
2058
+ children: /* @__PURE__ */ jsxs3("div", { className: "min-h-0", children: [
2059
+ /* @__PURE__ */ jsx3("div", { className: "h-px w-full bg-agg-separator" }),
2060
+ /* @__PURE__ */ jsxs3(
2061
+ "div",
2062
+ {
2063
+ className: cn(
2064
+ getMotionClassName(
2065
+ config.enableAnimations,
2066
+ "transition-all duration-500 ease-in-out"
2067
+ ),
2068
+ isOpened ? cn(
2069
+ "translate-y-0 opacity-100",
2070
+ getMotionClassName(config.enableAnimations, "delay-100")
2071
+ ) : "translate-y-5 opacity-0"
2072
+ ),
2073
+ children: [
2074
+ /* @__PURE__ */ jsx3("div", { className: cn("block", classNames == null ? void 0 : classNames.tabs), children: /* @__PURE__ */ jsx3(
2075
+ Tabs,
2076
+ {
2077
+ ariaLabel: labels.marketDetails.tabsAria,
2078
+ items: marketDetailsTabs,
2079
+ value: selectedTab === "other" ? "order-book" : selectedTab,
2080
+ onChange: (nextValue) => setSelectedTab(nextValue),
2081
+ variant: "underline",
2082
+ className: "w-full px-5"
2083
+ }
2084
+ ) }),
2085
+ /* @__PURE__ */ jsx3("div", { className: "h-px w-full bg-agg-separator" }),
2086
+ /* @__PURE__ */ jsxs3("div", { className: cn("p-5", classNames == null ? void 0 : classNames.content), children: [
2087
+ selectedTab === "order-book" ? /* @__PURE__ */ jsx3("div", { className: cn("flex flex-col gap-5", classNames == null ? void 0 : classNames.orderBook), children: isOrderBookLoading ? /* @__PURE__ */ jsx3(MarketDetailsOderbookSkeleton, {}) : hasOrderBookError ? /* @__PURE__ */ jsx3(
2088
+ StateMessage,
2089
+ {
2090
+ ariaLabel: labels.marketDetails.orderBookUnavailableAria,
2091
+ tone: "warning",
2092
+ title: labels.marketDetails.orderBookUnavailableTitle,
2093
+ description: labels.marketDetails.orderBookUnavailableDescription,
2094
+ actionLabel: labels.common.retry,
2095
+ onAction: handleRetryOrderBook,
2096
+ className: "min-h-[248px] px-5 py-10 md:min-h-[272px]"
2097
+ }
2098
+ ) : hasNoOrderBook ? /* @__PURE__ */ jsx3(
2099
+ StateMessage,
2100
+ {
2101
+ ariaLabel: labels.marketDetails.orderBookEmptyAria,
2102
+ title: labels.marketDetails.orderBookEmptyTitle,
2103
+ description: labels.marketDetails.orderBookEmptyDescription,
2104
+ className: "min-h-[248px] px-5 py-10 md:min-h-[272px]"
2105
+ }
2106
+ ) : /* @__PURE__ */ jsxs3(Fragment, { children: [
2107
+ /* @__PURE__ */ jsx3(
2108
+ OrderBookRows,
2109
+ {
2110
+ rows: askRows,
2111
+ title: labels.marketDetails.asks,
2112
+ formatNumber: config.formatNumber,
2113
+ formatCurrency: config.formatCurrency,
2114
+ visibleRows: orderBookDepth
2115
+ }
2116
+ ),
2117
+ /* @__PURE__ */ jsx3(
2118
+ OrderBookRows,
2119
+ {
2120
+ rows: bidRows,
2121
+ title: labels.marketDetails.bids,
2122
+ formatNumber: config.formatNumber,
2123
+ formatCurrency: config.formatCurrency,
2124
+ visibleRows: orderBookDepth
2125
+ }
2126
+ )
2127
+ ] }) }) : null,
2128
+ selectedTab === "graph" ? /* @__PURE__ */ jsxs3("div", { className: cn("flex flex-col gap-5", classNames == null ? void 0 : classNames.graph), children: [
2129
+ /* @__PURE__ */ jsx3(
2130
+ LineChart,
2131
+ {
2132
+ series: graphSeries,
2133
+ height: 260,
2134
+ isLoading: isPriceHistoryLoading,
2135
+ classNames: { root: "w-full" },
2136
+ showSeriesControls: selectedOutcomesByVenue.length > 0 || headerOutcomeItems.length > 0,
2137
+ renderSeriesControls: () => {
2138
+ return /* @__PURE__ */ jsxs3("div", { className: "flex flex-col gap-4 md:flex-row md:items-center md:justify-between", children: [
2139
+ /* @__PURE__ */ jsx3("div", { className: "flex flex-wrap gap-2", children: selectedOutcomesByVenue.map((item) => {
2140
+ const probability = formatProbabilityPercent(item.outcome.price);
2141
+ const isActiveVenue = selectedGraphVenue === item.venue;
2142
+ return /* @__PURE__ */ jsxs3(
2143
+ "button",
2144
+ {
2145
+ type: "button",
2146
+ "aria-label": `${item.venue} ${probability}`,
2147
+ "aria-pressed": isActiveVenue,
2148
+ className: cn(
2149
+ "inline-flex items-center gap-2 rounded-agg-full border-2 px-4 py-2",
2150
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-agg-primary focus-visible:ring-offset-2 focus-visible:ring-offset-agg-secondary-hover",
2151
+ isActiveVenue ? "border-agg-primary bg-agg-secondary" : "border-transparent bg-agg-secondary-hover"
2152
+ ),
2153
+ onClick: (e) => {
2154
+ e.preventDefault();
2155
+ e.stopPropagation();
2156
+ handleGraphVenueToggle(item.venue);
2157
+ },
2158
+ children: [
2159
+ /* @__PURE__ */ jsx3(VenueLogo, { venue: item.venue, size: "small" }),
2160
+ /* @__PURE__ */ jsx3("span", { className: "text-agg-base leading-agg-6 text-agg-foreground", children: probability })
2161
+ ]
2162
+ },
2163
+ `${item.market.id}-${item.outcome.id}`
2164
+ );
2165
+ }) }),
2166
+ /* @__PURE__ */ jsx3(
2167
+ SwitchButton,
2168
+ {
2169
+ ariaLabel: labels.marketDetails.outcomeSelectorAria,
2170
+ className: "shrink-0",
2171
+ value: selectedOutcomeLabel != null ? selectedOutcomeLabel : "",
2172
+ onValueChange: (nextValue) => setSelectedOutcomeLabel(nextValue),
2173
+ options: headerOutcomeItems.map((item) => ({
2174
+ value: item.label,
2175
+ label: `${item.label} ${formatProbabilityCents(item.probability)}`,
2176
+ ariaLabel: labels.marketDetails.showOutcomeAria(item.label)
2177
+ }))
2178
+ }
2179
+ )
2180
+ ] });
2181
+ }
2182
+ }
2183
+ ),
2184
+ /* @__PURE__ */ jsxs3(
2185
+ "div",
2186
+ {
2187
+ className: cn(
2188
+ "flex flex-col gap-3 text-agg-sm leading-agg-5 text-agg-muted-foreground md:flex-row md:items-center md:justify-between",
2189
+ classNames == null ? void 0 : classNames.footer
2190
+ ),
2191
+ children: [
2192
+ /* @__PURE__ */ jsx3("span", { children: typeof model.market.volume === "number" ? `${config.formatCompactCurrency(model.market.volume)} ${labels.marketDetails.meta.volumeSuffix}` : labels.marketDetails.volumeUnavailable }),
2193
+ /* @__PURE__ */ jsx3("div", { className: "flex flex-wrap items-center gap-3 md:gap-4", children: eventListItemDetailsTimeRanges.map((timeRange) => {
2194
+ const isActive = selectedTimeRange === timeRange;
2195
+ return /* @__PURE__ */ jsx3(
2196
+ "button",
2197
+ {
2198
+ type: "button",
2199
+ className: cn(
2200
+ "cursor-pointer text-agg-sm leading-agg-5",
2201
+ isActive ? "font-agg-bold text-agg-foreground" : "font-agg-normal text-agg-muted-foreground"
2202
+ ),
2203
+ "aria-pressed": isActive,
2204
+ onClick: (e) => {
2205
+ e.preventDefault();
2206
+ e.stopPropagation();
2207
+ setSelectedTimeRange(timeRange);
2208
+ },
2209
+ children: timeRange === "ALL" ? labels.eventItemDetails.allTimeRange : timeRange
2210
+ },
2211
+ timeRange
2212
+ );
2213
+ }) })
2214
+ ]
2215
+ }
2216
+ )
2217
+ ] }) : null,
2218
+ selectedTab === "other" ? /* @__PURE__ */ jsx3("div", { className: "flex flex-col gap-4", children: otherContent != null ? otherContent : /* @__PURE__ */ jsx3("div", { className: "grid grid-cols-1 gap-3", children: otherRows.map((row) => /* @__PURE__ */ jsxs3(
2219
+ "div",
2220
+ {
2221
+ className: "flex items-center justify-between rounded-agg-xl bg-agg-secondary-hover px-4 py-3",
2222
+ children: [
2223
+ /* @__PURE__ */ jsx3(Typography, { variant: "label", className: "text-agg-muted-foreground", children: row.label }),
2224
+ /* @__PURE__ */ jsx3(Typography, { variant: "body", className: "text-right", children: row.value })
2225
+ ]
2226
+ },
2227
+ row.label
2228
+ )) }) }) : null
2229
+ ] })
2230
+ ]
2231
+ }
2232
+ )
2233
+ ] })
2234
+ }
2235
+ )
2236
+ ]
2237
+ }
2238
+ );
2239
+ };
2240
+ var MarketDetails = (props) => {
2241
+ var _a;
2242
+ const [uncontrolledIsOpened, setUncontrolledIsOpened] = useState2(
2243
+ (_a = props.defaultIsOpened) != null ? _a : marketDetailsDefaultIsOpened
2244
+ );
2245
+ useEffect2(() => {
2246
+ if (typeof props.isOpened !== "boolean")
2247
+ return;
2248
+ setUncontrolledIsOpened(props.isOpened);
2249
+ }, [props.isOpened]);
2250
+ const resolvedIsOpened = typeof props.isOpened === "boolean" ? props.isOpened : uncontrolledIsOpened;
2251
+ const handleOpenChange = (nextIsOpened) => {
2252
+ var _a2;
2253
+ if (typeof props.isOpened !== "boolean") {
2254
+ setUncontrolledIsOpened(nextIsOpened);
2255
+ }
2256
+ (_a2 = props.onOpenChange) == null ? void 0 : _a2.call(props, nextIsOpened);
2257
+ };
2258
+ const hasEventProp = "event" in props && !!props.event;
2259
+ const {
2260
+ event: fetchedEvent,
2261
+ error: eventError,
2262
+ isLoading: isFetchingEvent
2263
+ } = useEvent3(hasEventProp ? void 0 : props.eventId, {
2264
+ enabled: !props.isLoading && !hasEventProp && !!props.eventId
2265
+ });
2266
+ if (props.isLoading) {
2267
+ return /* @__PURE__ */ jsx3(
2268
+ MarketDetailsLoadingState,
2269
+ {
2270
+ isOpened: resolvedIsOpened,
2271
+ ariaLabel: props.ariaLabel,
2272
+ classNames: props.classNames
2273
+ }
2274
+ );
2275
+ }
2276
+ if ("event" in props && props.event) {
2277
+ return /* @__PURE__ */ jsx3(
2278
+ MarketDetailsContent,
2279
+ __spreadProps(__spreadValues({}, props), {
2280
+ isOpened: resolvedIsOpened,
2281
+ onOpenChange: handleOpenChange,
2282
+ event: props.event
2283
+ })
2284
+ );
2285
+ }
2286
+ if (isFetchingEvent) {
2287
+ return /* @__PURE__ */ jsx3(
2288
+ MarketDetailsLoadingState,
2289
+ {
2290
+ isOpened: resolvedIsOpened,
2291
+ ariaLabel: props.ariaLabel,
2292
+ classNames: props.classNames
2293
+ }
2294
+ );
2295
+ }
2296
+ if (!fetchedEvent) {
2297
+ if (isErrorWithStatus(eventError, 404)) {
2298
+ return /* @__PURE__ */ jsx3(MarketDetailsNotFoundState, { ariaLabel: props.ariaLabel, classNames: props.classNames });
2299
+ }
2300
+ return /* @__PURE__ */ jsx3(MarketDetailsUnavailableState, { ariaLabel: props.ariaLabel, classNames: props.classNames });
2301
+ }
2302
+ return /* @__PURE__ */ jsx3(
2303
+ MarketDetailsContent,
2304
+ __spreadProps(__spreadValues({}, props), {
2305
+ isOpened: resolvedIsOpened,
2306
+ onOpenChange: handleOpenChange,
2307
+ event: fetchedEvent
2308
+ })
2309
+ );
2310
+ };
2311
+ MarketDetails.displayName = "MarketDetails";
2312
+
2313
+ // src/events/list/index.tsx
2314
+ import { useCallback, useEffect as useEffect3, useMemo as useMemo4, useRef, useState as useState3 } from "react";
2315
+ import { useEvents, useLabels as useLabels4 } from "@agg-market/hooks";
2316
+
2317
+ // src/events/list/event-list.constants.ts
2318
+ var POLYMARKET_VENUE = "polymarket";
2319
+ var KALSHI_VENUE = "kalshi";
2320
+ var POLYMARKET_VENUE_LOGO = "polymarket";
2321
+ var KALSHI_VENUE_LOGO = "kalshi";
2322
+ var getDefaultEventListTabs = (labels) => {
2323
+ return [
2324
+ {
2325
+ value: "matched",
2326
+ label: labels.eventList.matchedTab,
2327
+ iconName: "arrows-to-dot"
2328
+ },
2329
+ {
2330
+ value: "polymarket",
2331
+ label: labels.venues.polymarket,
2332
+ venueLogo: POLYMARKET_VENUE_LOGO,
2333
+ venues: [POLYMARKET_VENUE]
2334
+ },
2335
+ {
2336
+ value: "kalshi",
2337
+ label: labels.venues.kalshi,
2338
+ venueLogo: KALSHI_VENUE_LOGO,
2339
+ venues: [KALSHI_VENUE]
2340
+ }
2341
+ ];
2342
+ };
2343
+
2344
+ // src/events/list/event-list.utils.ts
2345
+ var mapEventToEventListItemEvent = (event) => {
2346
+ const mergedVenueMarkets = event.markets.flatMap((m) => m.venueMarkets);
2347
+ if (mergedVenueMarkets.length === 0)
2348
+ return null;
2349
+ return event;
2350
+ };
2351
+ var filterEventsByTabValue = (events, _tabValue) => {
2352
+ return events;
2353
+ };
2354
+ var resolveTabVenus = (tab) => {
2355
+ if (!tab)
2356
+ return void 0;
2357
+ if (tab.venues && tab.venues.length > 0)
2358
+ return tab.venues;
2359
+ if (tab.value === "polymarket" || tab.value === "kalshi") {
2360
+ return [tab.value];
2361
+ }
2362
+ return void 0;
2363
+ };
2364
+
2365
+ // src/events/list/index.tsx
2366
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
2367
+ var renderTabIcon = (tab, isActive) => {
2368
+ if (tab.venueLogo) {
2369
+ return /* @__PURE__ */ jsx4(VenueLogo, { venue: tab.venueLogo, size: "small" });
2370
+ }
2371
+ if (!tab.iconName)
2372
+ return null;
2373
+ return /* @__PURE__ */ jsx4(
2374
+ Icon,
2375
+ {
2376
+ name: tab.iconName,
2377
+ size: "small",
2378
+ color: isActive ? "var(--agg-color-primary)" : "var(--agg-color-foreground)"
2379
+ }
2380
+ );
2381
+ };
2382
+ var TAB_MIN_WIDTH = 80;
2383
+ var TAB_HORIZONTAL_PADDING = 32;
2384
+ var TAB_ICON_AND_GAP_WIDTH = 24;
2385
+ var TAB_OUTER_BORDER_WIDTH = 2;
2386
+ var TAB_INNER_BORDER_WIDTH = 1;
2387
+ var measureTabLabelWidth = (label) => {
2388
+ if (typeof document === "undefined")
2389
+ return label.length * 9;
2390
+ const canvas = document.createElement("canvas");
2391
+ const context = canvas.getContext("2d");
2392
+ if (!context)
2393
+ return label.length * 9;
2394
+ context.font = "700 16px Inter";
2395
+ return context.measureText(label).width;
2396
+ };
2397
+ var estimateTabsWidth = (items) => {
2398
+ if (items.length === 0)
2399
+ return 0;
2400
+ const tabsWidth = items.reduce((sum, item) => {
2401
+ const textWidth = Math.ceil(measureTabLabelWidth(item.label));
2402
+ const iconWidth = item.icon ? TAB_ICON_AND_GAP_WIDTH : 0;
2403
+ const buttonWidth = Math.max(TAB_MIN_WIDTH, textWidth + iconWidth + TAB_HORIZONTAL_PADDING);
2404
+ return sum + buttonWidth;
2405
+ }, 0);
2406
+ return tabsWidth + TAB_OUTER_BORDER_WIDTH + (items.length - 1) * TAB_INNER_BORDER_WIDTH;
2407
+ };
2408
+ var EventList = ({
2409
+ title,
2410
+ maxItemsPerRow = 3,
2411
+ limit = 3,
2412
+ maxVisibleItems,
2413
+ showVenueLogo = true,
2414
+ search,
2415
+ categoryIds
2416
+ }) => {
2417
+ var _a, _b;
2418
+ const labels = useLabels4();
2419
+ const defaultEventListTabs = useMemo4(() => {
2420
+ return getDefaultEventListTabs(labels);
2421
+ }, [labels]);
2422
+ const [activeTabValue, setActiveTabValue] = useState3(
2423
+ (_b = (_a = defaultEventListTabs[0]) == null ? void 0 : _a.value) != null ? _b : "matched"
2424
+ );
2425
+ const [_shouldUseSelectOverflow, setShouldUseSelectOverflow] = useState3(false);
2426
+ const activeTab = useMemo4(() => {
2427
+ return defaultEventListTabs.find((tab) => tab.value === activeTabValue);
2428
+ }, [activeTabValue]);
2429
+ const venues = useMemo4(() => {
2430
+ return resolveTabVenus(activeTab);
2431
+ }, [activeTab]);
2432
+ const resolvedMaxVisibleItems = useMemo4(() => {
2433
+ if (!Number.isFinite(maxVisibleItems))
2434
+ return void 0;
2435
+ return Math.max(1, Math.floor(maxVisibleItems));
2436
+ }, [maxVisibleItems]);
2437
+ const requestLimit = resolvedMaxVisibleItems != null ? resolvedMaxVisibleItems : limit;
2438
+ const shouldPaginate = resolvedMaxVisibleItems == null;
2439
+ const { events, isLoading, isError, fetchNextPage, hasNextPage, isFetchingNextPage } = useEvents({
2440
+ venues,
2441
+ search,
2442
+ categoryIds,
2443
+ limit: requestLimit
2444
+ });
2445
+ const filteredEvents = useMemo4(() => {
2446
+ return filterEventsByTabValue(events, activeTabValue);
2447
+ }, [events, activeTabValue]);
2448
+ const tileEvents = useMemo4(() => {
2449
+ const normalizedEvents = filteredEvents.map((event) => mapEventToEventListItemEvent(event)).filter((event) => event != null);
2450
+ if (resolvedMaxVisibleItems == null)
2451
+ return normalizedEvents;
2452
+ return normalizedEvents.slice(0, resolvedMaxVisibleItems);
2453
+ }, [filteredEvents, resolvedMaxVisibleItems]);
2454
+ const tabsItems = useMemo4(() => {
2455
+ return defaultEventListTabs.map((tab) => {
2456
+ const isActive = tab.value === activeTabValue;
2457
+ return {
2458
+ value: tab.value,
2459
+ label: tab.label,
2460
+ icon: renderTabIcon(tab, isActive),
2461
+ disabled: tab.disabled
2462
+ };
2463
+ });
2464
+ }, [activeTabValue]);
2465
+ const headerRef = useRef(null);
2466
+ const titleRef = useRef(null);
2467
+ const updateTabsOverflowBehavior = useCallback(() => {
2468
+ if (typeof window === "undefined")
2469
+ return;
2470
+ const headerElement = headerRef.current;
2471
+ const titleElement = titleRef.current;
2472
+ if (!headerElement || !titleElement)
2473
+ return;
2474
+ const isDesktop = window.matchMedia("(min-width: 768px)").matches;
2475
+ if (!isDesktop) {
2476
+ setShouldUseSelectOverflow(false);
2477
+ return;
2478
+ }
2479
+ const headerStyles = window.getComputedStyle(headerElement);
2480
+ const rawGap = headerStyles.columnGap || headerStyles.gap || "0";
2481
+ const horizontalGap = Number.parseFloat(rawGap) || 0;
2482
+ const availableTabsWidth = headerElement.clientWidth - titleElement.getBoundingClientRect().width - horizontalGap;
2483
+ const estimatedTabsWidth = estimateTabsWidth(tabsItems);
2484
+ setShouldUseSelectOverflow(availableTabsWidth > 0 && estimatedTabsWidth > availableTabsWidth);
2485
+ }, [tabsItems]);
2486
+ useEffect3(() => {
2487
+ updateTabsOverflowBehavior();
2488
+ }, [updateTabsOverflowBehavior]);
2489
+ useEffect3(() => {
2490
+ if (typeof ResizeObserver === "undefined")
2491
+ return;
2492
+ const headerElement = headerRef.current;
2493
+ const titleElement = titleRef.current;
2494
+ if (!headerElement || !titleElement)
2495
+ return;
2496
+ const resizeObserver = new ResizeObserver(() => {
2497
+ updateTabsOverflowBehavior();
2498
+ });
2499
+ resizeObserver.observe(headerElement);
2500
+ resizeObserver.observe(titleElement);
2501
+ return () => {
2502
+ resizeObserver.disconnect();
2503
+ };
2504
+ }, [updateTabsOverflowBehavior]);
2505
+ const resolvedMaxItemsPerRow = Number.isFinite(maxItemsPerRow) ? Math.max(1, Math.floor(maxItemsPerRow)) : 1;
2506
+ const loadingPlaceholderCount = isFetchingNextPage ? Math.min(resolvedMaxItemsPerRow, resolvedMaxVisibleItems != null ? resolvedMaxVisibleItems : Infinity) : 0;
2507
+ const shouldRenderLoadingState = isLoading && tileEvents.length === 0;
2508
+ const loadMoreRef = useRef(null);
2509
+ useEffect3(() => {
2510
+ if (!shouldPaginate)
2511
+ return;
2512
+ if (!hasNextPage)
2513
+ return;
2514
+ const target = loadMoreRef.current;
2515
+ if (!target)
2516
+ return;
2517
+ const observer = new IntersectionObserver(
2518
+ (entries) => {
2519
+ const entry = entries[0];
2520
+ if (!(entry == null ? void 0 : entry.isIntersecting))
2521
+ return;
2522
+ if (isLoading || isFetchingNextPage || !hasNextPage)
2523
+ return;
2524
+ void fetchNextPage();
2525
+ },
2526
+ {
2527
+ rootMargin: "320px 0px"
2528
+ }
2529
+ );
2530
+ observer.observe(target);
2531
+ return () => {
2532
+ observer.disconnect();
2533
+ };
2534
+ }, [fetchNextPage, hasNextPage, isFetchingNextPage, isLoading, shouldPaginate]);
2535
+ const gridStyle = {
2536
+ ["--agg-event-list-columns"]: String(resolvedMaxItemsPerRow)
2537
+ };
2538
+ const gridClassName = cn(
2539
+ "grid grid-cols-1 gap-5",
2540
+ "md:[grid-template-columns:repeat(var(--agg-event-list-columns),minmax(0,1fr))]"
2541
+ );
2542
+ if (shouldRenderLoadingState) {
2543
+ return /* @__PURE__ */ jsx4(Skeleton, { view: "event-list", ariaLabel: labels.eventList.loading(title) });
2544
+ }
2545
+ return /* @__PURE__ */ jsxs4("section", { className: "flex w-full flex-col gap-5", children: [
2546
+ /* @__PURE__ */ jsxs4(
2547
+ "header",
2548
+ {
2549
+ ref: headerRef,
2550
+ className: "flex flex-col sm:flex-row w-full flex-nowrap items-start sm:items-center justify-between gap-2 sm:gap-4",
2551
+ children: [
2552
+ /* @__PURE__ */ jsx4("div", { ref: titleRef, className: "min-w-0", children: /* @__PURE__ */ jsx4(Typography, { as: "h2", variant: "title", className: "truncate [&::first-letter]:uppercase", children: title }) }),
2553
+ /* @__PURE__ */ jsx4(
2554
+ Tabs,
2555
+ {
2556
+ ariaLabel: labels.eventList.tabsAria(title),
2557
+ items: tabsItems,
2558
+ value: activeTabValue,
2559
+ onChange: setActiveTabValue
2560
+ }
2561
+ )
2562
+ ]
2563
+ }
2564
+ ),
2565
+ /* @__PURE__ */ jsxs4("div", { className: gridClassName, style: gridStyle, children: [
2566
+ tileEvents.map((event) => /* @__PURE__ */ jsx4(
2567
+ EventListItem,
2568
+ {
2569
+ event,
2570
+ showVenueLogo,
2571
+ classNames: {
2572
+ root: "w-full min-w-0 max-w-none"
2573
+ }
2574
+ },
2575
+ event.id
2576
+ )),
2577
+ Array.from({ length: loadingPlaceholderCount }).map((_, index) => /* @__PURE__ */ jsx4(
2578
+ EventListItem,
2579
+ {
2580
+ isLoading: true,
2581
+ classNames: {
2582
+ root: "w-full min-w-0 max-w-none"
2583
+ }
2584
+ },
2585
+ `loading-${index}`
2586
+ )),
2587
+ !isLoading && !isError && (tileEvents == null ? void 0 : tileEvents.length) === 0 ? /* @__PURE__ */ jsx4(Card, { className: "col-span-full overflow-hidden shadow-none hover:shadow-none", children: /* @__PURE__ */ jsx4(
2588
+ StateMessage,
2589
+ {
2590
+ ariaLabel: labels.eventList.emptyAria,
2591
+ title: labels.eventList.emptyTitle,
2592
+ description: labels.eventList.emptyDescription,
2593
+ className: "min-h-[320px]"
2594
+ }
2595
+ ) }) : null,
2596
+ isError ? /* @__PURE__ */ jsx4(
2597
+ Typography,
2598
+ {
2599
+ variant: "body",
2600
+ className: "w-full col-span-full flex flex-col items-center justify-center h-32",
2601
+ children: labels.eventList.error
2602
+ }
2603
+ ) : null
2604
+ ] }),
2605
+ shouldPaginate && hasNextPage ? /* @__PURE__ */ jsx4("div", { ref: loadMoreRef, className: "h-px w-full", "aria-hidden": true }) : null
2606
+ ] });
2607
+ };
2608
+ EventList.displayName = "EventList";
2609
+
2610
+ export {
2611
+ isErrorWithStatus,
2612
+ EventListItem,
2613
+ EventListItemDetails,
2614
+ MarketDetails,
2615
+ EventList
2616
+ };