"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const vue = require("vue");
const uikitBaseComponentVue3 = require("@tencentcloud/uikit-base-component-vue3");
const room = require("tuikit-atomicx-vue3/room");
require("./useRoomSidePanel.js");
;/* empty css                                 */
;/* empty css                                     */
;/* empty css                                         */
require("tuikit-atomicx-vue3/chat");
require("../utils/utils.js");
;/* empty css                                      */
;/* empty css                                  */
;/* empty css                                   */
;/* empty css                                     */
;/* empty css                                        */
;/* empty css                                    */
;/* empty css                                    */
;/* empty css                                      */
;/* empty css                                       */
;/* empty css                                           */
;/* empty css                                      */
;/* empty css                                      */
;/* empty css                                        */
;/* empty css                                      */
;/* empty css                                    */
require("@tencentcloud/tuiroom-engine-js");
;/* empty css                                               */
;/* empty css                                              */
;/* empty css                                         */
;/* empty css                                      */
;/* empty css                                        */
;/* empty css                                     */
;/* empty css                                       */
;/* empty css                                     */
;/* empty css                                 */
;/* empty css                                       */
;/* empty css                                   */
;/* empty css                                  */
;/* empty css                                           */
;/* empty css                                      */
;/* empty css                                        */
;/* empty css                                        */
require("tuikit-atomicx-vue3/live");
;/* empty css                                         */
;/* empty css                                        */
;/* empty css                                         */
;/* empty css                                */
;/* empty css                                          */
;/* empty css                                           */
;/* empty css                                     */
;/* empty css                                       */
const index = require("../components/RoomInvitationH5/index.js");
;/* empty css                                              */
;/* empty css                                    */
;/* empty css                                                                            */
;/* empty css                                                                            */
;/* empty css                                                               */
;/* empty css                                                          */
;/* empty css                                        */
;/* empty css                                     */
;/* empty css                                                             */
;/* empty css                                           */
;/* empty css                                         */
;/* empty css                                             */
;/* empty css                                              */
;/* empty css                                              */
;/* empty css                                       */
;/* empty css                                         */
;/* empty css                                   */
;/* empty css                                               */
;/* empty css                                      */
const defaultAvatarUrl = "https://web.sdk.qcloud.com/component/TUIKit/assets/avatar_16.png";
function useRoomInvitationH5(options) {
  const { t } = uikitBaseComponentVue3.useUIKit();
  const { currentRoom, subscribeEvent, rejectCall, acceptCall } = room.useRoomState();
  const handleRoomCallReceived = ({ roomInfo, call }) => {
    var _a;
    const { caller } = call;
    if ((_a = currentRoom.value) == null ? void 0 : _a.roomId) {
      rejectCall({ roomId: roomInfo.roomId, reason: room.CallRejectReason.InOtherRoom });
      return;
    }
    const invitationOptions = {
      inviterName: caller.userName,
      inviterAvatar: caller.avatarUrl || defaultAvatarUrl,
      roomName: roomInfo.roomName,
      hostName: roomInfo.roomOwner.userName,
      participantCount: roomInfo.participantCount ?? 0,
      duration: 60,
      onCancel: () => {
        rejectCall({ roomId: roomInfo.roomId });
      },
      onAccept: () => {
        acceptCall({ roomId: roomInfo.roomId });
        if (options == null ? void 0 : options.onAcceptCall) {
          options.onAcceptCall({
            roomId: roomInfo.roomId,
            password: roomInfo.password || ""
          });
        }
      }
    };
    index.showRoomInvitationH5(invitationOptions);
  };
  const onRoomCallHandledByOtherDevice = () => {
    uikitBaseComponentVue3.TUIToast.info({ message: t("RoomInvitation.HandleByOtherDevice") });
    index.hideRoomInvitationH5();
  };
  vue.onMounted(() => {
    subscribeEvent(room.RoomEvent.onCallReceived, handleRoomCallReceived);
    subscribeEvent(room.RoomEvent.onCallHandledByOtherDevice, onRoomCallHandledByOtherDevice);
  });
}
exports.useRoomInvitationH5 = useRoomInvitationH5;
