import { defineComponent, computed, ref, createElementBlock, openBlock, createVNode, unref, withCtx, createElementVNode, createCommentVNode, toDisplayString, Fragment, renderList, createTextVNode } from "vue";
import { useUIKit, Badge, IconApplyManage, TUIDialog, TUIButton } from "@tencentcloud/uikit-base-component-vue3";
import { useRoomParticipantState, Avatar } from "tuikit-atomicx-vue3/room";
import IconButton from "../base/IconButton.vue2.mjs";
const _hoisted_1 = { class: "pending-device-invitations" };
const _hoisted_2 = {
  key: 0,
  class: "pending-device-invitation-empty"
};
const _hoisted_3 = { class: "user-info" };
const _hoisted_4 = { class: "user-name" };
const _hoisted_5 = { class: "action-area" };
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  setup(__props) {
    const { t } = useUIKit();
    const {
      pendingDeviceApplications,
      approveOpenDeviceRequest,
      rejectOpenDeviceRequest,
      promoteToParticipant
    } = useRoomParticipantState();
    const unreadCount = computed(() => pendingDeviceApplications.value.length);
    const dialogVisible = ref(false);
    const handleClick = () => {
      dialogVisible.value = true;
    };
    const handleAccept = (invitation) => {
      approveOpenDeviceRequest({ device: invitation.deviceType, userId: invitation.senderUserId });
      promoteToParticipant({ userId: invitation.senderUserId });
    };
    const handleReject = (invitation) => {
      rejectOpenDeviceRequest({ device: invitation.deviceType, userId: invitation.senderUserId });
    };
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", null, [
        createVNode(IconButton, {
          title: unref(t)("RaiseHands.List"),
          onClick: handleClick
        }, {
          default: withCtx(() => [
            createVNode(unref(Badge), {
              value: unreadCount.value,
              hidden: !unreadCount.value
            }, {
              default: withCtx(() => [
                createVNode(unref(IconApplyManage), { size: 24 })
              ]),
              _: 1
            }, 8, ["value", "hidden"])
          ]),
          _: 1
        }, 8, ["title"]),
        createVNode(unref(TUIDialog), {
          visible: dialogVisible.value,
          "onUpdate:visible": _cache[0] || (_cache[0] = ($event) => dialogVisible.value = $event),
          title: unref(t)("RaiseHands.List"),
          "custom-classes": ["raise-hands-list-dialog"],
          appendTo: "#roomPage"
        }, {
          footer: withCtx(() => [..._cache[1] || (_cache[1] = [
            createElementVNode("div", null, null, -1)
          ])]),
          default: withCtx(() => [
            createElementVNode("div", _hoisted_1, [
              unref(pendingDeviceApplications).length === 0 ? (openBlock(), createElementBlock("div", _hoisted_2, [
                createElementVNode("span", null, toDisplayString(unref(t)("RaiseHands.Empty")), 1)
              ])) : createCommentVNode("", true),
              (openBlock(true), createElementBlock(Fragment, null, renderList(unref(pendingDeviceApplications), (invitation) => {
                return openBlock(), createElementBlock("div", {
                  key: invitation.timestamp,
                  class: "pending-device-invitation"
                }, [
                  createElementVNode("div", _hoisted_3, [
                    createVNode(unref(Avatar), {
                      src: invitation.senderAvatarUrl,
                      size: 40
                    }, null, 8, ["src"]),
                    createElementVNode("span", _hoisted_4, toDisplayString(invitation.senderUserName || invitation.senderUserId), 1)
                  ]),
                  createElementVNode("div", _hoisted_5, [
                    createVNode(unref(TUIButton), {
                      type: "primary",
                      onClick: ($event) => handleAccept(invitation)
                    }, {
                      default: withCtx(() => [
                        createTextVNode(toDisplayString(unref(t)("RaiseHands.Agree")), 1)
                      ]),
                      _: 1
                    }, 8, ["onClick"]),
                    createVNode(unref(TUIButton), {
                      onClick: ($event) => handleReject(invitation)
                    }, {
                      default: withCtx(() => [
                        createTextVNode(toDisplayString(unref(t)("RaiseHands.Reject")), 1)
                      ]),
                      _: 1
                    }, 8, ["onClick"])
                  ])
                ]);
              }), 128))
            ])
          ]),
          _: 1
        }, 8, ["visible", "title"])
      ]);
    };
  }
});
export {
  _sfc_main as default
};
