import type { EventTradingState, UseMidpointsResult, VenueMarket } from "@agg-build/hooks";
import type React from "react";
import type { VenueLogoName } from "../../primitives/venue-logo/venue-logo.types";
export type MarketDetailsTab = "order-book" | "graph" | "other";
export type MarketDetailsClassNames = Partial<{
    root: string;
    header: string;
    tabs: string;
    content: string;
    orderBook: string;
    graph: string;
    footer: string;
}>;
export type MarketDetailsBaseProps = {
    /** Market ID used to fetch or match the active market details. */
    marketId?: string;
    /** Title shown in the market details header. */
    title?: string;
    /** Optional image shown alongside the market header content. */
    image?: string | null;
    /** Whether the accordion item should start opened. */
    defaultIsOpened?: boolean;
    /** Controlled open state for the market details accordion item. */
    isOpened?: boolean;
    /** Called when the market details accordion is opened. */
    onOpenChange?: (marketId: string) => void;
    /** Called when the market details surface is clicked. */
    onClick?: (market?: VenueMarket) => void;
    /** Called when a user explicitly selects an outcome from this market header. */
    onOutcomeSelect?: (selection: {
        marketId: string;
        outcomeId: string;
    }) => void;
    /** Default tab shown when the details open. */
    defaultTab?: MarketDetailsTab;
    /** Default outcome label used for order book and graph context. */
    defaultOutcomeLabel?: string;
    /** Number of order book rows to show per side. */
    orderBookDepth?: number;
    /** Accessible label applied to the market details surface. */
    ariaLabel?: string;
    /** Class name overrides for market details layout slots. */
    classNames?: MarketDetailsClassNames;
    /** Custom content rendered in the "other" tab. */
    otherContent?: React.ReactNode;
    /**
     * Optional content rendered between the card header (title + outcome pills)
     * and the collapsible details body — visible whether or not the card is
     * expanded. Used by the sports view to mount a spread/total line-selector
     * rail on the same card that drives the order book / graph. Regular event
     * markets omit it, so their layout is unchanged.
     */
    headerAccessory?: React.ReactNode;
    /**
     * Compact header treatment used by the sports view: hides the leading market
     * thumbnail and the headline probability so the card reads as
     * "{title} · {meta}" + outcome pills (matching the sports design). Defaults
     * to `false`, so regular event markets keep the image + headline.
     */
    compactHeader?: boolean;
    /**
     * Optional subtitle override for custom surfaces (for example the sports
     * compact header, which needs selected-option venue / volume metadata).
     */
    subtitleOverride?: string;
    /**
     * Optional header pill layout override. Sports cards use this to keep the
     * market-specific sizing and line-label treatment isolated from the default
     * market details header.
     */
    headerOutcomeVariant?: "outcome" | "line" | "yes_no";
    /** Optional prebuilt header pills used when the card should render a custom
     * market selection surface while keeping the regular details body. */
    headerOutcomeItemsOverride?: MarketDetailsHeaderOutcomeItem[];
    /** Whether the market details should render a loading state. */
    isLoading?: boolean;
    /**
     * When true, if a global selected outcome does not belong to this card,
     * do not fall back to a local default outcome for selected-state rendering.
     */
    suppressOutcomeFallbackSelection?: boolean;
    /** Override live WS subscriptions for chart and orderbook hooks.
     *  Set to `false` when a parent component already manages subscriptions
     *  (e.g. useEventOrderbookData on the event page).
     *  Defaults to the global `enableLiveUpdates` feature flag. */
    live?: boolean;
};
export type MarketDetailsLoadingProps = MarketDetailsBaseProps & {
    /** Forces the market details component into its loading state. */
    isLoading: true;
    /** Prevents passing prefetched markets while loading. */
    venueMarkets?: never;
    /** Legacy event prop is not supported in loading mode. */
    event?: never;
    /** Optional event ID used to fetch market details while loading. */
    eventId?: string;
};
export type MarketDetailsWithMarketsProps = MarketDetailsBaseProps & {
    /** Venue markets to display. Replaces the old event-based data source. */
    venueMarkets: VenueMarket[];
    /** Legacy event prop is intentionally unsupported. */
    event?: never;
    /** Prevents mixing prefetched markets with event ID fetching. */
    eventId?: never;
    /** Marks the market details component as loaded. */
    isLoading?: false;
    /**
     * Optional REST midpoints keyed by outcome id. Used as a fallback when the
     * live (WebSocket) cache has no data for an outcome — typically because the
     * card is not the selected market and therefore isn't on the WS feed.
     */
    midpointsFallback?: Map<string, number>;
    /**
     * Venue name for each outcome id in `midpointsFallback`. When a matched venue
     * offered a lower YES price, this records that venue so the outcome button
     * shows the correct logo alongside the best price.
     */
    midpointsFallbackVenues?: Map<string, string>;
    /**
     * Pre-fetched midpoint data (best price included) passed from parent.
     * Optional for backward compatibility. When provided, reduces unnecessary
     * redundant API calls for midpoint data.
     */
    midpointsResult?: UseMidpointsResult;
};
export type MarketDetailsProps = MarketDetailsLoadingProps | MarketDetailsWithMarketsProps;
export type MarketDetailsContentProps = MarketDetailsBaseProps & {
    /** Prefetched venue markets rendered by the content component. */
    venueMarkets: VenueMarket[];
    /** See MarketDetailsWithMarketsProps.midpointsFallback. */
    midpointsFallback?: Map<string, number>;
    /** See MarketDetailsWithMarketsProps.midpointsFallbackVenues. */
    midpointsFallbackVenues?: Map<string, string>;
    /** See MarketDetailsWithMarketsProps.midpointsResult. */
    midpointsResult?: UseMidpointsResult;
};
export type MarketDetailsListClassNames = Partial<{
    root: string;
    item: string;
}>;
export type MarketDetailsListProps = {
    /** Venue event ID to fetch all markets for. */
    eventId?: string;
    /** Prefetched markets to render instead of fetching by event ID. */
    markets?: VenueMarket[];
    /** Shared event-level trading state passed from the page when already derived. */
    eventTradingState?: EventTradingState;
    /** Called when the expanded market changes. */
    onExpandedMarketChange?: (marketId: string | null) => void;
    /** Called when a market is clicked. */
    onClick?: (market: VenueMarket) => void;
    /** Called when a user explicitly selects an outcome from any market card. */
    onOutcomeSelect?: (selection: {
        marketId: string;
        outcomeId: string;
    }) => void;
    /** Whether selected market changes should expand the matching accordion item. */
    expandSelectedMarketOnChange?: boolean;
    /** Whether fallback market selection should expand a card when none is expanded. */
    autoExpandFallbackMarket?: boolean;
    /** Whether the list should auto-select a fallback market when none is selected. */
    autoSelectFallbackMarket?: boolean;
    /** Default tab to display. */
    defaultTab?: MarketDetailsTab;
    /** Class names for the market details list. */
    classNames?: MarketDetailsListClassNames;
    /** Override live WS subscriptions for child MarketDetails.
     *  Set to `false` when a parent manages subscriptions centrally. */
    live?: boolean;
    /**
     * Pre-fetched midpoint data (best price included) passed from parent.
     * Optional for backward compatibility. When provided, reduces unnecessary
     * redundant API calls for midpoint data.
     */
    midpointsResult?: UseMidpointsResult;
};
export type MarketDetailsOrderBookTone = "positive" | "negative";
export type MarketDetailsOutcomeTone = MarketDetailsOrderBookTone;
export type MarketDetailsHeaderOutcomeItem = {
    id: string;
    label: string;
    title?: string | null;
    probability: number | undefined;
    isPriceLoading?: boolean;
    tone: MarketDetailsOutcomeTone;
    venue: VenueLogoName;
    variant?: "outcome" | "line" | "yes_no";
    lineLabel?: string | null;
};
export type MarketDetailsOrderBookRow = {
    id: string;
    venues: VenueLogoName[];
    price: number;
    size: number;
    total: number;
    tone: MarketDetailsOrderBookTone;
    barScale: number;
    venueBreakdown?: Partial<Record<VenueLogoName, number>>;
    sourceOutcomeIds?: string[];
};
export type MarketDetailsMetaRow = {
    label: string;
    value: string;
};
export type UnifiedOrderBookEntry = {
    kind: "ask";
    row: MarketDetailsOrderBookRow;
    cumulativeDepth: number;
    unifiedBarScale: number;
} | {
    kind: "bid";
    row: MarketDetailsOrderBookRow;
    cumulativeDepth: number;
    unifiedBarScale: number;
} | {
    kind: "spread";
    midPrice: number | null;
    spread: number | null;
};
