#pragma once

#include "block.h"

#include <cstdint>
#include <string>
#include <vector>

enum class CubeNetFace : std::uint8_t {
    Top = 0,
    Left = 1,
    Front = 2,
    Right = 3,
    Back = 4,
    Bottom = 5
};

struct TextureAtlasData {
    int width = 0;
    int height = 0;
    std::vector<std::uint8_t> pixels;
};

namespace TextureAtlasConfig {
    constexpr int FaceSize = 16;
    constexpr int BlockNetWidth = 64;
    constexpr int BlockNetHeight = 48;

    constexpr int AtlasColumns = 8;

    constexpr int SupportedBlockCount = 11; // без Air (world blocks)
    constexpr int ItemTypeCount = 5;        // Stick, WoodPickaxe, etc.
    constexpr int FacesPerBlock = 6;
    constexpr int BlockTiles = SupportedBlockCount * FacesPerBlock; // 66
    constexpr int TotalTiles = SupportedBlockCount * FacesPerBlock + ItemTypeCount; // 66+5=71
    constexpr int ItemTileStart = SupportedBlockCount * FacesPerBlock; // = 66
    constexpr int AtlasRows = (TotalTiles + AtlasColumns - 1) / AtlasColumns;

    constexpr int AtlasWidth = AtlasColumns * FaceSize;
    constexpr int AtlasHeight = AtlasRows * FaceSize;
}

class TextureAtlasBuilder {
public:
    static TextureAtlasData buildFromFolder(const std::string& folder);
};

int blockTextureOrderIndex(BlockType type);
int atlasTileIndex(BlockType type, CubeNetFace face);