import { FC, useState } from 'react'; import { FaCrown, FaDoorOpen, FaExchangeAlt, FaHome, FaLock, FaMapMarkerAlt, FaSearch, FaTimes, FaTrash, FaUserSlash, FaUsers, FaVolumeMute } from 'react-icons/fa'; import { LocalizeText } from '../../../../api'; import { Button } from '../../../../common'; import { useHousekeeping, useHousekeepingConfirm, useRoom } from '../../../../hooks'; const DEFAULT_MUTE_MINUTES = 10; export const HousekeepingRoomsTab: FC = () => { const { selectedRoom, setSelectedRoom, lookupRoomById, isRoomLoading, isActionPending, openRoom, closeRoom, muteRoom, kickAllFromRoom, transferRoomOwnership, deleteRoom } = useHousekeeping(); const { roomSession = null } = useRoom(); const [ query, setQuery ] = useState(''); const [ muteMinutes, setMuteMinutes ] = useState(DEFAULT_MUTE_MINUTES); const [ newOwnerId, setNewOwnerId ] = useState(0); const confirm = useHousekeepingConfirm(); const currentRoomId = roomSession && roomSession.roomId > 0 ? roomSession.roomId : 0; // Empty query + Cerca โ†’ fall back to the room the operator is // currently standing in. Saves a copy-paste of the room id from // navigator just to inspect "this room". Mirrors how /ban / /kick // in chat default to the active room. const submitLookup = () => { const trimmed = query.trim(); const idFromQuery = parseInt(trimmed); const id = (Number.isFinite(idFromQuery) && idFromQuery > 0) ? idFromQuery : currentRoomId; if(id <= 0) return; lookupRoomById(id); }; const useCurrentRoom = () => { if(currentRoomId <= 0) return; setQuery(String(currentRoomId)); lookupRoomById(currentRoomId); }; const disableActions = !selectedRoom || isActionPending; const confirmAndRun = (key: string, fn: () => void) => confirm(LocalizeText(key), fn); const occupancyPct = selectedRoom && selectedRoom.maxUsers > 0 ? Math.min(100, Math.round((selectedRoom.userCount / selectedRoom.maxUsers) * 100)) : 0; return (
{ /* Lookup bar */ }
0 ? `${ LocalizeText('housekeeping.room.search.placeholder') } ยท empty โ†’ current #${ currentRoomId }` : LocalizeText('housekeeping.room.search.placeholder') } value={ query } onChange={ event => setQuery(event.target.value) } onKeyDown={ event => { if(event.key === 'Enter') submitLookup(); } } />
{ currentRoomId > 0 && currentRoomId !== selectedRoom?.id && }
{ /* Selected room hero card */ } { selectedRoom ? (
{ selectedRoom.name } #{ selectedRoom.id } { selectedRoom.isPublic && public } { selectedRoom.isLocked && closed } { selectedRoom.isMuted && muted }
{ selectedRoom.description || 'โ€”' }
{ selectedRoom.userCount } / { selectedRoom.maxUsers } { selectedRoom.ownerName } #{ selectedRoom.ownerId }
{ selectedRoom.maxUsers > 0 &&
85 ? 'bg-rose-500' : occupancyPct > 60 ? 'bg-amber-500' : 'bg-emerald-500' }` } style={ { width: `${ occupancyPct }%` } } />
}
) : (
{ LocalizeText('housekeeping.room.none') }
) } { /* Open / Close + Mute */ }
setMuteMinutes(parseInt(event.target.value) || 0) } /> min
{ /* Transfer ownership card */ }
setNewOwnerId(parseInt(event.target.value) || 0) } />
); };