import { ComputedRef } from 'vue'
import { ManagerItem, PermGroupItem } from '/@/api/sys/model/managerModel'
import Icon from '/@/components/Icon'
import { BasicColumn } from '/@/components/Table/src/types/table'
import { formatToDateTime } from '/@/utils/dateUtil'
export function getTableColumns(
  fn: (item: ManagerItem) => void,
  permGroupList: ComputedRef<PermGroupItem[]>
): BasicColumn[] {
  return [
    {
      dataIndex: 'username',
      title: '用户名 (CLD)'
    },
    {
      dataIndex: 'category',
      title: '办事处'
    },
    {
      dataIndex: 'lastLogin',
      title: '最后登录时间',
      sortOrder: 'ascend',
      customRender: ({ text }) => <span>{text ? formatToDateTime(text, 'YYYY-MM-DD HH:mm:ss') : null}</span>
    },
    {
      dataIndex: 'loginIp',
      title: '最近登录IP'
    },
    {
      dataIndex: 'groupId',
      title: '用户组',
      customRender: ({ text }) => <span>{permGroupList.value.find(item => item.id === text)?.name}</span>
    },
    {
      dataIndex: 'opreate',
      title: '操作',
      customRender: ({ record }) =>
        !record.isAdmin && (
          <span class="text-[#007BFF] hover:text-[#005BB8] cursor-pointer">
            <Icon icon="fluent:edit-32-filled" onClick={() => fn(record)}></Icon>
          </span>
        )
    }
  ]
}
