import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_client__ from "@tachybase/client";
import * as __WEBPACK_EXTERNAL_MODULE_antd__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE__createApp_mjs__ from "./createApp.mjs";
const DemoForm = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_client__.withDynamicSchemaProps)((props)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE_antd__.Form, {
        labelCol: {
            span: 8
        },
        wrapperCol: {
            span: 16
        },
        style: {
            maxWidth: 600
        },
        autoComplete: "off",
        ...props,
        children: [
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Form.Item, {
                label: "Username",
                name: "username",
                rules: [
                    {
                        required: true,
                        message: 'Please input your username!'
                    }
                ],
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Input, {})
            }),
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Form.Item, {
                label: "Age",
                name: "age",
                rules: [
                    {
                        required: true,
                        message: 'Please input your age!'
                    }
                ],
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.InputNumber, {})
            }),
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Form.Item, {
                wrapperCol: {
                    offset: 8,
                    span: 16
                },
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Button, {
                    type: "primary",
                    htmlType: "submit",
                    children: "Submit"
                })
            })
        ]
    }));
function useDemoFormProps() {
    const data = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_client__.useCollectionRecordData)();
    const resource = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_client__.useDataBlockResource)();
    const [form] = __WEBPACK_EXTERNAL_MODULE_antd__.Form.useForm();
    (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
        form.setFieldsValue(data);
    }, [
        data,
        form
    ]);
    const onFinish = async (values)=>{
        console.log('values', values);
        await resource.update({
            filterByTk: data.id,
            values
        });
        __WEBPACK_EXTERNAL_MODULE_antd__.notification.success({
            message: 'Save successfully!'
        });
    };
    return {
        initialValues: data,
        preserve: true,
        onFinish,
        form
    };
}
const useFormBlockDecoratorProps = ()=>{
    const record = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_client__.useCollectionRecordData)();
    return {
        record
    };
};
const collection = 'users';
const action = 'get';
const schema = {
    type: 'void',
    name: 'root',
    'x-decorator': 'DataBlockProvider',
    'x-use-decorator-props': 'useFormBlockDecoratorProps',
    'x-decorator-props': {
        collection: collection,
        action: action
    },
    'x-component': 'CardItem',
    properties: {
        demo: {
            type: 'object',
            'x-component': 'DemoForm',
            'x-use-component-props': 'useDemoFormProps'
        }
    }
};
const recordData = {
    id: 1,
    username: 'Bamboo',
    age: 18
};
const Demo = ()=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.Fragment, {
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.CollectionRecordProvider, {
            record: recordData,
            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.SchemaComponent, {
                schema: schema
            })
        })
    });
const mocks = {
    ["".concat(collection, ":update")]: function(config) {
        console.log('config.data', config.data);
        return {
            data: 'ok'
        };
    }
};
const Root = (0, __WEBPACK_EXTERNAL_MODULE__createApp_mjs__.createApp)(Demo, {
    components: {
        DemoForm
    },
    scopes: {
        useDemoFormProps,
        useFormBlockDecoratorProps
    }
}, mocks);
const collection_form_record_and_update_rslib_entry_ = Root;
export { collection_form_record_and_update_rslib_entry_ as default };
