import { reactive as oe, defineComponent as he, inject as ve, ref as X, computed as ee, watch as re, onMounted as ke, nextTick as ie, openBlock as u, createElementBlock as f, createElementVNode as F, withModifiers as V, unref as J, normalizeClass as te, renderSlot as me, toDisplayString as de, Fragment as W, createVNode as be, renderList as Ce, createBlock as fe, Transition as Me, withCtx as ge, createCommentVNode as Te, useAttrs as Be, provide as He } from "vue";
import { C as o } from "./base-PQGakkrl.js";
import { C as Re } from "./index-BnerInzC.js";
import { _ as ze } from "./Index.vue_vue_type_script_setup_true_lang-Cuv5NgcY.js";
import { u as xe } from "./language-DxTlvFs2.js";
import De from "../Element/ClButton.js";
const M = {
  format: {
    img: ["jpg", "jpe", "jpeg", "png", "gif", "bmp", "ico"],
    video: [
      "mp4",
      "rmvb",
      "3gp",
      "avi",
      "asf",
      "asf",
      "dv",
      "mov",
      "mpg4",
      "mpeg",
      "mpg",
      "wm",
      "wmx",
      "flv",
      "mkv",
      "mp4a",
      "rm",
      "wmv",
      "swf",
      "swfl"
    ],
    audio: ["mp3", "ogg", "wav", "wma", "mid", "ra", "ram"],
    zip: ["rar", "zip"],
    excel: ["xls", "xlsx", "csv"],
    pdf: ["pdf"],
    txt: ["txt"],
    doc: ["doc", "docx"]
  },
  icon: {
    img: "clIconFont clIcon-image",
    video: "clIconFont clIcon-video",
    audio: "clIconFont clIcon-music",
    txt: "clIconFont clIcon-text",
    zip: "clIconFont clIcon-zip",
    excel: "clIconFont clIcon-excel",
    pdf: "clIconFont clIcon-pdf",
    doc: "clIconFont clIcon-word",
    default: "clIconFont clIcon-file"
  },
  suffix: {
    jpg: ["jpg", "jpe", "jpeg"],
    jpe: ["jpg", "jpe", "jpeg"],
    jpeg: ["jpg", "jpe", "jpeg"],
    png: ["png"],
    gif: ["gif"],
    bmp: ["bmp"],
    ico: ["ico"],
    mp4: ["mp4"],
    rmvb: ["rmvb"],
    "3gp": ["3gp"],
    avi: ["avi"],
    asf: ["asf"],
    dv: ["dv"],
    mov: ["mov"],
    mpg4: ["mpg4"],
    mpeg: ["mpeg"],
    mpg: ["mpg"],
    wm: ["wm"],
    wmx: ["wmx"],
    flv: ["flv"],
    mkv: ["mkv"],
    mp4a: ["mp4a"],
    rm: ["rm"],
    wmv: ["wmv"],
    swf: ["swf"],
    swfl: ["swfl"],
    mp3: ["mp3"],
    ogg: ["ogg"],
    wav: ["wav"],
    wma: ["wma"],
    mid: ["mid"],
    ra: ["ra"],
    ram: ["ram"],
    rar: ["rar"],
    zip: ["zip"],
    txt: ["txt"],
    xls: ["xls", "xlsx", "csv"],
    xlsx: ["xls", "xlsx", "csv"],
    csv: ["xls", "xlsx", "csv"],
    pdf: ["pdf"],
    doc: ["doc", "docx"]
  },
  mime: {
    jpg: ["image/jpg", "image/jpeg", "image/pjpeg"],
    jpe: ["image/jpg", "image/jpeg", "image/pjpeg"],
    jpeg: ["image/jpg", "image/jpeg", "image/pjpeg"],
    png: ["image/png", "image/x-png"],
    gif: ["image/gif"],
    bmp: ["image/bmp"],
    ico: ["ico"],
    mp4: ["video/mp4"],
    rmvb: ["audio/x-pn-realaudio"],
    "3gp": ["video/3gpp"],
    avi: ["video/x-msvideo"],
    asf: ["video/x-ms-asf"],
    dv: ["video/x-dv"],
    mov: ["video/quicktime"],
    mpg4: ["video/mp4"],
    mpeg: ["video/mpeg"],
    mpg: ["video/mpeg"],
    wm: ["video/x-ms-wmv"],
    wmx: ["video/x-ms-wmx"],
    flv: ["video/x-flv"],
    mkv: ["video/x-matroska"],
    mp4a: ["audio/mp4"],
    rm: ["audio/x-pn-realaudio"],
    wmv: ["audio/x-ms-wmv"],
    swf: ["application/x-shockwave-flash"],
    swfl: ["application/x-shockwave-flash"],
    mp3: ["audio/mpeg"],
    ogg: ["audio/ogg"],
    wav: ["audio/wav"],
    wma: ["audio/x-ms-wma"],
    mid: ["audio/midi"],
    ra: ["audio/x-pn-realaudio"],
    ram: ["audio/x-pn-realaudio"],
    rar: ["application/x-rar-compressed"],
    zip: ["application/zip", "application/x-zip-compressed"],
    txt: ["text/plain"],
    xls: ["application/vnd.ms-excel", "application/wps-office.xls"],
    xlsx: ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/wps-office.xlsx"],
    csv: ["text/csv"],
    pdf: ["application/pdf"],
    doc: ["application/msword"],
    docx: ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"]
  },
  getFormatGroup: (t) => {
    let c = [];
    return o.isEmpty(t) || (t.split(",").forEach((i) => {
      for (const [h, S] of Object.entries(M.format))
        o.isExistValue(S, i.toLocaleLowerCase()) && c.push(h);
    }), c = o.getArrUnique(c)), c;
  },
  getIcon: (t) => {
    let c = "";
    return o.isEmpty(t) ? c = M.icon.default : c = o.isExistJsonKey(M.icon, t) ? M.icon[t] : M.icon.default, c;
  },
  getSuffix: (t) => {
    let c = [];
    return o.isEmpty(t) || (t.forEach((r) => {
      const i = M.suffix[r.toLocaleLowerCase()];
      o.isUndefined(i) || (c = c.concat(i));
    }), o.isEmpty(c) && (c = t)), c = o.getArrUnique(c), c;
  },
  getRegexBySuffix: (t) => {
    if (o.isEmpty(t))
      return null;
    const c = `\\.(?:${t.join("|")})$`;
    return new RegExp(c, "i");
  },
  getMime: (t) => {
    let c = [];
    return o.isEmpty(t) || t.forEach((r) => {
      const i = M.mime[r];
      o.isUndefined(i) || (c = c.concat(i));
    }), c = o.getArrUnique(c), c;
  },
  getRegexByMime: (t) => {
    if (o.isEmpty(t))
      return null;
    const c = `^(?:${t.join("|").replace(/\//g, "\\/")})$`;
    return new RegExp(c, "i");
  },
  getImageThumbnail: (t, c, r) => {
    let i = null;
    try {
      const h = document.createElement("canvas");
      h.width = c, h.height = r, h.getContext("2d").drawImage(t, 0, 0, t.width, t.height, 0, 0, c, r), i = h.toDataURL("image/gif");
    } catch {
      i = null;
    }
    return i;
  }
}, Fe = (t, c) => {
  let r = t;
  const i = oe({
    mime: [],
    suffix: [],
    isCheckImgWH: !1
  });
  let h = null;
  const S = (m) => {
    r = o.getJsonMerge(r, m), I();
  }, I = () => {
    const m = o.isEmpty(r.checkFormat) ? [] : M.getSuffix(r.checkFormat.split(",")), g = M.getMime(m), w = !o.isEmpty(r.checkWidth) && !o.isEmpty(r.checkHeight);
    i.mime = g, i.suffix = m, i.isCheckImgWH = w;
  }, R = (m) => {
    const g = M.getIcon(m);
    return {
      type: m,
      icon: g,
      isImage: m === "img",
      isVideo: m === "video",
      isAudio: m === "audio",
      isTxt: m === "txt",
      isZip: m === "zip"
    };
  }, B = (m, g) => {
    if (o.isUndefined(h)) {
      h = {};
      for (const [a, l] of Object.entries(M.format)) {
        const x = M.getSuffix(l), b = M.getSuffix(x), D = M.getRegexBySuffix(x), p = M.getRegexByMime(b);
        h[a] = { suffix: x, mime: b, regSuffix: D, regMime: p };
      }
    }
    let w = "";
    return Object.keys(h).forEach((a) => {
      if (w.length === 0) {
        const l = h[a];
        (l.regSuffix && l.regSuffix.test(m) || g && l.regMime && l.regMime.test(g)) && (w = a);
      }
    }), R(w);
  }, z = (m) => {
    const g = M.getFormatGroup(o.isEmpty(m) ? r.checkFormat : m), w = g.length === 1 ? g[0] : "";
    return R(w);
  }, P = (m) => {
    const g = m.substring(m.lastIndexOf("/") + 1);
    return B(g);
  }, q = (m, g) => new Promise((w, a) => {
    const l = document.createElement("img");
    l.onload = (x) => {
      const b = x.target.width, D = x.target.height;
      let p = b, k = D;
      g && g > 0 && (p > g || k > g) && (p > k ? (k = parseInt((g / p * k).toString(), 10), p = g) : (p = parseInt((g / k * p).toString(), 10), k = g));
      const y = x.target.src;
      w({ src: y, w: b, h: D, tw: p, th: k, isImage: !0 });
    }, l.onerror = () => {
      a(new Error("fail: temp create image"));
    }, l.src = m;
  }), K = (m, g) => {
    const w = o.isEmpty(r.checkWidth) ? 0 : parseInt(r.checkWidth, 10), a = o.isEmpty(r.checkHeight) ? 0 : parseInt(r.checkHeight, 10);
    let l = !0;
    switch (r.checkWHType) {
      case "greater":
        l = m >= w && g >= a;
        break;
      case "less":
        l = m <= w && g <= a;
        break;
      case "equal":
        l = m === w && g === a;
        break;
      default:
        l = !0;
        break;
    }
    return l;
  }, Z = (m, g) => new Promise((w, a) => {
    if (m instanceof File) {
      const l = new FileReader();
      l.onload = (x) => {
        q(x.target.result, g.maxWidth).then((b) => {
          (i.isCheckImgWH ? K(b.w, b.h) : !0) ? w(b) : a(new Error(c.value.checkImageWHLabel));
        }).catch((b) => {
          a(b);
        });
      }, l.onerror = () => {
        a(new Error("fail: new FileReader image onload()"));
      }, l.readAsDataURL(m);
    }
  }), A = async (m, g) => {
    let w = [];
    const a = [], l = [], x = M.getRegexBySuffix(i.suffix), b = M.getRegexByMime(i.mime), D = o.isEmpty(r.checkMinSize) ? null : parseInt(r.checkMinSize, 10) * 1024, p = o.isEmpty(r.checkMaxSize) ? null : parseInt(r.checkMaxSize, 10) * 1024, k = m.length;
    for (let y = 0; y < k; y += 1) {
      const E = [], T = m[y], H = { suffix: !1, mime: !1, size: !1 }, L = T.name;
      x && !x.test(L) && (H.suffix = !0);
      const _ = T.type;
      !o.isEmpty(_) && b && !b.test(_) && (H.mime = !0), D && T.size < D && (H.size = !0), p && T.size > p && (H.size = !0), (H.suffix || H.mime) && E.push(c.value.checkSuffixMimeLabel), H.size && E.push(c.value.checkSizeLabel);
      const j = B(L, _);
      let O = null;
      j.isImage && (O = await Z(T, g).catch((N) => {
        E.push(N.message);
      })), o.isUndefined(O) && (O = {}), O = o.getJsonMerge(O, j), O.fileName = L, O.file = T, E.length === 0 ? (a.push(T), l.push(O)) : k === 1 ? w = E.map((N) => `${c.value.uploadFile} ${N}`) : w.push(`${L}:${E.join(",")}`);
    }
    return new Promise((y) => {
      setTimeout(() => {
        y({ errorMsg: w, passFiles: a, passFilesInfo: l, original: m });
      }, 200);
    });
  };
  return I(), {
    optBase: i,
    getTypeByFormat: z,
    getTypeByUrl: P,
    createTempImg: q,
    checkFile: A,
    setBaseOptions: S
  };
}, Ie = () => ({
  setFileInfo: (c, r) => {
    const i = r && r.fileUrl ? r.fileUrl : "", h = o.isEmpty(i);
    let S = "";
    h ? S = c.fileName : S = i.substr(i.lastIndexOf("/") + 1);
    let I = "", R = 0, B = 0;
    return c.isImage && (I = h ? c.src : i, R = c.tw || 0, B = c.th || 0), { name: S, url: i, imgSrc: I, imgWidth: R, imgHeight: B };
  }
}), Ee = () => {
  const t = (r, i) => {
    window.open(r);
  };
  return {
    downloadHref: t,
    downloadBlob: (r) => {
      if (!o.isEmpty(r)) {
        const i = r.lastIndexOf("/"), h = r.substring(i + 1), S = r.replace(/\\/g, "/"), I = new XMLHttpRequest();
        I.open("GET", S, !0), I.responseType = "blob", I.onload = () => {
          if (I.status === 200) {
            const R = window.URL || window.webkitURL || window, B = new Blob([I.response]), z = document.createElementNS("http://www.w3.org/1999/xhtml", "a");
            z.href = R.createObjectURL(B), z.download = h, z.click();
          }
        }, I.onerror = () => {
          t(r);
        }, I.send();
      }
    }
  };
}, Oe = ["for"], $e = ["id", "name", "accept"], We = ["id", "name"], je = { class: "fileUpload-label" }, Pe = {
  key: 0,
  class: "fileUpload-img"
}, Ne = { class: "fileUpload-img-container" }, Le = ["src", "width", "height"], _e = { class: "file-complete-img-msg" }, Ve = ["title"], qe = {
  key: 1,
  class: "fileUpload-video"
}, Ae = ["src"], Ge = ["title"], Je = {
  key: 2,
  class: "fileUpload-file"
}, Ke = ["title"], Xe = {
  key: 0,
  class: "fileUpload-load"
}, Ze = /* @__PURE__ */ he({
  name: "ClFileUploadDefault",
  __name: "Default",
  props: {
    value: String,
    name: String,
    isDisabled: {
      type: Boolean,
      default: !1
    },
    defaultHoverTitle: String,
    checkFormat: String,
    checkMinSize: [String, Number],
    checkMaxSize: [String, Number],
    checkWidth: [String, Number],
    checkHeight: [String, Number],
    checkWHType: String,
    isServerCallback: Boolean,
    isShowPreview: {
      type: Boolean,
      default: !0
    },
    isShowDownload: {
      type: Boolean,
      default: !0
    }
  },
  emits: ["onChange", "onError", "onRemove", "onPreview", "onSaveFile"],
  setup(t, { expose: c, emit: r }) {
    const i = t, h = r, { optPageLanguage: S, getPageLanguage: I } = xe();
    I("fileUpload");
    const R = ve("$FileuploadTop"), { setFileInfo: B } = Ie(), { optBase: z, getTypeByFormat: P, getTypeByUrl: q, createTempImg: K, checkFile: Z, setBaseOptions: A } = Fe(
      R.getFileCheckInfo(),
      S
    ), { downloadBlob: m, downloadHref: g } = Ee(), w = X(null), a = oe({
      isImage: !1,
      isVideo: !1,
      icon: "",
      completeMsgTxt: "",
      isInitFileInput: !0,
      runOperateType: "init"
    }), l = oe({ name: "", url: "", imgSrc: "", imgWidth: 0, imgHeight: 0 }), x = {
      file: null
    }, b = ee(() => {
      let e = i.name;
      return o.isEmpty(e) && (e = `fileUpload_${o.getRandom(8)}`), e;
    }), D = ee(() => {
      const e = {
        "fileUpload-icon": !0
      };
      return a.icon && a.icon.length > 0 && a.icon.split(" ").forEach((d) => {
        o.isEmpty(d) || (e[d] = !0);
      }), e;
    }), p = ee(() => ({
      "fileUpload-wait": !0,
      "fileUpload-disabled": i.isDisabled
    })), k = ee(() => ({
      "fileUpload-complete": !0,
      "fileUpload-disabled": i.isDisabled
    })), y = (e) => {
      h("onChange", e);
    }, E = (e) => {
      h("onError", e);
    }, T = () => {
      h("onRemove");
    }, H = (e, d) => {
      h("onPreview", e, d);
    }, L = (e, d) => {
      h("onSaveFile", e, d);
    }, _ = (e) => {
      a.isImage = e.isImage, a.isVideo = e.isVideo, a.icon = e.icon;
    }, j = (e) => {
      e !== "load" && (a.isInitFileInput = !0);
      let d = "";
      switch (e) {
        case "remove":
        case "clean": {
          d = "init";
          const U = P();
          _(U);
          break;
        }
        case "fail": {
          let U = !0;
          a.isImage ? (!o.isEmpty(l.url) || !o.isEmpty(l.imgSrc)) && (U = !1) : o.isEmpty(l.url) || (U = !1), d = U ? "init" : "complete";
          break;
        }
        default:
          d = e;
      }
      a.runOperateType = d;
    }, O = (e) => {
      for (const [d, U] of Object.entries(e))
        o.isUndefined(l[d]) || (l[d] = U);
      x.file = e.file;
    }, N = (e, d) => {
      _(e);
      const U = B(e, d);
      O(U), j("complete");
    }, le = () => {
      let e = null;
      return o.isEmpty(l.url) ? a.isImage && !o.isEmpty(l.imgSrc) ? e = l.imgSrc : e = x.file : e = l.url, o.isUndefined(e) && (e = ""), e;
    }, ne = (e) => {
      if (e.length > 0) {
        a.isInitFileInput = !1, j("load");
        const d = { maxWidth: w.value.clientWidth - 4 };
        Z(e, d).then((U) => {
          if (U.passFiles.length > 0) {
            const Y = U.passFiles[0], G = U.passFilesInfo[0];
            if (a.isImage && G.isImage)
              i.isServerCallback ? L(Y, G) : (N(G, {}), y(G.src));
            else if (i.isServerCallback)
              L(Y, G);
            else {
              const Se = {};
              if (G.isVideo) {
                const Ue = URL.createObjectURL(Y);
                Se.fileUrl = Ue;
              }
              N(G, Se), y(Y);
            }
          } else
            j("fail"), U.errorMsg.length > 0 && E(U.errorMsg);
        });
      }
    }, se = (e) => {
      if (o.isEmpty(e))
        ae();
      else {
        const d = q(e);
        if (a.isImage && d.isImage) {
          const U = w.value.clientWidth - 4;
          K(e, U).then((Y) => {
            const G = o.getJsonMerge(Y, d);
            N(G, { fileUrl: e });
          });
        } else
          N(d, { fileUrl: e });
      }
    }, ae = () => {
      O({ name: "", url: "", imgSrc: "", imgWidth: 0, imgHeight: 0 }), j("init");
    }, ce = () => {
      const e = o.isEmpty(i.value) ? P() : q(i.value);
      _(e);
    }, we = () => {
      let e = i.defaultHoverTitle;
      a.isImage && z.isCheckImgWH && o.isEmpty(e) ? e = `${i.checkWidth}x${i.checkHeight}` : e = "", a.completeMsgTxt = e;
    }, ue = () => {
      ce(), we(), se(i.value);
    };
    re(
      () => i.value,
      (e, d) => {
        if (e !== d) {
          const U = le();
          e !== U && (ce(), se(e));
        }
      }
    ), re(
      [
        () => i.checkFormat,
        () => i.checkWidth,
        () => i.checkHeight,
        () => i.checkWHType,
        () => i.checkMinSize,
        () => i.checkMaxSize
      ],
      () => {
        A(R.getFileCheckInfo()), ue();
      }
    ), ke(() => {
      ie(() => {
        ue();
      });
    });
    const ye = (e) => {
      e.preventDefault(), e.stopPropagation(), i.isDisabled || ne(e.dataTransfer.files);
    }, n = (e) => {
      ne(e.currentTarget.files);
    }, s = () => {
      O({ name: "", url: "", imgSrc: "", imgWidth: 0, imgHeight: 0 }), j("remove"), T();
    }, v = (e) => {
      const d = o.isEmpty(l.url) ? l.imgSrc : l.url;
      return H(d, "image"), e.preventDefault(), e.stopPropagation(), !1;
    }, C = (e) => (o.isEmpty(l.url) || H(l.url, "video"), e.preventDefault(), e.stopPropagation(), !1), $ = (e) => (o.isEmpty(l.url) ? g(l.imgSrc, l.name) : m(l.url), e.preventDefault(), e.stopPropagation(), !1), pe = (e) => (m(l.url), e.preventDefault(), e.stopPropagation(), !1);
    return c({
      saveServerCallback: (e) => {
        if (e.res.success) {
          let d = "";
          o.isString(e.res.fileUrl) ? d = e.res.fileUrl : o.isArray(e.res.fileUrl) && e.res.fileUrl.length > 0 && (d = e.res.fileUrl[0]), N(e.req, { fileUrl: d }), y(d);
        } else
          j("fail");
      },
      getValue: () => le(),
      cleanReduction: () => {
        ae();
      }
    }), (e, d) => (u(), f("div", {
      class: "fileUpload-default",
      ref_key: "refElTopParent",
      ref: w
    }, [
      F("div", {
        class: "fileUpload-default-container",
        onDrop: ye,
        onDragover: d[0] || (d[0] = V(() => {
        }, ["prevent"]))
      }, [
        F("label", { for: b.value }, [
          a.isInitFileInput && !t.isDisabled ? (u(), f("input", {
            key: 0,
            type: "file",
            id: b.value,
            name: b.value,
            onChange: n,
            accept: J(z).mime.join(",")
          }, null, 40, $e)) : (u(), f("input", {
            key: 1,
            id: b.value,
            name: b.value,
            style: { display: "none !important" }
          }, null, 8, We)),
          a.runOperateType === "init" ? (u(), f("span", {
            key: 2,
            class: te(p.value)
          }, [
            F("i", {
              class: te(D.value)
            }, null, 2),
            F("span", je, [
              me(e.$slots, "label")
            ])
          ], 2)) : a.runOperateType === "complete" ? (u(), f("span", {
            key: 3,
            class: te(k.value)
          }, [
            a.isImage ? (u(), f("span", Pe, [
              F("span", Ne, [
                F("img", {
                  src: l.imgSrc,
                  width: l.imgWidth,
                  height: l.imgHeight
                }, null, 8, Le)
              ]),
              F("span", _e, de(a.completeMsgTxt), 1),
              t.isShowPreview ? (u(), f("i", {
                key: 0,
                class: "preview-icon clIconFont clIcon-search-plus",
                title: J(S).common.preview,
                onClick: V(v, ["stop"])
              }, null, 8, Ve)) : (u(), f(W, { key: 1 }, [], 64)),
              t.isShowDownload ? (u(), f("i", {
                key: 2,
                class: "download-icon clIconFont clIcon-download",
                title: "下载",
                onClick: V($, ["stop"])
              })) : (u(), f(W, { key: 3 }, [], 64))
            ])) : a.isVideo ? (u(), f("span", qe, [
              F("video", {
                src: l.url
              }, null, 8, Ae),
              F("span", {
                class: "preview-icon",
                onClick: V(C, ["stop"])
              }, [...d[1] || (d[1] = [
                F("i", { class: "clIconFont clIcon-play" }, null, -1)
              ])]),
              F("i", {
                class: "download-icon clIconFont clIcon-download",
                title: J(S).common.download,
                onClick: V(pe, ["stop"])
              }, null, 8, Ge)
            ])) : (u(), f("span", Je, [
              F("i", {
                class: te(D.value)
              }, null, 2),
              F("span", null, de(l.name), 1)
            ])),
            t.isDisabled ? (u(), f(W, { key: 4 }, [], 64)) : (u(), f("a", {
              key: 3,
              class: "file-complete-remove",
              href: "javascript:",
              title: J(S).common.delete,
              onClick: V(s, ["stop"])
            }, [...d[2] || (d[2] = [
              F("i", { class: "clIconFont clIcon-close" }, null, -1)
            ])], 8, Ke))
          ], 2)) : (u(), f(W, { key: 4 }, [], 64))
        ], 8, Oe)
      ], 32),
      a.runOperateType === "load" ? (u(), f("div", Xe, [
        be(ze, { theme: "circleBubble" })
      ])) : (u(), f(W, { key: 1 }, [], 64))
    ], 512));
  }
}), Qe = { class: "fileUpload-button" }, Ye = ["id", "name", "multiple", "accept"], et = ["id", "name"], tt = ["for"], it = {
  key: 0,
  class: "fileUpload-list"
}, ot = {
  key: 0,
  class: "fileUpload-item"
}, lt = {
  key: 0,
  class: "fileUpload-item-icon fileUpload-item-img"
}, nt = ["src"], st = ["title", "onClick"], at = {
  key: 1,
  class: "fileUpload-item-icon fileUpload-item-video"
}, ct = ["src"], rt = ["onClick"], mt = { class: "fileUpload-item-name" }, ut = { class: "fileUpload-item-operate" }, pt = ["title", "onClick"], dt = ["title", "onClick"], ft = /* @__PURE__ */ he({
  name: "ClFileUploadButton",
  __name: "Button",
  props: {
    value: String,
    name: String,
    isDisabled: {
      type: Boolean,
      default: !1
    },
    isMultiple: Boolean,
    buttonClass: String,
    buttonLabel: String,
    buttonIcon: {
      type: String,
      default: ""
    },
    buttonColor: {
      type: String,
      default: "default"
    },
    checkFormat: String,
    checkMinSize: [String, Number],
    checkMaxSize: [String, Number],
    checkWidth: [String, Number],
    checkHeight: [String, Number],
    checkWHType: String,
    isServerCallback: Boolean,
    isShowUploadResult: {
      type: Boolean,
      default: !0
    },
    isShowUploadIng: {
      type: Boolean,
      default: !0
    },
    isShowPreview: {
      type: Boolean,
      default: !0
    },
    isShowDownload: {
      type: Boolean,
      default: !0
    }
  },
  emits: ["onChange", "onError", "onRemove", "onPreview", "onSaveFile"],
  setup(t, { expose: c, emit: r }) {
    const i = t, h = r, { optPageLanguage: S, getPageLanguage: I } = xe();
    I("fileUpload");
    const R = ve("$FileuploadTop"), { setFileInfo: B } = Ie(), { optBase: z, getTypeByUrl: P, checkFile: q, setBaseOptions: K } = Fe(
      R.getFileCheckInfo(),
      S
    ), { downloadBlob: Z, downloadHref: A } = Ee(), m = X(null), g = X(null), w = o.getRandom(8), a = oe({
      keyIndex: `file-${w}`,
      elFileId: `btnFile${w}`,
      isInitFileInput: !0,
      runOperateType: "init"
    }), l = X([]), x = X([]), b = ee(() => {
      let n = i.name;
      return o.isEmpty(n) && (n = `fileUpload_${o.getRandom(8)}`), n;
    }), D = (n, s) => {
      h("onChange", n, s);
    }, p = (n) => {
      h("onError", n);
    }, k = () => {
      h("onRemove");
    }, y = (n, s) => {
      h("onPreview", n, s);
    }, E = (n, s) => {
      h("onSaveFile", n, s);
    }, T = (n) => {
      let s = "";
      switch (n) {
        case "load":
          i.isShowUploadIng && m.value.loadStart();
          break;
        case "fail":
        case "complete":
          i.isShowUploadIng && m.value.loadStop(), s = "init";
          break;
        default:
          s = n;
      }
      a.isInitFileInput = n !== "load", a.runOperateType = s;
    }, H = (n, s) => {
      const v = [], C = [];
      l.value.forEach(($) => {
        v.push($), C.push($.rId);
      });
      for (let $ = 0; $ < n.length; $++) {
        const pe = s.length > $ ? { fileUrl: s[$] } : {};
        let Q = B(n[$], pe);
        Q.rId = o.getRandom(9), Q = o.getJsonMerge(n[$], Q), v.push(Q), C.push(Q.rId);
      }
      l.value = v, T("complete"), ie(() => {
        x.value = C;
      });
    }, L = () => {
      const n = [];
      return l.value.forEach((s) => {
        let v = null;
        o.isEmpty(s.url) ? s.isImage && !o.isEmpty(s.imgSrc) ? v = s.imgSrc : v = s.file : v = s.url, o.isUndefined(v) || n.push(v);
      }), n.length === 0 ? "" : i.isMultiple ? n : n[0];
    }, _ = (n) => {
      if (o.isEmpty(n))
        j();
      else {
        const s = [], v = [];
        n.split(",").forEach((C) => {
          const $ = P(C);
          s.push($), v.push(C);
        }), H(s, v);
      }
    }, j = () => {
      T("init"), l.value = [];
    }, O = () => {
      _(i.value);
    };
    re(
      () => i.value,
      (n, s) => {
        if (n !== s) {
          const v = L();
          n !== v && _(n);
        }
      }
    ), re(
      [
        () => i.checkFormat,
        () => i.checkWidth,
        () => i.checkHeight,
        () => i.checkWHType,
        () => i.checkMinSize,
        () => i.checkMaxSize
      ],
      () => {
        K(R.getFileCheckInfo());
      }
    ), ke(() => {
      ie(() => {
        O();
      });
    });
    const N = (n) => {
      n.currentTarget.files.length > 0 && (T("load"), q(n.currentTarget.files, {}).then((s) => {
        if (s.passFiles.length > 0)
          if (i.isServerCallback) {
            const v = i.isMultiple ? s.passFiles : s.passFiles[0], C = i.isMultiple ? s.passFilesInfo : s.passFilesInfo[0];
            E(v, C);
          } else
            D(s.passFiles, s.passFilesInfo), H(s.passFilesInfo, []);
        s.errorMsg.length > 0 && (p(s.errorMsg), s.passFiles.length === 0 && T("fail"));
      }));
    }, le = (n) => {
      const s = o.isEmpty(n.url) ? n.src : n.url;
      y(s, "image");
    }, ne = (n) => {
      o.isEmpty(n.url) || y(n.url, "video");
    }, se = (n) => {
      const s = [], v = [];
      l.value.forEach((C) => {
        C.rId !== n && (s.push(C), v.push(C.rId));
      }), x.value = v, ie(() => {
        s.length > 0 ? (l.value = s, k()) : setTimeout(() => {
          l.value = [], k();
        }, 200);
      });
    }, ae = (n) => {
      n.isImage && o.isEmpty(n.url) ? A(n.imgSrc, n.name) : Z(n.url);
    }, ce = () => {
      g.value.click();
    };
    return c({
      saveServerCallback: (n) => {
        if (n.res.success) {
          let s = [];
          o.isString(n.res.fileUrl) ? s.push(n.res.fileUrl) : o.isArray(n.res.fileUrl) && (s = n.res.fileUrl), H(i.isMultiple ? n.req : [n.req], s), D(s);
        } else
          T("fail");
      },
      getValue: () => L(),
      cleanReduction: () => {
        j();
      }
    }), (n, s) => (u(), f(W, null, [
      F("div", Qe, [
        a.isInitFileInput && !t.isDisabled ? (u(), f("input", {
          key: 0,
          type: "file",
          id: a.elFileId,
          name: b.value,
          multiple: t.isMultiple,
          accept: J(z).mime.join(","),
          onChange: N
        }, null, 40, Ye)) : (u(), f("input", {
          key: 1,
          id: a.elFileId,
          name: b.value,
          style: { display: "none !important" }
        }, null, 8, et)),
        F("label", {
          ref_key: "refElLabel",
          ref: g,
          for: a.elFileId
        }, [
          be(De, {
            ref_key: "refElButton",
            ref: m,
            className: t.buttonClass,
            isShowBackDrop: !0,
            disabled: t.isDisabled,
            label: t.buttonLabel || J(S).common.upload,
            icon: t.buttonIcon,
            color: t.buttonColor,
            onOnClick: ce
          }, null, 8, ["className", "disabled", "label", "icon", "color"])
        ], 8, tt)
      ]),
      me(n.$slots, "label"),
      l.value.length > 0 && t.isShowUploadResult ? (u(), f("ul", it, [
        (u(!0), f(W, null, Ce(l.value, (v) => (u(), fe(Me, {
          key: `${a.keyIndex}-${v.rId}`,
          name: "fileUploadButton",
          "enter-active-class": "animated fadeInDown",
          "leave-active-class": "animated fadeOut"
        }, {
          default: ge(() => [
            x.value.indexOf(v.rId) > -1 ? (u(), f("li", ot, [
              v.isImage ? (u(), f("span", lt, [
                F("img", {
                  src: v.imgSrc
                }, null, 8, nt),
                t.isShowPreview ? (u(), f("i", {
                  key: 0,
                  class: "preview-icon clIconFont clIcon-search-plus",
                  title: J(S).common.preview,
                  onClick: V((C) => le(v), ["stop"])
                }, null, 8, st)) : (u(), f(W, { key: 1 }, [], 64))
              ])) : v.isVideo ? (u(), f("span", at, [
                F("video", {
                  src: v.url
                }, null, 8, ct),
                t.isShowPreview ? (u(), f("span", {
                  key: 0,
                  class: "preview-icon",
                  onClick: V((C) => ne(v), ["stop"])
                }, [...s[0] || (s[0] = [
                  F("i", { class: "clIconFont clIcon-play" }, null, -1)
                ])], 8, rt)) : (u(), f(W, { key: 1 }, [], 64))
              ])) : (u(), f("i", {
                key: 2,
                class: te(["fileUpload-item-icon", v.icon])
              }, null, 2)),
              F("span", mt, de(v.name), 1),
              F("span", ut, [
                t.isShowDownload ? (u(), f("i", {
                  key: 0,
                  class: "download-icon clIconFont clIcon-download",
                  title: J(S).common.download,
                  onClick: V((C) => ae(v), ["stop"])
                }, null, 8, pt)) : (u(), f(W, { key: 1 }, [], 64)),
                t.isDisabled ? (u(), f(W, { key: 3 }, [], 64)) : (u(), f("a", {
                  key: 2,
                  class: "file-complete-remove",
                  href: "javascript:",
                  title: J(S).common.delete,
                  onClick: V((C) => se(v.rId), ["stop"])
                }, [...s[1] || (s[1] = [
                  F("i", { class: "clIconFont clIcon-close" }, null, -1)
                ])], 8, dt))
              ])
            ])) : Te("", !0)
          ]),
          _: 2
        }, 1024))), 128))
      ])) : (u(), f(W, { key: 1 }, [], 64))
    ], 64));
  }
}), xt = /* @__PURE__ */ he({
  name: "ClFileupload",
  __name: "Index",
  props: {
    value: String,
    name: String,
    className: {
      type: String,
      default: ""
    },
    theme: {
      type: String,
      default: "default"
      // default | button
    },
    disabled: {
      type: Boolean,
      default: !1
    },
    isMultiple: {
      type: Boolean,
      default: !1
      // 仅针对 theme:button
    },
    defaultHoverTitle: {
      type: String,
      default: ""
    },
    buttonClass: String,
    buttonLabel: String,
    buttonIcon: String,
    buttonColor: String,
    checkFormat: {
      type: String,
      default: ""
    },
    checkMinSize: [String, Number],
    checkMaxSize: [String, Number],
    checkWidth: [String, Number],
    checkHeight: [String, Number],
    checkWHType: {
      type: String,
      default: "equal"
      // equal | greater | less
    },
    serverFileCallback: Function,
    isShowPreview: {
      type: Boolean,
      default: !0
    },
    isShowDownload: {
      type: Boolean,
      default: !0
    },
    isShowUploadResult: {
      type: Boolean,
      default: !0
      // 仅针对 theme:button
    },
    isShowUploadIng: {
      type: Boolean,
      default: !0
    }
  },
  emits: ["update:value", "onChange", "onRemove"],
  setup(t, { expose: c, emit: r }) {
    const i = t, h = r, S = ve("$ClGlobals"), I = Be(), R = X(null), B = X(null), z = X(null), P = oe({
      isServerCallback: !1
    }), q = ee(() => {
      const p = {
        "panel-fileUpload": !0,
        "box-width": !0
      };
      return o.isEmpty(i.className) || i.className.split(" ").forEach((k) => {
        o.isEmpty(k) || (p[k] = !0);
      }), p;
    }), K = (p, k, y) => {
      h("update:value", p), h("onChange", k, y);
    }, Z = () => {
      h("onRemove");
    }, A = () => {
      let p = null;
      switch (i.theme) {
        case "default":
          p = B.value.getValue();
          break;
        case "button":
          p = z.value.getValue();
          break;
      }
      return p;
    }, m = () => {
      P.isServerCallback = o.isFunction(i.serverFileCallback);
    };
    ke(() => {
      ie(() => {
        m();
      });
    });
    const g = (p, k) => {
      const y = A(), E = P.isServerCallback ? y : p;
      K(y, E, k);
    }, w = (p) => {
      S.notify.error(p.join("<br>"));
    }, a = () => {
      Z();
      const p = A();
      K(p, p);
    }, l = (p, k) => {
      S.preview.show({
        type: p,
        src: k,
        showInx: 0
      });
    }, x = async (p, k) => {
      let y = !0;
      if (i.serverFileCallback) {
        const T = !i.isMultiple && o.isObject(k) && o.isBoolean(k.isImage) ? k.isImage : !1, H = Re.getElementData(I);
        y = await i.serverFileCallback(p, T, H);
      }
      let E = {};
      switch (o.isBoolean(y) || o.isUndefined(y) ? E.success = y : o.isString(y) || o.isArray(y) ? (E.success = !0, E.fileUrl = y) : o.isObject(y) && (E = y), i.theme) {
        case "default":
          B.value.saveServerCallback({ req: k, res: E });
          break;
        case "button":
          z.value.saveServerCallback({ req: k, res: E });
          break;
      }
    };
    return He("$FileuploadTop", {
      getFileCheckInfo: () => ({
        checkFormat: i.checkFormat,
        checkWidth: i.checkWidth,
        checkHeight: i.checkHeight,
        checkWHType: i.checkWHType,
        checkMinSize: i.checkMinSize,
        checkMaxSize: i.checkMaxSize
      })
    }), c({
      getValue: () => A(),
      cleanReduction: () => {
        switch (i.theme) {
          case "default":
            B.value.cleanReduction();
            break;
          case "button":
            z.value.cleanReduction();
            break;
        }
      }
    }), (p, k) => (u(), f("div", {
      class: te(q.value),
      ref_key: "refElTopParent",
      ref: R
    }, [
      t.theme === "button" ? (u(), fe(ft, {
        key: 0,
        ref_key: "refElFileButton",
        ref: z,
        value: t.value,
        name: t.name,
        isDisabled: t.disabled,
        isMultiple: t.isMultiple,
        buttonClass: t.buttonClass,
        buttonLabel: t.buttonLabel,
        buttonIcon: t.buttonIcon,
        buttonColor: t.buttonColor,
        checkFormat: t.checkFormat,
        checkMinSize: t.checkMinSize,
        checkMaxSize: t.checkMaxSize,
        checkWidth: t.checkWidth,
        checkHeight: t.checkHeight,
        checkWHType: t.checkWHType,
        isServerCallback: P.isServerCallback,
        isShowUploadResult: t.isShowUploadResult,
        isShowUploadIng: t.isShowUploadIng,
        isShowPreview: t.isShowPreview,
        isShowDownload: t.isShowDownload,
        onOnChange: g,
        onOnError: w,
        onOnRemove: a,
        onOnPreview: l,
        onOnSaveFile: x
      }, {
        label: ge(() => [
          me(p.$slots, "label")
        ]),
        _: 3
      }, 8, ["value", "name", "isDisabled", "isMultiple", "buttonClass", "buttonLabel", "buttonIcon", "buttonColor", "checkFormat", "checkMinSize", "checkMaxSize", "checkWidth", "checkHeight", "checkWHType", "isServerCallback", "isShowUploadResult", "isShowUploadIng", "isShowPreview", "isShowDownload"])) : t.theme === "default" ? (u(), fe(Ze, {
        key: 1,
        ref_key: "refElFileDefault",
        ref: B,
        value: t.value,
        name: t.name,
        isDisabled: t.disabled,
        checkFormat: t.checkFormat,
        checkMinSize: t.checkMinSize,
        checkMaxSize: t.checkMaxSize,
        checkWidth: t.checkWidth,
        checkHeight: t.checkHeight,
        checkWHType: t.checkWHType,
        isServerCallback: P.isServerCallback,
        isShowPreview: t.isShowPreview,
        isShowDownload: t.isShowDownload,
        onOnChange: g,
        onOnError: w,
        onOnRemove: a,
        onOnPreview: l,
        onOnSaveFile: x
      }, {
        label: ge(() => [
          me(p.$slots, "label")
        ]),
        _: 3
      }, 8, ["value", "name", "isDisabled", "checkFormat", "checkMinSize", "checkMaxSize", "checkWidth", "checkHeight", "checkWHType", "isServerCallback", "isShowPreview", "isShowDownload"])) : (u(), f(W, { key: 2 }, [], 64))
    ], 2));
  }
});
export {
  xt as _
};
//# sourceMappingURL=Index.vue_vue_type_script_setup_true_lang-BvGrVSSF.js.map
