"use strict";
var __webpack_require__ = {};
(()=>{
    __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: ()=>collection_form_record_and_update_rslib_entry_
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const client_namespaceObject = require("@tachybase/client");
const external_antd_namespaceObject = require("antd");
const external_createApp_js_namespaceObject = require("./createApp.js");
const DemoForm = (0, client_namespaceObject.withDynamicSchemaProps)((props)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_antd_namespaceObject.Form, {
        labelCol: {
            span: 8
        },
        wrapperCol: {
            span: 16
        },
        style: {
            maxWidth: 600
        },
        autoComplete: "off",
        ...props,
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Form.Item, {
                label: "Username",
                name: "username",
                rules: [
                    {
                        required: true,
                        message: 'Please input your username!'
                    }
                ],
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Input, {})
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Form.Item, {
                label: "Age",
                name: "age",
                rules: [
                    {
                        required: true,
                        message: 'Please input your age!'
                    }
                ],
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.InputNumber, {})
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Form.Item, {
                wrapperCol: {
                    offset: 8,
                    span: 16
                },
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Button, {
                    type: "primary",
                    htmlType: "submit",
                    children: "Submit"
                })
            })
        ]
    }));
function useDemoFormProps() {
    const data = (0, client_namespaceObject.useCollectionRecordData)();
    const resource = (0, client_namespaceObject.useDataBlockResource)();
    const [form] = external_antd_namespaceObject.Form.useForm();
    (0, external_react_namespaceObject.useEffect)(()=>{
        form.setFieldsValue(data);
    }, [
        data,
        form
    ]);
    const onFinish = async (values)=>{
        console.log('values', values);
        await resource.update({
            filterByTk: data.id,
            values
        });
        external_antd_namespaceObject.notification.success({
            message: 'Save successfully!'
        });
    };
    return {
        initialValues: data,
        preserve: true,
        onFinish,
        form
    };
}
const useFormBlockDecoratorProps = ()=>{
    const record = (0, client_namespaceObject.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, jsx_runtime_namespaceObject.jsx)(jsx_runtime_namespaceObject.Fragment, {
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.CollectionRecordProvider, {
            record: recordData,
            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.SchemaComponent, {
                schema: schema
            })
        })
    });
const mocks = {
    ["".concat(collection, ":update")]: function(config) {
        console.log('config.data', config.data);
        return {
            data: 'ok'
        };
    }
};
const Root = (0, external_createApp_js_namespaceObject.createApp)(Demo, {
    components: {
        DemoForm
    },
    scopes: {
        useDemoFormProps,
        useFormBlockDecoratorProps
    }
}, mocks);
const collection_form_record_and_update_rslib_entry_ = Root;
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
});
