import type { TableColumn, ActionButton } from '../types'
import { DICT_TYPE } from '@/utils/dict'
import { dateFormatter, formatPast2 } from '@/utils/formatTime'

// 抄送我的流程 - 表格列配置
export const copyTableColumns: TableColumn[] = [
  {
    prop: 'processInstanceName',
    label: '流程名',
    minWidth: 180,
    align: 'center'
  },
  {
    prop: 'startUser.nickname',
    label: '流程发起人',
    minWidth: 100,
    align: 'center'
  },
  {
    prop: 'processInstanceStartTime',
    label: '流程发起时间',
    width: 180,
    align: 'center',
    formatter: (row: any) => dateFormatter(row, {}, row.processInstanceStartTime)
  },
  {
    prop: 'activityName',
    label: '抄送节点',
    minWidth: 180,
    align: 'center'
  },
  {
    prop: 'createUser.nickname',
    label: '抄送人',
    minWidth: 100,
    align: 'center',
    render: (h: any, { row }: any) => {
      return h('span', {}, row.createUser?.nickname || '系统')
    }
  },
  {
    prop: 'reason',
    label: '抄送意见',
    width: 150,
    align: 'center'
  },
  {
    prop: 'createTime',
    label: '抄送时间',
    width: 180,
    align: 'center',
    formatter: (row: any) => dateFormatter(row, {}, row.createTime)
  }
]

// 待办任务 - 表格列配置
export const todoTableColumns: TableColumn[] = [
  {
    prop: 'processInstance.name',
    label: '流程',
    width: 180,
    align: 'center'
  },
  {
    prop: 'processInstance.startUser.nickname',
    label: '发起人',
    width: 100,
    align: 'center'
  },
  {
    prop: 'processInstance.createTime',
    label: '发起时间',
    width: 180,
    align: 'center',
    formatter: (row: any) => dateFormatter(row, {}, row.processInstance?.createTime)
  },
  {
    prop: 'name',
    label: '当前任务',
    width: 180,
    align: 'center'
  },
  {
    prop: 'createTime',
    label: '任务时间',
    width: 180,
    align: 'center',
    formatter: (row: any) => dateFormatter(row, {}, row.createTime)
  },
  {
    prop: 'processInstanceId',
    label: '流程编号',
    align: 'center',
    showOverflowTooltip: true
  },
  {
    prop: 'id',
    label: '任务编号',
    align: 'center',
    showOverflowTooltip: true
  }
]

// 已办任务 - 表格列配置
export const doneTableColumns: TableColumn[] = [
  {
    prop: 'processInstance.name',
    label: '流程',
    width: 180,
    align: 'center'
  },
  {
    prop: 'processInstance.startUser.nickname',
    label: '发起人',
    width: 100,
    align: 'center'
  },
  {
    prop: 'createTime',
    label: '发起时间',
    width: 180,
    align: 'center',
    formatter: (row: any) => dateFormatter(row, {}, row.createTime)
  },
  {
    prop: 'name',
    label: '当前任务',
    width: 180,
    align: 'center'
  },
  {
    prop: 'createTime',
    label: '任务开始时间',
    width: 180,
    align: 'center',
    formatter: (row: any) => dateFormatter(row, {}, row.createTime)
  },
  {
    prop: 'endTime',
    label: '任务结束时间',
    width: 180,
    align: 'center',
    formatter: (row: any) => dateFormatter(row, {}, row.endTime)
  },
  {
    prop: 'status',
    label: '审批状态',
    width: 120,
    align: 'center',
    dictType: DICT_TYPE.BPM_TASK_STATUS
  },
  {
    prop: 'reason',
    label: '审批建议',
    minWidth: 180,
    align: 'center'
  },
  {
    prop: 'durationInMillis',
    label: '耗时',
    width: 160,
    align: 'center',
    render: (h: any, { row }: any) => {
      return h('span', {}, formatPast2(row.durationInMillis))
    }
  },
  {
    prop: 'processInstanceId',
    label: '流程编号',
    align: 'center',
    showOverflowTooltip: true
  },
  {
    prop: 'id',
    label: '任务编号',
    align: 'center',
    showOverflowTooltip: true
  }
]

// 管理任务 - 表格列配置
export const managerTableColumns: TableColumn[] = [
  {
    prop: 'processInstance.name',
    label: '流程',
    width: 180,
    align: 'center'
  },
  {
    prop: 'processInstance.startUser.nickname',
    label: '发起人',
    width: 100,
    align: 'center'
  },
  {
    prop: 'createTime',
    label: '发起时间',
    width: 180,
    align: 'center',
    formatter: (row: any) => dateFormatter(row, {}, row.createTime)
  },
  {
    prop: 'name',
    label: '当前任务',
    width: 180,
    align: 'center'
  },
  {
    prop: 'createTime',
    label: '任务开始时间',
    width: 180,
    align: 'center',
    formatter: (row: any) => dateFormatter(row, {}, row.createTime)
  },
  {
    prop: 'endTime',
    label: '任务结束时间',
    width: 180,
    align: 'center',
    formatter: (row: any) => dateFormatter(row, {}, row.endTime)
  },
  {
    prop: 'assigneeUser.nickname',
    label: '审批人',
    width: 100,
    align: 'center'
  },
  {
    prop: 'status',
    label: '审批状态',
    width: 120,
    align: 'center',
    dictType: DICT_TYPE.BPM_TASK_STATUS
  },
  {
    prop: 'reason',
    label: '审批建议',
    minWidth: 180,
    align: 'center'
  },
  {
    prop: 'durationInMillis',
    label: '耗时',
    width: 160,
    align: 'center',
    render: (h: any, { row }: any) => {
      return h('span', {}, formatPast2(row.durationInMillis))
    }
  },
  {
    prop: 'processInstanceId',
    label: '流程编号',
    align: 'center',
    showOverflowTooltip: true
  },
  {
    prop: 'id',
    label: '任务编号',
    align: 'center',
    showOverflowTooltip: true
  }
]

// 操作按钮配置
export const createCopyActions = (handler: (row: any) => void): ActionButton[] => [
  {
    label: '详情',
    type: 'primary',
    link: true,
    handler
  }
]

export const createTodoActions = (handler: (row: any) => void): ActionButton[] => [
  {
    label: '办理',
    type: 'primary',
    link: true,
    handler
  }
]

export const createDoneActions = (handler: (row: any) => void): ActionButton[] => [
  {
    label: '历史',
    type: 'primary',
    link: true,
    handler
  }
]

export const createManagerActions = (handler: (row: any) => void): ActionButton[] => [
  {
    label: '历史',
    type: 'primary',
    link: true,
    handler
  }
]