#include <Color/Color.hpp>
#include <Encyclopedia/Encyclopedia.hpp>
#include <Widget/Label/Label.hpp>
#include <Widget/Layout/CompoundWidget/DocView/DocView.hpp>
#include <Widget/Layout/CompoundWidget/EncyclopediaView/EncyclopediaView.hpp>
#include <Widget/Layout/Frame/Frame.hpp>
#include <Widget/Layout/ScrollPanel/ScrollPanel.hpp>

EncyclopediaView::EncyclopediaView(int width, const std::string &url, const std::string &stateUrl)
{
    const std::string *pageContent = encyclopedia.tryGetPage(url);

    Widget *body;
    if (pageContent != nullptr)
    {
        body = new DocView(width, *pageContent);
    }
    else
    {
        body = new Label(formatString("ERROR:\nPage not found:\n$+", url), Color::error);
    }

    addChildren(
        new ScrollPanel(
            stateUrl,
            100,
            new Frame(
                glm::vec4(0.0f, 0.0f, 0.0f, 1.0f),
                body
            )
        )
    );
}