import { defineComponent, ref, computed, watch, openBlock, createElementBlock, normalizeClass, unref, normalizeStyle, createCommentVNode, renderSlot, createBlock, watchEffect, Fragment, createElementVNode, createVNode, withDirectives, vModelText, toDisplayString } from "vue";
import WlSvg from "@wltech/svg";
const onDebounce = (fn, delay) => {
  let timer;
  return function(...args) {
    if (timer) {
      clearTimeout(timer);
    }
    timer = setTimeout(
      () => {
        typeof fn === "function" && fn.apply(null, [...args]);
        clearTimeout(timer);
      },
      delay > 0 ? delay : 100
    );
  };
};
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;
};
var deleteIcon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAACxLAAAsSwGlPZapAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAOiSURBVHgBzZrdceIwFIWvneTd+5iZJAMVZFNBTAdJBZstgQoCFaSEsBUkWwFsB2wFkJ+ZPC7vCbDneGTGFrYl2QL8zRiB/7jHku69khyIZ2azWYSigy06OjpiKcvlcq4OT7vd7kI8EkhDaHAYhnfYroMg+L5erztV5+P4HOdNUf6GsAkEzaUBtQXA8Pj4+PgeX2NpxgRifl1cXIykBs4CPBqegzWDYugqxFrAx8dH5+vr61E8G64DISM0raFt07ISoJ76E75GsgdUbfRRG8+mc0PTCW9vb/cwfix7Mp6gk3ewPfG/jedWHVQ3GMhhGZyfnw/LDpYKaInxKaUiCgW8vr7esAqlXfQgYqLv3BJAbwMvMDYFpAOwgBe80r3TVif+/PwctNB4EsGZPOo7cwLQdO7QdH5Ie4nRN+PsjpwA5DNGt9UCcjZuBPDp12k6DDrYbvHVJctc8BrU9lzcydXCRkCdpkPj0eF7jJi4vid2IhY8l9cg3e7VFLGphcQLqTxnJg6kxme9wvv7O9PpqqidGH92djZNd9T1erD3G8cWSQ3A88TiCP60r7s0GlZRE1vGk9PT0/lqteqLIxyDJKX6fSOO0KXxiev7S0QUGk94Dxx7FEdwTcwyEQA1l+JOxOZiIaLSeEOTqyKxOeCQEE/zn9Sn0kCWOzA+gf0gULn+WJpRKqIIH8YT/OeVcTxgSWlz0vFlPMF9ojCd+vCAUYRP4wldr68aOBhhZtKpKcZ+YIgTzjCKhycnJz5uZt2JfYsIEYXn0oxKN+oQ7JyBG52Gaq7yRephDFKWwc4Z5mKbXAg/rPy3hm2EjXYk4i8/UgETcQTX/HSIsJUieC9x55kfiQBkgyNx5wFRvJPdYfDzhSKYTiMXexBHOLPNMhGg+sHE5QacPUMQHKciLINUTkTdsQDO/5Om8tlANhRHMiJuHCJsIoJzTw2mb0YbG7J7MdakEbG0GHofDEe76W89lXCuhQOQszEnQE3dTaSlcO1AXwDZSuYwNqBL87oQ5wM1ibDVQrYEcJCN4lbaR79o1aYwnVZNqU39YVi2WmNa4BiINpV3AIZ4oIOyg8Y1sgOLqDSeWC3yMegw3O9x2p1O5LZoQUPHakiZzmNyQVp2DNMELmTYGE+cF7o5i81peN+1QcORmgxsDU+p/aoBhaDggsi1NKCu4SmNX/ZgRqkmh9lPLi1q5oUDKI5BmMY3fXulsQAdNVWZpMupGM4eYFtw/O37dZv/XhxunoTWr/gAAAAASUVORK5CYII=";
const domain = "https://wlmvp-cos.weiling.cn";
const loadingPic = domain + "/frontend/weilingMobileUI/loading.png";
const loadingFailPic = domain + "/frontend/weilingMobileUI/loadingFail.png";
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__$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$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 searchIcon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAACxLAAAsSwGlPZapAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAASNSURBVHgB7ZqPddowEMYvZAE6Qb1B0gmACUInKJkgZIKSCZJMEJigdAJMFijdQJmgdICEfgdyHzWnv7YMDfze8zNPdiLr00k66Y7oxIkTJ46YM0rMbDa7xI2v7Ozs7OP2s9Vq9Rs3pa9Fr9dT1DC1C4AGt3Hro7FXuLr43Q74cwVRclwTiJFTA9QmADe81Wrd4OeQwhptQr29vd1BiDElpLIACRpeJqkQlQRA47to/BN+ZpQYDIsprtu654loAebz+VfcRr7v4+NfMCco2kx4TKbvF+RvOWwNLMKUaiJYADZ5NOQe18Dx6hLXBB/MH8sz/NLyP9crBaypj/sVuRl1Op07qoEgAfR4n9FmWTOxHrO4T22NttSRoY4Rfn5xvFqLCEEC5Hn+ZOl5buwjPmpENeApxAD1TagC3gI4xjz3ei+FIwMhhhCC6xbnCdT7CfUuKBIvAfARfXzEN8PjhW58sLn7wnOErj8THistQlT9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vFAAAAAElFTkSuQmCC";
const __default__$1 = {
  name: "WlSvgIcon"
};
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
  ...__default__$1,
  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"]);
    };
  }
});
var index_vue_vue_type_style_index_0_lang = "";
const _hoisted_1 = {
  class: "search-wrap",
  "data-weiling-mobile-ui-wl-search": ""
};
const _hoisted_2 = { class: "search-icon" };
const _hoisted_3 = { class: "search-input" };
const _hoisted_4 = ["placeholder"];
const _hoisted_5 = { class: "action" };
const _hoisted_6 = { class: "default-search-content" };
const _hoisted_7 = { class: "search-text" };
const __default__ = {
  name: "WlSearch"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
  ...__default__,
  props: {
    modelValue: { default: "" },
    icon: { default: searchIcon },
    placeholder: { default: "\u641C\u7D22" },
    closable: { type: Boolean, default: true },
    needBorder: { type: Boolean, default: true },
    showType: { default: "search" }
  },
  emits: ["onClear", "onClickDefault", "onChange", "onBlurChange", "onChinaChange", "update:modelValue"],
  setup(__props, { expose, emit }) {
    const props = __props;
    const fieldValue = ref("");
    const is_focus = ref(false);
    const inputRef = ref(null);
    let isChinaInput = false;
    const searchClass = computed(() => {
      return {
        search: true,
        "search-focus": is_focus.value,
        "search-border": props.needBorder
      };
    });
    const onClickDefault = () => emit("onClickDefault");
    const onClear = () => {
      fieldValue.value = "";
      emit("update:modelValue", "");
      emit("onChange", "");
      emit("onClear");
    };
    const onDebounceSave = onDebounce((event) => {
      if (!isChinaInput) {
        const val = event.target.value;
        emit("update:modelValue", val);
        emit("onChange", val);
      }
    }, 300);
    const onContentChange = onDebounce((event) => {
      var _a;
      const val = (_a = event.target) == null ? void 0 : _a.value;
      emit("update:modelValue", val);
      emit("onBlurChange", val);
    }, 300);
    const compositionend = () => {
      isChinaInput = false;
    };
    const compositionstart = () => {
      isChinaInput = true;
    };
    const onFocus = () => {
      var _a;
      (_a = inputRef.value) == null ? void 0 : _a.focus();
    };
    expose({
      onFocus,
      inputEl: inputRef
    });
    watch(
      () => fieldValue.value,
      (val) => {
        emit("update:modelValue", val);
      }
    );
    watchEffect(() => {
      fieldValue.value = props.modelValue;
    });
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", _hoisted_1, [
        __props.showType === "search" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
          createElementVNode("div", {
            class: normalizeClass(unref(searchClass))
          }, [
            createElementVNode("div", _hoisted_2, [
              createVNode(_sfc_main$2, { src: __props.icon }, null, 8, ["src"])
            ]),
            createElementVNode("div", _hoisted_3, [
              withDirectives(createElementVNode("input", {
                type: "text",
                placeholder: __props.placeholder,
                "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => fieldValue.value = $event),
                ref_key: "inputRef",
                ref: inputRef,
                onInput: _cache[1] || (_cache[1] = (...args) => unref(onDebounceSave) && unref(onDebounceSave)(...args)),
                onChange: _cache[2] || (_cache[2] = (...args) => unref(onContentChange) && unref(onContentChange)(...args)),
                onFocus: _cache[3] || (_cache[3] = ($event) => is_focus.value = true),
                onBlur: _cache[4] || (_cache[4] = ($event) => is_focus.value = false),
                onCompositionend: compositionend,
                onCompositionstart: compositionstart
              }, null, 40, _hoisted_4), [
                [vModelText, fieldValue.value]
              ])
            ]),
            __props.closable && fieldValue.value ? (openBlock(), createElementBlock("div", {
              key: 0,
              class: "search-close-icon",
              onClick: onClear
            }, [
              createVNode(_sfc_main$2, { src: unref(deleteIcon) }, null, 8, ["src"])
            ])) : createCommentVNode("", true)
          ], 2),
          createElementVNode("div", _hoisted_5, [
            renderSlot(_ctx.$slots, "action")
          ])
        ], 64)) : createCommentVNode("", true),
        __props.showType === "default" ? (openBlock(), createElementBlock("div", {
          key: 1,
          class: "default-search",
          onClick: onClickDefault
        }, [
          createElementVNode("div", _hoisted_6, [
            createVNode(_sfc_main$1, {
              type: "search",
              width: "18",
              height: "18",
              color: "#c1c1c1"
            }),
            createElementVNode("span", _hoisted_7, toDisplayString(__props.placeholder), 1)
          ])
        ])) : createCommentVNode("", true)
      ]);
    };
  }
});
var __uno = "";
_sfc_main.install = (app) => {
  app.component(_sfc_main.name, _sfc_main);
};
export { _sfc_main as default };
