import { h } from 'vue';
import { NTag } from 'naive-ui';
import { timestampToTime } from '@/utils/dateUtil';
import moment from 'moment';
export const columns = [
  {
    title: '序号',
    dataIndex: 'id',
    key: 'id',
  },
  {
    title: '标题',
    dataIndex: 'title',
    key: 'title',
  },
  {
    title: '预发送时间',
    dataIndex: 'sendAt',
    key: 'sendAt',
    render(row) {
      return timestampToTime(row.sendAt);
    },
  },
  {
    title: '收件方',
    dataIndex: 'recievers',
    key: 'recievers',
    render(row) {
      // 老模式
      if (row.recieverType === 0) {
        return row.recievers == '全员' ? '全员' : '指定用户';
      }

      if (row.recieverType === 1) {
        return '全服';
      }

      if (row.recieverType === 2) {
        return '指定服[' + row.recievers + ']';
      }

      if (row.recieverType === 3) {
        return '指定玩家[' + row.recievers + ']';
      }

      return '未知类型';
    },
  },
  {
    title: '状态',
    dataIndex: 'statusInfo',
    key: 'statusInfo',
    scopedSlots: { customRender: 'status' },
    render(row) {
      const now = moment();
      if (row.status == '待发送') {
        const send = moment(row.sendAt * 1000);
        if (send.isBefore(now)) {
          row.statusInfo = '已过期';
        } else {
          const diff = send.diff(now, 'days', true);
          if (diff >= 1) {
            row.statusInfo = diff.toFixed(0) + '天后发送';
          } else {
            const diffMin = send.diff(now, 'minutes', true);
            const hour = diffMin / 60;
            const min = diffMin % 60;
            row.statusInfo = hour.toFixed(0) + '小时' + min.toFixed(0) + '分后发送';
          }
        }
      } else {
        row.statusInfo = row.status == '' ? '草稿' : row.status;
      }

      return h(
        NTag,
        {
          style: {
            marginRight: '6px',
          },
          type: 'info',
          bordered: false,
        },
        {
          default: () => row.statusInfo,
        }
      );
    },
  },
  {
    title: '发送人',
    dataIndex: 'sender',
    key: 'sender',
    render(row) {
      return row.sender;
    },
  },
];
