import { defineComponent, ref, watch, onMounted, onUnmounted, withDirectives, openBlock, createElementBlock, createVNode, unref, vShow } from "vue";
import MemberInfo from "../MemberItemCommon/MemberInfo.vue.mjs";
import MemberControl from "../MemberControl/index.mjs";
import useMemberItem from "./useMemberItemHooks.mjs";
import vTap from "../../../directives/vTap.mjs";
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "indexH5",
  props: {
    userInfo: {}
  },
  setup(__props) {
    const props = __props;
    const memberItemContainerRef = ref();
    const { isMemberControlAccessible, openMemberControl, closeMemberControl } = useMemberItem(props.userInfo);
    const showMemberControl = ref(false);
    watch(isMemberControlAccessible, (accessible) => {
      if (accessible === false) {
        showMemberControl.value = false;
      }
    });
    const handleOpenMemberControl = (event) => {
      event.stopPropagation();
      openMemberControl();
      if (isMemberControlAccessible.value === true) {
        showMemberControl.value = true;
      }
    };
    const handleDocumentTouchend = (event) => {
      var _a;
      if ((_a = memberItemContainerRef.value) == null ? void 0 : _a.contains(event == null ? void 0 : event.target)) {
        return;
      }
      closeMemberControl();
      showMemberControl.value = false;
    };
    onMounted(() => {
      document.addEventListener("touchend", handleDocumentTouchend);
    });
    onUnmounted(() => {
      document.removeEventListener("touchend", handleDocumentTouchend);
    });
    return (_ctx, _cache) => {
      return withDirectives((openBlock(), createElementBlock("div", {
        ref_key: "memberItemContainerRef",
        ref: memberItemContainerRef,
        class: "member-item-container"
      }, [
        createVNode(MemberInfo, {
          "show-state-icon": true,
          "user-info": props.userInfo
        }, null, 8, ["user-info"]),
        withDirectives(createVNode(unref(MemberControl), {
          "show-member-control": showMemberControl.value,
          "user-info": props.userInfo,
          onOnCloseControl: handleDocumentTouchend
        }, null, 8, ["show-member-control", "user-info"]), [
          [vShow, showMemberControl.value]
        ])
      ])), [
        [unref(vTap), handleOpenMemberControl]
      ]);
    };
  }
});
export {
  _sfc_main as default
};
