<script setup lang="ts">
import { ref } from 'vue'

defineProps<{
  visible: boolean
}>()

const emit = defineEmits<{
  select: [emoji: string]
  close: []
}>()

const categories = [
  { key: 'smile', name: '😀', label: '笑脸' },
  { key: 'gesture', name: '👍', label: '手势' },
  { key: 'object', name: '📦', label: '物品' },
  { key: 'symbol', name: '💬', label: '符号' },
]

const emojiData: Record<string, string[]> = {
  smile: ['😀', '😃', '😄', '😁', '😅', '😂', '🤣', '😊', '😇', '🙂', '😉', '😌'],
  gesture: ['👍', '👎', '👌', '🤌', '🤏', '✌️', '🤞', '🖖', '🤙', '💪', '🙏', '👏'],
  object: ['📄', '📁', '🖼️', '📊', '📝', '💾', '📧', '🔗', '📌', '🔍', '💡', '⚡'],
  symbol: ['✅', '❌', '⚠️', '🔥', '💯', '🎯', '⭐', '✨', '💬', '🗨️', '❤️', '🧡'],
}

const activeCategory = ref('smile')

function selectEmoji(emoji: string) {
  emit('select', emoji)
}
</script>

<template>
  <div v-if="visible" class="emoji-picker">
    <div class="emoji-tabs">
      <button
        v-for="cat in categories"
        :key="cat.key"
        :class="{ active: activeCategory === cat.key }"
        @click="activeCategory = cat.key"
        :title="cat.label"
      >
        {{ cat.name }}
      </button>
    </div>
    <div class="emoji-grid">
      <button
        v-for="emoji in emojiData[activeCategory]"
        :key="emoji"
        class="emoji-btn"
        @click="selectEmoji(emoji)"
      >
        {{ emoji }}
      </button>
    </div>
  </div>
</template>

<style scoped>
.emoji-picker {
  position: absolute;
  bottom: 100%;
  right: 0;
  margin-bottom: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-md);
  padding: 8px;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
  z-index: 100;
  min-width: 240px;
}

.emoji-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-dim);
}

.emoji-tabs button {
  flex: 1;
  padding: 6px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 16px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.emoji-tabs button:hover {
  background: var(--accent-cyan-dim);
}

.emoji-tabs button.active {
  background: var(--accent-cyan-dim);
  border-color: var(--border-mid);
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 2px;
}

.emoji-btn {
  padding: 6px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 18px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.emoji-btn:hover {
  background: var(--accent-cyan-dim);
  transform: scale(1.2);
}
</style>
