import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import "react";
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_antd__ from "antd";
const ViewOptions = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.connect)((props)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.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, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useForm)();
    const index = __WEBPACK_EXTERNAL_MODULE__tachybase_components__.ArrayTable.useIndex();
    (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFormEffects)(()=>{
        (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.onFieldValueChange)("projects.".concat(index, ".type"), (field)=>{
            setValuesIn("projects.".concat(index, ".options"), {});
        });
    });
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Select, {
        ...props,
        children: Object.keys(types).map((key)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Select.Option, {
                value: key,
                children: types[key].title
            }, key))
    });
}
const EditOptions = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.observer)((props)=>{
    const record = __WEBPACK_EXTERNAL_MODULE__tachybase_components__.ArrayTable.useRecord();
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    console.log(record.type);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("a", {
            onClick: ()=>{
                (0, __WEBPACK_EXTERNAL_MODULE__tachybase_components__.FormDrawer)('Pop-up form', ()=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE__tachybase_components__.FormLayout, {
                        labelCol: 6,
                        wrapperCol: 10,
                        children: [
                            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(SchemaField, {
                                schema: {
                                    type: 'object',
                                    properties: record.type ? types[record.type] || {} : {}
                                }
                            }),
                            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_components__.FormDrawer.Footer, {
                                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_components__.FormButtonGroup, {
                                    align: "right",
                                    children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_components__.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, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.createSchemaField)({
    components: {
        FormItem: __WEBPACK_EXTERNAL_MODULE__tachybase_components__.FormItem,
        Editable: __WEBPACK_EXTERNAL_MODULE__tachybase_components__.Editable,
        Input: __WEBPACK_EXTERNAL_MODULE__tachybase_components__.Input,
        NumberPicker: __WEBPACK_EXTERNAL_MODULE__tachybase_components__.NumberPicker,
        ArrayTable: __WEBPACK_EXTERNAL_MODULE__tachybase_components__.ArrayTable,
        Select: __WEBPACK_EXTERNAL_MODULE_antd__.Select,
        ViewOptions,
        EditOptions
    }
});
const demo5_rslib_entry_form = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.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, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE__tachybase_components__.Form, {
        form: demo5_rslib_entry_form,
        layout: "vertical",
        children: [
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(SchemaField, {
                schema: schema
            }),
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_components__.FormButtonGroup, {
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_components__.Submit, {
                    onSubmit: console.log,
                    children: "提交"
                })
            })
        ]
    });
export { demo5_rslib_entry_ as default };
