import React, { useMemo } from "react" import { useAtom } from "jotai" import { Button } from "@/components/ui/button" import { Popover, PopoverTrigger, PopoverContent } from "@/components/ui/popover" import { cn } from "@/lib/utils" import { LaIcon } from "@/components/custom/la-icon" import { LEARNING_STATES, LearningStateValue } from "@/lib/constants" import { linkLearningStateSelectorAtom } from "@/store/link" import { Command, CommandInput, CommandList, CommandItem, CommandGroup } from "@/components/ui/command" import { ScrollArea } from "@/components/ui/scroll-area" import { icons } from "lucide-react" interface LearningStateSelectorProps { showSearch?: boolean defaultLabel?: string searchPlaceholder?: string value?: string onChange: (value: LearningStateValue) => void className?: string defaultIcon?: keyof typeof icons } export const LearningStateSelector: React.FC = ({ showSearch = true, defaultLabel = "State", searchPlaceholder = "Search state...", value, onChange, className, defaultIcon }) => { const [isLearningStateSelectorOpen, setIsLearningStateSelectorOpen] = useAtom(linkLearningStateSelectorAtom) const selectedLearningState = useMemo(() => LEARNING_STATES.find(ls => ls.value === value), [value]) const handleSelect = (selectedValue: string) => { onChange(selectedValue as LearningStateValue) setIsLearningStateSelectorOpen(false) } const iconName = selectedLearningState?.icon || defaultIcon const labelText = selectedLearningState?.label || defaultLabel return ( ) } interface LearningStateSelectorContentProps { showSearch: boolean searchPlaceholder: string value?: string onSelect: (value: string) => void } export const LearningStateSelectorContent: React.FC = ({ showSearch, searchPlaceholder, value, onSelect }) => { return ( {showSearch && } {LEARNING_STATES.map(ls => ( {ls.icon && } {ls.label} ))} ) }