import { Link } from 'react-router-dom'; import type { BrokerMoney, BrokerOperation, BrokerOperationsPage } from '../../api/responses'; import { getBrokerInstrumentPath, getBrokerOperationImpact, getBrokerOperationTypeLabel, type BrokerOperationImpact, } from './brokerDisplay'; import { TableSkeleton } from '../../components/TableSkeleton'; const tableStyle = { width: '100%', borderCollapse: 'collapse', fontSize: 14, } satisfies React.CSSProperties; const thStyle = { borderBottom: '1px solid #e0e0e0', color: 'var(--color-text-secondary)', fontWeight: 600, padding: '10px 8px', } satisfies React.CSSProperties; const tdStyle = { borderBottom: '1px solid #eeeeee', padding: '10px 8px', verticalAlign: 'top', } satisfies React.CSSProperties; function formatMoney(value: BrokerMoney | null | undefined) { if (!value) return '-'; const formatted = new Intl.NumberFormat('ru-RU', { style: 'currency', currency: value.currency || 'RUB', maximumFractionDigits: 2, }).format(value.value); return value.value > 0 ? `+${formatted}` : formatted; } function formatDate(value: string | null) { if (!value) return '-'; return new Date(value).toLocaleString('ru-RU'); } function moneyColor(impact: BrokerOperationImpact): string { if (impact === 'adds') return 'var(--color-positive)'; if (impact === 'reduces') return 'var(--color-negative)'; return 'var(--color-text)'; } function OperationInstrument({ operation }: { operation: BrokerOperation }) { const ticker = operation.ticker || operation.description || '-'; const path = getBrokerInstrumentPath({ ticker: operation.ticker, instrumentType: operation.instrumentType, classCode: operation.classCode, }); const name = operation.name || operation.description; if (!path && !name) return -; if (!path) return {name}; if (!ticker || ticker === '-') return {name}; return (
{ticker} {name && name !== ticker && ( {name} )}
); } const pagButtonStyle = { padding: '6px 14px', borderRadius: 6, border: '1px solid #e0e0e0', background: 'var(--color-surface)', color: 'var(--color-text)', fontSize: 14, fontWeight: 600, cursor: 'pointer', lineHeight: 1.4, } satisfies React.CSSProperties; const pagButtonDisabledStyle = { ...pagButtonStyle, opacity: 0.35, cursor: 'not-allowed', } satisfies React.CSSProperties; export function BrokerOperationsTable({ isLoading, page, pageNumber, canGoBack, canGoForward, onPrevious, onNext, }: { isLoading: boolean; page: BrokerOperationsPage | undefined; pageNumber: number; canGoBack: boolean; canGoForward: boolean; onPrevious: () => void; onNext: () => void; }) { const operations = page?.items ?? []; return (

Операции

{pageNumber}
{isLoading ? (
Дата Тип Инструмент Сумма
) : operations.length === 0 ? (

Операций за выбранный период нет

) : (
{operations.map((operation) => { const impact = getBrokerOperationImpact(operation); return ( ); })}
Дата Тип Инструмент Сумма
{formatDate(operation.date)} {getBrokerOperationTypeLabel(operation)} {formatMoney(operation.payment)}
)}
); }