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

export const runStatus = {
  1: '运行中',
  2: '已退出',
  3: '拉取超时',
  4: '未找到容器，docker离线？',
};

export const columns = [
  {
    title: '序号',
    dataIndex: 'id',
    key: 'id',
    width: 80,
  },
  {
    title: '应用名称',
    dataIndex: 'name',
    key: 'name',
    width: 150,
  },
  {
    title: '分组',
    dataIndex: 'group_id',
    key: 'group_id',
    render(row) {
      return h(
        NTag,
        {
          style: {
            marginRight: '6px',
          },
          type: row.group_id === 1 ? 'success' : 'info',
          bordered: false,
        },
        {
          default: () => (row.group_id === 1 ? '微信' : '抖音'),
        }
      );
    },
    width: 150,
  },
  {
    title: '服务类型',
    dataIndex: 'server_type',
    key: 'server_type',
    width: 100,
  },
  {
    title: '容器名称',
    dataIndex: 'container_name',
    key: 'container_name',
    width: 150,
  },
  {
    title: 'docker地址',
    dataIndex: 'docker_addr',
    key: 'docker_addr',
    width: 200,
  },
  {
    title: '创建人',
    dataIndex: 'adminName',
    key: 'adminName',
    width: 100,
  },
  {
    title: '运行状态',
    dataIndex: 'run_status',
    key: 'run_status',
    render(row) {
      return h(
        NTag,
        {
          style: {
            marginRight: '6px',
          },
          type: row.run_status === 1 ? 'info' : 'error',
          bordered: false,
        },
        {
          default: () => runStatus[row.run_status] ?? '未知状态',
        }
      );
    },
    width: 150,
  },
  {
    title: '最后部署状态',
    dataIndex: 'deploy_status',
    key: 'deploy_status',
    width: 150,
    render(rows) {
      return h(
        NTag,
        {
          style: {
            marginRight: '6px',
          },
          type: getStatusTag(rows.deploy_status),
          bordered: false,
        },
        {
          default: () => getStatusName(rows.deploy_status),
        }
      );
    },
  },
  // {
  //   title: '部署状态',
  //   dataIndex: 'deploy_status',
  //   key: 'deploy_status',
  //   width: 150,
  // },
  // {
  //   title: '备注',
  //   dataIndex: 'remark',
  //   key: 'remark',
  //   width: 150,
  // },
  {
    title: '创建时间',
    dataIndex: 'created_at',
    key: 'created_at',
    width: 180,
  },
];
