import { defineComponent, ref, computed, createElementBlock, openBlock, Fragment, createVNode, unref, withCtx, createElementVNode, toDisplayString, createBlock, createCommentVNode, createTextVNode } from "vue";
import { useUIKit, IconInvite, TUIPopup, IconShare, TUIButton, TUIToast } from "@tencentcloud/uikit-base-component-vue3";
import { useContactListState } from "tuikit-atomicx-vue3/chat";
import { useRoomState, useRoomParticipantState, RoomParticipantStatus, UserPicker } from "tuikit-atomicx-vue3/room";
import IconButtonH5 from "../base/IconButtonH5.vue2.mjs";
import PopUpArrowDown from "../base/PopUpArrowDown.vue2.mjs";
import RoomShare from "./RoomShare.vue2.mjs";
const _hoisted_1 = { class: "operate-list" };
const _hoisted_2 = { class: "operate-item-text" };
const _hoisted_3 = { class: "operate-item-text" };
const _hoisted_4 = { class: "room-share-content" };
const _hoisted_5 = { class: "room-share-header" };
const _hoisted_6 = { class: "user-picker-content" };
const _hoisted_7 = { class: "user-picker-header" };
const _hoisted_8 = { class: "user-picker-footer" };
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  setup(__props) {
    const { t } = useUIKit();
    const { currentRoom, callUserToRoom } = useRoomState();
    const { participantList, pendingParticipantList } = useRoomParticipantState();
    const { friendList } = useContactListState();
    const isVisible = ref(false);
    const userPickerRef = ref();
    const userPickerVisible = ref(false);
    const roomShareVisible = ref(false);
    const userPickerData = computed(() => friendList.value.filter((item) => !participantList.value.some((participant) => participant.userId === item.userID)).filter((item) => !pendingParticipantList.value.some((user) => user.userId === item.userID && user.roomStatus === RoomParticipantStatus.InCalling)).map((item) => ({
      key: item.userID,
      label: item.nick,
      avatarUrl: item.avatar,
      extraData: item
    })));
    const handleUserPickerConfirm = async () => {
      var _a;
      try {
        const selectedUsers = userPickerRef.value.getSelectedItems();
        if (selectedUsers.length === 0) {
          TUIToast.error({ message: t("Invite.PleaseSelectUser") });
          return;
        }
        await callUserToRoom({
          roomId: (_a = currentRoom.value) == null ? void 0 : _a.roomId,
          userIdList: selectedUsers.map((item) => item.key),
          timeout: 60
        });
        userPickerVisible.value = false;
        TUIToast.success({ message: t("Invite.InviteSuccess") });
      } catch (error) {
        console.error("Failed to invite users to room:", error);
        TUIToast.error({ message: t("Invite.InviteFailed") });
      }
    };
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock(Fragment, null, [
        createVNode(IconButtonH5, {
          title: unref(t)("Invite.Title"),
          onClick: _cache[0] || (_cache[0] = ($event) => isVisible.value = true)
        }, {
          default: withCtx(() => [
            createVNode(unref(IconInvite), { size: 24 })
          ]),
          _: 1
        }, 8, ["title"]),
        createVNode(unref(TUIPopup), {
          visible: isVisible.value,
          "onUpdate:visible": _cache[4] || (_cache[4] = ($event) => isVisible.value = $event)
        }, {
          default: withCtx(() => [
            createVNode(PopUpArrowDown, {
              onClick: _cache[1] || (_cache[1] = ($event) => isVisible.value = false)
            }),
            createElementVNode("div", _hoisted_1, [
              createElementVNode("div", {
                class: "operate-item",
                onClick: _cache[2] || (_cache[2] = ($event) => userPickerVisible.value = true)
              }, [
                createVNode(unref(IconInvite), { size: 18 }),
                createElementVNode("span", _hoisted_2, toDisplayString(unref(t)("Invite.AddMember")), 1)
              ]),
              createElementVNode("div", {
                class: "operate-item",
                onClick: _cache[3] || (_cache[3] = ($event) => roomShareVisible.value = true)
              }, [
                createVNode(unref(IconShare), { size: 18 }),
                createElementVNode("span", _hoisted_3, toDisplayString(unref(t)("Invite.ShareRoom")), 1)
              ])
            ])
          ]),
          _: 1
        }, 8, ["visible"]),
        createVNode(unref(TUIPopup), {
          visible: roomShareVisible.value,
          "onUpdate:visible": _cache[6] || (_cache[6] = ($event) => roomShareVisible.value = $event)
        }, {
          default: withCtx(() => [
            createVNode(PopUpArrowDown, {
              onClick: _cache[5] || (_cache[5] = ($event) => roomShareVisible.value = false)
            }),
            createElementVNode("div", _hoisted_4, [
              createElementVNode("div", _hoisted_5, toDisplayString(unref(t)("Invite.ShareRoom")), 1),
              createVNode(RoomShare, { "room-info": unref(currentRoom) }, null, 8, ["room-info"])
            ])
          ]),
          _: 1
        }, 8, ["visible"]),
        createVNode(unref(TUIPopup), {
          visible: userPickerVisible.value,
          "onUpdate:visible": _cache[8] || (_cache[8] = ($event) => userPickerVisible.value = $event),
          height: "90%"
        }, {
          default: withCtx(() => [
            createElementVNode("div", _hoisted_6, [
              createVNode(PopUpArrowDown, {
                onClick: _cache[7] || (_cache[7] = ($event) => userPickerVisible.value = false)
              }),
              createElementVNode("div", _hoisted_7, toDisplayString(`${unref(t)("Contacts")} (${userPickerData.value.length})`), 1),
              userPickerVisible.value ? (openBlock(), createBlock(unref(UserPicker), {
                key: 0,
                ref_key: "userPickerRef",
                ref: userPickerRef,
                class: "room-user-picker",
                "data-source": userPickerData.value,
                "display-mode": "list"
              }, null, 8, ["data-source"])) : createCommentVNode("", true),
              createElementVNode("div", _hoisted_8, [
                createVNode(unref(TUIButton), {
                  type: "primary",
                  onClick: handleUserPickerConfirm
                }, {
                  default: withCtx(() => [
                    createTextVNode(toDisplayString(unref(t)("Room.Confirm")), 1)
                  ]),
                  _: 1
                })
              ])
            ])
          ]),
          _: 1
        }, 8, ["visible"])
      ], 64);
    };
  }
});
export {
  _sfc_main as default
};
