import type { SelectOption } from '@shumai/dtos' import { ChevronDown, X } from 'lucide-react' import React, { useState } from 'react' import type { FieldProps } from './field-types' import { Popover, PopoverContent, PopoverTrigger } from '@/ui/components/ui/popover' import { getOptionStyle } from '../fields-manager' const SelectField: React.FC> = ({ value, config, onSave, readOnly }) => { const selectConfig = config?.select const [isEditing, setIsEditing] = useState(false) const selectedOption = selectConfig?.options?.find((opt: SelectOption) => opt.id === value) const handleStartEdit = () => { if (!readOnly) { setIsEditing(true) } } const handleSelect = (optionId: string) => { onSave(optionId) setIsEditing(false) } const handleOpenChange = (open: boolean) => { if (readOnly) return setIsEditing(open) } const renderOptionBadge = (option: SelectOption | undefined) => { if (!option) return Select an option return ( {option.displayName} ) } return (
e.stopPropagation()}>
{renderOptionBadge(selectedOption)} {!readOnly && ( )}
handleSelect('')} className="px-3 py-2 text-sm text-gray-500 hover:bg-gray-50 cursor-pointer flex items-center gap-2" > Clear
{selectConfig?.options?.map((option: SelectOption) => (
handleSelect(option.id)} className="px-3 py-2 hover:bg-gray-50 cursor-pointer flex items-center" > {option.displayName}
))}
) } export default SelectField