#pragma once

#include "UI/base/GuiWindow.h"
#include <unordered_map>
#include <vector>
#include "Types.hpp"
#include <chrono>
#include "Debug.hpp"

namespace TSE::EDITOR
{
    struct LogEntry
    {
        public:
        LogEntryType type;
        string msg;
        std::chrono::hh_mm_ss<std::chrono::milliseconds> time;
        int count = 1;

        inline LogEntry(const string& message, const LogEntryType& t)
        {
            msg = message;
            type = t;

            auto now = std::chrono::system_clock::now();

            auto today = std::chrono::floor<std::chrono::days>(now);
            auto time_since_midnight = now - today;

            time = std::chrono::hh_mm_ss<std::chrono::milliseconds>(std::chrono::floor<std::chrono::milliseconds>(time_since_midnight));

        };
        
        inline string CreateTimedMSG()
        {
            string res = std::to_string(time.hours().count()) + ":" + std::to_string(time.minutes().count()) + ":" + std::to_string(time.seconds().count());
            res += " -> " + msg;
            if(count > 1)
            {
                res += " (" + std::to_string(count) + ")";
            }
            return res;
        }
    };

    class ConsolView : public GuiWindow
    {
    private:
        static inline std::vector<LogEntry> entries = {};

        bool logs = false, warnings = false, errors = false, autoScroll = true;
        char* textbuffer = new char[512];
    public:
        static std::vector<string> arguments;

        ConsolView();
        ~ConsolView();
        void MenuBar();
        void LogList();
        void Input();
        void Define() override;
        void HandleInput(const string& input);
        static void CreateLogEntry(const string& msg, const LogEntryType& t);
    };
} // namespace TSE::EDITOR
