'use client' import * as React from 'react' import { Select, SelectTrigger, SelectContent, SelectItem, SelectValue, type SelectIcon, type SelectSize, } from './Select' export type SimpleSelectOption = { label: string value: OptionType Icon?: SelectIcon } type SharedProps = { /** Options to display in the dropdown. */ options: SimpleSelectOption[] /** Placeholder text shown when no option is selected. */ placeholder?: string /** Disables the select and prevents user interaction. */ disabled?: boolean /** Additional CSS class names applied to the trigger. */ className?: string /** Called with the new value when the selection changes. */ onValueChange?: (newValue: OptionType) => void /** Whether the dropdown is open on first render. */ defaultOpen?: boolean /** Visual density of the trigger and items. Defaults to `'default'`. */ size?: SelectSize /** When false, the hover clear control is not shown (default true). */ clearable?: boolean } /** * Controlled mode: pass `value` and manage selection state in the parent. * `defaultValue` is disallowed when using controlled mode. */ interface ControlledProps extends SharedProps { /** The currently selected value, managed by the parent. */ value: string defaultValue?: never } /** * Uncontrolled mode: optionally pass `defaultValue` for an initial selection. * The component manages its own state after mount. * `value` is disallowed when using uncontrolled mode. */ interface UncontrolledProps extends SharedProps { value?: never /** The initially selected value. The component manages state after mount. */ defaultValue?: string } export type SimpleSelectProps = | ControlledProps | UncontrolledProps /** * Opinionated select built on the Select primitive. Pass an `options` array and * get a fully composed select with no manual subcomponent setup. Supports * controlled (`value` + `onValueChange`) and uncontrolled (`defaultValue`) usage. */ export function SimpleSelect({ options, value, onValueChange, defaultValue, placeholder, disabled, defaultOpen, className, size = 'default', clearable = true, }: SimpleSelectProps) { // **Uncontrolled** local state: const [internalValue, setInternalValue] = React.useState( defaultValue, ) // Determine if we are in controlled mode (i.e., `value` prop is present) const isControlled = value !== undefined // The actual value to pass to {options.map(({ value, Icon, label }) => ( {label} ))} ) }