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_style__ from "antd-style";
import * as __WEBPACK_EXTERNAL_MODULE__application_hoc_withDynamicSchemaProps_mjs__ from "../../application/hoc/withDynamicSchemaProps.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__block_provider_index_mjs__ from "../../block-provider/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__ from "../../collection-manager/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__data_source_collection_record_CollectionRecordProvider_mjs__ from "../../data-source/collection-record/CollectionRecordProvider.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__record_provider_index_mjs__ from "../../record-provider/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__ from "../../schema-component/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_antd_filter_context_mjs__ from "../../schema-component/antd/filter/context.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__VariableInput_VariableInput_mjs__ from "../VariableInput/VariableInput.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__components_EnableLinkage_mjs__ from "./components/EnableLinkage.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__components_LinkageHeader_mjs__ from "./components/LinkageHeader.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__LinkageRuleActionGroup_mjs__ from "./LinkageRuleActionGroup.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      position: relative;\n      width: 100%;\n      margin-left: 10px;\n    "
    ]);
    _templateObject = function() {
        return data;
    };
    return data;
}
const useStyles = (0, __WEBPACK_EXTERNAL_MODULE_antd_style__.createStyles)((param)=>{
    let { css } = param;
    return {
        filter: css(_templateObject())
    };
});
const FormLinkageRules = (0, __WEBPACK_EXTERNAL_MODULE__application_hoc_withDynamicSchemaProps_mjs__.withDynamicSchemaProps)((0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.observer)((props)=>{
    const { styles } = useStyles();
    const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    const { options, defaultValues, collectionName, form, formBlockType, variables, localVariables, record, dynamicComponent } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useProps)(props);
    const { getAllCollectionsInheritChain } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollectionManager_deprecated)();
    const parentRecordData = (0, __WEBPACK_EXTERNAL_MODULE__data_source_collection_record_CollectionRecordProvider_mjs__.useCollectionParentRecordData)();
    const components = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
            ArrayCollapse: __WEBPACK_EXTERNAL_MODULE__components_LinkageHeader_mjs__.ArrayCollapse
        }), []);
    const schema = (0, __WEBPACK_EXTERNAL_MODULE_react__.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, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__components_EnableLinkage_mjs__.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, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__VariableInput_VariableInput_mjs__.VariableInput, {
                                                    ...props,
                                                    form: form,
                                                    record: record,
                                                    shouldChange: (0, __WEBPACK_EXTERNAL_MODULE__VariableInput_VariableInput_mjs__.getShouldChange)({
                                                        collectionField,
                                                        variables,
                                                        localVariables,
                                                        getAllCollectionsInheritChain
                                                    })
                                                });
                                            }
                                        }
                                    },
                                    actions: {
                                        'x-component': 'h4',
                                        'x-content': '{{ t("Properties") }}'
                                    },
                                    action: {
                                        type: 'void',
                                        'x-component': __WEBPACK_EXTERNAL_MODULE__LinkageRuleActionGroup_mjs__.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, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
            field: options,
            fieldSchema,
            dynamicComponent,
            options: options || []
        }), [
        dynamicComponent,
        fieldSchema,
        options
    ]);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__block_provider_index_mjs__.FormBlockContext.Provider, {
        value: {
            form,
            type: formBlockType,
            collectionName
        },
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__record_provider_index_mjs__.RecordProvider, {
            record: record,
            parent: parentRecordData,
            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_component_antd_filter_context_mjs__.FilterContext.Provider, {
                value: value,
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.SchemaComponent, {
                    components: components,
                    schema: schema
                })
            })
        })
    });
}), {
    displayName: 'FormLinkageRules'
});
export { FormLinkageRules };
