import '@das-fed/upf-ui/packages/components/upload/style.css';
import { withInstall as G } from "@das-fed/upf-utils/with-install/index";
import { currentLang as K, t as g, setI18nRule as P } from "@das-fed/upf-web/packages/i18n/index";
import { useAttrs as q, computed as $, defineComponent as H, openBlock as u, createElementBlock as v, Fragment as J, createVNode as h, unref as t, mergeProps as O, isRef as A, withCtx as m, renderSlot as V, createElementVNode as p, withDirectives as b, createTextVNode as C, toDisplayString as s, createCommentVNode as k, createBlock as M, vShow as B } from "vue";
import { UploadDragger as Q, Upload as X } from "ant-design-vue";
import "ant-design-vue/es/upload/style/css";
import { DasButton as D } from "@das-fed/upf-ui/packages/components/button/index";
import { vDasTooltip as L } from "@das-fed/upf-ui/packages/components/text-tooltip/index";
import { DasIconLink as T } from "@das-fed/upf-ui/packages/icons/link/index";
import { DasIconAddto as Y } from "@das-fed/upf-ui/packages/icons/addto/index";
import { DasAutoRegisterIcon as ee } from "@das-fed/upf-ui/packages/components/icon/index";
import { DasMessage as te } from "@das-fed/upf-ui/packages/components/message/index";
import { getFileExtension as oe } from "@das-fed/upf-utils/common-tools";
import { useModelValue as x } from "@das-fed/upf-utils/vue";
import "@das-fed/upf-ui/packages/global/theme";
const ae = (e) => {
  const o = ["B", "KB", "M", "G"];
  let c = 0;
  for (; e > 1024; )
    c++, e /= 1024;
  return e = Number(Number(e).toFixed(1)), `${e}${o[c]}`;
}, le = (e, d) => {
  const o = x(e, "modelValue"), c = x(e, "error"), i = x(e, "errorMessage"), z = x(e, "errorFileName"), w = q(), y = $(() => !w.multiple && e.maxCount === 1), F = $(() => y.value && o.value.length ? "none" : "block");
  return {
    fileList: o,
    error: c,
    errorMessage: i,
    errorFileName: z,
    uploadDiaplay: F,
    beforeupload: (l) => {
      if (e.accept) {
        const r = e.accept.split(",").filter((n) => n.trim().startsWith(".")).map((n) => n.trim()), a = e.accept.split(",").filter((n) => !n.trim().startsWith(".")).map((n) => n.trim()), f = oe(l.name), U = r.includes(f);
        let R = a.includes("image/*") && l.type.split("/")[0].trim() === "image", _ = a.includes("video/*") && l.type.split("/")[0].trim() === "video", j = a.includes("audio/*") && l.type.split("/")[0].trim() === "audio", Z = a.includes(l.type) || R || _ || j;
        if (!U && !Z) {
          const n = K.value === "zh-CN" ? "、" : ", ", W = e.errorMessage || g("das-ui-upload-accpet", e.accept.toUpperCase().replace(/\./g, "").replace(/,/g, n));
          return te.warning(W), !1;
        }
      }
      return l.sizeText = ae(l.size), w.multiple ? (o.value = o.value.map((r) => r.originFileObj ? r.originFileObj : r), e.maxCount > o.value.length && o.value.push(l)) : o.value = [l], d("update:modelValue", o.value), d("file-upload", l), !1;
    },
    errorFiledownload: () => {
      d("errorFile-download");
    },
    removeFileEvent: (l, r) => {
      o.value = o.value.filter((a) => a.uid != r.uid), o.value.length > 0 && (o.value = o.value.map((a) => a.originFileObj ? a.originFileObj : a)), d("update:modelValue", o.value), l.remove();
    }
  };
}, re = { class: "das-ui-upload" }, ie = { class: "das-ui-upload-dragger-context" }, se = { class: "text" }, de = { class: "file-list" }, ne = { class: "filename" }, ue = {
  key: 0,
  class: "file-size"
}, ce = { class: "error-container" }, me = { class: "file-list" }, pe = { class: "filename error-file-name" }, fe = {
  key: 0,
  class: "file-size"
}, ve = { class: "error-message" }, I = "var(--das-ui-color-secondary)", ge = /* @__PURE__ */ H({
  __name: "Index",
  props: {
    draggle: { type: Boolean, default: !0 },
    modelValue: {},
    maxCount: { default: 1 },
    width: { default: "100%" },
    error: { type: Boolean, default: !1 },
    accept: { default: "" },
    errorMessage: {},
    errorFileSize: {},
    errorFileName: {},
    isView: { type: Boolean, default: !1 },
    showSize: { type: Boolean, default: !0 },
    btnName: { default: "" }
  },
  emits: ["file-upload", "errorFile-download", "update:modelValue"],
  setup(e, { emit: d }) {
    ee({
      shangchuan: import("@das-fed/upf-ui/packages/icons/shangchuan")
    });
    const o = e, c = d, {
      fileList: i,
      error: z,
      errorMessage: w,
      errorFileName: y,
      uploadDiaplay: F,
      beforeupload: N,
      errorFiledownload: S,
      removeFileEvent: E
    } = le(o, c);
    return (l, r) => (u(), v("div", re, [
      e.draggle ? (u(), v(
        J,
        { key: 0 },
        [
          h(t(Q), O({
            class: "das-ui-upload-dragger",
            fileList: t(i),
            "onUpdate:fileList": r[0] || (r[0] = (a) => A(i) ? i.value = a : null),
            "max-count": e.maxCount,
            accept: e.accept,
            style: { width: e.width, display: t(F) },
            "before-upload": t(N),
            disabled: e.isView
          }, l.$attrs), {
            itemRender: m(({ file: a, actions: f }) => [
              V(l.$slots, "itemRender", {
                file: a,
                actions: f
              }, () => [
                p("div", de, [
                  h(t(T), {
                    iconColor: I,
                    size: "medium"
                  }),
                  b((u(), v("div", ne, [
                    C(
                      s(a.name),
                      1
                      /* TEXT */
                    )
                  ])), [
                    [t(L)]
                  ]),
                  e.showSize ? (u(), v(
                    "div",
                    ue,
                    "(" + s(a.sizeText) + ")",
                    1
                    /* TEXT */
                  )) : k("v-if", !0),
                  e.isView ? k("v-if", !0) : (u(), M(t(D), {
                    key: 1,
                    "btn-type": "primary-text",
                    size: "large",
                    onClick: (U) => t(E)(f, a),
                    block: ""
                  }, {
                    default: m(() => [
                      C(
                        s(t(g)("das-upload-delete")),
                        1
                        /* TEXT */
                      )
                    ]),
                    _: 1
                    /* STABLE */
                  }, 8, ["onClick"]))
                ])
              ], !0)
            ]),
            default: m(() => [
              p("div", ie, [
                h(t(Y), { iconColor: I }),
                p(
                  "div",
                  se,
                  s(t(g)("das-upload-text")),
                  1
                  /* TEXT */
                )
              ])
            ]),
            _: 3
            /* FORWARDED */
          }, 16, ["fileList", "max-count", "accept", "style", "before-upload", "disabled"]),
          b(p(
            "div",
            ce,
            [
              b(p(
                "div",
                me,
                [
                  h(t(T), {
                    iconColor: I,
                    size: "medium"
                  }),
                  b((u(), v("div", pe, [
                    C(
                      s(t(y)),
                      1
                      /* TEXT */
                    )
                  ])), [
                    [t(L)]
                  ]),
                  e.showSize ? (u(), v(
                    "div",
                    fe,
                    "(" + s(e.errorFileSize) + ")",
                    1
                    /* TEXT */
                  )) : k("v-if", !0),
                  h(t(D), {
                    "btn-type": "primary-text",
                    block: "",
                    size: "large",
                    onClick: t(S)
                  }, {
                    default: m(() => [
                      C(
                        s(t(g)("das-upload-download")),
                        1
                        /* TEXT */
                      )
                    ]),
                    _: 1
                    /* STABLE */
                  }, 8, ["onClick"])
                ],
                512
                /* NEED_PATCH */
              ), [
                [B, t(y)]
              ]),
              p(
                "div",
                ve,
                s(t(g)("das-upload-tips")) + s(t(w)),
                1
                /* TEXT */
              )
            ],
            512
            /* NEED_PATCH */
          ), [
            [B, t(z)]
          ])
        ],
        64
        /* STABLE_FRAGMENT */
      )) : (u(), M(t(X), O({
        key: 1,
        "file-list": t(i),
        "onUpdate:fileList": r[1] || (r[1] = (a) => A(i) ? i.value = a : null),
        accept: e.accept,
        "before-upload": t(N),
        "max-count": e.maxCount,
        disabled: e.isView
      }, l.$attrs), {
        itemRender: m(({ file: a, actions: f }) => [
          V(l.$slots, "itemRender", {
            file: a,
            actions: f
          }, () => [
            r[2] || (r[2] = p(
              "div",
              null,
              null,
              -1
              /* CACHED */
            ))
          ], !0)
        ]),
        default: m(() => [
          V(l.$slots, "customUpload", {}, () => [
            e.isView ? k("v-if", !0) : (u(), M(t(D), {
              key: 0,
              icon: "shangchuan",
              block: ""
            }, {
              default: m(() => [
                C(
                  s(e.btnName || t(g)("das-upload-btn-text")),
                  1
                  /* TEXT */
                )
              ]),
              _: 1
              /* STABLE */
            }))
          ], !0)
        ]),
        _: 3
        /* FORWARDED */
      }, 16, ["file-list", "accept", "before-upload", "max-count", "disabled"]))
    ]));
  }
}), he = (e, d) => {
  const o = e.__vccOpts || e;
  for (const [c, i] of d)
    o[c] = i;
  return o;
}, Ce = /* @__PURE__ */ he(ge, [["__scopeId", "data-v-e8a69aad"]]), we = {
  "das-upload-text": { "zh-CN": "点击或拖拽上传", en: "Click or drag to upload", "zh-MO": "點擊或拖曳上傳", _appCode: "framework" },
  "das-upload-btn-text": { "zh-CN": "上传文件", en: "Upload File", "zh-MO": "上傳文件", _appCode: "framework" },
  "das-upload-download": { "zh-CN": "下载", en: "Download", "zh-MO": "下載", _appCode: "framework" },
  "das-upload-delete": { "zh-CN": "删除", en: "Delete", "zh-MO": "刪除", _appCode: "framework" },
  "das-upload-tips": { "zh-CN": "提示: ", en: "Tip: ", "zh-MO": "提示：", _appCode: "framework" },
  "das-ui-upload-accpet": {
    "zh-CN": "上传的文件格式只能是$0",
    en: "The uploaded file format can only be $0",
    "zh-MO": "上傳的檔案格式只能是$0",
    _appCode: "framework"
  }
}, $e = G(Ce);
P(we);
export {
  $e as DasUpload,
  $e as default
};
