<template>
  <view class="exhibition-center">
    <text class="section-title">展出收益中心</text>

    <!-- 错误态 -->
    <view v-if="error" class="error-box" @tap="$emit('retry')">
      <text class="error-text">加载失败，点击重试</text>
    </view>

    <!-- 骨架态 -->
    <view v-else-if="loading || !data" class="skeleton-section">
      <view class="skeleton-stats"></view>
      <view class="skeleton-rows">
        <view v-for="i in 5" :key="i" class="skeleton-row"></view>
      </view>
    </view>

    <!-- 正常态 -->
    <view v-else>
      <!-- 顶部 3 联统计 -->
      <view class="stats-row">
        <view class="stat-cell">
          <text class="stat-value">{{ data.exhibiting_count }} / {{ data.starbook_count }}</text>
          <text class="stat-label">展出中 / 星册中</text>
        </view>
        <view class="stat-cell">
          <text class="stat-value">{{ data.total_duration }}</text>
          <text class="stat-label">累计展出时长</text>
        </view>
        <view class="stat-cell">
          <text class="stat-value">{{ data.total_earnings }}</text>
          <text class="stat-label">累计展出收益</text>
        </view>
      </view>

      <!-- 5 行表格 -->
      <view class="table">
        <view class="table-header">
          <text class="th th-thumb"></text>
          <text class="th th-duration">七日展出时长</text>
          <text class="th th-earnings">七日收益</text>
          <text class="th th-avg">平均收益</text>
        </view>
        <view
          v-for="(item, idx) in data.top5"
          :key="item.asset_id"
          class="table-row"
        >
          <view class="td td-thumb">
            <view class="thumb-placeholder" :class="`thumb-grad-${idx % 5}`">
              <text class="thumb-emoji">🎨</text>
            </view>
          </view>
          <text class="td td-duration">{{ item.duration_7d }}</text>
          <text class="td td-earnings">{{ item.earnings_7d }}</text>
          <text class="td td-avg">{{ item.avg_earnings }} / H</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
defineProps({
  data: { type: Object, default: null }, // ExhibitionIncomeSummary
  loading: { type: Boolean, default: false },
  error: { type: String, default: null },
})
defineEmits(['retry'])
</script>

<style lang="scss" scoped>
.exhibition-center {
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(10px);
  border-radius: 22rpx;
  padding: 24rpx;
  margin: 24rpx 0;
  box-shadow: 0px 4px 4px rgba(0, 0, 0, 0.15);
}

.section-title {
  display: block;
  font-size: 36rpx;
  font-weight: 700;
  color: #ffffff;
  margin-bottom: 24rpx;
  text-shadow: 0px 2px 4px rgba(0, 0, 0, 0.3);
}

.stats-row {
  display: flex;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 17rpx;
  padding: 24rpx 0;
  margin-bottom: 24rpx;
}

.stat-cell {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  border-right: 1px solid rgba(255, 255, 255, 0.1);

  &:last-child {
    border-right: none;
  }
}

.stat-value {
  font-size: 32rpx;
  font-weight: 700;
  color: #FFFABD;
  font-family: 'Baloo Bhai', sans-serif;
  margin-bottom: 8rpx;
}

.stat-label {
  font-size: 22rpx;
  color: rgba(255, 255, 255, 0.7);
}

.table {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 14rpx;
  overflow: hidden;
}

.table-header,
.table-row {
  display: flex;
  align-items: center;
  padding: 16rpx 12rpx;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.table-row:last-child {
  border-bottom: none;
}

.th,
.td {
  font-size: 24rpx;
  color: #ffffff;
  text-align: center;
}

.th-thumb,
.td-thumb {
  width: 80rpx;
  flex-shrink: 0;
}

.th-duration,
.td-duration,
.th-earnings,
.td-earnings {
  flex: 1;
}

.th-avg,
.td-avg {
  width: 100rpx;
  flex-shrink: 0;
}

.th {
  font-size: 20rpx;
  color: rgba(255, 255, 255, 0.6);
}

.thumb-placeholder {
  width: 56rpx;
  height: 56rpx;
  border-radius: 3rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
}

.thumb-grad-0 { background: linear-gradient(135deg, #FF6B6B 0%, #FFB199 100%); }
.thumb-grad-1 { background: linear-gradient(135deg, #B17BFF 0%, #FF8FE6 100%); }
.thumb-grad-2 { background: linear-gradient(135deg, #5EDFFF 0%, #6FA9FF 100%); }
.thumb-grad-3 { background: linear-gradient(135deg, #FFE066 0%, #FFB199 100%); }
.thumb-grad-4 { background: linear-gradient(135deg, #C5C5C5 0%, #8C8C8C 100%); }

.thumb-emoji {
  font-size: 32rpx;
}

.td-earnings {
  color: #FFFABD;
  font-weight: 600;
  font-family: 'Baloo Bhai', sans-serif;
}

/* 骨架 */
.skeleton-section {
  display: flex;
  flex-direction: column;
  gap: 16rpx;
}

.skeleton-stats {
  height: 120rpx;
  border-radius: 17rpx;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.05) 25%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.05) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

.skeleton-rows {
  display: flex;
  flex-direction: column;
  gap: 12rpx;
}

.skeleton-row {
  height: 80rpx;
  border-radius: 14rpx;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.05) 25%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.05) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.error-box {
  height: 240rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 100, 100, 0.15);
  border: 2rpx solid rgba(255, 100, 100, 0.4);
  border-radius: 17rpx;
}

.error-text {
  color: #ff8080;
  font-size: 28rpx;
}
</style>
