"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 IconButton = require("../base/IconButton.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: "user-picker-footer" };
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  __name: "index",
  setup(__props) {
    const { t } = uikitBaseComponentVue3.useUIKit();
    const { loginUserInfo } = room.useLoginState();
    const { currentRoom, callUserToRoom } = room.useRoomState();
    const { participantList, pendingParticipantList } = room.useRoomParticipantState();
    const { friendList } = chat.useContactListState();
    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) => {
      var _a, _b;
      return vue.openBlock(), vue.createElementBlock("div", null, [
        vue.createVNode(vue.unref(uikitBaseComponentVue3.Dropdown), {
          trigger: "click",
          placement: "top",
          teleported: false,
          hideOnClick: false
        }, {
          dropdown: vue.withCtx(() => [
            vue.createElementVNode("div", _hoisted_1, [
              vue.createElementVNode("div", {
                class: "operate-item",
                onClick: _cache[0] || (_cache[0] = ($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[1] || (_cache[1] = ($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)
              ])
            ])
          ]),
          default: vue.withCtx(() => [
            vue.createVNode(IconButton.default, {
              title: vue.unref(t)("Invite.Title")
            }, {
              default: vue.withCtx(() => [
                vue.createVNode(vue.unref(uikitBaseComponentVue3.IconInvite), { size: 24 })
              ]),
              _: 1
            }, 8, ["title"])
          ]),
          _: 1
        }),
        vue.createVNode(vue.unref(uikitBaseComponentVue3.TUIDialog), {
          visible: userPickerVisible.value,
          "onUpdate:visible": _cache[3] || (_cache[3] = ($event) => userPickerVisible.value = $event),
          "append-to": "body",
          title: `${vue.unref(t)("Contacts")} (${userPickerData.value.length})`
        }, {
          footer: vue.withCtx(() => [
            vue.createElementVNode("div", _hoisted_4, [
              vue.createVNode(vue.unref(uikitBaseComponentVue3.TUIButton), {
                onClick: _cache[2] || (_cache[2] = ($event) => userPickerVisible.value = false)
              }, {
                default: vue.withCtx(() => [
                  vue.createTextVNode(vue.toDisplayString(vue.unref(t)("Room.Cancel")), 1)
                ]),
                _: 1
              }),
              vue.createVNode(vue.unref(uikitBaseComponentVue3.TUIButton), {
                type: "primary",
                onClick: handleUserPickerConfirm
              }, {
                default: vue.withCtx(() => [
                  vue.createTextVNode(vue.toDisplayString(vue.unref(t)("Room.Confirm")), 1)
                ]),
                _: 1
              })
            ])
          ]),
          default: vue.withCtx(() => [
            vue.createVNode(vue.unref(room.UserPicker), {
              ref_key: "userPickerRef",
              ref: userPickerRef,
              class: "room-user-picker",
              "data-source": userPickerData.value,
              "display-mode": "list"
            }, null, 8, ["data-source"])
          ]),
          _: 1
        }, 8, ["visible", "title"]),
        vue.createVNode(vue.unref(uikitBaseComponentVue3.TUIDialog), {
          visible: roomShareVisible.value,
          "onUpdate:visible": _cache[4] || (_cache[4] = ($event) => roomShareVisible.value = $event),
          "append-to": "body",
          title: vue.unref(t)("Room.InviteToMeeting", { userName: ((_a = vue.unref(loginUserInfo)) == null ? void 0 : _a.userName) || ((_b = vue.unref(loginUserInfo)) == null ? void 0 : _b.userId) }),
          "custom-classes": ["room-share-dialog"]
        }, {
          footer: vue.withCtx(() => [..._cache[5] || (_cache[5] = [
            vue.createElementVNode("div", null, null, -1)
          ])]),
          default: vue.withCtx(() => [
            vue.createVNode(RoomShare.default, { "room-info": vue.unref(currentRoom) }, null, 8, ["room-info"])
          ]),
          _: 1
        }, 8, ["visible", "title"])
      ]);
    };
  }
});
exports.default = _sfc_main;
