import '@das-fed/upf-ui/packages/business-components/upload-file/style.css';
import { ref as v, computed as h, defineComponent as x, useCssVars as U, openBlock as r, createElementBlock as p, createVNode as f, unref as u, mergeProps as c, isRef as V, createCommentVNode as w, normalizeClass as y, createElementVNode as F } from "vue";
import { withInstall as k } from "@das-fed/upf-utils/with-install/index";
import { DasInput as S } from "@das-fed/upf-ui/packages/components/input/index";
import { DasUpload as B } from "@das-fed/upf-ui/packages/components/upload/index";
import { useCalculateSize as C, minioUpload as b, DasImageViewer as D } from "@das-fed/upf-ui/packages/components/image-viewer/index";
import { t as N, setI18nRule as P } from "@das-fed/upf-web/packages/i18n/index";
import { DasMessage as I } from "@das-fed/upf-ui/packages/components/message/index";
const T = (e, o) => {
  const a = v(!1), { size2B: d } = C(), { upload: n } = b(e), m = (i) => {
    if (e.maxSize) {
      const { finalSize: t, sizeText: s } = d(e.maxSize);
      if (i.size > t) {
        const z = N("upload-file_uploadFileSizeLimit", s);
        return I.warning(z), !1;
      }
    }
    return !0;
  }, l = h({
    get: () => e.modelValue,
    set: (i) => o("update:modelValue", i)
  });
  return {
    loading: a,
    imgUrl: l,
    uploadFile: async (i) => {
      if (a.value = !0, m(i)) {
        const t = await n(i);
        t && t !== "error" ? (l.value = t, o("upload-success", i, t)) : o("upload-fail", i);
      }
      a.value = !1;
    }
  };
}, $ = { class: "das-business-file-upload" }, A = {
  key: 0,
  class: "input-box"
}, H = { class: "upload-box" }, L = /* @__PURE__ */ x({
  inheritAttrs: !1,
  __name: "App",
  props: {
    modelValue: {},
    width: {},
    isView: { type: Boolean },
    type: { default: "input" },
    imageWidth: { default: "100px" },
    imageHeight: { default: "100px" },
    maxSize: {},
    baseUrl: {},
    serviceName: {},
    pathPrefix: {},
    bucketName: {},
    minioTokenApi: { default: "token" },
    autoContentType: { type: Boolean },
    inputProps: { default: () => ({}) },
    imageProps: { default: () => ({}) }
  },
  emits: ["update:modelValue", "upload-success", "upload-fail"],
  setup(e, { emit: o }) {
    U((i) => ({
      v39455900: m.value,
      v79e51072: i.imageHeight
    }));
    const a = e, d = o, n = v([]), m = h(() => (a == null ? void 0 : a.width) ?? "100%"), { imgUrl: l, uploadFile: g } = T(a, d);
    return (i, t) => (r(), p("div", $, [
      e.type === "input" ? (r(), p("div", A, [
        f(u(S), c({
          width: "100%",
          modelValue: u(l),
          "onUpdate:modelValue": t[0] || (t[0] = (s) => V(l) ? l.value = s : null),
          "is-view": e.isView
        }, e.inputProps), null, 16, ["modelValue", "is-view"])
      ])) : w("v-if", !0),
      e.type === "image" ? (r(), p(
        "div",
        {
          key: 1,
          class: y(["image-box", e.isView ? "is-view" : ""])
        },
        [
          f(u(D), c({
            style: { width: e.imageWidth, height: e.imageHeight },
            modelValue: u(l),
            "onUpdate:modelValue": t[1] || (t[1] = (s) => V(l) ? l.value = s : null),
            status: "info",
            "is-view": !0
          }, e.imageProps), null, 16, ["style", "modelValue"])
        ],
        2
        /* CLASS */
      )) : w("v-if", !0),
      F("div", H, [
        f(u(B), c({
          modelValue: n.value,
          "onUpdate:modelValue": t[2] || (t[2] = (s) => n.value = s),
          draggle: !1,
          "is-view": e.isView
        }, i.$attrs, { onFileUpload: u(g) }), null, 16, ["modelValue", "is-view", "onFileUpload"])
      ])
    ]));
  }
}), M = (e, o) => {
  const a = e.__vccOpts || e;
  for (const [d, n] of o)
    a[d] = n;
  return a;
}, R = /* @__PURE__ */ M(L, [["__scopeId", "data-v-800b87f7"]]), W = {
  "upload-file_uploadFileSizeLimit": {
    "zh-CN": "上传的文件大小不能超过$0",
    en: "The size of the uploaded file cannot exceed $0",
    "zh-MO": "上傳的文件大小不能超過$0",
    _appCode: "framework"
  }
};
P(W);
const Q = k(R), X = () => v(null), Y = { name: "复合型文件上传 upload-file" };
export {
  Q as DasBusinessUploadFile,
  X as DasBusinessUploadFileRef,
  Y as default
};
