import { jsx } from "react/jsx-runtime";
import "react";
import { TableOutlined } from "@ant-design/icons";
import { useSchemaInitializer, useSchemaInitializerItem } from "../../../../application/schema-initializer/context/index.mjs";
import { useCollectionManager_deprecated } from "../../../../collection-manager/hooks/useCollectionManager_deprecated.mjs";
import { DataBlockInitializer } from "../../../../schema-initializer/items/DataBlockInitializer.mjs";
import { createTableBlockUISchema } from "./createTableBlockUISchema.mjs";
const TableBlockInitializer = (param)=>{
    let { filterCollections, onlyCurrentDataSource, hideSearch, createBlockSchema, templateWrap, showAssociationFields } = param;
    const { createTableBlock } = useCreateTableBlock();
    const itemConfig = useSchemaInitializerItem();
    return /*#__PURE__*/ jsx(DataBlockInitializer, {
        ...itemConfig,
        icon: /*#__PURE__*/ jsx(TableOutlined, {}),
        componentType: 'Table',
        onCreateBlockSchema: async (options)=>{
            if (createBlockSchema) return createBlockSchema(options);
            createTableBlock(options);
        },
        onlyCurrentDataSource: onlyCurrentDataSource,
        hideSearch: hideSearch,
        filter: filterCollections,
        showAssociationFields: showAssociationFields
    });
};
const useCreateTableBlock = ()=>{
    const { insert } = useSchemaInitializer();
    const { getCollection } = useCollectionManager_deprecated();
    const createTableBlock = (param)=>{
        let { item } = param;
        const collection = getCollection(item.name, item.dataSource);
        const schema = createTableBlockUISchema({
            collectionName: item.name,
            dataSource: item.dataSource,
            rowKey: collection.filterTargetKey || 'id'
        });
        insert(schema);
    };
    return {
        createTableBlock
    };
};
export { TableBlockInitializer, useCreateTableBlock };
