import { ref as d, watch as j, resolveComponent as m, openBlock as y, createElementBlock as b, createElementVNode as o, toDisplayString as h, createCommentVNode as q, createVNode as c, withCtx as _ } from "vue";
import { l as z, W as A } from "./index2.js";
import { a as E, d as F, p as I } from "./upload.js";
import { U as H } from "./index16.js";
const P = { class: "s-file-upload-common" }, M = { class: "head" }, V = {
  key: 0,
  class: "label"
}, G = { class: "ant-upload-drag-icon" }, K = { class: "ant-upload-text" }, W = { class: "ant-upload-hint" }, X = { class: "preview-content" }, J = ["src"], Q = /* @__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
    }
  },
  emits: ["handChange"],
  setup(a, { emit: C }) {
    const L = C, s = a, n = d([]), p = d(!1), r = d(""), v = d(""), l = d(0);
    j(
      () => s.list,
      (e) => {
        e && e.length && (n.value = e);
      },
      { immediate: !0 }
    );
    const x = (e) => {
      console.log(s.sizeLimit);
      const t = e.size / 1024 / 1024 < s.sizeLimit;
      return t || A.warn({
        key: "only-you",
        message: window.$l("提醒"),
        description: `${window.$l("文件不能大于")}${s.sizeLimit}MB！`
      }), t;
    }, U = ({ onSuccess: e, onError: t, file: i }) => {
      E(i, s.businessTableName, i.uid).then((u) => {
        e(u);
      }).catch(() => {
        n.value.splice(n.value.length - 1, 1), t();
      });
    }, $ = (e) => {
      n.value = e.fileList, L("handChange", n.value);
    };
    function R(e) {
      console.log(e);
    }
    const D = (e) => {
      l.value = n.value.findIndex((t) => t.uid === e.uid), p.value = !0, v.value = e.name || window.$l("预览"), r.value = e.url || e.thumbUrl;
    }, k = (e) => {
      const t = document.createElement("a");
      t.href = F(e.uid), t.download = "test", t.click();
    }, B = () => {
      p.value = !1;
    }, g = (e) => {
      var t;
      l.value = l.value + e < 0 ? 0 : l.value + e > n.value.length - 1 ? n.value.length - 1 : l.value + e, (t = n.value[l.value]) != null && t.thumbUrl ? (v.value = n.value[l.value].name || window.$l("预览"), r.value = n.value[l.value].thumbUrl) : S(n.value[l.value]);
    }, S = (e) => {
      if (e.type.includes("office")) {
        const t = window.open("", "");
        t.location = I(e.uid + "/" + e.name);
      } else if (e.type.includes("text"))
        N(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: window.$l("不支持此文件类型")
        });
    }, N = (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" }), u = window.URL.createObjectURL(i), f = window.open("", "");
        f.location = u;
      }, t.send();
    };
    return (e, t) => {
      const i = m("inbox-outlined"), u = H, f = m("LeftOutlined"), O = m("RightOutlined"), T = m("s-modal");
      return y(), b("div", P, [
        o("div", M, [
          a.label ? (y(), b("div", V, h(a.label), 1)) : q("", !0)
        ]),
        c(u, {
          accept: a.accept,
          "list-type": "picture",
          "file-list": n.value,
          disabled: a.readonly,
          maxCount: a.maxFileCount,
          multiple: a.maxFileCount > 1,
          "before-upload": x,
          "custom-request": U,
          onDrop: R,
          onChange: $,
          onPreview: D,
          onDownload: k,
          showUploadList: a.showUploadList
        }, {
          default: _(() => [
            o("p", G, [
              c(i)
            ]),
            o("p", K, h(e.$l("点击或拖入文件到此处")), 1),
            o("p", W, h(e.$l("支持单个或批量上传")), 1)
          ]),
          _: 1
        }, 8, ["accept", "file-list", "disabled", "maxCount", "multiple", "showUploadList"]),
        c(T, {
          value: p.value,
          "onUpdate:value": t[2] || (t[2] = (w) => p.value = w),
          title: v.value,
          onHandCancel: B,
          width: "800px"
        }, {
          default: _(() => [
            o("div", X, [
              o("div", {
                class: "prev",
                onClick: t[0] || (t[0] = (w) => g(-1))
              }, [
                c(f)
              ]),
              o("img", {
                alt: "example",
                class: "view",
                src: r.value
              }, null, 8, J),
              o("div", {
                class: "next",
                onClick: t[1] || (t[1] = (w) => g(1))
              }, [
                c(O)
              ])
            ])
          ]),
          _: 1
        }, 8, ["value", "title"])
      ]);
    };
  }
}), ne = /* @__PURE__ */ z(Q, [["__scopeId", "data-v-84475a19"]]);
export {
  ne as default
};
