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

// comboBox.h  -- ComboBox widget API
#ifndef COMBOBOX_H
#define COMBOBOX_H

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

typedef struct {
    WidgetT *(*create)(WidgetT *parent, int32_t maxLen);
    void     (*setItems)(WidgetT *w, const char **items, int32_t count);
    int32_t  (*getSelected)(const WidgetT *w);
    void     (*setSelected)(WidgetT *w, int32_t idx);
    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);
} ComboBoxApiT;

static inline const ComboBoxApiT *dvxComboBoxApi(void) {
    static const ComboBoxApiT *sApi;
    if (!sApi) { sApi = (const ComboBoxApiT *)wgtGetApi("combobox"); }
    return sApi;
}

#define wgtComboBox(parent, maxLen)             dvxComboBoxApi()->create(parent, maxLen)
#define wgtComboBoxSetItems(w, items, count)    dvxComboBoxApi()->setItems(w, items, count)
#define wgtComboBoxGetSelected(w)              dvxComboBoxApi()->getSelected(w)
#define wgtComboBoxSetSelected(w, idx)         dvxComboBoxApi()->setSelected(w, idx)
#define wgtComboBoxAddItem(w, text)            dvxComboBoxApi()->addItem(w, text)
#define wgtComboBoxRemoveItem(w, idx)          dvxComboBoxApi()->removeItem(w, idx)
#define wgtComboBoxClear(w)                    dvxComboBoxApi()->clear(w)
#define wgtComboBoxGetItem(w, idx)             dvxComboBoxApi()->getItem(w, idx)
#define wgtComboBoxGetItemCount(w)             dvxComboBoxApi()->getItemCount(w)

#endif // COMBOBOX_H
