"use client"; import { useState, useMemo } from "react"; import { Button } from "@/components/ui/button"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandList, } from "@/components/ui/command"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { CategoryIcon } from "@/components/ui/category-icon"; import { ChevronsUpDown } from "lucide-react"; import { cn } from "@/lib/utils"; // Group icons by category for better organization const iconGroups: Record = { Alimentation: [ "shopping-cart", "utensils", "croissant", "coffee", "wine", "beer", "pizza", "apple", "cherry", "salad", "sandwich", "ice-cream", "cake", "cup-soda", "milk", "egg", "fish", "beef", ], Transport: [ "fuel", "train", "car", "parking", "bike", "plane", "bus", "ship", "sailboat", "truck", "car-front", "circle-parking", "train-front", ], Logement: [ "home", "zap", "droplet", "hammer", "sofa", "refrigerator", "washing-machine", "lamp", "lamp-desk", "armchair", "bath", "shower-head", "door-open", "fence", "trees", "flower", "leaf", "sun", "snowflake", "wind", "thermometer", ], Santé: [ "pill", "stethoscope", "hospital", "glasses", "dumbbell", "sparkles", "heart", "heart-pulse", "activity", "syringe", "bandage", "brain", "eye", "ear", "hand", "footprints", "person-standing", ], Loisirs: [ "tv", "music", "film", "gamepad", "book", "ticket", "clapperboard", "headphones", "speaker", "radio", "camera", "image", "palette", "brush", "pen-tool", "scissors", "drama", "party-popper", ], Sport: ["trophy", "medal", "target", "volleyball"], Shopping: [ "shirt", "smartphone", "package", "shopping-bag", "store", "gem", "watch", "sunglasses", "crown", "laptop", "monitor", "keyboard", "mouse", "printer", "tablet-smartphone", "headset", ], Services: [ "wifi", "repeat", "landmark", "shield", "receipt", "file-text", "mail", "phone", "message-square", "send", "globe", "cloud", "server", "lock", "unlock", "settings", "wrench", ], Finance: [ "piggy-bank", "banknote", "wallet", "hand-coins", "undo", "coins", "credit-card", "building", "building2", "trending-up", "trending-down", "bar-chart", "pie-chart", "line-chart", "calculator", "percent", "dollar-sign", "euro", ], Voyage: [ "bed", "luggage", "map", "map-pin", "compass", "mountain", "tent", "palmtree", "umbrella", "globe2", "flag", ], Famille: [ "graduation-cap", "baby", "paw-print", "users", "user", "user-plus", "dog", "cat", "bird", "rabbit", ], Autre: [ "heart-handshake", "gift", "cigarette", "arrow-right-left", "help-circle", "tag", "folder", "key", "star", "bookmark", "clock", "calendar", "bell", "alert-triangle", "info", "check-circle", "x-circle", "plus", "minus", "search", "trash", "edit", "download", "upload", "share", "link", "paperclip", "archive", "box", "boxes", "container", "briefcase", "education", "award", "lightbulb", "flame", "rocket", "atom", ], }; interface IconPickerProps { value: string; onChange: (icon: string) => void; color?: string; } export function IconPicker({ value, onChange, color }: IconPickerProps) { const [open, setOpen] = useState(false); const [search, setSearch] = useState(""); // Filter icons based on search const filteredGroups = useMemo(() => { if (!search.trim()) return iconGroups; const query = search.toLowerCase(); const result: Record = {}; Object.entries(iconGroups).forEach(([group, icons]) => { const filtered = icons.filter( (icon) => icon.toLowerCase().includes(query) || group.toLowerCase().includes(query), ); if (filtered.length > 0) { result[group] = filtered; } }); return result; }, [search]); const handleSelect = (icon: string) => { onChange(icon); setOpen(false); setSearch(""); }; return ( e.preventDefault()} > Aucune icône trouvée. {Object.entries(filteredGroups).map(([group, icons]) => (
{icons.map((icon) => ( ))}
))}
); }