import { useState, useMemo } from 'react'; import { KAOMOJI_CATEGORIES, type KaomojiItem } from '../lib/kaomojiData'; interface EmojiPickerProps { onSelect: (emoji: string) => void; onClose: () => void; } export function EmojiPicker({ onSelect, onClose }: EmojiPickerProps) { const [search, setSearch] = useState(''); const [activeTab, setActiveTab] = useState('All'); // Search logic (checks emoji or tags matching) const searchResults = useMemo(() => { if (!search) return []; const query = search.toLowerCase().trim(); const results: KaomojiItem[] = []; const seen = new Set(); for (const cat of KAOMOJI_CATEGORIES) { for (const item of cat.items) { if (seen.has(item.emoji)) continue; const matchesEmoji = item.emoji.toLowerCase().includes(query); const matchesTags = item.tags.some(tag => tag.includes(query)); if (matchesEmoji || matchesTags) { results.push(item); seen.add(item.emoji); } } } return results; }, [search]); // Tab filter logic const displayedItems = useMemo(() => { if (activeTab === 'All') { const all: KaomojiItem[] = []; const seen = new Set(); for (const cat of KAOMOJI_CATEGORIES) { for (const item of cat.items) { if (!seen.has(item.emoji)) { all.push(item); seen.add(item.emoji); } } } return all; } const cat = KAOMOJI_CATEGORIES.find(c => c.tabLabel === activeTab); return cat ? cat.items : []; }, [activeTab]); return (
KAOMOJI PICKER
setSearch(e.target.value)} placeholder="search (happy, bear, sad, table...)" className="w-full px-2 py-1 mb-2 text-xs bg-gb-bg-s text-gb-fg border border-gb-bg-t outline-none focus:border-gb-orange" autoFocus /> {/* Tabs list (only shown if not searching) */} {!search && (
{KAOMOJI_CATEGORIES.map(cat => ( ))}
)} {/* Emoticons grid */}
{search ? ( searchResults.map((item) => ( )) ) : ( displayedItems.map((item) => ( )) )}
{search && searchResults.length === 0 && (
[no matches found]
)}
); }