#include <eedb/widgets/DefaultCategoryTree.hpp>

#include <eedb/data/Category.hpp>

#include <Wt/WContainerWidget>
#include <Wt/WTreeView>

namespace std {

template <>
struct default_delete< Wt::WTreeView > {
    void operator()(Wt::WTreeView * ptr) {
        if(ptr && !ptr->parent())
            delete ptr;
    }
};
}

namespace eedb {

struct DefaultCategoriesTree::DefaultCategoriesTreePriv {
    DefaultCategoriesTreePriv() : tree(std::make_unique< Wt::WTreeView >()) {
        tree->setObjectName("categories_tree");
    }

    std::unique_ptr< Wt::WTreeView > tree;
};

DefaultCategoriesTree::DefaultCategoriesTree() : _priv(std::make_unique< DefaultCategoriesTreePriv >()) {}
DefaultCategoriesTree::~DefaultCategoriesTree() = default;

void DefaultCategoriesTree::attachTo(Wt::WContainerWidget * parent) {
    parent->addWidget(_priv->tree.get());
}

void DefaultCategoriesTree::registerOnCategoryChanged(std::function< void(const Category &) >) {}
}
