import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__ from "../../collection-manager/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__type_mjs__ from "./type.mjs";
const useLinkageCollectionFieldOptions = (collectionName)=>{
    const { getCollectionFields, getInterface } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollectionManager_deprecated)();
    const fields = getCollectionFields(collectionName).filter((v)=>![
            'id',
            'createdAt',
            'createdBy',
            'updatedAt',
            'updatedBy'
        ].includes(v.name));
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    const operators = [
        {
            label: t('Visible'),
            value: __WEBPACK_EXTERNAL_MODULE__type_mjs__.ActionType.Visible,
            selected: true,
            schema: {}
        },
        {
            label: t('Editable'),
            value: __WEBPACK_EXTERNAL_MODULE__type_mjs__.ActionType.Editable,
            selected: false,
            schema: {}
        },
        {
            label: t('Disabled'),
            value: __WEBPACK_EXTERNAL_MODULE__type_mjs__.ActionType.ReadOnly,
            selected: false,
            schema: {}
        },
        {
            label: t('Easy reading'),
            value: __WEBPACK_EXTERNAL_MODULE__type_mjs__.ActionType.ReadPretty,
            selected: false,
            schema: {}
        },
        {
            label: t('Hidden'),
            value: __WEBPACK_EXTERNAL_MODULE__type_mjs__.ActionType.None,
            selected: false,
            schema: {}
        },
        {
            label: t('Hidden(reserved value)'),
            value: __WEBPACK_EXTERNAL_MODULE__type_mjs__.ActionType.Hidden,
            selected: false,
            schema: {}
        },
        {
            label: t('Required'),
            value: __WEBPACK_EXTERNAL_MODULE__type_mjs__.ActionType.Required,
            selected: false,
            schema: {}
        },
        {
            label: t('Not required'),
            value: __WEBPACK_EXTERNAL_MODULE__type_mjs__.ActionType.InRequired,
            selected: false,
            schema: {}
        },
        {
            label: t('Value'),
            value: __WEBPACK_EXTERNAL_MODULE__type_mjs__.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 ? 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 ? void 0 : _operators_filter.call(operators, (operator)=>{
                if (nested || children || [
                    'formula',
                    'richText',
                    'sequence'
                ].includes(fieldInterface.name)) return (null == operator ? void 0 : operator.value) !== __WEBPACK_EXTERNAL_MODULE__type_mjs__.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 };
