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