<template>
  <view v-if="showBlock" class="express-panel">
    <view class="section-title">物流信息</view>
    <template v-if="display.hasData">
      <view class="row"><text>物流公司</text><text>{{ display.companyName }}</text></view>
      <view class="row"><text>运单号</text><text>{{ display.expressNo }}</text></view>
      <view class="row"><text>最新状态</text><text class="highlight-text">{{ display.stateText }}</text></view>

      <view v-if="display.tracks.length" class="timeline">
        <view class="timeline-title">物流追踪</view>
        <view v-for="(t, idx) in display.tracks" :key="idx" class="track-item">
          <view class="track-dot" :class="{ 'active': idx === 0 }" />
          <view class="track-body">
            <text class="track-status" :class="{ 'active': idx === 0 }">{{ t.status }}</text>
            <text class="track-detail">{{ t.detail }}</text>
            <text class="track-time">{{ t.time }}</text>
          </view>
        </view>
      </view>
    </template>
    <view v-else class="empty-express">暂无物流信息</view>
  </view>
</template>

<script>
import { mapExpressDetail } from '@/subPackages/sub_business_shared/common/display.js'

import businessMixin from '@/subPackages/sub_business_shared/common/businessMixin.js'

export default {
  mixins: [businessMixin],
  name: 'ExpressTimeline',
  props: {
    express: { type: Object, default: null },
    show: { type: Boolean, default: true },
  },
  computed: {
    showBlock() {
      return this.show
    },
    display() {
      return mapExpressDetail(this.express)
    },
  },
}
</script>

<style lang="scss" scoped>
$theme-primary: #6acdbb;
$color-text-title: #222B2A;
$color-text-body: #4E5969;
$color-text-muted: #86909C;
$color-border: #F2F3F5;

.express-panel {
  background: #ffffff;
  padding: 32rpx 40rpx;
  margin-bottom: 24rpx;
  /* 移除圆角和阴影，采用通栏设计 */
}

.section-title {
  font-size: 32rpx;
  font-weight: 700;
  color: $color-text-title;
  margin-bottom: 16rpx;
}

.row {
  display: flex;
  justify-content: space-between;
  padding: 24rpx 0;
  font-size: 28rpx;
  border-bottom: 1rpx solid $color-border;
  gap: 24rpx;

  text:first-child {
    color: $color-text-muted;
  }

  text:last-child {
    color: $color-text-title;
    text-align: right;
    flex: 1;
    word-break: break-all;
  }

  .highlight-text {
    color: $theme-primary;
    font-weight: 500;
  }
}

.timeline-title {
  font-size: 28rpx;
  color: $color-text-title;
  font-weight: 600;
  margin: 32rpx 0 24rpx;
}

.track-item {
  display: flex;
  padding: 0;
  margin-bottom: 16rpx;
}

.track-dot {
  width: 16rpx;
  height: 16rpx;
  border-radius: 50%;
  background: $color-border;
  margin-top: 12rpx;
  flex-shrink: 0;
  border: 4rpx solid #ffffff;
  box-shadow: 0 0 0 2rpx $color-border;

  &.active {
    background: $theme-primary;
    box-shadow: 0 0 0 4rpx rgba(106, 205, 187, 0.2);
    border-color: #ffffff;
  }
}

.track-body {
  flex: 1;
  margin-left: 28rpx;
  padding-bottom: 32rpx;
  border-left: 2rpx solid $color-border;
  padding-left: 28rpx;
  margin-left: 8rpx;
}

/* 最后一个元素去掉线 */
.track-item:last-child .track-body {
  border-left-color: transparent;
  padding-bottom: 0;
}

.track-status {
  display: block;
  font-size: 28rpx;
  color: $color-text-body;
  font-weight: 500;
  margin-bottom: 8rpx;

  &.active {
    color: $theme-primary;
  }
}

.track-detail {
  display: block;
  font-size: 26rpx;
  color: $color-text-body;
  line-height: 1.5;
  margin-bottom: 12rpx;
}

.track-time {
  display: block;
  font-size: 24rpx;
  color: $color-text-muted;
}

.empty-express {
  text-align: center;
  color: $color-text-muted;
  font-size: 26rpx;
  padding: 40rpx 0;
}
</style>