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_schema_initializer_context_index_mjs__ from "../../../../application/schema-initializer/context/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__collection_manager_hooks_useCollectionManager_deprecated_mjs__ from "../../../../collection-manager/hooks/useCollectionManager_deprecated.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_initializer_items_DataBlockInitializer_mjs__ from "../../../../schema-initializer/items/DataBlockInitializer.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__createTableBlockUISchema_mjs__ from "./createTableBlockUISchema.mjs";
const TableBlockInitializer = (param)=>{
    let { filterCollections, onlyCurrentDataSource, hideSearch, createBlockSchema, templateWrap, showAssociationFields } = param;
    const { createTableBlock } = useCreateTableBlock();
    const itemConfig = (0, __WEBPACK_EXTERNAL_MODULE__application_schema_initializer_context_index_mjs__.useSchemaInitializerItem)();
    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: 'Table',
        onCreateBlockSchema: async (options)=>{
            if (createBlockSchema) return createBlockSchema(options);
            createTableBlock(options);
        },
        onlyCurrentDataSource: onlyCurrentDataSource,
        hideSearch: hideSearch,
        filter: filterCollections,
        showAssociationFields: showAssociationFields
    });
};
const useCreateTableBlock = ()=>{
    const { insert } = (0, __WEBPACK_EXTERNAL_MODULE__application_schema_initializer_context_index_mjs__.useSchemaInitializer)();
    const { getCollection } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_hooks_useCollectionManager_deprecated_mjs__.useCollectionManager_deprecated)();
    const createTableBlock = (param)=>{
        let { item } = param;
        const collection = getCollection(item.name, item.dataSource);
        const schema = (0, __WEBPACK_EXTERNAL_MODULE__createTableBlockUISchema_mjs__.createTableBlockUISchema)({
            collectionName: item.name,
            dataSource: item.dataSource,
            rowKey: collection.filterTargetKey || 'id'
        });
        insert(schema);
    };
    return {
        createTableBlock
    };
};
export { TableBlockInitializer, useCreateTableBlock };
