#pragma once
#include <sstream>

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

#pragma pack(push, 1)
class CheckboxValue : public ConfigValue
{
public:
    CheckboxValue(const bool initial, const std::string& n, const bool safety_switch = false) : ConfigValue(n)
    {
        this->value_ = initial;
        this->def_ = initial;
        this->safety_switch_ = safety_switch;
    }

    void draw() override
    {
        imgui_addons::checkbox(this->get_imgui_title(), &this->value_, disabled_, master_toggle_, safety_switch_);
    }

    void set(const std::string& string) override
    {
        this->value_ = from_string(string);
    }

    std::string get() override
    {
        return to_string(this->value_);
    }

    std::string get_default() override
    {
        return to_string(this->def_);
    }

    [[nodiscard]] bool get_value() const
    {
        return this->value_;
    }

    void set_value(const bool v)
    {
        this->value_ = v;
    }

private:
    bool value_;
    bool def_;
    bool safety_switch_ = false;

    static std::string to_string(bool v)
    {
        std::ostringstream os("");
        os << std::boolalpha << v;
        return os.str();
    }

    static bool from_string(std::string string)
    {
        bool b1;
        std::istringstream is(string);
        is >> std::boolalpha >> b1;
        return b1;
    }
};
#pragma pack(pop)
