import { h } from 'vue';
import { NTag } from 'naive-ui';
import { timestampToTime } from '@/utils/dateUtil';
import { EmailStatusOptions } from '@/enums/optionsiEnum';
import { getOptionLabel, getOptionTag } from '@/utils';

export const columns = [
  {
    title: 'ID',
    dataIndex: 'id',
    key: 'id',
  },
  {
    title: '标题',
    dataIndex: 'title',
    key: 'title',
  },
  {
    title: '收件人',
    dataIndex: 'receipt_type',
    key: 'receipt_type',
    render(row) {
      if (row.receipt_type === 1) {
        return '全服';
      }

      if (row.receipt_type === 2) {
        return '指定服:' + row.server_ids;
      }

      if (row.receipt_type === 3) {
        return '指定玩家:' + row.player_ids;
      }
      return '未知类型';
    },
  },
  {
    title: '有效期',
    dataIndex: 'expired',
    key: 'expired',
    render(row) {
      return row.expired + '天';
    },
  },
  {
    title: '发送方式',
    dataIndex: 'send_type',
    key: 'send_type',
    render(row) {
      return row.send_type == 1 ? '立即发送' : '延迟发送';
    },
  },
  {
    title: '预计发送时间',
    dataIndex: 'send_at',
    key: 'sendAt',
    render(row) {
      if (row.send_at < 1) {
        return '-';
      }
      return timestampToTime(row.send_at);
    },
  },
  {
    title: '发送状态',
    key: 'status',
    render(row) {
      return h(
        NTag,
        {
          style: {
            marginRight: '6px',
          },
          type: getOptionTag(EmailStatusOptions, row.status),
          bordered: false,
        },
        {
          default: () => getOptionLabel(EmailStatusOptions, row.status),
        }
      );
    },
  },
  {
    title: '创建人',
    dataIndex: 'sender',
    key: 'sender',
    render(row) {
      return row.sender + ' ' + '[' + row.operator_id + ']';
    },
  },
  {
    title: '创建时间',
    dataIndex: 'created_at',
    key: 'created_at',
    render(row) {
      return timestampToTime(row.created_at);
    },
  },
];
