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__SchemaComponentOptions_mjs__ from "./SchemaComponentOptions.mjs";
const WithForm = (props)=>{
    const { children, form, ...others } = props;
    const options = (0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(__WEBPACK_EXTERNAL_MODULE__tachybase_schema__.SchemaOptionsContext);
    const expressionScope = (0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(__WEBPACK_EXTERNAL_MODULE__tachybase_schema__.SchemaExpressionScopeContext);
    const scope = {
        ...null == options ? void 0 : options.scope,
        ...expressionScope
    };
    const components = {
        ...null == options ? void 0 : options.components
    };
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_schema__.FormProvider, {
        ...others,
        form: form,
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__SchemaComponentOptions_mjs__.SchemaComponentOptions, {
            components: components,
            scope: scope,
            children: children
        })
    });
};
const WithoutForm = (props)=>{
    const { children, ...others } = props;
    const options = (0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(__WEBPACK_EXTERNAL_MODULE__tachybase_schema__.SchemaOptionsContext);
    const expressionScope = (0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(__WEBPACK_EXTERNAL_MODULE__tachybase_schema__.SchemaExpressionScopeContext);
    const scope = {
        ...null == options ? void 0 : options.scope,
        ...expressionScope
    };
    const components = {
        ...null == options ? void 0 : options.components
    };
    const form = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>(0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.createForm)(), []);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_schema__.FormProvider, {
        ...others,
        form: form,
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__SchemaComponentOptions_mjs__.SchemaComponentOptions, {
            components: components,
            scope: scope,
            children: children
        })
    });
};
const FormProvider = (props)=>props.form ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(WithForm, {
        ...props
    }) : /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(WithoutForm, {
        ...props
    });
export { FormProvider };
