import { jsx } from "react/jsx-runtime";
import "react";
import { RecursionField, observer } from "@tachybase/schema";
import { useCollectionManager_deprecated } from "../../../../collection-manager/index.mjs";
import { useRecord } from "../../../../record-provider/index.mjs";
const ColumnFieldProvider = observer((props)=>{
    const { schema, basePath } = props;
    const record = useRecord();
    const { getCollectionJoinField } = useCollectionManager_deprecated();
    const fieldSchema = schema.reduceProperties((buf, s)=>{
        if ('CollectionField' === s['x-component']) return s;
        return buf;
    }, null);
    const collectionField = fieldSchema && getCollectionJoinField(fieldSchema['x-collection-field']);
    if (fieldSchema && (null == record ? void 0 : record.__collection) && collectionField && [
        'select',
        'multipleSelect'
    ].includes(collectionField.interface)) {
        const fieldName = "".concat(record.__collection, ".").concat(fieldSchema.name);
        const newSchema = {
            ...schema.toJSON(),
            properties: {
                [fieldSchema.name]: {
                    ...fieldSchema.toJSON(),
                    'x-collection-field': fieldName
                }
            }
        };
        return /*#__PURE__*/ jsx(RecursionField, {
            basePath: basePath,
            schema: newSchema,
            onlyRenderProperties: true
        });
    }
    return props.children;
}, {
    displayName: 'ColumnFieldProvider'
});
export { ColumnFieldProvider };
