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";
const Hello = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.observer)(()=>{
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
        style: {
            marginBottom: 20,
            padding: '0 20px',
            height: 50,
            lineHeight: '50px',
            background: '#f1f1f1'
        },
        children: field.title
    });
});
function Demo() {
    const itemConfig = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_client__.useSchemaInitializerItem)();
    const { insert } = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_client__.useSchemaInitializer)();
    const handleClick = ()=>{
        insert({
            type: 'void',
            title: itemConfig.title,
            'x-component': 'Hello'
        });
    };
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
        onClick: handleClick,
        children: itemConfig.title
    });
}
const myInitializer = new __WEBPACK_EXTERNAL_MODULE__tachybase_client__.SchemaInitializer({
    name: 'myInitializer',
    title: 'Add Block',
    insertPosition: 'beforeEnd',
    items: [
        {
            name: 'a',
            title: 'Item A',
            Component: Demo
        },
        {
            name: 'b',
            title: 'Item B',
            Component: Demo
        }
    ]
});
const AddBlockButton = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.observer)(()=>{
    const { render } = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_client__.useSchemaInitializerRender)('myInitializer');
    return render();
});
const Page = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.observer)((props)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
        children: [
            props.children,
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(AddBlockButton, {})
        ]
    }), {
    displayName: 'Page'
});
const Root = ()=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.SchemaComponentProvider, {
            designable: true,
            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.SchemaComponent, {
                components: {
                    Page,
                    Hello,
                    AddBlockButton
                },
                schema: {
                    type: 'void',
                    name: 'page',
                    'x-component': 'Page',
                    properties: {
                        hello1: {
                            type: 'void',
                            title: 'Test1',
                            'x-component': 'Hello'
                        },
                        hello2: {
                            type: 'void',
                            title: 'Test2',
                            'x-component': 'Hello'
                        }
                    }
                }
            })
        })
    });
class MyPlugin extends __WEBPACK_EXTERNAL_MODULE__tachybase_client__.Plugin {
    async load() {
        this.app.schemaInitializerManager.add(myInitializer);
        this.app.router.add('root', {
            path: '/',
            Component: Root
        });
    }
}
const app = new __WEBPACK_EXTERNAL_MODULE__tachybase_client__.Application({
    router: {
        type: 'memory',
        initialEntries: [
            '/'
        ]
    },
    plugins: [
        MyPlugin
    ]
});
const insert_schema_basic_rslib_entry_ = app.getRootComponent();
export { insert_schema_basic_rslib_entry_ as default };
