"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = function(exports1, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
(()=>{
    __webpack_require__.r = function(exports1) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    useFilterVariable: ()=>useFilterVariable
});
const external_react_namespaceObject = require("react");
const schema_namespaceObject = require("@tachybase/schema");
const external_react_i18next_namespaceObject = require("react-i18next");
const index_js_namespaceObject = require("../../../block-provider/index.js");
const context_js_namespaceObject = require("../../filter-form/context.js");
const useFilterVariable = function() {
    let props = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
    var _props_form;
    const customFilter = (0, context_js_namespaceObject.useFilterContext)();
    const field = (0, schema_namespaceObject.useField)();
    const { getActiveFieldsName } = (0, index_js_namespaceObject.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, external_react_i18next_namespaceObject.useTranslation)();
    const settings = (0, external_react_namespaceObject.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
    };
};
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
