"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__, {
    FilterGroup: ()=>FilterGroup
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const schema_namespaceObject = require("@tachybase/schema");
const icons_namespaceObject = require("@ant-design/icons");
const external_antd_namespaceObject = require("antd");
const external_react_i18next_namespaceObject = require("react-i18next");
const index_js_namespaceObject = require("../__builtins__/index.js");
const external_context_js_namespaceObject = require("./context.js");
const external_FilterItems_js_namespaceObject = require("./FilterItems.js");
const FilterGroup = (0, schema_namespaceObject.connect)((props)=>{
    const { bordered = true, disabled } = props;
    const field = (0, schema_namespaceObject.useField)();
    const remove = (0, external_react_namespaceObject.useContext)(external_context_js_namespaceObject.RemoveConditionContext);
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const { token } = (0, index_js_namespaceObject.useToken)();
    const keys = Object.keys(field.value || {});
    const logic = keys.includes('$or') ? '$or' : '$and';
    const setLogic = (value)=>{
        const obj = field.value || {};
        field.value = {
            [value]: [
                ...obj[logic] || []
            ]
        };
    };
    const mergedDisabled = disabled || field.disabled;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_context_js_namespaceObject.FilterLogicContext.Provider, {
        value: logic,
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
            style: bordered ? {
                position: 'relative',
                border: "1px dashed ".concat(token.colorBorder),
                padding: token.paddingSM,
                marginBottom: token.marginXS
            } : {
                position: 'relative',
                marginBottom: token.marginXS
            },
            children: [
                remove && !mergedDisabled && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("a", {
                    role: "button",
                    "aria-label": "icon-close",
                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icons_namespaceObject.CloseCircleOutlined, {
                        style: {
                            position: 'absolute',
                            right: 10,
                            top: 10,
                            color: '#bfbfbf'
                        },
                        onClick: ()=>remove()
                    })
                }),
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                    style: {
                        marginBottom: 8,
                        color: token.colorText
                    },
                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_react_i18next_namespaceObject.Trans, {
                        children: [
                            'Meet ',
                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_antd_namespaceObject.Select, {
                                role: "button",
                                "data-testid": "filter-select-all-or-any",
                                style: {
                                    width: 'auto'
                                },
                                value: logic,
                                onChange: (value)=>{
                                    setLogic(value);
                                },
                                children: [
                                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Select.Option, {
                                        value: '$and',
                                        children: "All"
                                    }),
                                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Select.Option, {
                                        value: '$or',
                                        children: "Any"
                                    })
                                ]
                            }),
                            ' conditions in the group'
                        ]
                    })
                }),
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(schema_namespaceObject.ArrayFieldComponent, {
                        name: logic,
                        component: [
                            external_FilterItems_js_namespaceObject.FilterItems
                        ],
                        disabled: mergedDisabled
                    })
                }),
                !mergedDisabled && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_antd_namespaceObject.Space, {
                    size: 16,
                    style: {
                        marginTop: 8,
                        marginBottom: 8
                    },
                    children: [
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("a", {
                            onClick: ()=>{
                                const value = field.value || {};
                                const items = value[logic] || [];
                                items.push({});
                                field.value = {
                                    [logic]: items
                                };
                            },
                            children: t('Add condition')
                        }),
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("a", {
                            onClick: ()=>{
                                const value = field.value || {};
                                const items = value[logic] || [];
                                items.push({
                                    $and: [
                                        {}
                                    ]
                                });
                                field.value = {
                                    [logic]: items
                                };
                            },
                            children: t('Add condition group')
                        })
                    ]
                })
            ]
        })
    });
});
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
});
