<script setup lang="ts">
import type { AdminTaskDetail } from '@/types/admin'

interface Props {
  detail: AdminTaskDetail
  actionLoading: boolean
  canManageTaskLifecycle: boolean
  canCloseTasks: boolean
}

defineProps<Props>()

const emit = defineEmits<{
  retry: []
  regenerateClaimLink: []
  confirmRole: []
  supportRedeem: []
  prepareKuaishouCloud: []
  dispatchKuaishouCloud: []
  returnKuaishouCloud: []
  markManualReview: []
  submitManualDispatch: [outcome: 'delivered' | 'failed']
  closeTask: []
}>()
</script>

<template>
  <section class="action-row">
    <el-button
      v-if="canManageTaskLifecycle"
      :disabled="!detail.operations.canRetry"
      :loading="actionLoading"
      round
      type="primary"
      @click="emit('retry')"
    >
      重试任务
    </el-button>
    <el-button
      v-if="detail.operations.canRegenerateClaimLink"
      :disabled="!detail.operations.canRegenerateClaimLink"
      :loading="actionLoading"
      round
      @click="emit('regenerateClaimLink')"
    >
      重发链接
    </el-button>
    <el-button
      v-if="detail.operations.canSupportConfirmRole"
      :loading="actionLoading"
      round
      type="warning"
      @click="emit('confirmRole')"
    >
      客服确认角色
    </el-button>
    <el-button
      v-if="detail.operations.canSupportRedeem"
      :loading="actionLoading"
      round
      type="success"
      @click="emit('supportRedeem')"
    >
      客服开始兑换
    </el-button>
    <el-button
      v-if="canManageTaskLifecycle && detail.operations.canPrepareKuaishouCloudFulfillment"
      :loading="actionLoading"
      round
      type="primary"
      @click="emit('prepareKuaishouCloud')"
    >
      准备绑定资源
    </el-button>
    <el-button
      v-if="canManageTaskLifecycle && detail.operations.canDispatchKuaishouCloudFulfillment"
      :loading="actionLoading"
      round
      type="success"
      @click="emit('dispatchKuaishouCloud')"
    >
      确认绑定完成并发货
    </el-button>
    <el-button
      v-if="canManageTaskLifecycle && detail.operations.canReturnKuaishouCloudFulfillment"
      :loading="actionLoading"
      round
      type="warning"
      @click="emit('returnKuaishouCloud')"
    >
      退还号码
    </el-button>
    <el-button
      v-if="canManageTaskLifecycle"
      :disabled="!detail.operations.canMarkManualReview"
      :loading="actionLoading"
      round
      @click="emit('markManualReview')"
    >
      转人工
    </el-button>
    <el-button
      v-if="canManageTaskLifecycle && detail.operations.canCompleteManualDispatch"
      :loading="actionLoading"
      round
      type="success"
      @click="emit('submitManualDispatch', 'delivered')"
    >
      人工完成
    </el-button>
    <el-button
      v-if="canManageTaskLifecycle && detail.operations.canCompleteManualDispatch"
      :loading="actionLoading"
      round
      type="danger"
      plain
      @click="emit('submitManualDispatch', 'failed')"
    >
      履约失败
    </el-button>
    <el-button
      v-if="canCloseTasks"
      :disabled="!detail.operations.canClose"
      :loading="actionLoading"
      round
      type="danger"
      @click="emit('closeTask')"
    >
      关闭任务
    </el-button>
  </section>
</template>

<style scoped src="../AdminTaskDetail.css"></style>
