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_antd__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__application_hoc_withDynamicSchemaProps_mjs__ from "../../application/hoc/withDynamicSchemaProps.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_hooks_useProps_mjs__ from "../../schema-component/hooks/useProps.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__context_mjs__ from "./context.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__LinkageRuleAction_mjs__ from "./LinkageRuleAction.mjs";
const LinkageRuleActions = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.observer)((props)=>{
    var _field_value;
    const { type, linkageOptions } = props;
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    return null == field ? void 0 : null === (_field_value = field.value) || void 0 === _field_value ? void 0 : _field_value.map((item, index)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__context_mjs__.RemoveActionContext.Provider, {
            value: ()=>field.remove(index),
            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_schema__.ObjectFieldComponent, {
                name: index,
                component: [
                    'button' === type ? __WEBPACK_EXTERNAL_MODULE__LinkageRuleAction_mjs__.FormButtonLinkageRuleAction : __WEBPACK_EXTERNAL_MODULE__LinkageRuleAction_mjs__.FormFieldLinkageRuleAction,
                    {
                        ...props,
                        options: linkageOptions
                    }
                ]
            })
        }, index));
}, {
    displayName: 'LinkageRuleActions'
});
const LinkageRuleActionGroup = (0, __WEBPACK_EXTERNAL_MODULE__application_hoc_withDynamicSchemaProps_mjs__.withDynamicSchemaProps)((props)=>{
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    const logic = 'actions';
    const { type, linkageOptions, collectionName } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_hooks_useProps_mjs__.useProps)(props);
    const style = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
            marginLeft: 10
        }), []);
    const components = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>[
            LinkageRuleActions,
            {
                type,
                linkageOptions,
                collectionName
            }
        ], [
        collectionName,
        linkageOptions,
        type
    ]);
    const spaceStyle = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
            marginTop: 8,
            marginBottom: 8
        }), []);
    const onClick = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>{
        const f = field.query('.actions').take();
        const items = f.value || [];
        items.push({});
        f.value = items;
    }, [
        field
    ]);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
        style: style,
        children: [
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_schema__.ArrayFieldComponent, {
                name: logic,
                component: components,
                disabled: false
            }),
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Space, {
                size: 16,
                style: spaceStyle,
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("a", {
                    onClick: onClick,
                    children: t('Add property')
                })
            })
        ]
    });
}, {
    displayName: 'LinkageRuleActionGroup'
});
export { LinkageRuleActionGroup, LinkageRuleActions };
