import { Room } from 'matrix-js-sdk';
import { useMemo } from 'react';
import { useStateEvent } from './useStateEvent';
import { StateEvent } from '../../types/matrix/room';

/**
 * Content structure for Paarrot sub-rooms
 */
export interface PaarrotSubRoomsContent {
  children: string[];
}

/**
 * Hook to get the sub-rooms (child rooms) for a given room.
 * Sub-rooms are stored in the room's state as im.paarrot.sub_rooms
 * 
 * @param room - The parent room
 * @returns Array of child room IDs
 */
export const useRoomSubRooms = (room: Room): string[] => {
  const subRoomsEvent = useStateEvent(room, StateEvent.PaarrotSubRooms);
  
  const subRooms = useMemo(() => {
    const content = subRoomsEvent?.getContent<PaarrotSubRoomsContent>();
    return content?.children ?? [];
  }, [subRoomsEvent]);
  
  return subRooms;
};
