import { j as d } from "../../node_modules/react/jsx-runtime.mjs";
import "../../node_modules/@wangeditor/editor/dist/css/style.css.mjs";
import { useState as i, useEffect as p } from "react";
import { Toolbar as I, Editor as b } from "../../node_modules/@wangeditor/editor-for-react/dist/index.esm.mjs";
import D from "./transformImageUrl.mjs";
import j from "../../node_modules/axios/lib/axios.mjs";
import w from "../../node_modules/antd/es/spin/index.mjs";
import n from "../../node_modules/antd/es/message/index.mjs";
const T = {}.VITE_API_BITZ_EDITOR + "/api/Ueditor?action=uploadvideo&encode=utf-8", M = ({ content: u = "这是默认内容", onchange: s, limitFileSize: l = 20 }) => {
  const [c, r] = i(!1), [a, m] = i(null), [g, x] = i(""), E = {}, h = {
    placeholder: "请输入",
    MENU_CONF: {
      uploadImage: {
        base64LimitSize: l * 1024 * 1024
      },
      uploadVideo: {
        async customUpload(t, o) {
          if (new FormData().append("files", t), r(!0), t.size > (l || 20) * 1024 * 1024)
            return n.error(`文件应限制小于等于${l || 20}MB!`), r(!1), !1;
          try {
            const e = await j({
              url: T,
              method: "post",
              headers: {
                "Content-Type": "multipart/form-data"
              },
              data: {
                upfile: t
              }
            });
            e.status === 200 && e.data.url ? o(e.data.url, "", "") : n.error("网络服务错误，请重试！"), r(!1);
          } catch {
            n.error("网络服务错误，请重试！"), r(!1);
          }
        }
      }
    },
    customPaste(t, o) {
      var e;
      let f = ((e = o.clipboardData) == null ? void 0 : e.getData("text/html")) || "";
      return D(f).then((y) => {
        t.dangerouslyInsertHtml(y);
      }), o.preventDefault(), !1;
    }
  };
  p(() => {
    x(u);
  }, [u]), p(() => () => {
    a != null && (a.destroy(), m(null));
  }, [a]);
  const C = (t) => {
    const o = t.getHtml();
    s == null || s(o);
  };
  return d.jsxs(w, { spinning: c, tip: "上传中...", style: { border: "1px solid #ccc", zIndex: 100 }, children: [d.jsx(I, { editor: a, defaultConfig: E, mode: "default", style: { borderBottom: "1px solid #ccc" } }), d.jsx(b, { defaultConfig: h, value: g, onCreated: m, onChange: C, mode: "default", style: { height: "300px", overflowY: "hidden" } })] });
};
export {
  M as default
};
