<template>
  <view class="product-item-container">
    <view class="is-collect"></view>
    <image :src="product.cover" class="w-328rpx" mode="widthFix"></image>
    <view class="product-name">{{ product.name }}</view>
    <view class="sell-rate">
      <view class="rate">
        <view v-format.rate>{{ product.rate }}</view>
        <image src="@/static/images/rate.svg" class="w-28rpx ml-8rpx" mode="widthFix"></image>
      </view>
      <view class="sold">{{ product.sold }} Sold</view>
    </view>
    <view class="price-cart">
      <view class="flex">
        USD
        <view class="ml-8rpx" v-format.price>{{ product.price }}</view>
      </view>
      <view class="cart">
        <image src="@/static/images/cart.svg" class="w-32rpx" mode="widthFix"></image>
      </view>
    </view>
  </view>
</template>

<script lang="ts" setup>
  import { ProductSimpleType } from '@/model/product-type'

  defineOptions({
    name: 'ProductItem',
  })
  const { product } = defineProps<{ product: ProductSimpleType }>()
</script>

<style lang="scss" scoped>
  .product-item-container {
    position: relative;
    width: 328rpx;
    margin-bottom: 26rpx;

    &:nth-last-child(1),
    &:nth-last-child(2) {
      margin-bottom: 0;
    }

    .is-collect {
      position: absolute;
      display: flex;
      align-items: center;
      justify-content: center;
      width: 64rpx;
      height: 64rpx;
      background-color: $shop-white;
    }

    .product-name {
      height: 30rpx;
      margin-top: 16rpx;
      overflow: hidden;
      font-family: 'PingFang SC';
      font-size: 28rpx;
      font-style: normal;
      font-weight: 600;
      line-height: 30rpx;
      color: $shop-text-3;
      white-space: nowrap;
    }

    .sell-rate {
      display: flex;
      align-items: center;
      margin-top: 16rpx;
      font-family: 'PingFang SC';
      font-size: 24rpx;
      font-style: normal;
      font-weight: 400;
      line-height: 28rpx;
      color: $shop-text-9;

      .rate {
        display: flex;
        margin-right: 16rpx;
      }

      .sold {
        box-sizing: border-box;
        padding-left: 16rpx;
        border-left: 2rpx solid $shop-bg-line;
      }
    }

    .price-cart {
      display: flex;
      align-items: center;
      justify-content: space-between;
      font-family: 'PingFang SC';
      font-size: 28rpx;
      font-style: normal;
      font-weight: 600;
      line-height: 48rpx; /* 157.143% */
      color: $shop-primary;

      .price {
        display: flex;
      }

      .cart {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 48rpx;
        height: 48rpx;
        background-color: $shop-primary;
        border-radius: 50%;
      }
    }
  }
</style>
