import { jsx } from "react/jsx-runtime";
import "react";
import { useTranslation } from "react-i18next";
import { SchemaInitializerChildren } from "../../../../application/schema-initializer/components/SchemaInitializerChildren.mjs";
import { SchemaInitializer } from "../../../../application/schema-initializer/SchemaInitializer.mjs";
import { useCompile } from "../../../../schema-component/index.mjs";
import { gridRowColWrap, useAssociatedFormItemInitializerFields, useFormItemInitializerFields, useInheritsFormItemInitializerFields } from "../../../../schema-initializer/utils.mjs";
const ParentCollectionFields = ()=>{
    const inheritFields = useInheritsFormItemInitializerFields();
    const { t } = useTranslation();
    const compile = useCompile();
    if (!(null == inheritFields ? void 0 : inheritFields.length)) return null;
    const res = [];
    inheritFields.forEach((inherit)=>{
        Object.values(inherit)[0].length && res.push({
            type: 'itemGroup',
            divider: true,
            title: t("Parent collection fields") + '(' + compile("".concat(Object.keys(inherit)[0])) + ')',
            children: Object.values(inherit)[0]
        });
    });
    return /*#__PURE__*/ jsx(SchemaInitializerChildren, {
        children: res
    });
};
const AssociatedFields = ()=>{
    const associationFields = useAssociatedFormItemInitializerFields({
        readPretty: true,
        block: 'Form'
    });
    const { t } = useTranslation();
    if (0 === associationFields.length) return null;
    const schema = [
        {
            type: 'itemGroup',
            title: t('Display association fields'),
            children: associationFields
        }
    ];
    return /*#__PURE__*/ jsx(SchemaInitializerChildren, {
        children: schema
    });
};
const readPrettyFormItemInitializers = new SchemaInitializer({
    name: 'details:configureFields',
    wrap: gridRowColWrap,
    icon: 'SettingOutlined',
    title: '{{t("Configure fields")}}',
    items: [
        {
            type: 'itemGroup',
            name: 'displayFields',
            title: '{{t("Display fields")}}',
            useChildren: useFormItemInitializerFields
        },
        {
            name: 'parentCollectionFields',
            Component: ParentCollectionFields
        },
        {
            name: 'associationFields',
            Component: AssociatedFields
        },
        {
            name: 'divider',
            type: 'divider'
        },
        {
            name: 'addText',
            title: '{{t("Add text")}}',
            Component: 'BlockItemInitializer',
            schema: {
                type: 'void',
                'x-editable': false,
                'x-decorator': 'FormItem',
                'x-toolbar': 'BlockSchemaToolbar',
                'x-settings': 'blockSettings:markdown',
                'x-component': 'Markdown.Void',
                'x-component-props': {
                    content: '{{t("This is a demo text, **supports Markdown syntax**.")}}'
                }
            }
        }
    ]
});
export { readPrettyFormItemInitializers };
