import { defineComponent, ref, computed, watch, openBlock, createElementBlock, normalizeClass, unref, normalizeStyle, createCommentVNode, renderSlot, createElementVNode, withModifiers, createVNode, toDisplayString, onMounted, onBeforeUnmount, createBlock, Teleport, withCtx } from "vue";
import WlSvg from "@wltech/svg";
import { Popover } from "vant";
import dayjs from "dayjs";
const domain = "https://wlmvp-cos.weiling.cn";
const loadingPic = domain + "/frontend/weilingMobileUI/loading.png";
const loadingFailPic = domain + "/frontend/weilingMobileUI/loadingFail.png";
const xw_avatar = domain + "/frontend/weilingMobileUI/xw-avatar.png";
const xw_btn_border = domain + "/frontend/weilingMobileUI/contact-xw/btn-border.png";
const xw_ai = domain + "/frontend/weilingMobileUI/contact-xw/xw-ai.png";
const xw_ai_icon = domain + "/frontend/weilingMobileUI/contact-xw/xw-ai-icon.png";
const xw_third_anniversary = domain + "/frontend/weilingMobileUI/contact-xw/w-third-anniversary.png";
var listener = {
  addEvent(el, event, handler) {
    if (!el) {
      return;
    }
    if (el.attachEvent) {
      el.attachEvent("on" + event, handler);
    } else if (el.addEventListener) {
      el.addEventListener(event, handler, true);
    } else {
      el["on" + event] = handler;
    }
  },
  removeEvent(el, event, handler) {
    if (!el) {
      return;
    }
    if (el.detachEvent) {
      el.detachEvent("on" + event, handler);
    } else if (el.removeEventListener) {
      el.removeEventListener(event, handler, true);
    } else {
      el["on" + event] = null;
    }
  }
};
var employeeSelector = {
  employeeData: null,
  topFiveEmployeeData: null,
  organization: null,
  organization_count: null,
  count: 0,
  dept_list: [],
  company_list: [],
  company_list_count: 0,
  companyEmployeeList: [],
  totalCompanyEmployeeList: [],
  totalCompanyEmployeeObjList: []
};
const Store = {
  sid: "",
  app_id: "",
  user_id: "",
  user_name: "",
  corp_id: "",
  node_env: "",
  domain: "",
  token: "",
  card_resource: "",
  employeeSelector
};
var Store$1 = new Proxy(Store, {
  get(target, name, property) {
    return Reflect.get(target, name, property);
  },
  set(target, name, value, property) {
    return Reflect.set(target, name, value, property);
  }
});
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$2 = ["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$2)) : createCommentVNode("", true),
        renderSlot(_ctx.$slots, "picFooter")
      ], 2);
    };
  }
});
var __uno = "";
_sfc_main$2.install = (app) => {
  app.component(_sfc_main$2.name, _sfc_main$2);
};
var AlphaTest_vue_vue_type_style_index_0_scoped_true_lang = "";
var _export_sfc = (sfc, props) => {
  const target = sfc.__vccOpts || sfc;
  for (const [key, val] of props) {
    target[key] = val;
  }
  return target;
};
const _hoisted_1$1 = { class: "switch-page" };
const _hoisted_2$1 = ["onClick"];
const _hoisted_3$1 = { class: "btn-border" };
const __default__$1 = {
  name: "ContactxwTest"
};
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
  ...__default__$1,
  props: {
    isNormal: { type: Boolean, default: true },
    needGray: { type: Boolean, default: false }
  },
  emits: ["openXWAi"],
  setup(__props, { emit }) {
    const props = __props;
    function switchGray() {
      if (props.isNormal) {
        let d = new Date();
        d.setTime(d.getTime() + 365 * 24 * 60 * 60 * 1e3);
        let expires = "expires=" + d.toUTCString();
        document.cookie = "env=gray;path=/;" + expires;
      } else {
        let d = new Date();
        d.setTime(d.getTime() + 2 * 24 * 60 * 60 * 1e3);
        let expires = "expires=" + d.toUTCString();
        document.cookie = "env=tmp-prod;path=/;" + expires;
      }
      window.location.reload();
    }
    const openXWAi = () => {
      emit("openXWAi");
    };
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", _hoisted_1$1, [
        createElementVNode("div", {
          class: "switch-btn",
          onClick: withModifiers(openXWAi, ["stop"])
        }, [
          createVNode(unref(_sfc_main$2), { src: unref(xw_ai) }, null, 8, ["src"])
        ], 8, _hoisted_2$1),
        __props.needGray || !__props.isNormal ? (openBlock(), createElementBlock("div", {
          key: 0,
          class: "switch-btn",
          onClick: switchGray
        }, [
          createElementVNode("div", _hoisted_3$1, [
            createVNode(unref(_sfc_main$2), { src: unref(xw_btn_border) }, null, 8, ["src"])
          ]),
          createVNode(unref(WlSvg), {
            type: "revoke",
            color: "var(--wl-primary-color)",
            height: "24",
            width: "24"
          }),
          createElementVNode("span", null, toDisplayString(__props.isNormal ? "\u4F53\u9A8C\u65B0\u7248" : "\u8FD4\u56DE\u65E7\u7248"), 1)
        ])) : createCommentVNode("", true)
      ]);
    };
  }
});
var AlphaTest = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-76460ec0"]]);
var index_vue_vue_type_style_index_0_scoped_true_lang = "";
var index_vue_vue_type_style_index_1_lang = "";
const _hoisted_1 = ["onTouchstart"];
const _hoisted_2 = { class: "assistant-container" };
const _hoisted_3 = ["onClick"];
const _hoisted_4 = ["src"];
const _hoisted_5 = ["src"];
const __default__ = {
  name: "BCContactXW"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
  ...__default__,
  props: {
    src: { default: Object.freeze(xw_avatar) },
    width: { default: 40 },
    height: { default: 40 },
    x: { default: 0 },
    y: { default: 0 },
    marginX: { default: 0 },
    bottomY: { default: -1 },
    isRight: { type: Boolean, default: false },
    draggable: { type: Boolean, default: true },
    adsorb: { type: Boolean, default: true },
    scrollHide: { type: Boolean, default: true },
    scrollX: { default: 10 },
    appendToBody: { type: Boolean, default: true },
    env_data: { default: () => {
      return {};
    } },
    needGray: { type: Boolean, default: false }
  },
  emits: ["dragstart", "dragging", "dragstop"],
  setup(__props, { emit }) {
    const props = __props;
    const userSelectNone = {
      userSelect: "none",
      MozUserSelect: "none",
      WebkitUserSelect: "none",
      MsUserSelect: "none"
    };
    const userSelectAuto = {
      userSelect: "auto",
      MozUserSelect: "auto",
      WebkitUserSelect: "auto",
      MsUserSelect: "auto"
    };
    const rawTop = ref(0);
    const rawLeft = ref(0);
    const top = ref(0);
    const left = ref(0);
    const bodyWidth = ref(0);
    const bodyHeight = ref(0);
    const mouseClickPosition = ref({
      mouseX: 0,
      mouseY: 0,
      left: 0,
      top: 0
    });
    const bounds = ref({
      minLeft: 0,
      maxLeft: 0,
      minTop: 0,
      maxTop: 0
    });
    const dragging = ref(false);
    const showtran = ref(false);
    const startScroll = ref(0);
    const stopScroll = ref(0);
    const timer = ref(null);
    const showPopover = ref(false);
    const isNormal = ref(true);
    const styleEM = computed(() => {
      return {
        position: "fixed",
        top: `${top.value}px`,
        left: `${left.value}px`,
        borderRadius: `${+props.height / 2}px`,
        ...dragging.value ? userSelectNone : userSelectAuto
      };
    });
    const isLeft = computed(() => {
      return left.value + +props.width / 2 < bodyWidth.value / 2;
    });
    const popoverPlacement = computed(() => {
      let placement = isLeft.value ? "top-start" : "top-end";
      if (top.value < 150) {
        placement = isLeft.value ? "bottom-start" : "bottom-end";
      }
      return placement;
    });
    watch(
      () => rawTop.value,
      (newTop) => {
        const boundsObj = bounds.value;
        if (boundsObj.maxTop === 0) {
          top.value = newTop;
          return;
        }
        if (boundsObj.minTop !== null && newTop < boundsObj.minTop) {
          newTop = boundsObj.minTop;
        } else if (boundsObj.maxTop !== null && boundsObj.maxTop < newTop) {
          newTop = boundsObj.maxTop;
        }
        top.value = newTop;
      }
    );
    watch(
      () => rawLeft.value,
      (newLeft) => {
        const boundsObj = bounds.value;
        if (boundsObj.maxTop === 0) {
          left.value = newLeft;
          return;
        }
        if (boundsObj.minLeft !== null && newLeft < boundsObj.minLeft) {
          newLeft = boundsObj.minLeft;
        } else if (boundsObj.maxLeft !== null && boundsObj.maxLeft < newLeft) {
          newLeft = boundsObj.maxLeft;
        }
        left.value = newLeft;
      }
    );
    watch(
      () => props.env_data,
      (val) => {
        Store$1.sid = val.sid;
        Store$1.corp_id = val.corp_id;
        Store$1.node_env = val.node_env;
        Store$1.token = val.token;
        Store$1.domain = val.domain;
      },
      {
        immediate: true,
        deep: true
      }
    );
    const init = () => {
      [bodyWidth.value, bodyHeight.value] = getBodySize();
      bounds.value = calcDragLimits();
      if (props.isRight && props.x == 0) {
        rawLeft.value = left.value = bounds.value.maxLeft;
      } else {
        rawLeft.value = +props.x < +props.marginX ? +props.marginX : +props.x;
      }
      rawTop.value = top.value = +props.bottomY >= 0 && props.y == 0 ? bounds.value.maxTop - +props.bottomY : +props.y;
      if (props.adsorb) {
        listener.addEvent(document, "scroll", handleScroll);
      }
    };
    const getBodySize = () => {
      const style = window.getComputedStyle(document.body, null);
      return [
        parseInt(style.getPropertyValue("width"), 10),
        parseInt(style.getPropertyValue("height"), 10)
      ];
    };
    const calcDragLimits = () => {
      return {
        minLeft: 0 + +props.marginX,
        maxLeft: Math.floor(bodyWidth.value - +props.width - +props.marginX),
        minTop: 0,
        maxTop: Math.floor(bodyHeight.value - +props.height)
      };
    };
    const handleScroll = () => {
      showPopover.value = false;
      if (props.scrollHide) {
        if (timer.value)
          clearTimeout(timer.value);
        showtran.value = true;
        startScroll.value = document.documentElement.scrollTop || document.body.scrollTop;
        left.value = rawLeft.value = isLeft.value ? -parseInt(`${+props.width - +props.scrollX}`) : bounds.value.maxLeft + +props.marginX + parseInt(`${+props.width - +props.scrollX}`);
        timer.value = setTimeout(() => {
          stopScroll.value = document.documentElement.scrollTop || document.body.scrollTop;
          if (stopScroll.value == startScroll.value) {
            resetX("scroll");
          }
        }, 350);
      }
    };
    const handleDown = (e) => {
      if (props.draggable) {
        elementDown(e);
      }
    };
    const elementDown = (e) => {
      mouseClickPosition.value.left = left.value;
      mouseClickPosition.value.top = top.value;
      mouseClickPosition.value.mouseX = e.touches ? e.touches[0].pageX : e.pageX;
      mouseClickPosition.value.mouseY = e.touches ? e.touches[0].pageY : e.pageY;
      emit("dragstart", left.value, top.value);
      listener.addEvent(
        document.querySelector(".wl-contact-xw"),
        "touchmove",
        move
      );
      listener.addEvent(
        document.querySelector(".wl-contact-xw"),
        "touchend",
        handleUp
      );
    };
    const move = (e) => {
      showPopover.value = false;
      dragging.value = true;
      elementMove(e);
    };
    const elementMove = (e) => {
      const mouseClickPositionObj = mouseClickPosition.value;
      const tmpDeltaX = mouseClickPositionObj.mouseX - (e.touches ? e.touches[0].pageX : e.pageX) || 0;
      const tmpDeltaY = mouseClickPositionObj.mouseY - (e.touches ? e.touches[0].pageY : e.pageY) || 0;
      if (!tmpDeltaX && !tmpDeltaY)
        return;
      rawTop.value = mouseClickPositionObj.top - tmpDeltaY;
      rawLeft.value = mouseClickPositionObj.left - tmpDeltaX;
      emit("dragging", rawLeft.value, rawTop.value);
    };
    const handleUp = () => {
      rawTop.value = top.value;
      rawLeft.value = left.value;
      if (dragging.value)
        dragging.value = false;
      resetX("");
    };
    const resetX = (type) => {
      if (props.adsorb) {
        showtran.value = true;
        rawLeft.value = isLeft.value ? bounds.value.minLeft : bounds.value.maxLeft;
        setTimeout(() => {
          showtran.value = false;
        }, 400);
      }
      if (type != "scroll")
        emit("dragstop", rawLeft.value, rawTop.value);
      resetBoundsAndMouseState();
    };
    const resetBoundsAndMouseState = () => {
      mouseClickPosition.value = {
        mouseX: 0,
        mouseY: 0,
        left: 0,
        top: 0
      };
    };
    const handleXWImg = async () => {
      if (props.needGray || !isNormal.value) {
        showPopover.value = !showPopover.value;
        return;
      }
      openXWAi();
    };
    const isPre = computed(() => props.env_data.node_env === "stg");
    function autoBackToAlpha() {
      let d = new Date();
      d.setTime(d.getTime() + 365 * 24 * 60 * 60 * 1e3);
      let expires = "expires=" + d.toUTCString();
      document.cookie = "env=gray;path=/;" + expires;
      window.location.reload();
    }
    function judgeCookie() {
      let cookie = document.cookie;
      if (cookie == null ? void 0 : cookie.includes("env=tmp-prod")) {
        isNormal.value = true;
        return;
      }
      if (cookie == null ? void 0 : cookie.includes("env=gray")) {
        isNormal.value = false;
        return;
      }
      isNormal.value = true;
      if (props.needGray && !isPre.value) {
        autoBackToAlpha();
      }
    }
    const openXWAi = () => {
      var _a, _b;
      window.open(
        `${props.env_data.domain}/xiaoshifu/xiaowei-home?target=out&corp_id=${(_a = props.env_data) == null ? void 0 : _a.corp_id}&token=${(_b = props.env_data) == null ? void 0 : _b.token}&channel=worktableH5`
      );
    };
    const isHolidayShow = computed(() => {
      const nowTime = dayjs().valueOf();
      const holidayTime = dayjs("2023-12-15").valueOf();
      return nowTime < holidayTime;
    });
    onMounted(() => {
      init();
      judgeCookie();
    });
    onBeforeUnmount(() => {
      listener.removeEvent(
        document.querySelector(".wl-contact-xw"),
        "touchstart",
        handleDown
      );
      listener.removeEvent(
        document.querySelector(".wl-contact-xw"),
        "touchmove",
        move
      );
      listener.removeEvent(
        document.querySelector(".wl-contact-xw"),
        "touchend",
        handleUp
      );
    });
    return (_ctx, _cache) => {
      return openBlock(), createBlock(Teleport, {
        to: "body",
        disabled: !__props.appendToBody
      }, [
        createElementVNode("div", {
          class: normalizeClass(["wl-contact-xw", { "dra-tran": showtran.value }]),
          ref: "contactXwRef",
          style: normalizeStyle(unref(styleEM)),
          onTouchstart: withModifiers(handleDown, ["stop"]),
          onClick: _cache[1] || (_cache[1] = withModifiers(() => {
          }, ["stop"]))
        }, [
          createVNode(unref(Popover), {
            placement: unref(popoverPlacement),
            show: showPopover.value,
            "onUpdate:show": _cache[0] || (_cache[0] = ($event) => showPopover.value = $event),
            trigger: "click",
            class: "contact-xw-popover"
          }, {
            reference: withCtx(() => [
              createElementVNode("div", _hoisted_2, [
                createElementVNode("div", {
                  style: normalizeStyle({
                    width: `${__props.width}px`,
                    height: `${__props.height}px`
                  }),
                  onClick: withModifiers(handleXWImg, ["stop"]),
                  class: "assistant-content"
                }, [
                  unref(isHolidayShow) ? (openBlock(), createElementBlock("img", {
                    key: 0,
                    class: "assistant-birthday-hat",
                    alt: "",
                    src: unref(xw_third_anniversary)
                  }, null, 8, _hoisted_4)) : createCommentVNode("", true),
                  createVNode(_sfc_main$2, {
                    src: __props.src,
                    round: ""
                  }, null, 8, ["src"]),
                  createElementVNode("img", {
                    class: "assistant-ai",
                    alt: "",
                    src: unref(xw_ai_icon)
                  }, null, 8, _hoisted_5)
                ], 12, _hoisted_3)
              ])
            ]),
            default: withCtx(() => [
              __props.needGray || !isNormal.value ? (openBlock(), createBlock(AlphaTest, {
                key: 0,
                isNormal: isNormal.value,
                needGray: __props.needGray,
                onOpenXWAi: openXWAi
              }, null, 8, ["isNormal", "needGray"])) : createCommentVNode("", true)
            ]),
            _: 1
          }, 8, ["placement", "show"])
        ], 46, _hoisted_1)
      ], 8, ["disabled"]);
    };
  }
});
var Comp = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-6a0bc54a"]]);
Comp.install = (app) => {
  app.component(Comp.name, Comp);
};
export { Comp as default };
