"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = (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 = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (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,
    DataBlockProvider: ()=>DataBlockProvider,
    useDataBlock: ()=>useDataBlock,
    AssociationOrCollectionProvider: ()=>AssociationOrCollectionProvider,
    useDataBlockProps: ()=>useDataBlockProps
});
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;
};
exports.AssociationOrCollectionProvider = __webpack_exports__.AssociationOrCollectionProvider;
exports.DataBlockContext = __webpack_exports__.DataBlockContext;
exports.DataBlockProvider = __webpack_exports__.DataBlockProvider;
exports.useDataBlock = __webpack_exports__.useDataBlock;
exports.useDataBlockProps = __webpack_exports__.useDataBlockProps;
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
    "AssociationOrCollectionProvider",
    "DataBlockContext",
    "DataBlockProvider",
    "useDataBlock",
    "useDataBlockProps"
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
Object.defineProperty(exports, '__esModule', {
    value: true
});
