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

import Switch from '#/components/Switch'
import dayjs from '#/plugins/dayjs'

export default (event: { [key: string]: any }): TableColumn[] => [
  // { type: 'selection', fixed: 'left' },
  {
    label: '排序',
    prop: 'sort',
  },
  {
    label: '词汇名称',
    prop: 'name',
  },
  {
    label: '单词数量',
    prop: 'wordCount',
  },
  {
    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: '创建时间',
    prop: 'createTime',
    'show-overflow-tooltip': true,
    render: (h, scope) => {
      return dayjs(scope.row.createTime).format('YYYY/MM/DD HH:mm')
    },
  },

  {
    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>
      )
    },
  },
]
