"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__, {
    SchemaInitializerActionModalInternal: ()=>SchemaInitializerActionModalInternal,
    SchemaInitializerActionModal: ()=>SchemaInitializerActionModal
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const schema_namespaceObject = require("@tachybase/schema");
const index_js_namespaceObject = require("../../../schema-component/index.js");
const external_context_index_js_namespaceObject = require("../context/index.js");
const SchemaInitializerActionModal = (props)=>{
    const { title, schema, buttonText, component, onCancel, onSubmit } = props;
    const useCancelAction = (0, external_react_namespaceObject.useCallback)(()=>{
        const form = (0, schema_namespaceObject.useForm)();
        const ctx = (0, index_js_namespaceObject.useActionContext)();
        return {
            async run () {
                await (null == onCancel ? void 0 : onCancel());
                ctx.setVisible(false);
                form.reset();
            }
        };
    }, [
        onCancel
    ]);
    const useSubmitAction = (0, external_react_namespaceObject.useCallback)(()=>{
        const form = (0, schema_namespaceObject.useForm)();
        const ctx = (0, index_js_namespaceObject.useActionContext)();
        return {
            async run () {
                await form.validate();
                await (null == onSubmit ? void 0 : onSubmit(form.values));
                ctx.setVisible(false);
                form.reset();
            }
        };
    }, [
        onSubmit
    ]);
    const defaultSchema = (0, external_react_namespaceObject.useMemo)(()=>({
            type: 'void',
            properties: {
                action1: {
                    type: 'void',
                    'x-component': 'Action',
                    'x-component-props': component ? {
                        component
                    } : {
                        icon: 'PlusOutlined',
                        style: {
                            borderColor: 'var(--colorSettings)',
                            color: 'var(--colorSettings)'
                        },
                        title: buttonText,
                        type: 'dashed'
                    },
                    properties: {
                        drawer1: {
                            'x-decorator': 'Form',
                            'x-component': 'Action.Modal',
                            'x-component-props': {
                                style: {
                                    maxWidth: '520px',
                                    width: '100%'
                                }
                            },
                            type: 'void',
                            title,
                            properties: {
                                ...(null == schema ? void 0 : schema.properties) || schema,
                                footer: {
                                    'x-component': 'Action.Modal.Footer',
                                    type: 'void',
                                    properties: {
                                        cancel: {
                                            title: '{{t("Cancel")}}',
                                            'x-component': 'Action',
                                            'x-component-props': {
                                                useAction: useCancelAction
                                            }
                                        },
                                        submit: {
                                            title: '{{t("Submit")}}',
                                            'x-component': 'Action',
                                            'x-component-props': {
                                                type: 'primary',
                                                useAction: useSubmitAction
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }), [
        buttonText,
        component,
        schema,
        title,
        useCancelAction,
        useSubmitAction
    ]);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.SchemaComponent, {
        schema: defaultSchema
    });
};
const SchemaInitializerActionModalInternal = ()=>{
    const itemConfig = (0, external_context_index_js_namespaceObject.useSchemaInitializerItem)();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SchemaInitializerActionModal, {
        ...itemConfig
    });
};
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
});
