import { defineComponent, ref, computed, watch, openBlock, createElementBlock, normalizeClass, unref, normalizeStyle, createCommentVNode, renderSlot, useSlots, watchEffect, createBlock, createSlots, withCtx, createElementVNode, markRaw, defineAsyncComponent, withModifiers, toDisplayString, createVNode, Fragment, renderList, Suspense } from "vue";
import { Popover } from "vant";
const domain = "https://wlmvp-cos.weiling.cn";
const loadingPic = domain + "/frontend/weilingMobileUI/loading.png";
const loadingFailPic = domain + "/frontend/weilingMobileUI/loadingFail.png";
const en_default_logo = domain + "/frontend/images/company-default-logo.png";
const select_plat_icon = domain + "/frontend/weilingMobileUI/select_plat.png";
const arrow_trg_icon = domain + "/frontend/weilingMobileUI/arrow-trg.png";
const calendar_icon = domain + "/frontend/weilingMobileUI/calendar.png";
const bo_recommand_popup = domain + "/frontend/weilingMobileUI/bo-recommand-popup.png";
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;
};
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);
    };
  }
});
const __default__$1 = {
  name: "WlPopover"
};
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
  ...__default__$1,
  props: {
    actions: { default: null },
    modelValue: { type: Boolean, default: false }
  },
  emits: ["update:modelValue", "onSelect"],
  setup(__props, { emit }) {
    const props = __props;
    const slots = useSlots();
    const hasDefault = ref(slots.default !== void 0);
    const slotName = computed(() => hasDefault.value ? "default" : "content");
    const popoverVisible = ref(false);
    const onTogglePopover = (bool) => {
      popoverVisible.value = bool;
      emit("update:modelValue", bool);
    };
    const onSelect = (val) => {
      emit("onSelect", val);
      onTogglePopover(false);
    };
    watchEffect(() => {
      popoverVisible.value = props.modelValue;
    });
    return (_ctx, _cache) => {
      return openBlock(), createBlock(unref(Popover), {
        show: popoverVisible.value,
        "onUpdate:show": _cache[1] || (_cache[1] = ($event) => popoverVisible.value = $event),
        actions: __props.actions,
        onSelect
      }, createSlots({
        reference: withCtx(() => [
          renderSlot(_ctx.$slots, "reference")
        ]),
        _: 2
      }, [
        hasDefault.value ? {
          name: unref(slotName),
          fn: withCtx(() => [
            createElementVNode("div", {
              onClick: _cache[0] || (_cache[0] = ($event) => popoverVisible.value = false)
            }, [
              renderSlot(_ctx.$slots, "default")
            ])
          ])
        } : void 0
      ]), 1032, ["show", "actions"]);
    };
  }
});
var index_vue_vue_type_style_index_0_lang = "";
const _hoisted_1 = { class: "list-item" };
const _hoisted_2 = ["onClick"];
const _hoisted_3 = {
  key: 0,
  class: "arrow"
};
const _hoisted_4 = { class: "icon" };
const __default__ = {
  name: "BCBusinessStagePopup"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
  ...__default__,
  props: {
    modelValue: { default: null },
    businessOppDetail: { default: null },
    isEdit: { type: Boolean, default: true },
    stageList: { default: null },
    stageFailList: { default: null },
    maxWidth: { default: null }
  },
  emits: ["onClickItem", "onFail", "onSuccess", "update:modelValue"],
  setup(__props, { emit }) {
    const props = __props;
    const FailPopup = markRaw(
      defineAsyncComponent(() => import("./index3.js"))
    );
    const SucessPopup = markRaw(
      defineAsyncComponent(() => import("./index5.js"))
    );
    const default_color = "#6236FF";
    const default_background_color = "#F6F0FF";
    const stage_base_setting = {
      "4": {
        color: "rgba(98, 54, 255, 1)",
        backgroundColor: "rgba(246, 240, 255, 1)"
      },
      "2": {
        color: "rgba(98, 54, 255, 1)",
        backgroundColor: "rgba(246, 240, 255, 1)"
      },
      "100": {
        color: "rgba(255, 69, 69, 1)",
        type: "success",
        backgroundColor: "rgba(255, 242, 240, 1)"
      },
      "99": {
        color: "rgba(137, 138, 141, 1)",
        type: "fail",
        backgroundColor: "rgba(242, 242, 242, 1)"
      }
    };
    const successPopupVisibe = ref(false);
    const failPopupVisible = ref(false);
    const actionVisible = ref(false);
    const stageData = ref(null);
    const filterData = (list, key) => {
      let data = null;
      for (let i = 0; i < 2; i++) {
        const stage = list[i];
        const len = stage.length;
        for (let i2 = 0; i2 < len; i2++) {
          const ele = stage[i2];
          if (ele.key == key) {
            data = ele;
          }
        }
      }
      return data;
    };
    const item_style = computed(() => {
      return function(item) {
        const { key = "" } = props.modelValue;
        const { key: itemKey } = item;
        const is_select = key === itemKey;
        return {
          "--color": is_select ? item.color : "rgba(0, 0, 0, 1)",
          "--backgroundColor": is_select ? item.backgroundColor : "transparent"
        };
      };
    });
    const info_style = computed(() => {
      const { value = "", key = "" } = props.modelValue;
      if (value) {
        const setting = stage_base_setting[key + ""];
        const {
          color = default_color,
          backgroundColor = default_background_color
        } = setting || {};
        return {
          "--color": color,
          "--backgroundColor": backgroundColor
        };
      } else if (key) {
        const data = filterData(business_opportunity_stage_list.value, key);
        const {
          color = default_color,
          backgroundColor = default_background_color
        } = data || {};
        return {
          "--color": color,
          "--backgroundColor": backgroundColor
        };
      }
      return {};
    });
    const info_text = computed(() => {
      const { value = "", key = "" } = props.modelValue;
      if (value) {
        return value;
      } else if (key) {
        const data = filterData(business_opportunity_stage_list.value, key) || {};
        return data.value;
      }
      return "";
    });
    const business_opportunity_stage_list = computed(() => {
      var _a;
      const fail_list2 = props.stageFailList || [];
      const list_len = (_a = props.stageList) == null ? void 0 : _a.length;
      let list = [];
      let last_list = [];
      for (let i = 0; i < list_len; i++) {
        const ele = props.stageList[i];
        const { key = "" } = ele;
        if (key + "" === "99") {
          last_list.push({
            ...ele,
            fail_list: fail_list2,
            ...stage_base_setting[key]
          });
        } else {
          const setting = stage_base_setting[key] || {
            color: default_color,
            backgroundColor: default_background_color
          };
          list.push({
            fail_list: fail_list2,
            ...ele,
            ...setting
          });
        }
      }
      return [list, last_list];
    });
    const fail_list = computed(() => {
      var _a;
      const fail_list2 = ((_a = props.stageFailList) != null ? _a : []).map((ele) => {
        return {
          ...ele,
          name: ele.value,
          type: ele.key + "" === "99" ? "ipt" : ""
        };
      });
      return fail_list2;
    });
    const popover_style = computed(() => {
      if (!props.maxWidth)
        return {};
      if (typeof props.maxWidth === "number") {
        return {
          "max-width": props.maxWidth + "px"
        };
      }
      return {
        "max-width": props.maxWidth
      };
    });
    const onClickItem = (item) => {
      const { type = "" } = item;
      stageData.value = item;
      emit("onClickItem", { stage: item });
      actionVisible.value = false;
      if (type === "success") {
        successPopupVisibe.value = true;
        failPopupVisible.value = false;
      } else if (type === "fail") {
        successPopupVisibe.value = false;
        failPopupVisible.value = true;
      } else {
        emit("update:modelValue", item);
        failPopupVisible.value = false;
        successPopupVisibe.value = false;
      }
    };
    const onFailConfirm = (data) => {
      emit("onFail", { ...data, stage: stageData.value });
      successPopupVisibe.value = false;
      failPopupVisible.value = false;
      emit("update:modelValue", stageData.value);
    };
    const onPopupSuccess = (data) => {
      emit("onSuccess", { stage_value: data, stage: stageData.value });
      successPopupVisibe.value = false;
      failPopupVisible.value = false;
      emit("update:modelValue", stageData.value);
    };
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", {
        onClick: _cache[3] || (_cache[3] = withModifiers(() => {
        }, ["stop"])),
        class: "bo-stage",
        "data-weiling-mobile-ui-bc-business-stage-popup": ""
      }, [
        __props.isEdit ? (openBlock(), createBlock(_sfc_main$1, {
          key: 0,
          modelValue: actionVisible.value,
          "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => actionVisible.value = $event),
          trigger: "click",
          placement: "bottom-start"
        }, {
          reference: withCtx(() => [
            createElementVNode("div", {
              class: "info",
              style: normalizeStyle(unref(info_style))
            }, [
              createElementVNode("p", null, toDisplayString(unref(info_text)), 1),
              createElementVNode("div", _hoisted_4, [
                createVNode(_sfc_main$2, { src: unref(select_plat_icon) }, null, 8, ["src"])
              ])
            ], 4)
          ]),
          default: withCtx(() => [
            createElementVNode("div", {
              class: "business-opportunity-status-popover",
              "data-weiling-mobile-ui-bc-business-stage-popup-content": "",
              style: normalizeStyle(unref(popover_style))
            }, [
              (openBlock(true), createElementBlock(Fragment, null, renderList(unref(business_opportunity_stage_list), (parent, index) => {
                return openBlock(), createElementBlock("div", {
                  key: index,
                  class: "list"
                }, [
                  createElementVNode("div", _hoisted_1, [
                    (openBlock(true), createElementBlock(Fragment, null, renderList(parent, (item, index2) => {
                      return openBlock(), createElementBlock("div", {
                        class: "item-wrap",
                        key: item.key,
                        onClick: withModifiers(($event) => onClickItem(item), ["stop"])
                      }, [
                        createElementVNode("div", {
                          class: "item",
                          style: normalizeStyle(unref(item_style)(item))
                        }, toDisplayString(item.value), 5),
                        index2 !== parent.length - 1 ? (openBlock(), createElementBlock("div", _hoisted_3, [
                          createVNode(_sfc_main$2, { src: unref(arrow_trg_icon) }, null, 8, ["src"])
                        ])) : createCommentVNode("", true)
                      ], 8, _hoisted_2);
                    }), 128))
                  ])
                ]);
              }), 128))
            ], 4)
          ]),
          _: 1
        }, 8, ["modelValue"])) : (openBlock(), createElementBlock("div", {
          key: 1,
          class: "info",
          style: normalizeStyle(unref(info_style))
        }, [
          createElementVNode("p", null, toDisplayString(unref(info_text)), 1)
        ], 4)),
        failPopupVisible.value ? (openBlock(), createBlock(Suspense, { key: 2 }, {
          default: withCtx(() => [
            createVNode(unref(FailPopup), {
              modelValue: failPopupVisible.value,
              "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => failPopupVisible.value = $event),
              list: unref(fail_list),
              onOnConfirmField: onFailConfirm,
              onOnConfirm: onFailConfirm
            }, null, 8, ["modelValue", "list"])
          ]),
          _: 1
        })) : createCommentVNode("", true),
        successPopupVisibe.value ? (openBlock(), createBlock(Suspense, { key: 3 }, {
          default: withCtx(() => [
            createVNode(unref(SucessPopup), {
              modelValue: successPopupVisibe.value,
              "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => successPopupVisibe.value = $event),
              data: __props.businessOppDetail,
              onOnSubmit: onPopupSuccess
            }, null, 8, ["modelValue", "data"])
          ]),
          _: 1
        })) : createCommentVNode("", true)
      ]);
    };
  }
});
var __uno = "";
_sfc_main.install = (app) => {
  app.component(_sfc_main.name, _sfc_main);
};
export { _sfc_main$2 as _, _sfc_main as a, bo_recommand_popup as b, calendar_icon as c, en_default_logo as e, onDebounce as o };
