"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const vue = require("vue");
const uikitBaseComponentVue3 = require("@tencentcloud/uikit-base-component-vue3");
const chat = require("tuikit-atomicx-vue3/chat");
const room = require("tuikit-atomicx-vue3/room");
const IconButtonH5 = require("../base/IconButtonH5.vue2.js");
const PopUpArrowDown = require("../base/PopUpArrowDown.vue2.js");
const RoomShare = require("./RoomShare.vue2.js");
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__ */ vue.defineComponent({
  __name: "index",
  setup(__props) {
    const { t } = uikitBaseComponentVue3.useUIKit();
    const { currentRoom, callUserToRoom } = room.useRoomState();
    const { participantList, pendingParticipantList } = room.useRoomParticipantState();
    const { friendList } = chat.useContactListState();
    const isVisible = vue.ref(false);
    const userPickerRef = vue.ref();
    const userPickerVisible = vue.ref(false);
    const roomShareVisible = vue.ref(false);
    const userPickerData = vue.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 === room.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) {
          uikitBaseComponentVue3.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;
        uikitBaseComponentVue3.TUIToast.success({ message: t("Invite.InviteSuccess") });
      } catch (error) {
        console.error("Failed to invite users to room:", error);
        uikitBaseComponentVue3.TUIToast.error({ message: t("Invite.InviteFailed") });
      }
    };
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createElementBlock(vue.Fragment, null, [
        vue.createVNode(IconButtonH5.default, {
          title: vue.unref(t)("Invite.Title"),
          onClick: _cache[0] || (_cache[0] = ($event) => isVisible.value = true)
        }, {
          default: vue.withCtx(() => [
            vue.createVNode(vue.unref(uikitBaseComponentVue3.IconInvite), { size: 24 })
          ]),
          _: 1
        }, 8, ["title"]),
        vue.createVNode(vue.unref(uikitBaseComponentVue3.TUIPopup), {
          visible: isVisible.value,
          "onUpdate:visible": _cache[4] || (_cache[4] = ($event) => isVisible.value = $event)
        }, {
          default: vue.withCtx(() => [
            vue.createVNode(PopUpArrowDown.default, {
              onClick: _cache[1] || (_cache[1] = ($event) => isVisible.value = false)
            }),
            vue.createElementVNode("div", _hoisted_1, [
              vue.createElementVNode("div", {
                class: "operate-item",
                onClick: _cache[2] || (_cache[2] = ($event) => userPickerVisible.value = true)
              }, [
                vue.createVNode(vue.unref(uikitBaseComponentVue3.IconInvite), { size: 18 }),
                vue.createElementVNode("span", _hoisted_2, vue.toDisplayString(vue.unref(t)("Invite.AddMember")), 1)
              ]),
              vue.createElementVNode("div", {
                class: "operate-item",
                onClick: _cache[3] || (_cache[3] = ($event) => roomShareVisible.value = true)
              }, [
                vue.createVNode(vue.unref(uikitBaseComponentVue3.IconShare), { size: 18 }),
                vue.createElementVNode("span", _hoisted_3, vue.toDisplayString(vue.unref(t)("Invite.ShareRoom")), 1)
              ])
            ])
          ]),
          _: 1
        }, 8, ["visible"]),
        vue.createVNode(vue.unref(uikitBaseComponentVue3.TUIPopup), {
          visible: roomShareVisible.value,
          "onUpdate:visible": _cache[6] || (_cache[6] = ($event) => roomShareVisible.value = $event)
        }, {
          default: vue.withCtx(() => [
            vue.createVNode(PopUpArrowDown.default, {
              onClick: _cache[5] || (_cache[5] = ($event) => roomShareVisible.value = false)
            }),
            vue.createElementVNode("div", _hoisted_4, [
              vue.createElementVNode("div", _hoisted_5, vue.toDisplayString(vue.unref(t)("Invite.ShareRoom")), 1),
              vue.createVNode(RoomShare.default, { "room-info": vue.unref(currentRoom) }, null, 8, ["room-info"])
            ])
          ]),
          _: 1
        }, 8, ["visible"]),
        vue.createVNode(vue.unref(uikitBaseComponentVue3.TUIPopup), {
          visible: userPickerVisible.value,
          "onUpdate:visible": _cache[8] || (_cache[8] = ($event) => userPickerVisible.value = $event),
          height: "90%"
        }, {
          default: vue.withCtx(() => [
            vue.createElementVNode("div", _hoisted_6, [
              vue.createVNode(PopUpArrowDown.default, {
                onClick: _cache[7] || (_cache[7] = ($event) => userPickerVisible.value = false)
              }),
              vue.createElementVNode("div", _hoisted_7, vue.toDisplayString(`${vue.unref(t)("Contacts")} (${userPickerData.value.length})`), 1),
              userPickerVisible.value ? (vue.openBlock(), vue.createBlock(vue.unref(room.UserPicker), {
                key: 0,
                ref_key: "userPickerRef",
                ref: userPickerRef,
                class: "room-user-picker",
                "data-source": userPickerData.value,
                "display-mode": "list"
              }, null, 8, ["data-source"])) : vue.createCommentVNode("", true),
              vue.createElementVNode("div", _hoisted_8, [
                vue.createVNode(vue.unref(uikitBaseComponentVue3.TUIButton), {
                  type: "primary",
                  onClick: handleUserPickerConfirm
                }, {
                  default: vue.withCtx(() => [
                    vue.createTextVNode(vue.toDisplayString(vue.unref(t)("Room.Confirm")), 1)
                  ]),
                  _: 1
                })
              ])
            ])
          ]),
          _: 1
        }, 8, ["visible"])
      ], 64);
    };
  }
});
exports.default = _sfc_main;
