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_index_mjs__ from "../../../../application/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__block_provider_index_mjs__ from "../../../../block-provider/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__ from "../../../../collection-manager/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_initializer_utils_mjs__ from "../../../../schema-initializer/utils.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_templates_index_mjs__ from "../../../../schema-templates/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__createCreateFormBlockUISchema_mjs__ from "./createCreateFormBlockUISchema.mjs";
const CreateFormBlockInitializer = ()=>{
    const itemConfig = (0, __WEBPACK_EXTERNAL_MODULE__application_index_mjs__.useSchemaInitializerItem)();
    const { onCreateBlockSchema, componentType, createBlockSchema, ...others } = itemConfig;
    const { getTemplateSchemaByMode } = (0, __WEBPACK_EXTERNAL_MODULE__schema_templates_index_mjs__.useSchemaTemplateManager)();
    const { insert } = (0, __WEBPACK_EXTERNAL_MODULE__application_index_mjs__.useSchemaInitializer)();
    const association = (0, __WEBPACK_EXTERNAL_MODULE__block_provider_index_mjs__.useBlockAssociationContext)();
    const collection = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollection_deprecated)();
    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__.FormOutlined, {}),
        ...others,
        onClick: async (param)=>{
            let { item } = param;
            if (item.template) {
                const s = await getTemplateSchemaByMode(item);
                if ('FormItem' === item.template.componentName) {
                    const blockSchema = (0, __WEBPACK_EXTERNAL_MODULE__createCreateFormBlockUISchema_mjs__.createCreateFormBlockUISchema)(association ? {
                        association,
                        dataSource: collection.dataSource,
                        templateSchema: s
                    } : {
                        collectionName: collection.name,
                        dataSource: collection.dataSource,
                        templateSchema: s
                    });
                    if ('reference' === item.mode) blockSchema['x-template-key'] = item.template.key;
                    insert(blockSchema);
                } else insert(s);
            } else insert((0, __WEBPACK_EXTERNAL_MODULE__createCreateFormBlockUISchema_mjs__.createCreateFormBlockUISchema)(association ? {
                association,
                dataSource: collection.dataSource
            } : {
                collectionName: collection.name,
                dataSource: collection.dataSource
            }));
        },
        items: (0, __WEBPACK_EXTERNAL_MODULE__schema_initializer_utils_mjs__.useRecordCollectionDataSourceItems)('FormItem')
    });
};
export { CreateFormBlockInitializer };
