"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useSavingFocus = void 0;
var react_1 = require("react");
var useSavingFocus = function (selectRef, inputRef, disabled) {
    var _a;
    var needFocusRef = (0, react_1.useRef)(false);
    if (!needFocusRef.current &&
        disabled &&
        document.activeElement === ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.getElementsByTagName('input')[0])) {
        needFocusRef.current = true;
    }
    (0, react_1.useEffect)(function () {
        var _a;
        var handler = function () {
            if (needFocusRef.current) {
                needFocusRef.current = false;
            }
        };
        if (!disabled && needFocusRef.current) {
            (_a = selectRef.current) === null || _a === void 0 ? void 0 : _a.focus();
            needFocusRef.current = false;
        }
        if (disabled && needFocusRef.current) {
            document === null || document === void 0 ? void 0 : document.addEventListener('click', handler);
            return function () {
                document === null || document === void 0 ? void 0 : document.removeEventListener('click', handler);
            };
        }
    }, [disabled]);
};
exports.useSavingFocus = useSavingFocus;
