import { timestampToTime } from '@/utils/dateUtil';
import { h } from 'vue';
import { NTag } from 'naive-ui';

export const columns = [
  {
    title: 'ID',
    key: 'id',
    width: 50,
  },
  {
    title: '广播内容',
    key: 'content',
    width: 460,
    render(rows) {
      return h('p', { id: 'app' }, [
        h('div', {
          innerHTML: '<div style="white-space: pre-wrap">' + rows.content + '</div>',
        }),
      ]);
    },
  },
  {
    width: 100,
    title: '广播类型',
    key: 'notice_type',
    render(row) {
      return h(
        NTag,
        {
          style: {
            marginRight: '6px',
          },
          type: 'default',
          bordered: false,
        },
        {
          default: () => row.typeName,
        }
      );
    },
  },
  {
    title: '服务器',
    key: 'server_ids',
    render: (rows, _) => {
      return rows.server_ids;
    },
    width: 100,
  },
  {
    title: '时间区间',
    key: 'start_at',
    render(rows) {
      return h('p', { id: 'app' }, [
        h('div', { innerHTML: '<div>开始时间：' + timestampToTime(rows.start_at) + '</div>' }),
        h('div', { innerHTML: '<div>结束时间：' + timestampToTime(rows.end_at) + '</div>' }),
      ]);
    },
    width: 240,
  },
  {
    title: '发送间隔',
    key: 'send_interval',
    render: (rows, _) => {
      return rows.send_interval + '分钟';
    },
    width: 100,
  },
  {
    width: 100,
    title: '运行状态',
    key: 'status',
    render(row) {
      return h(
        NTag,
        {
          style: {
            marginRight: '6px',
          },
          type: row.statusTag,
          bordered: false,
        },
        {
          default: () => row.statusName,
        }
      );
    },
  },
  {
    title: '最后发送时间',
    key: 'last_send_at',
    render: (rows, _) => {
      if (rows.last_send_at === 0) {
        return '-';
      }
      return timestampToTime(rows.last_send_at);
    },
    width: 180,
  },
  {
    title: '创建时间',
    key: 'created_at',
    render: (rows, _) => {
      return timestampToTime(rows.created_at);
    },
    width: 180,
  },
];
