import '@das-fed/ui/packages/components/image-upload/style.css';
import { withInstall as Ie } from "@das-fed/utils/with-install/index";
import { currentLang as ge, i18n as ve, t as G, setI18nRule as Pe } from "@das-fed/web/packages/i18n/index";
import { getVar as L, setThemeRule as Se } from "@das-fed/web/packages/theme/index";
import { computed as X, defineComponent as je, createElementBlock as Le, openBlock as _e, createCommentVNode as ye, withDirectives as K, createVNode as M, unref as v, normalizeClass as Ne, withCtx as O, createElementVNode as z, toDisplayString as Y, vShow as q, createTextVNode as We } from "vue";
import { UploadDragger as He, Upload as $e } from "ant-design-vue";
import "ant-design-vue/es/upload/style/css";
import { DasSpin as Ve } from "@das-fed/ui/packages/components/spin/index";
import { DasButton as Ge } from "@das-fed/ui/packages/components/button/index";
import { DasIconAddto as Xe } from "@das-fed/ui/packages/icons/addto/index";
import { DasIconWarning as Ke } from "@das-fed/ui/packages/icons/warning/index";
import { DasMessage as be } from "@das-fed/ui/packages/components/message/index";
import { getFileExtension as Ye } from "@das-fed/utils/common-tools";
import { useModelValue as we } from "@das-fed/utils/vue";
import "@das-fed/ui/packages/global/theme";
const qe = () => ({ size2B: (e) => {
  isNaN(Number(e)) ? e = e.toString() : e = e + "M";
  const a = Number(e.slice(0, -1)), i = e[e.length - 1].toUpperCase(), r = 1024, o = {
    M: r * r,
    K: r,
    B: 1
  };
  return { finalSize: a * o[i], sizeText: e };
} });
/*!
 * Compressor.js v1.2.1
 * https://fengyuanchen.github.io/compressorjs
 *
 * Copyright 2018-present Chen Fengyuan
 * Released under the MIT license
 *
 * Date: 2023-02-28T14:09:41.732Z
 */
function xe(t, e) {
  var a = Object.keys(t);
  if (Object.getOwnPropertySymbols) {
    var i = Object.getOwnPropertySymbols(t);
    e && (i = i.filter(function(r) {
      return Object.getOwnPropertyDescriptor(t, r).enumerable;
    })), a.push.apply(a, i);
  }
  return a;
}
function j(t) {
  for (var e = 1; e < arguments.length; e++) {
    var a = arguments[e] != null ? arguments[e] : {};
    e % 2 ? xe(Object(a), !0).forEach(function(i) {
      Ze(t, i, a[i]);
    }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(t, Object.getOwnPropertyDescriptors(a)) : xe(Object(a)).forEach(function(i) {
      Object.defineProperty(t, i, Object.getOwnPropertyDescriptor(a, i));
    });
  }
  return t;
}
function Je(t, e) {
  if (!(t instanceof e))
    throw new TypeError("Cannot call a class as a function");
}
function Ce(t, e) {
  for (var a = 0; a < e.length; a++) {
    var i = e[a];
    i.enumerable = i.enumerable || !1, i.configurable = !0, "value" in i && (i.writable = !0), Object.defineProperty(t, De(i.key), i);
  }
}
function Qe(t, e, a) {
  return e && Ce(t.prototype, e), a && Ce(t, a), Object.defineProperty(t, "prototype", {
    writable: !1
  }), t;
}
function Ze(t, e, a) {
  return e = De(e), e in t ? Object.defineProperty(t, e, {
    value: a,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : t[e] = a, t;
}
function _() {
  return _ = Object.assign ? Object.assign.bind() : function(t) {
    for (var e = 1; e < arguments.length; e++) {
      var a = arguments[e];
      for (var i in a)
        Object.prototype.hasOwnProperty.call(a, i) && (t[i] = a[i]);
    }
    return t;
  }, _.apply(this, arguments);
}
function et(t, e) {
  if (typeof t != "object" || t === null) return t;
  var a = t[Symbol.toPrimitive];
  if (a !== void 0) {
    var i = a.call(t, e);
    if (typeof i != "object") return i;
    throw new TypeError("@@toPrimitive must return a primitive value.");
  }
  return String(t);
}
function De(t) {
  var e = et(t, "string");
  return typeof e == "symbol" ? e : String(e);
}
var Te = { exports: {} };
(function(t) {
  typeof window > "u" || function(e) {
    var a = e.HTMLCanvasElement && e.HTMLCanvasElement.prototype, i = e.Blob && function() {
      try {
        return !!new Blob();
      } catch {
        return !1;
      }
    }(), r = i && e.Uint8Array && function() {
      try {
        return new Blob([new Uint8Array(100)]).size === 100;
      } catch {
        return !1;
      }
    }(), o = e.BlobBuilder || e.WebKitBlobBuilder || e.MozBlobBuilder || e.MSBlobBuilder, m = /^data:((.*?)(;charset=.*?)?)(;base64)?,/, n = (i || o) && e.atob && e.ArrayBuffer && e.Uint8Array && function(c) {
      var u, f, s, h, p, l, w, g, y;
      if (u = c.match(m), !u)
        throw new Error("invalid data URI");
      for (f = u[2] ? u[1] : "text/plain" + (u[3] || ";charset=US-ASCII"), s = !!u[4], h = c.slice(u[0].length), s ? p = atob(h) : p = decodeURIComponent(h), l = new ArrayBuffer(p.length), w = new Uint8Array(l), g = 0; g < p.length; g += 1)
        w[g] = p.charCodeAt(g);
      return i ? new Blob([r ? w : l], {
        type: f
      }) : (y = new o(), y.append(l), y.getBlob(f));
    };
    e.HTMLCanvasElement && !a.toBlob && (a.mozGetAsFile ? a.toBlob = function(c, u, f) {
      var s = this;
      setTimeout(function() {
        f && a.toDataURL && n ? c(n(s.toDataURL(u, f))) : c(s.mozGetAsFile("blob", u));
      });
    } : a.toDataURL && n && (a.msToBlob ? a.toBlob = function(c, u, f) {
      var s = this;
      setTimeout(function() {
        (u && u !== "image/png" || f) && a.toDataURL && n ? c(n(s.toDataURL(u, f))) : c(s.msToBlob(u));
      });
    } : a.toBlob = function(c, u, f) {
      var s = this;
      setTimeout(function() {
        c(n(s.toDataURL(u, f)));
      });
    })), t.exports ? t.exports = n : e.dataURLtoBlob = n;
  }(window);
})(Te);
var Be = Te.exports, tt = function(e) {
  return typeof Blob > "u" ? !1 : e instanceof Blob || Object.prototype.toString.call(e) === "[object Blob]";
}, Ae = {
  /**
   * Indicates if output the original image instead of the compressed one
   * when the size of the compressed image is greater than the original one's
   * @type {boolean}
   */
  strict: !0,
  /**
   * Indicates if read the image's Exif Orientation information,
   * and then rotate or flip the image automatically.
   * @type {boolean}
   */
  checkOrientation: !0,
  /**
   * Indicates if retain the image's Exif information after compressed.
   * @type {boolean}
  */
  retainExif: !1,
  /**
   * The max width of the output image.
   * @type {number}
   */
  maxWidth: 1 / 0,
  /**
   * The max height of the output image.
   * @type {number}
   */
  maxHeight: 1 / 0,
  /**
   * The min width of the output image.
   * @type {number}
   */
  minWidth: 0,
  /**
   * The min height of the output image.
   * @type {number}
   */
  minHeight: 0,
  /**
   * The width of the output image.
   * If not specified, the natural width of the source image will be used.
   * @type {number}
   */
  width: void 0,
  /**
   * The height of the output image.
   * If not specified, the natural height of the source image will be used.
   * @type {number}
   */
  height: void 0,
  /**
   * Sets how the size of the image should be resized to the container
   * specified by the `width` and `height` options.
   * @type {string}
   */
  resize: "none",
  /**
   * The quality of the output image.
   * It must be a number between `0` and `1`,
   * and only available for `image/jpeg` and `image/webp` images.
   * Check out {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob canvas.toBlob}.
   * @type {number}
   */
  quality: 0.8,
  /**
   * The mime type of the output image.
   * By default, the original mime type of the source image file will be used.
   * @type {string}
   */
  mimeType: "auto",
  /**
   * Files whose file type is included in this list,
   * and whose file size exceeds the `convertSize` value will be converted to JPEGs.
   * @type {string｜Array}
   */
  convertTypes: ["image/png"],
  /**
   * PNG files over this size (5 MB by default) will be converted to JPEGs.
   * To disable this, just set the value to `Infinity`.
   * @type {number}
   */
  convertSize: 5e6,
  /**
   * The hook function to execute before draw the image into the canvas for compression.
   * @type {Function}
   * @param {CanvasRenderingContext2D} context - The 2d rendering context of the canvas.
   * @param {HTMLCanvasElement} canvas - The canvas for compression.
   * @example
   * function (context, canvas) {
   *   context.fillStyle = '#fff';
   * }
   */
  beforeDraw: null,
  /**
   * The hook function to execute after drew the image into the canvas for compression.
   * @type {Function}
   * @param {CanvasRenderingContext2D} context - The 2d rendering context of the canvas.
   * @param {HTMLCanvasElement} canvas - The canvas for compression.
   * @example
   * function (context, canvas) {
   *   context.filter = 'grayscale(100%)';
   * }
   */
  drew: null,
  /**
   * The hook function to execute when success to compress the image.
   * @type {Function}
   * @param {File} file - The compressed image File object.
   * @example
   * function (file) {
   *   console.log(file);
   * }
   */
  success: null,
  /**
   * The hook function to execute when fail to compress the image.
   * @type {Function}
   * @param {Error} err - An Error object.
   * @example
   * function (err) {
   *   console.log(err.message);
   * }
   */
  error: null
}, at = typeof window < "u" && typeof window.document < "u", U = at ? window : {}, N = function(e) {
  return e > 0 && e < 1 / 0;
}, it = Array.prototype.slice;
function Z(t) {
  return Array.from ? Array.from(t) : it.call(t);
}
var rt = /^image\/.+$/;
function Q(t) {
  return rt.test(t);
}
function ot(t) {
  var e = Q(t) ? t.substr(6) : "";
  return e === "jpeg" && (e = "jpg"), ".".concat(e);
}
var Me = String.fromCharCode;
function nt(t, e, a) {
  var i = "", r;
  for (a += e, r = e; r < a; r += 1)
    i += Me(t.getUint8(r));
  return i;
}
var st = U.btoa;
function ke(t, e) {
  for (var a = [], i = 8192, r = new Uint8Array(t); r.length > 0; )
    a.push(Me.apply(null, Z(r.subarray(0, i)))), r = r.subarray(i);
  return "data:".concat(e, ";base64,").concat(st(a.join("")));
}
function lt(t) {
  var e = new DataView(t), a;
  try {
    var i, r, o;
    if (e.getUint8(0) === 255 && e.getUint8(1) === 216)
      for (var m = e.byteLength, n = 2; n + 1 < m; ) {
        if (e.getUint8(n) === 255 && e.getUint8(n + 1) === 225) {
          r = n;
          break;
        }
        n += 1;
      }
    if (r) {
      var c = r + 4, u = r + 10;
      if (nt(e, c, 4) === "Exif") {
        var f = e.getUint16(u);
        if (i = f === 18761, (i || f === 19789) && e.getUint16(u + 2, i) === 42) {
          var s = e.getUint32(u + 4, i);
          s >= 8 && (o = u + s);
        }
      }
    }
    if (o) {
      var h = e.getUint16(o, i), p, l;
      for (l = 0; l < h; l += 1)
        if (p = o + l * 12 + 2, e.getUint16(p, i) === 274) {
          p += 8, a = e.getUint16(p, i), e.setUint16(p, 1, i);
          break;
        }
    }
  } catch {
    a = 1;
  }
  return a;
}
function ct(t) {
  var e = 0, a = 1, i = 1;
  switch (t) {
    case 2:
      a = -1;
      break;
    case 3:
      e = -180;
      break;
    case 4:
      i = -1;
      break;
    case 5:
      e = 90, i = -1;
      break;
    case 6:
      e = 90;
      break;
    case 7:
      e = 90, a = -1;
      break;
    case 8:
      e = -90;
      break;
  }
  return {
    rotate: e,
    scaleX: a,
    scaleY: i
  };
}
var ut = /\.\d*(?:0|9){12}\d*$/;
function Ee(t) {
  var e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1e11;
  return ut.test(t) ? Math.round(t * e) / e : t;
}
function I(t) {
  var e = t.aspectRatio, a = t.height, i = t.width, r = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "none", o = N(i), m = N(a);
  if (o && m) {
    var n = a * e;
    (r === "contain" || r === "none") && n > i || r === "cover" && n < i ? a = i / e : i = a * e;
  } else o ? a = i / e : m && (i = a * e);
  return {
    width: i,
    height: a
  };
}
function mt(t) {
  for (var e = Z(new Uint8Array(t)), a = e.length, i = [], r = 0; r + 3 < a; ) {
    var o = e[r], m = e[r + 1];
    if (o === 255 && m === 218)
      break;
    if (o === 255 && m === 216)
      r += 2;
    else {
      var n = e[r + 2] * 256 + e[r + 3], c = r + n + 2, u = e.slice(r, c);
      i.push(u), r = c;
    }
  }
  return i.reduce(function(f, s) {
    return s[0] === 255 && s[1] === 225 ? f.concat(s) : f;
  }, []);
}
function ft(t, e) {
  var a = Z(new Uint8Array(t));
  if (a[2] !== 255 || a[3] !== 224)
    return t;
  var i = a[4] * 256 + a[5], r = [255, 216].concat(e, a.slice(4 + i));
  return new Uint8Array(r);
}
var dt = U.ArrayBuffer, J = U.FileReader, D = U.URL || U.webkitURL, pt = /\.\w+$/, ht = U.Compressor, gt = /* @__PURE__ */ function() {
  function t(e, a) {
    Je(this, t), this.file = e, this.exif = [], this.image = new Image(), this.options = j(j({}, Ae), a), this.aborted = !1, this.result = null, this.init();
  }
  return Qe(t, [{
    key: "init",
    value: function() {
      var a = this, i = this.file, r = this.options;
      if (!tt(i)) {
        this.fail(new Error("The first argument must be a File or Blob object."));
        return;
      }
      var o = i.type;
      if (!Q(o)) {
        this.fail(new Error("The first argument must be an image File or Blob object."));
        return;
      }
      if (!D || !J) {
        this.fail(new Error("The current browser does not support image compression."));
        return;
      }
      dt || (r.checkOrientation = !1, r.retainExif = !1);
      var m = o === "image/jpeg", n = m && r.checkOrientation, c = m && r.retainExif;
      if (D && !n && !c)
        this.load({
          url: D.createObjectURL(i)
        });
      else {
        var u = new J();
        this.reader = u, u.onload = function(f) {
          var s = f.target, h = s.result, p = {}, l = 1;
          n && (l = lt(h), l > 1 && _(p, ct(l))), c && (a.exif = mt(h)), n || c ? !D || l > 1 ? p.url = ke(h, o) : p.url = D.createObjectURL(i) : p.url = h, a.load(p);
        }, u.onabort = function() {
          a.fail(new Error("Aborted to read the image with FileReader."));
        }, u.onerror = function() {
          a.fail(new Error("Failed to read the image with FileReader."));
        }, u.onloadend = function() {
          a.reader = null;
        }, n || c ? u.readAsArrayBuffer(i) : u.readAsDataURL(i);
      }
    }
  }, {
    key: "load",
    value: function(a) {
      var i = this, r = this.file, o = this.image;
      o.onload = function() {
        i.draw(j(j({}, a), {}, {
          naturalWidth: o.naturalWidth,
          naturalHeight: o.naturalHeight
        }));
      }, o.onabort = function() {
        i.fail(new Error("Aborted to load the image."));
      }, o.onerror = function() {
        i.fail(new Error("Failed to load the image."));
      }, U.navigator && /(?:iPad|iPhone|iPod).*?AppleWebKit/i.test(U.navigator.userAgent) && (o.crossOrigin = "anonymous"), o.alt = r.name, o.src = a.url;
    }
  }, {
    key: "draw",
    value: function(a) {
      var i = this, r = a.naturalWidth, o = a.naturalHeight, m = a.rotate, n = m === void 0 ? 0 : m, c = a.scaleX, u = c === void 0 ? 1 : c, f = a.scaleY, s = f === void 0 ? 1 : f, h = this.file, p = this.image, l = this.options, w = document.createElement("canvas"), g = w.getContext("2d"), y = Math.abs(n) % 180 === 90, C = (l.resize === "contain" || l.resize === "cover") && N(l.width) && N(l.height), x = Math.max(l.maxWidth, 0) || 1 / 0, B = Math.max(l.maxHeight, 0) || 1 / 0, A = Math.max(l.minWidth, 0) || 0, k = Math.max(l.minHeight, 0) || 0, E = r / o, b = l.width, d = l.height;
      if (y) {
        var P = [B, x];
        x = P[0], B = P[1];
        var S = [k, A];
        A = S[0], k = S[1];
        var ee = [d, b];
        b = ee[0], d = ee[1];
      }
      C && (E = b / d);
      var te = I({
        aspectRatio: E,
        width: x,
        height: B
      }, "contain");
      x = te.width, B = te.height;
      var ae = I({
        aspectRatio: E,
        width: A,
        height: k
      }, "cover");
      if (A = ae.width, k = ae.height, C) {
        var ie = I({
          aspectRatio: E,
          width: b,
          height: d
        }, l.resize);
        b = ie.width, d = ie.height;
      } else {
        var re = I({
          aspectRatio: E,
          width: b,
          height: d
        }), oe = re.width;
        b = oe === void 0 ? r : oe;
        var ne = re.height;
        d = ne === void 0 ? o : ne;
      }
      b = Math.floor(Ee(Math.min(Math.max(b, A), x))), d = Math.floor(Ee(Math.min(Math.max(d, k), B)));
      var Oe = -b / 2, Re = -d / 2, Fe = b, ze = d, W = [];
      if (C) {
        var se = 0, le = 0, H = r, $ = o, ce = I({
          aspectRatio: E,
          width: r,
          height: o
        }, {
          contain: "cover",
          cover: "contain"
        }[l.resize]);
        H = ce.width, $ = ce.height, se = (r - H) / 2, le = (o - $) / 2, W.push(se, le, H, $);
      }
      if (W.push(Oe, Re, Fe, ze), y) {
        var ue = [d, b];
        b = ue[0], d = ue[1];
      }
      w.width = b, w.height = d, Q(l.mimeType) || (l.mimeType = h.type);
      var me = "transparent";
      h.size > l.convertSize && l.convertTypes.indexOf(l.mimeType) >= 0 && (l.mimeType = "image/jpeg");
      var fe = l.mimeType === "image/jpeg";
      if (fe && (me = "#fff"), g.fillStyle = me, g.fillRect(0, 0, b, d), l.beforeDraw && l.beforeDraw.call(this, g, w), !this.aborted && (g.save(), g.translate(b / 2, d / 2), g.rotate(n * Math.PI / 180), g.scale(u, s), g.drawImage.apply(g, [p].concat(W)), g.restore(), l.drew && l.drew.call(this, g, w), !this.aborted)) {
        var de = function(R) {
          if (!i.aborted) {
            var pe = function(F) {
              return i.done({
                naturalWidth: r,
                naturalHeight: o,
                result: F
              });
            };
            if (R && fe && l.retainExif && i.exif && i.exif.length > 0) {
              var he = function(F) {
                return pe(Be(ke(ft(F, i.exif), l.mimeType)));
              };
              if (R.arrayBuffer)
                R.arrayBuffer().then(he).catch(function() {
                  i.fail(new Error("Failed to read the compressed image with Blob.arrayBuffer()."));
                });
              else {
                var T = new J();
                i.reader = T, T.onload = function(V) {
                  var F = V.target;
                  he(F.result);
                }, T.onabort = function() {
                  i.fail(new Error("Aborted to read the compressed image with FileReader."));
                }, T.onerror = function() {
                  i.fail(new Error("Failed to read the compressed image with FileReader."));
                }, T.onloadend = function() {
                  i.reader = null;
                }, T.readAsArrayBuffer(R);
              }
            } else
              pe(R);
          }
        };
        w.toBlob ? w.toBlob(de, l.mimeType, l.quality) : de(Be(w.toDataURL(l.mimeType, l.quality)));
      }
    }
  }, {
    key: "done",
    value: function(a) {
      var i = a.naturalWidth, r = a.naturalHeight, o = a.result, m = this.file, n = this.image, c = this.options;
      if (D && n.src.indexOf("blob:") === 0 && D.revokeObjectURL(n.src), o)
        if (c.strict && !c.retainExif && o.size > m.size && c.mimeType === m.type && !(c.width > i || c.height > r || c.minWidth > i || c.minHeight > r || c.maxWidth < i || c.maxHeight < r))
          o = m;
        else {
          var u = /* @__PURE__ */ new Date();
          o.lastModified = u.getTime(), o.lastModifiedDate = u, o.name = m.name, o.name && o.type !== m.type && (o.name = o.name.replace(pt, ot(o.type)));
        }
      else
        o = m;
      this.result = o, c.success && c.success.call(this, o);
    }
  }, {
    key: "fail",
    value: function(a) {
      var i = this.options;
      if (i.error)
        i.error.call(this, a);
      else
        throw a;
    }
  }, {
    key: "abort",
    value: function() {
      this.aborted || (this.aborted = !0, this.reader ? this.reader.abort() : this.image.complete ? this.fail(new Error("The compression process has been aborted.")) : (this.image.onload = null, this.image.onabort()));
    }
    /**
     * Get the no conflict compressor class.
     * @returns {Compressor} The compressor class.
     */
  }], [{
    key: "noConflict",
    value: function() {
      return window.Compressor = ht, t;
    }
    /**
     * Change the default options.
     * @param {Object} options - The new default options.
     */
  }, {
    key: "setDefaults",
    value: function(a) {
      _(Ae, a);
    }
  }]), t;
}();
const vt = (t, e) => new Promise((a, i) => {
  if (t.size <= e)
    return t;
  const r = e / t.size, o = Math.max(0.5, Math.min(0.9, 0.8 * r)), m = Math.max(800, Math.min(1920, 1920 * Math.sqrt(r)));
  Ue(t, o, m, m, (n) => {
    n.size <= e ? a(n) : (console.log("第一次压缩后仍大于5MB，进行二次压缩"), Ue(
      n,
      Math.max(0.4, o - 0.2),
      // 降低质量
      Math.max(640, m * 0.8),
      // 缩小尺寸
      Math.max(640, m * 0.8),
      a,
      i,
      t
      // 传递原始文件用于错误处理
    ));
  }, i, t);
}), Ue = (t, e, a, i, r, o, m) => {
  new gt(t, {
    quality: e,
    maxWidth: a,
    maxHeight: i,
    convertSize: 1 / 0,
    success(n) {
      try {
        const c = new File([n], t.name, {
          type: n.type || t.type,
          lastModified: Date.now()
        });
        r(c);
      } catch (c) {
        o({
          message: "文件转换失败",
          error: c,
          original: m || t
        });
      }
    },
    error(n) {
      o({
        message: "图片压缩失败",
        error: n,
        original: m || t
      });
    }
  });
}, yt = (t, e) => {
  const a = we(t, "status"), { size2B: i } = qe(), r = we(t, "isOverMaxLimitCompressImg"), o = [".mp4", ".avi", ".mkv", ".mov", ".wmv", ".flv", ".mpeg", ".webm"], m = [".mp3", ".wav", ".aac", ".flac", ".ogg", ".alff", ".wma", ".m4a"], n = X(() => {
    var h;
    let s = t.accept ? (h = t.accept) == null ? void 0 : h.split(",") : [];
    return s.includes("image/jpg") && !s.includes("image/jpeg") && s.push("image/jpeg"), s.includes(".jpg") && !s.includes(".jpeg") && s.push(".jpeg"), t.acceptVideo && (s = [...s, ...o]), t.acceptAudio && (s = [...s, ...m]), s.join(",");
  }), c = X(() => a.value === "uploading"), u = X(() => a.value === "error");
  return { isAccept: n, uploadStatus: a, loading: c, errored: u, beforeupload: (s) => {
    var l, w, g;
    if (t.maxSize) {
      const { finalSize: y, sizeText: C } = i(t.maxSize);
      if (s.size > y && !r.value) {
        const x = t.acceptAudio || t.acceptVideo ? "das-ui-import-upload-key4" : "das-ui-import-upload-key3", B = ge.value === "zh-CN" ? "、" : ", ", A = ve(
          x,
          C,
          ((g = (w = (l = n.value) == null ? void 0 : l.toUpperCase()) == null ? void 0 : w.replaceAll(".", "")) == null ? void 0 : g.replaceAll(",", B)) ?? ""
        ).value, k = t.errorMessage || A;
        return be.warning(k), e("update:status", "normal"), a.value = "normal", !1;
      }
    }
    const h = [
      "image/jpeg",
      "image/png",
      "image/webp",
      "image/gif",
      "image/bmp",
      "image/tiff",
      "image/svg+xml"
    ], p = async () => {
      a.value = "uploading";
      let y = s;
      if (t.maxSize) {
        const { finalSize: C } = i(t.maxSize);
        if (s.size > C && r.value && h.includes(s.type))
          try {
            y = await vt(s, C), console.log(
              "压缩成功:",
              `原始大小: ${(s.size / 1024 / 1024).toFixed(2)}MB →`,
              `压缩后: ${(y.size / 1024 / 1024).toFixed(2)}MB`
            );
          } catch (x) {
            console.log("压缩失败，使用原始文件"), y = (x == null ? void 0 : x.original) || s;
          }
      }
      return e("update:status", "uploading"), e("image-upload", y), !1;
    };
    if (t.customCheck) {
      const y = t.customCheck(s);
      if (y instanceof Promise)
        return new Promise(async (C, x) => {
          let B;
          try {
            B = await y.then();
          } catch {
            B = !1;
          }
          B ? p() : x(!1);
        });
      if (!y)
        return e("update:status", "normal"), a.value = "normal", !1;
    } else if (n.value) {
      const y = n.value.split(",").filter((d) => d.trim().startsWith(".")).map((d) => d.trim()), C = n.value.split(",").filter((d) => !d.trim().startsWith(".")).map((d) => d.trim()), x = Ye(s.name), B = y.includes(x);
      let A = C.includes("image/*") && s.type.split("/")[0].trim() === "image", k = C.includes("video/*") && s.type.split("/")[0].trim() === "video", E = C.includes("audio/*") && s.type.split("/")[0].trim() === "audio", b = C.includes(s.type) || A || k || E;
      if (!B && !b) {
        const d = t.acceptAudio || t.acceptVideo ? "das-ui-import-upload-key2" : "das-ui-import-upload-key1", P = ge.value === "zh-CN" ? "、" : ", ", S = t.errorMessage || ve(d, n.value.toUpperCase().replaceAll(".", "").replaceAll(",", P)).value;
        return be.warning(S), !1;
      }
    }
    return p();
  } };
}, bt = { class: "das-ui-image-upload" }, wt = { class: "das-ui-image-upload-dragger-context" }, xt = { class: "text" }, Ct = { class: "das-ui-image-upload-error-container" }, Bt = { class: "tips-container" }, At = { class: "text" }, kt = /* @__PURE__ */ je({
  __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 },
    isOverMaxLimitCompressImg: { type: Boolean, default: !1 }
  },
  emits: ["update:status", "image-upload"],
  setup(t, { emit: e }) {
    const a = t, i = e, { isAccept: r, uploadStatus: o, loading: m, errored: n, beforeupload: c } = yt(a, i);
    return (u, f) => (_e(), Le("div", bt, [
      ye(" 图片上传组件 "),
      K(M(v(Ve), {
        class: Ne([{ "loading-border": v(m) }]),
        type: "component",
        spinning: v(m)
      }, {
        default: O(() => [
          M(v(He), {
            class: "das-ui-image-upload-dragger",
            accept: v(r),
            "max-count": u.maxCount,
            "before-upload": v(c),
            openFileDialogOnClick: u.openFileDialogOnClick
          }, {
            itemRender: O(({ file: s, actions: h }) => f[0] || (f[0] = [])),
            default: O(() => [
              K(z(
                "div",
                wt,
                [
                  M(v(Xe), {
                    iconColor: v(L)("--das-ui-color-secondary")
                  }, null, 8, ["iconColor"]),
                  z(
                    "div",
                    xt,
                    Y(u.message || v(G)("das-image-upload-text")),
                    1
                    /* TEXT */
                  )
                ],
                512
                /* NEED_PATCH */
              ), [
                [q, v(o) === "normal"]
              ])
            ]),
            _: 1
            /* STABLE */
          }, 8, ["accept", "max-count", "before-upload", "openFileDialogOnClick"])
        ]),
        _: 1
        /* STABLE */
      }, 8, ["class", "spinning"]), [
        [q, !v(n)]
      ]),
      ye(" 错误状态 "),
      K(z(
        "div",
        Ct,
        [
          z("div", Bt, [
            M(v(Ke), {
              iconColor: v(L)("--das-ui-color-danger"),
              size: "small"
            }, null, 8, ["iconColor"]),
            z(
              "div",
              At,
              Y(v(G)("das-image-upload-fail")),
              1
              /* TEXT */
            )
          ]),
          M(v($e), {
            accept: v(r),
            "before-upload": v(c),
            "max-count": u.maxCount,
            openFileDialogOnClick: u.openFileDialogOnClick
          }, {
            itemRender: O(({ file: s, actions: h }) => f[1] || (f[1] = [])),
            default: O(() => [
              M(v(Ge), {
                "btn-type": "primary-text",
                block: ""
              }, {
                default: O(() => [
                  We(
                    Y(v(G)("das-image-upload-reupload")),
                    1
                    /* TEXT */
                  )
                ]),
                _: 1
                /* STABLE */
              })
            ]),
            _: 1
            /* STABLE */
          }, 8, ["accept", "before-upload", "max-count", "openFileDialogOnClick"])
        ],
        512
        /* NEED_PATCH */
      ), [
        [q, v(n)]
      ])
    ]));
  }
}), Et = (t, e) => {
  const a = t.__vccOpts || t;
  for (const [i, r] of e)
    a[i] = r;
  return a;
}, Ut = /* @__PURE__ */ Et(kt, [["__scopeId", "data-v-29473013"]]), Dt = {
  "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" }
}, Tt = {
  "--das-ui-image-upload-bgcolor": { light: "#FAFAFA" },
  "--das-ui-image-upload-border-color": { light: "#E5E5E5" },
  "--das-ui-image-upload-bgcolor-hover": { light: L("--das-ui-color-primary-level1") },
  "--das-ui-image-upload-border-color-hover": { light: "#5582F3" },
  "--das-ui-image-upload-border-color-error": { light: L("--das-ui-color-danger-level2") }
}, Vt = Ie(Ut);
Pe(Dt);
Se(Tt);
export {
  Vt as DasImageUpload,
  Vt as default
};
