"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: ()=>demo5_rslib_entry_
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
require("react");
const components_namespaceObject = require("@tachybase/components");
const schema_namespaceObject = require("@tachybase/schema");
const external_antd_namespaceObject = require("antd");
const ViewOptions = (0, schema_namespaceObject.connect)((props)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
        children: JSON.stringify(props.value)
    }));
const types = {
    type1: {
        input1: {
            type: 'string',
            title: 'Input11',
            'x-decorator': 'FormItem',
            'x-component': 'Input'
        },
        input2: {
            type: 'string',
            title: 'Input11',
            'x-decorator': 'FormItem',
            'x-component': 'Input'
        }
    },
    type2: {
        input1: {
            type: 'string',
            title: 'Input12',
            'x-decorator': 'FormItem',
            'x-component': 'Input'
        },
        input2: {
            type: 'string',
            title: 'Input12',
            'x-decorator': 'FormItem',
            'x-component': 'Input'
        }
    }
};
function TypeSelect(props) {
    const { setValuesIn } = (0, schema_namespaceObject.useForm)();
    const index = components_namespaceObject.ArrayTable.useIndex();
    (0, schema_namespaceObject.useFormEffects)(()=>{
        (0, schema_namespaceObject.onFieldValueChange)("projects.".concat(index, ".type"), (field)=>{
            setValuesIn("projects.".concat(index, ".options"), {});
        });
    });
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Select, {
        ...props,
        children: Object.keys(types).map((key)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Select.Option, {
                value: key,
                children: types[key].title
            }, key))
    });
}
const EditOptions = (0, schema_namespaceObject.observer)((props)=>{
    const record = components_namespaceObject.ArrayTable.useRecord();
    const field = (0, schema_namespaceObject.useField)();
    console.log(record.type);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("a", {
            onClick: ()=>{
                (0, components_namespaceObject.FormDrawer)('Pop-up form', ()=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(components_namespaceObject.FormLayout, {
                        labelCol: 6,
                        wrapperCol: 10,
                        children: [
                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaField, {
                                schema: {
                                    type: 'object',
                                    properties: record.type ? types[record.type] || {} : {}
                                }
                            }),
                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(components_namespaceObject.FormDrawer.Footer, {
                                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(components_namespaceObject.FormButtonGroup, {
                                    align: "right",
                                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(components_namespaceObject.Submit, {
                                        onSubmit: ()=>new Promise((resolve)=>{
                                                setTimeout(resolve, 1000);
                                            }),
                                        children: "Submit"
                                    })
                                })
                            })
                        ]
                    })).open({
                    initialValues: field.value
                }).then((values)=>{
                    field.value = values;
                    return values;
                }).catch((err)=>{
                    console.error(err);
                });
            },
            children: "Edit"
        })
    });
}, {
    displayName: 'EditOptions'
});
const SchemaField = (0, schema_namespaceObject.createSchemaField)({
    components: {
        FormItem: components_namespaceObject.FormItem,
        Editable: components_namespaceObject.Editable,
        Input: components_namespaceObject.Input,
        NumberPicker: components_namespaceObject.NumberPicker,
        ArrayTable: components_namespaceObject.ArrayTable,
        Select: external_antd_namespaceObject.Select,
        ViewOptions,
        EditOptions
    }
});
const demo5_rslib_entry_form = (0, schema_namespaceObject.createForm)();
const schema = {
    type: 'object',
    properties: {
        projects: {
            type: 'array',
            title: 'Projects',
            'x-decorator': 'FormItem',
            'x-component': 'ArrayTable',
            items: {
                type: 'object',
                properties: {
                    sort: {
                        type: 'void',
                        'x-component': 'ArrayTable.Column',
                        'x-component-props': {
                            width: 50,
                            title: '',
                            align: 'center'
                        },
                        properties: {
                            sort: {
                                type: 'void',
                                'x-component': 'ArrayTable.SortHandle'
                            }
                        }
                    },
                    column_33: {
                        type: 'void',
                        'x-component': 'ArrayTable.Column',
                        'x-component-props': {
                            title: 'Type'
                        },
                        properties: {
                            type: {
                                type: 'string',
                                'x-decorator': 'FormItem',
                                'x-component': TypeSelect
                            }
                        }
                    },
                    column_3: {
                        type: 'void',
                        'x-component': 'ArrayTable.Column',
                        'x-component-props': {
                            title: 'Options'
                        },
                        properties: {
                            options: {
                                type: 'object',
                                'x-component': 'ViewOptions'
                            }
                        }
                    },
                    column_6: {
                        type: 'void',
                        'x-component': 'ArrayTable.Column',
                        'x-component-props': {
                            title: 'Operations'
                        },
                        properties: {
                            item: {
                                type: 'void',
                                'x-component': 'FormItem',
                                properties: {
                                    options: {
                                        type: 'object',
                                        'x-component': 'EditOptions'
                                    }
                                }
                            }
                        }
                    }
                }
            },
            properties: {
                add: {
                    type: 'void',
                    title: 'Add',
                    'x-component': 'ArrayTable.Addition'
                }
            }
        }
    }
};
const demo5_rslib_entry_ = ()=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(components_namespaceObject.Form, {
        form: demo5_rslib_entry_form,
        layout: "vertical",
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaField, {
                schema: schema
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(components_namespaceObject.FormButtonGroup, {
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(components_namespaceObject.Submit, {
                    onSubmit: console.log,
                    children: "提交"
                })
            })
        ]
    });
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
});
