<template>
  <div class="supported-formats">
    <div v-loading="loading" class="formats-content">
      <transition-group name="tag-fade" tag="div" class="formats-grid">
        <el-tooltip
          v-for="format in formats"
          :key="format.extension"
          :content="format.description"
          placement="top"
          :disabled="!format.description"
          effect="light"
        >
          <div class="format-item">
            <div class="format-icon">
              <span class="extension">{{ format.extension }}</span>
            </div>
            <div class="format-info">
              <span class="format-name">{{ format.name }}</span>
            </div>
          </div>
        </el-tooltip>
      </transition-group>
      <el-empty v-if="!loading && formats.length === 0" description="暂无支持的格式" :image-size="80">
        <template #image>
          <div class="empty-icon">
            <el-icon><Document /></el-icon>
          </div>
        </template>
      </el-empty>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed, onMounted } from 'vue'
import { Document } from '@element-plus/icons-vue'
import { useEmbeddingStore } from '@/stores/embedding'

const embeddingStore = useEmbeddingStore()

const formats = computed(() => embeddingStore.formats)
const loading = computed(() => embeddingStore.formatsLoading)

onMounted(() => {
  if (formats.value.length === 0) {
    embeddingStore.loadFormats()
  }
})
</script>

<style scoped>
.supported-formats {
  padding: 8px 0;
}

.formats-content {
  min-height: 60px;
}

.formats-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.format-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: linear-gradient(135deg, #f8f9fc 0%, #eef1f5 100%);
  border-radius: 10px;
  border: 1px solid #e4e7ed;
  cursor: default;
  transition: all 0.3s ease;
}

.format-item:hover {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-color: transparent;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.format-item:hover .extension,
.format-item:hover .format-name {
  color: #ffffff;
}

.format-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 8px;
}

.format-item:hover .format-icon {
  background: rgba(255, 255, 255, 0.2);
}

.extension {
  font-size: 11px;
  font-weight: 700;
  color: #ffffff;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.format-info {
  display: flex;
  flex-direction: column;
}

.format-name {
  font-size: 13px;
  font-weight: 600;
  color: #303133;
  transition: color 0.3s ease;
}

.empty-icon {
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f5f7fa 0%, #e8ecf1 100%);
  border-radius: 50%;
  margin: 0 auto;
}

.empty-icon .el-icon {
  font-size: 40px;
  color: #c0c4cc;
}

.tag-fade-enter-active {
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.tag-fade-leave-active {
  transition: all 0.3s cubic-bezier(1, 0.5, 0.8, 1);
}

.tag-fade-enter-from {
  opacity: 0;
  transform: scale(0.8);
}

.tag-fade-leave-to {
  opacity: 0;
  transform: scale(0.8);
}

.tag-fade-move {
  transition: transform 0.3s ease;
}
</style>
