import { hasPermission } from '@/utils/composables/permission'

function error(permPath: string) {
  if (permPath === undefined) {
    throw new Error('Button permission url is required!!!')
  }
}

export default {
  agree: {
    if: (row: any, permPath: string) => {
      error(permPath)
      return hasPermission(permPath) && row.approvalStatusName === '待审批'
    },
    disabled: (row: any) => {
      return row.approvalStatusName !== '待审批' && row.approvalStatusName !== '审批中'
    },
  },
  reject: {
    if: (row: any, permPath: string) => {
      error(permPath)
      return hasPermission(permPath) && row.approvalStatusName === '待审批'
    },
    disabled: (row: any) => {
      return row.approvalStatusName !== '待审批' && row.approvalStatusName !== '审批中'
    },
  },
  refuse: {
    if: (row: any, permPath: string) => {
      error(permPath)
      return hasPermission(permPath) && row.approvalStatusName === '待审批' && [1, 3].includes(row.decisionItem)
    },
    disabled: (row: any) => {
      return row.approvalStatusName !== '待审批' && row.approvalStatusName !== '审批中'
    },
  },
  edit: {
    if: (row: any, permPath: string) => {
      error(permPath)

      return hasPermission(permPath) && row.approvalStatusName === '全部'
    },
  },
  submit: {
    if: (row: any, permPath: string) => {
      // permPath ? console.log(permPath) : ''
      return row.approvalStatusName === '草稿箱' || row.approvalStatusName === '已取消'
    },
  },
  cancel: {
    if: (row: any, permPath: string) => {
      error(permPath)
      return hasPermission(permPath) && row.approvalStatusName === '审批中'
    },
    disabled: (row: any) => {
      return row.approvalStatusName !== '审批中'
    },
  },
  delete: {
    if: (row: any, permPath: string) => {
      error(permPath)
      return hasPermission(permPath) && row.approvalStatusName !== '待审批' && row.approvalStatusName !== '未通过' && row.approvalStatusName !== '已通过' && row.approvalStatusName !== '审批中' && row.approvalStatusName !== '审批' && row.approvalStatusName !== '已审批'
    },
    disabled: (row: any) => {
      return row.approvalStatusName === '未通过' || row.approvalStatusName === '已通过'
    },
  },
}
