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_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_utils_client__ from "@tachybase/utils/client";
import * as __WEBPACK_EXTERNAL_MODULE__application_index_mjs__ from "../../application/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__ from "../../schema-component/index.mjs";
function ModalActionSchemaInitializerItem(props) {
    const { modalSchema = {}, ...otherProps } = props;
    const { properties, ...others } = modalSchema;
    const [visible, setVisible] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(false);
    const { setVisible: setSchemaInitializerVisible } = (0, __WEBPACK_EXTERNAL_MODULE__application_index_mjs__.useSchemaInitializer)();
    const schema = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
            name: (0, __WEBPACK_EXTERNAL_MODULE__tachybase_utils_client__.uid)(),
            'x-component': 'Action.Modal',
            'x-component-props': {
                width: '520px'
            },
            type: 'void',
            'x-decorator': 'FormV2',
            'x-decorator-props': {},
            ...others,
            properties: {
                ...properties,
                footer1: {
                    'x-component': 'Action.Modal.Footer',
                    type: 'void',
                    properties: {
                        close: {
                            title: 'Cancel',
                            'x-component': 'Action',
                            'x-component-props': {
                                type: 'default'
                            },
                            'x-use-component-props': ()=>({
                                    onClick () {
                                        var _props_onCancel;
                                        setVisible(false);
                                        null == props || null === (_props_onCancel = props.onCancel) || void 0 === _props_onCancel || _props_onCancel.call(props);
                                    }
                                })
                        },
                        submit: {
                            title: 'OK',
                            'x-component': 'Action',
                            'x-component-props': {
                                type: 'primary'
                            },
                            'x-use-component-props': ()=>{
                                const form = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useForm)();
                                return {
                                    async onClick () {
                                        var _props_onSubmit;
                                        await form.submit();
                                        setVisible(false);
                                        null == props || null === (_props_onSubmit = props.onSubmit) || void 0 === _props_onSubmit || _props_onSubmit.call(props, form.values);
                                    }
                                };
                            }
                        }
                    }
                }
            }
        }), [
        visible
    ]);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.Fragment, {
        children: [
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__application_index_mjs__.SchemaInitializerItem, {
                ...otherProps,
                onClick: (e)=>{
                    var _props_onClick;
                    setSchemaInitializerVisible(false);
                    setVisible(true);
                    null == props || null === (_props_onClick = props.onClick) || void 0 === _props_onClick || _props_onClick.call(props, e);
                }
            }),
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.ActionContextProvider, {
                value: {
                    visible,
                    setVisible
                },
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.SchemaComponent, {
                    components: {
                        Action: __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.Action
                    },
                    schema: schema
                })
            })
        ]
    });
}
export { ModalActionSchemaInitializerItem };
