import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "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__modules_blocks_data_blocks_list_createListBlockUISchema_mjs__ from "../../modules/blocks/data-blocks/list/createListBlockUISchema.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_templates_index_mjs__ from "../../schema-templates/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__utils_mjs__ from "../utils.mjs";
const RecordAssociationListBlockInitializer = ()=>{
    const itemConfig = (0, __WEBPACK_EXTERNAL_MODULE__application_index_mjs__.useSchemaInitializerItem)();
    const { onCreateBlockSchema, componentType, createBlockSchema, ...others } = itemConfig;
    const { insert } = (0, __WEBPACK_EXTERNAL_MODULE__application_index_mjs__.useSchemaInitializer)();
    const { getTemplateSchemaByMode } = (0, __WEBPACK_EXTERNAL_MODULE__schema_templates_index_mjs__.useSchemaTemplateManager)();
    const { getCollection } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollectionManager_deprecated)();
    const field = itemConfig.field;
    const collection = getCollection(field.target);
    const resource = "".concat(field.collectionName, ".").concat(field.name);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__application_index_mjs__.SchemaInitializerItem, {
        icon: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__ant_design_icons__.TableOutlined, {}),
        ...others,
        onClick: async (param)=>{
            let { item } = param;
            if (item.template) {
                const s = await getTemplateSchemaByMode(item);
                insert(s);
            } else insert((0, __WEBPACK_EXTERNAL_MODULE__modules_blocks_data_blocks_list_createListBlockUISchema_mjs__.createListBlockUISchema)({
                rowKey: collection.filterTargetKey,
                dataSource: collection.dataSource,
                association: resource
            }));
        },
        items: (0, __WEBPACK_EXTERNAL_MODULE__utils_mjs__.useRecordCollectionDataSourceItems)('List', itemConfig, field.target, resource)
    });
};
function useCreateAssociationListBlock() {
    const { insert } = (0, __WEBPACK_EXTERNAL_MODULE__application_index_mjs__.useSchemaInitializer)();
    const { getCollection } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollectionManager_deprecated)();
    const createAssociationListBlock = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((param)=>{
        let { item } = param;
        const field = item.associationField;
        const collection = getCollection(field.target);
        insert((0, __WEBPACK_EXTERNAL_MODULE__modules_blocks_data_blocks_list_createListBlockUISchema_mjs__.createListBlockUISchema)({
            rowKey: collection.filterTargetKey,
            dataSource: collection.dataSource,
            association: "".concat(field.collectionName, ".").concat(field.name)
        }));
    }, [
        getCollection,
        insert
    ]);
    return {
        createAssociationListBlock
    };
}
export { RecordAssociationListBlockInitializer, useCreateAssociationListBlock };
