import { defineComponent as C, inject as D, shallowRef as _, ref as N, onMounted as F, openBlock as m, createElementBlock as p, createVNode as t, unref as l, withCtx as a, Fragment as R, renderList as U, toDisplayString as E, createBlock as B, createTextVNode as g, createElementVNode as b } from "vue";
import { ElDropdown as T, ElDropdownMenu as A, ElDropdownItem as M, ElUpload as j, ElIcon as z, ElDialog as P, ElForm as Q, ElFormItem as w, ElInput as S, ElButton as V, ElMessage as G } from "element-plus";
import { PictureFilled as H } from "../../../node_modules/.pnpm/@element-plus_icons-vue@2.3.1_vue@3.4.21/node_modules/@element-plus/icons-vue/dist/index.mjs";
import { SymbolState as J } from "../symbol.mjs";
import K from "../async-import.mjs";
const O = { key: 0 }, W = { style: { "text-align": "right" } }, te = /* @__PURE__ */ C({
  __name: "image-insert",
  setup(X) {
    let d;
    const { quill: o, httpRequest: v } = D(J), y = _(), c = _(!1), r = N({
      url: "",
      name: ""
    }), x = [
      {
        key: 1,
        label: "图片链接"
      },
      {
        key: 2,
        label: "内联图片"
      },
      {
        key: 3,
        label: "上传图片"
      }
    ], h = async (u, n) => {
      const e = u.file;
      if (n === "inline") {
        const s = new FileReader();
        s.onload = function(i) {
          if (i.target) {
            const L = i.target.result, f = o.value.getSelection(!0);
            f && (o.value.insertEmbed(f.index, "image", L), o.value.setSelection(f.index + 1, d.sources.SILENT));
          } else
            G.error("图片错误，请重新选择");
        }, s.readAsDataURL(e);
      } else {
        const s = await v.value(u), i = o.value.getSelection(!0);
        i && (o.value.insertEmbed(i.index, "image", s), o.value.setSelection(i.index + 1, d.sources.SILENT));
      }
    }, q = (u) => {
      u === 1 && (c.value = !0);
    }, k = () => {
      c.value = !1;
    }, I = async () => {
      var n;
      await ((n = y.value) == null ? void 0 : n.validate());
      const u = o.value.getSelection(!0);
      u && (o.value.insertEmbed(u.index, "image", r.value.url), o.value.setSelection(u.index + 1, d.sources.SILENT), k());
    };
    return F(async () => {
      d = await K();
    }), (u, n) => (m(), p("span", null, [
      t(l(T), null, {
        dropdown: a(() => [
          t(l(A), null, {
            default: a(() => [
              (m(), p(R, null, U(x, (e) => t(l(M), {
                disabled: e.key === 3 && !l(v),
                onClick: () => q(e.key),
                key: e.key
              }, {
                default: a(() => [
                  e.key === 1 ? (m(), p("span", O, E(e.label), 1)) : (m(), B(l(j), {
                    key: 1,
                    "show-file-list": !1,
                    "http-request": (s) => h(s, e.key === 2 ? "inline" : "upload")
                  }, {
                    default: a(() => [
                      g(E(e.label), 1)
                    ]),
                    _: 2
                  }, 1032, ["http-request"]))
                ]),
                _: 2
              }, 1032, ["disabled", "onClick"])), 64))
            ]),
            _: 1
          })
        ]),
        default: a(() => [
          b("button", null, [
            t(l(z), { size: 18 }, {
              default: a(() => [
                t(l(H))
              ]),
              _: 1
            })
          ])
        ]),
        _: 1
      }),
      t(l(P), {
        class: "wet-quill-imagelink",
        width: "400",
        "append-to-body": "",
        title: "插入图片",
        modelValue: c.value,
        "onUpdate:modelValue": n[2] || (n[2] = (e) => c.value = e),
        modal: !1,
        "show-close": !1
      }, {
        default: a(() => [
          t(l(Q), {
            model: r.value,
            ref_key: "formins",
            ref: y
          }, {
            default: a(() => [
              t(l(w), {
                label: "图片名称",
                prop: "name",
                rules: [{
                  required: !0,
                  message: "图片名称不能为空"
                }]
              }, {
                default: a(() => [
                  t(l(S), {
                    modelValue: r.value.name,
                    "onUpdate:modelValue": n[0] || (n[0] = (e) => r.value.name = e)
                  }, null, 8, ["modelValue"])
                ]),
                _: 1
              }),
              t(l(w), {
                label: "图片链接",
                prop: "url",
                rules: [{
                  required: !0,
                  type: "url",
                  message: "图片链接不能为空/url格式不正确"
                }]
              }, {
                default: a(() => [
                  t(l(S), {
                    modelValue: r.value.url,
                    "onUpdate:modelValue": n[1] || (n[1] = (e) => r.value.url = e)
                  }, null, 8, ["modelValue"])
                ]),
                _: 1
              })
            ]),
            _: 1
          }, 8, ["model"]),
          b("div", W, [
            t(l(V), { onClick: k }, {
              default: a(() => [
                g("取消")
              ]),
              _: 1
            }),
            t(l(V), {
              type: "primary",
              onClick: I
            }, {
              default: a(() => [
                g("确定")
              ]),
              _: 1
            })
          ])
        ]),
        _: 1
      }, 8, ["modelValue"])
    ]));
  }
});
export {
  te as default
};
