"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Vue = require("vue");
const TUIRoomEngine = require("@tencentcloud/tuiroom-engine-js");
const useEndControlHooks = require("./useEndControlHooks.js");
const index = require("../../../utils/common/logger/index.js");
const PopUpH5 = require("../../common/base/PopUpH5.vue.js");
const SvgIcon = require("../../common/base/SvgIcon.vue.js");
const CorrectIcon = require("../../common/icons/CorrectIcon.vue.js");
const SearchIcon = require("../../common/icons/SearchIcon.vue.js");
const Avatar = require("../../common/Avatar.vue.js");
const vTap = require("../../../directives/vTap.js");
const EndRoomIcon = require("../../common/icons/EndRoomIcon.vue.js");
require("../../../services/main.js");
const roomService = require("../../../services/roomService.js");
require("../../../locales/index.js");
require("mitt");
require("../../../services/manager/roomActionManager.js");
require("@tencentcloud/tui-core");
const _hoisted_1 = { class: "end-control-container" };
const _hoisted_2 = {
  class: "end-button",
  tabindex: "1"
};
const _hoisted_3 = { class: "end-button-title" };
const _hoisted_4 = {
  key: 0,
  class: "end-main-content"
};
const _hoisted_5 = { key: 0 };
const _hoisted_6 = {
  key: 0,
  class: "end-dialog-header"
};
const _hoisted_7 = {
  key: 0,
  class: "end-dialog-text"
};
const _hoisted_8 = { key: 1 };
const _hoisted_9 = {
  key: 1,
  class: "dialog-middle-content"
};
const _hoisted_10 = { key: 2 };
const _hoisted_11 = { style: { "height": "100%" } };
const _hoisted_12 = { class: "transfer-list-container" };
const _hoisted_13 = { class: "transfer-header" };
const _hoisted_14 = { class: "search-container" };
const _hoisted_15 = ["placeholder"];
const _hoisted_16 = { class: "transfer-body" };
const _hoisted_17 = ["onClick"];
const _hoisted_18 = { class: "member-basic-info" };
const _hoisted_19 = { class: "user-name" };
const _hoisted_20 = {
  key: 0,
  class: "member-has-no-data"
};
const _hoisted_21 = { class: "transfer-button" };
const _sfc_main = /* @__PURE__ */ Vue.defineComponent({
  __name: "EndControlH5",
  setup(__props) {
    const {
      t,
      isShowLeaveRoomDialog,
      roomStore,
      roomEngine,
      stopMeeting,
      cancel,
      DialogType,
      logPrefix,
      currentDialogType,
      visible,
      resetState,
      toggleMangeMemberSidebar,
      searchName,
      hasNoData,
      handleShowMemberControl,
      filteredList,
      selectedUser,
      showSideBar,
      remoteEnteredUserList,
      isMasterWithOneRemoteUser,
      isMasterWithRemoteUser
    } = useEndControlHooks.default();
    function handleEndBtnClick() {
      stopMeeting();
    }
    function handleEndLeaveClick() {
      if (!roomStore.isMaster) {
        leaveRoom();
        return;
      }
      if (isMasterWithRemoteUser.value) {
        selectedUser.value = remoteEnteredUserList.value[0].userId;
        if (isMasterWithOneRemoteUser.value) {
          transferAndLeave();
          return;
        }
        currentDialogType.value = DialogType.TransferDialog;
        toggleMangeMemberSidebar();
        resetState();
        return;
      }
    }
    async function dismissRoom() {
      try {
        index.default.log(`${logPrefix}dismissRoom: enter`);
        resetState();
        await roomService.roomService.dismissRoom();
      } catch (error) {
        index.default.error(`${logPrefix}dismissRoom error:`, error);
      }
    }
    async function leaveRoom() {
      try {
        resetState();
        await roomService.roomService.leaveRoom();
      } catch (error) {
        index.default.error(`${logPrefix}leaveRoom error:`, error);
      }
    }
    async function transferAndLeave() {
      var _a;
      if (!selectedUser.value) {
        return;
      }
      try {
        const userId = selectedUser.value;
        const changeUserRoleResponse = await ((_a = roomEngine.instance) == null ? void 0 : _a.changeUserRole({
          userId,
          userRole: TUIRoomEngine.TUIRole.kRoomOwner
        }));
        index.default.log(`${logPrefix}transferAndLeave:`, changeUserRoleResponse);
        resetState();
        await roomService.roomService.leaveRoom();
      } catch (error) {
        index.default.error(`${logPrefix}transferAndLeave error:`, error);
      }
    }
    return (_ctx, _cache) => {
      return Vue.openBlock(), Vue.createElementBlock("div", null, [
        Vue.createElementVNode("div", _hoisted_1, [
          Vue.withDirectives((Vue.openBlock(), Vue.createElementBlock("div", _hoisted_2, [
            Vue.createVNode(SvgIcon.default, { icon: EndRoomIcon.default }),
            Vue.createElementVNode("span", _hoisted_3, Vue.toDisplayString(Vue.unref(t)("EndH5")), 1)
          ])), [
            [Vue.unref(vTap.default), handleEndBtnClick]
          ])
        ]),
        Vue.unref(visible) ? (Vue.openBlock(), Vue.createElementBlock("div", _hoisted_4, [
          Vue.createElementVNode("div", {
            class: Vue.normalizeClass(
              Vue.unref(isShowLeaveRoomDialog) ? "end-dialog-leave" : "end-dialog-dismiss"
            )
          }, [
            Vue.unref(currentDialogType) === Vue.unref(DialogType).BasicDialog ? (Vue.openBlock(), Vue.createElementBlock("div", _hoisted_5, [
              Vue.unref(roomStore).isMaster ? (Vue.openBlock(), Vue.createElementBlock("div", _hoisted_6, [
                Vue.unref(roomStore).isMaster ? (Vue.openBlock(), Vue.createElementBlock("span", _hoisted_7, Vue.toDisplayString(Vue.unref(t)(
                  "If you do not want to end the meeting, please designate a new host before leaving the meeting."
                )), 1)) : (Vue.openBlock(), Vue.createElementBlock("span", _hoisted_8, Vue.toDisplayString(Vue.unref(t)("Are you sure you want to leave this room?")), 1))
              ])) : Vue.createCommentVNode("", true)
            ])) : Vue.createCommentVNode("", true),
            Vue.unref(currentDialogType) === Vue.unref(DialogType).BasicDialog ? (Vue.openBlock(), Vue.createElementBlock("div", _hoisted_9, [
              Vue.unref(roomStore).isMaster ? (Vue.openBlock(), Vue.createElementBlock("span", {
                key: 0,
                class: Vue.normalizeClass(
                  Vue.unref(isShowLeaveRoomDialog) ? "end-button-dismiss" : "end-button-dismiss-single"
                ),
                onClick: Vue.withModifiers(dismissRoom, ["stop"])
              }, Vue.toDisplayString(Vue.unref(t)("Dismiss")), 3)) : Vue.createCommentVNode("", true),
              Vue.unref(isShowLeaveRoomDialog) ? Vue.withDirectives((Vue.openBlock(), Vue.createElementBlock("span", {
                key: 1,
                class: Vue.normalizeClass(
                  Vue.unref(roomStore).isMaster ? "end-button-leave" : "end-button-leave-single"
                )
              }, [
                Vue.createTextVNode(Vue.toDisplayString(Vue.unref(t)("Leave")), 1)
              ], 2)), [
                [Vue.unref(vTap.default), handleEndLeaveClick]
              ]) : Vue.createCommentVNode("", true),
              Vue.createElementVNode("span", {
                class: "end-button-cancel",
                onClick: _cache[0] || (_cache[0] = Vue.withModifiers(
                  //@ts-ignore
                  (...args) => Vue.unref(cancel) && Vue.unref(cancel)(...args),
                  ["stop"]
                ))
              }, Vue.toDisplayString(Vue.unref(t)("Cancel")), 1)
            ])) : Vue.createCommentVNode("", true),
            Vue.unref(currentDialogType) === Vue.unref(DialogType).TransferDialog ? (Vue.openBlock(), Vue.createElementBlock("div", _hoisted_10, [
              Vue.createElementVNode("span", {
                class: "end-button-cancel",
                onClick: _cache[1] || (_cache[1] = Vue.withModifiers(
                  //@ts-ignore
                  (...args) => Vue.unref(cancel) && Vue.unref(cancel)(...args),
                  ["stop"]
                ))
              }, Vue.toDisplayString(Vue.unref(t)("Cancel")), 1)
            ])) : Vue.createCommentVNode("", true)
          ], 2)
        ])) : Vue.createCommentVNode("", true),
        Vue.withDirectives(Vue.createVNode(PopUpH5.default, {
          title: Vue.unref(t)("Appoint a new host"),
          class: "transfer-container"
        }, {
          sidebarContent: Vue.withCtx(() => [
            Vue.createElementVNode("div", _hoisted_11, [
              Vue.createElementVNode("div", _hoisted_12, [
                Vue.createElementVNode("div", _hoisted_13, [
                  Vue.createElementVNode("div", _hoisted_14, [
                    Vue.createVNode(SvgIcon.default, { icon: SearchIcon.default }),
                    Vue.withDirectives(Vue.createElementVNode("input", {
                      "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => Vue.isRef(searchName) ? searchName.value = $event : null),
                      type: "text",
                      class: "searching-input",
                      placeholder: Vue.unref(t)("Search for conference attendees"),
                      enterkeyhint: "done"
                    }, null, 8, _hoisted_15), [
                      [Vue.vModelText, Vue.unref(searchName)]
                    ])
                  ])
                ]),
                Vue.createElementVNode("div", _hoisted_16, [
                  (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(Vue.unref(filteredList), (user) => {
                    return Vue.openBlock(), Vue.createElementBlock("div", {
                      key: user.userId,
                      class: "transfer-list-content",
                      onClick: ($event) => Vue.unref(handleShowMemberControl)(user.userId)
                    }, [
                      Vue.createElementVNode("div", _hoisted_18, [
                        Vue.createVNode(Avatar.default, {
                          class: "avatar-url",
                          "img-src": user.avatarUrl
                        }, null, 8, ["img-src"]),
                        Vue.createElementVNode("div", _hoisted_19, Vue.toDisplayString(Vue.unref(roomService.roomService).getDisplayName(user)), 1),
                        Vue.unref(selectedUser) === user.userId ? (Vue.openBlock(), Vue.createBlock(SvgIcon.default, {
                          key: 0,
                          icon: CorrectIcon.default,
                          class: "correct"
                        })) : Vue.createCommentVNode("", true)
                      ])
                    ], 8, _hoisted_17);
                  }), 128)),
                  Vue.unref(hasNoData) ? (Vue.openBlock(), Vue.createElementBlock("div", _hoisted_20, Vue.toDisplayString(Vue.unref(t)("No relevant user found.")), 1)) : Vue.createCommentVNode("", true)
                ])
              ])
            ])
          ]),
          sidebarFooter: Vue.withCtx(() => [
            Vue.createElementVNode("div", {
              class: "transfer-leave",
              onClick: transferAndLeave
            }, [
              Vue.createElementVNode("span", _hoisted_21, Vue.toDisplayString(Vue.unref(t)("Transfer and leave")), 1)
            ])
          ]),
          _: 1
        }, 8, ["title"]), [
          [Vue.vShow, Vue.unref(showSideBar)]
        ])
      ]);
    };
  }
});
exports.default = _sfc_main;
