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_antd_style__ from "antd-style";
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__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__VariableInput_index_mjs__ from "../VariableInput/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__context_mjs__ from "./context.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 FormFilterScope = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.observer)((props)=>{
    const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    const { useProps, dynamicComponent } = props;
    const { options, defaultValues, collectionName, form, formBlockType, variables, localVariables, record } = useProps();
    const { getAllCollectionsInheritChain } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollectionManager_deprecated)();
    const components = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
            ArrayCollapse: __WEBPACK_EXTERNAL_MODULE__tachybase_components__.ArrayCollapse
        }), []);
    const schema = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
            type: 'object',
            properties: {
                condition: {
                    'x-component': 'Filter',
                    default: defaultValues,
                    'x-component-props': {
                        collectionName,
                        useProps () {
                            return {
                                options,
                                className: (0, __WEBPACK_EXTERNAL_MODULE_antd_style__.css)(_templateObject())
                            };
                        },
                        dynamicComponent: (props)=>{
                            const { collectionField } = props;
                            return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__VariableInput_index_mjs__.VariableInput, {
                                ...props,
                                form: form,
                                record: record,
                                collectionField: props.collectionField,
                                shouldChange: (0, __WEBPACK_EXTERNAL_MODULE__VariableInput_index_mjs__.getShouldChange)({
                                    collectionField,
                                    variables,
                                    localVariables,
                                    getAllCollectionsInheritChain
                                })
                            });
                        }
                    }
                }
            }
        }), [
        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: collectionName
        },
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__record_provider_index_mjs__.RecordProvider, {
            record: record,
            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__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: 'FormFilterScope'
});
export { FormFilterScope };
