#pragma once

#include "ConfigValue.h"
#include "../gui/menu/imgui_addons.h"

class CompactTextboxValue : public ConfigValue
{
public:
    CompactTextboxValue(const std::string& initial, const std::string& n, const size_t max_chars = 3)
        : ConfigValue(n), value_(initial), def_(initial), max_chars_(max_chars)
    {
    }

    void draw() override
    {
        imgui_addons::compact_textbox(get_imgui_title(), &value_, max_chars_, disabled_);
    }

    void set(const std::string& string) override
    {
        value_ = string;
        trim();
    }

    std::string get() override
    {
        return value_;
    }

    std::string get_default() override
    {
        return def_;
    }

private:
    std::string value_;
    std::string def_;
    size_t max_chars_;

    void trim()
    {
        if (value_.size() > max_chars_)
            value_.resize(max_chars_);
    }
};