<template>
  <view class="equipment-section">
    <view class="section-title">{{ title }}</view>
    <view class="equipment-list">
      <view
        v-for="equipment in equipmentList"
        :key="equipment.id"
        class="equipment-item"
        @click="onEquipmentClick(equipment)"
      >
        <image :src="equipment.image" class="equipment-image" mode="aspectFit"></image>
        <view class="equipment-info">
          <view class="equipment-header">
            <text class="equipment-name">{{ equipment.name }}</text>
          </view>
          <view class="equipment-details">
            <view class="detail-item-row">
              <text class="detail-item-time">租赁时间:</text>
              <text class="detail-item">{{ equipment.startTime }}</text>
            </view>
            <view class="detail-item-row">
              <text class="detail-item-time">到期时间:</text>
              <text class="detail-item">{{ equipment.endTime }}</text>
            </view>
          </view>
          <button class="renew-btn" @click.stop="onRenew(equipment)">去续费</button>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'EquipmentList',
  props: {
    title: {
      type: String,
      default: '我的租赁设备',
    },
    equipmentList: {
      type: Array,
      default: () => [],
    },
  },
  methods: {
    getStatusText(status) {
      const statusMap = {
        available: '可租用',
        rented: '已出租',
        maintenance: '维护中',
        scrapped: '报废',
        normal: '正常',
        warning: '警告',
        error: '异常',
      }
      return statusMap[status] || '未知'
    },

    onEquipmentClick(equipment) {
      this.$emit('equipment-click', equipment)
    },

    onRenew(equipment) {
      this.$emit('renew', equipment)
    },
  },
}
</script>

<style lang="scss" scoped>
.equipment-section {
  padding: 0 30rpx;
}

.section-title {
  width: 180rpx;
  height: 33rpx;
  background: #ffffff;
  font-size: 14px;
  font-weight: 400;
  color: #3d3d3d;
  margin-bottom: 20rpx;
  padding: 14rpx 20rpx;
  border-radius: 4px;
}

.equipment-list {
  display: flex;
  flex-direction: column;
  gap: 20rpx;
}

.equipment-item {
  background: #fff;
  border-radius: 20rpx;
  padding: 30rpx;
  display: flex;
  gap: 30rpx;
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  justify-content: center;
  align-items: center;

  .equipment-image {
    width: 160rpx;
    height: 106rpx;
    border-radius: 10rpx;
    background-color: #f8f9fa;
    flex-shrink: 0;
  }
}

.equipment-item:active {
  transform: scale(0.98);
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.15);
}

.equipment-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.equipment-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15rpx;
}

.equipment-name {
  font-size: 16px;
  font-weight: 500;
  color: #3d3d3d;
}

.status-badge {
  padding: 4rpx 26rpx;
  border-radius: 5rpx;
  font-size: 24rpx;
  color: #40c186;

  &.available {
    background-color: #e6f7ff;
    color: #1890ff;
  }

  &.rented {
    background-color: #ebfff6;
    color: #40c186;
  }

  &.maintenance {
    background-color: #fff7e6;
    color: #fa8c16;
  }

  &.scrapped {
    background-color: #fff1f0;
    color: #ff4d4f;
  }

  &.normal {
    background-color: #ebfff6;
  }

  &.warning {
    background-color: #faad14;
  }

  &.error {
    background-color: #ff4d4f;
  }
}

.equipment-details {
  display: flex;
  flex-direction: column;
  gap: 8rpx;
  margin-bottom: 15rpx;
}

.detail-item-row {
  display: flex;
  justify-content: space-between;

  .detail-item-time {
    color: #817f7f;
    font-size: 26rpx;
  }

  .detail-item {
    font-size: 24rpx;
    color: #666;
  }
}

.renew-btn {
  margin-right: 0;
  background: #f15a04;
  color: #fff;
  border-radius: 5px;
  padding: 0 57rpx;
  font-size: 32rpx;
  font-weight: 500;
  margin-top: 10rpx;
}
</style>
