import { useMemo } from "react";
import { useFieldSchema } from "@tachybase/schema";
import { useTranslation } from "react-i18next";
import { useCollectionManager_deprecated, useCollection_deprecated } from "../../collection-manager/index.mjs";
const useFieldComponentOptions = ()=>{
    var _fieldSchema_xcomponentprops;
    const { getCollectionJoinField, getCollection } = useCollectionManager_deprecated();
    const fieldSchema = useFieldSchema();
    const { getField } = useCollection_deprecated();
    const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
    const { t } = useTranslation();
    const { label } = (null == (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops.fieldNames) || {};
    const fieldComponentOptions = useMemo(()=>{
        if (!collectionField || !(null == collectionField ? void 0 : collectionField.interface)) return;
        if (![
            'o2o',
            'oho',
            'obo',
            'o2m',
            'linkTo',
            'm2o',
            'm2m'
        ].includes(collectionField.interface)) return;
        const collection = getCollection(collectionField.target);
        if ((null == collection ? void 0 : collection.template) === 'file') return [
            {
                label: t('Record picker'),
                value: 'CollectionField'
            },
            {
                label: t('Select'),
                value: 'AssociationSelect'
            }
        ];
        switch(collectionField.interface){
            case 'o2m':
                return [
                    {
                        label: t('Record picker'),
                        value: 'CollectionField'
                    },
                    {
                        label: t('Subtable'),
                        value: 'TableField'
                    },
                    {
                        label: t('Select'),
                        value: 'AssociationSelect'
                    }
                ];
            case 'm2o':
            case 'm2m':
            case 'linkTo':
                return [
                    {
                        label: t('Record picker'),
                        value: 'CollectionField'
                    },
                    {
                        label: t('Select'),
                        value: 'AssociationSelect'
                    }
                ];
            default:
                return [
                    {
                        label: t('Record picker'),
                        value: 'CollectionField'
                    },
                    {
                        label: t('Subform'),
                        value: 'FormField'
                    },
                    {
                        label: t('Select'),
                        value: 'AssociationSelect'
                    }
                ];
        }
    }, [
        t,
        null == collectionField ? void 0 : collectionField.interface,
        label
    ]);
    return fieldComponentOptions;
};
export { useFieldComponentOptions };
