#include "DeerStudio/EditorEngine.h"
#include "DeerRender/Render/Texture.h"
#include "Deer/DataStore.h"

#include <unordered_map>

namespace Deer {
    namespace DataStore {
        std::unordered_map<std::string, Ref<Texture2D>> icons;
    }

    int DataStore::getIconId(const std::string& name) {
        if (icons.contains(name))
            return icons[name]->getTextureID();
        
        uint8_t* data;
        uint32_t size;

        if (!DataStore::loadGlobalFileData(DEER_EDITOR_PATH, name, &data, &size))
            return -1;
        
        icons[name] = Texture2D::create(data, size);
        DataStore::freeFileData(data);

        return icons[name]->getTextureID();
    }

}