import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import "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__collection_manager_index_mjs__ from "../../../../collection-manager/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_initializer_items_DataBlockInitializer_mjs__ from "../../../../schema-initializer/items/DataBlockInitializer.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__createListBlockUISchema_mjs__ from "./createListBlockUISchema.mjs";
const ListBlockInitializer = (param)=>{
    let { filterCollections, onlyCurrentDataSource, hideSearch, createBlockSchema, componentType = 'FormItem', templateWrap, showAssociationFields } = param;
    const itemConfig = (0, __WEBPACK_EXTERNAL_MODULE__application_index_mjs__.useSchemaInitializerItem)();
    const { createListBlock } = useCreateListBlock();
    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__.OrderedListOutlined, {}),
        componentType: 'List',
        onCreateBlockSchema: async (options)=>{
            if (createBlockSchema) return createBlockSchema(options);
            createListBlock(options);
        },
        onlyCurrentDataSource: onlyCurrentDataSource,
        hideSearch: hideSearch,
        filter: filterCollections,
        showAssociationFields: showAssociationFields
    });
};
const useCreateListBlock = ()=>{
    const { getCollection } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollectionManager_deprecated)();
    const { insert } = (0, __WEBPACK_EXTERNAL_MODULE__application_index_mjs__.useSchemaInitializer)();
    const createListBlock = (param)=>{
        let { item } = param;
        const collection = getCollection(item.name, item.dataSource);
        const schema = (0, __WEBPACK_EXTERNAL_MODULE__createListBlockUISchema_mjs__.createListBlockUISchema)({
            collectionName: item.name,
            dataSource: item.dataSource,
            rowKey: collection.filterTargetKey || 'id'
        });
        insert(schema);
    };
    return {
        createListBlock
    };
};
export { ListBlockInitializer, useCreateListBlock };
