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_components__ from "@tachybase/components";
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_antd_style__ from "antd-style";
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__type_mjs__ from "./type.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__useValues_mjs__ from "./useValues.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__ValueDynamicComponent_mjs__ from "./ValueDynamicComponent.mjs";
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, __WEBPACK_EXTERNAL_MODULE_antd_style__.createStyles)((param)=>{
    let { css } = param;
    return {
        container: css(_templateObject()),
        item: css(_templateObject1()),
        select: css(_templateObject2()),
        tree: css(_templateObject3())
    };
});
const FormFieldLinkageRuleAction = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.observer)((props)=>{
    const { value, options, collectionName } = props;
    const { styles } = useStyles();
    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__.RemoveActionContext);
    const { schema, fields, operator, setDataIndex, setOperator, setValue, value: fieldValue, operators } = (0, __WEBPACK_EXTERNAL_MODULE__useValues_mjs__.useValues)(options);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__context_mjs__.LinkageLogicContext.Provider, {
        value: (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.uid)(),
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
            style: {
                marginBottom: 8
            },
            className: styles.container,
            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE_antd__.Space, {
                className: styles.item,
                children: [
                    /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_components__.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, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.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')
                    }),
                    [
                        __WEBPACK_EXTERNAL_MODULE__type_mjs__.ActionType.Value
                    ].includes(operator) && /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__ValueDynamicComponent_mjs__.ValueDynamicComponent, {
                        fieldValue: fieldValue,
                        schema: schema,
                        setValue: setValue,
                        collectionName: collectionName
                    }),
                    !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: {
                                color: '#bfbfbf'
                            }
                        })
                    })
                ]
            })
        })
    });
}, {
    displayName: 'FormFieldLinkageRuleAction'
});
const FormButtonLinkageRuleAction = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.observer)((props)=>{
    const { value, options } = props;
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    const compile = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useCompile)();
    const [editFlag, setEditFlag] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(false);
    const remove = (0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(__WEBPACK_EXTERNAL_MODULE__context_mjs__.RemoveActionContext);
    const { schema, operator, setOperator, setValue } = (0, __WEBPACK_EXTERNAL_MODULE__useValues_mjs__.useValues)(options);
    const operators = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>compile([
            {
                label: t('Visible'),
                value: __WEBPACK_EXTERNAL_MODULE__type_mjs__.ActionType.Visible,
                schema: {}
            },
            {
                label: t('Hidden'),
                value: __WEBPACK_EXTERNAL_MODULE__type_mjs__.ActionType.Hidden,
                schema: {}
            },
            {
                label: t('Disabled'),
                value: __WEBPACK_EXTERNAL_MODULE__type_mjs__.ActionType.Disabled,
                schema: {}
            },
            {
                label: t('Enabled'),
                value: __WEBPACK_EXTERNAL_MODULE__type_mjs__.ActionType.Active,
                schema: {}
            }
        ]), [
        compile,
        t
    ]);
    const onChange = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((value)=>{
        const flag = [
            __WEBPACK_EXTERNAL_MODULE__type_mjs__.ActionType.Value
        ].includes(value);
        setEditFlag(flag);
        setOperator(value);
    }, [
        setOperator
    ]);
    const onChangeValue = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((value)=>{
        setValue(value);
    }, [
        setValue
    ]);
    const closeStyle = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
            color: '#bfbfbf'
        }), []);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
        style: {
            marginBottom: 8
        },
        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__.Select, {
                    "data-testid": "select-linkage-properties",
                    popupMatchSelectWidth: false,
                    value: operator,
                    options: operators,
                    onChange: onChange,
                    placeholder: t('action')
                }),
                editFlag && /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createElement(__WEBPACK_EXTERNAL_MODULE__DynamicComponent_mjs__.DynamicComponent, {
                    value,
                    schema,
                    onChange: onChangeValue
                }),
                !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: closeStyle
                    })
                })
            ]
        })
    });
}, {
    displayName: 'FormButtonLinkageRuleAction'
});
export { FormButtonLinkageRuleAction, FormFieldLinkageRuleAction };
