#ifndef FONT_HPP_
#define FONT_HPP_

#include <Bitmap/Bitmap.hpp>
#include <cstdint>
#include <Utilities/Extern.hpp>
#include <Material/Material.hpp>
#include <memory>
#include <set>
#include <string>

/**
 * @brief Represents font information, typically loaded from assets.
 */
class Font final
{
public:
    struct Sheet
    {
        Material mat;
        Bitmap bitmap = Bitmap(glm::uvec2(1, 1));
    };

private:
    std::string name;
    std::set<std::string> includedModules;
    Sheet *currentSheet = nullptr;
    std::unordered_map<std::string, std::unique_ptr<Sheet>> sheets;

    int tryParseSheetAttr(const std::string &attr);

    bool tryParseRangeStatement(const std::string &line);
    bool tryParseGlyphHeightStatement(const std::string &line);
    bool tryParseIncludeStatement(const std::string &line);
    bool tryParseSheetStatement(const std::string &line);

    void includeDefFile(const std::string &defFilePath);

public:
    struct Glyph
    {
        Sheet *sheet;
        glm::ivec2 sheetBase;
        int width;
    };

    int glyphHeight;
    std::unordered_map<uint64_t, Glyph> codepointGlyphs;

    void load(const char *name, std::atomic<unsigned int> &tasksDone);

    #define DECL_FONT(name) static Font name
    #include <Font/FontList.hpp>
};

#endif