import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
const FormActiveFieldsContext = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.createContext)(null);
const FormActiveFieldsProvider = (param)=>{
    let { children, name, getActiveFieldsName, addActiveFieldName, removeActiveFieldName } = param;
    const activeFieldsNameRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(new Set());
    const upLevelContext = (0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(FormActiveFieldsContext);
    const value = (0, __WEBPACK_EXTERNAL_MODULE_react__.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__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(FormActiveFieldsContext.Provider, {
        value: value,
        children: children
    });
};
const useFormActiveFields = ()=>(0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(FormActiveFieldsContext);
export { FormActiveFieldsProvider, useFormActiveFields };
