import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_client__ from "@tachybase/client";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_test_client__ from "@tachybase/test/client";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__ from "../../schema-component/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_toolbar_index_mjs__ from "../schema-toolbar/index.mjs";
describe('SchemaToolbar', ()=>{
    test('SchemaToolbarProvider & useSchemaToolbar', ()=>{
        const Demo = ()=>{
            const context = (0, __WEBPACK_EXTERNAL_MODULE__schema_toolbar_index_mjs__.useSchemaToolbar)();
            return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                "data-testid": "content",
                children: context.test
            });
        };
        const Root = ()=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_toolbar_index_mjs__.SchemaToolbarProvider, {
                test: '123',
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(Demo, {})
            });
        (0, __WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.render)(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(Root, {}));
        expect(__WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.screen.getByTestId('content')).toHaveTextContent('123');
    });
    describe('useSchemaToolbarRender()', ()=>{
        const renderApp = function(demoSchema) {
            let designable = !(arguments.length > 1) || void 0 === arguments[1] || arguments[1];
            const Demo = ()=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                    "data-testid": "demo",
                    children: "Demo"
                });
            const CustomToolbar = (props)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.Fragment, {
                    children: [
                        /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                            "data-testid": "custom-toolbar",
                            children: "CustomToolbar"
                        }),
                        /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                            "data-testid": "custom-toolbar-props",
                            children: JSON.stringify(props)
                        })
                    ]
                });
            const schema = {
                name: 'root',
                type: 'object',
                'x-decorator': 'Wrapper',
                'x-component': 'Demo',
                ...demoSchema
            };
            const Wrapper = (param)=>{
                let { children } = param;
                const schema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
                const context = (0, __WEBPACK_EXTERNAL_MODULE__schema_toolbar_index_mjs__.useSchemaToolbarRender)(schema);
                return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.Fragment, {
                    children: [
                        /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                            "data-testid": "toolbar",
                            children: context.render({
                                customProps: '123'
                            })
                        }),
                        /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                            "data-testid": "toolbar-exists",
                            children: JSON.stringify(context.exists)
                        }),
                        children
                    ]
                });
            };
            const app = new __WEBPACK_EXTERNAL_MODULE__tachybase_client__.Application({});
            (0, __WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.render)(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.ApplicationContext.Provider, {
                value: app,
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.SortableProvider, {
                    children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.SchemaComponentProvider, {
                        designable: designable,
                        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.SchemaComponent, {
                            schema: schema,
                            components: {
                                Demo,
                                Wrapper,
                                CustomToolbar
                            }
                        })
                    })
                })
            }));
        };
        test('Render x-designer if x-designer has a value', ()=>{
            renderApp({
                'x-designer': 'CustomToolbar'
            });
            expect(__WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.screen.getByTestId('custom-toolbar')).toHaveTextContent('CustomToolbar');
            expect(__WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.screen.getByTestId('custom-toolbar-props')).toHaveTextContent('{"customProps":"123"}');
            expect(__WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.screen.getByTestId('toolbar-exists')).toHaveTextContent('true');
        });
        test('Render x-toolbar if it has a value', ()=>{
            renderApp({
                'x-toolbar': 'CustomToolbar'
            });
            expect(__WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.screen.getByTestId('custom-toolbar')).toHaveTextContent('CustomToolbar');
        });
        test('Render x-toolbar if both x-toolbar and x-designer have values', ()=>{
            renderApp({
                'x-toolbar': 'CustomToolbar',
                'x-designer': 'CustomToolbar'
            });
            expect(__WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.screen.getByTestId('custom-toolbar')).toHaveTextContent('CustomToolbar');
        });
        test('Render the default SchemaToolbar component if x-toolbar and x-designer have no values and x-settings has a value', ()=>{
            renderApp({
                'x-settings': 'DemoSettings'
            });
            expect(__WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.screen.getByTestId('toolbar').innerHTML.length > 0).toBe(true);
            expect(__WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.screen.getByTestId('toolbar-exists')).toHaveTextContent('true');
        });
        test('Do not render if x-toolbar and x-designer have no values and x-settings also has no value', ()=>{
            renderApp({});
            expect(__WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.screen.getByTestId('toolbar')).toHaveTextContent('');
            expect(__WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.screen.getByTestId('toolbar-exists')).toHaveTextContent('false');
        });
        test('Do not render if the component corresponding to x-toolbar cannot be found', ()=>{
            renderApp({
                'x-toolbar': 'NotFound'
            });
            expect(__WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.screen.getByTestId('toolbar')).toHaveTextContent('');
        });
        test('Do not render if designable is false', ()=>{
            renderApp({
                'x-designer': 'CustomToolbar'
            }, false);
            expect(__WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.screen.getByTestId('toolbar')).toHaveTextContent('');
        });
        test('x-toolbar-props and custom Props', ()=>{
            renderApp({
                'x-toolbar': 'CustomToolbar',
                'x-toolbar-props': {
                    test: '123'
                }
            });
            expect(__WEBPACK_EXTERNAL_MODULE__tachybase_test_client__.screen.getByTestId('custom-toolbar-props')).toHaveTextContent('{"test":"123","customProps":"123"}');
        });
    });
});
