<script setup>
import { NButton, NIcon, NTooltip, NTag } from 'naive-ui'
import { CreateOutline, TrashOutline, FolderOutline, PricetagsOutline, BookmarksOutline } from '@vicons/ionicons5'

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

const emit = defineEmits(['edit', 'delete', 'tag', 'category'])
</script>

<template>
  <div class="skill-card glow-border">
    <div class="card-glow-bg"></div>

    <div class="card-content">
      <!-- 头部：图标 + 操作按钮 -->
      <div class="card-header">
        <div class="card-icon">
          <n-icon size="22">
            <FolderOutline />
          </n-icon>
        </div>
        <div class="card-actions">
          <n-tooltip trigger="hover">
            <template #trigger>
              <button class="action-btn tag-btn" @click="$emit('tag', skill)">
                <n-icon size="16">
                  <PricetagsOutline />
                </n-icon>
              </button>
            </template>
            标签
          </n-tooltip>
          <n-tooltip trigger="hover">
            <template #trigger>
              <button class="action-btn category-btn" @click="$emit('category', skill)">
                <n-icon size="16">
                  <BookmarksOutline />
                </n-icon>
              </button>
            </template>
            分类
          </n-tooltip>
          <n-tooltip trigger="hover">
            <template #trigger>
              <button class="action-btn edit-btn" @click="$emit('edit', skill)">
                <n-icon size="16">
                  <CreateOutline />
                </n-icon>
              </button>
            </template>
            编辑
          </n-tooltip>
          <n-tooltip trigger="hover">
            <template #trigger>
              <button class="action-btn delete-btn" @click="$emit('delete', skill)">
                <n-icon size="16">
                  <TrashOutline />
                </n-icon>
              </button>
            </template>
            删除
          </n-tooltip>
        </div>
      </div>

      <!-- 展示名称（优先级：displayName → translatedDisplayName → name） -->
      <h3 class="card-title">{{ skill.displayName || skill.translatedDisplayName || skill.name }}</h3>
      <p
        v-if="(skill.displayName || skill.translatedDisplayName) && (skill.displayName || skill.translatedDisplayName) !== skill.name"
        class="card-original-name"
      >
        {{ skill.name }}
      </p>

      <!-- 描述 -->
      <p class="card-desc">{{ skill.translatedDescription || skill.description }}</p>

      <!-- 标签 -->
      <div v-if="skill.tags && skill.tags.length" class="card-tags">
        <n-tag
          v-for="tag in skill.tags"
          :key="tag.tagId"
          size="small"
          :bordered="false"
          type="info"
        >
          {{ tag.tagName }}
        </n-tag>
      </div>

      <!-- 底部：文件夹标识 -->
      <div class="card-footer">
        <span class="folder-tag">{{ skill.folderName }}</span>
      </div>
    </div>
  </div>
</template>

<style scoped>
.skill-card {
  position: relative;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  transition: all var(--transition-normal);
  overflow: hidden;
  cursor: default;
}

.skill-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-color-hover);
  box-shadow: var(--shadow-card-hover);
  transform: translateY(-4px);
}

/* 卡片背景光效 */
.card-glow-bg {
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle at 30% 30%, rgba(37, 99, 235, 0.06) 0%, transparent 60%);
  pointer-events: none;
  transition: opacity var(--transition-normal);
  opacity: 0;
}

.skill-card:hover .card-glow-bg {
  opacity: 1;
}

.card-content {
  position: relative;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 1;
}

/* 头部 */
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(37, 99, 235, 0.12);
  border-radius: var(--radius-sm);
  color: var(--color-accent);
}

.card-actions {
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.skill-card:hover .card-actions {
  opacity: 1;
}

.action-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.edit-btn {
  background: rgba(37, 99, 235, 0.1);
  color: var(--color-primary-light);
}

.edit-btn:hover {
  background: rgba(37, 99, 235, 0.2);
  box-shadow: 0 0 10px rgba(37, 99, 235, 0.2);
}

.delete-btn {
  background: rgba(239, 68, 68, 0.1);
  color: var(--color-danger);
}

.delete-btn:hover {
  background: rgba(239, 68, 68, 0.2);
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.2);
}

.tag-btn {
  background: rgba(34, 197, 94, 0.1);
  color: #22c55e;
}

.tag-btn:hover {
  background: rgba(34, 197, 94, 0.2);
}

.category-btn {
  background: rgba(168, 85, 247, 0.1);
  color: #a855f7;
}

.category-btn:hover {
  background: rgba(168, 85, 247, 0.2);
}

/* 标题 */
.card-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.4;
}

.card-original-name {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: -8px;
}

/* 描述 */
.card-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* 标签 */
.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

/* 底部 */
.card-footer {
  margin-top: 4px;
  padding-top: 12px;
  border-top: 1px solid rgba(56, 189, 248, 0.06);
}

.folder-tag {
  font-size: 11px;
  color: var(--text-muted);
  background: rgba(100, 116, 139, 0.1);
  padding: 3px 8px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
}
</style>
