import { defineComponent, ref, computed, watch, onMounted, onUnmounted, withDirectives, createElementBlock, openBlock, createElementVNode, createVNode, normalizeClass, unref, createBlock, createCommentVNode, vShow, withCtx, isRef } from "vue";
import { useUIKit, TUIWatermark, vTuiLoading } from "@tencentcloud/uikit-base-component-vue3";
import { useLoginState, useRoomState, useRoomParticipantState, useAITranscriberState, RoomType, RoomParticipantRole, RoomLayoutTemplate, RoomEvent, RoomParticipantEvent, RoomParticipantList, RealtimeMessageList } from "tuikit-atomicx-vue3/room";
import { conference } from "../../adapter/conference.mjs";
import { ComponentName, RoomEvent as RoomEvent$1 } from "../../adapter/type.mjs";
import AIToolsButton from "../../components/AIToolsButton/index.vue2.mjs";
import _sfc_main$7 from "../../components/BasicBeautyButton/index.vue2.mjs";
/* empty css                                            */
import CallButton from "../../components/CallButton/index.vue2.mjs";
import "tuikit-atomicx-vue3/chat";
/* empty css                                      */
/* empty css                                        */
import "../../utils/utils.mjs";
/* empty css                                           */
/* empty css                                       */
import CameraButton from "../../components/CameraButton/index.vue2.mjs";
/* empty css                                         */
import CurrentRoomInfo from "../../components/CurrentRoomInfo/index.vue2.mjs";
/* empty css                                              */
/* empty css                                         */
/* empty css                                         */
/* empty css                                           */
import LanguageButton from "../../components/LanguageButton/index.vue2.mjs";
import LayoutButton from "../../components/LayoutButton/index.vue2.mjs";
import _sfc_main$9 from "../../components/LeaveRoomButton/index.vue.mjs";
import "@tencentcloud/tuiroom-engine-js";
/* empty css                                            */
/* empty css                                         */
import LocalNetworkInfo from "../../components/LocalNetworkInfo/index.vue2.mjs";
import LoginUserInfo from "../../components/LoginUserInfo/index.vue2.mjs";
/* empty css                                          */
import MicButton from "../../components/MicButton/index.vue2.mjs";
/* empty css                                          */
/* empty css                                      */
import MoreButton from "../../components/MoreButton/index.vue2.mjs";
import _sfc_main$5 from "../../components/ParticipantButton/index.vue.mjs";
/* empty css                                              */
import PasswordDialog from "../../components/PasswordDialog/index.vue2.mjs";
/* empty css                                           */
import RaiseHandsButton from "../../components/RaiseHandsButton/index.vue2.mjs";
import _sfc_main$2 from "../../components/RoomBarrage/BarrageButton.vue.mjs";
import RoomBarrage from "../../components/RoomBarrage/RoomBarrage.vue2.mjs";
import _sfc_main$4 from "../../components/RoomChat/ChatButton.vue.mjs";
import RoomChat from "../../components/RoomChat/index.vue2.mjs";
/* empty css                                             */
/* empty css                                              */
/* empty css                                        */
/* empty css                                          */
/* empty css                                                      */
/* empty css                                                 */
/* empty css                                       */
import _sfc_main$1 from "../../components/RoomLayoutView/index.vue.mjs";
/* empty css                                                             */
/* empty css                                           */
import RoomSidePanel from "../../components/RoomSidePanel/index.vue2.mjs";
/* empty css                                                                */
/* empty css                                              */
import ScreenShareButton from "../../components/ScreenShareButton/index.vue2.mjs";
import _sfc_main$8 from "../../components/SettingButton/index.vue.mjs";
/* empty css                                                 */
/* empty css                                          */
/* empty css                                            */
import ThemeButton from "../../components/ThemeButton/index.vue2.mjs";
import _sfc_main$6 from "../../components/VirtualBackgroundButton/index.vue2.mjs";
/* empty css                                                  */
import _sfc_main$3 from "../../components/RaiseHandsList/index.vue2.mjs";
/* empty css                                         */
import useCustomizedAutoPlayDialog from "../../hooks/useCustomizedAutoPlayDialog.mjs";
import useRoomLifeCycle from "../../hooks/useRoomLifeCycle.mjs";
import { useRoomSidePanel, RoomTabKey } from "../../hooks/useRoomSidePanel.mjs";
import { useRoomTips } from "../../hooks/useRoomTips.mjs";
import { useRoomToolbar } from "../../hooks/useRoomToolbar.mjs";
import { eventCenter } from "../../utils/eventCenter.mjs";
const _hoisted_1 = { class: "header" };
const _hoisted_2 = { class: "header-left" };
const _hoisted_3 = { class: "header-center" };
const _hoisted_4 = { class: "header-right" };
const _hoisted_5 = { class: "room-main" };
const _hoisted_6 = { class: "control-bar" };
const _hoisted_7 = {
  key: 0,
  class: "control-left"
};
const _hoisted_8 = {
  key: 1,
  class: "control-left"
};
const _hoisted_9 = { class: "control-center" };
const _hoisted_10 = { class: "control-right" };
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  setup(__props) {
    const AIToolsButtonConfig = conference.getComponentConfig(ComponentName.AIToolsButton);
    const { t } = useUIKit();
    const roomPageRef = ref(null);
    const { showToolbar } = useRoomToolbar(roomPageRef);
    const { activeTab, sidePanelTitle, toggleSidePanel, closePanel } = useRoomSidePanel();
    useCustomizedAutoPlayDialog();
    useRoomTips();
    const { loginUserInfo } = useLoginState();
    const {
      currentRoom,
      subscribeEvent: subscribeRoomEvent,
      unsubscribeEvent: unsubscribeRoomEvent
    } = useRoomState();
    const {
      localParticipant,
      participantList,
      audienceListCursor,
      participantListCursor,
      getParticipantList,
      getAudienceList,
      subscribeEvent: subscribeRoomParticipantEvent,
      unsubscribeEvent: unsubscribeRoomParticipantEvent
    } = useRoomParticipantState();
    const { startRealtimeTranscriber } = useAITranscriberState();
    const {
      isJoiningRoom,
      joiningRoomId,
      roomPasswordVisible,
      handleJoinRoomError
    } = useRoomLifeCycle();
    const isWebinar = computed(() => {
      var _a;
      return ((_a = currentRoom.value) == null ? void 0 : _a.roomType) === RoomType.Webinar;
    });
    const isOwner = computed(() => {
      var _a;
      return ((_a = localParticipant.value) == null ? void 0 : _a.role) === RoomParticipantRole.Owner;
    });
    const isGuest = computed(() => participantList.value.some((participant) => {
      var _a;
      return participant.userId === ((_a = localParticipant.value) == null ? void 0 : _a.userId);
    }));
    const isAudience = computed(() => !participantList.value.some((participant) => {
      var _a;
      return participant.userId === ((_a = localParticipant.value) == null ? void 0 : _a.userId);
    }));
    const participantViewLayout = ref(void 0);
    function handleLayoutUpdate(layout) {
      participantViewLayout.value = layout;
    }
    watch(() => {
      var _a;
      return (_a = currentRoom.value) == null ? void 0 : _a.roomType;
    }, (newRoomType) => {
      if (newRoomType === RoomType.Webinar) {
        participantViewLayout.value = void 0;
      } else {
        participantViewLayout.value = RoomLayoutTemplate.GridLayout;
      }
    }, { immediate: true });
    watch(
      () => {
        var _a;
        return (_a = currentRoom.value) == null ? void 0 : _a.roomId;
      },
      async (roomId, oldRoomId) => {
        if (!oldRoomId && roomId) {
          await getParticipantList({ cursor: participantListCursor.value });
          await getAudienceList({ cursor: audienceListCursor.value });
          if (isOwner.value && (AIToolsButtonConfig == null ? void 0 : AIToolsButtonConfig.visible)) {
            await startRealtimeTranscriber({
              sourceLanguage: "zh",
              translationLanguages: ["en"]
            });
          }
        }
      },
      { immediate: true }
    );
    const handlePasswordCancel = () => {
      eventCenter.emit(RoomEvent$1.ROOM_ERROR);
    };
    const handleLeaveRoom = () => {
      eventCenter.emit(RoomEvent$1.ROOM_LEAVE);
    };
    const handleEndRoom = () => {
      eventCenter.emit(RoomEvent$1.ROOM_DISMISS);
    };
    const onRoomEnded = () => {
      eventCenter.emit(RoomEvent$1.ROOM_DISMISS, {});
    };
    const onKickedFromRoom = (eventInfo) => {
      eventCenter.emit(RoomEvent$1.KICKED_OUT, eventInfo);
    };
    onMounted(() => {
      subscribeRoomEvent(RoomEvent.onRoomEnded, onRoomEnded);
      subscribeRoomParticipantEvent(
        RoomParticipantEvent.onKickedFromRoom,
        onKickedFromRoom
      );
    });
    onUnmounted(() => {
      unsubscribeRoomEvent(RoomEvent.onRoomEnded, onRoomEnded);
      unsubscribeRoomParticipantEvent(
        RoomParticipantEvent.onKickedFromRoom,
        onKickedFromRoom
      );
      closePanel();
    });
    return (_ctx, _cache) => {
      var _a, _b;
      return withDirectives((openBlock(), createElementBlock("div", {
        id: "roomPage",
        ref_key: "roomPageRef",
        ref: roomPageRef,
        class: "room-page"
      }, [
        createElementVNode("div", {
          class: normalizeClass(["room-container", { "has-side-panel": unref(activeTab) }])
        }, [
          withDirectives(createElementVNode("header", _hoisted_1, [
            createElementVNode("div", _hoisted_2, [
              createVNode(unref(ThemeButton)),
              !isWebinar.value ? (openBlock(), createBlock(unref(LayoutButton), {
                key: 0,
                layout: participantViewLayout.value,
                "onUpdate:layout": handleLayoutUpdate
              }, null, 8, ["layout"])) : createCommentVNode("", true),
              createVNode(unref(LocalNetworkInfo))
            ]),
            createElementVNode("div", _hoisted_3, [
              createVNode(unref(CurrentRoomInfo))
            ]),
            createElementVNode("div", _hoisted_4, [
              createVNode(unref(LanguageButton)),
              createVNode(unref(LoginUserInfo), { "show-logout": false })
            ])
          ], 512), [
            [vShow, unref(showToolbar)]
          ]),
          createElementVNode("main", _hoisted_5, [
            createVNode(unref(TUIWatermark), {
              font: { fontSize: 16 },
              content: [
                ((_a = unref(loginUserInfo)) == null ? void 0 : _a.userName) || "",
                ((_b = unref(loginUserInfo)) == null ? void 0 : _b.userId) || ""
              ]
            }, {
              default: withCtx(() => [
                createVNode(unref(_sfc_main$1), {
                  "layout-template": participantViewLayout.value,
                  "onUpdate:layoutTemplate": handleLayoutUpdate
                }, null, 8, ["layout-template"])
              ]),
              _: 1
            }, 8, ["content"])
          ]),
          withDirectives(createElementVNode("footer", _hoisted_6, [
            isWebinar.value ? (openBlock(), createElementBlock("div", _hoisted_7, [
              isGuest.value || isOwner.value ? (openBlock(), createBlock(unref(MicButton), { key: 0 })) : createCommentVNode("", true),
              isOwner.value ? (openBlock(), createBlock(unref(CameraButton), { key: 1 })) : createCommentVNode("", true),
              isAudience.value ? (openBlock(), createBlock(unref(RaiseHandsButton), { key: 2 })) : createCommentVNode("", true)
            ])) : (openBlock(), createElementBlock("div", _hoisted_8, [
              createVNode(unref(MicButton)),
              createVNode(unref(CameraButton))
            ])),
            createElementVNode("div", _hoisted_9, [
              !isWebinar.value || isOwner.value ? (openBlock(), createBlock(unref(ScreenShareButton), { key: 0 })) : createCommentVNode("", true),
              !isWebinar.value ? (openBlock(), createBlock(unref(CallButton), { key: 1 })) : createCommentVNode("", true),
              isWebinar.value ? (openBlock(), createBlock(unref(_sfc_main$2), {
                key: 2,
                "is-chat-open": unref(activeTab) === unref(RoomTabKey).Barrage,
                onClick: _cache[0] || (_cache[0] = ($event) => unref(toggleSidePanel)(unref(RoomTabKey).Barrage))
              }, null, 8, ["is-chat-open"])) : createCommentVNode("", true),
              isWebinar.value && isOwner.value ? (openBlock(), createBlock(unref(_sfc_main$3), { key: 3 })) : createCommentVNode("", true),
              !isWebinar.value ? (openBlock(), createBlock(unref(_sfc_main$4), {
                key: 4,
                "is-chat-open": unref(activeTab) === unref(RoomTabKey).Chat,
                onClick: _cache[1] || (_cache[1] = ($event) => unref(toggleSidePanel)(unref(RoomTabKey).Chat))
              }, null, 8, ["is-chat-open"])) : createCommentVNode("", true),
              createVNode(unref(_sfc_main$5), {
                onClick: _cache[2] || (_cache[2] = ($event) => unref(toggleSidePanel)(unref(RoomTabKey).ParticipantList))
              }),
              !isWebinar.value || isOwner.value ? (openBlock(), createBlock(unref(MoreButton), { key: 5 }, {
                default: withCtx(() => {
                  var _a2;
                  return [
                    !isWebinar.value ? (openBlock(), createBlock(unref(_sfc_main$6), { key: 0 })) : createCommentVNode("", true),
                    !isWebinar.value || isOwner.value ? (openBlock(), createBlock(unref(_sfc_main$7), { key: 1 })) : createCommentVNode("", true),
                    !isWebinar.value && ((_a2 = unref(AIToolsButtonConfig)) == null ? void 0 : _a2.visible) ? (openBlock(), createBlock(unref(AIToolsButton), { key: 2 })) : createCommentVNode("", true),
                    !isWebinar.value || isOwner.value ? (openBlock(), createBlock(unref(_sfc_main$8), { key: 3 })) : createCommentVNode("", true)
                  ];
                }),
                _: 1
              })) : createCommentVNode("", true)
            ]),
            createElementVNode("div", _hoisted_10, [
              createVNode(unref(_sfc_main$9), {
                onLeave: handleLeaveRoom,
                onEnd: handleEndRoom
              })
            ])
          ], 512), [
            [vShow, unref(showToolbar)]
          ]),
          createVNode(unref(PasswordDialog), {
            modelValue: unref(roomPasswordVisible),
            "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => isRef(roomPasswordVisible) ? roomPasswordVisible.value = $event : null),
            "room-id": unref(joiningRoomId),
            onCancel: handlePasswordCancel,
            onError: unref(handleJoinRoomError)
          }, null, 8, ["modelValue", "room-id", "onError"])
        ], 2),
        createVNode(unref(RoomSidePanel), {
          class: normalizeClass(["side-panel", { "side-panel-visible": unref(activeTab) }]),
          title: unref(sidePanelTitle),
          onClose: unref(closePanel)
        }, {
          default: withCtx(() => [
            unref(activeTab) === unref(RoomTabKey).ParticipantList ? (openBlock(), createBlock(unref(RoomParticipantList), { key: 0 })) : createCommentVNode("", true),
            !isWebinar.value ? withDirectives((openBlock(), createBlock(unref(RoomChat), {
              key: 1,
              "is-chat-open": unref(activeTab) === unref(RoomTabKey).Chat
            }, null, 8, ["is-chat-open"])), [
              [vShow, unref(activeTab) === unref(RoomTabKey).Chat]
            ]) : createCommentVNode("", true),
            withDirectives(createVNode(RoomBarrage, {
              "is-chat-open": unref(activeTab) === unref(RoomTabKey).Barrage
            }, null, 8, ["is-chat-open"]), [
              [vShow, isWebinar.value && unref(activeTab) === unref(RoomTabKey).Barrage]
            ]),
            unref(activeTab) === unref(RoomTabKey).AIToolsRealtimeMessageList ? (openBlock(), createBlock(unref(RealtimeMessageList), { key: 2 })) : createCommentVNode("", true)
          ]),
          _: 1
        }, 8, ["class", "title", "onClose"])
      ])), [
        [unref(vTuiLoading), {
          visible: unref(isJoiningRoom),
          text: unref(t)("Room.EnteringRoom"),
          background: "var(--bg-color-topbar)"
        }]
      ]);
    };
  }
});
export {
  _sfc_main as default
};
