<template>
  <div class="model-card">
    <!-- 右上角：按量收费 -->
    <div class="tag-top">按量收费</div>

    <!-- 头部：图标 + 模型名 -->
    <div class="card-header">
      <div class="model-icon">
        <span>{{ iconLetter }}</span>
      </div>
      <div class="model-name" :title="model.modelName">{{ model.modelName }}</div>
    </div>

    <!-- 描述 -->
    <div class="card-description">
      {{ model.description || '暂无描述' }}
    </div>

    <!-- 底部：收费价格 tag + 输入/输出价格 -->
    <div class="card-footer">
      <div class="tag-price">收费价格</div>
      <div class="price-text">
        <span>输入:<b>¥{{ formatPrice(model.inputPrice) }}</b></span>
        <span class="unit"> / 1M tokens</span>
        <span class="divider"></span>
        <span>输出:<b>¥{{ formatPrice(model.outputPrice) }}</b></span>
        <span class="unit"> / 1M tokens</span>
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue'

const props = defineProps({
  model: {
    type: Object,
    required: true
  }
})

const iconLetter = computed(() => {
  const name = props.model?.modelName || 'AI'
  return name.charAt(0).toUpperCase()
})

function formatPrice(price) {
  if (price === null || price === undefined) return '-'
  const num = Number(price)
  if (Number.isNaN(num)) return '-'
  return num.toFixed(4).replace(/\.?0+$/, '')
}
</script>

<style scoped lang="scss">
.model-card {
  position: relative;
  background: #fff;
  border: 1px solid #ebeef5;
  border-radius: 12px;
  padding: 20px 24px 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
  min-height: 180px;

  &:hover {
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
    transform: translateY(-2px);
  }
}

/* 右上角：按量收费 */
.tag-top {
  position: absolute;
  top: 0;
  right: 0px;
  background: linear-gradient(135deg, #ff6b6b, #ee5a52);
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  padding: 5px 14px;
  border-radius: 0 6px 0px 6px;
  line-height: 1.4;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 6px;
  margin-bottom: 14px;
}

.model-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: linear-gradient(135deg, #4e6ef2, #6b8aff);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;

  span {
    color: #fff;
    font-size: 20px;
    font-weight: 600;
  }
}

.model-name {
  flex: 1;
  font-size: 16px;
  font-weight: 600;
  color: #1a1a1a;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-description {
  font-size: 13px;
  color: #666;
  line-height: 1.65;
  margin-bottom: 16px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 60px;
  word-break: break-word;
}

.card-footer {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.tag-price {
  background: #f0f5ff;
  color: #4e6ef2;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: 6px;
  line-height: 1.5;
}

.price-text {
  font-size: 13px;
  color: #666;
  display: flex;
  height: 26px;
  align-items: center;
  // flex-wrap: wrap;
  & span {
    display: block;
    height: 26px;
    display: flex;
    align-items: center;
  }
  b {
    color: #ee5a52;
    font-weight: 600;
    margin: 0 2px;
  }

  .divider {
    margin: 0 8px;
  }

  .unit {
    color: #999;
    font-size: 12px;
  }
}
</style>
