// Quantity input widget for @rjsf forms.
// A simple number input with step="0.01" for quantity values.

import type { WidgetProps } from '@rjsf/utils'

export function QuantityInput(props: WidgetProps) {
  const { id, value, required, disabled, readonly, onChange } = props

  return (
    <input
      id={id}
      type="number"
      step="0.01"
      value={value ?? ''}
      required={required}
      disabled={disabled || readonly}
      onChange={(e) =>
        onChange(e.target.value === '' ? undefined : Number(e.target.value))
      }
      className="mt-1 w-full rounded-md border border-slate-300 px-3 py-2 text-sm"
    />
  )
}
