import React from 'react'
import { ListGroup } from 'react-bootstrap';

function OpenList(props) {

  function enterChatRoomCH(e) {
    if (props.roomCode){
      props.closeChatRoom(props.roomCode)
    }
    
    console.log('e확인', e.target)
    const roomCode = e.target.name
    // props.enterChatRoom(roomCode) // 각각의 room으로 들어가도록 설정해야 함
    props.openListroom(roomCode)
    props.setRoomCode(roomCode)
    // props.clearChat()
  }

  return (
    <div>
      {props.openlist.map((item, index) =>
        <ListGroup key={index}>
          <ListGroup.Item action onClick={enterChatRoomCH} name={item.roomId}>
            {item.roomName}
          </ListGroup.Item>
        </ListGroup>
      )}
    </div>
  )
}

export default OpenList
