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

// spinner.h  -- Spinner widget API
#ifndef SPINNER_H
#define SPINNER_H

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

typedef struct {
    WidgetT *(*create)(WidgetT *parent, int32_t minVal, int32_t maxVal, int32_t step);
    void     (*setValue)(WidgetT *w, int32_t value);
    int32_t  (*getValue)(const WidgetT *w);
    void     (*setRange)(WidgetT *w, int32_t minVal, int32_t maxVal);
    void     (*setStep)(WidgetT *w, int32_t step);
    void     (*setRealMode)(WidgetT *w, bool enable);
    double   (*getRealValue)(const WidgetT *w);
    void     (*setRealValue)(WidgetT *w, double value);
    void     (*setRealRange)(WidgetT *w, double minVal, double maxVal);
    void     (*setRealStep)(WidgetT *w, double step);
    void     (*setDecimals)(WidgetT *w, int32_t decimals);
} SpinnerApiT;

static inline const SpinnerApiT *dvxSpinnerApi(void) {
    static const SpinnerApiT *sApi;
    if (!sApi) { sApi = (const SpinnerApiT *)wgtGetApi("spinner"); }
    return sApi;
}

#define wgtSpinner(parent, minVal, maxVal, step) dvxSpinnerApi()->create(parent, minVal, maxVal, step)
#define wgtSpinnerSetValue(w, value)             dvxSpinnerApi()->setValue(w, value)
#define wgtSpinnerGetValue(w)                    dvxSpinnerApi()->getValue(w)
#define wgtSpinnerSetRange(w, minVal, maxVal)    dvxSpinnerApi()->setRange(w, minVal, maxVal)
#define wgtSpinnerSetStep(w, step)               dvxSpinnerApi()->setStep(w, step)
#define wgtSpinnerSetRealMode(w, enable)         dvxSpinnerApi()->setRealMode(w, enable)
#define wgtSpinnerGetRealValue(w)                dvxSpinnerApi()->getRealValue(w)
#define wgtSpinnerSetRealValue(w, value)         dvxSpinnerApi()->setRealValue(w, value)
#define wgtSpinnerSetRealRange(w, minVal, maxVal) dvxSpinnerApi()->setRealRange(w, minVal, maxVal)
#define wgtSpinnerSetRealStep(w, step)           dvxSpinnerApi()->setRealStep(w, step)
#define wgtSpinnerSetDecimals(w, decimals)       dvxSpinnerApi()->setDecimals(w, decimals)

#endif // SPINNER_H
