import { useField, useFieldSchema } from "@tachybase/schema";
import { useCollectionField, useCollectionManager } from "../data-source/index.mjs";
import { useIsFileField } from "../schema-component/antd/form-item/FormItem.Settings.mjs";
import { useColumnSchema } from "../schema-component/antd/table-v2/Table.Column.Decorator.mjs";
function useFieldComponentName() {
    var _fieldSchema_xcomponentprops, _field_componentProps, _collectionField_uiSchema, _fieldSchema_xcomponentprops1;
    const { fieldSchema: tableColumnSchema, collectionField: tableColumnField } = useColumnSchema();
    const field = useField();
    const cm = useCollectionManager();
    const isFileField = useIsFileField();
    const schema = useFieldSchema();
    const targetCollectionField = useCollectionField();
    const targetCollection = cm.getCollection(null == targetCollectionField ? void 0 : targetCollectionField.target);
    const isTreeCollection = (null == targetCollection ? void 0 : targetCollection.template) === 'tree';
    const fieldSchema = tableColumnSchema || schema;
    const collectionField = tableColumnField || targetCollectionField;
    const map = {
        AssociationField: isTreeCollection ? 'Cascader' : 'Select'
    };
    const fieldComponentName = (null == fieldSchema ? void 0 : null == (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops['mode']) || (null == field ? void 0 : null == (_field_componentProps = field.componentProps) ? void 0 : _field_componentProps['mode']) || (isFileField ? 'FileManager' : '') || (null == collectionField ? void 0 : null == (_collectionField_uiSchema = collectionField.uiSchema) ? void 0 : _collectionField_uiSchema['x-component']);
    return map[fieldComponentName] || fieldComponentName || (null == (_fieldSchema_xcomponentprops1 = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops1['component']);
}
export { useFieldComponentName };
