import { useFieldSchema } from "@tachybase/schema";
import { SchemaSettings } from "../../../../application/schema-settings/SchemaSettings.mjs";
import { useFormBlockContext } from "../../../../block-provider/index.mjs";
import { useCollection_deprecated } from "../../../../collection-manager/index.mjs";
import { SchemaSettingsBlockTitleItem, SchemaSettingsDataTemplates, SchemaSettingsFormItemTemplate, SchemaSettingsLinkageRules } from "../../../../schema-settings/index.mjs";
const creationFormBlockSettings = new SchemaSettings({
    name: 'blockSettings:creationForm',
    items: [
        {
            name: 'title',
            Component: SchemaSettingsBlockTitleItem
        },
        {
            name: 'linkageRules',
            Component: SchemaSettingsLinkageRules,
            useComponentProps () {
                const { name } = useCollection_deprecated();
                return {
                    collectionName: name
                };
            }
        },
        {
            name: 'dataTemplates',
            Component: SchemaSettingsDataTemplates,
            useVisible () {
                const { action } = useFormBlockContext();
                return !action;
            },
            useComponentProps () {
                const { name } = useCollection_deprecated();
                return {
                    collectionName: name
                };
            }
        },
        {
            name: 'divider',
            type: 'divider'
        },
        {
            name: 'formItemTemplate',
            Component: SchemaSettingsFormItemTemplate,
            useComponentProps () {
                var _fieldSchema_xdecoratorprops, _fieldSchema_xdecoratorprops1;
                const { name } = useCollection_deprecated();
                const fieldSchema = useFieldSchema();
                const defaultResource = (null == fieldSchema ? void 0 : null == (_fieldSchema_xdecoratorprops = fieldSchema['x-decorator-props']) ? void 0 : _fieldSchema_xdecoratorprops.resource) || (null == fieldSchema ? void 0 : null == (_fieldSchema_xdecoratorprops1 = fieldSchema['x-decorator-props']) ? void 0 : _fieldSchema_xdecoratorprops1.association);
                return {
                    componentName: 'FormItem',
                    collectionName: name,
                    resourceName: defaultResource
                };
            }
        },
        {
            name: 'divider2',
            type: 'divider'
        },
        {
            name: 'remove',
            type: 'remove',
            componentProps: {
                removeParentsIfNoChildren: true,
                breakRemoveOn: {
                    'x-component': 'Grid'
                }
            }
        }
    ]
});
const createFormBlockSettings = new SchemaSettings({
    name: 'blockSettings:createForm',
    items: [
        {
            name: 'title',
            Component: SchemaSettingsBlockTitleItem
        },
        {
            name: 'linkageRules',
            Component: SchemaSettingsLinkageRules,
            useComponentProps () {
                const { name } = useCollection_deprecated();
                return {
                    collectionName: name
                };
            }
        },
        {
            name: 'dataTemplates',
            Component: SchemaSettingsDataTemplates,
            useVisible () {
                const { action } = useFormBlockContext();
                return !action;
            },
            useComponentProps () {
                const { name } = useCollection_deprecated();
                return {
                    collectionName: name
                };
            }
        },
        {
            name: 'divider',
            type: 'divider'
        },
        {
            name: 'formItemTemplate',
            Component: SchemaSettingsFormItemTemplate,
            useComponentProps () {
                var _fieldSchema_xdecoratorprops, _fieldSchema_xdecoratorprops1;
                const { name } = useCollection_deprecated();
                const fieldSchema = useFieldSchema();
                const defaultResource = (null == fieldSchema ? void 0 : null == (_fieldSchema_xdecoratorprops = fieldSchema['x-decorator-props']) ? void 0 : _fieldSchema_xdecoratorprops.resource) || (null == fieldSchema ? void 0 : null == (_fieldSchema_xdecoratorprops1 = fieldSchema['x-decorator-props']) ? void 0 : _fieldSchema_xdecoratorprops1.association);
                return {
                    componentName: 'FormItem',
                    collectionName: name,
                    resourceName: defaultResource
                };
            }
        },
        {
            name: 'divider2',
            type: 'divider'
        },
        {
            name: 'remove',
            type: 'remove',
            componentProps: {
                removeParentsIfNoChildren: true,
                breakRemoveOn: {
                    'x-component': 'Grid'
                }
            }
        }
    ]
});
export { createFormBlockSettings, creationFormBlockSettings };
