"use strict";

/** @format */

import { useMemo } from 'react';
import { useSelector } from 'react-redux';
export const useRoomState = roomJID => {
  const room = useSelector(state => roomJID ? state.rooms.rooms[roomJID] : undefined);
  const roomsList = useSelector(state => state.rooms.rooms);
  const activeRoomJID = useSelector(state => state.rooms.activeRoomJID);
  const visibleRoomJID = useSelector(state => state.rooms.visibleRoomJID);
  const editAction = useSelector(state => state.rooms.editAction);
  const globalLoading = useSelector(state => state.rooms.isLoading);
  const loading = useSelector(state => {
    const activeJID = state.rooms.activeRoomJID;
    return activeJID ? state.rooms.rooms[activeJID]?.isLoading || false : false;
  });
  const loadingText = useSelector(state => state.rooms.loadingText);
  const usersSet = useSelector(state => state.rooms.usersSet);
  const roomMessages = useMemo(() => activeRoomJID && roomsList[activeRoomJID] ? roomsList[activeRoomJID].messages || [] : [], [roomsList, activeRoomJID]);
  return {
    room,
    roomsList,
    activeRoomJID,
    visibleRoomJID,
    editAction,
    globalLoading,
    loadingText,
    loading,
    roomMessages,
    usersSet
  };
};
//# sourceMappingURL=useRoomState.js.map