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_lodash__ from "lodash";
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)();
const sleep = (value)=>new Promise((resolve)=>setTimeout(resolve, value));
mockRequest.onGet('/users:list').reply(async (config)=>{
    const { page = 1, pageSize = 10 } = config.params;
    await sleep(200);
    return [
        200,
        {
            data: (0, __WEBPACK_EXTERNAL_MODULE_lodash__.range)(0, pageSize).map((index)=>({
                    id: index + (page - 1) * pageSize + 1,
                    nickname: "name".concat(index + (page - 1) * pageSize + 1)
                })),
            meta: {
                count: 100,
                page,
                pageSize
            }
        }
    ];
});
mockRequest.onGet('/users:get').reply(async (config)=>{
    const { filterByTk } = config.params;
    await sleep(200);
    return [
        200,
        {
            data: {
                id: filterByTk,
                nickname: "name".concat(filterByTk)
            }
        }
    ];
});
mockRequest.onPost('/users:create').reply(async (config)=>{
    await sleep(200);
    __WEBPACK_EXTERNAL_MODULE_antd__.notification.success({
        message: config.data
    });
    return [
        200,
        {
            data: JSON.parse(config.data)
        }
    ];
});
function useAction() {
    const ctx = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_client__.useTableBlockContext)();
    return {
        async run () {
            var _ctx_service_params;
            const params = (null === (_ctx_service_params = ctx.service.params) || void 0 === _ctx_service_params ? void 0 : _ctx_service_params[0]) || {};
            ctx.service.run({
                ...params,
                page: 2
            });
        }
    };
}
function useCreateAction() {
    const ctx = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_client__.useFormBlockContext)();
    const form = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useForm)();
    return {
        async run () {
            console.log('form.values', form.values);
            await ctx.resource.create({
                values: form.values
            });
        }
    };
}
const formSchema = {
    type: 'void',
    'x-decorator': 'FormBlockProvider',
    'x-decorator-props': {
        collection: 'users',
        resource: 'users',
        action: 'get',
        useParams: '{{ useParamsFromRecord }}'
    },
    properties: {
        form: {
            type: 'void',
            'x-component': 'FormV2',
            'x-use-component-props': 'useFormBlockProps',
            properties: {
                id: {
                    type: 'string',
                    title: 'ID',
                    'x-decorator': 'FormItem',
                    'x-component': 'InputNumber',
                    'x-read-pretty': true
                },
                nickname: {
                    type: 'string',
                    'x-decorator': 'FormItem',
                    'x-component': 'CollectionField'
                },
                button: {
                    title: '提交',
                    'x-component': 'Action',
                    'x-component-props': {
                        htmlType: 'submit',
                        type: 'primary',
                        useAction: '{{ useCreateAction }}'
                    }
                }
            }
        }
    }
};
const schema = {
    type: 'object',
    properties: {
        block: {
            type: 'void',
            'x-decorator': 'TableBlockProvider',
            'x-decorator-props': {
                collection: 'users',
                resource: 'users',
                action: 'list',
                params: {
                    pageSize: 2
                },
                showIndex: true,
                dragSort: false
            },
            properties: {
                button: {
                    title: '刷新',
                    'x-component': 'Action',
                    'x-component-props': {
                        useAction
                    }
                },
                table: {
                    type: 'array',
                    title: "编辑模式",
                    'x-component': 'TableV2',
                    'x-use-component-props': 'useTableBlockProps',
                    'x-component-props': {
                        rowKey: 'id',
                        rowSelection: {
                            type: 'checkbox'
                        }
                    },
                    properties: {
                        column1: {
                            type: 'void',
                            title: 'Name',
                            'x-component': 'TableV2.Column',
                            properties: {
                                nickname: {
                                    type: 'string',
                                    'x-component': 'CollectionField',
                                    'x-read-pretty': true
                                }
                            }
                        },
                        actions: {
                            type: 'void',
                            title: 'Actions',
                            'x-component': 'TableV2.Column',
                            properties: {
                                view: {
                                    type: 'void',
                                    title: 'View',
                                    'x-component': 'Action',
                                    'x-component-props': {},
                                    properties: {
                                        drawer: {
                                            'x-component': 'Action.Drawer',
                                            type: 'void',
                                            title: 'Drawer Title',
                                            properties: {
                                                formSchema
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
};
const Root = ()=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.APIClientProvider, {
        apiClient: apiClient,
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.SchemaComponentProvider, {
            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.ExtendCollectionsProvider, {
                collections: __WEBPACK_EXTERNAL_MODULE__collections_mjs__["default"].data,
                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__.BlockSchemaComponentProvider, {
                        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.SchemaComponent, {
                            schema: schema,
                            scope: {
                                useCreateAction
                            }
                        })
                    })
                })
            })
        })
    });
const app = new __WEBPACK_EXTERNAL_MODULE__tachybase_client__.Application({
    providers: [
        Root
    ]
});
const demo1_rslib_entry_ = app.getRootComponent();
export { demo1_rslib_entry_ as default };
