import { jsx } from "react/jsx-runtime";
import { useCallback } from "react";
import { FormOutlined } from "@ant-design/icons";
import { SchemaInitializerItem, useSchemaInitializer, useSchemaInitializerItem } from "../../application/index.mjs";
import { useCollectionManager_deprecated } from "../../collection-manager/index.mjs";
import { createDetailsWithPaginationUISchema } from "../../modules/blocks/data-blocks/details-multi/createDetailsWithPaginationUISchema.mjs";
import { useSchemaTemplateManager } from "../../schema-templates/index.mjs";
import { useRecordCollectionDataSourceItems } from "../utils.mjs";
const RecordAssociationDetailsBlockInitializer = ()=>{
    const itemConfig = useSchemaInitializerItem();
    const { onCreateBlockSchema, componentType, createBlockSchema, ...others } = itemConfig;
    const { insert } = useSchemaInitializer();
    const { getTemplateSchemaByMode } = useSchemaTemplateManager();
    const { getCollection } = useCollectionManager_deprecated();
    const field = itemConfig.field;
    const collection = getCollection(field.target);
    const resource = "".concat(field.collectionName, ".").concat(field.name);
    return /*#__PURE__*/ jsx(SchemaInitializerItem, {
        icon: /*#__PURE__*/ jsx(FormOutlined, {}),
        ...others,
        onClick: async (param)=>{
            let { item } = param;
            if (item.template) {
                const s = await getTemplateSchemaByMode(item);
                insert(s);
            } else insert(createDetailsWithPaginationUISchema({
                dataSource: collection.dataSource,
                association: resource,
                rowKey: collection.filterTargetKey || 'id'
            }));
        },
        items: useRecordCollectionDataSourceItems('Details', itemConfig, field.target, resource)
    });
};
function useCreateAssociationDetailsBlock() {
    const { insert } = useSchemaInitializer();
    const { getCollection } = useCollectionManager_deprecated();
    const createAssociationDetailsBlock = useCallback((param)=>{
        let { item } = param;
        const field = item.associationField;
        const collection = getCollection(field.target);
        insert(createDetailsWithPaginationUISchema({
            dataSource: collection.dataSource,
            association: "".concat(field.collectionName, ".").concat(field.name),
            rowKey: collection.filterTargetKey || 'id'
        }));
    }, [
        getCollection,
        insert
    ]);
    return {
        createAssociationDetailsBlock
    };
}
export { RecordAssociationDetailsBlockInitializer, useCreateAssociationDetailsBlock };
