import { statusListMap, peddingListMap, subjectLocationStatusName } from '../constants/index'

export default function useRadio(certList: any) {
  const getRadio = (subjectLocationItem: string): boolean => {
    // OTHER 直接返回
    if (subjectLocationItem === 'OTHER') return false
    const current = certList.value.find((item: any) => item.subjectLocation === subjectLocationItem)
    if (!current) return true
    const certStatus = current.certStatus
    const callbackStatus = current.callbackStatus
    // 渠道认证进行中, 不允许操作
    if (callbackStatus === 'IN_PROGRESS') return false
    // 显示checkbox的情况
    const currentList = statusListMap[subjectLocationItem]
    return currentList.includes(certStatus)
  }

  const IS_IN_PROGRESS = (subjectLocationItem: string): boolean => {
    const current = certList.value.find((item: any) => item.subjectLocation === subjectLocationItem)
    if (!current) return false
    const callbackStatus = current.callbackStatus
    // 渠道认证进行中, 不允许操作
    return callbackStatus === 'IN_PROGRESS'
  }

  const getStatusText = (subjectLocationItem: string): boolean => {
    const current = certList.value.find((item: any) => item.subjectLocation === subjectLocationItem)
    if (!current) return false
    const certStatus = current.certStatus
    const callbackStatus = current.callbackStatus
    // 渠道认证进行中, 不允许操作
    if (callbackStatus === 'IN_PROGRESS') return false
    const currentList = peddingListMap[subjectLocationItem]
    return currentList.includes(certStatus)
  }

  const getStatusName = (subjectLocationItem: string): string => {
    const current = certList.value.find((item: any) => item.subjectLocation === subjectLocationItem)
    if (!current) return ''
    const certStatus = current.certStatus
    const currMap = subjectLocationStatusName[subjectLocationItem]
    return currMap[certStatus]
  }
  return {
    getRadio,
    IS_IN_PROGRESS,
    getStatusText,
    getStatusName
  }
}
