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

export const idColumn = {
  title: '玩家ID',
  key: 'playerid',
  width: 100,
};

export const banColumn = {
  title: '账号状态',
  key: 'ban',
  width: 100,
  render(row) {
    return h(
      NTag,
      {
        style: {
          marginRight: '6px',
        },
        type: row.ban == 1 || row.singleBan == 1 ? 'error' : 'info',
        bordered: false,
      },
      {
        default: () => (row.ban == 1 ? '全服封禁' : row.singleBan == 1 ? '当前服封禁' : '正常'),
      }
    );
  },
};

export const createtimeColumn = {
  title: '注册时间',
  key: 'createtime',
  width: 180,
  render: (rows, _) => {
    return timestampToTime(rows.createtime);
  },
};

export const columns = [
  idColumn,
  {
    title: '账号ID',
    key: 'accId',
    width: 120,
  },
  {
    title: '昵称',
    key: 'nickName',
    width: 120,
  },
  {
    title: '头像',
    key: 'imgUrl',
    width: 80,
    render(row) {
      return h(NAvatar, {
        size: 32,
        src: row.imgUrl,
      });
    },
  },
  {
    title: 'openId',
    key: 'openId',
    width: 200,
  },
  {
    title: '所在服务器',
    key: 'serverName',
    width: 150,
  },
  {
    title: '等级',
    key: 'level',
    width: 150,
  },
  {
    title: '最后登录时间',
    key: 'lastlogintick',
    render: (rows, _) => {
      return timestampToTime(rows.lastlogintick);
    },
    width: 180,
  },
  createtimeColumn,
  banColumn,
];
