#include <sstream>
#include <random>

#include <Widget/Layout/CompoundWidget/WorldSeedField/WorldSeedField.hpp>
#include <Widget/TextField/TextField.hpp>
#include <Widget/Button/Button.hpp>
#include <Widget/Layout/Row/Row.hpp>

WorldSeedField::WorldSeedField(std::string &text, std::function<void()> onAccept) :
    CompoundWidget(
        new Row(
            Layout::WithProportion<1>(),
            new TextField(text, onAccept),
            (new Button("", [&text]()
            {
                std::random_device rd;
                std::mt19937_64 gen(rd());
                std::uniform_int_distribution<uint64_t> dis;

                std::stringstream ss;
                ss << dis(gen);
                text = ss.str();
            }))
            ->withIcon(Material::random)
            ->withToolTip("Random")
        )
    )
{}