import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__ from "../../collection-manager/index.mjs";
const useFieldModeOptions = (props)=>{
    var _fieldSchema_xcomponentprops;
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    const { getCollectionJoinField, getCollection } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollectionManager_deprecated)();
    const currentFieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    const fieldSchema = (null == props ? void 0 : props.fieldSchema) || currentFieldSchema;
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    const form = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useForm)();
    const isReadPretty = (null == fieldSchema ? void 0 : fieldSchema['x-read-pretty']) || field.readPretty || form.readPretty;
    const isTableField = null == props ? void 0 : props.fieldSchema;
    const { getField } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollection_deprecated)();
    const collectionField = (null == props ? void 0 : props.collectionField) || getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
    const { label } = (null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops.fieldNames) || {};
    const fieldModeOptions = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
        if (!collectionField || !(null == collectionField ? void 0 : collectionField.interface)) return;
        if (![
            'o2o',
            'oho',
            'obo',
            'o2m',
            'linkTo',
            'm2o',
            'm2m',
            'updatedBy',
            'createdBy'
        ].includes(collectionField.interface)) return;
        const collection = getCollection(collectionField.target);
        if ((null == collection ? void 0 : collection.template) === 'file') return isReadPretty ? [
            {
                label: t('Title'),
                value: 'Select'
            },
            {
                label: t('File manager'),
                value: 'FileManager'
            },
            {
                label: t('Tag'),
                value: 'Tag'
            }
        ] : [
            {
                label: t('Select'),
                value: 'Select'
            },
            {
                label: t('Record picker'),
                value: 'Picker'
            },
            {
                label: t('File manager'),
                value: 'FileManager'
            }
        ];
        if ((null == collection ? void 0 : collection.template) === 'tree' && [
            'm2m',
            'o2m',
            'm2o'
        ].includes(collectionField.interface)) return isReadPretty ? [
            {
                label: t('Title'),
                value: 'Select'
            },
            {
                label: t('Tag'),
                value: 'Tag'
            }
        ] : [
            {
                label: t('Select'),
                value: 'Select'
            },
            {
                label: t('Record picker'),
                value: 'Picker'
            },
            [
                'm2m',
                'o2m'
            ].includes(collectionField.interface) && {
                label: t('Sub-table'),
                value: 'SubTable'
            },
            {
                label: t('Cascade Select'),
                value: 'CascadeSelect'
            },
            !isTableField && {
                label: t('Sub-form'),
                value: 'Nester'
            },
            {
                label: t('Subform: Popover'),
                value: 'PopoverNester'
            },
            {
                label: t('Subtable: Drawer'),
                value: 'DrawerSubTable'
            },
            {
                label: t('Cascader'),
                value: 'Cascader'
            }
        ];
        switch(collectionField.interface){
            case 'o2m':
                return isReadPretty ? [
                    {
                        label: t('Title'),
                        value: 'Select'
                    },
                    {
                        label: t('Tag'),
                        value: 'Tag'
                    },
                    !isTableField && {
                        label: t('Sub-table'),
                        value: 'SubTable'
                    },
                    !isTableField && {
                        label: t('Sub-details'),
                        value: 'Nester'
                    }
                ] : [
                    {
                        label: t('Select'),
                        value: 'Select'
                    },
                    {
                        label: t('Record picker'),
                        value: 'Picker'
                    },
                    !isTableField && {
                        label: t('Sub-form'),
                        value: 'Nester'
                    },
                    {
                        label: t('Subform: Popover'),
                        value: 'PopoverNester'
                    },
                    {
                        label: t('Subtable: Drawer'),
                        value: 'DrawerSubTable'
                    },
                    !isTableField && {
                        label: t('Sub-table'),
                        value: 'SubTable'
                    }
                ];
            case 'm2m':
                return isReadPretty ? [
                    {
                        label: t('Title'),
                        value: 'Select'
                    },
                    {
                        label: t('Tag'),
                        value: 'Tag'
                    },
                    !isTableField && {
                        label: t('Sub-details'),
                        value: 'Nester'
                    },
                    !isTableField && {
                        label: t('Sub-table'),
                        value: 'SubTable'
                    }
                ] : [
                    {
                        label: t('Select'),
                        value: 'Select'
                    },
                    {
                        label: t('Record picker'),
                        value: 'Picker'
                    },
                    !isTableField && {
                        label: t('Sub-table'),
                        value: 'SubTable'
                    },
                    !isTableField && {
                        label: t('Sub-form'),
                        value: 'Nester'
                    },
                    {
                        label: t('Subform: Popover'),
                        value: 'PopoverNester'
                    },
                    {
                        label: t('Subtable: Drawer'),
                        value: 'DrawerSubTable'
                    }
                ];
            case 'm2o':
            case 'linkTo':
                return isReadPretty ? [
                    {
                        label: t('Title'),
                        value: 'Select'
                    },
                    {
                        label: t('Tag'),
                        value: 'Tag'
                    },
                    !isTableField && {
                        label: t('Sub-details'),
                        value: 'Nester'
                    }
                ] : [
                    {
                        label: t('Select'),
                        value: 'Select'
                    },
                    {
                        label: t('Record picker'),
                        value: 'Picker'
                    },
                    !isTableField && {
                        label: t('Sub-form'),
                        value: 'Nester'
                    },
                    {
                        label: t('Subform: Popover'),
                        value: 'PopoverNester'
                    },
                    {
                        label: t('Subtable: Drawer'),
                        value: 'DrawerSubTable'
                    },
                    {
                        label: t('Cascader'),
                        value: 'Cascader'
                    }
                ];
            default:
                return isReadPretty ? [
                    {
                        label: t('Title'),
                        value: 'Select'
                    },
                    {
                        label: t('Tag'),
                        value: 'Tag'
                    },
                    !isTableField && {
                        label: t('Sub-details'),
                        value: 'Nester'
                    }
                ] : [
                    {
                        label: t('Select'),
                        value: 'Select'
                    },
                    {
                        label: t('Record picker'),
                        value: 'Picker'
                    },
                    !isTableField && {
                        label: t('Sub-form'),
                        value: 'Nester'
                    },
                    {
                        label: t('Subform: Popover'),
                        value: 'PopoverNester'
                    },
                    {
                        label: t('Subtable: Drawer'),
                        value: 'DrawerSubTable'
                    }
                ];
        }
    }, [
        t,
        null == collectionField ? void 0 : collectionField.interface,
        label
    ]);
    return (fieldModeOptions || []).filter(Boolean);
};
export { useFieldModeOptions };
