"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useRoomState = void 0;
var _react = require("react");
var _reactRedux = require("react-redux");
/** @format */

const useRoomState = roomJID => {
  const room = (0, _reactRedux.useSelector)(state => roomJID ? state.rooms.rooms[roomJID] : undefined);
  const roomsList = (0, _reactRedux.useSelector)(state => state.rooms.rooms);
  const activeRoomJID = (0, _reactRedux.useSelector)(state => state.rooms.activeRoomJID);
  const visibleRoomJID = (0, _reactRedux.useSelector)(state => state.rooms.visibleRoomJID);
  const editAction = (0, _reactRedux.useSelector)(state => state.rooms.editAction);
  const globalLoading = (0, _reactRedux.useSelector)(state => state.rooms.isLoading);
  const loading = (0, _reactRedux.useSelector)(state => {
    const activeJID = state.rooms.activeRoomJID;
    return activeJID ? state.rooms.rooms[activeJID]?.isLoading || false : false;
  });
  const loadingText = (0, _reactRedux.useSelector)(state => state.rooms.loadingText);
  const usersSet = (0, _reactRedux.useSelector)(state => state.rooms.usersSet);
  const roomMessages = (0, _react.useMemo)(() => activeRoomJID && roomsList[activeRoomJID] ? roomsList[activeRoomJID].messages || [] : [], [roomsList, activeRoomJID]);
  return {
    room,
    roomsList,
    activeRoomJID,
    visibleRoomJID,
    editAction,
    globalLoading,
    loadingText,
    loading,
    roomMessages,
    usersSet
  };
};
exports.useRoomState = useRoomState;
//# sourceMappingURL=useRoomState.js.map