// 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.

// listBox.h  -- ListBox widget API
#ifndef LISTBOX_H
#define LISTBOX_H

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

typedef struct {
    WidgetT *(*create)(WidgetT *parent);
    void     (*setItems)(WidgetT *w, const char **items, int32_t count);
    int32_t  (*getSelected)(const WidgetT *w);
    void     (*setSelected)(WidgetT *w, int32_t idx);
    void     (*setMultiSelect)(WidgetT *w, bool multi);
    bool     (*isItemSelected)(const WidgetT *w, int32_t idx);
    void     (*setItemSelected)(WidgetT *w, int32_t idx, bool selected);
    void     (*selectAll)(WidgetT *w);
    void     (*clearSelection)(WidgetT *w);
    void     (*setReorderable)(WidgetT *w, bool reorderable);
    void     (*addItem)(WidgetT *w, const char *text);
    void     (*removeItem)(WidgetT *w, int32_t idx);
    void     (*clear)(WidgetT *w);
    const char *(*getItem)(const WidgetT *w, int32_t idx);
    int32_t  (*getItemCount)(const WidgetT *w);
} ListBoxApiT;

static inline const ListBoxApiT *dvxListBoxApi(void) {
    static const ListBoxApiT *sApi;
    if (!sApi) { sApi = (const ListBoxApiT *)wgtGetApi("listbox"); }
    return sApi;
}

#define wgtListBox(parent)                          dvxListBoxApi()->create(parent)
#define wgtListBoxSetItems(w, items, count)          dvxListBoxApi()->setItems(w, items, count)
#define wgtListBoxGetSelected(w)                     dvxListBoxApi()->getSelected(w)
#define wgtListBoxSetSelected(w, idx)                dvxListBoxApi()->setSelected(w, idx)
#define wgtListBoxSetMultiSelect(w, multi)           dvxListBoxApi()->setMultiSelect(w, multi)
#define wgtListBoxIsItemSelected(w, idx)             dvxListBoxApi()->isItemSelected(w, idx)
#define wgtListBoxSetItemSelected(w, idx, selected)  dvxListBoxApi()->setItemSelected(w, idx, selected)
#define wgtListBoxSelectAll(w)                       dvxListBoxApi()->selectAll(w)
#define wgtListBoxClearSelection(w)                  dvxListBoxApi()->clearSelection(w)
#define wgtListBoxSetReorderable(w, reorderable)     dvxListBoxApi()->setReorderable(w, reorderable)

#endif // LISTBOX_H
