<SupportModelList :layout="'grid'" />

<script lang="ts" setup>
import { useModelStore } from '@/stores/modules/model';

interface Props {
  layout?: 'list' | 'grid'; // 布局方式：list(单列)或grid(网格)
  columns?: number; // 网格布局时的列数，默认为2
}

const props = withDefaults(defineProps<Props>(), {
  layout: 'list',
  columns: 2,
});

// 从store获取模型列表
const modelStore = useModelStore();
const modelList = computed(() => modelStore.modelList);

// 计算网格布局的列数
const gridTemplateColumns = computed(() => {
  if (props.layout === 'list')
    return '1fr';
  return `repeat(${props.columns}, minmax(300px, 1fr))`;
});
</script>

<template>
  <div class="model-container">
    <div class="model-header">
      支持的模型
    </div>
    <div
      class="model-grid"
      :style="{ 'grid-template-columns': gridTemplateColumns }"
    >
      <div v-for="model in modelList" :key="model.id" class="model-card">
        <div class="model-card-header">
          <h3 class="model-name">
            {{ model.modelName }}
          </h3>
          <div class="model-price">
            <template v-if="model.modelPrice === 0">
              <span
                class="free-tag"
                :class="model.isFree ? 'free' : 'vip'"
              >
                {{ model.isFree ? '免费' : 'Vip专享' }}
              </span>
            </template>
            <template v-else>
              <span class="price">{{ model.modelPrice }}元/次</span>
              <span class="per-token">{{ model.modelPrice * 100 }}元/百万Token</span>
            </template>
          </div>
        </div>
        <div class="model-description">
          {{ model.modelDescribe }}
        </div>
        <div class="model-footer">
          <span class="model-id">{{ model.modelId }}</span>
          <!--          <el-tag v-if="model.category === 'chat'" size="small" type="success"> -->
          <!--            对话 -->
          <!--          </el-tag> -->
          <!--          <el-tag v-else size="small" type="info"> -->
          <!--            其他 -->
          <!--          </el-tag> -->
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.model-container {
  margin: 10px 0;
  height: 100%;
  overflow-y: auto;
}

.model-header {
  font-size: 14px;
  margin-bottom: 24px;
  color: #333;
  font-weight: 600;
}

.model-grid {
  display: grid;
  gap: 20px;
}

.model-card {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  padding: 10px;
  transition: all 0.3s ease;
  border: 1px solid #ebeef5;
}

.model-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 6px 16px 0 rgba(0, 0, 0, 0.1);
}

.model-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid #f0f0f0;
}

.model-name {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
  color: #333;
}

.model-price {
  text-align: right;
}
.free-tag {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}

.free-tag.free {
  background: #f0f9eb;
  color: #67c23a;
}

.free-tag.vip {
  background: #fff7e6;
  color: #d48806;
}

.price {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #f56c6c;
}

.per-token {
  font-size: 12px;
  color: #909399;
}

.model-description {
  color: #606266;
  line-height: 1.6;
  margin-bottom: 16px;
  min-height: 60px;
}

.model-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 12px;
  border-top: 1px solid #f0f0f0;
}

.model-id {
  font-size: 12px;
  color: #909399;
}

@media (max-width: 768px) {
  .model-grid {
    grid-template-columns: 1fr !important;
  }

  .model-card {
    padding: 16px;
  }
}
</style>
