import React from 'react'
import { View } from 'react-native'
import { TableColumn } from '../TableTypes'
import { useContextTableMinWidth } from '../context'
import TableScrollContainer from './TableScrollContainer'

type Props = {
  tableObjectId: string
  scrollEnabled: boolean
  columns: TableColumn[]
  tableWidth: number
}

const TableScroll: React.FC<Props> = props => {
  const { tableObjectId, columns, children, scrollEnabled, tableWidth } = props
  const minWidth = useContextTableMinWidth(tableObjectId, tableWidth, columns)

  return (
    <TableScrollContainer scrollEnabled={scrollEnabled}>
      <View style={{ minWidth }}>{children}</View>
    </TableScrollContainer>
  )
}

export default TableScroll
