#pragma once

#include <Button.h>
#include <HashMap.h>
#include <List.h>
#include <TextField.h>

#include "Menu.h"

class ServerStatus : public DrawableBackground
{
private:
    Framework::Text name;
    Framework::Text ip;
    unsigned short sslPort;
    unsigned short port;
    Framework::Text playerName;
    int ping;
    Framework::Text status;
    int statusId;
    int requestId;
    Framework::HashMap<Framework::Text, Framework::Text>* secrets;
    Framework::Button* removeButton;
    Framework::Button* join;
    ReadWriteLock requestIdLock;

public:
    ServerStatus(Framework::Text name,
        Framework::Text ip,
        unsigned short sslPort,
        unsigned short port,
        Framework::HashMap<Framework::Text, Framework::Text>* secrets);
    ~ServerStatus();

    virtual void updatePlayerName(Framework::Text playerName);

    virtual void doMouseEvent(Framework::MouseEvent& me, bool userRet) override;
    virtual bool tick(double time) override;
    virtual void render(Framework::Image& rObj) override;

    Framework::Text getName() const;
    Framework::Text getIp() const;
    unsigned short getSSLPort() const;
    unsigned short getPort() const;
    Framework::HashMap<Framework::Text, Framework::Text>* zSecrets() const;
    bool canConnect() const;
};

class ServerSelectionMenu : public Menu
{
private:
    Framework::TextField* playerName;
    Framework::TextField* playerNameLabel;
    Framework::TextField* serverLabel;
    Framework::DrawableList* serverList;
    Framework::Button* add;
    Framework::Button* refresh;
    Framework::Button* exit;

public:
    ServerSelectionMenu(Framework::Screen* zScreen);
    void addServer(Framework::Text name,
        Framework::Text ip,
        unsigned short sslPort,
        unsigned short port);
    bool hasServer(Framework::Text name) const;
    void removeServer(Framework::Text name) const;
    void saveServers() const;
};