"use strict";
const common_vendor = require("../../../../common/vendor.js");
require("../../../adapter-vue.js");
const TUIKit_constant = require("../../../constant.js");
const TUIKit_utils_env = require("../../../utils/env.js");
if (!Math) {
  (Dialog + Overlay)();
}
const Overlay = () => "../../common/Overlay/index.js";
const Dialog = () => "../../common/Dialog/index.js";
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "index",
  props: {
    actionsMenuPosition: {},
    selectedConversation: {},
    selectedConversationDomRect: {}
  },
  emits: ["closeConversationActionMenu"],
  setup(__props, { emit: __emit }) {
    var _a, _b;
    const emits = __emit;
    const props = __props;
    const thisInstance = ((_a = common_vendor.getCurrentInstance()) == null ? void 0 : _a.proxy) || common_vendor.getCurrentInstance();
    const actionsMenuDomRef = common_vendor.ref();
    const isHiddenActionsMenu = common_vendor.ref(true);
    const isShowDeleteConversationDialog = common_vendor.ref(false);
    const currentConversation = common_vendor.Jt.getConversationModel(
      ((_b = props.selectedConversation) == null ? void 0 : _b.conversationID) || ""
    );
    const _actionsMenuPosition = common_vendor.ref(props.actionsMenuPosition);
    common_vendor.onMounted(() => {
      checkExceedBounds();
    });
    const deleteConversationDialogTitle = common_vendor.computed(() => {
      var _a2, _b2;
      return ((_a2 = props.selectedConversation) == null ? void 0 : _a2.type) === common_vendor.qt.TYPES.CONV_C2C ? "TUIConversation.删除后，将清空该聊天的消息记录" : ((_b2 = props.selectedConversation) == null ? void 0 : _b2.type) === common_vendor.qt.TYPES.CONV_GROUP ? "TUIConversation.删除后，将清空该群聊的消息记录" : "";
    });
    function checkExceedBounds() {
      common_vendor.nextTick$1(() => {
        var _a2, _b2;
        if (TUIKit_utils_env.isUniFrameWork) {
          const query = (_a2 = common_vendor.i) == null ? void 0 : _a2.createSelectorQuery().in(thisInstance);
          query.select(`#conversation-actions-menu`).boundingClientRect((data) => {
            var _a3, _b3;
            if (data) {
              if (data.bottom > ((_b3 = (_a3 = common_vendor.i) == null ? void 0 : _a3.getWindowInfo) == null ? void 0 : _b3.call(_a3).windowHeight)) {
                _actionsMenuPosition.value = {
                  ...props.actionsMenuPosition,
                  top: props.actionsMenuPosition.top - (props.actionsMenuPosition.conversationHeight || 0) - data.height
                };
              }
              if (_actionsMenuPosition.value.left + data.width + 5 > common_vendor.i.getWindowInfo().windowWidth) {
                _actionsMenuPosition.value.left = common_vendor.i.getWindowInfo().windowWidth - data.width - 5;
              }
            }
            isHiddenActionsMenu.value = false;
          }).exec();
        } else {
          const rect = (_b2 = actionsMenuDomRef.value) == null ? void 0 : _b2.getBoundingClientRect();
          if (TUIKit_utils_env.isPC && typeof props.actionsMenuPosition.left !== "undefined") {
            _actionsMenuPosition.value.left = props.actionsMenuPosition.left;
          }
          if (rect && rect.bottom > window.innerHeight) {
            _actionsMenuPosition.value.top = props.actionsMenuPosition.top - (props.actionsMenuPosition.conversationHeight || 0) - rect.height;
          }
          isHiddenActionsMenu.value = false;
        }
      });
    }
    const handleItem = (params) => {
      const { name } = params;
      const conversationModel = currentConversation;
      if (!name || !conversationModel || !conversationModel.conversationID) {
        return;
      }
      switch (name) {
        case TUIKit_constant.CONV_OPERATION.DELETE:
          conversationModel == null ? void 0 : conversationModel.deleteConversation();
          break;
        case TUIKit_constant.CONV_OPERATION.ISPINNED:
          conversationModel == null ? void 0 : conversationModel.pinConversation();
          break;
        case TUIKit_constant.CONV_OPERATION.DISPINNED:
          conversationModel == null ? void 0 : conversationModel.pinConversation();
          break;
        case TUIKit_constant.CONV_OPERATION.MUTE:
          conversationModel == null ? void 0 : conversationModel.muteConversation();
          break;
        case TUIKit_constant.CONV_OPERATION.NOTMUTE:
          conversationModel == null ? void 0 : conversationModel.muteConversation();
          break;
      }
      emits("closeConversationActionMenu");
    };
    const deleteConversation = () => {
      isShowDeleteConversationDialog.value = true;
    };
    const updateShowDeleteConversationDialog = (isShow) => {
      if (!isShow) {
        emits("closeConversationActionMenu");
      }
      isShowDeleteConversationDialog.value = isShow;
    };
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.t(common_vendor.unref(common_vendor.Wt).t("TUIConversation.删除会话")),
        b: common_vendor.o$1(($event) => deleteConversation()),
        c: !(props.selectedConversation && props.selectedConversation.isPinned)
      }, !(props.selectedConversation && props.selectedConversation.isPinned) ? {
        d: common_vendor.t(common_vendor.unref(common_vendor.Wt).t("TUIConversation.置顶会话")),
        e: common_vendor.o$1(($event) => handleItem({
          name: common_vendor.unref(TUIKit_constant.CONV_OPERATION).ISPINNED
        }))
      } : {}, {
        f: props.selectedConversation && props.selectedConversation.isPinned
      }, props.selectedConversation && props.selectedConversation.isPinned ? {
        g: common_vendor.t(common_vendor.unref(common_vendor.Wt).t("TUIConversation.取消置顶")),
        h: common_vendor.o$1(($event) => handleItem({
          name: common_vendor.unref(TUIKit_constant.CONV_OPERATION).DISPINNED
        }))
      } : {}, {
        i: !(props.selectedConversation && props.selectedConversation.isMuted)
      }, !(props.selectedConversation && props.selectedConversation.isMuted) ? {
        j: common_vendor.t(common_vendor.unref(common_vendor.Wt).t("TUIConversation.消息免打扰")),
        k: common_vendor.o$1(($event) => handleItem({
          name: common_vendor.unref(TUIKit_constant.CONV_OPERATION).MUTE
        }))
      } : {}, {
        l: props.selectedConversation && props.selectedConversation.isMuted
      }, props.selectedConversation && props.selectedConversation.isMuted ? {
        m: common_vendor.t(common_vendor.unref(common_vendor.Wt).t("TUIConversation.取消免打扰")),
        n: common_vendor.o$1(($event) => handleItem({
          name: common_vendor.unref(TUIKit_constant.CONV_OPERATION).NOTMUTE
        }))
      } : {}, {
        o: common_vendor.n(common_vendor.unref(TUIKit_utils_env.isPC) && "actions-menu-pc"),
        p: common_vendor.n(!common_vendor.unref(isHiddenActionsMenu) && "cancel-hidden"),
        q: `${common_vendor.unref(_actionsMenuPosition).top}px`,
        r: `${common_vendor.unref(_actionsMenuPosition).left}px`,
        s: common_vendor.t(common_vendor.unref(common_vendor.Wt).t(common_vendor.unref(deleteConversationDialogTitle))),
        t: common_vendor.o$1(($event) => handleItem({
          name: common_vendor.unref(TUIKit_constant.CONV_OPERATION).DELETE
        })),
        v: common_vendor.o$1(updateShowDeleteConversationDialog),
        w: common_vendor.p({
          show: common_vendor.unref(isShowDeleteConversationDialog),
          center: true,
          isHeaderShow: common_vendor.unref(TUIKit_utils_env.isPC)
        }),
        x: common_vendor.o$1(() => emits("closeConversationActionMenu")),
        y: common_vendor.p({
          maskColor: "transparent"
        })
      });
    };
  }
});
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-63e37304"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/TUIKit/components/TUIConversation/actions-menu/index.js.map
