"use strict";
var __webpack_exports__ = {};
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
require("react");
const client_namespaceObject = require("@tachybase/test/client");
const index_js_namespaceObject = require("../../../schema-component/index.js");
const external_hoc_index_js_namespaceObject = require("../../hoc/index.js");
const HelloComponent = (0, external_hoc_index_js_namespaceObject.withDynamicSchemaProps)((props)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("pre", {
        "data-testid": "component",
        children: JSON.stringify(props)
    }));
const HelloDecorator = (0, external_hoc_index_js_namespaceObject.withDynamicSchemaProps)((param)=>{
    let { children, ...others } = param;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("pre", {
                "data-testid": "decorator",
                children: JSON.stringify(others)
            }),
            children
        ]
    });
});
function withTestDemo(schema, scopes) {
    const Demo = ()=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.SchemaComponentProvider, {
            components: {
                HelloComponent,
                HelloDecorator
            },
            scope: scopes,
            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.SchemaComponent, {
                schema: {
                    type: 'void',
                    name: 'hello',
                    'x-component': 'HelloComponent',
                    'x-decorator': 'HelloDecorator',
                    ...schema
                }
            })
        });
    return Demo;
}
describe('withDynamicSchemaProps', ()=>{
    test('x-use-component-props', ()=>{
        function useComponentProps() {
            return {
                a: 'a'
            };
        }
        const schema = {
            'x-use-component-props': 'useComponentProps'
        };
        const scopes = {
            useComponentProps
        };
        const Demo = withTestDemo(schema, scopes);
        const { getByTestId } = (0, client_namespaceObject.render)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Demo, {}));
        expect(getByTestId('component')).toHaveTextContent(JSON.stringify({
            a: 'a'
        }));
    });
    test('x-use-component-props and x-component-props should merge', ()=>{
        function useComponentProps() {
            return {
                a: 'a'
            };
        }
        const schema = {
            'x-use-component-props': 'useComponentProps',
            'x-component-props': {
                b: 'b'
            }
        };
        const scopes = {
            useComponentProps
        };
        const Demo = withTestDemo(schema, scopes);
        const { getByTestId } = (0, client_namespaceObject.render)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Demo, {}));
        expect(getByTestId('component')).toHaveTextContent(JSON.stringify({
            b: 'b',
            a: 'a'
        }));
    });
    test('x-use-decorator-props', ()=>{
        function useDecoratorProps() {
            return {
                a: 'a'
            };
        }
        const schema = {
            'x-use-decorator-props': 'useDecoratorProps'
        };
        const scopes = {
            useDecoratorProps
        };
        const Demo = withTestDemo(schema, scopes);
        const { getByTestId } = (0, client_namespaceObject.render)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Demo, {}));
        expect(getByTestId('decorator')).toHaveTextContent(JSON.stringify({
            a: 'a'
        }));
    });
    test('x-use-decorator-props and x-decorator-props should merge', ()=>{
        function useDecoratorProps() {
            return {
                a: 'a'
            };
        }
        const schema = {
            'x-use-decorator-props': 'useDecoratorProps',
            'x-decorator-props': {
                b: 'b'
            }
        };
        const scopes = {
            useDecoratorProps
        };
        const Demo = withTestDemo(schema, scopes);
        const { getByTestId } = (0, client_namespaceObject.render)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Demo, {}));
        expect(getByTestId('decorator')).toHaveTextContent(JSON.stringify({
            b: 'b',
            a: 'a'
        }));
    });
    test('x-use-component-props and x-use-decorator-props exist simultaneously', ()=>{
        function useDecoratorProps() {
            return {
                a: 'a'
            };
        }
        function useComponentProps() {
            return {
                c: 'c'
            };
        }
        const schema = {
            'x-use-decorator-props': 'useDecoratorProps',
            'x-decorator-props': {
                b: 'b'
            },
            'x-use-component-props': 'useComponentProps',
            'x-component-props': {
                d: 'd'
            }
        };
        const scopes = {
            useDecoratorProps,
            useComponentProps
        };
        const Demo = withTestDemo(schema, scopes);
        const { getByTestId } = (0, client_namespaceObject.render)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Demo, {}));
        expect(getByTestId('decorator')).toHaveTextContent(JSON.stringify({
            b: 'b',
            a: 'a'
        }));
        expect(getByTestId('component')).toHaveTextContent(JSON.stringify({
            d: 'd',
            c: 'c'
        }));
    });
    test('no register scope', ()=>{
        const schema = {
            'x-use-component-props': 'useComponentProps'
        };
        const Demo = withTestDemo(schema);
        const { getByTestId } = (0, client_namespaceObject.render)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Demo, {}));
        expect(getByTestId('component')).toHaveTextContent(JSON.stringify({}));
    });
    test('x-use-component-props should override x-component-props', ()=>{
        function useComponentProps() {
            return {
                a: 'a'
            };
        }
        const schema = {
            'x-use-component-props': 'useComponentProps',
            'x-component-props': {
                a: 'b'
            }
        };
        const scopes = {
            useComponentProps
        };
        const Demo = withTestDemo(schema, scopes);
        const { getByTestId } = (0, client_namespaceObject.render)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Demo, {}));
        expect(getByTestId('component')).toHaveTextContent(JSON.stringify({
            a: 'a'
        }));
    });
});
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
});
