import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE__collection_field_index_mjs__ from "../collection-field/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__components_CollectionDeletedPlaceholder_mjs__ from "../components/CollectionDeletedPlaceholder.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__CollectionManagerProvider_mjs__ from "./CollectionManagerProvider.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__CollectionProvider_mjs__ from "./CollectionProvider.mjs";
const ParentCollectionContext = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.createContext)(null);
ParentCollectionContext.displayName = 'ParentCollectionContext';
const ParentCollectionProvider = (props)=>{
    const collection = (0, __WEBPACK_EXTERNAL_MODULE__CollectionProvider_mjs__.useCollection)();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(ParentCollectionContext.Provider, {
        value: collection,
        children: props.children
    });
};
const useParentCollection = ()=>(0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(ParentCollectionContext);
const AssociationProvider = (props)=>{
    const { name, children } = props;
    const collectionManager = (0, __WEBPACK_EXTERNAL_MODULE__CollectionManagerProvider_mjs__.useCollectionManager)();
    const collectionName = collectionManager.getCollectionName(name);
    if (!collectionName) return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__components_CollectionDeletedPlaceholder_mjs__.CollectionDeletedPlaceholder, {
        type: "Collection",
        name: name
    });
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__CollectionProvider_mjs__.CollectionProvider, {
        name: String(name).split('.')[0],
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(ParentCollectionProvider, {
            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__collection_field_index_mjs__.CollectionFieldProvider, {
                name: name,
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__CollectionProvider_mjs__.CollectionProvider, {
                    name: collectionName,
                    children: children
                })
            })
        })
    });
};
const useAssociationName = ()=>{
    const field = (0, __WEBPACK_EXTERNAL_MODULE__collection_field_index_mjs__.useCollectionField)();
    return field ? "".concat(field.collectionName, ".").concat(field.name) : null;
};
export { AssociationProvider, useAssociationName, useParentCollection };
