<template>
  <PostcardBase
    :notification="notification"
    :displayTitle="displayTitle"
    @mark-read="emit('mark-read', $event)"
    @delete="emit('delete', $event)"
  >
    <template #body>
      <view class="report-body">
        <view class="badge-row">
          <text class="badge" :class="actionColor">{{ actionText }}</text>
          <text v-if="targetType" class="target">目标: {{ targetType }}#{{ targetId }}</text>
        </view>
        <view v-if="categoryCode" class="chip-row">
          <text class="chip-label">分类:</text>
          <text class="chip-value">{{ categoryCode }}</text>
        </view>
        <view v-if="reportId" class="chip-row chip-row-muted">
          <text class="chip-label">举报 ID:</text>
          <text class="chip-value">{{ reportId }}</text>
        </view>
        <view class="report-content">
          <text>{{ notification.content }}</text>
        </view>
      </view>
    </template>
  </PostcardBase>
</template>

<script setup>
import { computed } from 'vue'
import PostcardBase from './PostcardBase.vue'
import { parseData, actionLabel, actionColorClass } from './postcardHelpers.js'

const props = defineProps({
  notification:  { type: Object, required: true },
  displayTitle:  { type: String, default: '' },
})
const emit = defineEmits(['mark-read', 'delete'])

const data = computed(() => parseData(props.notification.data))
// 后端 moderation_admin.py 用 action(规范名);老数据可能用 resolved_action
const rawAction = computed(() => data.value.resolved_action || data.value.action || '')
const actionText = computed(() => actionLabel(rawAction.value))
const actionColor = computed(() => actionColorClass(rawAction.value))
const targetType   = computed(() => data.value.target_type || '')
const targetId     = computed(() => data.value.target_id   || '')
const categoryCode = computed(() => data.value.category_code || '')
const reportId     = computed(() => data.value.report_id     || '')
</script>

<style lang="scss" scoped>
.report-body {
  .badge-row {
    display: flex;
    align-items: center;
    gap: 16rpx;
    margin-bottom: 12rpx;
    .badge {
      display: inline-block;
      padding: 4rpx 16rpx;
      border-radius: 8rpx;
      font-size: 22rpx;
      color: #fff;
      &.badge-red    { background: #f5222d; }
      &.badge-orange { background: #fa8c16; }
      &.badge-green  { background: #52c41a; }
      &.badge-gray   { background: #999; }
    }
    .target { font-size: 24rpx; color: #666; }
  }
  .chip-row {
    display: flex;
    font-size: 24rpx;
    padding: 6rpx 0;
    .chip-label { color: #999; margin-right: 16rpx; min-width: 140rpx; }
    .chip-value { color: #333; }
  }
  .chip-row-muted .chip-value { color: #888; font-family: monospace; }
  .report-content {
    margin-top: 16rpx;
    font-size: 28rpx;
    line-height: 1.7;
    color: #333;
    white-space: pre-wrap;
  }
}
</style>