import { Checkbox, Input, Typography } from 'antd'; import type { ColumnsType } from 'antd/es/table'; import type { GoodwillRow, GoodwillTreeRow } from '../../../types/goodwill/goodwill'; import { chessTableCellFormatValue } from '../../../utils/chessTableCellFormatValue'; const { Text } = Typography; interface GetColumnsParams { units: string; decimals: number; isEditMode: boolean; editedRows: Record>; onRowEdit: (rowId: string, field: keyof GoodwillRow, value: any) => void; } export const getGoodwillColumns = ({ units, decimals, isEditMode, editedRows, onRowEdit, }: GetColumnsParams): ColumnsType => { const formatMoney = (val: string | undefined) => { if (!val || val === '0' || val === '0.00') return '—'; return chessTableCellFormatValue(val, units, decimals); }; return [ { title: 'Учет в отчете', key: 'include_in_kfo', width: 120, align: 'center', render: (_, row) => { const isChecked = row.isGroup ? row.include_in_kfo : (editedRows[row.key]?.include_in_kfo ?? row.include_in_kfo); return ( onRowEdit(row.key, 'include_in_kfo', e.target.checked)} /> ); }, }, { title: 'Наименование дочерней организации', key: 'name', width: 300, render: (_, row) => (row.isGroup ? {row.head_legal_entity.name} : row.subsidiary_legal_entity.name), }, { title: 'Доля владения', key: 'ownership_share', width: 150, align: 'right', onCell: (row) => { if (row.isGroup) return {}; const isChecked = editedRows[row.key]?.include_in_kfo ?? row.include_in_kfo; if (!isChecked) return {}; const val = editedRows[row.key]?.ownership_share ?? row.ownership_share; const isShareEmpty = !val || String(val).trim() === ''; const isInvalid = isShareEmpty; return { style: { backgroundColor: isInvalid ? '#fffbe6' : '#f6ffed', }, }; }, render: (_, row) => { if (row.isGroup) return null; const val = editedRows[row.key]?.ownership_share ?? row.ownership_share; const isChecked = editedRows[row.key]?.include_in_kfo ?? row.include_in_kfo; if (isEditMode && isChecked) { return ( { const intValue = e.target.value.replace(/\D/g, ''); onRowEdit(row.key, 'ownership_share', intValue); }} placeholder='%' /> ); } return val ? `${Math.floor(Number(val))}%` : '—'; }, }, { title: 'Фондовые вложения головной организации', dataIndex: 'financial_investment_amount', key: 'financial_investment_amount', width: 150, align: 'right', render: (val, row) => (row.isGroup ? null : formatMoney(val)), }, { title: 'Доля участия головной организации в уставном капитале', dataIndex: 'participation_amount', key: 'participation_amount', width: 150, align: 'right', render: (val, row) => (row.isGroup ? null : formatMoney(val)), }, { title: 'Уставный капитал', dataIndex: 'charter_capital_amount', key: 'charter_capital_amount', width: 150, align: 'right', render: (val, row) => (row.isGroup ? null : formatMoney(val)), }, { title: 'Гудвилл (+/-)', dataIndex: 'goodwill_amount', key: 'goodwill_amount', width: 150, align: 'right', render: (val, row) => { if (row.isGroup) return null; const formatted = formatMoney(val); if (formatted === '—') return —; const isNegative = String(val).trim().startsWith('-'); return ( {formatted} ); }, }, { title: 'Комментарий', key: 'comment', width: 200, onCell: (row) => { if (row.isGroup) return {}; const isChecked = editedRows[row.key]?.include_in_kfo ?? row.include_in_kfo; if (!isChecked) return {}; const comment = editedRows[row.key]?.comment ?? row.comment; const isCommentEmpty = !comment || String(comment).trim() === ''; const isInvalid = isCommentEmpty; return { style: { backgroundColor: isInvalid ? '#fffbe6' : '#f6ffed', }, }; }, render: (_, row) => { if (row.isGroup) return null; const val = editedRows[row.key]?.comment ?? row.comment; const isChecked = editedRows[row.key]?.include_in_kfo ?? row.include_in_kfo; if (isEditMode && isChecked) { return ( onRowEdit(row.key, 'comment', e.target.value)} placeholder='Комментарий' /> ); } return val || '—'; }, }, ]; };