"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = function(module) {
        var getter = module && module.__esModule ? function() {
            return module['default'];
        } : function() {
            return module;
        };
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __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__, {
    MarkdownVoid: ()=>MarkdownVoid
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const schema_namespaceObject = require("@tachybase/schema");
const external_antd_namespaceObject = require("antd");
const external_classnames_namespaceObject = require("classnames");
var external_classnames_default = /*#__PURE__*/ __webpack_require__.n(external_classnames_namespaceObject);
const external_react_i18next_namespaceObject = require("react-i18next");
const index_js_namespaceObject = require("../../../style/theme/index.js");
const useDesignable_js_namespaceObject = require("../../hooks/useDesignable.js");
const external_Markdown_Void_Designer_js_namespaceObject = require("./Markdown.Void.Designer.js");
const external_style_js_namespaceObject = require("./style.js");
const external_util_js_namespaceObject = require("./util.js");
const MarkdownEditor = (props)=>{
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const [value, setValue] = (0, external_react_namespaceObject.useState)(props.defaultValue);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
        className: 'mb-markdown',
        style: {
            position: 'relative'
        },
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Input.TextArea, {
                autoSize: {
                    minRows: 3
                },
                ...props,
                value: value,
                onChange: (e)=>{
                    setValue(e.target.value);
                }
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_antd_namespaceObject.Space, {
                style: {
                    position: 'absolute',
                    bottom: 5,
                    right: 5
                },
                children: [
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Button, {
                        onClick: (e)=>{
                            var _props_onCancel;
                            null === (_props_onCancel = props.onCancel) || void 0 === _props_onCancel || _props_onCancel.call(props, e);
                        },
                        children: t('Cancel')
                    }),
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Button, {
                        type: 'primary',
                        onClick: ()=>{
                            var _props_onSubmit;
                            null === (_props_onSubmit = props.onSubmit) || void 0 === _props_onSubmit || _props_onSubmit.call(props, value);
                        },
                        children: t('Save')
                    })
                ]
            })
        ]
    });
};
const MarkdownVoid = (0, schema_namespaceObject.observer)((props)=>{
    const { isDarkTheme } = (0, index_js_namespaceObject.useGlobalTheme)();
    const { componentCls, hashId } = (0, external_style_js_namespaceObject.useStyles)({
        isDarkTheme
    });
    const { content, className } = props;
    const field = (0, schema_namespaceObject.useField)();
    const schema = (0, schema_namespaceObject.useFieldSchema)();
    const { dn } = (0, useDesignable_js_namespaceObject.useDesignable)();
    const { onSave, onCancel } = props;
    const { html, loading } = (0, external_util_js_namespaceObject.useParseMarkdown)(content);
    if (loading) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Spin, {});
    return (null == field ? void 0 : field.editable) ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(MarkdownEditor, {
        ...props,
        className: true,
        defaultValue: content,
        onCancel: ()=>{
            field.editable = false;
            null == onCancel || onCancel();
        },
        onSubmit: async (value)=>{
            field.editable = false;
            var _schema_xcomponentprops;
            null !== (_schema_xcomponentprops = schema['x-component-props']) && void 0 !== _schema_xcomponentprops || (schema['x-component-props'] = {});
            schema['x-component-props']['content'] = value;
            field.componentProps.content = value;
            null == onSave || onSave(schema);
            dn.emit('patch', {
                schema: {
                    'x-uid': schema['x-uid'],
                    'x-component-props': {
                        content: value
                    }
                }
            });
        }
    }) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
        className: external_classnames_default()([
            componentCls,
            hashId,
            'tb-markdown tb-markdown-default tb-markdown-table',
            className
        ]),
        style: props.style,
        dangerouslySetInnerHTML: {
            __html: html
        }
    });
}, {
    displayName: 'MarkdownVoid'
});
MarkdownVoid.Designer = external_Markdown_Void_Designer_js_namespaceObject.MarkdownVoidDesigner;
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
});
