"use strict";
var __webpack_require__ = {};
(()=>{
    __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__, {
    default: ()=>demo5_rslib_entry_
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const client_namespaceObject = require("@tachybase/client");
const components_namespaceObject = require("@tachybase/components");
const schema_namespaceObject = require("@tachybase/schema");
const external_lodash_namespaceObject = require("lodash");
const collection = {
    name: 'posts',
    fields: []
};
const demo5_rslib_entry_schema = {
    type: 'object',
    properties: {
        grid: {
            type: 'void',
            'x-component': client_namespaceObject.Grid,
            'x-read-pretty': true,
            'x-initializer': 'addFieldButton',
            'x-uid': (0, schema_namespaceObject.uid)(),
            properties: {}
        }
    }
};
const gridRowColWrap = (schema)=>({
        type: 'void',
        'x-component': client_namespaceObject.Grid.Row,
        properties: {
            [(0, schema_namespaceObject.uid)()]: {
                type: 'void',
                'x-component': client_namespaceObject.Grid.Col,
                properties: {
                    [schema.name || (0, schema_namespaceObject.uid)()]: schema
                }
            }
        }
    });
const demo5_rslib_entry_form = (0, schema_namespaceObject.createForm)({
    initialValues: {}
});
const FormItemInitializer = ()=>{
    const itemConfig = (0, client_namespaceObject.useSchemaInitializerItem)();
    const { getInterface } = (0, client_namespaceObject.useCollectionManager_deprecated)();
    const schemaOptions = (0, external_react_namespaceObject.useContext)(schema_namespaceObject.SchemaOptionsContext);
    const cm = (0, client_namespaceObject.useCollectionManager)();
    const { insert } = (0, client_namespaceObject.useSchemaInitializer)();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.SchemaInitializerItem, {
        title: 'add',
        onClick: async ()=>{
            const interfaceOptions = getInterface(itemConfig.fieldInterface);
            if (!interfaceOptions) return;
            const name = "f_".concat((0, schema_namespaceObject.uid)());
            const options = (0, external_lodash_namespaceObject.cloneDeep)(interfaceOptions.default);
            options.name = name;
            options.uiSchema.title = name;
            collection.fields.push(options);
            demo5_rslib_entry_form.setValuesIn(name, (0, schema_namespaceObject.uid)());
            await (0, components_namespaceObject.FormDrawer)('Add field', ()=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.CollectionManagerProvider, {
                    instance: cm,
                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.AntdSchemaComponentProvider, {
                        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.SchemaComponentOptions, {
                            scope: schemaOptions.scope,
                            components: schemaOptions.components,
                            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(components_namespaceObject.FormLayout, {
                                layout: 'vertical',
                                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.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 client_namespaceObject.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, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.CollectionManagerProvider_deprecated, {
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.CollectionProvider_deprecated, {
            collection: collection,
            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(schema_namespaceObject.FormContext.Provider, {
                value: demo5_rslib_entry_form,
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(components_namespaceObject.FormLayout, {
                    layout: 'vertical',
                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.SchemaComponent, {
                        schema: demo5_rslib_entry_schema
                    })
                })
            })
        })
    });
class MyPlugin extends client_namespaceObject.Plugin {
    async load() {
        this.app.addComponents({
            Grid: client_namespaceObject.Grid,
            CardItem: client_namespaceObject.CardItem,
            Markdown: client_namespaceObject.Markdown,
            InputNumber: client_namespaceObject.InputNumber,
            FormItem: client_namespaceObject.FormItem,
            Input: client_namespaceObject.Input
        });
        this.app.schemaInitializerManager.add(addFieldButton);
        this.app.router.add('root', {
            path: '/',
            Component: Root
        });
    }
}
const app = new client_namespaceObject.Application({
    router: {
        type: 'memory',
        initialEntries: [
            '/'
        ]
    },
    plugins: [
        MyPlugin
    ]
});
const demo5_rslib_entry_ = app.getRootComponent();
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
});
