<template>
  <el-card class="api-card" @click="goToDetail">
    <div class="card-content">
      <div v-if="props.tag" class="corner-tag">{{ props.tag }}</div>
      <div class="icon-wrapper">
        <el-image :src="props.coverImage" fit="cover" class="icon" />
        <div class="title-wrapper">
          <h3 class="title">
            {{ props.title }}
          </h3>
<!--          <div class="tags">-->
<!--            <el-tag effect="plain">{{props.tag}}</el-tag>-->
<!--          </div>-->
        </div>
      </div>
      <div class="info-wrapper">
        <p class="description">
          {{ props.description }}{{ props.description }}
        </p>
        <div class="price">
          <span class="main_currency"> 低至 ￥</span>
          <span class="amount">{{ props.priceInfo }}</span>
          <span class="unit"> /次</span>
        </div>
      </div>
    </div>
  </el-card>
</template>

<script setup lang="ts">
import { useRouter } from "vue-router";
interface Props {
  id?: number;
  coverImage: string;
  title: string;
  description: string;
  priceInfo: string;
  tag?: string;
}

const props = defineProps<Props>();
const router = useRouter();

const goToDetail = () => {
  if (props.id) {
    router.push(`/marketplace/ai/detail?id=${props.id}`);
  }
};
</script>

<style scoped lang="scss">
.api-card {
  width: 100%;
  margin-bottom: 40px;
  cursor: pointer;
  transition: all 0.3s;
  border-radius: 10px;
}

.api-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
:deep(.el-card__body) {
  padding: 0 !important;
}
.card-content {
  padding: 20px 30px;
  position: relative;
}

.corner-tag {
  position: absolute;
  top: 0;
  right: 0;
  background-color: #f56c6c;
  color: white;
  font-size: 12px;
  padding: 6px 15px;
  border-bottom-left-radius: 10px;
}

.icon-wrapper {
  position: relative;
  margin-bottom: 12px;
  border-bottom: 1px solid #e8e8e8;
  padding: 0 10px 15px;
  display: flex;
  .icon {
    width: 70px;
    height: 70px;
    margin-right: 20px;
    object-fit: cover;
  }
}
.title-wrapper {
  flex: 1;
  width: calc(100% - 74px);
}
.title {
  font-size: 20px;
  line-height: 40px;
  height: 40px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  margin: 0 0 8px 0;
}
.tags {
  display: flex;
  gap: 10px;
  .el-tag {
    height: 26px;
  }
}

.description {
  font-size: 16px;
  color: #666;
  margin: 10px 0;
  line-height: 25px;
  height: 50px;
  overflow: hidden;
  width: 100%;
  text-indent: 32px;
  display: -webkit-box;
  -webkit-line-clamp: 2; /* 限制文本块显示两行 */
  -webkit-box-orient: vertical;
}

.price {
  display: flex;
  align-items: baseline; // 保证文字基线对齐
  gap: 4px;              // 控制间距
  color: #f56c6c;

  .main-currency {
    font-size: 14px;
    font-weight: 500;
  }

  .amount {
    font-size: 22px;
    font-weight: bold;
    line-height: 1;
  }

  .unit {
    font-size: 14px;
    color: #999;
  }
}



</style>
