import type { VenueLogoName } from "../../primitives/venue-logo/venue-logo.types";
import type { UserProfileTabValue } from "./user-profile.constants";
export interface UserProfileSocialLink {
    platform: "twitter" | "discord" | "telegram";
    handle?: string;
}
export interface UserProfileConnectedExchange {
    venue: VenueLogoName;
}
export interface UserProfileConnectedWallet {
    /** Chain identifier, e.g. "evm" or "solana" */
    chain: string;
    /** Shortened wallet address, e.g. "0xec57...f8460" */
    displayAddress: string;
}
export interface UserProfileInfo {
    /** Display name */
    username: string;
    /** Avatar image URL; falls back to default SVG when absent */
    avatarUrl?: string | null;
    /** Social handles shown as icons beside the username */
    socialLinks?: UserProfileSocialLink[];
    /** Connected exchanges displayed as overlapping venue logos */
    connectedExchanges?: UserProfileConnectedExchange[];
    /** Connected wallets with chain icons (Ethereum for EVM, Solana for Solana) */
    connectedWallets?: UserProfileConnectedWallet[];
    /** Shortened wallet address displayed next to exchange logos, e.g. "0x82b1E...CeDB0" */
    displayAddress?: string;
    /** Primary social handle displayed in connected accounts section, e.g. "CryptoPapay" */
    socialHandle?: string;
    /** Venue logo displayed next to the socialHandle */
    socialHandleVenue?: VenueLogoName;
}
export interface UserProfileVenueBalance {
    chain: string;
    accountCount?: number;
    /** Balance formatted as a string, e.g. "$1,234.56" */
    balanceLabel: string;
}
export interface UserProfileBalance {
    /** Formatted total value, e.g. "$103,456.00" */
    totalLabel: string;
    /** Formatted change value, e.g. "+$1,234.56" (deprecated; optional) */
    changeLabel?: string;
    /** Formatted change percentage, e.g. "+12.3%" (deprecated; optional) */
    changePercentLabel?: string;
    /** True when the change is positive (green), false when negative (deprecated; optional) */
    isPositive?: boolean;
}
/** One venue line under the outcome pill (API `venueBreakdown` entry). */
export interface UserProfilePositionVenueShare {
    venue: VenueLogoName;
    /** Localized shares string, e.g. "103.4 shares" */
    sharesLabel: string;
}
export interface UserProfilePosition {
    id: string;
    /** Event ID used for deep-link navigation to event details. */
    eventId?: string;
    /** Market ID used to preselect a market on the event details page. */
    marketId?: string;
    /** Market thumbnail image URL */
    thumbnailSrc: string;
    /** Market title */
    title: string;
    /** Outcome name for the pill only, e.g. "Yes" (no price). */
    outcomeLabel: string;
    /** Resolved winning outcome name shown in closed position rows, e.g. "No". */
    resolutionLabel?: string | null;
    /** Per-venue position sizes with logos below the pill. */
    venueShareBreakdown: UserProfilePositionVenueShare[];
    /** Total shares/contracts represented by this row. */
    totalShares?: number | null;
    /** Average price, e.g. "29¢" */
    averageLabel: string;
    /** Average entry price as a 0-1 decimal, e.g. 0.29. */
    averagePrice?: number | null;
    /** Current price, e.g. "25¢" */
    currentLabel: string;
    /** Current or mark price as a 0-1 decimal, e.g. 0.25. */
    currentPrice?: number | null;
    /** Total value, e.g. "$25.86" */
    valueLabel: string;
    /** Current position value in USD. */
    currentValue?: number | null;
    /** P&L label, e.g. "-$4.14 (-13.79%)" */
    pnlLabel: string;
    /** Absolute P&L in USD. */
    pnlValue?: number | null;
    /** P&L percentage as display percent, e.g. -13.79 for -13.79%. */
    pnlPercent?: number | null;
    /** True when P&L is positive */
    isPnlPositive: boolean;
    /** Bucket the backend placed this row in. */
    status: "active" | "closed";
    /** Raw VenueMarket.status for the primary market in the group. */
    marketStatus: "unopened" | "paused" | "open" | "closed" | "resolved";
    /** Aggregated winner across sibling outcomes; null until any venue resolves. */
    winner: boolean | null;
    /** Earliest non-null resolutionDate across sibling markets, ISO. */
    resolutionDate: string | null;
    /** Closed-table total traded label, e.g. "$310.11". */
    closedTotalTradedLabel?: string;
    /** Total order cost in USD. */
    totalTradedValue?: number | null;
    /** Closed-table amount won label, e.g. "$469.95". */
    closedAmountWonLabel?: string;
    /** Final payout value in USD. */
    finalPayoutValue?: number | null;
    /** Final absolute P&L in USD. */
    finalPnlValue?: number | null;
    /** Final P&L percentage as display percent, e.g. -100 for -100%. */
    finalPnlPercent?: number | null;
    /** Final price as a 0-1 decimal, e.g. 1 for 100¢. */
    finalPrice?: number | null;
    /** Closed-table return label, e.g. "+51.54%". */
    closedReturnLabel?: string;
    /** Redeem state used by the closed-table Claim column. */
    closedClaimStatus?: "eligible" | "pending" | "redeemed" | "ineligible";
    /** Winning outcome ids used to redeem closed winning positions. */
    winningOutcomeIds?: string[];
}
export type UserProfileActivityKind = "trade" | "redeem" | "withdrawal" | "deposit" | "bridge" | "user_op" | "unknown";
export interface UserProfileTradeActivity {
    kind: "trade";
    id: string;
    /** Event ID used for deep-link navigation when available. */
    eventId?: string;
    /** Market ID used to preselect the market on event details when available. */
    marketId?: string;
    /** Whether the activity failed and should render in a degraded state. */
    isFailed?: boolean;
    /** Whether the row should use error-colored text because the activity has an error. */
    hasError?: boolean;
    /** Error message for the activity. */
    errorMessage?: string;
    /** Normalized lifecycle status driving row tone. Defaults to "completed". */
    status?: UserProfileActivityStatus;
    /** Activity type, e.g. "Buy", "Sell" */
    type: string;
    /** Market thumbnail image URL */
    thumbnailSrc: string;
    /** Market title */
    title: string;
    /** Venue logo for the market */
    venue: VenueLogoName;
    /** Outcome label, e.g. "Yes 29¢" */
    outcomeLabel: string;
    /** Number of shares, e.g. "103.4 shares" */
    sharesLabel: string;
    /** Amount label, e.g. "$100.00" */
    amountLabel: string;
    /** Time label, e.g. "3d ago" */
    timeLabel: string;
}
export interface UserProfileRedeemActivity {
    kind: "redeem";
    id: string;
    /** Chain ID used to build an explorer link for the redeem transaction. */
    chainId?: string;
    /** Transaction hash used to build an explorer link for the redeem transaction. */
    txHash?: string;
    /** Whether the activity failed and should render in a degraded state. */
    isFailed?: boolean;
    /** Whether the row should use error-colored text because the activity has an error. */
    hasError?: boolean;
    /** Error message for the activity. */
    errorMessage?: string;
    /** Normalized lifecycle status driving row title and amount rendering. */
    status?: UserProfileActivityStatus;
    /** Activity type label, e.g. "Redeem". */
    type: string;
    /** Status-aware title, e.g. "Successful claim". */
    title: string;
    /** Market thumbnail image URL. */
    thumbnailSrc: string;
    /** Market question shown below the redeem title. */
    marketTitle: string;
    /** Outcome label, e.g. "Down". */
    outcomeLabel: string;
    /** Right-side payout label, e.g. "+20.00 USDC". */
    amountLabel: string;
    /** Time label, e.g. "3d ago". */
    timeLabel: string;
}
/**
 * Normalized UI state for activity rows. Backend statuses collapse into
 * one of four buckets so row tone, status icons, titles, and amounts stay
 * aligned. Unknown statuses fall back to "completed" — a stale row at rest
 * is the safer default than a sticky spinner.
 */
export type UserProfileActivityStatus = "completed" | "pending" | "failed" | "canceled";
export type UserProfileTransferStatus = UserProfileActivityStatus;
/** Non-market-image activity row: withdrawal / deposit / bridge / user_op / unknown. */
export interface UserProfileTransferActivity {
    kind: "withdrawal" | "deposit" | "bridge" | "user_op" | "unknown";
    id: string;
    /** Chain ID used to build an explorer link for the activity transaction. */
    chainId?: string;
    /** Transaction hash used to build an explorer link for the activity transaction. */
    txHash?: string;
    /** Whether the activity failed and should render in a degraded state. */
    isFailed?: boolean;
    /** Whether the row should use error-colored text because the activity has an error. */
    hasError?: boolean;
    /** Error message for the activity. */
    errorMessage?: string;
    /** Normalized status driving icon, title, and amount rendering. Defaults to "completed". */
    status?: UserProfileTransferStatus;
    /** Header label, e.g. "Withdraw", "Deposit", "Bridge", "Wallet op". */
    type: string;
    /** Title, e.g. "Withdraw USDC". */
    title: string;
    /** Subtitle line, e.g. "to 0xab…cd · base". */
    subtitleLabel: string;
    /** Right-side amount, e.g. "-100 USDC". May be empty. */
    amountLabel: string;
    /** Time label, e.g. "3d ago". */
    timeLabel: string;
    /** Deposit source — determines the icon in the thumbnail square. Only set when kind is "deposit". */
    depositSource?: "wallet" | "crypto" | "card";
}
export type UserProfileActivity = UserProfileTradeActivity | UserProfileRedeemActivity | UserProfileTransferActivity;
export interface UserProfileOpenOrder {
    id: string;
    /** Market thumbnail image URL */
    thumbnailSrc: string;
    /** Market title */
    title: string;
    /** Outcome name for the pill, e.g. "Yes" */
    outcomeLabel: string;
    /** Venue logo for the market */
    venue: VenueLogoName;
    /** Filled-out-of-total label, e.g. "0/150" */
    filledLabel: string;
    /** Total notional label, e.g. "$25.86" */
    valueLabel: string;
    /** Raw order status from API (used to gate Cancel availability). */
    status: string;
    /** DAG run ID; present once the order has been picked up by the processing queue. */
    dagRunId?: string | null;
}
export type UserProfilePositionFilter = "active" | "closed";
export type UserProfilePageClassNames = Partial<{
    root: string;
    topRow: string;
    leftColumn: string;
    rightColumn: string;
    userInfoCard: string;
    balanceDisplay: string;
    balancesCard: string;
    positionsActivity: string;
}>;
export type UserProfileCancelOrderHandler = (order: UserProfileOpenOrder) => void;
export interface UserProfilePageProps {
    /** User information. When omitted, page resolves current authenticated user via hooks. */
    user?: UserProfileInfo;
    /** Override for balances-by-network tooltip in storybook/demos; when omitted, hooks are used. */
    balanceChainsOverride?: Array<{
        /** Stable key for the balance chain row. */
        key: string;
        /** User-facing label for the chain. */
        label: string;
        /** Numeric balance value shown for the chain. */
        balance: number;
        /** Number of connected accounts contributing to this chain balance. */
        accountCount: number;
        /**
         * Optional venues that hold this chain's balance (renders venue logos in tooltip).
         * Unknown values are ignored at render time.
         */
        venues?: string[];
    }>;
    /** Venue balances shown in the sidebar card */
    venueBalances?: UserProfileVenueBalance[];
    /** Consolidated Balance / P&L data */
    balance?: UserProfileBalance;
    /** Active-tab positions (size > threshold && market not resolved). */
    activePositions?: UserProfilePosition[];
    /** Closed-tab positions (sold, resolved, dust). */
    closedPositions?: UserProfilePosition[];
    /** Initial positions filter selection. */
    initialPositionFilter?: UserProfilePositionFilter;
    /**
     * Active tab — controlled. Pair with `onTabChange` so the host (e.g. router /
     * URL state) drives the selected tab. Defaults to "positions" when omitted.
     */
    tab?: UserProfileTabValue;
    /** Fires when the user clicks a tab. Use to reflect the change in your URL. */
    onTabChange?: (tab: UserProfileTabValue) => void;
    /** Open orders (resting / partially filled) */
    openOrders?: UserProfileOpenOrder[];
    /** Activity items */
    activities?: UserProfileActivity[];
    executionMode?: "live" | "paper";
    /** Called when the user clicks "Edit" on the user info card */
    onEditProfile?: () => void;
    /** Called when the user clicks "Deposit" */
    onDeposit?: () => void;
    /** Called when the user clicks "Withdraw" */
    onWithdraw?: () => void;
    /** Called when a position row is clicked */
    onPositionClick?: (position: UserProfilePosition) => void;
    /** Optional href for a position row (enables ctrl/cmd/middle-click to open in a new tab). */
    getPositionHref?: (position: UserProfilePosition) => string | undefined;
    /** Called when the user claims a closed winning position. */
    onClaim?: (position: UserProfilePosition) => Promise<void> | void;
    /**
     * Map of claim key (marketId or position id) to loading state while claim is in-flight.
     *
     * Passing this prop overrides the internal lifecycle-driven spinner (the page derives
     * spinner state from the in-flight redeem's WS lifecycle when this prop is omitted).
     * Partners who own the claim flow via `onClaim` typically pass their own state here;
     * partners who let the page own the flow should omit this prop.
     */
    claimingPositionKeys?: Record<string, boolean>;
    /**
     * Called once per redeem when its lifecycle reaches terminal (every expected leg
     * confirmed or failed on chain). Receives the same `claimKey` that
     * `claimingPositionKeys` uses (i.e. `position.marketId ?? position.id`) plus a
     * summary of the terminal lifecycle state. Use this to fire one-shot success/failure
     * toasts.
     *
     * NOT fired for synchronous submit failures (network errors, `RedeemRejectedError`)
     * — those go through `onClaimSubmitError`.
     *
     * Only fired when the internal claim path is used (i.e. when the caller does NOT
     * pass an `onClaim` prop). Callers that own the claim flow via `onClaim` are
     * responsible for their own toasting.
     */
    onClaimResult?: (claimKey: string, lifecycle: {
        allConfirmed: boolean;
        anyFailed: boolean;
        errorMessage: string | null;
    }) => void;
    /**
     * Called when the redeem mutation itself rejects — i.e. transport error, validation
     * error, or `RedeemRejectedError` (all legs ineligible/rejected at submit time). The
     * redeem never enters the WS lifecycle in these cases, so `onClaimResult` does NOT
     * fire.
     *
     * Only fired when the internal claim path is used.
     */
    onClaimSubmitError?: (claimKey: string, error: Error) => void;
    /** Called when an activity row is clicked */
    onActivityClick?: (activity: UserProfileActivity) => void;
    /** Optional href for an activity row (enables ctrl/cmd/middle-click to open in a new tab). */
    getActivityHref?: (activity: UserProfileActivity) => string | undefined;
    /** Called when an open-order row is clicked */
    onOpenOrderClick?: (order: UserProfileOpenOrder) => void;
    /** Called when the user clicks Cancel on an open order. */
    onCancelOrder?: UserProfileCancelOrderHandler;
    /** Map of orderId → true while a cancel request is in-flight. */
    cancellingOrderIds?: Record<string, boolean>;
    /** Whether to show loading state on the currently-visible positions tab. */
    isLoadingPositions?: boolean;
    /** Whether the activity tab content is currently loading. */
    isLoadingActivities?: boolean;
    isLoadingOpenOrders?: boolean;
    /** Whether to show error state on the currently-visible positions tab. */
    positionsError?: boolean;
    /** Whether the activity tab should render its error state. */
    activitiesError?: boolean;
    openOrdersError?: boolean;
    /** Active-tab pagination */
    hasMoreActivePositions?: boolean;
    isLoadingMoreActivePositions?: boolean;
    onLoadMoreActivePositions?: () => void;
    /** Closed-tab pagination */
    hasMoreClosedPositions?: boolean;
    isLoadingMoreClosedPositions?: boolean;
    onLoadMoreClosedPositions?: () => void;
    /** Called when the user switches between Active and Closed filter pills. */
    onPositionFilterChange?: (filter: "active" | "closed") => void;
    /** Whether there are more activity items to fetch in connected mode. */
    hasMoreActivities?: boolean;
    /** Loading state for activity pagination. */
    isLoadingMoreActivities?: boolean;
    /** Cursor pagination handler for activity. */
    onLoadMoreActivities?: () => void;
    /** Whether there are more open orders to fetch in connected mode. */
    hasMoreOpenOrders?: boolean;
    /** Loading state for open-orders pagination. */
    isLoadingMoreOpenOrders?: boolean;
    /** Cursor pagination handler for open orders. */
    onLoadMoreOpenOrders?: () => void;
    /** Custom class names for sub-sections */
    classNames?: UserProfilePageClassNames;
}
