import { message } from '@/common/one-ui'
import FlowService from '../flow-service'

export default function({ button }) {
  const duration = 1
  const key = 'key'
  const title = this.getFieldValue('title') || this.FlowData.pageTitle
  message.loading({ content: '处理中...', key })
  if (button.buttonId === 'workflow$myAttention') {
    return FlowService.attention(this.FlowData.instId, title, '').then(
      () => {
        message.success({ content: '关注成功', key, duration })
        this.updateFlow()
      },
      (_) => {
        message.error({ content: '关注失败', key, duration })
      }
    )
  } else {
    return FlowService.attention(this.FlowData.instId, '', 'retract').then(
      () => {
        message.success({ content: '取消关注成功', key, duration })
        this.updateFlow()
      },
      (_) => {
        message.error({ content: '取消关注失败', key, duration })
      }
    )
  }
}
