import { jsx } from "react/jsx-runtime";
import "react";
import { FormOutlined } from "@ant-design/icons";
import { SchemaInitializerItem, useSchemaInitializer, useSchemaInitializerItem } from "../../../../application/index.mjs";
import { useBlockAssociationContext } from "../../../../block-provider/index.mjs";
import { useCollection_deprecated } from "../../../../collection-manager/index.mjs";
import { useRecordCollectionDataSourceItems } from "../../../../schema-initializer/utils.mjs";
import { useSchemaTemplateManager } from "../../../../schema-templates/index.mjs";
import { createCreateFormBlockUISchema } from "./createCreateFormBlockUISchema.mjs";
const CreateFormBlockInitializer = ()=>{
    const itemConfig = useSchemaInitializerItem();
    const { onCreateBlockSchema, componentType, createBlockSchema, ...others } = itemConfig;
    const { getTemplateSchemaByMode } = useSchemaTemplateManager();
    const { insert } = useSchemaInitializer();
    const association = useBlockAssociationContext();
    const collection = useCollection_deprecated();
    return /*#__PURE__*/ jsx(SchemaInitializerItem, {
        icon: /*#__PURE__*/ jsx(FormOutlined, {}),
        ...others,
        onClick: async (param)=>{
            let { item } = param;
            if (item.template) {
                const s = await getTemplateSchemaByMode(item);
                if ('FormItem' === item.template.componentName) {
                    const blockSchema = 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(createCreateFormBlockUISchema(association ? {
                association,
                dataSource: collection.dataSource
            } : {
                collectionName: collection.name,
                dataSource: collection.dataSource
            }));
        },
        items: useRecordCollectionDataSourceItems('FormItem')
    });
};
export { CreateFormBlockInitializer };
