import { h } from 'vue';
import { NImage, NTag } from 'naive-ui';
import { BasicColumn } from '@/components/Table';

export const columns: BasicColumn[] = [
  {
    type: 'selection',
    width: 50,
    fixed: 'left',
  },
  {
    title: 'ID',
    key: 'id',
    width: 50,
    fixed: 'left',
  },
  {
    title: '登录账号',
    key: 'username',
    width: 150,
  },
  {
    title: '用户姓名',
    key: 'realname',
    width: 150,
  },
  {
    title: '头像',
    key: 'avatar',
    render(row) {
      return h(NImage, {
        width: 48,
        src: row.avatar,
        shape: 'square',
        fit: 'fill',
      });
    },
    width: 100,
  },
  {
    title: '性别',
    width: 100,
    key: 'gender',
    render(row) {
      let typeText = '';
      let color = '';
      switch (row.gender) {
        case 1:
          typeText = '男';
          color = 'info';
          break;
        case 2:
          typeText = '女';
          color = 'error';
          break;
        case 3:
          typeText = '保密';
          color = 'warning';
          break;
        default:
          break;
      }
      return h(
        NTag,
        {
          type: color,
        },
        {
          default: () => typeText,
        },
      );
    },
  },
  {
    title: '手机号',
    key: 'mobile',
    width: 160,
  },
  {
    title: '用户角色',
    key: 'role',
    render(row) {
      let roleNames = '';
      if (row.roles.length > 0) {
        roleNames = row.roles.map((role) => role.name).join(',');
      }
      return h('span', roleNames || '-');
    },
    width: 100,
  },
  {
    title: '职级',
    key: 'levelName',
    width: 100,
  },
  {
    title: '岗位',
    key: 'positionName',
    width: 100,
  },
  {
    title: '部门',
    key: 'deptName',
    width: 160,
  },
  {
    title: '状态',
    key: 'status',
    width: 100,
    render(row) {
      return h(
        NTag,
        {
          type: row.status == 1 ? 'success' : 'error',
        },
        {
          default: () => (row.status == 1 ? '正常' : '禁用'),
        },
      );
    },
  },
  {
    title: '创建人',
    key: 'createUser',
    width: 100,
  },
  {
    title: '创建时间',
    key: 'createTime',
    width: 180,
  },
];
