import { h } from 'vue';
import { NTag } from 'naive-ui';
import { getStatusName, getStatusTag } from '@/utils/deploy';

export const columns = [
  {
    title: '序号',
    dataIndex: 'id',
    key: 'id',
    width: 80,
  },
  {
    title: '操作人',
    dataIndex: 'adminName',
    key: 'adminName',
    width: 100,
  },
  {
    title: '操作类型',
    dataIndex: 'publish_type',
    key: 'publish_type',
    render(row) {
      return h(
        NTag,
        {
          style: {
            marginRight: '6px',
          },
          type: row.publish_type === 1 ? 'success' : 'warning',
          bordered: false,
        },
        {
          default: () => (row.publish_type === 1 ? '版本发布' : '停止服务'),
        }
      );
    },
    width: 150,
  },
  {
    title: '操作信息',
    dataIndex: 'container_name',
    key: 'container_name',
    width: 180,
    render(rows) {
      return h('p', { id: 'app' }, [
        h('div', { innerHTML: '<div>容器名称：' + rows.container_name + '</div>' }),
        h('div', { innerHTML: '<div>应用名称：' + rows.name + '</div>' }),
        h('div', {
          innerHTML:
            rows.publish_type === 1
              ? '<div>部署版本号：' + rows.version + '</div>'
              : '<div>参数：' + rows.extra + '</div>',
        }),
      ]);
    },
  },
  {
    title: '部署状态',
    dataIndex: 'container_name',
    key: 'container_name',
    width: 360,
    render(rows) {
      return h('p', { id: 'app' }, [
        h(
          NTag,
          {
            style: {
              marginRight: '6px',
            },
            type: getStatusTag(rows.status),
            bordered: false,
          },
          {
            default: () => getStatusName(rows.status),
          }
        ),
        h('div', { innerHTML: '<div>消息提示：' + rows.error_msg + '</div>' }),
        h('div', { innerHTML: '<div>部署结束时间：' + rows.end_at + '</div>' }),
      ]);
    },
  },
  {
    title: '操作时间',
    dataIndex: 'created_at',
    key: 'created_at',
    width: 180,
  },
];
