import { useEffect } from "react";
import { useDidMountEffect } from ".";
export var useCodeHook = function useCodeHook(param) {
    var inputRefs = param.inputRefs, codeLength = param.codeLength, disabled = param.disabled, autoFocus = param.autoFocus, originalValue = param.originalValue, getLastActiveIndex = param.getLastActiveIndex, handleFullCodeEnter = param.handleFullCodeEnter;
    useEffect(function() {
        inputRefs.current = inputRefs.current.slice(0, codeLength);
    }, [
        codeLength
    ]);
    useEffect(function() {
        if (autoFocus && !disabled) {
            var lastActiveIndex = getLastActiveIndex();
            if (inputRefs === null || inputRefs === void 0 ? void 0 : inputRefs.current[lastActiveIndex]) {
                var _inputRefs_current_lastActiveIndex;
                (_inputRefs_current_lastActiveIndex = inputRefs.current[lastActiveIndex]) === null || _inputRefs_current_lastActiveIndex === void 0 ? void 0 : _inputRefs_current_lastActiveIndex.focus();
            }
        }
    }, [
        autoFocus
    ]);
    useDidMountEffect(function() {
        if (handleFullCodeEnter && originalValue.length === codeLength) {
            handleFullCodeEnter(originalValue);
        }
    }, [
        originalValue,
        handleFullCodeEnter
    ]);
};
