import React, { FC, memo } from 'react'
import { Text } from 'react-native'
import { isEqual } from 'lodash'

import { CellProps } from './TableTypes'
import { styles } from './TableRow'

const LINEMAP = {
  singleLine: 1,
  multiLine: 2,
  noMax: Number.MAX_SAFE_INTEGER,
}

const TextCell: FC<CellProps> = ({ cell, theme }) => {
  const { binding } = cell

  return (
    <Text
      ellipsizeMode="tail"
      numberOfLines={LINEMAP[binding?.format?.textLength ?? 'singleLine']}
      style={[styles.cellText, theme.cellText]}
    >
      {cell.value}
    </Text>
  )
}

export default memo(TextCell, isEqual)
