#ifndef FORM_FIELD_HPP_
#define FORM_FIELD_HPP_

#include <Widget/Layout/CompoundWidget/CompoundWidget.hpp>
#include <Widget/Label/Label.hpp>
#include <Widget/Layout/Column/Column.hpp>
#include <Widget/Layout/Margin/Margin.hpp>
#include <Widget/Builder/Builder.hpp>
#include <Color/Color.hpp>
#include <Widget/Panel/Panel.hpp>

/**
 * @brief Form field widget, showing a label, child widget, and optionally an error.
 */
class FormField : public CompoundWidget
{
public:
    template<typename TValue>
    FormField(
        std::string label,
        TValue &valueRef,
        Widget *child,
        std::function<std::string()> getError = [](){return "";}
    ) : CompoundWidget(
        new Margin<0, 2>(
            new Column(
                new Label(label),
                new Panel(glm::ivec2(0, 1)),
                child,
                new Panel(glm::ivec2(0, 1)),
                new Builder<TValue>(
                    valueRef,
                    [getError](TValue)
                    {
                        return new Label(getError(), Color::error);
                    }
                )
            )
        )
    )
    {}
};

#endif