import '@das-fed/ui/packages/components/image-upload/style.css';
import { withInstall as O } from "@das-fed/utils/with-install/index";
import { currentLang as T, i18n as V, t as w, setI18nRule as R } from "@das-fed/web/packages/i18n/index";
import { getVar as x, setThemeRule as K } from "@das-fed/web/packages/theme/index";
import { computed as z, defineComponent as W, createElementBlock as P, openBlock as H, createCommentVNode as B, withDirectives as N, createVNode as g, unref as o, normalizeClass as L, withCtx as f, createElementVNode as v, toDisplayString as D, vShow as S, createTextVNode as q } from "vue";
import { UploadDragger as G, Upload as J } from "ant-design-vue";
import "ant-design-vue/es/upload/style/css";
import { DasSpin as Q } from "@das-fed/ui/packages/components/spin/index";
import { DasButton as X } from "@das-fed/ui/packages/components/button/index";
import { DasIconAddto as Y } from "@das-fed/ui/packages/icons/addto/index";
import { DasIconWarning as Z } from "@das-fed/ui/packages/icons/warning/index";
import { DasMessage as U } from "@das-fed/ui/packages/components/message/index";
import { getFileExtension as ee } from "@das-fed/utils/common-tools";
import { useModelValue as ae } from "@das-fed/utils/vue";
import "@das-fed/ui/packages/global/theme";
const oe = () => ({ size2B: (t) => {
  isNaN(Number(t)) ? t = t.toString() : t = t + "M";
  const i = Number(t.slice(0, -1)), n = t[t.length - 1].toUpperCase(), l = 1024, C = {
    M: l * l,
    K: l,
    B: 1
  };
  return { finalSize: i * C[n], sizeText: t };
} }), te = (a, t) => {
  const i = ae(a, "status"), { size2B: n } = oe(), l = [".mp4", ".avi", ".mkv", ".mov", ".wmv", ".flv", ".mpeg", ".webm"], C = [".mp3", ".wav", ".aac", ".flac", ".ogg", ".alff", ".wma", ".m4a"], s = z(() => {
    var c;
    let e = a.accept ? (c = a.accept) == null ? void 0 : c.split(",") : [];
    return e.includes("image/jpg") && !e.includes("image/jpeg") && e.push("image/jpeg"), e.includes(".jpg") && !e.includes(".jpeg") && e.push(".jpeg"), a.acceptVideo && (e = [...e, ...l]), a.acceptAudio && (e = [...e, ...C]), e.join(",");
  }), y = z(() => i.value === "uploading"), k = z(() => i.value === "error");
  return { isAccept: s, uploadStatus: i, loading: y, errored: k, beforeupload: (e) => {
    var _, F, I;
    if (a.maxSize) {
      const { finalSize: d, sizeText: u } = n(a.maxSize);
      if (e.size > d) {
        const h = a.acceptAudio || a.acceptVideo ? "das-ui-import-upload-key4" : "das-ui-import-upload-key3", p = T.value === "zh-CN" ? "、" : ", ", b = V(
          h,
          u,
          ((I = (F = (_ = s.value) == null ? void 0 : _.toUpperCase()) == null ? void 0 : F.replaceAll(".", "")) == null ? void 0 : I.replaceAll(",", p)) ?? ""
        ).value, A = a.errorMessage || b;
        return U.warning(A), t("update:status", "normal"), i.value = "normal", !1;
      }
    }
    const c = () => (i.value = "uploading", t("update:status", "uploading"), t("image-upload", e), !1);
    if (a.customCheck) {
      const d = a.customCheck(e);
      if (d instanceof Promise)
        return new Promise(async (u, h) => {
          let p;
          try {
            p = await d.then();
          } catch {
            p = !1;
          }
          p ? c() : h(!1);
        });
      if (!d)
        return t("update:status", "normal"), i.value = "normal", !1;
    } else if (s.value) {
      const d = s.value.split(",").filter((r) => r.trim().startsWith(".")).map((r) => r.trim()), u = s.value.split(",").filter((r) => !r.trim().startsWith(".")).map((r) => r.trim()), h = ee(e.name), p = d.includes(h);
      let b = u.includes("image/*") && e.type.split("/")[0].trim() === "image", A = u.includes("video/*") && e.type.split("/")[0].trim() === "video", $ = u.includes("audio/*") && e.type.split("/")[0].trim() === "audio", M = u.includes(e.type) || b || A || $;
      if (!p && !M) {
        const r = a.acceptAudio || a.acceptVideo ? "das-ui-import-upload-key2" : "das-ui-import-upload-key1", j = T.value === "zh-CN" ? "、" : ", ", E = a.errorMessage || V(r, s.value.toUpperCase().replaceAll(".", "").replaceAll(",", j)).value;
        return U.warning(E), !1;
      }
    }
    return c();
  } };
}, ie = { class: "das-ui-image-upload" }, le = { class: "das-ui-image-upload-dragger-context" }, se = { class: "text" }, re = { class: "das-ui-image-upload-error-container" }, ne = { class: "tips-container" }, ce = { class: "text" }, de = /* @__PURE__ */ W({
  __name: "Index",
  props: {
    maxCount: { default: 1 },
    status: { default: "normal" },
    message: { default: "" },
    errorMessage: { default: "" },
    accept: { default: ".png, .jpg, .jpeg, .gif, .svg" },
    acceptVideo: { type: Boolean },
    acceptAudio: { type: Boolean },
    maxSize: {},
    customCheck: {},
    autoContentType: { type: Boolean },
    openFileDialogOnClick: { type: Boolean, default: !0 }
  },
  emits: ["update:status", "image-upload"],
  setup(a, { emit: t }) {
    const i = a, n = t, { isAccept: l, uploadStatus: C, loading: s, errored: y, beforeupload: k } = te(i, n);
    return (m, e) => (H(), P("div", ie, [
      B(" 图片上传组件 "),
      N(g(o(Q), {
        class: L([{ "loading-border": o(s) }]),
        type: "component",
        spinning: o(s)
      }, {
        default: f(() => [
          g(o(G), {
            class: "das-ui-image-upload-dragger",
            accept: o(l),
            "max-count": m.maxCount,
            "before-upload": o(k),
            openFileDialogOnClick: m.openFileDialogOnClick
          }, {
            itemRender: f(({ file: c, actions: _ }) => e[0] || (e[0] = [])),
            default: f(() => [
              N(v(
                "div",
                le,
                [
                  g(o(Y), {
                    iconColor: o(x)("--das-ui-color-secondary")
                  }, null, 8, ["iconColor"]),
                  v(
                    "div",
                    se,
                    D(m.message || o(w)("das-image-upload-text")),
                    1
                    /* TEXT */
                  )
                ],
                512
                /* NEED_PATCH */
              ), [
                [S, o(C) === "normal"]
              ])
            ]),
            _: 1
            /* STABLE */
          }, 8, ["accept", "max-count", "before-upload", "openFileDialogOnClick"])
        ]),
        _: 1
        /* STABLE */
      }, 8, ["class", "spinning"]), [
        [S, !o(y)]
      ]),
      B(" 错误状态 "),
      N(v(
        "div",
        re,
        [
          v("div", ne, [
            g(o(Z), {
              iconColor: o(x)("--das-ui-color-danger"),
              size: "small"
            }, null, 8, ["iconColor"]),
            v(
              "div",
              ce,
              D(o(w)("das-image-upload-fail")),
              1
              /* TEXT */
            )
          ]),
          g(o(J), {
            accept: o(l),
            "before-upload": o(k),
            "max-count": m.maxCount,
            openFileDialogOnClick: m.openFileDialogOnClick
          }, {
            itemRender: f(({ file: c, actions: _ }) => e[1] || (e[1] = [])),
            default: f(() => [
              g(o(X), {
                "btn-type": "primary-text",
                block: ""
              }, {
                default: f(() => [
                  q(
                    D(o(w)("das-image-upload-reupload")),
                    1
                    /* TEXT */
                  )
                ]),
                _: 1
                /* STABLE */
              })
            ]),
            _: 1
            /* STABLE */
          }, 8, ["accept", "before-upload", "max-count", "openFileDialogOnClick"])
        ],
        512
        /* NEED_PATCH */
      ), [
        [S, o(y)]
      ])
    ]));
  }
}), ue = (a, t) => {
  const i = a.__vccOpts || a;
  for (const [n, l] of t)
    i[n] = l;
  return i;
}, pe = /* @__PURE__ */ ue(de, [["__scopeId", "data-v-1159eda2"]]), me = {
  "das-ui-import-upload-key1": {
    "zh-CN": "上传的图片格式只能是$0",
    en: "The uploaded picture format can only be $0",
    _appCode: "framework"
  },
  "das-ui-import-upload-key2": {
    "zh-CN": "上传的文件格式只能是$0",
    en: "The uploaded file format can only be $0",
    _appCode: "framework"
  },
  "das-ui-import-upload-key3": {
    "zh-CN": "上传的图片大小不能超过$0的$1文件",
    en: "The uploaded picture format can only be $0",
    _appCode: "framework"
  },
  "das-ui-import-upload-key4": {
    "zh-CN": "上传的文件大小不能超过$0的$1文件",
    en: "The uploaded file format can only be $0",
    _appCode: "framework"
  },
  "das-image-upload-text": { "zh-CN": "上传图片", en: "Upload Image", _appCode: "framework" },
  "das-image-upload-reupload": { "zh-CN": "重新上传", en: "Re-upload", _appCode: "framework" },
  "das-image-upload-fail": { "zh-CN": "上传失败", en: "Uploaded Failed", _appCode: "framework" }
}, ge = {
  "--das-ui-image-upload-bgcolor": { light: "#FAFAFA" },
  "--das-ui-image-upload-border-color": { light: "#E5E5E5" },
  "--das-ui-image-upload-bgcolor-hover": { light: x("--das-ui-color-primary-level1") },
  "--das-ui-image-upload-border-color-hover": { light: "#5582F3" },
  "--das-ui-image-upload-border-color-error": { light: x("--das-ui-color-danger-level2") }
}, Se = O(pe);
R(me);
K(ge);
export {
  Se as DasImageUpload,
  Se as default
};
