import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE__ant_design_icons__ from "@ant-design/icons";
import * as __WEBPACK_EXTERNAL_MODULE_antd__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__index_mjs__ from "../../index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__context_mjs__ from "./context.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__DynamicComponent_mjs__ from "./DynamicComponent.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__useValues_mjs__ from "./useValues.mjs";
const FilterItem = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.observer)((props)=>{
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    const compile = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useCompile)();
    const remove = (0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(__WEBPACK_EXTERNAL_MODULE__context_mjs__.RemoveConditionContext);
    const { schema, fields, operators, dataIndex, operator, setDataIndex, setOperator, value, setValue, collectionField } = (0, __WEBPACK_EXTERNAL_MODULE__useValues_mjs__.useValues)();
    const style = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
            marginBottom: 8
        }), []);
    const fieldNames = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
            label: 'title',
            value: 'name',
            children: 'children'
        }), []);
    const onChange = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((value)=>{
        setDataIndex(value);
    }, [
        setDataIndex
    ]);
    const onOperatorsChange = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((value)=>{
        setOperator(value);
    }, [
        setOperator
    ]);
    const removeStyle = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
            color: '#bfbfbf'
        }), []);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
        style: style,
        className: "nc-filter-item",
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE_antd__.Space, {
            children: [
                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Cascader, {
                    "data-testid": "select-filter-field",
                    style: {
                        width: '160px'
                    },
                    fieldNames: fieldNames,
                    changeOnSelect: false,
                    value: dataIndex,
                    options: compile(fields),
                    onChange: onChange,
                    placeholder: t('Select field')
                }),
                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Select, {
                    "data-testid": "select-filter-operator",
                    style: {
                        minWidth: '110px'
                    },
                    popupMatchSelectWidth: false,
                    value: null == operator ? void 0 : operator.value,
                    options: compile(operators),
                    onChange: onOperatorsChange,
                    placeholder: t('Comparision')
                }),
                (null == operator ? void 0 : operator.noValue) ? null : /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__DynamicComponent_mjs__.DynamicComponent, {
                    value: value,
                    schema: schema,
                    collectionField: collectionField,
                    onChange: setValue
                }),
                !props.disabled && /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("a", {
                    role: "button",
                    "aria-label": "icon-close",
                    children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__ant_design_icons__.CloseCircleOutlined, {
                        onClick: remove,
                        style: removeStyle
                    })
                })
            ]
        })
    });
}, {
    displayName: 'FilterItem'
});
export { FilterItem };
