import type { ProTableProps } from '@ant-design/pro-table'
import { mergeTableProps as _mergeTableProps } from '@genting/hooks'
import { Typography } from 'antd'

const { Text } = Typography

export function mergeTableProps<T extends ProTableProps<any, any>>(
  ...args: Parameters<typeof _mergeTableProps<T>>
) {
  const tableProps = _mergeTableProps(...args)

  // 处理 columns，重写 render 方法实现省略段落
  tableProps.columns?.forEach((column) => {
    if (column.ellipsis) {
      const oldRender = column.render
      column.render = (...args) => {
        const [remark, , , , { width }] = args
        return (
          <Text style={{ width }} ellipsis={{ tooltip: remark }}>
            {oldRender?.(...args) || remark}
          </Text>
        )
      }
      column.ellipsis = false
    }
  })

  return tableProps
}
