import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import * as __WEBPACK_EXTERNAL_MODULE__schema_initializer_utils_mjs__ from "../../schema-initializer/utils.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__CollectionFieldsToInitializerItems_mjs__ from "./CollectionFieldsToInitializerItems.mjs";
const findKanbanFormItem = (schema, key, action)=>{
    const s = (0, __WEBPACK_EXTERNAL_MODULE__schema_initializer_utils_mjs__.findSchema)(schema, 'x-component', 'Kanban');
    return (0, __WEBPACK_EXTERNAL_MODULE__schema_initializer_utils_mjs__.findSchema)(s, key, action);
};
const CollectionFieldsToFormInitializerItems = (props)=>{
    const block = (null == props ? void 0 : props.block) || 'Form';
    const fieldItemSchema = {
        'x-toolbar': 'FormItemSchemaToolbar',
        'x-settings': 'fieldSettings:FormItem',
        'x-decorator': 'FormItem'
    };
    const initializerItem = {
        remove: __WEBPACK_EXTERNAL_MODULE__schema_initializer_utils_mjs__.removeGridFormItem
    };
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__CollectionFieldsToInitializerItems_mjs__.CollectionFieldsToInitializerItems, {
        block: block,
        selfField: {
            filter: (field)=>!field.treeChildren,
            getSchema: (field, param)=>{
                let { targetCollection } = param;
                var _field_uiSchema_xcomponentprops, _field_uiSchema;
                const isFileCollection = (null == targetCollection ? void 0 : targetCollection.template) === 'file';
                const isAssociationField = targetCollection;
                const fieldNames = null == field ? void 0 : null === (_field_uiSchema = field.uiSchema) || void 0 === _field_uiSchema ? void 0 : null === (_field_uiSchema_xcomponentprops = _field_uiSchema['x-component-props']) || void 0 === _field_uiSchema_xcomponentprops ? void 0 : _field_uiSchema_xcomponentprops['fieldNames'];
                return {
                    ...fieldItemSchema,
                    'x-component-props': isFileCollection ? {
                        fieldNames: {
                            label: 'preview',
                            value: 'id'
                        }
                    } : isAssociationField && fieldNames ? {
                        fieldNames: {
                            ...fieldNames,
                            label: (null == targetCollection ? void 0 : targetCollection.titleField) || fieldNames.label
                        }
                    } : {}
                };
            },
            getInitializerItem: ()=>({
                    ...initializerItem,
                    find: (null == props ? void 0 : props.block) === 'Kanban' ? findKanbanFormItem : void 0
                })
        },
        parentField: {
            getSchema: ()=>fieldItemSchema,
            getInitializerItem: ()=>initializerItem
        },
        associationField: {
            filterSelfField: (field)=>{
                if ('Form' !== block) return true;
                return (null == field ? void 0 : field.interface) === 'm2o';
            },
            filterAssociationField (collectionField) {
                return (null == collectionField ? void 0 : collectionField.interface) && ![
                    'subTable'
                ].includes(null == collectionField ? void 0 : collectionField.interface) && !collectionField.treeChildren;
            },
            getSchema: ()=>fieldItemSchema,
            getInitializerItem: ()=>initializerItem
        }
    });
};
export { CollectionFieldsToFormInitializerItems, findKanbanFormItem };
