import type { AggUiLabels, DagStepProgress, EventTradingState, UseMidpointsResult, VenueMarket, VenueMarketOutcome } from "@agg-build/hooks";
import type { ExecutionMode, SmartRouteResponse } from "@agg-build/sdk";
import type { PlaceOrderRoutingRow, PlaceOrderStatus, PlaceOrderTab, TradingVenue } from "../types";
export type PlaceOrderProps = {
    /** Custom class name applied to the place-order root. */
    className?: string;
    /** Custom class name applied to the place-order elements. */
    classNames?: PlaceOrderClassNames;
    /** Trading state used to drive markets, balances, and quotes. */
    eventTradingState?: EventTradingState;
    /** Trading mode used by normal execution endpoints. Defaults to live. */
    executionMode?: ExecutionMode;
    /** Whether the place-order panel should render its loading state. */
    isLoading?: boolean;
    /** Whether the primary submit action should be disabled. */
    isPrimaryActionDisabled?: boolean;
    /** Whether the primary submit action should show a loading spinner. */
    isPrimaryActionLoading?: boolean;
    /**
     * Whether this place-order instance is the active, visible quote surface.
     * Hidden or closed surfaces should pass false so quote polling can pause.
     * Defaults to true.
     */
    isQuotePanelActive?: boolean;
    /** Called when the entered order amount changes. */
    onAmountChange?: (amount: number) => void;
    /** Called when the place-order panel should close. */
    onClose?: () => void;
    /** Called when the selected outcome changes. */
    onOutcomeChange?: (outcomeId: string) => void;
    /**
     * Called when the primary action is triggered, in place of the internal
     * quote execution. When provided, the component delegates the fill entirely
     * to this callback and does NOT run its own execution. For a pre-flight gate
     * that should run *before* the normal fill (and let it proceed), use
     * `onBeforePrimaryAction` instead.
     */
    onPrimaryAction?: (context?: {
        quoteId?: string;
        mode?: ExecutionMode;
    }) => void;
    /**
     * Called when the primary action is triggered, BEFORE the internal quote
     * execution. Unlike `onPrimaryAction`, this does not replace the fill — it
     * runs in between and, when it resolves, the order is filled as usual. Use it
     * for a partner gate such as a verification/KYC modal that must complete
     * before the order goes through.
     *
     * The returned promise is awaited before execution proceeds:
     * - resolve (return `undefined`/`true`) → continue with the normal fill
     * - return `false` → cancel silently; the panel returns to idle
     * - throw → abort and surface the error as submission feedback
     */
    onBeforePrimaryAction?: (context?: {
        quoteId?: string;
        mode?: ExecutionMode;
    }) => void | boolean | Promise<void | boolean>;
    /** Called when the slippage control value changes. */
    onSlippageChange?: (value: string) => void;
    /** Called when the active trade tab changes. */
    onTabChange?: (tab: PlaceOrderTab) => void;
    /** Optional chain balance overrides keyed by chain ID. */
    chainBalancesOverride?: Record<string, number>;
    /** Called when order execution completes successfully. */
    onSuccess?: (summary: PlaceOrderExecutionSummary) => void;
    /** Called when order execution fails. */
    onError?: (error: Error) => void;
    /** Called on each execution phase transition (finding-route → submitting → executing → success → failed). */
    onExecutionStateChange?: (state: PlaceOrderSubmissionProgressState) => void;
    /** Optional resolved-event claim summary shown in read-only state. */
    resolvedClaim?: PlaceOrderResolvedClaimSummary;
    /** Pre-fetched midpoint data (best price included) passed from parent. Optional for backward compatibility. */
    midpointsResult?: UseMidpointsResult;
};
export type PlaceOrderResolvedClaimSummary = {
    /** Resolution date label, e.g. "Mar 21, 2026". */
    resolutionDateLabel: string;
    /** Winning outcome label, e.g. "Yes". */
    winningOutcomeLabel: string;
    /** Shares label, e.g. "286 Yes". */
    sharesLabel: string;
    /** Total payout label, e.g. "$8.50". */
    totalPayoutLabel: string;
    /** Whether the claim action is currently in-flight. */
    isClaiming?: boolean;
    /** Optional claim action for eligible winnings. */
    onClaim?: () => void;
};
export type PlaceOrderClassNames = {
    root?: string;
    body?: string;
    header?: string;
    content?: string;
    footer?: string;
};
export type PlaceOrderSlippageControlProps = {
    /** Default slippage value shown when the control initializes. */
    defaultValue: string;
    /** Whether the control should animate state changes. */
    enableAnimations: boolean;
    /** Minimum allowed slippage percentage. */
    minimumValue: number;
    /** Called when the slippage value changes. */
    onChange?: (value: string) => void;
    /** Controlled slippage value. */
    value: string;
};
export type PlaceOrderRouteCardKind = "split" | "venue";
export type PlaceOrderRouteCard = {
    id: string;
    hint: string;
    kind: PlaceOrderRouteCardKind;
    label: string;
    numericValue: number;
    quoteData: SmartRouteResponse;
    rows?: PlaceOrderRoutingRow[];
    value: string;
    venue?: TradingVenue;
    /** Whether the venue is unavailable in the user's region (geo-blocked). */
    isUnavailable?: boolean;
};
export type PlaceOrderOutcomeClassNameParams = {
    enableAnimations: boolean;
    isActive: boolean;
    isPositive: boolean;
};
export type PlaceOrderOutcomeLabelValue = Pick<VenueMarketOutcome, "id" | "label" | "title">;
export type PlaceOrderVenueOutcome = Pick<VenueMarketOutcome, "id" | "label" | "price"> & {
    title?: string | null;
};
export type PlaceOrderVenueQuote = {
    price: number;
    venue: TradingVenue;
    venueMarketId: string;
    venueMarketOutcomeId: string;
};
export type PlaceOrderResultTone = "default" | "success";
export type PlaceOrderQuoteResult = {
    hint: string;
    value: string;
};
export type PlaceOrderTradingLabels = AggUiLabels["trading"];
export type PlaceOrderExecutionStep = {
    id: string;
    label: string;
    tone?: "complete" | "warning" | "error";
    venue?: TradingVenue;
};
export type PlaceOrderExecutionStepGroup = PlaceOrderExecutionStep[];
export type PlaceOrderTerminalOrderEvent = {
    orderId: string;
    venue: string;
    event: "filled" | "partial_fill" | "failed";
    filledAmountRaw?: string;
    remainingAmountRaw?: string;
    /** Actual shares + payout received, 6-decimal atomic. Populated by the
     * venue's finalize handler on filled/partial_fill and used to override
     * the stale quote estimate in the execution summary. */
    actualSharesRaw?: string;
    actualToWinRaw?: string;
    /** Quote-time shares + payout, 6-decimal atomic. */
    quotedSharesRaw?: string;
    quotedToWinRaw?: string;
    /** Avg execution price as a numeric string (e.g. "0.087"). */
    executionPriceRaw?: string;
    quotedPriceRaw?: string;
    errorReason?: string;
    timestamp: number;
};
export type PlaceOrderFailureStepTone = "complete" | "warning" | "error";
export type PlaceOrderFailureStep = {
    id: string;
    label: string;
    tone: PlaceOrderFailureStepTone;
    venue?: TradingVenue;
};
export type PlaceOrderFailureAction = {
    id: string;
    label: string;
    variant: "retry" | "dismiss" | "continue" | "skip";
};
export type PlaceOrderFailureKind = "partial_fill" | "venue_unavailable" | "market_resolved" | "generic";
export type PlaceOrderFailureSummary = {
    actionLabel: string;
    actions: PlaceOrderFailureAction[];
    errorMessage?: string;
    eventImage?: string | null;
    eventSubtitle?: string;
    eventTitle: string;
    kind: PlaceOrderFailureKind;
    steps: PlaceOrderFailureStep[];
};
export type ResolvePlaceOrderQuoteResultParams = {
    labels: PlaceOrderTradingLabels;
    quoteData: SmartRouteResponse | null;
    tradeSide: PlaceOrderTab;
};
export type BuildLiveRouteCardsParams = {
    labels: PlaceOrderTradingLabels;
    quoteData: SmartRouteResponse;
    tradeSide: PlaceOrderTab;
    eventVenues?: TradingVenue[];
};
export type ResolvePlaceOrderQuoteStatusParams = {
    amount: number;
    labels: PlaceOrderTradingLabels;
    quoteData: SmartRouteResponse | null;
    selectedMarket: VenueMarket | null;
};
export type ResolvePlaceOrderTabKeyParams = {
    currentTab: PlaceOrderTab;
    key: string;
};
export type PlaceOrderQuoteStatus = PlaceOrderStatus | undefined;
export type PlaceOrderSubmissionProgressPhase = "finding-route" | "submitting" | "executing" | "success" | "failed";
export type PlaceOrderExecutionSummary = {
    tradeSide?: PlaceOrderTab;
    shares: string;
    avgPrice: string;
    estimatedCost: string;
    venue?: string;
    eventTitle?: string;
    eventDateLabel?: string;
    eventImage?: string | null;
    actionLabel?: string;
    amountLabel?: string;
    toWinLabel?: string;
    potentialReturnLabel?: string;
    executionStepGroups?: PlaceOrderExecutionStepGroup[];
    shareText?: string;
};
export type PlaceOrderSubmissionProgressState = {
    errorMessage?: string;
    executionVenue?: TradingVenue;
    failureSummary?: PlaceOrderFailureSummary;
    orderId?: string;
    orderIds?: string[];
    quoteId?: string;
    phase: PlaceOrderSubmissionProgressPhase;
    summary?: PlaceOrderExecutionSummary;
    dagProgress?: DagStepProgress | null;
};
