#pragma once



#include <string>
#include <GL/glew.h>
#include <glm/glm.hpp>
#include <ctime>


// here so i only need to include once.
#include "Profiler.h"
#include "Logging.h"
#include "FileDialog.h"
#include "EngineConfig.h"

#include "AssetManager.h"

struct ImageCacheEntry {
    unsigned int textureID;
    glm::vec2 size;
};

extern std::unordered_map<std::string, ImageCacheEntry> textureCache;



// Returns filename from a full path (e.g., "C:/foo/bar.png" → "bar.png")
std::string GetFilenameFromPath(const std::string& path);



GLuint LoadTextureIfNeeded(const std::string& path);
ImageCacheEntry LoadImageCache(const std::string& path);

GLuint EngineLoadTextureIfNeeded(const std::string &path);


bool DeleteLatestLogFile();

bool IsWindowVisibleTab(const char* name);

std::string HashString(const std::string& data);
std::time_t GetFileLastWrite(const std::string &path);

std::string GetFileHash(const std::string &path);


// HSV → RGB helper
inline glm::vec3 HSVtoRGB(float h, float s, float v)
{
    float r, g, b;

    int i = int(h * 6);
    float f = h * 6 - i;
    float p = v * (1 - s);
    float q = v * (1 - f * s);
    float t = v * (1 - (1 - f) * s);

    switch (i % 6)
    {
        case 0: r = v; g = t; b = p; break;
        case 1: r = q; g = v; b = p; break;
        case 2: r = p; g = v; b = t; break;
        case 3: r = p; g = q; b = v; break;
        case 4: r = t; g = p; b = v; break;
        case 5: r = v; g = p; b = q; break;
    }

    return glm::vec3(r, g, b);
}

inline std::string GetFileExtension(const std::string &path)
{
    size_t dot = path.find_last_of('.');
    if (dot == std::string::npos)
        return "";
    return path.substr(dot + 1);
}