import { createContext, useContext } from 'react' import { type ComboBoxState } from '@react-stately/combobox' import { type SelectState } from '@react-stately/select' type BaseSingleSelectContextType = { anchorName: string isDisabled: boolean isReadOnly: boolean secondary: boolean size?: 'small' | 'medium' | 'large' fieldLabel: React.ReactNode } type SingleSelectContextType = | (BaseSingleSelectContextType & { state: ComboBoxState isComboBox: true }) | (BaseSingleSelectContextType & { state: SelectState isComboBox: false }) export const SingleSelectContext = createContext(undefined) export const useSingleSelectContext = (): SingleSelectContextType => { const context = useContext(SingleSelectContext) if (!context) { throw new Error('useSingleSelectContext must be used within a SingleSelectContext.Provider') } return context }