#ifndef WORLD_SELECTION_HPP_
#define WORLD_SELECTION_HPP_

#include <Widget/TextField/TextField.hpp>
#include <string>
#include <memory>
#include <Display/WidgetDisplay/WidgetDisplay.hpp>
#include <Widget/Layout/Column/Column.hpp>
#include <WorldIndex/WorldIndex.hpp>

/**
 * @brief World selection display.
 */
class WorldSelection : public WidgetDisplay
{
private:
    struct WorldListEntry
    {
        std::string name;
        std::shared_ptr<WorldIndex> index;
        std::string error;

        Widget* makeWidget(WorldSelection &display);
        bool operator==(const WorldListEntry &other) const;
    };

    static constexpr Uint32 ticksBetweenRefreshes = 1000;

    std::vector<WorldListEntry> worlds;
    WorldListEntry selectedWorld;
    Uint32 lastRefreshTicks;
    
    std::string worldBeingRenamed;
    std::string newWorldName;
    TextField *renameField;

    void refresh();
    
public:
    WorldSelection();

    virtual void update() override;
};

#endif