"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__, {
    FormLinkageRules: ()=>FormLinkageRules
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const schema_namespaceObject = require("@tachybase/schema");
const external_antd_style_namespaceObject = require("antd-style");
const withDynamicSchemaProps_js_namespaceObject = require("../../application/hoc/withDynamicSchemaProps.js");
const index_js_namespaceObject = require("../../block-provider/index.js");
const external_collection_manager_index_js_namespaceObject = require("../../collection-manager/index.js");
const CollectionRecordProvider_js_namespaceObject = require("../../data-source/collection-record/CollectionRecordProvider.js");
const external_record_provider_index_js_namespaceObject = require("../../record-provider/index.js");
const external_schema_component_index_js_namespaceObject = require("../../schema-component/index.js");
const context_js_namespaceObject = require("../../schema-component/antd/filter/context.js");
const VariableInput_js_namespaceObject = require("../VariableInput/VariableInput.js");
const EnableLinkage_js_namespaceObject = require("./components/EnableLinkage.js");
const LinkageHeader_js_namespaceObject = require("./components/LinkageHeader.js");
const external_LinkageRuleActionGroup_js_namespaceObject = require("./LinkageRuleActionGroup.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      position: relative;\n      width: 100%;\n      margin-left: 10px;\n    "
    ]);
    _templateObject = function() {
        return data;
    };
    return data;
}
const useStyles = (0, external_antd_style_namespaceObject.createStyles)((param)=>{
    let { css } = param;
    return {
        filter: css(_templateObject())
    };
});
const FormLinkageRules = (0, withDynamicSchemaProps_js_namespaceObject.withDynamicSchemaProps)((0, schema_namespaceObject.observer)((props)=>{
    const { styles } = useStyles();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { options, defaultValues, collectionName, form, formBlockType, variables, localVariables, record, dynamicComponent } = (0, external_schema_component_index_js_namespaceObject.useProps)(props);
    const { getAllCollectionsInheritChain } = (0, external_collection_manager_index_js_namespaceObject.useCollectionManager_deprecated)();
    const parentRecordData = (0, CollectionRecordProvider_js_namespaceObject.useCollectionParentRecordData)();
    const components = (0, external_react_namespaceObject.useMemo)(()=>({
            ArrayCollapse: LinkageHeader_js_namespaceObject.ArrayCollapse
        }), []);
    const schema = (0, external_react_namespaceObject.useMemo)(()=>({
            type: 'object',
            properties: {
                rules: {
                    type: 'array',
                    default: defaultValues,
                    'x-component': 'ArrayCollapse',
                    'x-decorator': 'FormItem',
                    'x-component-props': {
                        accordion: true
                    },
                    items: {
                        type: 'object',
                        'x-component': 'ArrayCollapse.CollapsePanel',
                        'x-component-props': {
                            extra: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(EnableLinkage_js_namespaceObject.EnableLinkage, {})
                        },
                        properties: {
                            layout: {
                                type: 'void',
                                'x-component': 'FormLayout',
                                'x-component-props': {
                                    labelStyle: {
                                        marginTop: '6px'
                                    },
                                    labelCol: 8,
                                    wrapperCol: 16
                                },
                                properties: {
                                    conditions: {
                                        'x-component': 'h4',
                                        'x-content': '{{ t("Condition") }}'
                                    },
                                    condition: {
                                        'x-component': 'Filter',
                                        'x-use-component-props': ()=>({
                                                options,
                                                className: styles.filter
                                            }),
                                        'x-component-props': {
                                            collectionName,
                                            dynamicComponent: (props)=>{
                                                const { collectionField } = props;
                                                return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(VariableInput_js_namespaceObject.VariableInput, {
                                                    ...props,
                                                    form: form,
                                                    record: record,
                                                    shouldChange: (0, VariableInput_js_namespaceObject.getShouldChange)({
                                                        collectionField,
                                                        variables,
                                                        localVariables,
                                                        getAllCollectionsInheritChain
                                                    })
                                                });
                                            }
                                        }
                                    },
                                    actions: {
                                        'x-component': 'h4',
                                        'x-content': '{{ t("Properties") }}'
                                    },
                                    action: {
                                        type: 'void',
                                        'x-component': external_LinkageRuleActionGroup_js_namespaceObject.LinkageRuleActionGroup,
                                        'x-component-props': {
                                            ...props
                                        }
                                    }
                                }
                            },
                            remove: {
                                type: 'void',
                                'x-component': 'ArrayCollapse.Remove'
                            },
                            moveUp: {
                                type: 'void',
                                'x-component': 'ArrayCollapse.MoveUp'
                            },
                            moveDown: {
                                type: 'void',
                                'x-component': 'ArrayCollapse.MoveDown'
                            },
                            copy: {
                                type: 'void',
                                'x-component': 'ArrayCollapse.Copy'
                            }
                        }
                    },
                    properties: {
                        add: {
                            type: 'void',
                            title: '{{ t("Add linkage rule") }}',
                            'x-component': 'ArrayCollapse.Addition',
                            'x-reactions': {
                                dependencies: [
                                    'rules'
                                ],
                                fulfill: {
                                    state: {}
                                }
                            }
                        }
                    }
                }
            }
        }), [
        collectionName,
        defaultValues,
        form,
        localVariables,
        options,
        props,
        record,
        variables
    ]);
    const value = (0, external_react_namespaceObject.useMemo)(()=>({
            field: options,
            fieldSchema,
            dynamicComponent,
            options: options || []
        }), [
        dynamicComponent,
        fieldSchema,
        options
    ]);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.FormBlockContext.Provider, {
        value: {
            form,
            type: formBlockType,
            collectionName
        },
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_record_provider_index_js_namespaceObject.RecordProvider, {
            record: record,
            parent: parentRecordData,
            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(context_js_namespaceObject.FilterContext.Provider, {
                value: value,
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_component_index_js_namespaceObject.SchemaComponent, {
                    components: components,
                    schema: schema
                })
            })
        })
    });
}), {
    displayName: 'FormLinkageRules'
});
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
});
