import { defineComponent, ref, computed, watch, openBlock, createElementBlock, normalizeClass, unref, normalizeStyle, createCommentVNode, renderSlot, onMounted, createVNode, toDisplayString, Fragment, renderList, createTextVNode, onUnmounted } 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$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__$2 = {
  name: "WlPic"
};
const _sfc_main$2 = /* @__PURE__ */ defineComponent({
  ...__default__$2,
  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 = "";
const _hoisted_1$1 = {
  class: "reply-recomment",
  "data-weiling-mobile-ui-bc-reply-recommend": ""
};
const _hoisted_2$1 = {
  key: 0,
  class: "text"
};
const _hoisted_3 = {
  key: 1,
  class: "text"
};
const _hoisted_4 = /* @__PURE__ */ createTextVNode("\u4F1A\u8BDD\u4E2D\u63D0\u5230 ");
const _hoisted_5 = { key: 0 };
const __default__$1 = {
  name: "BCReplyRecommend"
};
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
  ...__default__$1,
  props: {
    keywords: { default: null },
    text: { default: "" },
    avatarUrl: { default: "https://wlmvp-cos.weiling.cn/frontend/xiaowei.jpg" },
    number: { default: 1 }
  },
  emits: ["onExecuteNow"],
  setup(__props, { emit }) {
    const props = __props;
    const limit = 3;
    onMounted(() => {
      emit("onExecuteNow");
    });
    const list = computed(() => {
      return props.keywords.slice(0, limit);
    });
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", _hoisted_1$1, [
        createVNode(_sfc_main$2, {
          src: __props.avatarUrl,
          class: "avatar"
        }, null, 8, ["src"]),
        __props.text ? (openBlock(), createElementBlock("span", _hoisted_2$1, toDisplayString(__props.text), 1)) : (openBlock(), createElementBlock("span", _hoisted_3, [
          _hoisted_4,
          (openBlock(true), createElementBlock(Fragment, null, renderList(unref(list), (item, index) => {
            return openBlock(), createElementBlock("span", { key: index }, " [" + toDisplayString(item) + "] ", 1);
          }), 128)),
          __props.keywords.length > limit ? (openBlock(), createElementBlock("span", _hoisted_5, "\u7B49" + toDisplayString(__props.keywords.length) + "\u4E2A\u5173\u952E\u8BCD", 1)) : createCommentVNode("", true),
          createTextVNode(" \uFF0C\u4E3A\u4F60\u63A8\u8350" + toDisplayString(__props.number) + "\u6761\u56DE\u590D", 1)
        ]))
      ]);
    };
  }
});
var index_vue_vue_type_style_index_0_lang = "";
const _hoisted_1 = {
  class: "reply-recommend-list",
  "data-weiling-mobile-ui-bc-reply-recommend-list": "",
  ref: "recommendListWrapRef"
};
const _hoisted_2 = ["onClick"];
const __default__ = {
  name: "BCReplyRecommendList"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
  ...__default__,
  props: {
    list: { default: () => [] },
    wordsKey: { default: "keywords" },
    avatarUrl: { default: "" },
    numberKey: { default: "number" },
    textKey: { default: "text" },
    spaceTime: { default: 15 },
    selectdDelete: { type: Boolean, default: true },
    defaultKey: { default: "key" },
    baseHeight: { default: 500 },
    currentHeight: { default: "" }
  },
  emits: ["update:list", "onSelect"],
  setup(__props, { emit }) {
    const props = __props;
    let tagList = ref([]);
    let renderTime = ref(0);
    let renderSpace = ref(0);
    let intervalTimer = ref(null);
    onMounted(() => {
      if (intervalTimer.value)
        clearInterval(intervalTimer);
      intervalTimer.value = setInterval(() => {
        const data = [];
        for (let i = 0; i < tagList.value.length; i++) {
          const item = tagList.value[i];
          const currentTime = new Date().getTime();
          const spaceTime = currentTime - item["_renderTime"];
          const delayTime = item["_replyRecommendDelay"] || i;
          if (spaceTime < (delayTime + props.spaceTime) * 1e3) {
            data.push(item);
          }
        }
        emit("update:list", data);
      }, props.spaceTime * 1e3);
    });
    onUnmounted(() => {
      if (intervalTimer.value)
        clearInterval(intervalTimer);
    });
    const tagStyle = computed(() => {
      return (item, index) => {
        return {
          "animation-delay": (item["_replyRecommendDelay"] || index) + "s",
          "--spaceTime": props.spaceTime + "s"
        };
      };
    });
    const onSelect = (item) => {
      emit("onSelect", item);
      if (props.selectdDelete) {
        const list = tagList.value.filter(
          (ele) => ele[props.defaultKey] !== item[props.defaultKey]
        );
        emit("update:list", list);
      }
    };
    watch(
      () => props.list,
      (data) => {
        if (data.length > tagList.value.length) {
          let arr = data.slice(tagList.value.length, data.length);
          const currentTime = new Date().getTime();
          const interval = (currentTime - renderTime.value) / 1e3;
          const previousDelay = tagList.value.length === 0 ? 0 : tagList.value[tagList.value.length - 1]["_replyRecommendDelay"];
          const baseTime = interval < previousDelay ? previousDelay : 0;
          const currentHeight = props.currentHeight || parseInt(document.body.clientHeight.toString());
          const spaceTime = props.baseHeight / parseInt(currentHeight.toString()) < 1 ? 0 : props.baseHeight / parseInt(currentHeight.toString());
          arr = arr.map((ele, index) => {
            let currentIndex = tagList.value.length + index;
            return {
              ...ele,
              _replyRecommendDelay: index + baseTime + 0.5 + currentIndex * spaceTime * 0.5,
              _renderTime: new Date().getTime()
            };
          });
          const tagListSec = tagList.value.concat(arr);
          renderSpace.value = arr.length;
          renderTime.value = new Date().getTime();
          tagList.value = tagListSec;
          emit("update:list", tagList);
        } else {
          tagList.value = data;
        }
      },
      { immediate: true }
    );
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", _hoisted_1, [
        (openBlock(true), createElementBlock(Fragment, null, renderList(unref(tagList), (item, index) => {
          return openBlock(), createElementBlock("div", {
            key: item[__props.defaultKey],
            style: normalizeStyle(unref(tagStyle)(item, index)),
            class: "tag",
            onClick: ($event) => onSelect(item)
          }, [
            createVNode(_sfc_main$1, {
              avatarUrl: __props.avatarUrl,
              keywords: item[__props.wordsKey],
              text: item[__props.textKey],
              number: item[__props.numberKey]
            }, null, 8, ["avatarUrl", "keywords", "text", "number"])
          ], 12, _hoisted_2);
        }), 128))
      ], 512);
    };
  }
});
var __uno = "";
_sfc_main.install = (app) => {
  app.component(_sfc_main.name, _sfc_main);
};
export { _sfc_main as default };
