import { jsx } from "react/jsx-runtime";
import { createContext, useContext, useMemo, useRef } from "react";
const FormActiveFieldsContext = /*#__PURE__*/ createContext(null);
const FormActiveFieldsProvider = (param)=>{
    let { children, name, getActiveFieldsName, addActiveFieldName, removeActiveFieldName } = param;
    const activeFieldsNameRef = useRef(new Set());
    const upLevelContext = useContext(FormActiveFieldsContext);
    const value = useMemo(()=>({
            getActiveFieldsName: getActiveFieldsName || ((_name)=>{
                if (!_name || _name === name) return Array.from(activeFieldsNameRef.current);
                return null == upLevelContext ? void 0 : upLevelContext.getActiveFieldsName(_name);
            }),
            addActiveFieldName: addActiveFieldName || ((field)=>{
                activeFieldsNameRef.current.add(field);
            }),
            removeActiveFieldName: removeActiveFieldName || ((field)=>{
                activeFieldsNameRef.current.delete(field);
            }),
            name,
            parent: upLevelContext
        }), [
        addActiveFieldName,
        getActiveFieldsName,
        name,
        removeActiveFieldName,
        upLevelContext
    ]);
    return /*#__PURE__*/ jsx(FormActiveFieldsContext.Provider, {
        value: value,
        children: children
    });
};
const useFormActiveFields = ()=>useContext(FormActiveFieldsContext);
export { FormActiveFieldsProvider, useFormActiveFields };
