import { onMounted } from "vue";
import { useUIKit, TUIToast } from "@tencentcloud/uikit-base-component-vue3";
import { useRoomState, RoomEvent, CallRejectReason } from "tuikit-atomicx-vue3/room";
import "./useRoomSidePanel.mjs";
/* empty css                                 */
/* empty css                                     */
/* empty css                                         */
import "tuikit-atomicx-vue3/chat";
import "../utils/utils.mjs";
/* 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                                    */
import "@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                                        */
import "tuikit-atomicx-vue3/live";
/* empty css                                         */
/* empty css                                        */
/* empty css                                         */
/* empty css                                */
/* empty css                                          */
/* empty css                                           */
/* empty css                                     */
/* empty css                                       */
import { showRoomInvitationH5, hideRoomInvitationH5 } from "../components/RoomInvitationH5/index.mjs";
/* 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 } = useUIKit();
  const { currentRoom, subscribeEvent, rejectCall, acceptCall } = useRoomState();
  const handleRoomCallReceived = ({ roomInfo, call }) => {
    var _a;
    const { caller } = call;
    if ((_a = currentRoom.value) == null ? void 0 : _a.roomId) {
      rejectCall({ roomId: roomInfo.roomId, reason: 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 || ""
          });
        }
      }
    };
    showRoomInvitationH5(invitationOptions);
  };
  const onRoomCallHandledByOtherDevice = () => {
    TUIToast.info({ message: t("RoomInvitation.HandleByOtherDevice") });
    hideRoomInvitationH5();
  };
  onMounted(() => {
    subscribeEvent(RoomEvent.onCallReceived, handleRoomCallReceived);
    subscribeEvent(RoomEvent.onCallHandledByOtherDevice, onRoomCallHandledByOtherDevice);
  });
}
export {
  useRoomInvitationH5
};
