import { defineComponent, watch, onMounted, onUnmounted, createElementBlock, openBlock, createElementVNode, withDirectives, createVNode, unref, vShow, withCtx, isRef } from "vue";
import { useUIKit, TUIWatermark, vTuiLoading } from "@tencentcloud/uikit-base-component-vue3";
import { useLoginState, useRoomState, useRoomParticipantState, RoomEvent, RoomParticipantEvent } from "tuikit-atomicx-vue3/room";
import "../../hooks/useRoomSidePanel.mjs";
/* empty css                                    */
/* empty css                                        */
/* empty css                                            */
import "tuikit-atomicx-vue3/chat";
import "../../utils/utils.mjs";
/* empty css                                         */
/* empty css                                     */
import CallButtonH5 from "../../components/CallButtonH5/index.vue2.mjs";
/* empty css                                       */
import CameraButtonH5 from "../../components/CameraButtonH5/index.vue2.mjs";
/* empty css                                          */
import ExpandFooterH5 from "../../components/ExpandFooterH5/index.vue2.mjs";
/* empty css                                         */
/* empty css                                           */
/* empty css                                         */
/* empty css                                       */
import "@tencentcloud/tuiroom-engine-js";
/* empty css                                                  */
/* empty css                                                 */
import LeaveRoomButtonH5 from "../../components/LeaveRoomButtonH5/index.vue2.mjs";
/* empty css                                         */
/* empty css                                           */
/* empty css                                        */
/* empty css                                        */
/* empty css                                          */
/* empty css                                        */
/* empty css                                    */
import MicButtonH5 from "../../components/MicButtonH5/index.vue2.mjs";
/* empty css                                     */
import ParticipantButtonH5 from "../../components/ParticipantButtonH5/index.vue2.mjs";
/* empty css                                         */
import PasswordDialogH5 from "../../components/PasswordDialogH5/index.vue2.mjs";
/* empty css                                           */
import "tuikit-atomicx-vue3/live";
/* empty css                                            */
/* empty css                                           */
/* empty css                                            */
/* empty css                                   */
import ChatButtonH5 from "../../components/RoomChatH5/ChatButton.vue2.mjs";
/* empty css                                                      */
import RoomITitleH5 from "../../components/RoomITitleH5/index.vue2.mjs";
/* empty css                                                                               */
/* empty css                                                                               */
/* empty css                                                                  */
import RoomLayoutViewH5 from "../../components/RoomLayoutViewH5/index.vue2.mjs";
/* empty css                                        */
/* empty css                                                                */
/* empty css                                              */
/* empty css                                            */
/* empty css                                                */
/* empty css                                                 */
import _sfc_main$2 from "../../components/SettingButtonH5/index.vue.mjs";
/* empty css                                          */
/* empty css                                            */
import _sfc_main$1 from "../../components/SwitchCameraButtonH5/index.vue.mjs";
/* empty css                                      */
/* empty css                                                  */
/* empty css                                         */
import useCustomizedAutoPlayDialog from "../../hooks/useCustomizedAutoPlayDialog.mjs";
import { useRoomTips } from "../../hooks/useRoomTips.mjs";
import { useRoomToolbarH5 } from "../../hooks/useRoomToolbarH5.mjs";
import useRoomLifeCycle from "../../hooks/useRoomLifeCycle.mjs";
import { eventCenter } from "../../utils/eventCenter.mjs";
import { RoomEvent as RoomEvent$1 } from "../../adapter/type.mjs";
const _hoisted_1 = {
  id: "roomPage",
  class: "room-page"
};
const _hoisted_2 = { class: "room-container" };
const _hoisted_3 = { class: "header" };
const _hoisted_4 = { class: "header-left" };
const _hoisted_5 = { class: "header-center" };
const _hoisted_6 = { class: "header-right" };
const _hoisted_7 = { class: "room-footer" };
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  setup(__props) {
    const { t } = useUIKit();
    const { showToolbar, toggleToolbar } = useRoomToolbarH5();
    useCustomizedAutoPlayDialog();
    useRoomTips();
    const { loginUserInfo } = useLoginState();
    const { currentRoom } = useRoomState();
    const {
      getParticipantList,
      participantListCursor,
      subscribeEvent: subscribeRoomParticipantEvent,
      unsubscribeEvent: unsubscribeRoomParticipantEvent
    } = useRoomParticipantState();
    const {
      subscribeEvent: subscribeRoomEvent,
      unsubscribeEvent: unsubscribeRoomEvent
    } = useRoomState();
    const {
      isJoiningRoom,
      joiningRoomId,
      roomPasswordVisible,
      handleJoinRoomError
    } = useRoomLifeCycle();
    watch(
      () => {
        var _a;
        return (_a = currentRoom.value) == null ? void 0 : _a.roomId;
      },
      async (roomId, oldRoomId) => {
        if (!oldRoomId && roomId) {
          await getParticipantList({ cursor: participantListCursor.value });
        }
      },
      { 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, {});
    };
    onMounted(() => {
      subscribeRoomEvent(RoomEvent.onRoomEnded, onRoomEnded);
      subscribeRoomParticipantEvent(
        RoomParticipantEvent.onKickedFromRoom,
        onKickedFromRoom
      );
    });
    onUnmounted(() => {
      unsubscribeRoomEvent(RoomEvent.onRoomEnded, onRoomEnded);
      unsubscribeRoomParticipantEvent(
        RoomParticipantEvent.onKickedFromRoom,
        onKickedFromRoom
      );
    });
    return (_ctx, _cache) => {
      var _a, _b;
      return openBlock(), createElementBlock("div", _hoisted_1, [
        createElementVNode("div", _hoisted_2, [
          withDirectives(createElementVNode("header", _hoisted_3, [
            createElementVNode("div", _hoisted_4, [
              createVNode(unref(_sfc_main$1))
            ]),
            createElementVNode("div", _hoisted_5, [
              createVNode(unref(RoomITitleH5))
            ]),
            createElementVNode("div", _hoisted_6, [
              createVNode(unref(LeaveRoomButtonH5), {
                onLeave: handleLeaveRoom,
                onEnd: handleEndRoom
              })
            ])
          ], 512), [
            [vShow, unref(showToolbar)]
          ]),
          withDirectives((openBlock(), createElementBlock("main", {
            class: "room-main",
            onClick: _cache[0] || (_cache[0] = //@ts-ignore
            (...args) => unref(toggleToolbar) && unref(toggleToolbar)(...args))
          }, [
            createVNode(unref(TUIWatermark), {
              font: { fontSize: 16 },
              content: [
                ((_a = unref(loginUserInfo)) == null ? void 0 : _a.userName) || "",
                ((_b = unref(loginUserInfo)) == null ? void 0 : _b.userId) || ""
              ],
              gap: [0, 100]
            }, {
              default: withCtx(() => [
                createVNode(unref(RoomLayoutViewH5))
              ]),
              _: 1
            }, 8, ["content"])
          ])), [
            [unref(vTuiLoading), {
              visible: unref(isJoiningRoom),
              text: unref(t)("Room.EnteringRoom"),
              background: "transparent"
            }]
          ]),
          withDirectives(createElementVNode("footer", _hoisted_7, [
            createVNode(unref(ExpandFooterH5), null, {
              default: withCtx(() => [
                createVNode(unref(ParticipantButtonH5)),
                createVNode(unref(MicButtonH5)),
                createVNode(unref(CameraButtonH5)),
                createVNode(unref(CallButtonH5)),
                createVNode(unref(ChatButtonH5)),
                createVNode(unref(_sfc_main$2))
              ]),
              _: 1
            })
          ], 512), [
            [vShow, unref(showToolbar)]
          ]),
          createVNode(unref(PasswordDialogH5), {
            modelValue: unref(roomPasswordVisible),
            "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => isRef(roomPasswordVisible) ? roomPasswordVisible.value = $event : null),
            "room-id": unref(joiningRoomId),
            onCancel: handlePasswordCancel,
            onError: unref(handleJoinRoomError)
          }, null, 8, ["modelValue", "room-id", "onError"])
        ])
      ]);
    };
  }
});
export {
  _sfc_main as default
};
