import { type ReactNode, type SelectHTMLAttributes, forwardRef } from "react"; import cn from "../../utils/classnames.ts"; import { FormError } from "../index.ts"; import LabelTooltip from "./LabelTooltip.tsx"; interface Option { value: string; label: string; disabled?: boolean; } interface OptGroup { label: string; options: Option[]; } type SelectOptions = Option[] | OptGroup[]; interface InputSelectProps extends Omit, "className"> { label: string; placeholder?: string; error?: string; required?: boolean; className?: string; id?: string; options: SelectOptions; tooltip?: string | ReactNode; more?: ReactNode; moreTitle?: string; } const InputSelect = forwardRef( ( { label, placeholder, error, required, className = "", id, options, tooltip = "", more = null, moreTitle = null, ...props }, ref ) => { return ( {label} {required && ( * )} {tooltip !== "" && ( {tooltip}>} /> )} {placeholder && ( {placeholder} )} {options.map((item, index) => { // Check if this is an OptGroup by checking for 'options' property if ("options" in item) { return ( {item.options.map((option) => ( {option.label} ))} ); } else { // This is a regular Option return ( {item.label} ); } })} {error && {error}} ); } ); InputSelect.displayName = "InputSelect"; export default InputSelect;