/*
 * @Author: 赵伟
 * @Date: 2024-04-28 14:18:11
 * @Description: 自定义 Table 数组类单元格
 */

import { Tooltip } from 'antd';

function ArrayTableCell(ellipsis: boolean = false, property?: string) {
  return (value?: any | null) => {
    if (
      value === undefined ||
      value === null ||
      Array.isArray(value) === false ||
      value.length === 0
    ) {
      return <span>--</span>;
    }

    let list = value;
    if (property && typeof value[0] === 'object') {
      list = value.map((item) => item[property]);
    }
    const text = list.join(',');
    if (ellipsis) {
      return (
        <Tooltip title={text} placement="topLeft" overlayStyle={{ maxWidth: '400px' }}>
          <span>{text}</span>;
        </Tooltip>
      );
    } else {
      return <span>{text}</span>;
    }
  };
}

export default ArrayTableCell;
