<template>
  <view class="product-item" @click="handleClick">
    <view class="product-image">
      <image :src="item.picurl" mode="aspectFill" />
      <!-- 视频播放图标 -->
      <view v-if="item.isVideo" class="play-icon">
        <i class="icon-font icon-play"></i>
      </view>
    </view>
    <view class="product-info">
      <view class="product-title">{{ item.goodsName }}</view>
      <view class="product-middle">
        <view class="product-sales">
          <trans _t="已售" />
          {{ item.sale }}</view
        >
        <view class="favorite-icon" @click.stop="toggleFavorite">
          <image
            class="img"
            :src="
              item.iscollect
                ? '/static/seller/collect_active.png'
                : '/static/seller/collect.png'
            "
          ></image>
        </view>
      </view>

      <view class="product-price">
        <text class="current-price">{{ symbol }} {{ item.price }}</text>
        <text class="original-price"
          >{{ symbol }} {{ item.originalprice }}</text
        >
      </view>
    </view>
  </view>
</template>

<script setup>
import { computed } from "vue";
import { useSystemStore } from "@/store";

const useSystem = useSystemStore();
const symbol = computed(() => useSystem.getSymbol.symbol);
const props = defineProps({
  item: {
    type: Object,
    required: true,
  },
});

const emit = defineEmits(["click", "favorite"]);

const handleClick = () => {
  emit("click", props.item);
};

const toggleFavorite = () => {
  emit("favorite", props.item);
};
</script>

<style lang="less" scoped>
@import url("@/style.less");

.product-item {
  background: var(--light);
  border-radius: 16rpx;
  overflow: hidden;
  margin-bottom: 20rpx;
  box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);

  .product-image {
    width: 100%;
    height: 300rpx;
    position: relative;

    image {
      width: 100%;
      height: 100%;
    }

    .play-icon {
      position: absolute;
      top: 20rpx;
      left: 20rpx;
      width: 60rpx;
      height: 60rpx;
      background: rgba(0, 0, 0, 0.6);
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;

      .icon-play {
        color: white;
        font-size: 32rpx;
      }
    }
  }

  .product-info {
    padding: 24rpx;

    .product-title {
      font-size: 28rpx;
      color: var(--black);
      line-height: 1.4;
      margin-bottom: 12rpx;
      .ellipsis(2);
    }
    .product-middle {
      width: 100%;
      .flex_position(space-between);
      margin-bottom: 12rpx;
      .product-sales {
        .size(24rpx);
        color: #fe7907;
      }
      .favorite-icon {
        width: 32rpx;
        height: 32rpx;
        .img {
          width: 100%;
          height: 100%;
        }
      }
    }

    .product-price {
      display: flex;
      align-items: baseline;
      gap: 12rpx;

      .current-price {
        font-size: 32rpx;
        font-weight: bold;
        color: var(--red);
      }

      .original-price {
        font-size: 24rpx;
        color: var(--text-01);
        text-decoration: line-through;
      }
    }
  }
}
</style>
