import React, {type HTMLProps, useId} from 'react' import {cn} from '@/lib/utils' import {Label} from '@/components/ui/label' import FormError from '@/components/form/formError' import {Controller} from 'react-hook-form' import {Select, SelectContent, SelectItem, SelectTrigger, SelectValue} from '@/components/ui/select' interface BaseProps extends HTMLProps { name: string label?: string options: T[] } interface PropsWithLabel { labelExtractor?: (option: T) => string } interface PropsWithoutLabel { labelExtractor: (option: T) => string } interface PropsWithValue { valueExtractor?: (option: T) => string } interface PropsWithoutValue { valueExtractor: (option: T) => string } type FormSelectProps = (T extends {label: string} ? PropsWithLabel : PropsWithoutLabel) & (T extends {value: string} ? PropsWithValue : PropsWithoutValue) & BaseProps function FormSelect({ label, name, className, options, labelExtractor, valueExtractor, ...inputProps }: FormSelectProps) { const id = useId() labelExtractor ??= (option: T) => (option as {label: string}).label valueExtractor ??= (option: T) => (option as {value: string}).value return (
( <> {}} /> )} />
) } export default FormSelect