import { useDebouncedCallback } from 'use-debounce';
import { useEffect } from 'react';

var useDebouncedOnChange = function (_a) {
    var onChange = _a.onChange, onBlur = _a.onBlur, debounce = _a.debounce;
    var debouncedOnChange = useDebouncedCallback(onChange ||
        (function () {
            return;
        }), debounce);
    var onBlurHandler = function (event) {
        if (debounce && debouncedOnChange.isPending()) {
            debouncedOnChange.flush();
        }
        onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
    };
    useEffect(function () {
        return function () {
            if (debounce && debouncedOnChange.isPending()) {
                debouncedOnChange.flush();
            }
        };
    }, [debounce, debouncedOnChange]);
    return {
        onChange: debounce ? debouncedOnChange : onChange,
        onBlur: debounce ? onBlurHandler : onBlur,
    };
};

export { useDebouncedOnChange as default };
//# sourceMappingURL=useDebouncedOnChange.js.map
