import { useStyleConfig, vui } from '../core'
import type { IconProps } from '../icon'
import Icon from '../icon'
import { cs } from '../utils'
import { useInputContext } from './context'

/** Displays an icon within the Input. */
export const InputIcon = vui<'svg', IconProps>((props, ref) => {
  const { className, ...rest } = props
  const inputProps = useInputContext()
  const mergedProps = { ...inputProps, ...props }
  const styles = useStyleConfig('Input', mergedProps)

  return <Icon className={cs('vui-inputIcon', className)} ref={ref} {...styles.icon} {...rest} />
})

InputIcon.displayName = 'InputIcon'

export default InputIcon
