import { jsx } from "react/jsx-runtime";
import "react";
import { OrderedListOutlined } from "@ant-design/icons";
import { useSchemaInitializer, useSchemaInitializerItem } from "../../../../application/index.mjs";
import { useCollectionManager_deprecated } from "../../../../collection-manager/index.mjs";
import { DataBlockInitializer } from "../../../../schema-initializer/items/DataBlockInitializer.mjs";
import { createListBlockUISchema } from "./createListBlockUISchema.mjs";
const ListBlockInitializer = (param)=>{
    let { filterCollections, onlyCurrentDataSource, hideSearch, createBlockSchema, componentType = 'FormItem', templateWrap, showAssociationFields } = param;
    const itemConfig = useSchemaInitializerItem();
    const { createListBlock } = useCreateListBlock();
    return /*#__PURE__*/ jsx(DataBlockInitializer, {
        ...itemConfig,
        icon: /*#__PURE__*/ jsx(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 } = useCollectionManager_deprecated();
    const { insert } = useSchemaInitializer();
    const createListBlock = (param)=>{
        let { item } = param;
        const collection = getCollection(item.name, item.dataSource);
        const schema = createListBlockUISchema({
            collectionName: item.name,
            dataSource: item.dataSource,
            rowKey: collection.filterTargetKey || 'id'
        });
        insert(schema);
    };
    return {
        createListBlock
    };
};
export { ListBlockInitializer, useCreateListBlock };
