"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = function(module) {
        var getter = module && module.__esModule ? function() {
            return module['default'];
        } : function() {
            return module;
        };
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __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: ()=>demo1_rslib_entry_
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
require("react");
const client_namespaceObject = require("@tachybase/client");
const schema_namespaceObject = require("@tachybase/schema");
const external_antd_namespaceObject = require("antd");
const external_lodash_namespaceObject = require("lodash");
const index_js_namespaceObject = require("../../../../testUtils/index.js");
const external_collections_js_namespaceObject = require("./collections.js");
var external_collections_js_default = /*#__PURE__*/ __webpack_require__.n(external_collections_js_namespaceObject);
const { apiClient, mockRequest } = (0, index_js_namespaceObject.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, external_lodash_namespaceObject.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);
    external_antd_namespaceObject.notification.success({
        message: config.data
    });
    return [
        200,
        {
            data: JSON.parse(config.data)
        }
    ];
});
function useAction() {
    const ctx = (0, client_namespaceObject.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, client_namespaceObject.useFormBlockContext)();
    const form = (0, schema_namespaceObject.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, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.APIClientProvider, {
        apiClient: apiClient,
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.SchemaComponentProvider, {
            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.ExtendCollectionsProvider, {
                collections: external_collections_js_default().data,
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.AntdSchemaComponentProvider, {
                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.BlockSchemaComponentProvider, {
                        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.SchemaComponent, {
                            schema: schema,
                            scope: {
                                useCreateAction
                            }
                        })
                    })
                })
            })
        })
    });
const app = new client_namespaceObject.Application({
    providers: [
        Root
    ]
});
const demo1_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
});
