import { defineComponent, ref, computed, watch, openBlock, createElementBlock, normalizeClass, unref, normalizeStyle, createCommentVNode, renderSlot, createElementVNode, createVNode, withCtx, 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 snapshot_notice_figer = domain + "/frontend/weilingMobileUI/figer.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$2 = ["src", "alt"];
const _hoisted_2$2 = ["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$2 = /* @__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$2)) : 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$2)) : 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 index_vue_vue_type_style_index_0_lang$1 = "";
var _export_sfc = (sfc, props) => {
  const target = sfc.__vccOpts || sfc;
  for (const [key, val] of props) {
    target[key] = val;
  }
  return target;
};
const _sfc_main$1 = {};
const _hoisted_1$1 = {
  class: "container",
  "data-weiling-mobile-ui-bc-snapshot-notice-container": ""
};
const _hoisted_2$1 = /* @__PURE__ */ createElementVNode("div", { class: "bg-wrap" }, [
  /* @__PURE__ */ createElementVNode("div", { class: "bg-3DADFF" }),
  /* @__PURE__ */ createElementVNode("div", { class: "bg-62bdff" })
], -1);
function _sfc_render(_ctx, _cache) {
  return openBlock(), createElementBlock("div", _hoisted_1$1, [
    _hoisted_2$1,
    renderSlot(_ctx.$slots, "default")
  ]);
}
var Container = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render]]);
var index_vue_vue_type_style_index_0_lang = "";
const _hoisted_1 = {
  class: "bc-snapshot-notice-wrap",
  "data-weiling-mobile-ui-bc-snapshot-notice": ""
};
const _hoisted_2 = { class: "snapshot-notice" };
const _hoisted_3 = { class: "text" };
const _hoisted_4 = { class: "figer-wrap" };
const __default__ = {
  name: "BCSnapshotNotice"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
  ...__default__,
  props: {
    show_background: { type: Boolean, default: true },
    text: { default: "\u70B9\u51FB\u4E0B\u65B9\u201C\u4F7F\u7528\u5B8C\u6574\u670D\u52A1\u201D\u67E5\u770B\u6587\u7AE0" }
  },
  setup(__props) {
    const backgroundStyle = {};
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", _hoisted_1, [
        __props.show_background ? (openBlock(), createElementBlock("div", {
          key: 0,
          class: "show-background",
          style: backgroundStyle
        })) : createCommentVNode("", true),
        createVNode(Container, null, {
          default: withCtx(() => [
            createElementVNode("div", _hoisted_2, [
              createElementVNode("p", _hoisted_3, toDisplayString(__props.text), 1)
            ]),
            createElementVNode("div", _hoisted_4, [
              createVNode(_sfc_main$2, { src: unref(snapshot_notice_figer) }, null, 8, ["src"])
            ])
          ]),
          _: 1
        })
      ]);
    };
  }
});
var __uno = "";
_sfc_main.install = (app) => {
  app.component(_sfc_main.name, _sfc_main);
};
export { _sfc_main as default };
