#pragma once

#include <stdint.h>
#include <led-matrix.h>

namespace cube {

// Default physical correction rotations (clockwise degrees) for your build,
// based on your faceID observation with face 2 facing you:
//
// 0 TOP:    appears 270, compensate  90
// 1 RIGHT:  appears  90, compensate 270   (your “left from view” maps to face 1)
// 2 REAR:   appears   0, compensate   0
// 3 LEFT:   appears 270, compensate  90   (your “right from view” maps to face 3)
// 4 FRONT:  appears   0, compensate   0
// 5 BOTTOM: appears  90, compensate 270
//
static constexpr int kDefaultFaceRotCW[6] = {90, 270, 0, 90, 0, 270};

// A Canvas wrapper that applies per face rotation for a cube laid out as a strip:
// x = face * face_w + local_x
// y = local_y
class CubeCanvas : public rgb_matrix::Canvas {
 public:
  CubeCanvas(rgb_matrix::Canvas* base, int face_w, int face_h,
             const int rot_deg_cw[6] = kDefaultFaceRotCW);

  // SwapOnVSync returns a new FrameCanvas pointer, update the base each frame.
  void SetBase(rgb_matrix::Canvas* base);

  int width() const override;
  int height() const override;

  void SetPixel(int x, int y, uint8_t r, uint8_t g, uint8_t b) override;
  void Clear() override;
  void Fill(uint8_t r, uint8_t g, uint8_t b) override;

 private:
  void ApplyRotation(int face, int& x, int& y) const;

  rgb_matrix::Canvas* base_;
  int fw_;
  int fh_;
  int rot_[6];
};

}  // namespace cube
