import { DetailMessage, TableStyle, TableWrapper } from '../../../styles/Components'; import { StatusLabel } from '../../../styles/ModuleComponents'; import { Button, CheckBox } from '../index'; import { convertKTC, getOptionsArray } from '../../../utils'; import { styled } from 'styled-components'; const CaliTable = ({ columns, data, selectedRows = [], onSelectRow, onAction, refProp }) => { const renderCell = (column, item) => { const { type, id, option_name, format, action } = column; const value = item[id]; const options = getOptionsArray(option_name); switch (type) { case 'text': return value; case 'date': return convertKTC(value); case 'status': const statusOption = options.find(opt => opt.value === value); return ( {statusOption ? statusOption.name : value} ); case 'button': return ( onAction(id, item)} /> ); case 'checkbox': return ( onSelectRow(e, item)} checked={selectedRows.some(row => row.id === item.id)} /> ); case 'option': const dataOption = options.find(opt => opt.value === value); return ( dataOption ? dataOption.name : value ); case "link": return ( onAction(action)}> {value.content.length > 20 ? value.content.slice(0, 20) + '...' : value.content || ''} ); default: return value; } }; return ( {columns.map((column, index) => ( {column.title} ))} {data?.map((item, rowIndex) => ( {columns.map((column, colIndex) => ( {renderCell(column, item)} ))} ))} ); }; export default CaliTable; const StatusWapper = styled.div` display: flex; gap: 0.35rem; align-items: center; justify-content: center; `;