'use client'; import { Text, XStack, YStack } from '@hanzo/gui'; import * as React from 'react'; // --------------------------------------------------------------------------- // Types // --------------------------------------------------------------------------- export interface OptionPosition { symbol: string; underlying: string; type: 'call' | 'put'; strike: number; expiration: string; quantity: number; avgCost: number; currentValue: number; pnl: number; pnlPercent: number; greeks: { delta: number; gamma: number; theta: number; vega: number; }; } export interface OptionPositionCardProps extends React.HTMLAttributes { readonly position: OptionPosition; readonly onClose?: (position: OptionPosition) => void; readonly onExercise?: (position: OptionPosition) => void; readonly onRoll?: (position: OptionPosition) => void; } // --------------------------------------------------------------------------- // Helpers // --------------------------------------------------------------------------- function formatDate(date: string): string { const d = new Date(date); return d.toLocaleDateString('en-US', { month: 'short', day: 'numeric' }); } const MONO = { fontFamily: 'monospace' } as never; // --------------------------------------------------------------------------- // OptionPositionCard // --------------------------------------------------------------------------- export const OptionPositionCard = React.forwardRef( function OptionPositionCard(props, ref) { const { position, onClose, onExercise, onRoll, className, ...rest } = props; const isLong = position.quantity > 0; const isCall = position.type === 'call'; const isProfitable = position.pnl >= 0; const pnlColor = (isProfitable ? 'var(--color-status-good)' : 'var(--color-status-bad)') as never; return ( {/* Header row: symbol badge + quantity */} {/* Symbol badge. Call vs put is a rank difference, not a hue difference. */} { position.underlying } { position.strike } { position.type === 'call' ? 'C' : 'P' } { formatDate(position.expiration) } {/* Quantity */} { isLong ? '+' : '' }{ position.quantity } {/* Values row (3 equal columns) */} Avg Cost ${ position.avgCost.toFixed(2) } Value ${ position.currentValue.toFixed(2) } P/L { isProfitable ? '+' : '' }{ position.pnl.toFixed(2) } ({ isProfitable ? '+' : '' }{ position.pnlPercent.toFixed(1) }%) {/* Greeks row — same achromatic ramp as : a greek is identified by its symbol, never by a hue. */} {/* Action buttons */} { (onClose || onExercise || onRoll) && ( { onClose && onClose(position) }>Close } { onExercise && onExercise(position) }>Exercise } { onRoll && onRoll(position) }>Roll } ) } ); }, ); // --------------------------------------------------------------------------- // ActionButton (internal) — Close / Exercise / Roll. Same resting/hover pair // button.tsx's "subtle" variant uses: hover repaints the text, not the fill. // --------------------------------------------------------------------------- interface ActionButtonProps { readonly onClick: () => void; readonly children: React.ReactNode; } function ActionButton({ onClick, children }: ActionButtonProps) { return ( } onClick={ onClick } flex={ 1 } alignItems="center" justifyContent="center" borderRadius={ 6 } borderWidth={ 0 } paddingHorizontal={ 8 } paddingVertical={ 4 } backgroundColor={ 'var(--color-button-subtle-bg)' as never } cursor="pointer" > {/* `hoverStyle` lives on the Text, not the button frame — Stacks carry no `color` (same reason they carry no `fontSize`), so the hover re-tint has to be the text's own state, not the button's. */} { children } ); } // --------------------------------------------------------------------------- // GreekPill (internal) // --------------------------------------------------------------------------- interface GreekPillProps { readonly label: string; readonly value: number; /** A resolved `var(--…)` token — this component is package-private. */ readonly color: string; } function GreekPill({ label, value, color }: GreekPillProps) { return ( { label } { value.toFixed(4) } ); }