// The MIT License (MIT)
//
// Copyright (C) 2026 Scott Duensing
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.

// treeView.h  -- TreeView widget API
#ifndef TREEVIEW_H
#define TREEVIEW_H

#include "../../../libs/kpunch/libdvx/dvxWgt.h"

typedef struct {
    WidgetT *(*create)(WidgetT *parent);
    WidgetT *(*getSelected)(const WidgetT *w);
    void     (*setSelected)(WidgetT *w, WidgetT *item);
    void     (*setMultiSelect)(WidgetT *w, bool multi);
    void     (*setReorderable)(WidgetT *w, bool reorderable);
    WidgetT *(*item)(WidgetT *parent, const char *text);
    void     (*itemSetExpanded)(WidgetT *w, bool expanded);
    bool     (*itemIsExpanded)(const WidgetT *w);
    bool     (*itemIsSelected)(const WidgetT *w);
    void     (*itemSetSelected)(WidgetT *w, bool selected);
} TreeViewApiT;

static inline const TreeViewApiT *dvxTreeViewApi(void) {
    static const TreeViewApiT *sApi;
    if (!sApi) { sApi = (const TreeViewApiT *)wgtGetApi("treeview"); }
    return sApi;
}

#define wgtTreeView(parent)                       dvxTreeViewApi()->create(parent)
#define wgtTreeViewGetSelected(w)                 dvxTreeViewApi()->getSelected(w)
#define wgtTreeViewSetSelected(w, item)           dvxTreeViewApi()->setSelected(w, item)
#define wgtTreeViewSetMultiSelect(w, multi)       dvxTreeViewApi()->setMultiSelect(w, multi)
#define wgtTreeViewSetReorderable(w, reorderable) dvxTreeViewApi()->setReorderable(w, reorderable)
#define wgtTreeItem(parent, text)                 dvxTreeViewApi()->item(parent, text)
#define wgtTreeItemSetExpanded(w, expanded)       dvxTreeViewApi()->itemSetExpanded(w, expanded)
#define wgtTreeItemIsExpanded(w)                  dvxTreeViewApi()->itemIsExpanded(w)
#define wgtTreeItemIsSelected(w)                  dvxTreeViewApi()->itemIsSelected(w)
#define wgtTreeItemSetSelected(w, selected)       dvxTreeViewApi()->itemSetSelected(w, selected)

#endif // TREEVIEW_H
