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_components__ from "@tachybase/components";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE_axios_mock_adapter__ from "axios-mock-adapter";
const apiClient = new __WEBPACK_EXTERNAL_MODULE__tachybase_client__.APIClient();
const mock = new __WEBPACK_EXTERNAL_MODULE_axios_mock_adapter__["default"](apiClient.axios);
mock.onGet('/china_regions').reply(200, {
    data: [
        {
            value: 'zhejiang',
            label: 'Zhejiang',
            isLeaf: false
        },
        {
            value: 'jiangsu',
            label: 'Jiangsu',
            isLeaf: false
        }
    ]
});
const useAsyncDataSource = (api)=>(field)=>{
        field.loading = true;
        console.log('useAsyncDataSource');
        api.request({
            url: 'china_regions'
        }).then(__WEBPACK_EXTERNAL_MODULE__tachybase_schema__.action.bound((res)=>{
            var _res_data;
            field.dataSource = (null == res ? void 0 : null === (_res_data = res.data) || void 0 === _res_data ? void 0 : _res_data.data) || [];
            field.loading = false;
        })).catch(console.error);
    };
const useLoadData = ()=>{
    (0, __WEBPACK_EXTERNAL_MODULE__tachybase_client__.useAPIClient)();
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    return (selectedOptions)=>{
        const targetOption = selectedOptions[selectedOptions.length - 1];
        targetOption.loading = true;
        setTimeout(()=>{
            targetOption.loading = false;
            targetOption.children = [
                {
                    label: "".concat(targetOption.label, " Dynamic 1"),
                    value: 'dynamic1'
                },
                {
                    label: "".concat(targetOption.label, " Dynamic 2"),
                    value: 'dynamic2'
                }
            ];
            field.dataSource = [
                ...field.dataSource
            ];
        }, 300);
    };
};
const schema = {
    type: 'object',
    properties: {
        input: {
            type: 'string',
            title: "编辑模式",
            'x-decorator': 'FormItem',
            'x-component': 'Cascader',
            'x-component-props': {
                changeOnSelectLast: false,
                labelInValue: true,
                maxLevel: 3,
                useLoadData: '{{useLoadData}}'
            },
            'x-reactions': [
                '{{useAsyncDataSource(apiClient)}}',
                {
                    target: 'read',
                    fulfill: {
                        state: {
                            value: '{{$self.value}}'
                        }
                    }
                }
            ]
        },
        read: {
            type: 'string',
            title: "阅读模式",
            'x-read-pretty': true,
            'x-decorator': 'FormItem',
            'x-component': 'Cascader',
            'x-component-props': {
                changeOnSelectLast: false,
                labelInValue: true,
                maxLevel: 3
            }
        }
    }
};
const demo2_rslib_entry_ = ()=>/*#__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, {
            components: {
                Cascader: __WEBPACK_EXTERNAL_MODULE__tachybase_client__.Cascader,
                FormItem: __WEBPACK_EXTERNAL_MODULE__tachybase_components__.FormItem
            },
            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.SchemaComponent, {
                scope: {
                    apiClient,
                    useLoadData,
                    useAsyncDataSource
                },
                schema: schema
            })
        })
    });
export { demo2_rslib_entry_ as default };
