import { useEffect } from "react";
import { useDidMountEffect } from ".";
export const useCodeHook = ({ inputRefs, codeLength, disabled, autoFocus, originalValue, getLastActiveIndex, handleFullCodeEnter })=>{
    useEffect(()=>{
        inputRefs.current = inputRefs.current.slice(0, codeLength);
    }, [
        codeLength
    ]);
    useEffect(()=>{
        if (autoFocus && !disabled) {
            const lastActiveIndex = getLastActiveIndex();
            if (inputRefs?.current[lastActiveIndex]) {
                inputRefs.current[lastActiveIndex]?.focus();
            }
        }
    }, [
        autoFocus
    ]);
    useDidMountEffect(()=>{
        if (handleFullCodeEnter && originalValue.length === codeLength) {
            handleFullCodeEnter(originalValue);
        }
    }, [
        originalValue,
        handleFullCodeEnter
    ]);
};
