import { jsx } from "react/jsx-runtime";
import "react";
import { connect, mapProps, mapReadPretty } from "@tachybase/schema";
import { LoadingOutlined } from "@ant-design/icons";
import { Input, Spin } from "antd";
import { useGlobalTheme } from "../../../style/theme/index.mjs";
import { ReadPretty } from "../input/index.mjs";
import { MarkdownVoid } from "./Markdown.Void.mjs";
import { useStyles } from "./style.mjs";
import { convertToText, useParseMarkdown } from "./util.mjs";
const Markdown_Markdown = connect(Input.TextArea, mapProps((props, field)=>({
        autoSize: {
            maxRows: 10,
            minRows: 3
        },
        ...props,
        suffix: /*#__PURE__*/ jsx("span", {
            children: (null == field ? void 0 : field['loading']) || (null == field ? void 0 : field['validating']) ? /*#__PURE__*/ jsx(LoadingOutlined, {}) : props.suffix
        })
    })), mapReadPretty((props)=>/*#__PURE__*/ jsx(MarkdownReadPretty, {
        ...props
    })));
const MarkdownReadPretty = (props)=>{
    const { isDarkTheme } = useGlobalTheme();
    const { wrapSSR, hashId, componentCls: className } = useStyles({
        isDarkTheme
    });
    const { html = '', loading } = useParseMarkdown(props.value);
    const text = convertToText(html);
    const value = /*#__PURE__*/ jsx("div", {
        className: "".concat(hashId, " ").concat(className, " tb-markdown tb-markdown-default tb-markdown-table"),
        dangerouslySetInnerHTML: {
            __html: html
        }
    });
    if (loading) return wrapSSR(/*#__PURE__*/ jsx(Spin, {}));
    return wrapSSR(/*#__PURE__*/ jsx(ReadPretty.TextArea, {
        ...props,
        autop: false,
        text: text,
        value: value
    }));
};
Markdown_Markdown.Void = MarkdownVoid;
const Markdown = Markdown_Markdown;
export { Markdown_Markdown as Markdown, MarkdownReadPretty, Markdown as default };
