import { h } from 'vue';
import { NImage } from 'naive-ui';

const types = {
  1: '玩家',
  2: '客服',
};

export const columns = [
  {
    title: '序号',
    dataIndex: 'id',
    key: 'id',
    width: 20,
  },
  {
    title: '主体',
    dataIndex: 'type',
    key: 'type',
    width: 30,
    render(row) {
      let fontColor = '';
      if (row.type === 1) {
        fontColor = 'red';
      } else if (row.type === 2) {
        fontColor = 'blue';
      }
      return h('span', {
        style: {
          color: fontColor,
        },
      }, types[row.type]);
      //return types[row.type];
    },
  },
  {
    title: 'openId',
    dataIndex: 'open_id',
    key: 'open_id',
    render(row) {
      return row.open_id;
    },
    width: 80,
  },
  {
    title: '玩家昵称',
    dataIndex: 'player_name',
    key: 'player_name',
    render(row) {
      return row.player_name;
    },
    width: 30,
  },
  {
    title: '消息内容',
    dataIndex: 'text',
    key: 'text',
    width: 200,
    render(row) {
      if (row.text && row.text.startsWith('http')) {
        return h(NImage, { src: row.text, alt: '图片',width: '100',height: '120'});
      }
      return row.text;
    },
  },
  {
    title: '发送时间',
    dataIndex: 'time',
    key: 'time',
    render: (rows) => {
      return rows.time;
    },
    width: 60,
  },
];
