#include <Display/WidgetDisplay/MessageDisplay/MessageDisplay.hpp>
#include <Log/Log.hpp>
#include <Widget/Layout/Center/Center.hpp>
#include <Widget/Layout/Column/Column.hpp>
#include <Widget/Label/Label.hpp>
#include <Widget/Layout/CompoundWidget/Form/Form.hpp>
#include <Widget/Layout/CompoundWidget/IconText/IconText.hpp>
#include <Widget/Panel/Panel.hpp>
#include <sstream>

MessageDisplay::MessageDisplay(Material &icon, const std::string &caption, const std::string &message)
{
    std::vector<Widget*> labels;

    std::istringstream iss(message);
    std::string line;

    while (std::getline(iss, line))
    {
        labels.push_back(new Label(line));
    }

    setWidget(
        new Center(
            new Form(
                new IconText(icon, caption),
                new Center(new Column(new Panel(glm::ivec2(150, 0)), labels)),

                Layout::WithProportion<1>(),
                new Center(
                    new Column(
                        new Panel(glm::ivec2(50, 0)),
                        new Button("OK", [](){ Display::navPop(); })
                    )
                )
            )
        )
    );
}