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__ant_design_icons__ from "@ant-design/icons";
import * as __WEBPACK_EXTERNAL_MODULE__application_index_mjs__ from "../../../../application/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__data_source_index_mjs__ from "../../../../data-source/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_initializer_items_DataBlockInitializer_mjs__ from "../../../../schema-initializer/items/DataBlockInitializer.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__createDetailsWithPaginationUISchema_mjs__ from "./createDetailsWithPaginationUISchema.mjs";
const DetailsBlockInitializer = (param)=>{
    let { filterCollections, onlyCurrentDataSource, hideSearch, componentType = 'Details', createBlockSchema, templateWrap, showAssociationFields, hideChildrenIfSingleCollection } = param;
    const itemConfig = (0, __WEBPACK_EXTERNAL_MODULE__application_index_mjs__.useSchemaInitializerItem)();
    const { createDetailsBlock } = useCreateDetailsBlock();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_initializer_items_DataBlockInitializer_mjs__.DataBlockInitializer, {
        ...itemConfig,
        icon: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__ant_design_icons__.TableOutlined, {}),
        componentType: componentType,
        onCreateBlockSchema: async (options)=>{
            if (createBlockSchema) return createBlockSchema(options);
            createDetailsBlock(options);
        },
        onlyCurrentDataSource: !!onlyCurrentDataSource,
        hideSearch: hideSearch,
        filter: filterCollections,
        templateWrap: templateWrap,
        showAssociationFields: showAssociationFields,
        hideChildrenIfSingleCollection: hideChildrenIfSingleCollection
    });
};
const useCreateDetailsBlock = ()=>{
    const { insert } = (0, __WEBPACK_EXTERNAL_MODULE__application_index_mjs__.useSchemaInitializer)();
    const cm = (0, __WEBPACK_EXTERNAL_MODULE__data_source_index_mjs__.useCollectionManager)();
    const createDetailsBlock = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((param)=>{
        let { item } = param;
        const collection = cm.getCollection(item.name);
        const schema = (0, __WEBPACK_EXTERNAL_MODULE__createDetailsWithPaginationUISchema_mjs__.createDetailsWithPaginationUISchema)({
            collectionName: item.name,
            dataSource: item.dataSource,
            rowKey: collection.filterTargetKey || 'id',
            hideActionInitializer: !(('view' !== collection.template || (null == collection ? void 0 : collection.writableView)) && 'sql' !== collection.template)
        });
        insert(schema);
    }, [
        cm,
        insert
    ]);
    return {
        createDetailsBlock
    };
};
export { DetailsBlockInitializer, useCreateDetailsBlock };
