import { ElButton, ElPopconfirm } from 'element-plus'

import Switch from '#/components/Switch'
import getDict from '#/hooks/useDict'
import dayjs from '#/plugins/dayjs'
import { ArrToObj } from '#/utils/tool'

// 反馈类型
const feedbackType: anyObj = ArrToObj(getDict('feedback_type'))

export default (event: { [key: string]: any }): TableColumn[] => [
  { type: 'selection', fixed: 'left' },
  {
    label: '用户名',
    prop: 'nickName',
  },
  {
    label: '账号',
    prop: 'account',
  },
  {
    label: '职业',
    prop: 'career',
  },
  {
    label: '角色',
    prop: 'roleName',
  },
  {
    label: '邮箱',
    prop: 'email',
  },
  {
    label: '创建时间',
    prop: 'createTime',
    'show-overflow-tooltip': true,
    render: (h, scope) => {
      return dayjs(scope.row.createTime).format('YYYY/MM/DD HH:mm')
    },
  },
  {
    label: '状态',
    width: 180,
    render: (h, scope) => {
      return (
        <Switch
          active-value={0}
          before-change={() => event.updateState(scope.row)}
          inactive-value={1}
          loading={scope.row.loading}
          v-model={scope.row.status}
        />
      )
    },
  },
  {
    label: '操作',
    width: 240,
    fixed: 'right',
    render: (h, scope) => {
      return (
        <div>
          <ElButton
            onClick={() => event.handleClick(scope.row, 0)}
            type="primary"
          >
            编辑
          </ElButton>
          <ElPopconfirm
            onConfirm={() => event.handleClick(scope.row, 1)}
            persistent
            title="删除后无法恢复，确定吗？"
            width="220"
          >
            {{
              reference: () => <ElButton type="danger">删除</ElButton>,
            }}
          </ElPopconfirm>
        </div>
      )
    },
  },
]
