"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = function(exports1, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
(()=>{
    __webpack_require__.r = function(exports1) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    DataBlockContext: ()=>DataBlockContext,
    useDataBlockProps: ()=>useDataBlockProps,
    AssociationOrCollectionProvider: ()=>AssociationOrCollectionProvider,
    DataBlockProvider: ()=>DataBlockProvider,
    useDataBlock: ()=>useDataBlock
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const index_js_namespaceObject = require("../../application/hoc/index.js");
const acl_index_js_namespaceObject = require("../../built-in/acl/index.js");
const external_schema_component_index_js_namespaceObject = require("../../schema-component/index.js");
const external_collection_index_js_namespaceObject = require("../collection/index.js");
const ConfigSetting_provider_js_namespaceObject = require("./context/ConfigSetting.provider.js");
const external_DataBlockRequestProvider_js_namespaceObject = require("./DataBlockRequestProvider.js");
const external_DataBlockResourceProvider_js_namespaceObject = require("./DataBlockResourceProvider.js");
const DataBlockContext = /*#__PURE__*/ (0, external_react_namespaceObject.createContext)({});
DataBlockContext.displayName = 'DataBlockContext';
const AssociationOrCollectionProvider = (props)=>{
    const { collection, association, allowNull = false } = props;
    const AssociationOrCollection = (0, external_react_namespaceObject.useMemo)(()=>{
        if (association) return {
            Component: external_collection_index_js_namespaceObject.AssociationProvider,
            name: association
        };
        return {
            Component: external_collection_index_js_namespaceObject.CollectionProvider,
            name: collection
        };
    }, [
        collection,
        association
    ]);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(AssociationOrCollection.Component, {
        name: AssociationOrCollection.name,
        allowNull: allowNull,
        children: props.children
    });
};
const DataBlockProvider = (0, index_js_namespaceObject.withDynamicSchemaProps)((props)=>{
    const { collection, association, dataSource, children, layoutDirection, ...resets } = props;
    const configSetting = {
        layoutDirection
    };
    const { dn } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(DataBlockContext.Provider, {
        value: {
            dn,
            props: {
                ...resets,
                collection,
                association,
                dataSource
            }
        },
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(ConfigSetting_provider_js_namespaceObject.ConfigSettingProvider, {
            value: configSetting,
            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_collection_index_js_namespaceObject.CollectionManagerProvider, {
                dataSource: dataSource,
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(AssociationOrCollectionProvider, {
                    collection: collection,
                    association: association,
                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(acl_index_js_namespaceObject.ACLCollectionProvider, {
                        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_DataBlockResourceProvider_js_namespaceObject.DataBlockResourceProvider, {
                            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_DataBlockRequestProvider_js_namespaceObject.BlockRequestProvider, {
                                children: children
                            })
                        })
                    })
                })
            })
        })
    });
}, {
    displayName: 'DataBlockProvider'
});
const useDataBlock = ()=>{
    const context = (0, external_react_namespaceObject.useContext)(DataBlockContext);
    if (!context) throw new Error('useDataBlock() must be used within a DataBlockProvider');
    return context;
};
const useDataBlockProps = ()=>{
    const context = useDataBlock();
    return context.props;
};
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
