<script setup lang="ts">
import AdminStatusTag from '@/components/admin/AdminStatusTag.vue'
import type { AdminTaskDetail } from '@/types/admin'
import { formatAutoDeliveryReason, formatAutoDeliveryTrigger } from '@/utils/admin-display'
import { formatAdminDateTime } from '@/utils/admin-time'

interface Props {
  detail: AdminTaskDetail
  autoDeliveryStatus: string
  autoDeliverySummary: string
}

defineProps<Props>()
</script>

<template>
  <section class="info-card">
    <h3>咸鱼自动发货</h3>
    <p class="section-copy">
      这里展示这条任务最近一次触发咸鱼自动发货的状态、原因和接口回执摘要。
    </p>

    <div class="redeem-summary-grid">
      <article class="redeem-summary-card">
        <span>当前状态</span>
        <div class="auto-delivery-tag-line">
          <AdminStatusTag :status="autoDeliveryStatus" />
        </div>
      </article>
      <article class="redeem-summary-card">
        <span>触发来源</span>
        <strong>{{
          formatAutoDeliveryTrigger(detail.task.agisoAutoDelivery?.trigger || '')
        }}</strong>
      </article>
      <article class="redeem-summary-card">
        <span>最近执行</span>
        <strong>{{ formatAdminDateTime(detail.task.agisoAutoDelivery?.updatedAt) }}</strong>
      </article>
      <article class="redeem-summary-card">
        <span>接口回执</span>
        <strong>
          {{
            detail.task.agisoAutoDelivery?.requestId ||
            (detail.task.agisoAutoDelivery?.responseStatus
              ? `HTTP ${detail.task.agisoAutoDelivery.responseStatus}`
              : '-')
          }}
        </strong>
      </article>
    </div>

    <div class="auto-delivery-note">
      <p>{{ autoDeliverySummary }}</p>
      <p v-if="detail.task.agisoAutoDelivery?.reason">
        原因：{{ formatAutoDeliveryReason(detail.task.agisoAutoDelivery.reason) }}
      </p>
      <p v-if="detail.task.agisoAutoDelivery?.responseStatus">
        HTTP：{{ detail.task.agisoAutoDelivery.responseStatus }}
      </p>
      <p v-if="detail.task.agisoAutoDelivery?.requestId">
        请求 ID：{{ detail.task.agisoAutoDelivery.requestId }}
      </p>
    </div>
  </section>
</template>

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