"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = function(module) {
        var getter = module && module.__esModule ? function() {
            return module['default'];
        } : function() {
            return module;
        };
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __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__, {
    DynamicComponent: ()=>DynamicComponent
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
const schema_namespaceObject = require("@tachybase/schema");
const index_js_namespaceObject = require("../../core/index.js");
const external_hooks_index_js_namespaceObject = require("../../hooks/index.js");
const external_context_js_namespaceObject = require("./context.js");
const DynamicComponent = (props)=>{
    const { dynamicComponent, disabled } = (0, external_react_namespaceObject.useContext)(external_context_js_namespaceObject.FilterContext);
    const component = (0, external_hooks_index_js_namespaceObject.useComponent)(dynamicComponent);
    const form = (0, external_react_namespaceObject.useMemo)(()=>(0, schema_namespaceObject.createForm)({
            values: {
                value: props.value
            },
            disabled,
            effects () {
                (0, schema_namespaceObject.onFieldValueChange)('value', (field)=>{
                    var _props_onChange;
                    null == props || null === (_props_onChange = props.onChange) || void 0 === _props_onChange || _props_onChange.call(props, field.value);
                });
            }
        }), [
        JSON.stringify(props.value),
        props.schema
    ]);
    const renderSchemaComponent = (0, external_react_namespaceObject.useCallback)(()=>{
        var _props_schema;
        return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(schema_namespaceObject.FieldContext.Provider, {
            value: null,
            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.SchemaComponent, {
                schema: {
                    'x-component': 'Input',
                    ...props.schema,
                    'x-component-props': (0, schema_namespaceObject.merge)((null == props ? void 0 : null === (_props_schema = props.schema) || void 0 === _props_schema ? void 0 : _props_schema['x-component-props']) || {}, {
                        style: {
                            minWidth: 150
                        }
                    }),
                    name: 'value',
                    'x-read-pretty': false,
                    'x-validator': void 0,
                    'x-decorator': void 0
                }
            })
        });
    }, [
        props.schema
    ]);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(schema_namespaceObject.FormContext.Provider, {
        value: form,
        children: component ? /*#__PURE__*/ external_react_default().createElement(component, {
            value: props.value,
            collectionField: props.collectionField,
            onChange: null == props ? void 0 : props.onChange,
            renderSchemaComponent
        }) : renderSchemaComponent()
    });
};
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
});
