/****************************************************************************
** Copyright (c) 2016, Fougue SAS <https://www.fougue.pro>
** SPDX-License-Identifier: BSD-2-Clause
****************************************************************************/

#pragma once

#include "../base/document_ptr.h"
#include "../base/document_tree_node.h"
#include "../base/property_builtins.h"
#include "widget_model_tree.h"
#include <QtCore/QString>
class QAction;
class QObject;
class QTreeWidget;
class QTreeWidgetItem;

namespace Mayo {

// TODO Rename Builder -> Extension ?
class WidgetModelTreeBuilder {
public:
    virtual ~WidgetModelTreeBuilder();

    virtual bool supportsDocument(const DocumentPtr&) const { return true; }
    virtual bool supportsDocumentTreeNode(const DocumentTreeNode&) const { return true; }

    virtual void refreshTextTreeItem(const DocumentPtr& doc, QTreeWidgetItem* treeItem);
    virtual void refreshTextTreeItem(const DocumentTreeNode& node, QTreeWidgetItem* treeItem);

    virtual QTreeWidgetItem* createTreeItem(const DocumentPtr& doc);
    virtual QTreeWidgetItem* createTreeItem(const DocumentTreeNode& node);

    QTreeWidget* treeWidget() const { return m_treeWidget; }
    void setTreeWidget(QTreeWidget* tree) { m_treeWidget = tree; }

    virtual WidgetModelTree_UserActions createUserActions(QObject* /*parent*/) { return {}; }

    virtual std::unique_ptr<WidgetModelTreeBuilder> clone() const;

protected:
    static QString labelText(const PropertyString& propLabel);
    static QString labelText(const QString& label);
    static QString labelText(const TDF_Label& label);

private:
    QTreeWidget* m_treeWidget = nullptr;
};

} // namespace Mayo
