@agg-market/ui 9.0.0 → 10.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 (52) hide show
  1. package/dist/{chunk-N7U7QCSB.mjs → chunk-55YYUTBK.mjs} +807 -358
  2. package/dist/{chunk-3U4VHAP6.mjs → chunk-5G4T5R2H.mjs} +6 -2
  3. package/dist/{chunk-6CRY27SQ.mjs → chunk-GYOCLZGH.mjs} +538 -418
  4. package/dist/{chunk-HJ4UPYM7.mjs → chunk-RYQSVETG.mjs} +201 -165
  5. package/dist/{chunk-3G7C6WEC.mjs → chunk-XP7DREIX.mjs} +47 -15
  6. package/dist/events.js +575 -429
  7. package/dist/events.mjs +6 -4
  8. package/dist/index.js +1577 -948
  9. package/dist/index.mjs +10 -6
  10. package/dist/modals.js +1185 -374
  11. package/dist/modals.mjs +4 -2
  12. package/dist/pages.js +1400 -1010
  13. package/dist/pages.mjs +4 -4
  14. package/dist/primitives.js +46 -14
  15. package/dist/primitives.mjs +1 -1
  16. package/dist/styles.css +1 -1
  17. package/dist/tailwind.css +1 -1
  18. package/dist/trading.js +20 -4
  19. package/dist/trading.mjs +2 -2
  20. package/dist/types/events/item/event-list-item.types.d.mts +1 -2
  21. package/dist/types/events/item/event-list-item.types.d.ts +1 -2
  22. package/dist/types/events/item-details/event-list-item-details.types.d.mts +1 -4
  23. package/dist/types/events/item-details/event-list-item-details.types.d.ts +1 -4
  24. package/dist/types/events/item-details/event-list-item-details.utils.d.mts +42 -3
  25. package/dist/types/events/item-details/event-list-item-details.utils.d.ts +42 -3
  26. package/dist/types/events/list/event-list.types.d.mts +2 -1
  27. package/dist/types/events/list/event-list.types.d.ts +2 -1
  28. package/dist/types/events/list/index.d.mts +1 -1
  29. package/dist/types/events/list/index.d.ts +1 -1
  30. package/dist/types/events/market-details/index.d.mts +6 -2
  31. package/dist/types/events/market-details/index.d.ts +6 -2
  32. package/dist/types/events/market-details/market-details.types.d.mts +33 -9
  33. package/dist/types/events/market-details/market-details.types.d.ts +33 -9
  34. package/dist/types/events/market-details/market-details.utils.d.mts +15 -10
  35. package/dist/types/events/market-details/market-details.utils.d.ts +15 -10
  36. package/dist/types/modals/index.d.mts +1 -0
  37. package/dist/types/modals/index.d.ts +1 -0
  38. package/dist/types/pages/event-market/event-market.types.d.mts +2 -0
  39. package/dist/types/pages/event-market/event-market.types.d.ts +2 -0
  40. package/dist/types/pages/home/home.constants.d.mts +1 -3
  41. package/dist/types/pages/home/home.constants.d.ts +1 -3
  42. package/dist/types/pages/home/home.types.d.mts +0 -2
  43. package/dist/types/pages/home/home.types.d.ts +0 -2
  44. package/dist/types/pages/home/home.utils.d.mts +4 -0
  45. package/dist/types/pages/home/home.utils.d.ts +4 -0
  46. package/dist/types/pages/home/index.d.mts +1 -1
  47. package/dist/types/pages/home/index.d.ts +1 -1
  48. package/dist/types/primitives/chart/index.d.mts +9 -1
  49. package/dist/types/primitives/chart/index.d.ts +9 -1
  50. package/dist/types/primitives/venue-logo/index.d.mts +1 -1
  51. package/dist/types/primitives/venue-logo/index.d.ts +1 -1
  52. package/package.json +3 -3
package/dist/events.js CHANGED
@@ -62,7 +62,8 @@ __export(events_exports, {
62
62
  EventList: () => EventList,
63
63
  EventListItem: () => EventListItem,
64
64
  EventListItemDetails: () => EventListItemDetails,
65
- MarketDetails: () => MarketDetails
65
+ MarketDetails: () => MarketDetails,
66
+ MarketDetailsList: () => MarketDetailsList
66
67
  });
67
68
  module.exports = __toCommonJS(events_exports);
68
69
 
@@ -138,9 +139,9 @@ function Badge({
138
139
  )
139
140
  }, onClick && { onClick }), {
140
141
  children: [
141
- prefix ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: classNames == null ? void 0 : classNames.prefix, children: prefix }) : null,
142
+ prefix ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: cn(classNames == null ? void 0 : classNames.prefix, "empty:hidden"), children: prefix }) : null,
142
143
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: cn("truncate", classNames == null ? void 0 : classNames.text), children: text }),
143
- suffix ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: classNames == null ? void 0 : classNames.suffix, children: suffix }) : null
144
+ suffix ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: cn(classNames == null ? void 0 : classNames.suffix, "empty:hidden"), children: suffix }) : null
144
145
  ]
145
146
  })
146
147
  );
@@ -2498,7 +2499,11 @@ var StateMessage = ({
2498
2499
  size: "large",
2499
2500
  className: "text-agg-base leading-agg-6",
2500
2501
  "aria-label": actionLabel,
2501
- onClick: onAction,
2502
+ onClick: (e) => {
2503
+ e.stopPropagation();
2504
+ e.preventDefault();
2505
+ onAction == null ? void 0 : onAction();
2506
+ },
2502
2507
  children: actionLabel
2503
2508
  }
2504
2509
  ) : null
@@ -2911,9 +2916,12 @@ var VenueLogo = ({
2911
2916
  title
2912
2917
  }) => {
2913
2918
  var _a;
2919
+ const { showVenueLogo = true } = (0, import_hooks10.useAggUiConfig)();
2914
2920
  const labels = (0, import_hooks10.useLabels)();
2915
2921
  const sizeClass = sizeClasses2[size];
2916
2922
  const resolvedLabel = (_a = ariaLabel != null ? ariaLabel : labels.venues[venue]) != null ? _a : venueLogoLabels[venue];
2923
+ if (!showVenueLogo)
2924
+ return null;
2917
2925
  if (variant === "logo") {
2918
2926
  return /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(
2919
2927
  RemoteImage,
@@ -3027,7 +3035,7 @@ var SwitchButton = ({
3027
3035
  "div",
3028
3036
  {
3029
3037
  className: cn(
3030
- "group/agg-switch",
3038
+ "group/agg-switch min-w-fit",
3031
3039
  "inline-flex min-w-0 rounded-agg-full bg-agg-secondary-hover font-agg-sans",
3032
3040
  getMotionClassName(enableAnimations, "transition-background duration-200 ease-in-out"),
3033
3041
  "cursor-pointer hover:bg-agg-tertiary",
@@ -3073,6 +3081,7 @@ var SwitchButton = ({
3073
3081
  tabIndex: isActive ? 0 : -1,
3074
3082
  disabled: option.disabled,
3075
3083
  className: cn(
3084
+ "whitespace-nowrap",
3076
3085
  "relative z-10 min-w-0 rounded-agg-full px-5 py-1.5 font-agg-sans text-agg-base leading-agg-6 text-agg-foreground",
3077
3086
  getMotionClassName(
3078
3087
  enableAnimations,
@@ -3269,11 +3278,12 @@ var LineChart = ({
3269
3278
  liveCandle: liveForming,
3270
3279
  lineData,
3271
3280
  lineValue,
3272
- live = false
3281
+ live
3273
3282
  }) => {
3274
3283
  var _a, _b;
3275
3284
  const labels = (0, import_hooks12.useLabels)();
3276
- const { theme } = (0, import_hooks12.useSdkUiConfig)();
3285
+ const { theme, enableGradients, enableLiveUpdates } = (0, import_hooks12.useSdkUiConfig)();
3286
+ const isLive = enableLiveUpdates && (live != null ? live : true);
3277
3287
  const normalizedSeries = (0, import_react3.useMemo)(() => {
3278
3288
  return normalizeSeries(series);
3279
3289
  }, [series]);
@@ -3296,7 +3306,19 @@ var LineChart = ({
3296
3306
  if (!primarySeries) {
3297
3307
  return [];
3298
3308
  }
3299
- return toLivelinePoints(primarySeries.points);
3309
+ const points = toLivelinePoints(primarySeries.points);
3310
+ if (points.length < 3) {
3311
+ return [
3312
+ ...points,
3313
+ ...points.map((point) => __spreadProps(__spreadValues({}, point), {
3314
+ time: point.time + 1500
3315
+ })),
3316
+ ...points.map((point) => __spreadProps(__spreadValues({}, point), {
3317
+ time: point.time + 3e3
3318
+ }))
3319
+ ];
3320
+ }
3321
+ return points;
3300
3322
  }, [primarySeries]);
3301
3323
  const primaryCandles = (0, import_react3.useMemo)(() => {
3302
3324
  if (!primarySeries) {
@@ -3330,7 +3352,7 @@ var LineChart = ({
3330
3352
  const timeFormatter = (0, import_react3.useMemo)(() => {
3331
3353
  return resolveTimeFormatter(windowSeconds);
3332
3354
  }, [windowSeconds]);
3333
- const seriesControls = showSeriesControls && normalizedSeries.length > 0 ? (_a = renderSeriesControls == null ? void 0 : renderSeriesControls({
3355
+ const seriesControls = showSeriesControls ? (_a = renderSeriesControls == null ? void 0 : renderSeriesControls({
3334
3356
  series: normalizedSeries,
3335
3357
  activeSeriesId,
3336
3358
  handleSeriesChange
@@ -3363,9 +3385,10 @@ var LineChart = ({
3363
3385
  series: livelineSeries,
3364
3386
  color: (_b = primarySeries == null ? void 0 : primarySeries.color) != null ? _b : "var(--agg-color-primary)",
3365
3387
  theme: livelineTheme,
3388
+ fill: enableGradients,
3366
3389
  grid: true,
3367
- momentum: live,
3368
- pulse: live,
3390
+ momentum: isLive,
3391
+ pulse: isLive,
3369
3392
  window: windowSeconds,
3370
3393
  mode: chartType === "candlestick" ? "candle" : "line",
3371
3394
  candles: chartType === "candlestick" ? primaryCandles : void 0,
@@ -3381,7 +3404,8 @@ var LineChart = ({
3381
3404
  bottom: 28,
3382
3405
  left: 12
3383
3406
  },
3384
- loading: isLoading
3407
+ loading: isLoading,
3408
+ lineWidth: 1
3385
3409
  }
3386
3410
  )
3387
3411
  }
@@ -3588,7 +3612,7 @@ var getTabButtonClassName = ({
3588
3612
  return cn(
3589
3613
  "cursor-pointer disabled:cursor-not-allowed",
3590
3614
  "relative inline-flex h-full shrink-0 items-center justify-center gap-2 font-agg-sans",
3591
- isBarVariant ? "hover:text-agg-foreground hover:bg-agg-secondary-hover" : "hover:text-agg-foreground hover:font-bold",
3615
+ isBarVariant ? "hover:text-agg-foreground hover:bg-agg-secondary-hover" : "hover:text-agg-foreground hover:font-agg-bold",
3592
3616
  getMotionClassName(
3593
3617
  enableAnimations,
3594
3618
  "transition-[colors] duration-300 ease-in-out motion-reduce:transition-none"
@@ -4014,8 +4038,17 @@ var Tabs = ({
4014
4038
  )
4015
4039
  }
4016
4040
  ) }) : null,
4017
- item.icon ? /* @__PURE__ */ (0, import_jsx_runtime75.jsx)("span", { className: "relative z-10 inline-flex shrink-0 items-center justify-center", children: item.icon }) : null,
4018
- /* @__PURE__ */ (0, import_jsx_runtime75.jsx)("span", { className: "relative z-10 truncate whitespace-nowrap [&::first-letter]:uppercase", children: item.label })
4041
+ item.icon ? /* @__PURE__ */ (0, import_jsx_runtime75.jsx)("span", { className: "relative z-10 inline-flex shrink-0 items-center justify-center empty:hidden", children: item.icon }) : null,
4042
+ /* @__PURE__ */ (0, import_jsx_runtime75.jsx)(
4043
+ "span",
4044
+ {
4045
+ className: cn(
4046
+ "relative z-10 truncate whitespace-nowrap [&::first-letter]:uppercase"
4047
+ ),
4048
+ "data-text": item.label,
4049
+ children: item.label
4050
+ }
4051
+ )
4019
4052
  ]
4020
4053
  },
4021
4054
  item.value
@@ -4258,7 +4291,6 @@ var EventListItemContent = ({
4258
4291
  event,
4259
4292
  title,
4260
4293
  image,
4261
- showVenueLogo = true,
4262
4294
  maxOutcomes = 2,
4263
4295
  classNames,
4264
4296
  venueInfo,
@@ -4294,7 +4326,7 @@ var EventListItemContent = ({
4294
4326
  return;
4295
4327
  if ((eventToHandle == null ? void 0 : eventToHandle.key) === "Enter" || (eventToHandle == null ? void 0 : eventToHandle.key) === " ") {
4296
4328
  eventToHandle == null ? void 0 : eventToHandle.preventDefault();
4297
- onClick();
4329
+ onClick == null ? void 0 : onClick(event);
4298
4330
  }
4299
4331
  };
4300
4332
  const renderArbitrage = (value) => {
@@ -4321,7 +4353,7 @@ var EventListItemContent = ({
4321
4353
  className: cn(baseCardClassName, onClick && "cursor-pointer", classNames == null ? void 0 : classNames.root),
4322
4354
  role: onClick ? "button" : void 0,
4323
4355
  tabIndex: onClick ? 0 : void 0,
4324
- onClick,
4356
+ onClick: () => onClick == null ? void 0 : onClick(event),
4325
4357
  onKeyDown: handleKeyDown,
4326
4358
  "aria-label": ariaLabel != null ? ariaLabel : resolvedTitle,
4327
4359
  children: [
@@ -4375,7 +4407,7 @@ var EventListItemContent = ({
4375
4407
  Badge,
4376
4408
  {
4377
4409
  text: config.formatPercent(probability),
4378
- prefix: showVenueLogo ? /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(VenueLogo, { venue: visibleOutcome.venue, size: "small" }) : void 0,
4410
+ prefix: /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(VenueLogo, { venue: visibleOutcome.venue, size: "small" }),
4379
4411
  size: "large",
4380
4412
  classNames: {
4381
4413
  root: cn(
@@ -4408,7 +4440,7 @@ var EventListItemContent = ({
4408
4440
  ) }),
4409
4441
  /* @__PURE__ */ (0, import_jsx_runtime76.jsx)("span", { className: "text-agg-muted-foreground", children: "\xD7" }),
4410
4442
  singleVenue ? /* @__PURE__ */ (0, import_jsx_runtime76.jsxs)("span", { className: "flex items-center gap-1 truncate text-agg-muted-foreground", children: [
4411
- showVenueLogo ? /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
4443
+ /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
4412
4444
  VenueLogo,
4413
4445
  {
4414
4446
  venue: singleVenue,
@@ -4416,14 +4448,14 @@ var EventListItemContent = ({
4416
4448
  isMonochromatic: true,
4417
4449
  className: "text-agg-muted-foreground!"
4418
4450
  }
4419
- ) : null,
4451
+ ),
4420
4452
  /* @__PURE__ */ (0, import_jsx_runtime76.jsx)("span", { children: venueLabel })
4421
4453
  ] }) : /* @__PURE__ */ (0, import_jsx_runtime76.jsx)("span", { className: "truncate text-agg-muted-foreground", children: formatCountLabel(
4422
4454
  venueCount,
4423
4455
  labels.eventItem.venueSingular,
4424
4456
  labels.eventItem.venuePlural
4425
4457
  ) }),
4426
- showVenueLogo && !singleVenue && visibleVenueLogos.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime76.jsx)("span", { className: "flex items-center gap-1 overflow-hidden", children: visibleVenueLogos.map((venue) => /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
4458
+ !singleVenue && visibleVenueLogos.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime76.jsx)("span", { className: "flex items-center gap-1 overflow-hidden", children: visibleVenueLogos.map((venue) => /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
4427
4459
  VenueLogo,
4428
4460
  {
4429
4461
  venue,
@@ -4554,7 +4586,9 @@ var ChartTypeSwitch = ({
4554
4586
  "transition-colors duration-200 ease-in-out",
4555
4587
  isActive ? "text-agg-foreground" : "text-agg-muted-foreground"
4556
4588
  ),
4557
- onClick: () => {
4589
+ onClick: (e) => {
4590
+ e.stopPropagation();
4591
+ e.preventDefault();
4558
4592
  if (isActive) {
4559
4593
  return;
4560
4594
  }
@@ -4583,14 +4617,9 @@ var isDateLikeLabel = (value) => {
4583
4617
  return false;
4584
4618
  return (0, import_dayjs3.default)(value).isValid();
4585
4619
  };
4586
- var formatDateLabel = (value) => {
4587
- if (!isDateLikeLabel(value))
4588
- return value;
4589
- return (0, import_dayjs3.default)(value).format("MMM D, YYYY");
4590
- };
4591
- var getDefaultSelectedTimeRange = (value) => {
4620
+ var getDefaultSelectedTimeRange = (value, fallback = "1D") => {
4592
4621
  if (!value)
4593
- return "1M";
4622
+ return fallback;
4594
4623
  return value;
4595
4624
  };
4596
4625
  var getTimeWindowByRange = (range) => {
@@ -4672,24 +4701,6 @@ var resolveOutcomesByVenue = (venueMarkets, selectedOutcomeLabel) => {
4672
4701
  };
4673
4702
  }).filter((item) => item != null);
4674
4703
  };
4675
- var buildPriceHistoryGroups = (selectedOutcomes, fallbackMarketId) => {
4676
- const marketIdByVenue = /* @__PURE__ */ new Map();
4677
- selectedOutcomes.forEach(({ venue, market }) => {
4678
- var _a, _b;
4679
- const marketWithCanonicalId = market;
4680
- const canonicalMarketId = (_a = marketWithCanonicalId.marketId) != null ? _a : fallbackMarketId;
4681
- if (!canonicalMarketId)
4682
- return;
4683
- if (!marketIdByVenue.has(venue)) {
4684
- marketIdByVenue.set(venue, /* @__PURE__ */ new Set());
4685
- }
4686
- (_b = marketIdByVenue.get(venue)) == null ? void 0 : _b.add(canonicalMarketId);
4687
- });
4688
- return [...marketIdByVenue.entries()].map(([venue, marketIds]) => ({
4689
- venue,
4690
- venueMarketOutcomeIds: [...marketIds]
4691
- })).filter((group) => group.venueMarketOutcomeIds.length > 0);
4692
- };
4693
4704
  var resolveSeriesColor = (venue, index) => {
4694
4705
  var _a;
4695
4706
  const colorFromVenue = lineColorByVenue[venue];
@@ -4697,6 +4708,98 @@ var resolveSeriesColor = (venue, index) => {
4697
4708
  return colorFromVenue;
4698
4709
  return (_a = fallbackLineColors[index % fallbackLineColors.length]) != null ? _a : "#2e5cff";
4699
4710
  };
4711
+ var toNonEmptyString = (value) => {
4712
+ if (typeof value !== "string")
4713
+ return void 0;
4714
+ const trimmedValue = value.trim();
4715
+ return trimmedValue ? trimmedValue : void 0;
4716
+ };
4717
+ var resolveCanonicalMarketId = (venueMarkets, fallbackMarketId) => {
4718
+ var _a;
4719
+ const uniqueMarketIds = Array.from(
4720
+ new Set(venueMarkets.map((market) => toNonEmptyString(market.marketId)).filter(Boolean))
4721
+ );
4722
+ if (uniqueMarketIds.length === 1) {
4723
+ return uniqueMarketIds[0];
4724
+ }
4725
+ return (_a = toNonEmptyString(fallbackMarketId)) != null ? _a : uniqueMarketIds[0];
4726
+ };
4727
+ var toChartDisplayValue = (value, transformProbability) => {
4728
+ if (value == null || !Number.isFinite(value))
4729
+ return void 0;
4730
+ return transformProbability(value) * 100;
4731
+ };
4732
+ var marketChartCandleToLineChartPoint = (candle, transformProbability) => {
4733
+ var _a, _b, _c, _d;
4734
+ const open = (_a = toChartDisplayValue(candle.open, transformProbability)) != null ? _a : 0;
4735
+ const high = (_b = toChartDisplayValue(candle.high, transformProbability)) != null ? _b : open;
4736
+ const low = (_c = toChartDisplayValue(candle.low, transformProbability)) != null ? _c : open;
4737
+ const close = (_d = toChartDisplayValue(candle.close, transformProbability)) != null ? _d : open;
4738
+ return {
4739
+ time: candle.time,
4740
+ value: close,
4741
+ open,
4742
+ high,
4743
+ low,
4744
+ close
4745
+ };
4746
+ };
4747
+ var marketChartCandleToScaledCandlePoint = (candle, transformProbability) => {
4748
+ var _a, _b, _c, _d;
4749
+ const point = marketChartCandleToLineChartPoint(candle, transformProbability);
4750
+ return {
4751
+ time: point.time,
4752
+ open: (_a = point.open) != null ? _a : point.value,
4753
+ high: (_b = point.high) != null ? _b : point.value,
4754
+ low: (_c = point.low) != null ? _c : point.value,
4755
+ close: (_d = point.close) != null ? _d : point.value,
4756
+ v: candle.volume
4757
+ };
4758
+ };
4759
+ var resolveMarketChartVenueSeries = ({
4760
+ chartData,
4761
+ transformProbability
4762
+ }) => {
4763
+ if (!chartData)
4764
+ return [];
4765
+ return Object.entries(chartData.venues).map(([venue, venueData]) => ({
4766
+ venue,
4767
+ points: venueData.candles.map(
4768
+ (candle) => marketChartCandleToLineChartPoint(candle, transformProbability)
4769
+ )
4770
+ })).filter((item) => item.points.length > 0);
4771
+ };
4772
+ var resolveMarketChartLiveState = ({
4773
+ chartData,
4774
+ selectedVenue,
4775
+ transformProbability
4776
+ }) => {
4777
+ var _a, _b;
4778
+ if (!chartData) {
4779
+ return {
4780
+ liveCandle: null,
4781
+ lineValue: void 0,
4782
+ live: false
4783
+ };
4784
+ }
4785
+ const venueEntries = selectedVenue ? Object.entries(chartData.venues).filter(([venue]) => venue === selectedVenue) : Object.entries(chartData.venues);
4786
+ if (venueEntries.length === 0) {
4787
+ return {
4788
+ liveCandle: null,
4789
+ lineValue: void 0,
4790
+ live: false
4791
+ };
4792
+ }
4793
+ const singleVenueView = selectedVenue != null || venueEntries.length === 1;
4794
+ const liveCandleEntry = singleVenueView ? venueEntries.find(([, venueData]) => venueData.liveCandle != null) : null;
4795
+ const primaryLineValue = (_b = (_a = venueEntries[0]) == null ? void 0 : _a[1]) == null ? void 0 : _b.lineValue;
4796
+ const lineValue = primaryLineValue != null ? toChartDisplayValue(primaryLineValue, transformProbability) : void 0;
4797
+ return {
4798
+ liveCandle: (liveCandleEntry == null ? void 0 : liveCandleEntry[1].liveCandle) ? marketChartCandleToScaledCandlePoint(liveCandleEntry[1].liveCandle, transformProbability) : null,
4799
+ lineValue,
4800
+ live: liveCandleEntry != null
4801
+ };
4802
+ };
4700
4803
 
4701
4804
  // src/events/item-details/index.tsx
4702
4805
  var import_jsx_runtime78 = require("react/jsx-runtime");
@@ -4761,31 +4864,23 @@ var resolveAverageProbability = (values) => {
4761
4864
  return void 0;
4762
4865
  return validValues.reduce((sum, value) => sum + value, 0) / validValues.length;
4763
4866
  };
4764
- var resolveOutcomeCandidateIds = (market, outcome) => {
4765
- var _a, _b;
4766
- const marketWithCanonicalId = market;
4767
- return [
4768
- outcome.id,
4769
- (_a = outcome.externalIdentifier) != null ? _a : void 0,
4770
- market.externalIdentifier,
4771
- (_b = marketWithCanonicalId.marketId) != null ? _b : void 0
4772
- ].filter((value) => typeof value === "string" && value.trim().length > 0);
4773
- };
4774
4867
  var EventListItemDetailsGraphSection = ({
4775
4868
  venueMarkets,
4776
- canonicalMarketId,
4777
4869
  selectedOutcomeLabel,
4778
4870
  onSelectedOutcomeLabelChange,
4779
4871
  switchLabels,
4780
4872
  isDateOutcomeMarket,
4781
4873
  classNames,
4782
- showVenueLogo,
4783
4874
  venueInfo,
4784
4875
  formatPercent,
4785
4876
  selectedTimeRange,
4786
- selectedChartType
4877
+ selectedChartType,
4878
+ selectedOutcome: _selectedOutcome,
4879
+ selectedMarket
4787
4880
  }) => {
4881
+ var _a, _b;
4788
4882
  const labels = (0, import_hooks17.useLabels)();
4883
+ const { enableLiveUpdates } = (0, import_hooks17.useSdkUiConfig)();
4789
4884
  const [selectedVenue, setSelectedVenue] = (0, import_react8.useState)(null);
4790
4885
  const [activeProbabilityMode, setActiveProbabilityMode] = (0, import_react8.useState)("yes");
4791
4886
  const probabilityModeConfigs = (0, import_react8.useMemo)(() => {
@@ -4854,105 +4949,71 @@ var EventListItemDetailsGraphSection = ({
4854
4949
  no: buildModeData("no")
4855
4950
  };
4856
4951
  }, [labels, probabilityModeConfigs, selectedOutcomesByMode, venueInfo]);
4857
- const allOutcomesForHistory = (0, import_react8.useMemo)(() => {
4858
- const outcomeByModeAndId = /* @__PURE__ */ new Map();
4859
- probabilityModeOrder.forEach((mode) => {
4860
- selectedOutcomesByMode[mode].forEach((outcomeByVenue) => {
4861
- outcomeByModeAndId.set(
4862
- `${outcomeByVenue.venue}:${outcomeByVenue.outcome.id}`,
4863
- outcomeByVenue
4864
- );
4865
- });
4866
- });
4867
- return [...outcomeByModeAndId.values()];
4868
- }, [selectedOutcomesByMode]);
4869
- const priceHistoryGroups = (0, import_react8.useMemo)(() => {
4870
- return buildPriceHistoryGroups(allOutcomesForHistory, canonicalMarketId);
4871
- }, [allOutcomesForHistory, canonicalMarketId]);
4872
4952
  const timeWindow = (0, import_react8.useMemo)(() => {
4873
4953
  return getTimeWindowByRange(selectedTimeRange);
4874
4954
  }, [selectedTimeRange]);
4955
+ const activeOutcomes = selectedOutcomesByMode[activeProbabilityMode];
4956
+ const activeCanonicalMarketId = (0, import_react8.useMemo)(() => {
4957
+ return resolveCanonicalMarketId(activeOutcomes.map((item) => item.market));
4958
+ }, [activeOutcomes]);
4959
+ const venueMarketIds = (0, import_react8.useMemo)(() => {
4960
+ return activeOutcomes.map((item) => item.market.id);
4961
+ }, [activeOutcomes]);
4875
4962
  const {
4876
- data: priceHistoryData,
4877
- isLoading: isPriceHistoryLoading,
4878
- error: priceHistoryError,
4879
- results: priceHistoryResults
4880
- } = (0, import_hooks17.usePriceHistory)(__spreadProps(__spreadValues({
4881
- groups: priceHistoryGroups
4882
- }, timeWindow), {
4883
- enabled: priceHistoryGroups.length > 0
4884
- }));
4885
- const priceHistoryByVenue = (0, import_react8.useMemo)(() => {
4886
- const historyByVenue = /* @__PURE__ */ new Map();
4887
- if (!(priceHistoryData == null ? void 0 : priceHistoryData.length)) {
4888
- return historyByVenue;
4889
- }
4890
- priceHistoryData.forEach((historyItem) => {
4891
- const venue = historyItem.venue;
4892
- const venueHistory = historyByVenue.get(venue);
4893
- if (venueHistory) {
4894
- venueHistory.push(historyItem);
4895
- return;
4896
- }
4897
- historyByVenue.set(venue, [historyItem]);
4898
- });
4899
- return historyByVenue;
4900
- }, [priceHistoryData]);
4901
- const chartSeriesByMode = (0, import_react8.useMemo)(() => {
4902
- const buildSeries = (mode) => {
4903
- const modeConfig = probabilityModeConfigs[mode];
4904
- const chartSeries = [];
4905
- normalizedVenueDataByMode[mode].forEach((venueData) => {
4906
- var _a;
4907
- const venueHistory = priceHistoryByVenue.get(venueData.venue);
4908
- if (!(venueHistory == null ? void 0 : venueHistory.length))
4909
- return;
4910
- const candidateIds = resolveOutcomeCandidateIds(venueData.market, venueData.outcome);
4911
- const matchingHistory = (_a = venueHistory.find((historyItem) => candidateIds.includes(historyItem.marketId))) != null ? _a : venueHistory.length === 1 ? venueHistory[0] : void 0;
4912
- if (!matchingHistory)
4913
- return;
4914
- const points = matchingHistory.points.map((point) => {
4915
- const probability = normalizeProbability(point.price);
4916
- if (probability == null || !Number.isFinite(point.timestamp))
4917
- return null;
4918
- const open = normalizeProbability(point.open);
4919
- const high = normalizeProbability(point.high);
4920
- const low = normalizeProbability(point.low);
4921
- const close = normalizeProbability(point.close);
4922
- const transformedPoint = {
4923
- time: point.timestamp,
4924
- value: clampProbability(modeConfig.transformProbability(probability)) * 100,
4925
- open: open == null ? void 0 : clampProbability(modeConfig.transformProbability(open)) * 100,
4926
- high: high == null ? void 0 : clampProbability(modeConfig.transformProbability(high)) * 100,
4927
- low: low == null ? void 0 : clampProbability(modeConfig.transformProbability(low)) * 100,
4928
- close: close == null ? void 0 : clampProbability(modeConfig.transformProbability(close)) * 100
4929
- };
4930
- return transformedPoint;
4931
- }).filter((point) => point != null);
4932
- if (points.length === 0)
4933
- return;
4934
- chartSeries.push({
4935
- id: `${mode}-${venueData.venue}-${matchingHistory.marketId}`,
4936
- venue: venueData.venue,
4937
- color: venueData.color,
4938
- points,
4939
- lineWidth: 2,
4940
- lineStyle: "solid"
4941
- });
4942
- });
4943
- return chartSeries;
4944
- };
4945
- return {
4946
- yes: buildSeries("yes"),
4947
- no: buildSeries("no")
4948
- };
4949
- }, [normalizedVenueDataByMode, priceHistoryByVenue, probabilityModeConfigs]);
4963
+ data: marketChartData,
4964
+ isLoading: isMarketChartLoading,
4965
+ error: marketChartError,
4966
+ refetch: refetchMarketChart
4967
+ } = (0, import_hooks17.useMarketChart)({
4968
+ marketId: (_a = selectedMarket == null ? void 0 : selectedMarket.id) != null ? _a : null,
4969
+ venueMarketIds,
4970
+ interval: (0, import_hooks17.timeRangeToInterval)(selectedTimeRange),
4971
+ startTs: timeWindow.startTs * 1e3,
4972
+ endTs: timeWindow.endTs * 1e3,
4973
+ enabled: !!(selectedMarket == null ? void 0 : selectedMarket.id),
4974
+ live: enableLiveUpdates
4975
+ });
4950
4976
  const visibleChartSeries = (0, import_react8.useMemo)(() => {
4951
- const modeSeries = chartSeriesByMode[activeProbabilityMode];
4977
+ const transformProbability = probabilityModeConfigs[activeProbabilityMode].transformProbability;
4978
+ const colorByVenue = new Map(
4979
+ normalizedVenueDataByMode[activeProbabilityMode].map((venueData) => [
4980
+ venueData.venue,
4981
+ venueData.color
4982
+ ])
4983
+ );
4984
+ const series = resolveMarketChartVenueSeries({
4985
+ chartData: marketChartData,
4986
+ transformProbability
4987
+ }).map((seriesItem) => {
4988
+ var _a2;
4989
+ const resolvedVenue = seriesItem.venue;
4990
+ return {
4991
+ id: `${activeProbabilityMode}-${resolvedVenue}-${activeCanonicalMarketId != null ? activeCanonicalMarketId : "chart"}`,
4992
+ venue: resolvedVenue,
4993
+ color: (_a2 = colorByVenue.get(resolvedVenue)) != null ? _a2 : resolveSeriesColor(resolvedVenue, 0),
4994
+ points: seriesItem.points,
4995
+ lineWidth: 2,
4996
+ lineStyle: "solid"
4997
+ };
4998
+ });
4952
4999
  if (!selectedVenue)
4953
- return modeSeries;
4954
- return modeSeries.filter((seriesItem) => seriesItem.venue === selectedVenue);
4955
- }, [activeProbabilityMode, chartSeriesByMode, selectedVenue]);
5000
+ return series;
5001
+ return series.filter((seriesItem) => seriesItem.venue === selectedVenue);
5002
+ }, [
5003
+ activeCanonicalMarketId,
5004
+ activeProbabilityMode,
5005
+ marketChartData,
5006
+ normalizedVenueDataByMode,
5007
+ probabilityModeConfigs,
5008
+ selectedVenue
5009
+ ]);
5010
+ const chartLiveState = (0, import_react8.useMemo)(() => {
5011
+ return resolveMarketChartLiveState({
5012
+ chartData: marketChartData,
5013
+ selectedVenue,
5014
+ transformProbability: probabilityModeConfigs[activeProbabilityMode].transformProbability
5015
+ });
5016
+ }, [activeProbabilityMode, marketChartData, probabilityModeConfigs, selectedVenue]);
4956
5017
  const segmentedDisplayItems = (0, import_react8.useMemo)(() => {
4957
5018
  return probabilityModeOrder.map((mode) => {
4958
5019
  const averageProbability = resolveAverageProbability(
@@ -4990,31 +5051,22 @@ var EventListItemDetailsGraphSection = ({
4990
5051
  return venue;
4991
5052
  });
4992
5053
  };
4993
- const handleRetryPriceHistory = () => {
4994
- void Promise.all(priceHistoryResults.map((result) => result.refetch()));
5054
+ const handleRetryMarketChart = () => {
5055
+ void refetchMarketChart();
4995
5056
  };
4996
- if (priceHistoryError) {
4997
- return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
4998
- "div",
5057
+ if (marketChartError) {
5058
+ return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)("div", { className: cn("w-full", classNames == null ? void 0 : classNames.chart), children: /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
5059
+ StateMessage,
4999
5060
  {
5000
- className: cn(
5001
- "w-full rounded-agg-xl border border-agg-separator bg-agg-secondary",
5002
- classNames == null ? void 0 : classNames.chart
5003
- ),
5004
- children: /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
5005
- StateMessage,
5006
- {
5007
- ariaLabel: labels.eventItemDetails.chartUnavailableAria,
5008
- tone: "warning",
5009
- title: labels.eventItemDetails.chartUnavailableTitle,
5010
- description: labels.eventItemDetails.chartUnavailableDescription,
5011
- actionLabel: labels.common.retry,
5012
- onAction: handleRetryPriceHistory,
5013
- className: "min-h-[300px] px-5 py-10 md:px-10"
5014
- }
5015
- )
5061
+ tone: "warning",
5062
+ ariaLabel: labels.eventItemDetails.chartUnavailableAria,
5063
+ title: labels.eventItemDetails.chartUnavailableTitle,
5064
+ description: labels.eventItemDetails.chartUnavailableDescription,
5065
+ actionLabel: labels.common.retry,
5066
+ onAction: handleRetryMarketChart,
5067
+ className: "min-h-[300px] px-5 py-10 md:px-10"
5016
5068
  }
5017
- );
5069
+ ) });
5018
5070
  }
5019
5071
  return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
5020
5072
  LineChart,
@@ -5022,8 +5074,10 @@ var EventListItemDetailsGraphSection = ({
5022
5074
  classNames: { root: classNames == null ? void 0 : classNames.chart },
5023
5075
  series: visibleChartSeries,
5024
5076
  height: 300,
5025
- isLoading: isPriceHistoryLoading,
5077
+ isLoading: isMarketChartLoading,
5026
5078
  chartType: selectedChartType,
5079
+ liveCandle: selectedChartType === "candlestick" ? (_b = chartLiveState.liveCandle) != null ? _b : void 0 : void 0,
5080
+ lineValue: chartLiveState.lineValue,
5027
5081
  showSeriesControls: activeModeVenueData.length > 0 || segmentedDisplayItems.length > 0,
5028
5082
  renderSeriesControls: () => {
5029
5083
  return /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(
@@ -5039,7 +5093,7 @@ var EventListItemDetailsGraphSection = ({
5039
5093
  classNames == null ? void 0 : classNames.outcomeBadges
5040
5094
  ),
5041
5095
  children: activeModeVenueData.map((venueData) => {
5042
- var _a;
5096
+ var _a2;
5043
5097
  const text = venueData.probability == null ? "-" : formatPercent(venueData.probability);
5044
5098
  const isActiveVenue = selectedVenue === venueData.venue;
5045
5099
  return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
@@ -5056,14 +5110,14 @@ var EventListItemDetailsGraphSection = ({
5056
5110
  {
5057
5111
  text,
5058
5112
  size: "large",
5059
- prefix: showVenueLogo ? /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
5113
+ prefix: /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
5060
5114
  VenueLogo,
5061
5115
  {
5062
5116
  venue: venueData.venue,
5063
5117
  size: "small",
5064
- title: (_a = venueInfo == null ? void 0 : venueInfo[venueData.venue]) == null ? void 0 : _a.label
5118
+ title: (_a2 = venueInfo == null ? void 0 : venueInfo[venueData.venue]) == null ? void 0 : _a2.label
5065
5119
  }
5066
- ) : void 0,
5120
+ ),
5067
5121
  classNames: {
5068
5122
  root: cn("h-9 shrink-0 border-2 px-4 text-agg-base leading-agg-6")
5069
5123
  },
@@ -5104,45 +5158,55 @@ var EventListItemDetailsGraphSection = ({
5104
5158
  };
5105
5159
  var EventListItemDetailsContent = ({
5106
5160
  event,
5107
- title,
5108
- image,
5109
- showVenueLogo = true,
5110
5161
  classNames,
5111
5162
  venueInfo,
5112
5163
  detailsStats,
5113
5164
  ariaLabel,
5114
- defaultTimeRange
5165
+ defaultTimeRange,
5166
+ onClick
5115
5167
  }) => {
5168
+ var _a;
5116
5169
  const config = (0, import_hooks17.useSdkUiConfig)();
5117
5170
  const labels = (0, import_hooks17.useLabels)();
5118
5171
  const venueMarkets = (0, import_react8.useMemo)(() => {
5119
- var _a;
5120
- return (_a = event.venueMarkets) != null ? _a : [];
5172
+ var _a2;
5173
+ return (_a2 = event.venueMarkets) != null ? _a2 : [];
5121
5174
  }, [event.venueMarkets]);
5175
+ const [selectedMarket, setSelectedMarket] = (0, import_react8.useState)(venueMarkets[0]);
5176
+ const [selectedOutcome] = (0, import_react8.useState)(
5177
+ (_a = selectedMarket == null ? void 0 : selectedMarket.venueMarketOutcomes.find(
5178
+ (outcome) => outcome.winner
5179
+ )) != null ? _a : selectedMarket == null ? void 0 : selectedMarket.venueMarketOutcomes[0]
5180
+ );
5122
5181
  const primaryVenueMarket = (0, import_react8.useMemo)(() => {
5123
5182
  return selectPrimaryVenueMarket(venueMarkets);
5124
5183
  }, [venueMarkets]);
5184
+ const filteredVenueMarkets = (0, import_react8.useMemo)(() => {
5185
+ if (!selectedMarket)
5186
+ return venueMarkets;
5187
+ return venueMarkets.filter(
5188
+ (vm) => vm.question === (selectedMarket == null ? void 0 : selectedMarket.question)
5189
+ );
5190
+ }, [venueMarkets, selectedMarket]);
5125
5191
  const outcomeLabels = (0, import_react8.useMemo)(() => {
5126
- return resolveOutcomeLabels(venueMarkets);
5127
- }, [venueMarkets]);
5192
+ return resolveOutcomeLabels(filteredVenueMarkets);
5193
+ }, [filteredVenueMarkets]);
5128
5194
  const [selectedOutcomeLabel, setSelectedOutcomeLabel] = (0, import_react8.useState)(() => {
5129
5195
  return resolveDefaultOutcomeLabel(outcomeLabels);
5130
5196
  });
5197
+ const configTimeRange = config.defaultChartTimeRange;
5131
5198
  const [selectedTimeRange, setSelectedTimeRange] = (0, import_react8.useState)(() => {
5132
- return getDefaultSelectedTimeRange(defaultTimeRange);
5199
+ return getDefaultSelectedTimeRange(defaultTimeRange, configTimeRange);
5133
5200
  });
5134
5201
  const [selectedChartType, setSelectedChartType] = (0, import_react8.useState)("line");
5135
5202
  (0, import_react8.useEffect)(() => {
5136
- setSelectedTimeRange(getDefaultSelectedTimeRange(defaultTimeRange));
5137
- }, [defaultTimeRange]);
5138
- const resolvedTitle = resolveTileTitle(event, primaryVenueMarket, title);
5139
- const resolvedImage = resolveTileImage(event, primaryVenueMarket, image);
5203
+ setSelectedTimeRange(getDefaultSelectedTimeRange(defaultTimeRange, configTimeRange));
5204
+ }, [defaultTimeRange, configTimeRange]);
5140
5205
  const isDateOutcomeMarket = outcomeLabels.length > 2 && outcomeLabels.every(isDateLikeLabel);
5141
- const outcomeSelectorLabels = outcomeLabels;
5142
5206
  const probabilityByLabel = (0, import_react8.useMemo)(() => {
5143
5207
  return new Map(
5144
5208
  outcomeLabels.map((label) => {
5145
- const outcomesByVenue = resolveOutcomesByVenue(venueMarkets, label);
5209
+ const outcomesByVenue = resolveOutcomesByVenue(filteredVenueMarkets, label);
5146
5210
  const probabilities = outcomesByVenue.map((item) => normalizeProbability(item.outcome.price)).filter((value) => value != null);
5147
5211
  if (probabilities.length === 0) {
5148
5212
  return [label, void 0];
@@ -5151,13 +5215,13 @@ var EventListItemDetailsContent = ({
5151
5215
  return [label, averageProbability];
5152
5216
  })
5153
5217
  );
5154
- }, [outcomeLabels, venueMarkets]);
5218
+ }, [outcomeLabels, filteredVenueMarkets]);
5155
5219
  const mainOutcomeLabel = (0, import_react8.useMemo)(() => {
5156
5220
  if (outcomeLabels.length === 0)
5157
5221
  return void 0;
5158
5222
  return [...outcomeLabels].sort((left, right) => {
5159
- var _a, _b;
5160
- const leftProbability = (_a = probabilityByLabel.get(left)) != null ? _a : -1;
5223
+ var _a2, _b;
5224
+ const leftProbability = (_a2 = probabilityByLabel.get(left)) != null ? _a2 : -1;
5161
5225
  const rightProbability = (_b = probabilityByLabel.get(right)) != null ? _b : -1;
5162
5226
  return rightProbability - leftProbability;
5163
5227
  })[0];
@@ -5174,17 +5238,17 @@ var EventListItemDetailsContent = ({
5174
5238
  setSelectedOutcomeLabel(fallbackOutcomeLabel);
5175
5239
  }, [isDateOutcomeMarket, mainOutcomeLabel, outcomeLabels, selectedOutcomeLabel]);
5176
5240
  const switchLabels = (0, import_react8.useMemo)(() => {
5177
- var _a, _b;
5241
+ var _a2, _b;
5178
5242
  if (isDateOutcomeMarket) {
5179
5243
  return [labels.eventItemDetails.yes, labels.eventItemDetails.no];
5180
5244
  }
5181
5245
  const sortedOutcomeLabels = [...outcomeLabels].sort((left, right) => {
5182
- var _a2, _b2;
5183
- const leftProbability = (_a2 = probabilityByLabel.get(left)) != null ? _a2 : -1;
5246
+ var _a3, _b2;
5247
+ const leftProbability = (_a3 = probabilityByLabel.get(left)) != null ? _a3 : -1;
5184
5248
  const rightProbability = (_b2 = probabilityByLabel.get(right)) != null ? _b2 : -1;
5185
5249
  return rightProbability - leftProbability;
5186
5250
  });
5187
- const firstLabel = (_a = sortedOutcomeLabels[0]) != null ? _a : labels.eventItemDetails.yes;
5251
+ const firstLabel = (_a2 = sortedOutcomeLabels[0]) != null ? _a2 : labels.eventItemDetails.yes;
5188
5252
  const secondLabel = (_b = sortedOutcomeLabels.find((label) => label !== firstLabel)) != null ? _b : firstLabel;
5189
5253
  return [firstLabel, secondLabel];
5190
5254
  }, [
@@ -5195,34 +5259,44 @@ var EventListItemDetailsContent = ({
5195
5259
  probabilityByLabel
5196
5260
  ]);
5197
5261
  const volumeLabel = (0, import_react8.useMemo)(() => {
5198
- var _a;
5199
- const resolvedVolume = typeof event.volume === "number" ? event.volume : (_a = primaryVenueMarket == null ? void 0 : primaryVenueMarket.volume) != null ? _a : void 0;
5262
+ var _a2;
5263
+ const resolvedVolume = typeof event.volume === "number" ? event.volume : (_a2 = primaryVenueMarket == null ? void 0 : primaryVenueMarket.volume) != null ? _a2 : void 0;
5200
5264
  if (typeof resolvedVolume !== "number")
5201
5265
  return "";
5202
5266
  return `${config.formatCompactCurrency(resolvedVolume)} ${labels.eventItemDetails.volumeSuffix}`;
5203
5267
  }, [config, event.volume, labels.eventItemDetails.volumeSuffix, primaryVenueMarket == null ? void 0 : primaryVenueMarket.volume]);
5204
5268
  if (!primaryVenueMarket || !selectedOutcomeLabel) {
5205
- return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(EventListItemDetailsUnavailableState, { classNames, ariaLabel });
5269
+ return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
5270
+ EventListItemDetailsUnavailableState,
5271
+ {
5272
+ classNames,
5273
+ ariaLabel: ariaLabel != null ? ariaLabel : event.title
5274
+ }
5275
+ );
5206
5276
  }
5207
5277
  return /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(
5208
5278
  Card,
5209
5279
  {
5210
5280
  className: cn(detailsBaseCardClassName, classNames == null ? void 0 : classNames.root),
5211
- "aria-label": ariaLabel != null ? ariaLabel : resolvedTitle,
5281
+ "aria-label": ariaLabel != null ? ariaLabel : event.title,
5282
+ onClick: () => {
5283
+ onClick == null ? void 0 : onClick(event);
5284
+ },
5212
5285
  children: [
5213
5286
  /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(
5214
5287
  "div",
5215
5288
  {
5216
5289
  className: cn(
5217
5290
  "flex flex-row gap-3 md:gap-4",
5218
- "items-center justify-start",
5291
+ venueMarkets.length > 1 ? "items-start" : "items-center",
5292
+ "justify-start",
5219
5293
  classNames == null ? void 0 : classNames.header
5220
5294
  ),
5221
5295
  children: [
5222
- resolvedImage ? /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
5296
+ event.image ? /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
5223
5297
  RemoteImage,
5224
5298
  {
5225
- src: resolvedImage,
5299
+ src: event.image,
5226
5300
  alt: "",
5227
5301
  className: "size-10 rounded-agg-lg object-cover md:size-[60px]"
5228
5302
  }
@@ -5237,19 +5311,18 @@ var EventListItemDetailsContent = ({
5237
5311
  "truncate text-wrap wrap-break-word line-clamp-2",
5238
5312
  classNames == null ? void 0 : classNames.title
5239
5313
  ),
5240
- children: resolvedTitle
5314
+ children: event.title
5241
5315
  }
5242
5316
  ),
5243
- outcomeSelectorLabels.length > 2 ? /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
5317
+ venueMarkets.length > 1 ? /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
5244
5318
  "div",
5245
5319
  {
5246
5320
  className: cn(
5247
- "flex items-center gap-2 overflow-x-auto pb-1 md:flex-wrap md:overflow-visible md:pb-0",
5321
+ "flex flex-row flex-nowrap items-center gap-2 overflow-x-auto pb-1 md:pb-0",
5248
5322
  classNames == null ? void 0 : classNames.headerPills
5249
5323
  ),
5250
- children: outcomeSelectorLabels.map((outcomeSelectorLabel) => {
5251
- const isActive = outcomeSelectorLabel === selectedOutcomeLabel;
5252
- const displayLabel = isDateLikeLabel(outcomeSelectorLabel) ? formatDateLabel(outcomeSelectorLabel) : outcomeSelectorLabel;
5324
+ children: venueMarkets.map((venueMarket) => {
5325
+ const isActive = (selectedMarket == null ? void 0 : selectedMarket.id) === venueMarket.id;
5253
5326
  return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
5254
5327
  Button,
5255
5328
  {
@@ -5261,10 +5334,14 @@ var EventListItemDetailsContent = ({
5261
5334
  "border-2",
5262
5335
  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"
5263
5336
  ),
5264
- onClick: () => setSelectedOutcomeLabel(outcomeSelectorLabel),
5265
- children: displayLabel
5337
+ onClick: (e) => {
5338
+ e.stopPropagation();
5339
+ e.preventDefault();
5340
+ setSelectedMarket(venueMarket);
5341
+ },
5342
+ children: venueMarket.question
5266
5343
  },
5267
- outcomeSelectorLabel
5344
+ venueMarket.id
5268
5345
  );
5269
5346
  })
5270
5347
  }
@@ -5293,14 +5370,14 @@ var EventListItemDetailsContent = ({
5293
5370
  /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
5294
5371
  EventListItemDetailsGraphSection,
5295
5372
  {
5296
- venueMarkets,
5297
- canonicalMarketId: event.id,
5373
+ selectedOutcome,
5374
+ selectedMarket,
5375
+ venueMarkets: filteredVenueMarkets,
5298
5376
  selectedOutcomeLabel,
5299
5377
  onSelectedOutcomeLabelChange: setSelectedOutcomeLabel,
5300
5378
  switchLabels,
5301
5379
  isDateOutcomeMarket,
5302
5380
  classNames,
5303
- showVenueLogo,
5304
5381
  venueInfo,
5305
5382
  formatPercent: config.formatPercent,
5306
5383
  selectedTimeRange,
@@ -5326,7 +5403,11 @@ var EventListItemDetailsContent = ({
5326
5403
  isActive ? "font-agg-bold! text-agg-foreground!" : "font-agg-normal! text-agg-muted-foreground!"
5327
5404
  ),
5328
5405
  "aria-pressed": isActive,
5329
- onClick: () => setSelectedTimeRange(timeRange),
5406
+ onClick: (e) => {
5407
+ e.stopPropagation();
5408
+ e.preventDefault();
5409
+ setSelectedTimeRange(timeRange);
5410
+ },
5330
5411
  children: timeRange === "ALL" ? labels.eventItemDetails.allTimeRange : timeRange
5331
5412
  },
5332
5413
  timeRange
@@ -5344,19 +5425,20 @@ var EventListItemDetailsByEventId = (_a) => {
5344
5425
  } = _b, rest = __objRest(_b, [
5345
5426
  "eventId"
5346
5427
  ]);
5428
+ const resolvedEventId = eventId != null ? eventId : "";
5347
5429
  const {
5348
5430
  event: fetchedEvent,
5349
5431
  error,
5350
5432
  isError,
5351
5433
  isLoading
5352
5434
  } = (0, import_hooks17.useVenueEvent)({
5353
- eventId: eventId != null ? eventId : "",
5354
- enabled: !!eventId
5435
+ eventId: resolvedEventId,
5436
+ enabled: !!resolvedEventId
5355
5437
  });
5356
5438
  const resolvedEvent = (0, import_react8.useMemo)(() => {
5357
5439
  return resolveEventListItemEvent(fetchedEvent);
5358
5440
  }, [fetchedEvent]);
5359
- if (!eventId) {
5441
+ if (!resolvedEventId) {
5360
5442
  return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
5361
5443
  EventListItemDetailsUnavailableState,
5362
5444
  {
@@ -5395,26 +5477,22 @@ var EventListItemDetails = (props) => {
5395
5477
  }
5396
5478
  if ("eventId" in props && typeof props.eventId === "string") {
5397
5479
  const {
5398
- title: titleOverride,
5399
- image: imageOverride,
5400
- showVenueLogo: showVenueLogoOverride,
5401
5480
  classNames,
5402
5481
  venueInfo,
5403
5482
  detailsStats,
5404
5483
  ariaLabel: ariaLabelOverride,
5405
- defaultTimeRange: defaultTimeRangeOverride
5484
+ defaultTimeRange: defaultTimeRangeOverride,
5485
+ onClick
5406
5486
  } = props;
5407
5487
  const byEventIdProps = {
5408
5488
  eventId: props.eventId,
5409
5489
  isLoading: false,
5410
- title: titleOverride,
5411
- image: imageOverride,
5412
- showVenueLogo: showVenueLogoOverride,
5413
5490
  classNames,
5414
5491
  venueInfo,
5415
5492
  detailsStats,
5416
5493
  ariaLabel: ariaLabelOverride,
5417
- defaultTimeRange: defaultTimeRangeOverride
5494
+ defaultTimeRange: defaultTimeRangeOverride,
5495
+ onClick
5418
5496
  };
5419
5497
  return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(EventListItemDetailsByEventId, __spreadValues({}, byEventIdProps));
5420
5498
  }
@@ -5461,24 +5539,29 @@ var resolveInitialTab = (defaultTab) => {
5461
5539
  return parsedTab.data;
5462
5540
  return "order-book";
5463
5541
  };
5464
- var resolveMarket = (event, marketId) => {
5465
- var _a, _b, _c, _d, _e;
5466
- if (!event.venueMarkets || event.venueMarkets.length === 0)
5542
+ var resolveMarketFromVenueMarkets = (venueMarkets, marketId) => {
5543
+ var _a, _b;
5544
+ if (!venueMarkets || venueMarkets.length === 0)
5467
5545
  return void 0;
5468
5546
  if (!marketId) {
5547
+ const primary = selectPrimaryVenueMarket(venueMarkets);
5548
+ const totalVolume2 = venueMarkets.reduce((sum, vm) => {
5549
+ return sum + (typeof vm.volume === "number" ? vm.volume : 0);
5550
+ }, 0);
5469
5551
  return {
5470
- id: event.id,
5471
- venueMarkets: event.venueMarkets,
5472
- volume: event.volume,
5473
- status: event.status,
5474
- startDate: event.startDate,
5475
- endDate: event.endDate,
5476
- creationDate: event.creationDate,
5477
- question: event.title
5552
+ id: (_a = primary == null ? void 0 : primary.id) != null ? _a : venueMarkets[0].id,
5553
+ venueMarkets,
5554
+ volume: totalVolume2 || (primary == null ? void 0 : primary.volume),
5555
+ status: primary == null ? void 0 : primary.status,
5556
+ startDate: primary == null ? void 0 : primary.startDate,
5557
+ endDate: primary == null ? void 0 : primary.endDate,
5558
+ creationDate: primary == null ? void 0 : primary.creationDate,
5559
+ question: (_b = primary == null ? void 0 : primary.question) != null ? _b : venueMarkets[0].question
5478
5560
  };
5479
5561
  }
5480
- const venueMarkets = event.venueMarkets;
5481
- const matchedVenueMarket = venueMarkets.find((vm) => vm.id === marketId);
5562
+ const matchedVenueMarket = venueMarkets.find(
5563
+ (vm) => vm.id === marketId || vm.externalIdentifier === marketId
5564
+ );
5482
5565
  if (!matchedVenueMarket)
5483
5566
  return void 0;
5484
5567
  const siblingVenueMarkets = venueMarkets.filter(
@@ -5491,11 +5574,11 @@ var resolveMarket = (event, marketId) => {
5491
5574
  id: matchedVenueMarket.id,
5492
5575
  venueMarkets: siblingVenueMarkets,
5493
5576
  volume: totalVolume || matchedVenueMarket.volume,
5494
- status: (_a = matchedVenueMarket.status) != null ? _a : event.status,
5495
- startDate: (_b = matchedVenueMarket.startDate) != null ? _b : event.startDate,
5496
- endDate: (_c = matchedVenueMarket.endDate) != null ? _c : event.endDate,
5497
- creationDate: (_d = matchedVenueMarket.creationDate) != null ? _d : event.creationDate,
5498
- question: (_e = matchedVenueMarket.question) != null ? _e : event.title
5577
+ status: matchedVenueMarket.status,
5578
+ startDate: matchedVenueMarket.startDate,
5579
+ endDate: matchedVenueMarket.endDate,
5580
+ creationDate: matchedVenueMarket.creationDate,
5581
+ question: matchedVenueMarket.question
5499
5582
  };
5500
5583
  };
5501
5584
  var resolveDisplayOutcomeLabels = (labels) => {
@@ -5564,7 +5647,8 @@ var resolveHeaderOutcomeItems = (venueMarkets, defaultOutcomeLabel) => {
5564
5647
  label,
5565
5648
  probability: probabilityByLabel.get(label),
5566
5649
  tone: resolveOutcomeTone(label, index),
5567
- isDefault: normalizeLabel2(label) === normalizeLabel2((_a = defaultOutcomeLabel != null ? defaultOutcomeLabel : labels[0]) != null ? _a : "")
5650
+ isDefault: normalizeLabel2(label) === normalizeLabel2((_a = defaultOutcomeLabel != null ? defaultOutcomeLabel : labels[0]) != null ? _a : ""),
5651
+ venue: venueMarkets[0].venue
5568
5652
  };
5569
5653
  });
5570
5654
  };
@@ -5655,23 +5739,23 @@ var resolveOtherTabRows = (market, labels) => {
5655
5739
  return rows;
5656
5740
  };
5657
5741
  var buildMarketDetailsModel = ({
5658
- event,
5742
+ venueMarkets,
5659
5743
  marketId,
5660
5744
  title,
5661
5745
  image,
5662
5746
  formatCompactCurrency,
5663
5747
  labels
5664
5748
  }) => {
5665
- var _a;
5666
- const market = resolveMarket(event, marketId);
5749
+ var _a, _b;
5750
+ const market = resolveMarketFromVenueMarkets(venueMarkets, marketId);
5667
5751
  if (!market)
5668
5752
  return void 0;
5669
5753
  const primaryVenueMarket = selectPrimaryVenueMarket(market.venueMarkets);
5670
5754
  if (!primaryVenueMarket)
5671
5755
  return void 0;
5672
- const resolvedTitle = resolveTileTitle(event, primaryVenueMarket, title);
5673
- const resolvedImage = resolveTileImage(event, primaryVenueMarket, image);
5674
- const resolvedVolume = typeof market.volume === "number" ? market.volume : (_a = primaryVenueMarket.volume) != null ? _a : void 0;
5756
+ const resolvedTitle = (title == null ? void 0 : title.trim()) || primaryVenueMarket.question || market.question;
5757
+ const resolvedImage = (_a = typeof image === "string" && image.trim() ? image : void 0) != null ? _a : typeof primaryVenueMarket.image === "string" && primaryVenueMarket.image.trim() ? primaryVenueMarket.image : void 0;
5758
+ const resolvedVolume = typeof market.volume === "number" ? market.volume : (_b = primaryVenueMarket.volume) != null ? _b : void 0;
5675
5759
  const subtitle = resolveSubtitle({
5676
5760
  venueMarkets: market.venueMarkets,
5677
5761
  volume: resolvedVolume,
@@ -5817,7 +5901,7 @@ var getOutcomeButtonClassName = ({
5817
5901
  );
5818
5902
  };
5819
5903
  var MarketDetailsContent = ({
5820
- event,
5904
+ venueMarkets,
5821
5905
  marketId,
5822
5906
  title,
5823
5907
  image,
@@ -5825,29 +5909,29 @@ var MarketDetailsContent = ({
5825
5909
  onOpenChange,
5826
5910
  defaultTab,
5827
5911
  defaultOutcomeLabel,
5828
- defaultTimeRange = "1M",
5912
+ defaultTimeRange,
5829
5913
  orderBookDepth = orderBookRowLimitDefault,
5830
5914
  ariaLabel,
5831
5915
  classNames,
5832
- otherContent,
5833
- liveUpdate = false
5916
+ otherContent
5834
5917
  }) => {
5918
+ var _a, _b, _c, _d;
5835
5919
  const config = (0, import_hooks18.useSdkUiConfig)();
5836
5920
  const labels = (0, import_hooks18.useLabels)();
5837
5921
  const detailsContentId = (0, import_react9.useId)();
5838
5922
  const model = (0, import_react9.useMemo)(() => {
5839
5923
  return buildMarketDetailsModel({
5840
- event,
5924
+ venueMarkets,
5841
5925
  marketId,
5842
5926
  title,
5843
5927
  image,
5844
5928
  formatCompactCurrency: config.formatCompactCurrency,
5845
5929
  labels
5846
5930
  });
5847
- }, [config.formatCompactCurrency, event, image, labels, marketId, title]);
5931
+ }, [config.formatCompactCurrency, venueMarkets, image, labels, marketId, title]);
5848
5932
  const resolvedMarket = (0, import_react9.useMemo)(() => {
5849
- return resolveMarket(event, marketId);
5850
- }, [event, marketId]);
5933
+ return resolveMarketFromVenueMarkets(venueMarkets, marketId);
5934
+ }, [venueMarkets, marketId]);
5851
5935
  const marketDetailsTabs = (0, import_react9.useMemo)(() => {
5852
5936
  return getMarketDetailsTabs(labels);
5853
5937
  }, [labels]);
@@ -5858,22 +5942,23 @@ var MarketDetailsContent = ({
5858
5942
  (0, import_react9.useEffect)(() => {
5859
5943
  setSelectedTab(resolveInitialTab(defaultTab));
5860
5944
  }, [defaultTab]);
5861
- const [selectedTimeRange, setSelectedTimeRange] = (0, import_react9.useState)(defaultTimeRange);
5945
+ const resolvedDefaultTimeRange = (_a = defaultTimeRange != null ? defaultTimeRange : config.defaultChartTimeRange) != null ? _a : "1D";
5946
+ const [selectedTimeRange, setSelectedTimeRange] = (0, import_react9.useState)(resolvedDefaultTimeRange);
5862
5947
  const [selectedChartType, setSelectedChartType] = (0, import_react9.useState)("line");
5863
5948
  (0, import_react9.useEffect)(() => {
5864
- setSelectedTimeRange(defaultTimeRange);
5865
- }, [defaultTimeRange]);
5949
+ setSelectedTimeRange(resolvedDefaultTimeRange);
5950
+ }, [resolvedDefaultTimeRange]);
5866
5951
  const [selectedOutcomeLabel, setSelectedOutcomeLabel] = (0, import_react9.useState)(
5867
5952
  () => {
5868
- var _a;
5869
- return resolveInitialOutcomeLabel((_a = model == null ? void 0 : model.outcomeLabels) != null ? _a : [], defaultOutcomeLabel);
5953
+ var _a2;
5954
+ return resolveInitialOutcomeLabel((_a2 = model == null ? void 0 : model.outcomeLabels) != null ? _a2 : [], defaultOutcomeLabel);
5870
5955
  }
5871
5956
  );
5872
5957
  const [selectedGraphVenue, setSelectedGraphVenue] = (0, import_react9.useState)(null);
5873
5958
  (0, import_react9.useEffect)(() => {
5874
- var _a;
5959
+ var _a2;
5875
5960
  setSelectedOutcomeLabel(
5876
- resolveInitialOutcomeLabel((_a = model == null ? void 0 : model.outcomeLabels) != null ? _a : [], defaultOutcomeLabel)
5961
+ resolveInitialOutcomeLabel((_a2 = model == null ? void 0 : model.outcomeLabels) != null ? _a2 : [], defaultOutcomeLabel)
5877
5962
  );
5878
5963
  }, [defaultOutcomeLabel, model == null ? void 0 : model.outcomeLabels]);
5879
5964
  const headerOutcomeItems = (0, import_react9.useMemo)(() => {
@@ -5900,52 +5985,66 @@ var MarketDetailsContent = ({
5900
5985
  return outcomesByLabelMap;
5901
5986
  }, [headerOutcomeItems, model]);
5902
5987
  const selectedOutcomesByVenue = (0, import_react9.useMemo)(() => {
5903
- var _a;
5988
+ var _a2;
5904
5989
  if (!selectedOutcomeLabel)
5905
5990
  return [];
5906
- return (_a = outcomesByLabel.get(selectedOutcomeLabel)) != null ? _a : [];
5991
+ return (_a2 = outcomesByLabel.get(selectedOutcomeLabel)) != null ? _a2 : [];
5907
5992
  }, [outcomesByLabel, selectedOutcomeLabel]);
5993
+ const chartEnabled = isOpened && selectedTab === "graph";
5994
+ const orderBookEnabled = isOpened && selectedTab === "order-book";
5908
5995
  const timeWindow = (0, import_react9.useMemo)(() => {
5909
5996
  return getTimeWindowByRange(selectedTimeRange);
5910
5997
  }, [selectedTimeRange]);
5911
- const graphOutcomes = (0, import_react9.useMemo)(() => {
5912
- const uniqueOutcomesByVenueAndId = /* @__PURE__ */ new Map();
5913
- outcomesByLabel.forEach((outcomes) => {
5914
- outcomes.forEach((outcomeByVenue) => {
5915
- uniqueOutcomesByVenueAndId.set(
5916
- `${outcomeByVenue.venue}:${outcomeByVenue.outcome.id}`,
5917
- outcomeByVenue
5918
- );
5919
- });
5920
- });
5921
- return [...uniqueOutcomesByVenueAndId.values()];
5922
- }, [outcomesByLabel]);
5923
- const canonicalMarketIdForHistory = model == null ? void 0 : model.market.id;
5924
- const priceHistoryGroups = (0, import_react9.useMemo)(() => {
5925
- return buildPriceHistoryGroups(graphOutcomes, canonicalMarketIdForHistory);
5926
- }, [canonicalMarketIdForHistory, graphOutcomes]);
5927
- const { data: priceHistoryData, isLoading: isPriceHistoryLoading } = (0, import_hooks18.usePriceHistory)(__spreadProps(__spreadValues({
5928
- groups: priceHistoryGroups
5929
- }, timeWindow), {
5930
- enabled: isOpened && selectedTab === "graph" && priceHistoryGroups.length > 0
5931
- }));
5932
- const orderBookInputs = (0, import_react9.useMemo)(() => {
5933
- return selectedOutcomesByVenue.map(({ market, outcome }) => ({
5934
- market,
5935
- outcome,
5936
- liveUpdate
5937
- }));
5938
- }, [selectedOutcomesByVenue, liveUpdate]);
5998
+ const primaryVenueMarketId = (_c = (_b = selectedOutcomesByVenue[0]) == null ? void 0 : _b.market.id) != null ? _c : null;
5999
+ const venueMarketIds = (0, import_react9.useMemo)(() => {
6000
+ return selectedOutcomesByVenue.map((item) => item.market.id);
6001
+ }, [selectedOutcomesByVenue]);
5939
6002
  const {
5940
- data: orderBookData,
6003
+ data: marketChartData,
6004
+ isLoading: isMarketChartLoading,
6005
+ error: marketChartError,
6006
+ refetch: refetchMarketChart
6007
+ } = (0, import_hooks18.useMarketChart)({
6008
+ marketId: primaryVenueMarketId,
6009
+ venueMarketIds,
6010
+ interval: (0, import_hooks18.timeRangeToInterval)(selectedTimeRange),
6011
+ startTs: timeWindow.startTs * 1e3,
6012
+ endTs: timeWindow.endTs * 1e3,
6013
+ enabled: chartEnabled && !!primaryVenueMarketId
6014
+ });
6015
+ const {
6016
+ data: marketOrderbookData,
5941
6017
  isLoading: isOrderBookLoading,
5942
6018
  error: orderBookError,
5943
- results: orderBookResults
5944
- } = (0, import_hooks18.useOrderBook)({
5945
- orderbooks: orderBookInputs,
5946
- enabled: isOpened && selectedTab === "order-book" && orderBookInputs.length > 0,
5947
- canonicalMarketId: liveUpdate ? canonicalMarketIdForHistory : void 0
6019
+ refetch: refetchOrderBook
6020
+ } = (0, import_hooks18.useMarketOrderbook)({
6021
+ marketId: primaryVenueMarketId,
6022
+ enabled: orderBookEnabled && !!primaryVenueMarketId,
6023
+ venueOutcomes: selectedOutcomesByVenue.map((item) => ({
6024
+ venue: item.market.venue,
6025
+ venueMarketOutcomeId: item.outcome.id
6026
+ }))
5948
6027
  });
6028
+ const orderBookData = (0, import_react9.useMemo)(() => {
6029
+ if (!marketOrderbookData)
6030
+ return void 0;
6031
+ const results = selectedOutcomesByVenue.flatMap(({ market, outcome }) => {
6032
+ const venueOrderbook = marketOrderbookData.venueOrderbooks[market.venue];
6033
+ if (!venueOrderbook)
6034
+ return [];
6035
+ return [
6036
+ {
6037
+ market,
6038
+ outcome,
6039
+ orderbook: {
6040
+ bids: venueOrderbook.bids,
6041
+ asks: venueOrderbook.asks
6042
+ }
6043
+ }
6044
+ ];
6045
+ });
6046
+ return results.length === selectedOutcomesByVenue.length ? results : void 0;
6047
+ }, [marketOrderbookData, selectedOutcomesByVenue]);
5949
6048
  const askRows = (0, import_react9.useMemo)(() => {
5950
6049
  return resolveOrderBookRows({
5951
6050
  data: orderBookData,
@@ -5958,78 +6057,43 @@ var MarketDetailsContent = ({
5958
6057
  side: "bids"
5959
6058
  });
5960
6059
  }, [orderBookData]);
5961
- const priceHistoryByVenue = (0, import_react9.useMemo)(() => {
5962
- const historyByVenue = /* @__PURE__ */ new Map();
5963
- if (!(priceHistoryData == null ? void 0 : priceHistoryData.length)) {
5964
- return historyByVenue;
5965
- }
5966
- priceHistoryData.forEach((historyItem) => {
5967
- const venue = historyItem.venue;
5968
- const venueHistory = historyByVenue.get(venue);
5969
- if (venueHistory) {
5970
- venueHistory.push(historyItem);
5971
- return;
5972
- }
5973
- historyByVenue.set(venue, [historyItem]);
5974
- });
5975
- return historyByVenue;
5976
- }, [priceHistoryData]);
5977
- const graphSeriesByOutcomeLabel = (0, import_react9.useMemo)(() => {
5978
- const seriesByOutcomeLabel = /* @__PURE__ */ new Map();
5979
- const resolveOutcomeCandidateIds2 = (outcomeByVenue) => {
5980
- var _a, _b;
5981
- const marketWithCanonicalId = outcomeByVenue.market;
5982
- return [
5983
- outcomeByVenue.outcome.id,
5984
- (_a = outcomeByVenue.outcome.externalIdentifier) != null ? _a : void 0,
5985
- outcomeByVenue.market.externalIdentifier,
5986
- (_b = marketWithCanonicalId.marketId) != null ? _b : void 0,
5987
- canonicalMarketIdForHistory
5988
- ].filter((value) => typeof value === "string" && value.trim().length > 0);
5989
- };
5990
- headerOutcomeItems.forEach((headerOutcomeItem) => {
5991
- var _a;
5992
- const outcomes = (_a = outcomesByLabel.get(headerOutcomeItem.label)) != null ? _a : [];
5993
- const graphSeries2 = [];
5994
- outcomes.forEach((outcomeByVenue, index) => {
5995
- var _a2;
5996
- const venueHistory = priceHistoryByVenue.get(outcomeByVenue.venue);
5997
- if (!(venueHistory == null ? void 0 : venueHistory.length))
5998
- return;
5999
- const candidateIds = resolveOutcomeCandidateIds2(outcomeByVenue);
6000
- const matchingHistory = (_a2 = venueHistory.find((historyItem) => candidateIds.includes(historyItem.marketId))) != null ? _a2 : venueHistory.length === 1 ? venueHistory[0] : void 0;
6001
- if (!matchingHistory)
6002
- return;
6003
- const points = matchingHistory.points.map((point) => ({
6004
- time: point.timestamp,
6005
- value: point.price * 100,
6006
- open: point.open == null ? void 0 : point.open * 100,
6007
- high: point.high == null ? void 0 : point.high * 100,
6008
- low: point.low == null ? void 0 : point.low * 100,
6009
- close: point.close == null ? void 0 : point.close * 100
6010
- })).filter((point) => Number.isFinite(point.time) && Number.isFinite(point.value));
6011
- if (points.length === 0)
6012
- return;
6013
- graphSeries2.push({
6014
- id: `${headerOutcomeItem.label}-${outcomeByVenue.venue}-${matchingHistory.marketId}`,
6015
- venue: outcomeByVenue.venue,
6016
- color: resolveSeriesColor(outcomeByVenue.venue, index),
6017
- points
6018
- });
6019
- });
6020
- seriesByOutcomeLabel.set(headerOutcomeItem.label, graphSeries2);
6021
- });
6022
- return seriesByOutcomeLabel;
6023
- }, [canonicalMarketIdForHistory, headerOutcomeItems, outcomesByLabel, priceHistoryByVenue]);
6024
6060
  const graphSeries = (0, import_react9.useMemo)(() => {
6025
- var _a;
6026
- if (!selectedOutcomeLabel)
6027
- return [];
6028
- const seriesForOutcomeLabel = (_a = graphSeriesByOutcomeLabel.get(selectedOutcomeLabel)) != null ? _a : [];
6061
+ const colorByVenue = new Map(
6062
+ selectedOutcomesByVenue.map((item, index) => [
6063
+ item.venue,
6064
+ resolveSeriesColor(item.venue, index)
6065
+ ])
6066
+ );
6067
+ const seriesForOutcomeLabel = resolveMarketChartVenueSeries({
6068
+ chartData: marketChartData,
6069
+ transformProbability: (value) => value
6070
+ }).map((seriesItem) => {
6071
+ var _a2;
6072
+ const resolvedVenue = seriesItem.venue;
6073
+ return {
6074
+ id: `${selectedOutcomeLabel != null ? selectedOutcomeLabel : "graph"}-${resolvedVenue}-${primaryVenueMarketId != null ? primaryVenueMarketId : "chart"}`,
6075
+ venue: resolvedVenue,
6076
+ color: (_a2 = colorByVenue.get(resolvedVenue)) != null ? _a2 : resolveSeriesColor(resolvedVenue, 0),
6077
+ points: seriesItem.points
6078
+ };
6079
+ });
6029
6080
  if (!selectedGraphVenue)
6030
6081
  return seriesForOutcomeLabel;
6031
6082
  return seriesForOutcomeLabel.filter((seriesItem) => seriesItem.venue === selectedGraphVenue);
6032
- }, [graphSeriesByOutcomeLabel, selectedGraphVenue, selectedOutcomeLabel]);
6083
+ }, [
6084
+ primaryVenueMarketId,
6085
+ marketChartData,
6086
+ selectedGraphVenue,
6087
+ selectedOutcomeLabel,
6088
+ selectedOutcomesByVenue
6089
+ ]);
6090
+ const graphLiveState = (0, import_react9.useMemo)(() => {
6091
+ return resolveMarketChartLiveState({
6092
+ chartData: marketChartData,
6093
+ selectedVenue: selectedGraphVenue,
6094
+ transformProbability: (value) => value
6095
+ });
6096
+ }, [marketChartData, selectedGraphVenue]);
6033
6097
  const otherRows = (0, import_react9.useMemo)(() => {
6034
6098
  if (!model)
6035
6099
  return [];
@@ -6037,9 +6101,10 @@ var MarketDetailsContent = ({
6037
6101
  }, [labels, model]);
6038
6102
  const isOrderBookNotFound = orderBookError && typeof orderBookError === "object" && "status" in orderBookError && orderBookError.status === 404;
6039
6103
  const hasOrderBookError = !!orderBookError && !isOrderBookNotFound;
6040
- const hasNoOrderBook = isOrderBookNotFound || !isOrderBookLoading && !hasOrderBookError && (orderBookInputs.length === 0 || askRows.length === 0 && bidRows.length === 0);
6104
+ const hasNoOrderBook = isOrderBookNotFound || !isOrderBookLoading && !hasOrderBookError && (selectedOutcomesByVenue.length === 0 || askRows.length === 0 && bidRows.length === 0);
6105
+ const hasChartError = !!marketChartError;
6041
6106
  const handleOutcomeKeyDown = (eventToHandle) => {
6042
- var _a;
6107
+ var _a2;
6043
6108
  if ((eventToHandle == null ? void 0 : eventToHandle.key) !== "ArrowLeft" && (eventToHandle == null ? void 0 : eventToHandle.key) !== "ArrowRight") {
6044
6109
  return;
6045
6110
  }
@@ -6050,14 +6115,14 @@ var MarketDetailsContent = ({
6050
6115
  });
6051
6116
  const direction = eventToHandle.key === "ArrowRight" ? 1 : -1;
6052
6117
  const nextIndex = activeIndex < 0 ? 0 : (activeIndex + direction + headerOutcomeItems.length) % headerOutcomeItems.length;
6053
- setSelectedOutcomeLabel((_a = headerOutcomeItems[nextIndex]) == null ? void 0 : _a.label);
6118
+ setSelectedOutcomeLabel((_a2 = headerOutcomeItems[nextIndex]) == null ? void 0 : _a2.label);
6054
6119
  };
6055
- const handleToggleExpanded = (event2) => {
6056
- if (event2 && "key" in event2 && (event2 == null ? void 0 : event2.key) !== "Enter" && (event2 == null ? void 0 : event2.key) !== " ") {
6120
+ const handleToggleExpanded = (event) => {
6121
+ if (event && "key" in event && (event == null ? void 0 : event.key) !== "Enter" && (event == null ? void 0 : event.key) !== " ") {
6057
6122
  return;
6058
6123
  }
6059
- event2 == null ? void 0 : event2.preventDefault();
6060
- event2 == null ? void 0 : event2.stopPropagation();
6124
+ event == null ? void 0 : event.preventDefault();
6125
+ event == null ? void 0 : event.stopPropagation();
6061
6126
  setIsOpened((prev) => {
6062
6127
  const next = !prev;
6063
6128
  onOpenChange == null ? void 0 : onOpenChange(next);
@@ -6072,7 +6137,10 @@ var MarketDetailsContent = ({
6072
6137
  });
6073
6138
  };
6074
6139
  const handleRetryOrderBook = () => {
6075
- void Promise.all(orderBookResults.map((result) => result.refetch()));
6140
+ void refetchOrderBook();
6141
+ };
6142
+ const handleRetryMarketChart = () => {
6143
+ void refetchMarketChart();
6076
6144
  };
6077
6145
  (0, import_react9.useEffect)(() => {
6078
6146
  if (!selectedGraphVenue) {
@@ -6115,7 +6183,7 @@ var MarketDetailsContent = ({
6115
6183
  onClick: handleToggleExpanded,
6116
6184
  onKeyDown: handleToggleExpanded,
6117
6185
  children: [
6118
- /* @__PURE__ */ (0, import_jsx_runtime79.jsxs)("div", { className: "flex min-w-52 items-center gap-3 md:gap-4", children: [
6186
+ /* @__PURE__ */ (0, import_jsx_runtime79.jsxs)("div", { className: "flex min-w-52 max-w-3/4 items-center gap-3 md:gap-4", children: [
6119
6187
  model.image ? /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(
6120
6188
  RemoteImage,
6121
6189
  {
@@ -6162,7 +6230,7 @@ var MarketDetailsContent = ({
6162
6230
  /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(
6163
6231
  VenueLogo,
6164
6232
  {
6165
- venue: isPositive ? "polymarket" : "probable",
6233
+ venue: "polymarket",
6166
6234
  size: "small",
6167
6235
  color: isActiveOutcome ? "var(--agg-color-on-primary)" : void 0
6168
6236
  }
@@ -6269,13 +6337,26 @@ var MarketDetailsContent = ({
6269
6337
  )
6270
6338
  ] }) }) : null,
6271
6339
  selectedTab === "graph" ? /* @__PURE__ */ (0, import_jsx_runtime79.jsxs)("div", { className: cn("flex flex-col gap-5", classNames == null ? void 0 : classNames.graph), children: [
6272
- /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(
6340
+ hasChartError ? /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(
6341
+ StateMessage,
6342
+ {
6343
+ ariaLabel: labels.marketDetails.chartUnavailableAria,
6344
+ tone: "warning",
6345
+ title: labels.marketDetails.chartUnavailableTitle,
6346
+ description: labels.marketDetails.chartUnavailableDescription,
6347
+ actionLabel: labels.common.retry,
6348
+ onAction: handleRetryMarketChart,
6349
+ className: "min-h-[248px] px-5 py-10 md:min-h-[272px]"
6350
+ }
6351
+ ) : /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(
6273
6352
  LineChart,
6274
6353
  {
6275
6354
  series: graphSeries,
6276
6355
  height: 260,
6277
- isLoading: isPriceHistoryLoading,
6356
+ isLoading: isMarketChartLoading,
6278
6357
  chartType: selectedChartType,
6358
+ liveCandle: selectedChartType === "candlestick" ? (_d = graphLiveState.liveCandle) != null ? _d : void 0 : void 0,
6359
+ lineValue: graphLiveState.lineValue,
6279
6360
  classNames: { root: "w-full" },
6280
6361
  showSeriesControls: selectedOutcomesByVenue.length > 0 || headerOutcomeItems.length > 0,
6281
6362
  renderSeriesControls: () => {
@@ -6399,7 +6480,7 @@ var MarketDetailsContent = ({
6399
6480
  );
6400
6481
  };
6401
6482
  var MarketDetails = (props) => {
6402
- var _a, _b;
6483
+ var _a;
6403
6484
  const [uncontrolledIsOpened, setUncontrolledIsOpened] = (0, import_react9.useState)(
6404
6485
  (_a = props.defaultIsOpened) != null ? _a : marketDetailsDefaultIsOpened
6405
6486
  );
@@ -6416,15 +6497,6 @@ var MarketDetails = (props) => {
6416
6497
  }
6417
6498
  (_a2 = props.onOpenChange) == null ? void 0 : _a2.call(props, nextIsOpened);
6418
6499
  };
6419
- const hasEventProp = "event" in props && !!props.event;
6420
- const {
6421
- event: fetchedEvent,
6422
- error: eventError,
6423
- isLoading: isFetchingEvent
6424
- } = (0, import_hooks18.useVenueEvent)({
6425
- eventId: hasEventProp ? "" : (_b = props.eventId) != null ? _b : "",
6426
- enabled: !props.isLoading && !hasEventProp && !!props.eventId
6427
- });
6428
6500
  if (props.isLoading) {
6429
6501
  return /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(
6430
6502
  MarketDetailsLoadingState,
@@ -6435,42 +6507,115 @@ var MarketDetails = (props) => {
6435
6507
  }
6436
6508
  );
6437
6509
  }
6438
- if ("event" in props && props.event) {
6510
+ if ("venueMarkets" in props && props.venueMarkets) {
6439
6511
  return /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(
6440
6512
  MarketDetailsContent,
6441
6513
  __spreadProps(__spreadValues({}, props), {
6442
6514
  isOpened: resolvedIsOpened,
6443
6515
  onOpenChange: handleOpenChange,
6444
- event: props.event
6516
+ venueMarkets: props.venueMarkets
6445
6517
  })
6446
6518
  );
6447
6519
  }
6448
- if (isFetchingEvent) {
6449
- return /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(
6450
- MarketDetailsLoadingState,
6520
+ const { ariaLabel: fallbackAriaLabel, classNames: fallbackClassNames } = props;
6521
+ return /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(MarketDetailsUnavailableState, { ariaLabel: fallbackAriaLabel, classNames: fallbackClassNames });
6522
+ };
6523
+ MarketDetails.displayName = "MarketDetails";
6524
+ var resolveInitialExpandedId = (markets, defaultId) => {
6525
+ var _a, _b;
6526
+ if (!markets.length)
6527
+ return null;
6528
+ if (defaultId) {
6529
+ const match = markets.find((m) => m.id === defaultId);
6530
+ if (match)
6531
+ return match.id;
6532
+ }
6533
+ return (_b = (_a = markets[0]) == null ? void 0 : _a.id) != null ? _b : null;
6534
+ };
6535
+ var MarketDetailsList = ({
6536
+ eventId,
6537
+ expandedMarketId,
6538
+ defaultExpandedMarketId,
6539
+ onExpandedMarketChange,
6540
+ defaultTab,
6541
+ defaultTimeRange,
6542
+ classNames,
6543
+ ariaLabel
6544
+ }) => {
6545
+ const labels = (0, import_hooks18.useLabels)();
6546
+ const resolvedEventId = eventId || "";
6547
+ const { markets, isLoading, error } = (0, import_hooks18.useVenueMarkets)({
6548
+ venueEventId: resolvedEventId,
6549
+ enabled: !!resolvedEventId
6550
+ });
6551
+ const [internalExpandedId, setInternalExpandedId] = (0, import_react9.useState)(
6552
+ () => resolveInitialExpandedId(markets, defaultExpandedMarketId)
6553
+ );
6554
+ (0, import_react9.useEffect)(() => {
6555
+ if (typeof expandedMarketId !== "undefined")
6556
+ return;
6557
+ setInternalExpandedId((current) => {
6558
+ if (current && markets.some((m) => m.id === current))
6559
+ return current;
6560
+ return resolveInitialExpandedId(markets, defaultExpandedMarketId);
6561
+ });
6562
+ }, [defaultExpandedMarketId, expandedMarketId, markets]);
6563
+ (0, import_react9.useEffect)(() => {
6564
+ if (typeof expandedMarketId === "undefined")
6565
+ return;
6566
+ setInternalExpandedId(expandedMarketId);
6567
+ }, [expandedMarketId]);
6568
+ const resolvedExpandedId = typeof expandedMarketId === "undefined" ? internalExpandedId : expandedMarketId;
6569
+ const handleToggle = (marketId, isOpened) => {
6570
+ const next = isOpened ? marketId : null;
6571
+ if (typeof expandedMarketId === "undefined") {
6572
+ setInternalExpandedId(next);
6573
+ }
6574
+ onExpandedMarketChange == null ? void 0 : onExpandedMarketChange(next);
6575
+ };
6576
+ if (isLoading) {
6577
+ return /* @__PURE__ */ (0, import_jsx_runtime79.jsxs)("div", { className: cn("flex flex-col gap-3", classNames == null ? void 0 : classNames.root), "aria-label": ariaLabel, children: [
6578
+ /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(MarketDetailsLoadingState, { isOpened: true, classNames: { root: classNames == null ? void 0 : classNames.item } }),
6579
+ /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(MarketDetailsLoadingState, { isOpened: false, classNames: { root: classNames == null ? void 0 : classNames.item } })
6580
+ ] });
6581
+ }
6582
+ if (error) {
6583
+ return /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(Card, { className: cn(marketDetailsBaseCardClassName, "p-0", classNames == null ? void 0 : classNames.root), children: /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(
6584
+ StateMessage,
6451
6585
  {
6452
- isOpened: resolvedIsOpened,
6453
- ariaLabel: props.ariaLabel,
6454
- classNames: props.classNames
6586
+ ariaLabel: ariaLabel != null ? ariaLabel : labels.marketDetails.unavailableAria,
6587
+ title: labels.marketDetails.unavailableTitle,
6588
+ description: labels.marketDetails.unavailableDescription,
6589
+ className: "min-h-[280px] md:min-h-[320px]"
6455
6590
  }
6456
- );
6591
+ ) });
6457
6592
  }
6458
- if (!fetchedEvent) {
6459
- if (isErrorWithStatus(eventError, 404)) {
6460
- return /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(MarketDetailsNotFoundState, { ariaLabel: props.ariaLabel, classNames: props.classNames });
6461
- }
6462
- return /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(MarketDetailsUnavailableState, { ariaLabel: props.ariaLabel, classNames: props.classNames });
6593
+ if (markets.length === 0) {
6594
+ return /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(Card, { className: cn(marketDetailsBaseCardClassName, "p-0", classNames == null ? void 0 : classNames.root), children: /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(
6595
+ StateMessage,
6596
+ {
6597
+ ariaLabel: ariaLabel != null ? ariaLabel : labels.marketDetails.notFoundAria,
6598
+ title: labels.marketDetails.notFoundTitle,
6599
+ description: labels.marketDetails.notFoundDescription,
6600
+ className: "min-h-[280px] md:min-h-[320px]"
6601
+ }
6602
+ ) });
6463
6603
  }
6464
- return /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(
6465
- MarketDetailsContent,
6466
- __spreadProps(__spreadValues({}, props), {
6467
- isOpened: resolvedIsOpened,
6468
- onOpenChange: handleOpenChange,
6469
- event: fetchedEvent
6470
- })
6471
- );
6604
+ return /* @__PURE__ */ (0, import_jsx_runtime79.jsx)("div", { className: cn("flex flex-col gap-3", classNames == null ? void 0 : classNames.root), "aria-label": ariaLabel, children: markets.map((market) => /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(
6605
+ MarketDetails,
6606
+ {
6607
+ venueMarkets: [market],
6608
+ isOpened: resolvedExpandedId === market.id,
6609
+ onOpenChange: (nextIsOpened) => handleToggle(market.id, nextIsOpened),
6610
+ defaultTab,
6611
+ defaultTimeRange,
6612
+ ariaLabel: market.question,
6613
+ classNames: { root: classNames == null ? void 0 : classNames.item }
6614
+ },
6615
+ market.id
6616
+ )) });
6472
6617
  };
6473
- MarketDetails.displayName = "MarketDetails";
6618
+ MarketDetailsList.displayName = "MarketDetailsList";
6474
6619
 
6475
6620
  // src/events/list/index.tsx
6476
6621
  var import_react10 = require("react");
@@ -6569,11 +6714,11 @@ var estimateTabsWidth = (items) => {
6569
6714
  var EventList = ({
6570
6715
  title,
6571
6716
  maxItemsPerRow = 3,
6572
- limit = 3,
6717
+ limit = 9,
6573
6718
  maxVisibleItems,
6574
- showVenueLogo = true,
6575
6719
  search,
6576
- categoryIds
6720
+ categoryIds,
6721
+ onClick
6577
6722
  }) => {
6578
6723
  var _a, _b;
6579
6724
  const labels = (0, import_hooks19.useLabels)();
@@ -6728,10 +6873,10 @@ var EventList = ({
6728
6873
  EventListItem,
6729
6874
  {
6730
6875
  event,
6731
- showVenueLogo,
6732
6876
  classNames: {
6733
6877
  root: "w-full min-w-0 max-w-none"
6734
- }
6878
+ },
6879
+ onClick
6735
6880
  },
6736
6881
  event.id
6737
6882
  )),
@@ -6772,5 +6917,6 @@ EventList.displayName = "EventList";
6772
6917
  EventList,
6773
6918
  EventListItem,
6774
6919
  EventListItemDetails,
6775
- MarketDetails
6920
+ MarketDetails,
6921
+ MarketDetailsList
6776
6922
  });