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 { createGridCardBlockUISchema } from "./createGridCardBlockUISchema.mjs";
const GridCardBlockInitializer = (param)=>{
    let { filterCollections, onlyCurrentDataSource, hideSearch, createBlockSchema, componentType = 'FormItem', templateWrap, showAssociationFields } = param;
    const itemConfig = useSchemaInitializerItem();
    const { createGridCardBlock } = useCreateGridCardBlock();
    return /*#__PURE__*/ jsx(DataBlockInitializer, {
        ...itemConfig,
        icon: /*#__PURE__*/ jsx(OrderedListOutlined, {}),
        componentType: 'GridCard',
        onCreateBlockSchema: async (options)=>{
            if (createBlockSchema) return createBlockSchema(options);
            createGridCardBlock(options);
        },
        onlyCurrentDataSource: onlyCurrentDataSource,
        hideSearch: hideSearch,
        filter: filterCollections,
        showAssociationFields: showAssociationFields
    });
};
const useCreateGridCardBlock = ()=>{
    const { insert } = useSchemaInitializer();
    const { getCollection } = useCollectionManager_deprecated();
    const createGridCardBlock = (param)=>{
        let { item } = param;
        const collection = getCollection(item.name, item.dataSource);
        const schema = createGridCardBlockUISchema({
            collectionName: item.name,
            dataSource: item.dataSource,
            rowKey: collection.filterTargetKey || 'id'
        });
        insert(schema);
    };
    return {
        createGridCardBlock
    };
};
export { GridCardBlockInitializer, useCreateGridCardBlock };
