import { defineComponent, ref, computed, watch, openBlock, createElementBlock, normalizeClass, unref, normalizeStyle, createCommentVNode, renderSlot, watchEffect, createElementVNode, createVNode, toDisplayString } from "vue";
const domain = "https://wlmvp-cos.weiling.cn";
const loadingPic = domain + "/frontend/weilingMobileUI/loading.png";
const loadingFailPic = domain + "/frontend/weilingMobileUI/loadingFail.png";
const loadImage = (url) => {
  return new Promise((resolve, reject) => {
    const newImg = new Image();
    newImg.src = url;
    newImg.onerror = () => {
      reject("failure");
    };
    newImg.onload = (e) => {
      resolve(e.target);
    };
  });
};
const isTencentCosPic = (url) => {
  return url.includes("wlmvp-cos.weiling.cn");
};
const isBase64 = (str) => {
  return str.indexOf("data:") != -1 && str.indexOf("base64") != -1;
};
const _hoisted_1$1 = ["src", "alt"];
const _hoisted_2$1 = ["src"];
const _hoisted_3$1 = ["src"];
var ECosType = /* @__PURE__ */ ((ECosType2) => {
  ECosType2["normal"] = "imageView2/1/q/85";
  ECosType2["thumbnail"] = "imageView2/1/w/100/h/100/q/85";
  return ECosType2;
})(ECosType || {});
const __default__$1 = {
  name: "WlPic"
};
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
  ...__default__$1,
  props: {
    src: { default: "" },
    needCos: { type: Boolean, default: true },
    cosType: { default: "normal" },
    radius: { type: Boolean, default: false },
    round: { type: Boolean, default: false },
    needLoading: { type: Boolean, default: true },
    needMiddleCenter: { type: Boolean, default: true },
    needHeightAuto: { type: Boolean, default: false },
    fit: { default: "fill" }
  },
  setup(__props, { expose }) {
    const props = __props;
    const isLoading = ref(true);
    const isError = ref(false);
    const imgSrc = ref("");
    const imgWrapRef = ref("");
    const imgStyleComputed = computed(() => {
      return {
        "border-radius": props.round ? "50%" : "",
        "object-fit": props.fit
      };
    });
    const imgWrapClassComputed = computed(() => {
      return [
        "wl-img",
        "wh-full",
        "relative",
        "flex-col",
        props.needMiddleCenter ? "flex-middle-center" : ""
      ];
    });
    const onLoadImage = (url) => {
      return new Promise((resolve, reject) => {
        loadImage(url).then((elem) => {
          resolve(elem);
        }).catch((reason) => {
          reject(reason);
        }).finally(() => {
          isLoading.value = false;
        });
      });
    };
    const setImgSrc = (url) => {
      const needCos = isTencentCosPic(url) && props.needCos;
      const file_type = url.split(".").pop();
      let isSvg = file_type === "svg";
      let isBase64Bool = isBase64(url);
      if (isSvg || !needCos || isBase64Bool) {
        imgSrc.value = url;
        onLoadImage(imgSrc.value).catch(() => {
          isError.value = true;
        });
      } else {
        imgSrc.value = `${url}?${ECosType[props.cosType]}`;
        onLoadImage(imgSrc.value).catch(() => {
          imgSrc.value = url;
        });
      }
    };
    watch(
      () => props.src,
      (val) => {
        if (val) {
          isLoading.value = true;
          setImgSrc(props.src);
        }
      },
      { immediate: true }
    );
    expose({
      imgWrapRef
    });
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", {
        class: normalizeClass(unref(imgWrapClassComputed)),
        ref_key: "imgWrapRef",
        ref: imgWrapRef
      }, [
        !isLoading.value && !isError.value ? (openBlock(), createElementBlock("img", {
          key: 0,
          src: imgSrc.value,
          style: normalizeStyle(unref(imgStyleComputed)),
          class: normalizeClass(`w-full block ${__props.needHeightAuto ? "h-auto" : "h-full"}`),
          alt: imgSrc.value
        }, null, 14, _hoisted_1$1)) : createCommentVNode("", true),
        isLoading.value && __props.needLoading ? (openBlock(), createElementBlock("img", {
          key: 1,
          src: unref(loadingPic),
          alt: "loading",
          class: "w-1/5 uno-min-w-20 uno-min-h-20 uno-max-w-60 uno-max-h-60 absolute-middle-center animate-spin"
        }, null, 8, _hoisted_2$1)) : createCommentVNode("", true),
        isError.value ? (openBlock(), createElementBlock("img", {
          key: 2,
          src: unref(loadingFailPic),
          alt: "failure",
          class: "w-1/5 uno-min-w-20 uno-min-h-20 uno-max-w-60 uno-max-h-60 absolute-middle-center"
        }, null, 8, _hoisted_3$1)) : createCommentVNode("", true),
        renderSlot(_ctx.$slots, "picFooter")
      ], 2);
    };
  }
});
var __uno = "";
_sfc_main$1.install = (app) => {
  app.component(_sfc_main$1.name, _sfc_main$1);
};
var index_vue_vue_type_style_index_0_lang = "";
const _hoisted_1 = {
  class: "default-page",
  "data-weiling-mobile-ui-wl-default-page": ""
};
const _hoisted_2 = { class: "error-pic-url" };
const _hoisted_3 = { class: "error-text" };
const __default__ = {
  name: "BCDefaultPage"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
  ...__default__,
  props: {
    code: { default: 500 },
    errorMessage: { default: "" }
  },
  setup(__props) {
    const props = __props;
    const errorText = ref("");
    const needRefresh = ref(false);
    const errorPicUrl = ref("");
    const onGetErrorPicUrl = (code) => {
      const picDict = {
        1003: "search_no_result.png",
        3001: "error-page.png",
        4008: "error-no-group-member.png",
        5004: "error-page.png",
        5018: `error-no-company.png`,
        "-1001": "search_no_result.png",
        "-1002": "custom-no-auth.png"
      };
      return `${domain}/frontend/errorPage/${picDict[code]}`;
    };
    const onGetErrorText = (code) => {
      const textDict = {
        1003: "\u8BE5\u5206\u53D1\u4EFB\u52A1\u5DF2\u5220\u9664",
        3001: "\u8BF7\u5728\u79FB\u52A8\u7AEF\u6253\u5F00\u672C\u9875\u9762\uFF0C\u5373\u53EF\u4E00\u952E\u8F6C\u53D1\u81F3\u5BA2\u6237\u670B\u53CB\u5708",
        4008: "\u8BE5\u7FA4\u7531\u5916\u90E8\u8054\u7CFB\u4EBA\u521B\u5EFA\uFF0C\u65E0\u6CD5\u83B7\u53D6\u7FA4\u6D88\u606F",
        5004: decodeURIComponent(props.errorMessage || "\u7CFB\u7EDF\u5F02\u5E38\uFF01"),
        5018: `\u5F53\u524D\u4F01\u4E1A\u5DF2\u88AB\u5220\u9664`,
        "-1001": props.errorMessage,
        "-1002": "\u60A8\u7684\u8D26\u53F7\u6CA1\u6709\u8BE5\u529F\u80FD\u7684\u4F7F\u7528\u6743\u9650\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458"
      };
      return textDict[code];
    };
    const onGetNeedRefresh = (code) => {
      const refreshBtnDict = {
        1003: false,
        3001: false,
        5004: true,
        4008: false,
        5018: false
      };
      return refreshBtnDict[code];
    };
    const onRefresh = () => {
      window.location.hash = "";
      window.location.reload();
    };
    watchEffect(() => {
      errorPicUrl.value = onGetErrorPicUrl(props.code);
      errorText.value = onGetErrorText(props.code);
      needRefresh.value = onGetNeedRefresh(props.code);
    });
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", _hoisted_1, [
        createElementVNode("div", _hoisted_2, [
          createVNode(unref(_sfc_main$1), { src: errorPicUrl.value }, null, 8, ["src"])
        ]),
        createElementVNode("p", _hoisted_3, toDisplayString(errorText.value), 1),
        needRefresh.value ? (openBlock(), createElementBlock("div", {
          key: 0,
          class: "refresh-btn",
          onClick: onRefresh
        }, "\u5237\u65B0")) : createCommentVNode("", true)
      ]);
    };
  }
});
_sfc_main.install = (app) => {
  app.component(_sfc_main.name, _sfc_main);
};
export { _sfc_main as default };
