import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__ from "../../../../collection-manager/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__record_provider_index_mjs__ from "../../../../record-provider/index.mjs";
const ColumnFieldProvider = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.observer)((props)=>{
    const { schema, basePath } = props;
    const record = (0, __WEBPACK_EXTERNAL_MODULE__record_provider_index_mjs__.useRecord)();
    const { getCollectionJoinField } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.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__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_schema__.RecursionField, {
            basePath: basePath,
            schema: newSchema,
            onlyRenderProperties: true
        });
    }
    return props.children;
}, {
    displayName: 'ColumnFieldProvider'
});
export { ColumnFieldProvider };
