import { ref as u, watch as O, resolveComponent as v, openBlock as w, createElementBlock as g, createElementVNode as a, toDisplayString as T, createCommentVNode as j, createVNode as c, withCtx as y, pushScopeId as q, popScopeId as z } from "vue";
import { r as A, v as E } from "./index2.js";
import { a as F, d as M, b as $ } from "./upload.js";
import { U as P } from "./index6.js";
import { M as H } from "./index7.js";
const b = (n) => (q("data-v-6353f81e"), n = n(), z(), n), V = { class: "s-file-upload-common" }, G = { class: "head" }, K = {
  key: 0,
  class: "label"
}, X = { class: "ant-upload-drag-icon" }, J = /* @__PURE__ */ b(() => /* @__PURE__ */ a("p", { class: "ant-upload-text" }, "点击或拖入文件到此处", -1)), Q = /* @__PURE__ */ b(() => /* @__PURE__ */ a("p", { class: "ant-upload-hint" }, "支持单个或批量上传", -1)), W = { class: "preview-content" }, Y = ["src"], Z = /* @__PURE__ */ Object.assign({
  inheritAttrs: !0
}, {
  __name: "SDraggerUpload",
  props: {
    /**
     * 文件列表
     * @list
     */
    list: {
      type: Array,
      default: () => []
    },
    /**
     * 标题
     * @label
     */
    label: {
      type: String,
      default: ""
    },
    /**
     * 只读
     * @readonly
    */
    readonly: {
      type: Boolean,
      default: !1
    },
    /**
     * 是否显示删除
     * @delete
    */
    showRemoveIcon: {
      type: Boolean,
      default: !1
    },
    /**
     * 是否显示新增
     * @isAdd
    */
    isAdd: {
      type: Boolean,
      default: !0
    },
    /**
     * 文件类型
     * @accept
    */
    accept: {
      type: String,
      default: ""
    },
    // 展示类型 picture | picture-card 注：规范内不设定text上传类型
    listType: {
      type: String,
      default: "picture"
    },
    maxFileCount: {
      type: Number,
      default: 3
    },
    sizeLimit: {
      type: Number,
      default: 50
    },
    businessTableName: {
      type: String,
      default: "sapit-ui-plus-components-upload"
    },
    businessKey: {
      type: String,
      default: void 0
    },
    showUploadList: {
      type: Boolean,
      default: !0
    }
  },
  setup(n) {
    const s = n, o = u([]), d = u(!1), p = u(""), r = u(""), l = u(0);
    O(() => s.list, (e) => {
      e && e.length && (o.value = e);
    }, { immediate: !0 });
    const _ = (e) => {
      console.log(s.sizeLimit);
      const t = e.size / 1024 / 1024 < s.sizeLimit;
      return t || E.warn({
        key: "only-you",
        message: "提醒",
        description: `文件不能大于${s.sizeLimit}MB！`
      }), t;
    }, x = ({ onSuccess: e, onError: t, file: i }) => {
      F(i, s.businessTableName, i.uid).then(() => {
        e();
      }).catch(() => {
        o.value.splice(o.value.length - 1, 1), t();
      });
    }, L = (e) => {
      o.value = e.fileList;
    };
    function C(e) {
      console.log(e);
    }
    const U = (e) => {
      l.value = o.value.findIndex((t) => t.uid === e.uid), d.value = !0, r.value = e.name || "预览", p.value = e.url || e.thumbUrl;
    }, R = (e) => {
      const t = document.createElement("a");
      t.href = M(e.uid), t.download = "test", t.click();
    }, S = () => {
      d.value = !1;
    }, h = (e) => {
      var t;
      l.value = l.value + e < 0 ? 0 : l.value + e > o.value.length - 1 ? o.value.length - 1 : l.value + e, (t = o.value[l.value]) != null && t.thumbUrl ? (r.value = o.value[l.value].name || "预览", p.value = o.value[l.value].thumbUrl) : D(o.value[l.value]);
    }, D = (e) => {
      if (e.type.includes("office")) {
        const t = window.open("", "");
        t.location = $(e.uid + "/" + e.name);
      } else if (e.type.includes("text"))
        k(e.url);
      else if (e.type.includes("pdf") || e.type.includes("png") || e.type.includes("gif") || e.type.includes("jpeg") || e.type.includes("bmp") || e.type.includes("ico") || e.type.includes("webp")) {
        const t = window.open("", "");
        t.location = e.url;
      } else
        this.$notification.warning({
          message: "不支持此文件类型"
        });
    }, k = (e) => {
      const t = new XMLHttpRequest();
      t.open("GET", e, !0), t.responseType = "blob", t.setRequestHeader("Content-Type", "application/json"), t.onload = function() {
        const i = new Blob([t.response], { type: "application/json;charset=utf-8" }), m = window.URL.createObjectURL(i), f = window.open("", "");
        f.location = m;
      }, t.send();
    };
    return (e, t) => {
      const i = v("inbox-outlined"), m = P, f = v("LeftOutlined"), B = v("RightOutlined"), I = H;
      return w(), g("div", V, [
        a("div", G, [
          n.label ? (w(), g("div", K, T(n.label), 1)) : j("", !0)
        ]),
        c(m, {
          accept: n.accept,
          "list-type": "picture",
          "file-list": o.value,
          disabled: n.readonly,
          maxCount: n.maxFileCount,
          multiple: n.maxFileCount > 1,
          "before-upload": _,
          "custom-request": x,
          onDrop: C,
          onChange: L,
          onPreview: U,
          onDownload: R,
          showUploadList: n.showUploadList
        }, {
          default: y(() => [
            a("p", X, [
              c(i)
            ]),
            J,
            Q
          ]),
          _: 1
        }, 8, ["accept", "file-list", "disabled", "maxCount", "multiple", "showUploadList"]),
        c(I, {
          open: d.value,
          title: r.value,
          footer: null,
          onCancel: S,
          width: "800px"
        }, {
          default: y(() => [
            a("div", W, [
              a("div", {
                class: "prev",
                onClick: t[0] || (t[0] = (N) => h(-1))
              }, [
                c(f)
              ]),
              a("img", {
                alt: "example",
                class: "view",
                src: p.value
              }, null, 8, Y),
              a("div", {
                class: "next",
                onClick: t[1] || (t[1] = (N) => h(1))
              }, [
                c(B)
              ])
            ])
          ]),
          _: 1
        }, 8, ["open", "title"])
      ]);
    };
  }
}), ae = /* @__PURE__ */ A(Z, [["__scopeId", "data-v-6353f81e"]]);
export {
  ae as default
};
