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

// dropdown.h  -- Dropdown widget API
#ifndef DROPDOWN_H
#define DROPDOWN_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     (*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);
} DropdownApiT;

static inline const DropdownApiT *dvxDropdownApi(void) {
    static const DropdownApiT *sApi;
    if (!sApi) { sApi = (const DropdownApiT *)wgtGetApi("dropdown"); }
    return sApi;
}

#define wgtDropdown(parent)                  dvxDropdownApi()->create(parent)
#define wgtDropdownSetItems(w, items, count)  dvxDropdownApi()->setItems(w, items, count)
#define wgtDropdownGetSelected(w)            dvxDropdownApi()->getSelected(w)
#define wgtDropdownSetSelected(w, idx)       dvxDropdownApi()->setSelected(w, idx)
#define wgtDropdownAddItem(w, text)          dvxDropdownApi()->addItem(w, text)
#define wgtDropdownRemoveItem(w, idx)        dvxDropdownApi()->removeItem(w, idx)
#define wgtDropdownClear(w)                  dvxDropdownApi()->clear(w)
#define wgtDropdownGetItem(w, idx)           dvxDropdownApi()->getItem(w, idx)
#define wgtDropdownGetItemCount(w)           dvxDropdownApi()->getItemCount(w)

#endif // DROPDOWN_H
