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__api_client_index_mjs__ from "../../api-client/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__hooks_index_mjs__ from "../hooks/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__FormProvider_mjs__ from "./FormProvider.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__SchemaComponent_mjs__ from "./SchemaComponent.mjs";
const defaultTransform = (s)=>s;
const RequestSchemaComponent = (props)=>{
    const { noForm, onlyRenderProperties, hidden, scope, uid, components, onSuccess, schemaTransform = defaultTransform } = props;
    const { reset } = (0, __WEBPACK_EXTERNAL_MODULE__hooks_index_mjs__.useSchemaComponentContext)();
    const conf = {
        url: "/uiSchemas:".concat(onlyRenderProperties ? 'getProperties' : 'getJsonSchema', "/").concat(uid)
    };
    const form = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>(0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.createForm)(), [
        uid
    ]);
    const { data, loading } = (0, __WEBPACK_EXTERNAL_MODULE__api_client_index_mjs__.useRequest)(conf, {
        refreshDeps: [
            uid
        ],
        onSuccess (data) {
            onSuccess && onSuccess(data);
            reset && reset();
        }
    });
    if (loading || hidden || !data) return;
    return noForm ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__SchemaComponent_mjs__.SchemaComponent, {
        components: components,
        scope: scope,
        schema: schemaTransform((null == data ? void 0 : data.data) || {})
    }) : /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__FormProvider_mjs__.FormProvider, {
        form: form,
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__SchemaComponent_mjs__.SchemaComponent, {
            components: components,
            scope: scope,
            schema: schemaTransform((null == data ? void 0 : data.data) || {})
        })
    });
};
const RemoteSchemaComponent = (props)=>props.uid ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(RequestSchemaComponent, {
        ...props
    }) : null;
export { RemoteSchemaComponent };
