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_client__ from "@tachybase/client";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_components__ from "@tachybase/components";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash";
const collection = {
    name: 'posts',
    fields: []
};
const demo5_rslib_entry_schema = {
    type: 'object',
    properties: {
        grid: {
            type: 'void',
            'x-component': __WEBPACK_EXTERNAL_MODULE__tachybase_client__.Grid,
            'x-read-pretty': true,
            'x-initializer': 'addFieldButton',
            'x-uid': (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.uid)(),
            properties: {}
        }
    }
};
const gridRowColWrap = (schema)=>({
        type: 'void',
        'x-component': __WEBPACK_EXTERNAL_MODULE__tachybase_client__.Grid.Row,
        properties: {
            [(0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.uid)()]: {
                type: 'void',
                'x-component': __WEBPACK_EXTERNAL_MODULE__tachybase_client__.Grid.Col,
                properties: {
                    [schema.name || (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.uid)()]: schema
                }
            }
        }
    });
const demo5_rslib_entry_form = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.createForm)({
    initialValues: {}
});
const FormItemInitializer = ()=>{
    const itemConfig = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_client__.useSchemaInitializerItem)();
    const { getInterface } = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_client__.useCollectionManager_deprecated)();
    const schemaOptions = (0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(__WEBPACK_EXTERNAL_MODULE__tachybase_schema__.SchemaOptionsContext);
    const cm = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_client__.useCollectionManager)();
    const { insert } = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_client__.useSchemaInitializer)();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.SchemaInitializerItem, {
        title: 'add',
        onClick: async ()=>{
            const interfaceOptions = getInterface(itemConfig.fieldInterface);
            if (!interfaceOptions) return;
            const name = "f_".concat((0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.uid)());
            const options = (0, __WEBPACK_EXTERNAL_MODULE_lodash__.cloneDeep)(interfaceOptions.default);
            options.name = name;
            options.uiSchema.title = name;
            collection.fields.push(options);
            demo5_rslib_entry_form.setValuesIn(name, (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.uid)());
            await (0, __WEBPACK_EXTERNAL_MODULE__tachybase_components__.FormDrawer)('Add field', ()=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.CollectionManagerProvider, {
                    instance: cm,
                    children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.AntdSchemaComponentProvider, {
                        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.SchemaComponentOptions, {
                            scope: schemaOptions.scope,
                            components: schemaOptions.components,
                            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_components__.FormLayout, {
                                layout: 'vertical',
                                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.SchemaComponent, {
                                    schema: {
                                        properties: interfaceOptions.properties
                                    }
                                })
                            })
                        })
                    })
                })).open({
                initialValues: {}
            });
            insert({
                name,
                type: 'string',
                'x-component': 'CollectionField',
                'x-collection-field': "posts.".concat(name),
                'x-component-props': {},
                'x-decorator': 'FormItem',
                'x-designer': 'FormItem.Designer'
            });
        }
    });
};
const addFieldButton = new __WEBPACK_EXTERNAL_MODULE__tachybase_client__.SchemaInitializer({
    name: 'addFieldButton',
    designable: true,
    title: 'Add Field',
    wrap: gridRowColWrap,
    items: [
        {
            name: 'media',
            type: 'itemGroup',
            title: 'Field interfaces',
            children: [
                {
                    name: 'singleText',
                    title: 'Single text',
                    fieldInterface: 'input',
                    Component: FormItemInitializer
                }
            ]
        }
    ]
});
const Root = ()=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.CollectionManagerProvider_deprecated, {
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.CollectionProvider_deprecated, {
            collection: collection,
            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_schema__.FormContext.Provider, {
                value: demo5_rslib_entry_form,
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_components__.FormLayout, {
                    layout: 'vertical',
                    children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.SchemaComponent, {
                        schema: demo5_rslib_entry_schema
                    })
                })
            })
        })
    });
class MyPlugin extends __WEBPACK_EXTERNAL_MODULE__tachybase_client__.Plugin {
    async load() {
        this.app.addComponents({
            Grid: __WEBPACK_EXTERNAL_MODULE__tachybase_client__.Grid,
            CardItem: __WEBPACK_EXTERNAL_MODULE__tachybase_client__.CardItem,
            Markdown: __WEBPACK_EXTERNAL_MODULE__tachybase_client__.Markdown,
            InputNumber: __WEBPACK_EXTERNAL_MODULE__tachybase_client__.InputNumber,
            FormItem: __WEBPACK_EXTERNAL_MODULE__tachybase_client__.FormItem,
            Input: __WEBPACK_EXTERNAL_MODULE__tachybase_client__.Input
        });
        this.app.schemaInitializerManager.add(addFieldButton);
        this.app.router.add('root', {
            path: '/',
            Component: Root
        });
    }
}
const app = new __WEBPACK_EXTERNAL_MODULE__tachybase_client__.Application({
    router: {
        type: 'memory',
        initialEntries: [
            '/'
        ]
    },
    plugins: [
        MyPlugin
    ]
});
const demo5_rslib_entry_ = app.getRootComponent();
export { demo5_rslib_entry_ as default };
