import { defineComponent, ref, computed, watch, openBlock, createElementBlock, normalizeClass, unref, normalizeStyle, createCommentVNode, renderSlot, createBlock, toDisplayString, createElementVNode, createVNode } from "vue";
import WlSvg from "@wltech/svg";
const isEmpty = (value) => {
  if (value === null || value === "" || value === void 0 || value === "null" || value === "0") {
    return true;
  } else if (typeof value === "string") {
    value = value.replace(/\s/g, "");
    if (value === "") {
      return true;
    }
    return false;
  }
  return false;
};
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 domain = "https://wlmvp-cos.weiling.cn";
const loadingPic = domain + "/frontend/weilingMobileUI/loading.png";
const loadingFailPic = domain + "/frontend/weilingMobileUI/loadingFail.png";
const _hoisted_1$2 = ["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__$3 = {
  name: "WlPic"
};
const _sfc_main$3 = /* @__PURE__ */ defineComponent({
  ...__default__$3,
  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$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);
    };
  }
});
const __default__$2 = {
  name: "WlSvgIcon"
};
const _sfc_main$2 = /* @__PURE__ */ defineComponent({
  ...__default__$2,
  props: {
    type: { default: "" },
    color: { default: "var(--wl-text-color-title-1)" },
    width: { default: "16" },
    height: { default: "16" }
  },
  setup(__props) {
    const sub = location.origin;
    return (_ctx, _cache) => {
      return openBlock(), createBlock(unref(WlSvg), {
        type: __props.type,
        width: __props.width,
        height: __props.height,
        color: __props.color,
        sub: unref(sub)
      }, null, 8, ["type", "width", "height", "color", "sub"]);
    };
  }
});
const _hoisted_1$1 = ["type", "openid"];
const __default__$1 = {
  name: "WlStaffName"
};
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
  ...__default__$1,
  props: {
    is_trial: { type: Boolean, default: false },
    type: { default: "userName" },
    name: { default: "" },
    openid: { default: "" },
    fontSize: { default: "" },
    color: { default: "" },
    cursor: { default: "" }
  },
  setup(__props) {
    const props = __props;
    const openDataEl = ref();
    const name_style = computed(() => {
      return {
        fontSize: typeof props.fontSize === "string" ? props.fontSize : props.fontSize + "px",
        color: props.color,
        cursor: props.cursor
      };
    });
    watch(
      [() => props.openid, () => props.is_trial, openDataEl],
      ([id, shouldBind, el]) => {
        var _a;
        if (id && shouldBind && el) {
          (_a = window.parent.WWOpenData) == null ? void 0 : _a.bind(el);
        }
      }
    );
    return (_ctx, _cache) => {
      return __props.is_trial ? (openBlock(), createElementBlock("ww-open-data", {
        key: 0,
        ref_key: "openDataEl",
        ref: openDataEl,
        type: __props.type,
        openid: __props.openid,
        style: normalizeStyle(unref(name_style))
      }, null, 12, _hoisted_1$1)) : (openBlock(), createElementBlock("span", {
        key: 1,
        style: normalizeStyle(unref(name_style))
      }, toDisplayString(__props.name), 5));
    };
  }
});
var index_vue_vue_type_style_index_0_lang = "";
const _hoisted_1 = ["target", "href"];
const _hoisted_2 = { class: "avatar-wrap" };
const _hoisted_3 = {
  key: 0,
  class: "avatar"
};
const _hoisted_4 = {
  key: 0,
  class: "user-name"
};
const __default__ = {
  name: "WlUser"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
  ...__default__,
  props: {
    data: { default: null },
    size: { default: "normal" },
    target: { default: "_self" },
    icon_type: { default: "" },
    is_trial: { type: Boolean, default: false },
    inline: { type: Boolean, default: false }
  },
  setup(__props) {
    const props = __props;
    const disabledAttr = "javascript:void(0);";
    const userUrl = computed(() => {
      var _a;
      return ((_a = props.data) == null ? void 0 : _a.href) || disabledAttr;
    });
    const userClass = computed(() => {
      var _a;
      return {
        "user-wrap": true,
        [props.size]: true,
        inline: props.inline,
        cursor: !isEmpty((_a = props.data) == null ? void 0 : _a.href),
        "disabled-href": userUrl.value === disabledAttr
      };
    });
    const show_type = computed(() => {
      return ["weixin", "wxwork"].includes(props.icon_type);
    });
    return (_ctx, _cache) => {
      var _a, _b, _c, _d, _e, _f;
      return openBlock(), createElementBlock("a", {
        class: normalizeClass(unref(userClass)),
        target: __props.target,
        href: unref(userUrl),
        "data-weiling-mobile-ui-wl-user": ""
      }, [
        createElementVNode("div", _hoisted_2, [
          ((_a = __props.data) == null ? void 0 : _a.head_img_url) ? (openBlock(), createElementBlock("p", _hoisted_3, [
            createVNode(_sfc_main$3, {
              src: (_b = __props.data) == null ? void 0 : _b.head_img_url
            }, null, 8, ["src"])
          ])) : createCommentVNode("", true),
          unref(show_type) ? (openBlock(), createElementBlock("div", {
            key: 1,
            class: normalizeClass(`user-icon ${__props.icon_type}`)
          }, [
            __props.icon_type === "weixin" ? (openBlock(), createBlock(_sfc_main$2, {
              key: 0,
              type: "wechatFill",
              width: "9",
              height: "9",
              color: "#fff"
            })) : createCommentVNode("", true),
            __props.icon_type === "wxwork" ? (openBlock(), createBlock(_sfc_main$2, {
              key: 1,
              type: "wecomFill",
              width: "8",
              height: "8",
              color: "#fff"
            })) : createCommentVNode("", true)
          ], 2)) : createCommentVNode("", true)
        ]),
        ((_c = __props.data) == null ? void 0 : _c.nick_name) && !__props.is_trial || __props.is_trial && ((_d = __props.data) == null ? void 0 : _d.userid_third) ? (openBlock(), createElementBlock("p", _hoisted_4, [
          createVNode(_sfc_main$1, {
            name: (_e = __props.data) == null ? void 0 : _e.nick_name,
            type: "userName",
            openid: (_f = __props.data) == null ? void 0 : _f.userid_third,
            is_trial: __props.is_trial
          }, null, 8, ["name", "openid", "is_trial"])
        ])) : createCommentVNode("", true)
      ], 10, _hoisted_1);
    };
  }
});
var __uno = "";
_sfc_main.install = (app) => {
  app.component(_sfc_main.name, _sfc_main);
};
export { _sfc_main as default };
