"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const react_1 = require("react");
const usePrevious_1 = tslib_1.__importDefault(require("./usePrevious"));
const useAutoFocus = (props, focusElementRef) => {
    const autoFocus = props.autoFocus === undefined ? true : props.autoFocus;
    const prevAutoFocus = (0, usePrevious_1.default)(props.previous ? props.previous({ autoFocus }) : autoFocus, undefined);
    (0, react_1.useEffect)(() => {
        if (focusElementRef.current &&
            focusElementRef.current.focus &&
            autoFocus &&
            (props.shouldFocus ? props.shouldFocus({ autoFocus }) : true) &&
            (prevAutoFocus === undefined || prevAutoFocus !== autoFocus)) {
            focusElementRef.current.focus();
        }
    }, [autoFocus, prevAutoFocus, props.isOpen]);
};
exports.default = useAutoFocus;
