import { isNil } from 'lodash';
import { useCallback } from 'react';
import { canCommit, isValueValid } from './validation';
export function useChangeHandlers(isNegativeAllowed, min, max, onChange, setCommittedValue) {
  var handleInputChange = useCallback(function (event) {
    if (!isValueValid(event.currentTarget.value, isNegativeAllowed)) {
      return;
    }
    var newValue = event.currentTarget.value || null;
    if (!newValue || canCommit(newValue, min, max)) {
      setCommittedValue(newValue);
      onChange(event, isNil(newValue) ? null : Number(newValue));
    }
  }, [isNegativeAllowed, min, max, setCommittedValue, onChange]);
  var handleButtonClick = useCallback(function (event, newValue) {
    if (canCommit(newValue, min, max)) {
      setCommittedValue(newValue);
      onChange(event, Number(newValue));
    }
  }, [min, max, onChange, setCommittedValue]);
  return {
    handleButtonClick: handleButtonClick,
    handleInputChange: handleInputChange
  };
}