import { useTranslation } from "react-i18next";
import { useCollectionManager_deprecated } from "../../collection-manager/index.mjs";
import { ActionType } from "./type.mjs";
const useLinkageCollectionFieldOptions = (collectionName)=>{
    const { getCollectionFields, getInterface } = useCollectionManager_deprecated();
    const fields = getCollectionFields(collectionName).filter((v)=>![
            'id',
            'createdAt',
            'createdBy',
            'updatedAt',
            'updatedBy'
        ].includes(v.name));
    const { t } = useTranslation();
    const operators = [
        {
            label: t('Visible'),
            value: ActionType.Visible,
            selected: true,
            schema: {}
        },
        {
            label: t('Editable'),
            value: ActionType.Editable,
            selected: false,
            schema: {}
        },
        {
            label: t('Disabled'),
            value: ActionType.ReadOnly,
            selected: false,
            schema: {}
        },
        {
            label: t('Easy reading'),
            value: ActionType.ReadPretty,
            selected: false,
            schema: {}
        },
        {
            label: t('Hidden'),
            value: ActionType.None,
            selected: false,
            schema: {}
        },
        {
            label: t('Hidden(reserved value)'),
            value: ActionType.Hidden,
            selected: false,
            schema: {}
        },
        {
            label: t('Required'),
            value: ActionType.Required,
            selected: false,
            schema: {}
        },
        {
            label: t('Not required'),
            value: ActionType.InRequired,
            selected: false,
            schema: {}
        },
        {
            label: t('Value'),
            value: ActionType.Value,
            selected: false,
            schema: {}
        }
    ];
    const field2option = (field, depth)=>{
        var _field_uiSchema, _operators_filter;
        const fieldInterface = getInterface(field.interface);
        if (!fieldInterface) return;
        const { nested, children } = (null == fieldInterface ? void 0 : fieldInterface.filterable) || {};
        const option = {
            name: field.name,
            title: (null == field ? void 0 : null == (_field_uiSchema = field.uiSchema) ? void 0 : _field_uiSchema.title) || field.name,
            schema: null == field ? void 0 : field.uiSchema,
            interface: field.interface,
            target: field.target,
            operators: (null == operators ? void 0 : null == (_operators_filter = operators.filter) ? void 0 : _operators_filter.call(operators, (operator)=>{
                if (nested || children || [
                    'formula',
                    'richText',
                    'sequence'
                ].includes(fieldInterface.name)) return (null == operator ? void 0 : operator.value) !== ActionType.Value;
                return true;
            })) || []
        };
        if (field.target && depth > 2) return;
        return option;
    };
    const getOptions = (fields, depth)=>{
        const options = [];
        fields.forEach((field)=>{
            const option = field2option(field, depth);
            if (option) options.push(option);
        });
        return options;
    };
    return getOptions(fields, 1);
};
export { useLinkageCollectionFieldOptions };
