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_antd__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE__block_provider_BlockProvider_mjs__ from "../../../../block-provider/BlockProvider.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__testUtils_index_mjs__ from "../../../../testUtils/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__collections_mjs__ from "./collections.mjs";
const { apiClient, mockRequest } = (0, __WEBPACK_EXTERNAL_MODULE__testUtils_index_mjs__.mockAPIClient)();
mockRequest.onGet('/users:get').reply(200, {
    data: {
        id: 1,
        nickname: '张三',
        password: '123456'
    }
});
mockRequest.onPost('/users:update').reply((params)=>{
    __WEBPACK_EXTERNAL_MODULE_antd__.notification.success({
        message: params.data
    });
    return [
        200,
        JSON.parse(params.data)
    ];
});
mockRequest.onGet('/auth:check').reply(()=>[
        200,
        {
            data: {}
        }
    ]);
const useAction = ()=>{
    const ctx = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_client__.useFormBlockContext)();
    const form = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useForm)();
    const filterByTk = (0, __WEBPACK_EXTERNAL_MODULE__block_provider_BlockProvider_mjs__.useFilterByTk)();
    return {
        async run () {
            console.log('form.values', form.values);
            await ctx.resource.update({
                filterByTk,
                values: form.values
            });
        }
    };
};
const schema = {
    type: 'object',
    properties: {
        block: {
            type: 'void',
            'x-decorator': 'FormBlockProvider',
            'x-decorator-props': {
                collection: 'users',
                resource: 'users',
                action: 'get'
            },
            properties: {
                form: {
                    type: 'void',
                    'x-component': 'FormV2',
                    'x-use-component-props': 'useFormBlockProps',
                    properties: {
                        nickname: {
                            type: 'string',
                            'x-decorator': 'FormItem',
                            'x-component': 'CollectionField',
                            'x-component-props': {
                                className: 'nickname'
                            }
                        },
                        password: {
                            type: 'string',
                            'x-decorator': 'FormItem',
                            'x-designer': 'FormItem.Designer',
                            'x-component': 'CollectionField',
                            'x-component-props': {
                                className: 'password'
                            }
                        },
                        button: {
                            title: 'Submit',
                            'x-component': 'Action',
                            'x-component-props': {
                                htmlType: 'submit',
                                type: 'primary',
                                useAction
                            }
                        }
                    }
                }
            }
        }
    }
};
const Demo = ()=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.CurrentUserProvider, {
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.BlockSchemaComponentProvider, {
            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.SchemaComponent, {
                schema: schema
            })
        })
    });
class MyPlugin extends __WEBPACK_EXTERNAL_MODULE__tachybase_client__.Plugin {
    async load() {
        this.app.dataSourceManager.addDataSource(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.LocalDataSource, {
            key: __WEBPACK_EXTERNAL_MODULE__tachybase_client__.DEFAULT_DATA_SOURCE_KEY,
            displayName: __WEBPACK_EXTERNAL_MODULE__tachybase_client__.DEFAULT_DATA_SOURCE_TITLE,
            collections: __WEBPACK_EXTERNAL_MODULE__collections_mjs__["default"]
        });
    }
}
const app = new __WEBPACK_EXTERNAL_MODULE__tachybase_client__.Application({
    apiClient,
    plugins: [
        __WEBPACK_EXTERNAL_MODULE__tachybase_client__.CollectionPlugin,
        MyPlugin
    ],
    components: {
        FormBlockProvider: __WEBPACK_EXTERNAL_MODULE__tachybase_client__.FormBlockProvider,
        FormItem: __WEBPACK_EXTERNAL_MODULE__tachybase_client__.FormItem,
        CollectionField: __WEBPACK_EXTERNAL_MODULE__tachybase_client__.CollectionField,
        Input: __WEBPACK_EXTERNAL_MODULE__tachybase_client__.Input,
        Action: __WEBPACK_EXTERNAL_MODULE__tachybase_client__.Action,
        FormV2: __WEBPACK_EXTERNAL_MODULE__tachybase_client__.FormV2,
        Password: __WEBPACK_EXTERNAL_MODULE__tachybase_client__.Password
    },
    providers: [
        Demo
    ]
});
const demo2_rslib_entry_ = app.getRootComponent();
export { demo2_rslib_entry_ as default };
