"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = function(module) {
        var getter = module && module.__esModule ? function() {
            return module['default'];
        } : function() {
            return module;
        };
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __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__, {
    FormFieldLinkageRuleAction: ()=>FormFieldLinkageRuleAction,
    FormButtonLinkageRuleAction: ()=>FormButtonLinkageRuleAction
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
const components_namespaceObject = require("@tachybase/components");
const schema_namespaceObject = require("@tachybase/schema");
const icons_namespaceObject = require("@ant-design/icons");
const external_antd_namespaceObject = require("antd");
const external_antd_style_namespaceObject = require("antd-style");
const external_react_i18next_namespaceObject = require("react-i18next");
const external_index_js_namespaceObject = require("../../index.js");
const external_context_js_namespaceObject = require("./context.js");
const external_DynamicComponent_js_namespaceObject = require("./DynamicComponent.js");
const external_type_js_namespaceObject = require("./type.js");
const external_useValues_js_namespaceObject = require("./useValues.js");
const external_ValueDynamicComponent_js_namespaceObject = require("./ValueDynamicComponent.js");
function _tagged_template_literal(strings, raw) {
    if (!raw) raw = strings.slice(0);
    return Object.freeze(Object.defineProperties(strings, {
        raw: {
            value: Object.freeze(raw)
        }
    }));
}
function _templateObject() {
    const data = _tagged_template_literal([
        "\n      .ant-space {\n        display: inline-block;\n      }\n    "
    ]);
    _templateObject = function() {
        return data;
    };
    return data;
}
function _templateObject1() {
    const data = _tagged_template_literal([
        "\n      .ant-space {\n        display: inline-block;\n      }\n      .ant-space-item {\n        max-width: 95%;\n        display: inline-block;\n        margin: 2px;\n        vertical-align: top;\n      }\n    "
    ]);
    _templateObject1 = function() {
        return data;
    };
    return data;
}
function _templateObject2() {
    const data = _tagged_template_literal([
        "\n      min-width: 120px;\n    "
    ]);
    _templateObject2 = function() {
        return data;
    };
    return data;
}
function _templateObject3() {
    const data = _tagged_template_literal([
        "\n      min-width: 160px;\n    "
    ]);
    _templateObject3 = function() {
        return data;
    };
    return data;
}
const useStyles = (0, external_antd_style_namespaceObject.createStyles)((param)=>{
    let { css } = param;
    return {
        container: css(_templateObject()),
        item: css(_templateObject1()),
        select: css(_templateObject2()),
        tree: css(_templateObject3())
    };
});
const FormFieldLinkageRuleAction = (0, schema_namespaceObject.observer)((props)=>{
    const { value, options, collectionName } = props;
    const { styles } = useStyles();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const compile = (0, external_index_js_namespaceObject.useCompile)();
    const remove = (0, external_react_namespaceObject.useContext)(external_context_js_namespaceObject.RemoveActionContext);
    const { schema, fields, operator, setDataIndex, setOperator, setValue, value: fieldValue, operators } = (0, external_useValues_js_namespaceObject.useValues)(options);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_context_js_namespaceObject.LinkageLogicContext.Provider, {
        value: (0, schema_namespaceObject.uid)(),
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
            style: {
                marginBottom: 8
            },
            className: styles.container,
            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_antd_namespaceObject.Space, {
                className: styles.item,
                children: [
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(components_namespaceObject.TreeSelect, {
                        role: "button",
                        "data-testid": "select-linkage-property-field",
                        className: styles.tree,
                        fieldNames: {
                            label: 'title',
                            value: 'name',
                            children: 'children'
                        },
                        treeCheckable: true,
                        value: null == value ? void 0 : value.targetFields,
                        multiple: true,
                        allowClear: true,
                        treeData: compile(fields),
                        onChange: (value)=>{
                            setDataIndex(value);
                        },
                        placeholder: t('Select field')
                    }),
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Select, {
                        role: "button",
                        "data-testid": "select-linkage-action-field",
                        popupMatchSelectWidth: false,
                        value: operator,
                        className: styles.select,
                        options: compile(operators),
                        onChange: (value)=>{
                            setOperator(value);
                        },
                        placeholder: t('action')
                    }),
                    [
                        external_type_js_namespaceObject.ActionType.Value
                    ].includes(operator) && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_ValueDynamicComponent_js_namespaceObject.ValueDynamicComponent, {
                        fieldValue: fieldValue,
                        schema: schema,
                        setValue: setValue,
                        collectionName: collectionName
                    }),
                    !props.disabled && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("a", {
                        role: "button",
                        "aria-label": "icon-close",
                        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icons_namespaceObject.CloseCircleOutlined, {
                            onClick: ()=>remove(),
                            style: {
                                color: '#bfbfbf'
                            }
                        })
                    })
                ]
            })
        })
    });
}, {
    displayName: 'FormFieldLinkageRuleAction'
});
const FormButtonLinkageRuleAction = (0, schema_namespaceObject.observer)((props)=>{
    const { value, options } = props;
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const compile = (0, external_index_js_namespaceObject.useCompile)();
    const [editFlag, setEditFlag] = (0, external_react_namespaceObject.useState)(false);
    const remove = (0, external_react_namespaceObject.useContext)(external_context_js_namespaceObject.RemoveActionContext);
    const { schema, operator, setOperator, setValue } = (0, external_useValues_js_namespaceObject.useValues)(options);
    const operators = (0, external_react_namespaceObject.useMemo)(()=>compile([
            {
                label: t('Visible'),
                value: external_type_js_namespaceObject.ActionType.Visible,
                schema: {}
            },
            {
                label: t('Hidden'),
                value: external_type_js_namespaceObject.ActionType.Hidden,
                schema: {}
            },
            {
                label: t('Disabled'),
                value: external_type_js_namespaceObject.ActionType.Disabled,
                schema: {}
            },
            {
                label: t('Enabled'),
                value: external_type_js_namespaceObject.ActionType.Active,
                schema: {}
            }
        ]), [
        compile,
        t
    ]);
    const onChange = (0, external_react_namespaceObject.useCallback)((value)=>{
        const flag = [
            external_type_js_namespaceObject.ActionType.Value
        ].includes(value);
        setEditFlag(flag);
        setOperator(value);
    }, [
        setOperator
    ]);
    const onChangeValue = (0, external_react_namespaceObject.useCallback)((value)=>{
        setValue(value);
    }, [
        setValue
    ]);
    const closeStyle = (0, external_react_namespaceObject.useMemo)(()=>({
            color: '#bfbfbf'
        }), []);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
        style: {
            marginBottom: 8
        },
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_antd_namespaceObject.Space, {
            children: [
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Select, {
                    "data-testid": "select-linkage-properties",
                    popupMatchSelectWidth: false,
                    value: operator,
                    options: operators,
                    onChange: onChange,
                    placeholder: t('action')
                }),
                editFlag && /*#__PURE__*/ external_react_default().createElement(external_DynamicComponent_js_namespaceObject.DynamicComponent, {
                    value,
                    schema,
                    onChange: onChangeValue
                }),
                !props.disabled && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("a", {
                    role: "button",
                    "aria-label": "icon-close",
                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icons_namespaceObject.CloseCircleOutlined, {
                        onClick: remove,
                        style: closeStyle
                    })
                })
            ]
        })
    });
}, {
    displayName: 'FormButtonLinkageRuleAction'
});
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
});
