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