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__block_provider_index_mjs__ from "../../../block-provider/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__filter_form_context_mjs__ from "../../filter-form/context.mjs";
const useFilterVariable = function() {
    let props = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
    var _props_form;
    const customFilter = (0, __WEBPACK_EXTERNAL_MODULE__filter_form_context_mjs__.useFilterContext)();
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    const { getActiveFieldsName } = (0, __WEBPACK_EXTERNAL_MODULE__block_provider_index_mjs__.useFormActiveFields)();
    const activeFields = getActiveFieldsName('form');
    const fields = null == props ? void 0 : null === (_props_form = props.form) || void 0 === _props_form ? void 0 : _props_form.fields;
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    const settings = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
        const customFields = [];
        for(const field in fields)customFields.push({
            key: field,
            ...fields[field]
        });
        const options = customFields.filter((value)=>{
            var _value_props;
            return null == value ? void 0 : null === (_value_props = value.props) || void 0 === _value_props ? void 0 : _value_props.name.includes('__custom.');
        }).map((custom)=>{
            var _custom_props;
            if (!activeFields.includes(null == custom ? void 0 : null === (_custom_props = custom.props) || void 0 === _custom_props ? void 0 : _custom_props.name)) return null;
            {
                var _custom_props1, _custom_props2;
                const value = null == custom ? void 0 : null === (_custom_props1 = custom.props) || void 0 === _custom_props1 ? void 0 : _custom_props1.name.replace(/^__custom\./, '');
                return {
                    key: null == custom ? void 0 : null === (_custom_props2 = custom.props) || void 0 === _custom_props2 ? void 0 : _custom_props2.name,
                    value,
                    label: custom.title
                };
            }
        }).filter(Boolean);
        return {
            label: t('Current filter'),
            value: '$nFilter',
            key: '$nFilter',
            children: options
        };
    }, [
        fields
    ]);
    return {
        currentCustomFilterSetting: settings,
        currentCustonFilterCtx: null == field ? void 0 : field.value,
        shouldDisplayCustomFilter: !!customFilter
    };
};
export { useFilterVariable };
