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__application_hoc_index_mjs__ from "../../application/hoc/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__built_in_acl_index_mjs__ from "../../built-in/acl/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__ from "../../schema-component/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__collection_index_mjs__ from "../collection/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__context_ConfigSetting_provider_mjs__ from "./context/ConfigSetting.provider.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__DataBlockRequestProvider_mjs__ from "./DataBlockRequestProvider.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__DataBlockResourceProvider_mjs__ from "./DataBlockResourceProvider.mjs";
const DataBlockContext = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.createContext)({});
DataBlockContext.displayName = 'DataBlockContext';
const AssociationOrCollectionProvider = (props)=>{
    const { collection, association, allowNull = false } = props;
    const AssociationOrCollection = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
        if (association) return {
            Component: __WEBPACK_EXTERNAL_MODULE__collection_index_mjs__.AssociationProvider,
            name: association
        };
        return {
            Component: __WEBPACK_EXTERNAL_MODULE__collection_index_mjs__.CollectionProvider,
            name: collection
        };
    }, [
        collection,
        association
    ]);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(AssociationOrCollection.Component, {
        name: AssociationOrCollection.name,
        allowNull: allowNull,
        children: props.children
    });
};
const DataBlockProvider = (0, __WEBPACK_EXTERNAL_MODULE__application_hoc_index_mjs__.withDynamicSchemaProps)((props)=>{
    const { collection, association, dataSource, children, layoutDirection, ...resets } = props;
    const configSetting = {
        layoutDirection
    };
    const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useDesignable)();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(DataBlockContext.Provider, {
        value: {
            dn,
            props: {
                ...resets,
                collection,
                association,
                dataSource
            }
        },
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__context_ConfigSetting_provider_mjs__.ConfigSettingProvider, {
            value: configSetting,
            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__collection_index_mjs__.CollectionManagerProvider, {
                dataSource: dataSource,
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(AssociationOrCollectionProvider, {
                    collection: collection,
                    association: association,
                    children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__built_in_acl_index_mjs__.ACLCollectionProvider, {
                        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__DataBlockResourceProvider_mjs__.DataBlockResourceProvider, {
                            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__DataBlockRequestProvider_mjs__.BlockRequestProvider, {
                                children: children
                            })
                        })
                    })
                })
            })
        })
    });
}, {
    displayName: 'DataBlockProvider'
});
const useDataBlock = ()=>{
    const context = (0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(DataBlockContext);
    if (!context) throw new Error('useDataBlock() must be used within a DataBlockProvider');
    return context;
};
const useDataBlockProps = ()=>{
    const context = useDataBlock();
    return context.props;
};
export { AssociationOrCollectionProvider, DataBlockContext, DataBlockProvider, useDataBlock, useDataBlockProps };
