import { useEffect, useRef, useState } from 'react';
export var useEventListener = function (eventName, handler, target) {
    if (target === void 0) { target = window; }
    var savedHandler = useRef();
    useEffect(function () {
        savedHandler.current = handler;
    }, [handler]);
    useEffect(function () {
        var isSupported = target && target.addEventListener;
        if (!isSupported)
            return;
        var eventListener = function (event) {
            return savedHandler.current && savedHandler.current(event);
        };
        target.addEventListener(eventName, eventListener);
        return function () {
            target.removeEventListener(eventName, eventListener);
        };
    }, [eventName, target]);
};
export var useClickOutside = function (target, handler) {
    useEffect(function () {
        var listener = function (event) {
            if (!target || target.contains(event.target)) {
                return;
            }
            handler(event);
        };
        document.addEventListener('click', listener);
        return function () {
            document.removeEventListener('click', listener);
        };
    }, [target, handler]);
};
export function useDebounce(value, delay) {
    if (delay === void 0) { delay = 300; }
    var _a = useState(value), debouncedValue = _a[0], setDebouncedValue = _a[1];
    useEffect(function () {
        var handler = window.setTimeout(function () {
            setDebouncedValue(value);
        }, delay);
        return function () {
            window.clearTimeout(handler);
        };
    }, [value, delay]);
    return [debouncedValue];
}
//# sourceMappingURL=hooks.js.map