/*
 *
 * Copyright (c) Souldbminer, Lightos_ and Horizon OC Contributors
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
#pragma once
#include <set>
#include <string>
#include <vector>

#include "../../ipc.h"
#include "base_menu_gui.h"
#include "freq_choice_gui.h"
#include "info_gui.h"
#include "value_choice_gui.h"
#include <initializer_list>
#include <unordered_map>
class MiscGui : public BaseMenuGui {
    public:
    MiscGui();
    ~MiscGui();
    void listUI() override;
    void refresh() override;

    protected:
    HocClkConfigValueList *configList;
    std::map<HocClkConfigValue, tsl::elm::ListItem *> configButtons;
    std::map<HocClkConfigValue, ValueRange> configRanges;
    std::map<HocClkConfigValue, std::vector<NamedValue>> configNamedValues;
    std::map<HocClkConfigValue, tsl::elm::ToggleListItem *> configToggles;
    std::map<HocClkConfigValue, std::tuple<tsl::elm::TrackBar *, tsl::elm::ListItem *, std::vector<uint64_t>>> configTrackbars;
    std::set<HocClkConfigValue> configButtonSKeys;
    std::map<HocClkConfigValue, std::string> configButtonSSubtext;
    std::set<HocClkConfigValue> emcClockConfigs;

    void addConfigToggle(HocClkConfigValue configVal, const char *altName, bool kip = false);
    void addConfigTrackbar(HocClkConfigValue configVal, const char *altName, const ValueRange &range, bool kip = true);
    void addMappedConfigTrackbar(HocClkConfigValue configVal, const char *altName, std::vector<u32> vals, std::initializer_list<std::string> names,
                                 bool kip = true);
    void addConfigButton(HocClkConfigValue configVal, const char *altName, const ValueRange &range, const std::string &categoryName,
                         const ValueThresholds *thresholds, const std::map<uint32_t, std::string> &labels = {},
                         const std::vector<NamedValue> &namedValues = {}, bool showDefaultValue = true, bool kip = false);

    void addConfigButtonS(HocClkConfigValue configVal, const char *altName, const ValueRange &range, const std::string &categoryName,
                          const ValueThresholds *thresholds, const std::map<uint32_t, std::string> &labels = {},
                          const std::vector<NamedValue> &namedValues = {}, bool showDefaultValue = true, const char *subText = nullptr,
                          bool kip = false);
    void addFreqButton(HocClkConfigValue configVal, const char *altName, HocClkModule module, const std::map<uint32_t, std::string> &labels = {});
    void addGpuFreqVoltageButton(HocClkConfigValue configVal, const char *altName, uint32_t freqHz, const ValueRange &range,
                              const std::string &categoryName, const ValueThresholds *thresholds,
                              const std::map<uint32_t, std::string> &labels, const std::vector<NamedValue> &namedValues,
                              bool showDefaultValue, bool kip);
    void updateConfigToggles();

    tsl::elm::ToggleListItem *enabledToggle;
    u8 frameCounter = 60;
    bool shouldSaveKip = false;
    std::string getJumpToItemName() override;
};
