// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2005-2011, Jari Sundell <jaris@ifi.uio.no>

#ifndef RTORRENT_UI_ELEMENT_PEER_LIST_H
#define RTORRENT_UI_ELEMENT_PEER_LIST_H

#include <torrent/peer/connection_list.h>

#include "core/download.h"
#include "ui/element_base.h"

namespace ui {

class ElementText;

class ElementPeerList : public ElementBase {
public:
  using PList = std::list<torrent::Peer*>;

  using signal_connection = torrent::ConnectionList::signal_peer_type::iterator;

  using Display = enum { DISPLAY_LIST, DISPLAY_INFO, DISPLAY_MAX_SIZE };

  ElementPeerList(core::Download* d);
  ~ElementPeerList() override;

  void activate(display::Frame* frame, bool focus = true) override;
  void disable() override;

  void activate_display(Display display);

private:
  inline ElementText* create_info();

  void receive_next();
  void receive_prev();

  void receive_disconnect_peer();

  void receive_peer_connected(torrent::Peer* p);
  void receive_peer_disconnected(torrent::Peer* p);

  void receive_snub_peer();
  void receive_ban_peer();

  void update_itr();

  core::Download* m_download;

  Display          m_state;
  display::Window* m_windowList;

  ElementText* m_elementInfo;

  PList           m_list;
  PList::iterator m_listItr;

  signal_connection m_peer_connected;
  signal_connection m_peer_disconnected;
};

}

#endif
