"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__, {
    ModalActionSchemaInitializerItem: ()=>ModalActionSchemaInitializerItem
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const schema_namespaceObject = require("@tachybase/schema");
const client_namespaceObject = require("@tachybase/utils/client");
const index_js_namespaceObject = require("../../application/index.js");
const external_schema_component_index_js_namespaceObject = require("../../schema-component/index.js");
function ModalActionSchemaInitializerItem(props) {
    const { modalSchema = {}, ...otherProps } = props;
    const { properties, ...others } = modalSchema;
    const [visible, setVisible] = (0, external_react_namespaceObject.useState)(false);
    const { setVisible: setSchemaInitializerVisible } = (0, index_js_namespaceObject.useSchemaInitializer)();
    const schema = (0, external_react_namespaceObject.useMemo)(()=>({
            name: (0, client_namespaceObject.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, schema_namespaceObject.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, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.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, jsx_runtime_namespaceObject.jsx)(external_schema_component_index_js_namespaceObject.ActionContextProvider, {
                value: {
                    visible,
                    setVisible
                },
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_component_index_js_namespaceObject.SchemaComponent, {
                    components: {
                        Action: external_schema_component_index_js_namespaceObject.Action
                    },
                    schema: schema
                })
            })
        ]
    });
}
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
});
